Aegis  4.25.D505
common/wstring/accumulator.h
Go to the documentation of this file.
00001 //
00002 // aegis - project change supervisor
00003 // Copyright (C) 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 (at
00008 // 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 GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License along
00016 // with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #ifndef COMMON_WSTRING_ACCUMULATOR_H
00020 #define COMMON_WSTRING_ACCUMULATOR_H
00021 
00022 #include <common/wstring.h>
00023 
00028 class wstring_accumulator
00029 {
00030 public:
00035     ~wstring_accumulator();
00036 
00040     wstring_accumulator();
00041 
00045     wstring_accumulator(const wstring_accumulator &);
00046 
00050     wstring_accumulator &operator=(const wstring_accumulator &);
00051 
00056     wstring mkstr() const;
00057 
00065     void
00066     push_back(wchar_t c)
00067     {
00068         if (length < maximum)
00069             buffer[length++] = c;
00070         else
00071             overflow(c);
00072     }
00073 
00083     void push_back(const wchar_t *data, size_t len);
00084 
00092     void push_back(const wchar_t *data);
00093 
00101     void push_back(const wstring_accumulator &data);
00102 
00110     void push_back(const wstring &data);
00111 
00116     void clear() { length = 0; }
00117 
00122     size_t size() const { return length; }
00123 
00128     bool empty() const { return (length == 0); }
00129 
00134     void pop_back() { if (length) --length; }
00135 
00140     wchar_t back() { return (length ? buffer[length - 1] : 0); }
00141 
00152     const wchar_t *get_data() const { return (buffer ? buffer : L""); }
00153 
00162     wchar_t operator[](size_t n) { return buffer[n]; }
00163 
00164 private:
00173     void overflow(wchar_t c);
00174 
00179     size_t length;
00180 
00185     size_t maximum;
00186 
00191     wchar_t *buffer;
00192 };
00193 
00194 #endif // COMMON_WSTRING_ACCUMULATOR_H