CStringBuilder.h++
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 };
00158
00159 #endif // __ccxx_CStringBuilder_hxx