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 #ifndef TINYXML_INCLUDED
00031 #define TINYXML_INCLUDED
00032
00033 #include <ctype.h>
00034 #include <cstdio>
00035 #include <cstdlib>
00036 #include <cstring>
00037 #include <cassert>
00038
00039 #include <string>
00040 #include <iostream>
00041 #define TIXML_STRING std::string
00042 #define TIXML_ISTREAM std::istream
00043 #define TIXML_OSTREAM std::ostream
00044
00045
00046
00047
00048
00049
00050 #define TIXML_SAFE // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress.
00051 #ifdef TIXML_SAFE
00052 #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
00053
00054
00055 #define TIXML_SNPRINTF _snprintf
00056 #define TIXML_SNSCANF _snscanf
00057 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00058
00059
00060 #define TIXML_SNPRINTF snprintf
00061 #define TIXML_SNSCANF snscanf
00062 #endif
00063 #endif
00064
00065 class TiXmlDocument;
00066 class TiXmlElement;
00067 class TiXmlComment;
00068 class TiXmlUnknown;
00069 class TiXmlAttribute;
00070 class TiXmlText;
00071 class TiXmlDeclaration;
00072 class TiXmlParsingData;
00073
00074 const int TIXML_MAJOR_VERSION = 2;
00075 const int TIXML_MINOR_VERSION = 4;
00076 const int TIXML_PATCH_VERSION = 2;
00077
00078
00079
00080
00081 struct TiXmlCursor
00082 {
00083 TiXmlCursor() { Clear(); }
00084 void Clear() { row = col = -1; }
00085
00086 int row;
00087 int col;
00088 };
00089
00090
00091
00092 enum
00093 {
00094 TIXML_SUCCESS,
00095 TIXML_NO_ATTRIBUTE,
00096 TIXML_WRONG_TYPE
00097 };
00098
00099
00100
00101 enum TiXmlEncoding
00102 {
00103 TIXML_ENCODING_UNKNOWN,
00104 TIXML_ENCODING_UTF8,
00105 TIXML_ENCODING_LEGACY
00106 };
00107
00108 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00109
00132 class TiXmlBase
00133 {
00134 friend class TiXmlNode;
00135 friend class TiXmlElement;
00136 friend class TiXmlDocument;
00137
00138 public:
00139 TiXmlBase() : userData(0) {}
00140 virtual ~TiXmlBase() {}
00141
00147 virtual void Print( FILE* cfile, int depth ) const = 0;
00148
00155 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00156
00158 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00159
00178 int Row() const { return location.row + 1; }
00179 int Column() const { return location.col + 1; }
00180
00181 void SetUserData( void* user ) { userData = user; }
00182 void* GetUserData() { return userData; }
00183
00184
00185
00186 static const int utf8ByteTable[256];
00187
00188 virtual const char* Parse( const char* p,
00189 TiXmlParsingData* data,
00190 TiXmlEncoding encoding ) = 0;
00191
00192 enum
00193 {
00194 TIXML_NO_ERROR = 0,
00195 TIXML_ERROR,
00196 TIXML_ERROR_OPENING_FILE,
00197 TIXML_ERROR_OUT_OF_MEMORY,
00198 TIXML_ERROR_PARSING_ELEMENT,
00199 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00200 TIXML_ERROR_READING_ELEMENT_VALUE,
00201 TIXML_ERROR_READING_ATTRIBUTES,
00202 TIXML_ERROR_PARSING_EMPTY,
00203 TIXML_ERROR_READING_END_TAG,
00204 TIXML_ERROR_PARSING_UNKNOWN,
00205 TIXML_ERROR_PARSING_COMMENT,
00206 TIXML_ERROR_PARSING_DECLARATION,
00207 TIXML_ERROR_DOCUMENT_EMPTY,
00208 TIXML_ERROR_EMBEDDED_NULL,
00209 TIXML_ERROR_PARSING_CDATA,
00210
00211 TIXML_ERROR_STRING_COUNT
00212 };
00213
00214 protected:
00215
00216
00217
00218 class StringToBuffer
00219 {
00220 public:
00221 StringToBuffer( const TIXML_STRING& str );
00222 ~StringToBuffer();
00223 char* buffer;
00224 };
00225
00226 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00227 inline static bool IsWhiteSpace( char c )
00228 {
00229 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00230 }
00231
00232 virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00233
00234 static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00235 static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00236
00237
00238
00239
00240
00241 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00242
00243
00244
00245
00246 static const char* ReadText( const char* in,
00247 TIXML_STRING* text,
00248 bool ignoreWhiteSpace,
00249 const char* endTag,
00250 bool ignoreCase,
00251 TiXmlEncoding encoding );
00252
00253
00254 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00255
00256
00257
00258 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00259 {
00260 assert( p );
00261 if ( encoding == TIXML_ENCODING_UTF8 )
00262 {
00263 *length = utf8ByteTable[ *((unsigned char*)p) ];
00264 assert( *length >= 0 && *length < 5 );
00265 }
00266 else
00267 {
00268 *length = 1;
00269 }
00270
00271 if ( *length == 1 )
00272 {
00273 if ( *p == '&' )
00274 return GetEntity( p, _value, length, encoding );
00275 *_value = *p;
00276 return p+1;
00277 }
00278 else if ( *length )
00279 {
00280
00281
00282 for( int i=0; p[i] && i<*length; ++i ) {
00283 _value[i] = p[i];
00284 }
00285 return p + (*length);
00286 }
00287 else
00288 {
00289
00290 return 0;
00291 }
00292 }
00293
00294
00295
00296 static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00297
00298 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00299
00300
00301
00302
00303 static bool StringEqual( const char* p,
00304 const char* endTag,
00305 bool ignoreCase,
00306 TiXmlEncoding encoding );
00307
00308 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00309
00310 TiXmlCursor location;
00311
00313 void* userData;
00314
00315
00316
00317 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00318 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00319 inline static int ToLower( int v, TiXmlEncoding encoding )
00320 {
00321 if ( encoding == TIXML_ENCODING_UTF8 )
00322 {
00323 if ( v < 128 ) return tolower( v );
00324 return v;
00325 }
00326 else
00327 {
00328 return tolower( v );
00329 }
00330 }
00331 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00332
00333 private:
00334 TiXmlBase( const TiXmlBase& );
00335 void operator=( const TiXmlBase& base );
00336
00337 struct Entity
00338 {
00339 const char* str;
00340 unsigned int strLength;
00341 char chr;
00342 };
00343 enum
00344 {
00345 NUM_ENTITY = 5,
00346 MAX_ENTITY_LENGTH = 6
00347
00348 };
00349 static Entity entity[ NUM_ENTITY ];
00350 static bool condenseWhiteSpace;
00351 };
00352
00353
00360 class TiXmlNode : public TiXmlBase
00361 {
00362 friend class TiXmlDocument;
00363 friend class TiXmlElement;
00364
00365 public:
00366
00370 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00371
00388 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00389
00391 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00392
00393
00397 enum NodeType
00398 {
00399 DOCUMENT,
00400 ELEMENT,
00401 COMMENT,
00402 UNKNOWN,
00403 TEXT,
00404 DECLARATION,
00405 TYPECOUNT
00406 };
00407
00408 virtual ~TiXmlNode();
00409
00422 const char *Value() const { return value.c_str (); }
00423
00424 const std::string& ValueStr() const { return value; }
00425
00435 void SetValue(const char * _value) { value = _value;}
00436
00438 void SetValue( const std::string& _value )
00439 {
00440 StringToBuffer buf( _value );
00441 SetValue( buf.buffer ? buf.buffer : "" );
00442 }
00443
00445 void Clear();
00446
00448 TiXmlNode* Parent() { return parent; }
00449 const TiXmlNode* Parent() const { return parent; }
00450
00451 const TiXmlNode* FirstChild() const { return firstChild; }
00452 TiXmlNode* FirstChild() { return firstChild; }
00453 const TiXmlNode* FirstChild( const char * value ) const;
00454 TiXmlNode* FirstChild( const char * value );
00455
00456 const TiXmlNode* LastChild() const { return lastChild; }
00457 TiXmlNode* LastChild() { return lastChild; }
00458 const TiXmlNode* LastChild( const char * value ) const;
00459 TiXmlNode* LastChild( const char * value );
00460
00461 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00462 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00463 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00464 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00465
00482 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00483 TiXmlNode* IterateChildren( TiXmlNode* previous );
00484
00486 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00487 TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous );
00488
00489 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00490 TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
00491
00495 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00496
00497
00507 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00508
00512 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00513
00517 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00518
00522 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00523
00525 bool RemoveChild( TiXmlNode* removeThis );
00526
00528 const TiXmlNode* PreviousSibling() const { return prev; }
00529 TiXmlNode* PreviousSibling() { return prev; }
00530
00532 const TiXmlNode* PreviousSibling( const char * ) const;
00533 TiXmlNode* PreviousSibling( const char * );
00534
00535 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00536 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00537 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00538 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00539
00540
00542 const TiXmlNode* NextSibling() const { return next; }
00543 TiXmlNode* NextSibling() { return next; }
00544
00546 const TiXmlNode* NextSibling( const char * ) const;
00547 TiXmlNode* NextSibling( const char * );
00548
00553 const TiXmlElement* NextSiblingElement() const;
00554 TiXmlElement* NextSiblingElement();
00555
00560 const TiXmlElement* NextSiblingElement( const char * ) const;
00561 TiXmlElement* NextSiblingElement( const char * );
00562
00563 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00564 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
00565
00567 const TiXmlElement* FirstChildElement() const;
00568 TiXmlElement* FirstChildElement();
00569
00571 const TiXmlElement* FirstChildElement( const char * value ) const;
00572 TiXmlElement* FirstChildElement( const char * value );
00573
00574 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00575 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
00576
00581 int Type() const { return type; }
00582
00586 const TiXmlDocument* GetDocument() const;
00587 TiXmlDocument* GetDocument();
00588
00590 bool NoChildren() const { return !firstChild; }
00591
00592 const TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (const TiXmlDocument*) this : 0; }
00593 const TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (const TiXmlElement*) this : 0; }
00594 const TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (const TiXmlComment*) this : 0; }
00595 const TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (const TiXmlUnknown*) this : 0; }
00596 const TiXmlText* ToText() const { return ( this && type == TEXT ) ? (const TiXmlText*) this : 0; }
00597 const TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (const TiXmlDeclaration*) this : 0; }
00598
00599 TiXmlDocument* ToDocument() { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
00600 TiXmlElement* ToElement() { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
00601 TiXmlComment* ToComment() { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
00602 TiXmlUnknown* ToUnknown() { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
00603 TiXmlText* ToText() { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
00604 TiXmlDeclaration* ToDeclaration() { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
00605
00609 virtual TiXmlNode* Clone() const = 0;
00610
00611 protected:
00612 TiXmlNode( NodeType _type );
00613
00614
00615
00616 void CopyTo( TiXmlNode* target ) const;
00617
00618
00619 virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00620
00621
00622 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00623
00624 TiXmlNode* parent;
00625 NodeType type;
00626
00627 TiXmlNode* firstChild;
00628 TiXmlNode* lastChild;
00629
00630 TIXML_STRING value;
00631
00632 TiXmlNode* prev;
00633 TiXmlNode* next;
00634
00635 private:
00636 TiXmlNode( const TiXmlNode& );
00637 void operator=( const TiXmlNode& base );
00638 };
00639
00640
00648 class TiXmlAttribute : public TiXmlBase
00649 {
00650 friend class TiXmlAttributeSet;
00651
00652 public:
00654 TiXmlAttribute() : TiXmlBase()
00655 {
00656 document = 0;
00657 prev = next = 0;
00658 }
00659
00661 TiXmlAttribute( const std::string& _name, const std::string& _value )
00662 {
00663 name = _name;
00664 value = _value;
00665 document = 0;
00666 prev = next = 0;
00667 }
00668
00670 TiXmlAttribute( const char * _name, const char * _value )
00671 {
00672 name = _name;
00673 value = _value;
00674 document = 0;
00675 prev = next = 0;
00676 }
00677
00678 const char* Name() const { return name.c_str (); }
00679 const char* Value() const { return value.c_str (); }
00680 int IntValue() const;
00681 double DoubleValue() const;
00682
00692 int QueryIntValue( int* _value ) const;
00694 int QueryDoubleValue( double* _value ) const;
00695
00696 void SetName( const char* _name ) { name = _name; }
00697 void SetValue( const char* _value ) { value = _value; }
00698
00699 void SetIntValue( int _value );
00700 void SetDoubleValue( double _value );
00701
00703 void SetName( const std::string& _name )
00704 {
00705 StringToBuffer buf( _name );
00706 SetName ( buf.buffer ? buf.buffer : "error" );
00707 }
00709 void SetValue( const std::string& _value )
00710 {
00711 StringToBuffer buf( _value );
00712 SetValue( buf.buffer ? buf.buffer : "error" );
00713 }
00714
00716 const TiXmlAttribute* Next() const;
00717 TiXmlAttribute* Next();
00719 const TiXmlAttribute* Previous() const;
00720 TiXmlAttribute* Previous();
00721
00722 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00723 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00724 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00725
00726
00727
00728
00729 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00730
00731
00732 virtual void Print( FILE* cfile, int depth ) const;
00733
00734 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00735
00736
00737 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00738
00739 private:
00740 TiXmlAttribute( const TiXmlAttribute& );
00741 void operator=( const TiXmlAttribute& base );
00742
00743 TiXmlDocument* document;
00744 TIXML_STRING name;
00745 TIXML_STRING value;
00746 TiXmlAttribute* prev;
00747 TiXmlAttribute* next;
00748 };
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763 class TiXmlAttributeSet
00764 {
00765 public:
00766 TiXmlAttributeSet();
00767 ~TiXmlAttributeSet();
00768
00769 void Add( TiXmlAttribute* attribute );
00770 void Remove( TiXmlAttribute* attribute );
00771
00772 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00773 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00774 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00775 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00776
00777 const TiXmlAttribute* Find( const char * name ) const;
00778 TiXmlAttribute* Find( const char * name );
00779
00780 private:
00781
00782
00783 TiXmlAttributeSet( const TiXmlAttributeSet& );
00784 void operator=( const TiXmlAttributeSet& );
00785
00786 TiXmlAttribute sentinel;
00787 };
00788
00789
00794 class TiXmlElement : public TiXmlNode
00795 {
00796 public:
00798 TiXmlElement (const char * in_value);
00799
00801 TiXmlElement( const std::string& _value );
00802
00803 TiXmlElement( const TiXmlElement& );
00804
00805 void operator=( const TiXmlElement& base );
00806
00807 virtual ~TiXmlElement();
00808
00812 const char* Attribute( const char* name ) const;
00813
00820 const char* Attribute( const char* name, int* i ) const;
00821
00828 const char* Attribute( const char* name, double* d ) const;
00829
00837 int QueryIntAttribute( const char* name, int* _value ) const;
00839 int QueryDoubleAttribute( const char* name, double* _value ) const;
00841 int QueryFloatAttribute( const char* name, float* _value ) const {
00842 double d;
00843 int result = QueryDoubleAttribute( name, &d );
00844 if ( result == TIXML_SUCCESS ) {
00845 *_value = (float)d;
00846 }
00847 return result;
00848 }
00849
00853 void SetAttribute( const char* name, const char * _value );
00854
00855
00856 const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
00857 const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
00858 const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); }
00859 int QueryIntAttribute( const std::string& name, int* _value ) const { return QueryIntAttribute( name.c_str(), _value ); }
00860 int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); }
00861
00863 void SetAttribute( const std::string& name, const std::string& _value )
00864 {
00865 StringToBuffer n( name );
00866 StringToBuffer v( _value );
00867 if ( n.buffer && v.buffer )
00868 SetAttribute (n.buffer, v.buffer );
00869 }
00871 void SetAttribute( const std::string& name, int _value )
00872 {
00873 StringToBuffer n( name );
00874 if ( n.buffer )
00875 SetAttribute (n.buffer, _value);
00876 }
00877
00878
00882 void SetAttribute( const char * name, int value );
00883
00887 void SetDoubleAttribute( const char * name, double value );
00888
00891 void RemoveAttribute( const char * name );
00892
00893 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
00894
00895
00896 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
00897 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
00898 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
00899 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
00900
00933 const char* GetText() const;
00934
00936 virtual TiXmlNode* Clone() const;
00937
00938 virtual void Print( FILE* cfile, int depth ) const;
00939
00940
00941
00942
00943 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00944
00945 protected:
00946
00947 void CopyTo( TiXmlElement* target ) const;
00948 void ClearThis();
00949
00950
00951
00952 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00953
00954 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00955
00956
00957
00958
00959
00960 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
00961
00962 private:
00963
00964 TiXmlAttributeSet attributeSet;
00965 };
00966
00967
00970 class TiXmlComment : public TiXmlNode
00971 {
00972 public:
00974 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
00975 TiXmlComment( const TiXmlComment& );
00976 void operator=( const TiXmlComment& base );
00977
00978 virtual ~TiXmlComment() {}
00979
00981 virtual TiXmlNode* Clone() const;
00983 virtual void Print( FILE* cfile, int depth ) const;
00984
00985
00986
00987
00988 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00989
00990 protected:
00991 void CopyTo( TiXmlComment* target ) const;
00992
00993
00994
00995 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00996
00997 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00998
00999 private:
01000
01001 };
01002
01003
01009 class TiXmlText : public TiXmlNode
01010 {
01011 friend class TiXmlElement;
01012 public:
01017 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01018 {
01019 SetValue( initValue );
01020 cdata = false;
01021 }
01022 virtual ~TiXmlText() {}
01023
01024
01026 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01027 {
01028 SetValue( initValue );
01029 cdata = false;
01030 }
01031
01032
01033 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01034 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01035
01037 virtual void Print( FILE* cfile, int depth ) const;
01038
01040 bool CDATA() { return cdata; }
01042 void SetCDATA( bool _cdata ) { cdata = _cdata; }
01043
01044 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01045
01046 protected :
01048 virtual TiXmlNode* Clone() const;
01049 void CopyTo( TiXmlText* target ) const;
01050
01051 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01052 bool Blank() const;
01053
01054
01055 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01056
01057
01058 private:
01059 bool cdata;
01060 };
01061
01062
01076 class TiXmlDeclaration : public TiXmlNode
01077 {
01078 public:
01080 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01081
01082
01084 TiXmlDeclaration( const std::string& _version,
01085 const std::string& _encoding,
01086 const std::string& _standalone );
01087
01088
01090 TiXmlDeclaration( const char* _version,
01091 const char* _encoding,
01092 const char* _standalone );
01093
01094 TiXmlDeclaration( const TiXmlDeclaration& copy );
01095 void operator=( const TiXmlDeclaration& copy );
01096
01097 virtual ~TiXmlDeclaration() {}
01098
01100 const char *Version() const { return version.c_str (); }
01102 const char *Encoding() const { return encoding.c_str (); }
01104 const char *Standalone() const { return standalone.c_str (); }
01105
01107 virtual TiXmlNode* Clone() const;
01109 virtual void Print( FILE* cfile, int depth ) const;
01110
01111 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01112
01113 protected:
01114 void CopyTo( TiXmlDeclaration* target ) const;
01115
01116
01117 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01118
01119 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01120
01121 private:
01122
01123 TIXML_STRING version;
01124 TIXML_STRING encoding;
01125 TIXML_STRING standalone;
01126 };
01127
01128
01136 class TiXmlUnknown : public TiXmlNode
01137 {
01138 public:
01139 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01140 virtual ~TiXmlUnknown() {}
01141
01142 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01143 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01144
01146 virtual TiXmlNode* Clone() const;
01148 virtual void Print( FILE* cfile, int depth ) const;
01149
01150 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01151
01152 protected:
01153 void CopyTo( TiXmlUnknown* target ) const;
01154
01155
01156 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01157
01158 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01159
01160 private:
01161
01162 };
01163
01164
01169 class TiXmlDocument : public TiXmlNode
01170 {
01171 public:
01173 TiXmlDocument();
01175 TiXmlDocument( const char * documentName );
01176
01177
01179 TiXmlDocument( const std::string& documentName );
01180
01181
01182 TiXmlDocument( const TiXmlDocument& copy );
01183 void operator=( const TiXmlDocument& copy );
01184
01185 virtual ~TiXmlDocument() {}
01186
01191 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01193 bool SaveFile() const;
01195 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01197 bool SaveFile( const char * filename ) const;
01198
01199
01200 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01201 {
01202 StringToBuffer f( filename );
01203 return ( f.buffer && LoadFile( f.buffer, encoding ));
01204 }
01205 bool SaveFile( const std::string& filename ) const
01206 {
01207 StringToBuffer f( filename );
01208 return ( f.buffer && SaveFile( f.buffer ));
01209 }
01210
01211
01216 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01217
01222 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01223 TiXmlElement* RootElement() { return FirstChildElement(); }
01224
01230 bool Error() const { return error; }
01231
01233 const char * ErrorDesc() const { return errorDesc.c_str (); }
01234
01238 int ErrorId() const { return errorId; }
01239
01247 int ErrorRow() { return errorLocation.row+1; }
01248 int ErrorCol() { return errorLocation.col+1; }
01249
01274 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01275
01276 int TabSize() const { return tabsize; }
01277
01281 void ClearError() { error = false;
01282 errorId = 0;
01283 errorDesc = "";
01284 errorLocation.row = errorLocation.col = 0;
01285
01286 }
01287
01289 void Print() const { Print( stdout, 0 ); }
01290
01292 virtual void Print( FILE* cfile, int depth = 0 ) const;
01293
01294 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01295
01296 protected :
01297 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01298
01299 virtual TiXmlNode* Clone() const;
01300
01301 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01302
01303
01304 private:
01305 void CopyTo( TiXmlDocument* target ) const;
01306
01307 bool error;
01308 int errorId;
01309 TIXML_STRING errorDesc;
01310 int tabsize;
01311 TiXmlCursor errorLocation;
01312 bool useMicrosoftBOM;
01313 };
01314
01315
01396 class TiXmlHandle
01397 {
01398 public:
01400 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01402 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01403 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01404
01406 TiXmlHandle FirstChild() const;
01408 TiXmlHandle FirstChild( const char * value ) const;
01410 TiXmlHandle FirstChildElement() const;
01412 TiXmlHandle FirstChildElement( const char * value ) const;
01413
01417 TiXmlHandle Child( const char* value, int index ) const;
01421 TiXmlHandle Child( int index ) const;
01426 TiXmlHandle ChildElement( const char* value, int index ) const;
01431 TiXmlHandle ChildElement( int index ) const;
01432
01433
01434 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01435 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01436
01437 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01438 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01439
01440
01442 TiXmlNode* Node() const { return node; }
01444 TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01446 TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01448 TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01449
01450 private:
01451 TiXmlNode* node;
01452 };
01453
01454 #endif
01455