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 "cal3d/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
00079 void operator = (const char * content);
00080
00081
00082 void operator = (const TiXmlString & copy);
00083
00084
00085 TiXmlString& operator += (const char * suffix)
00086 {
00087 append (suffix);
00088 return *this;
00089 }
00090
00091
00092 TiXmlString& operator += (char single)
00093 {
00094 append (single);
00095 return *this;
00096 }
00097
00098
00099 TiXmlString& operator += (TiXmlString & suffix)
00100 {
00101 append (suffix);
00102 return *this;
00103 }
00104 bool operator == (const TiXmlString & compare) const;
00105 bool operator < (const TiXmlString & compare) const;
00106 bool operator > (const TiXmlString & compare) const;
00107
00108
00109 bool empty () const
00110 {
00111 return length () ? false : true;
00112 }
00113
00114
00115
00116
00117
00118
00119
00120 const char& at (unsigned index) const
00121 {
00122 assert( index < length ());
00123 return cstring [index];
00124 }
00125
00126
00127 unsigned find (char lookup) const
00128 {
00129 return find (lookup, 0);
00130 }
00131
00132
00133 unsigned find (char tofind, unsigned offset) const;
00134
00135
00136
00137
00138 void reserve (unsigned size)
00139 {
00140 empty_it ();
00141 if (size)
00142 {
00143 allocated = size;
00144 cstring = new char [size];
00145 cstring [0] = 0;
00146 current_length = 0;
00147 }
00148 }
00149
00150
00151 char& operator [] (unsigned index) const
00152 {
00153 assert( index < length ());
00154 return cstring [index];
00155 }
00156
00157
00158 enum { notfound = 0xffffffff,
00159 npos = notfound };
00160
00161 void append (const char *str, int len );
00162
00163 protected :
00164
00165
00166 char * cstring;
00167
00168 unsigned allocated;
00169
00170 unsigned current_length;
00171
00172
00173
00174 unsigned assign_new_size (unsigned minimum_to_allocate)
00175 {
00176 return minimum_to_allocate * 2;
00177 }
00178
00179
00180 void empty_it ()
00181 {
00182 if (cstring)
00183 delete [] cstring;
00184 cstring = NULL;
00185 allocated = 0;
00186 current_length = 0;
00187 }
00188
00189 void append (const char *suffix );
00190
00191
00192 void append (const TiXmlString & suffix)
00193 {
00194 append (suffix . c_str ());
00195 }
00196
00197
00198 void append (char single)
00199 {
00200 char smallstr [2];
00201 smallstr [0] = single;
00202 smallstr [1] = 0;
00203 append (smallstr);
00204 }
00205
00206 } ;
00207
00208
00209
00210
00211
00212 class TiXmlOutStream : public TiXmlString
00213 {
00214 public :
00215 TiXmlOutStream () : TiXmlString () {}
00216
00217
00218 TiXmlOutStream & operator << (const char * in)
00219 {
00220 append (in);
00221 return (* this);
00222 }
00223
00224
00225 TiXmlOutStream & operator << (const TiXmlString & in)
00226 {
00227 append (in . c_str ());
00228 return (* this);
00229 }
00230 } ;
00231
00232 #endif // TIXML_STRING_INCLUDED
00233 #endif // TIXML_USE_STL