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