CStringBuilder.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2012  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020    ---------------------------------------------------------------------------
00021 */
00022 
00023 #ifndef __ccxx_CStringBuilder_hxx
00024 #define __ccxx_CStringBuilder_hxx
00025 
00026 #include <commonc++/Common.h++>
00027 
00028 namespace ccxx {
00029 
00041 class COMMONCPP_API CStringBuilder
00042 {
00043   public:
00044 
00050   CStringBuilder(char *buf, size_t size);
00051 
00053   ~CStringBuilder();
00054 
00058   CStringBuilder& clear();
00059 
00067   CStringBuilder& append(const char *s, size_t length = 0);
00068 
00070   CStringBuilder& append(char c);
00071 
00080   CStringBuilder& append(int val, size_t width, bool zeroPad = true);
00081 
00091   CStringBuilder& append(uint_t val, size_t width, bool zeroPad = true);
00092 
00094   inline char *getPosition() const
00095   { return(_pos); }
00096 
00100   inline size_t getRemaining() const
00101   { return(_left); }
00102 
00105   inline bool hasRemaining() const
00106   { return(_left > 0); }
00107 
00111   inline size_t getLength() const
00112   { return(_pos - _buf); }
00113 
00117   inline size_t length() const
00118   { return(getLength()); }
00119 
00121   inline char *c_str() const
00122   { return(_buf); }
00123 
00130   bool bump(size_t delta);
00131 
00133   void terminate();
00134 
00136   inline CStringBuilder& operator+=(const char *s)
00137   { return(append(s)); }
00138 
00140   inline CStringBuilder& operator+=(char c)
00141   { return(append(c)); }
00142 
00143   private:
00144 
00145   CCXX_COPY_DECLS(CStringBuilder);
00146 
00147   template<typename T> char * _formatValue(T value, size_t width,
00148                                            char padChar, char *buf,
00149                                            size_t bufsz);
00150 
00151   char *_buf;
00152   size_t _length;
00153   char *_pos;
00154   size_t _left;
00155 };
00156 
00157 }; // namespace ccxx
00158 
00159 #endif // __ccxx_CStringBuilder_hxx
Generated on Sat Nov 26 16:49:07 2011 for libcommonc++ by  doxygen 1.6.3