00001 #ifndef bufstring_h
00002 #define bufstring_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "convert.h"
00017 #include <iosfwd>
00018
00034 mClass BufferString
00035 {
00036 public:
00037
00038 inline BufferString();
00039 inline BufferString(const char*);
00040 BufferString(int minlen,bool setnull);
00041 BufferString(const BufferString& bs);
00042 template <class T>
00043 inline BufferString(const char*,T,const char* s=0);
00044 virtual ~BufferString();
00045
00046 BufferString& operator=(const char*);
00047 inline BufferString& operator=(const BufferString& bs);
00048 template <class T>
00049 inline BufferString& operator=(T);
00050
00051 inline bool operator==(const BufferString&) const;
00052 inline bool operator!=(const BufferString&) const;
00053 bool operator==(const char*) const;
00054 inline bool operator!=(const char*) const;
00055 template <class T>
00056 inline bool operator==(T) const;
00057 template <class T>
00058 inline bool operator!=( T t ) const { return !(*this==t); }
00059
00060 char* buf();
00061 inline const char* buf() const { return buf_ ? buf_ : empty().buf_; }
00062 inline const char* str() const;
00063 inline operator const char*() const { return buf(); }
00064 inline char& operator []( int idx ) { return buf()[idx]; }
00065 inline const char& operator []( int idx ) const { return buf()[idx]; }
00066 bool isEmpty() const;
00067 void setEmpty();
00068 bool isEqual(const char*,bool caseinsens=false) const;
00069 bool isStartOf(const char*,bool caseinsens=false) const;
00070 bool matches(const char*,bool caseinsens=false) const;
00071
00072 BufferString& add(const char*);
00073 template <class T>
00074 BufferString& add(T);
00075 BufferString& operator+=( const char* s ) { return add( s ); }
00076 template <class T>
00077 inline BufferString& operator+=( T t ) { return add( t ); }
00078
00079 unsigned int size() const;
00080 inline unsigned int bufSize() const { return len_; }
00081 void setBufSize(unsigned int);
00082 inline unsigned int minBufSize() const { return minlen_; }
00083 void setMinBufSize(unsigned int);
00084
00085 void insertAt(int idx, const char*);
00086
00087 void replaceAt(int idx, const char*,bool cutoff=true);
00088
00089
00090 bool operator >(const char*) const;
00091 bool operator <(const char*) const;
00092 template <class T>
00093 inline bool operator >(T) const;
00094 template <class T>
00095 inline bool operator <(T) const;
00096
00097 static const BufferString& empty();
00098
00099 protected:
00100
00101 char* buf_;
00102 unsigned int len_;
00103 const unsigned int minlen_;
00104
00105 private:
00106
00107 void init();
00108 inline void destroy() { delete [] buf_; buf_ = 0; }
00109
00110 };
00111
00112 mGlobal std::ostream& operator <<(std::ostream&,const BufferString&);
00113 mGlobal std::istream& operator >>(std::istream&,BufferString&);
00114
00115
00116 #define mBufferStringSimpConstrInitList \
00117 minlen_(mMaxFilePathLength+1), buf_(0), len_(0)
00118
00119 inline BufferString::BufferString()
00120 : mBufferStringSimpConstrInitList {}
00121 inline BufferString::BufferString( const char* s )
00122 : mBufferStringSimpConstrInitList { *this = s; }
00123
00124 template <class T> inline
00125 BufferString::BufferString( const char* s1, T t, const char* s2 )
00126 : mBufferStringSimpConstrInitList
00127 { *this += s1; *this += t; *this += s2; }
00128
00129
00130 inline
00131 const char* BufferString::str() const
00132 { return isEmpty() ? 0 : buf_; }
00133
00134
00135 inline bool BufferString::operator==( const BufferString& s ) const
00136 { return operator ==( s.buf() ); }
00137
00138 template <class T> inline bool BufferString::operator==( T t ) const
00139 { return *this == Conv::to<const char*>( t ); }
00140
00141 inline bool BufferString::operator!=( const BufferString& s ) const
00142 { return operator !=( s.buf() ); }
00143
00144 inline bool BufferString::operator!=( const char* s ) const
00145 { return ! (*this == s); }
00146
00147 inline BufferString& BufferString::operator=( const BufferString& bs )
00148 { if ( &bs != this ) *this = bs.buf_; return *this; }
00149
00150 template <class T> inline BufferString& BufferString::operator=( T t )
00151 { *this = Conv::to<const char*>( t ); return *this; }
00152
00153 template <class T> inline BufferString& BufferString::add( T t )
00154 { return add( Conv::to<const char*>( t ) ); }
00155
00156 template <class T> inline bool BufferString::operator >( T t ) const
00157 { return *this > ( Conv::to<const char*>( t ) ); }
00158
00159 template <class T> inline bool BufferString::operator <( T t ) const
00160 { return *this < ( Conv::to<const char*>( t ) ); }
00161
00162
00163 #endif