00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifdef _WINDOWS
00038
00039 #ifdef LIBYXML_EXPORTS
00040 #define YXML_API __declspec(dllexport)
00041 #else
00042 #ifndef LIBYXML_STATIC
00043 #define YXML_API __declspec(dllimport)
00044 #endif
00045 #endif
00046
00047 #endif
00048
00049 #ifndef YXML_API
00050 #define YXML_API
00051 #endif
00052
00056 namespace TelEngine {
00057
00058 #ifndef TIXML_USE_STL
00059
00060 #ifndef TIXML_STRING_INCLUDED
00061 #define TIXML_STRING_INCLUDED
00062
00063 #include <assert.h>
00064 #include <string.h>
00065
00066
00067
00068
00069
00070 #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
00071
00072 #define TIXML_EXPLICIT explicit
00073 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00074
00075 #define TIXML_EXPLICIT explicit
00076 #else
00077 #define TIXML_EXPLICIT
00078 #endif
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 class YXML_API TiXmlString
00089 {
00090 public :
00091
00092 typedef size_t size_type;
00093
00094
00095 static const size_type npos;
00096
00097
00098
00099 TiXmlString () : rep_(&nullrep_)
00100 {
00101 }
00102
00103
00104 TiXmlString ( const TiXmlString & copy)
00105 {
00106 init(copy.length());
00107 memcpy(start(), copy.data(), length());
00108 }
00109
00110
00111 TIXML_EXPLICIT TiXmlString ( const char * copy)
00112 {
00113 init( static_cast<size_type>( strlen(copy) ));
00114 memcpy(start(), copy, length());
00115 }
00116
00117
00118 TIXML_EXPLICIT TiXmlString ( const char * str, size_type len)
00119 {
00120 init(len);
00121 memcpy(start(), str, len);
00122 }
00123
00124
00125 ~TiXmlString ()
00126 {
00127 quit();
00128 }
00129
00130
00131 TiXmlString& operator = (const char * copy)
00132 {
00133 return assign( copy, (size_type)strlen(copy));
00134 }
00135
00136
00137 TiXmlString& operator = (const TiXmlString & copy)
00138 {
00139 return assign(copy.start(), copy.length());
00140 }
00141
00142
00143
00144 TiXmlString& operator += (const char * suffix)
00145 {
00146 return append(suffix, static_cast<size_type>( strlen(suffix) ));
00147 }
00148
00149
00150 TiXmlString& operator += (char single)
00151 {
00152 return append(&single, 1);
00153 }
00154
00155
00156 TiXmlString& operator += (const TiXmlString & suffix)
00157 {
00158 return append(suffix.data(), suffix.length());
00159 }
00160
00161
00162
00163 const char * c_str () const { return rep_->str; }
00164
00165
00166 const char * data () const { return rep_->str; }
00167
00168
00169 size_type length () const { return rep_->size; }
00170
00171
00172 size_type size () const { return rep_->size; }
00173
00174
00175 bool empty () const { return rep_->size == 0; }
00176
00177
00178 size_type capacity () const { return rep_->capacity; }
00179
00180
00181
00182 const char& at (size_type index) const
00183 {
00184 assert( index < length() );
00185 return rep_->str[ index ];
00186 }
00187
00188
00189 char& operator [] (size_type index) const
00190 {
00191 assert( index < length() );
00192 return rep_->str[ index ];
00193 }
00194
00195
00196 size_type find (char lookup) const
00197 {
00198 return find(lookup, 0);
00199 }
00200
00201
00202 size_type find (char tofind, size_type offset) const
00203 {
00204 if (offset >= length()) return npos;
00205
00206 for (const char* p = c_str() + offset; *p != '\0'; ++p)
00207 {
00208 if (*p == tofind) return static_cast< size_type >( p - c_str() );
00209 }
00210 return npos;
00211 }
00212
00213 void clear ()
00214 {
00215
00216
00217
00218
00219 quit();
00220 init(0,0);
00221 }
00222
00223
00224
00225
00226 void reserve (size_type cap);
00227
00228 TiXmlString& assign (const char* str, size_type len);
00229
00230 TiXmlString& append (const char* str, size_type len);
00231
00232 void swap (TiXmlString& other)
00233 {
00234 Rep* r = rep_;
00235 rep_ = other.rep_;
00236 other.rep_ = r;
00237 }
00238
00239 private:
00240
00241 void init(size_type sz) { init(sz, sz); }
00242 void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
00243 char* start() const { return rep_->str; }
00244 char* finish() const { return rep_->str + rep_->size; }
00245
00246 struct Rep
00247 {
00248 size_type size, capacity;
00249 char str[1];
00250 };
00251
00252 void init(size_type sz, size_type cap)
00253 {
00254 if (cap)
00255 {
00256
00257
00258
00259
00260
00261 const size_type bytesNeeded = sizeof(Rep) + cap;
00262 const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
00263 rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
00264
00265 rep_->str[ rep_->size = sz ] = '\0';
00266 rep_->capacity = cap;
00267 }
00268 else
00269 {
00270 rep_ = &nullrep_;
00271 }
00272 }
00273
00274 void quit()
00275 {
00276 if (rep_ != &nullrep_)
00277 {
00278
00279
00280 delete [] ( reinterpret_cast<int*>( rep_ ) );
00281 }
00282 }
00283
00284 Rep * rep_;
00285 static Rep nullrep_;
00286
00287 } ;
00288
00289
00290 inline bool operator == (const TiXmlString & a, const TiXmlString & b)
00291 {
00292 return ( a.length() == b.length() )
00293 && ( strcmp(a.c_str(), b.c_str()) == 0 );
00294 }
00295 inline bool operator < (const TiXmlString & a, const TiXmlString & b)
00296 {
00297 return strcmp(a.c_str(), b.c_str()) < 0;
00298 }
00299
00300 inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
00301 inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; }
00302 inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); }
00303 inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); }
00304
00305 inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; }
00306 inline bool operator == (const char* a, const TiXmlString & b) { return b == a; }
00307 inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); }
00308 inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); }
00309
00310 TiXmlString operator + (const TiXmlString & a, const TiXmlString & b);
00311 TiXmlString operator + (const TiXmlString & a, const char* b);
00312 TiXmlString operator + (const char* a, const TiXmlString & b);
00313
00314
00315
00316
00317
00318
00319 class YXML_API TiXmlOutStream : public TiXmlString
00320 {
00321 public :
00322
00323
00324 TiXmlOutStream & operator << (const TiXmlString & in)
00325 {
00326 *this += in;
00327 return *this;
00328 }
00329
00330
00331 TiXmlOutStream & operator << (const char * in)
00332 {
00333 *this += in;
00334 return *this;
00335 }
00336
00337 };
00338
00339 };
00340
00341 #endif // TIXML_STRING_INCLUDED
00342 #endif // TIXML_USE_STL