Aegis  4.25.D505
common/stracc.h
Go to the documentation of this file.
00001 //
00002 //      aegis - project change supervisor
00003 //      Copyright (C) 1998, 2001, 2004-2006, 2008 Peter Miller
00004 //
00005 //      This program is free software; you can redistribute it and/or modify
00006 //      it under the terms of the GNU General Public License as published by
00007 //      the Free Software Foundation; either version 3 of the License, or
00008 //      (at your option) any later version.
00009 //
00010 //      This program is distributed in the hope that it will be useful,
00011 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //      GNU General Public License for more details.
00014 //
00015 //      You should have received a copy of the GNU General Public License
00016 //      along with this program. If not, see
00017 //      <http://www.gnu.org/licenses/>.
00018 //
00019 
00020 #ifndef COMMON_STRACC_H
00021 #define COMMON_STRACC_H
00022 
00023 #include <common/str.h>
00024 
00034 class stracc_t
00035 {
00036 public:
00041     ~stracc_t();
00042 
00046     stracc_t();
00047 
00051     stracc_t(const stracc_t &);
00052 
00056     stracc_t &operator=(const stracc_t &);
00057 
00062     string_ty *mkstr() const;
00063 
00071     void
00072     push_back(char c)
00073     {
00074         //
00075         // The stracc::push_back(char) method shows up in the profiles
00076         // as occupying 10% of the time it takes to parse the database
00077         // files.  By making it an inline, things go measurably faster.
00078         //
00079         if (length < maximum)
00080             buffer[length++] = c;
00081         else
00082             overflow(c);
00083     }
00084 
00094     void push_back(const char *data, size_t len);
00095 
00103     void push_back(const char *data);
00104 
00112     void push_back(const stracc_t &data);
00113 
00118     char back() { return buffer[length - 1]; }
00119 
00124     void clear() { length = 0; }
00125 
00130     size_t size() const { return length; }
00131 
00136     bool empty() const { return (length == 0); }
00137 
00142     void pop_back() { if (length) --length; }
00143 
00154     const char *get_data() const { return buffer; }
00155 
00163     char operator[](size_t n) { return buffer[n]; }
00164 
00165     size_t count_nul_characters() const;
00166 
00167 private:
00176     void overflow(char c);
00177 
00182     size_t length;
00183 
00188     size_t maximum;
00189 
00194     char *buffer;
00195 };
00196 
00197 inline DEPRECATED void
00198 stracc_constructor(stracc_t *p)
00199 {
00200     p->clear();
00201 }
00202 
00203 inline DEPRECATED void
00204 stracc_destructor(stracc_t *p)
00205 {
00206     p->clear();
00207 }
00208 
00209 inline DEPRECATED void
00210 stracc_open(stracc_t *p)
00211 {
00212     p->clear();
00213 }
00214 
00215 inline DEPRECATED string_ty *
00216 stracc_close(const stracc_t *p)
00217 {
00218     return p->mkstr();
00219 }
00220 
00221 inline DEPRECATED void
00222 stracc_char(stracc_t *p, char c)
00223 {
00224     p->push_back(c);
00225 }
00226 
00227 inline DEPRECATED void
00228 stracc_chars(stracc_t *p, const char *data, size_t len)
00229 {
00230     p->push_back(data, len);
00231 }
00232 
00233 
00235 #endif // COMMON_STRACC_H