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 #include "tinyxml.h"
00027
00028
00029 #ifndef TIXML_USE_STL
00030
00031 #ifndef TIXML_STRING_INCLUDED
00032 #define TIXML_STRING_INCLUDED
00033
00034 #pragma warning( disable : 4514 )
00035
00036 #include <assert.h>
00037
00038
00039
00040
00041
00042
00043
00044
00045 class TiXmlString
00046 {
00047 public:
00048
00049 TiXmlString(const char *instring);
00050
00051
00052 TiXmlString()
00053 {
00054 allocated = 0;
00055 cstring = NULL;
00056 current_length = 0;
00057 }
00058
00059
00060 TiXmlString(const TiXmlString & copy);
00061
00062
00063 ~TiXmlString()
00064 {
00065 empty_it();
00066 }
00067
00068
00069 const char *c_str() const
00070 {
00071 if(allocated)
00072 return cstring;
00073 return "";
00074 }
00075
00076
00077 unsigned length() const;
00078
00079
00080 void operator =(const char *content);
00081
00082
00083 void operator =(const TiXmlString & copy);
00084
00085
00086 TiXmlString & operator +=(const char *suffix)
00087 {
00088 append(suffix);
00089 return *this;
00090 }
00091
00092
00093 TiXmlString & operator +=(char single)
00094 {
00095 append(single);
00096 return *this;
00097 }
00098
00099
00100 TiXmlString & operator +=(TiXmlString & suffix)
00101 {
00102 append(suffix);
00103 return *this;
00104 }
00105 bool operator ==(const TiXmlString & compare) const;
00106 bool operator <(const TiXmlString & compare) const;
00107 bool operator >(const TiXmlString & compare) const;
00108
00109
00110 bool empty() const
00111 {
00112 return length() ? false : true;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121 const char &at(unsigned index) const
00122 {
00123 assert(index < length());
00124 return cstring[index];
00125 }
00126
00127
00128 unsigned find(char lookup) const
00129 {
00130 return find(lookup, 0);
00131 }
00132
00133
00134 unsigned find(char tofind, unsigned offset) const;
00135
00136
00137
00138
00139 void reserve(unsigned size)
00140 {
00141 empty_it();
00142 if(size)
00143 {
00144 allocated = size;
00145 cstring = new char[size];
00146
00147 cstring[0] = 0;
00148 current_length = 0;
00149 }
00150 }
00151
00152
00153 char &operator [] (unsigned index) const
00154 {
00155 assert(index < length());
00156 return cstring[index];
00157 }
00158
00159
00160 enum
00161 { notfound = 0xffffffff,
00162 npos = notfound
00163 };
00164
00165 void append(const char *str, int len);
00166
00167 protected:
00168
00169
00170 char *cstring;
00171
00172
00173 unsigned allocated;
00174
00175
00176 unsigned current_length;
00177
00178
00179
00180 unsigned assign_new_size(unsigned minimum_to_allocate)
00181 {
00182 return minimum_to_allocate * 2;
00183 }
00184
00185
00186 void empty_it()
00187 {
00188 if(cstring)
00189 delete[]cstring;
00190 cstring = NULL;
00191 allocated = 0;
00192 current_length = 0;
00193 }
00194
00195 void append(const char *suffix);
00196
00197
00198 void append(const TiXmlString & suffix)
00199 {
00200 append(suffix.c_str());
00201 }
00202
00203
00204 void append(char single)
00205 {
00206 char smallstr[2];
00207
00208 smallstr[0] = single;
00209 smallstr[1] = 0;
00210 append(smallstr);
00211 }
00212
00213 };
00214
00215
00216
00217
00218
00219 class TiXmlOutStream:public TiXmlString
00220 {
00221 public:TiXmlOutStream():TiXmlString()
00222 {
00223 }
00224
00225
00226 TiXmlOutStream & operator <<(const char *in)
00227 {
00228 append(in);
00229 return (*this);
00230 }
00231
00232
00233 TiXmlOutStream & operator <<(const TiXmlString & in)
00234 {
00235 append(in.c_str());
00236 return (*this);
00237 }
00238 };
00239
00240 #endif // TIXML_STRING_INCLUDED
00241 #endif // TIXML_USE_STL