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 #ifndef TINYXML_INCLUDED
00027 #define TINYXML_INCLUDED
00028
00029 #ifdef _MSC_VER
00030 #pragma warning( disable : 4530 )
00031 #pragma warning( disable : 4786 )
00032 #endif
00033
00034 #include <ctype.h>
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038 #include <assert.h>
00039
00040
00041 #if defined( _DEBUG ) && !defined( DEBUG )
00042 #define DEBUG
00043 #endif
00044
00045 #if defined( DEBUG ) && defined( _MSC_VER )
00046 #include <windows.h>
00047 #define TIXML_LOG OutputDebugString
00048 #else
00049 #define TIXML_LOG printf
00050 #endif
00051
00052 #ifdef TIXML_USE_STL
00053 #include <string>
00054 #include <iostream>
00055 #define TIXML_STRING std::string
00056 #define TIXML_ISTREAM std::istream
00057 #define TIXML_OSTREAM std::ostream
00058 #define TIXML_CAST_STRING std::string
00059 #else
00060 #include "tinystr.h"
00061 #define TIXML_STRING TiXmlString
00062 #define TIXML_OSTREAM TiXmlOutStream
00063 #define TIXML_CAST_STRING
00064 #endif
00065
00066 class TiXmlDocument;
00067 class TiXmlElement;
00068 class TiXmlComment;
00069 class TiXmlUnknown;
00070 class TiXmlAttribute;
00071 class TiXmlText;
00072 class TiXmlDeclaration;
00073 class TiXmlParsingData;
00074
00075 const int TIXML_MAJOR_VERSION = 2;
00076 const int TIXML_MINOR_VERSION = 3;
00077 const int TIXML_PATCH_VERSION = 3;
00078
00079
00080
00081
00082 struct TiXmlCursor
00083 {
00084 TiXmlCursor() { Clear(); }
00085 void Clear() { row = col = -1; }
00086
00087 int row;
00088 int col;
00089 };
00090
00091
00092
00093 enum
00094 {
00095 TIXML_SUCCESS,
00096 TIXML_NO_ATTRIBUTE,
00097 TIXML_WRONG_TYPE
00098 };
00099
00100
00101
00102 enum TiXmlEncoding
00103 {
00104 TIXML_ENCODING_UNKNOWN,
00105 TIXML_ENCODING_UTF8,
00106 TIXML_ENCODING_LEGACY
00107 };
00108
00109 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00110
00133 class TiXmlBase
00134 {
00135 friend class TiXmlNode;
00136 friend class TiXmlElement;
00137 friend class TiXmlDocument;
00138
00139 public:
00140 TiXmlBase() : userData(0) {}
00141 virtual ~TiXmlBase() {}
00142
00148 virtual void Print( FILE* cfile, int depth ) const = 0;
00149
00156 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00157
00159 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00160
00179 int Row() const { return location.row + 1; }
00180 int Column() const { return location.col + 1; }
00181
00182 void SetUserData( void* user ) { userData = user; }
00183 void* GetUserData() { return userData; }
00184
00185
00186
00187 static const int utf8ByteTable[256];
00188
00189 virtual const char* Parse( const char* p,
00190 TiXmlParsingData* data,
00191 TiXmlEncoding encoding ) = 0;
00192
00193 enum
00194 {
00195 TIXML_NO_ERROR = 0,
00196 TIXML_ERROR,
00197 TIXML_ERROR_OPENING_FILE,
00198 TIXML_ERROR_OUT_OF_MEMORY,
00199 TIXML_ERROR_PARSING_ELEMENT,
00200 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00201 TIXML_ERROR_READING_ELEMENT_VALUE,
00202 TIXML_ERROR_READING_ATTRIBUTES,
00203 TIXML_ERROR_PARSING_EMPTY,
00204 TIXML_ERROR_READING_END_TAG,
00205 TIXML_ERROR_PARSING_UNKNOWN,
00206 TIXML_ERROR_PARSING_COMMENT,
00207 TIXML_ERROR_PARSING_DECLARATION,
00208 TIXML_ERROR_DOCUMENT_EMPTY,
00209 TIXML_ERROR_EMBEDDED_NULL,
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 #ifdef TIXML_USE_STL
00235 static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00236 static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00237 #endif
00238
00239
00240
00241
00242
00243 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00244
00245
00246
00247
00248 static const char* ReadText( const char* in,
00249 TIXML_STRING* text,
00250 bool ignoreWhiteSpace,
00251 const char* endTag,
00252 bool ignoreCase,
00253 TiXmlEncoding encoding );
00254
00255
00256 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00257
00258
00259
00260 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00261 {
00262 assert( p );
00263 if ( encoding == TIXML_ENCODING_UTF8 )
00264 {
00265 *length = utf8ByteTable[ *((unsigned char*)p) ];
00266 assert( *length >= 0 && *length < 5 );
00267 }
00268 else
00269 {
00270 *length = 1;
00271 }
00272
00273 if ( *length == 1 )
00274 {
00275 if ( *p == '&' )
00276 return GetEntity( p, _value, length, encoding );
00277 *_value = *p;
00278 return p+1;
00279 }
00280 else if ( *length )
00281 {
00282 strncpy( _value, p, *length );
00283 return p + (*length);
00284 }
00285 else
00286 {
00287
00288 return 0;
00289 }
00290 }
00291
00292
00293
00294 static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00295
00296 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00297
00298
00299
00300
00301 static bool StringEqual( const char* p,
00302 const char* endTag,
00303 bool ignoreCase,
00304 TiXmlEncoding encoding );
00305
00306 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00307
00308 TiXmlCursor location;
00309
00311 void* userData;
00312
00313
00314
00315 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00316 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00317 inline static int ToLower( int v, TiXmlEncoding encoding )
00318 {
00319 if ( encoding == TIXML_ENCODING_UTF8 )
00320 {
00321 if ( v < 128 ) return tolower( v );
00322 return v;
00323 }
00324 else
00325 {
00326 return tolower( v );
00327 }
00328 }
00329 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00330
00331 private:
00332 TiXmlBase( const TiXmlBase& );
00333 void operator=( const TiXmlBase& base );
00334
00335 struct Entity
00336 {
00337 const char* str;
00338 unsigned int strLength;
00339 char chr;
00340 };
00341 enum
00342 {
00343 NUM_ENTITY = 5,
00344 MAX_ENTITY_LENGTH = 6
00345
00346 };
00347 static Entity entity[ NUM_ENTITY ];
00348 static bool condenseWhiteSpace;
00349 };
00350
00351
00358 class TiXmlNode : public TiXmlBase
00359 {
00360 friend class TiXmlDocument;
00361 friend class TiXmlElement;
00362
00363 public:
00364 #ifdef TIXML_USE_STL
00365
00369 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00370
00387 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00388
00390 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00391
00392 #else
00393
00394 friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00395 #endif
00396
00400 enum NodeType
00401 {
00402 DOCUMENT,
00403 ELEMENT,
00404 COMMENT,
00405 UNKNOWN,
00406 TEXT,
00407 DECLARATION,
00408 TYPECOUNT
00409 };
00410
00411 virtual ~TiXmlNode();
00412
00425 const char * Value() const { return value.c_str (); }
00426
00436 void SetValue(const char * _value) { value = _value;}
00437
00438 #ifdef TIXML_USE_STL
00439
00440 void SetValue( const std::string& _value )
00441 {
00442 StringToBuffer buf( _value );
00443 SetValue( buf.buffer ? buf.buffer : "" );
00444 }
00445 #endif
00446
00448 void Clear();
00449
00451 TiXmlNode* Parent() { return parent; }
00452 const TiXmlNode* Parent() const { return parent; }
00453
00454 const TiXmlNode* FirstChild() const { return firstChild; }
00455 TiXmlNode* FirstChild() { return firstChild; }
00456 const TiXmlNode* FirstChild( const char * value ) const;
00457 TiXmlNode* FirstChild( const char * value );
00458
00459 const TiXmlNode* LastChild() const { return lastChild; }
00460 TiXmlNode* LastChild() { return lastChild; }
00461 const TiXmlNode* LastChild( const char * value ) const;
00462 TiXmlNode* LastChild( const char * value );
00463
00464 #ifdef TIXML_USE_STL
00465 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00466 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00467 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00468 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00469 #endif
00470
00487 const TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
00488 TiXmlNode* IterateChildren( TiXmlNode* previous );
00489
00491 const TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
00492 TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous );
00493
00494 #ifdef TIXML_USE_STL
00495 const TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00496 TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
00497 #endif
00498
00502 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00503
00504
00514 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00515
00519 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00520
00524 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00525
00529 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00530
00532 bool RemoveChild( TiXmlNode* removeThis );
00533
00535 const TiXmlNode* PreviousSibling() const { return prev; }
00536 TiXmlNode* PreviousSibling() { return prev; }
00537
00539 const TiXmlNode* PreviousSibling( const char * ) const;
00540 TiXmlNode* PreviousSibling( const char * );
00541
00542 #ifdef TIXML_USE_STL
00543 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00544 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00545 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00546 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00547 #endif
00548
00550 const TiXmlNode* NextSibling() const { return next; }
00551 TiXmlNode* NextSibling() { return next; }
00552
00554 const TiXmlNode* NextSibling( const char * ) const;
00555 TiXmlNode* NextSibling( const char * );
00556
00561 const TiXmlElement* NextSiblingElement() const;
00562 TiXmlElement* NextSiblingElement();
00563
00568 const TiXmlElement* NextSiblingElement( const char * ) const;
00569 TiXmlElement* NextSiblingElement( const char * );
00570
00571 #ifdef TIXML_USE_STL
00572 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00573 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
00574 #endif
00575
00577 const TiXmlElement* FirstChildElement() const;
00578 TiXmlElement* FirstChildElement();
00579
00581 const TiXmlElement* FirstChildElement( const char * value ) const;
00582 TiXmlElement* FirstChildElement( const char * value );
00583
00584 #ifdef TIXML_USE_STL
00585 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00586 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
00587 #endif
00588
00593 virtual int Type() const { return type; }
00594
00598 const TiXmlDocument* GetDocument() const;
00599 TiXmlDocument* GetDocument();
00600
00602 bool NoChildren() const { return !firstChild; }
00603
00604 const TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (const TiXmlDocument*) this : 0; }
00605 const TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (const TiXmlElement*) this : 0; }
00606 const TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (const TiXmlComment*) this : 0; }
00607 const TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (const TiXmlUnknown*) this : 0; }
00608 const TiXmlText* ToText() const { return ( this && type == TEXT ) ? (const TiXmlText*) this : 0; }
00609 const TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (const TiXmlDeclaration*) this : 0; }
00610
00611 TiXmlDocument* ToDocument() { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
00612 TiXmlElement* ToElement() { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
00613 TiXmlComment* ToComment() { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
00614 TiXmlUnknown* ToUnknown() { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
00615 TiXmlText* ToText() { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
00616 TiXmlDeclaration* ToDeclaration() { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
00617
00621 virtual TiXmlNode* Clone() const = 0;
00622
00623 protected:
00624 TiXmlNode( NodeType _type );
00625
00626
00627
00628 void CopyTo( TiXmlNode* target ) const;
00629
00630 #ifdef TIXML_USE_STL
00631
00632 virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00633 #endif
00634
00635
00636 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00637
00638
00639 const TIXML_STRING& SValue() const { return value ; }
00640
00641 TiXmlNode* parent;
00642 NodeType type;
00643
00644 TiXmlNode* firstChild;
00645 TiXmlNode* lastChild;
00646
00647 TIXML_STRING value;
00648
00649 TiXmlNode* prev;
00650 TiXmlNode* next;
00651
00652 private:
00653 TiXmlNode( const TiXmlNode& );
00654 void operator=( const TiXmlNode& base );
00655 };
00656
00657
00665 class TiXmlAttribute : public TiXmlBase
00666 {
00667 friend class TiXmlAttributeSet;
00668
00669 public:
00671 TiXmlAttribute() : TiXmlBase()
00672 {
00673 document = 0;
00674 prev = next = 0;
00675 }
00676
00677 #ifdef TIXML_USE_STL
00678
00679 TiXmlAttribute( const std::string& _name, const std::string& _value )
00680 {
00681 name = _name;
00682 value = _value;
00683 document = 0;
00684 prev = next = 0;
00685 }
00686 #endif
00687
00689 TiXmlAttribute( const char * _name, const char * _value )
00690 {
00691 name = _name;
00692 value = _value;
00693 document = 0;
00694 prev = next = 0;
00695 }
00696
00697 const char* Name() const { return name.c_str (); }
00698 const char* Value() const { return value.c_str (); }
00699 const int IntValue() const;
00700 const double DoubleValue() const;
00701
00711 int QueryIntValue( int* value ) const;
00713 int QueryDoubleValue( double* value ) const;
00714
00715 void SetName( const char* _name ) { name = _name; }
00716 void SetValue( const char* _value ) { value = _value; }
00717
00718 void SetIntValue( int value );
00719 void SetDoubleValue( double value );
00720
00721 #ifdef TIXML_USE_STL
00722
00723 void SetName( const std::string& _name )
00724 {
00725 StringToBuffer buf( _name );
00726 SetName ( buf.buffer ? buf.buffer : "error" );
00727 }
00729 void SetValue( const std::string& _value )
00730 {
00731 StringToBuffer buf( _value );
00732 SetValue( buf.buffer ? buf.buffer : "error" );
00733 }
00734 #endif
00735
00737 const TiXmlAttribute* Next() const;
00738 TiXmlAttribute* Next();
00740 const TiXmlAttribute* Previous() const;
00741 TiXmlAttribute* Previous();
00742
00743 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00744 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00745 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00746
00747
00748
00749
00750 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00751
00752
00753 virtual void Print( FILE* cfile, int depth ) const;
00754
00755 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00756
00757
00758 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00759
00760 private:
00761 TiXmlAttribute( const TiXmlAttribute& );
00762 void operator=( const TiXmlAttribute& base );
00763
00764 TiXmlDocument* document;
00765 TIXML_STRING name;
00766 TIXML_STRING value;
00767 TiXmlAttribute* prev;
00768 TiXmlAttribute* next;
00769 };
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784 class TiXmlAttributeSet
00785 {
00786 public:
00787 TiXmlAttributeSet();
00788 ~TiXmlAttributeSet();
00789
00790 void Add( TiXmlAttribute* attribute );
00791 void Remove( TiXmlAttribute* attribute );
00792
00793 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00794 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00795 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00796 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00797
00798 const TiXmlAttribute* Find( const char * name ) const;
00799 TiXmlAttribute* Find( const char * name );
00800
00801 private:
00802
00803
00804 TiXmlAttributeSet( const TiXmlAttributeSet& );
00805 void operator=( const TiXmlAttributeSet& );
00806
00807 TiXmlAttribute sentinel;
00808 };
00809
00810
00815 class TiXmlElement : public TiXmlNode
00816 {
00817 public:
00819 TiXmlElement (const char * in_value);
00820
00821 #ifdef TIXML_USE_STL
00822
00823 TiXmlElement( const std::string& _value );
00824 #endif
00825
00826 TiXmlElement( const TiXmlElement& );
00827
00828 void operator=( const TiXmlElement& base );
00829
00830 virtual ~TiXmlElement();
00831
00835 const char* Attribute( const char* name ) const;
00836
00843 const char* Attribute( const char* name, int* i ) const;
00844
00851 const char* Attribute( const char* name, double* d ) const;
00852
00860 int QueryIntAttribute( const char* name, int* value ) const;
00862 int QueryDoubleAttribute( const char* name, double* value ) const;
00864 int QueryDoubleAttribute( const char* name, float* value ) const {
00865 double d;
00866 int result = QueryDoubleAttribute( name, &d );
00867 *value = (float)d;
00868 return result;
00869 }
00870
00874 void SetAttribute( const char* name, const char * value );
00875
00876 #ifdef TIXML_USE_STL
00877 const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
00878 const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
00879 const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); }
00880 int QueryIntAttribute( const std::string& name, int* value ) const { return QueryIntAttribute( name.c_str(), value ); }
00881 int QueryDoubleAttribute( const std::string& name, double* value ) const { return QueryDoubleAttribute( name.c_str(), value ); }
00882
00884 void SetAttribute( const std::string& name, const std::string& _value )
00885 {
00886 StringToBuffer n( name );
00887 StringToBuffer v( _value );
00888 if ( n.buffer && v.buffer )
00889 SetAttribute (n.buffer, v.buffer );
00890 }
00892 void SetAttribute( const std::string& name, int _value )
00893 {
00894 StringToBuffer n( name );
00895 if ( n.buffer )
00896 SetAttribute (n.buffer, _value);
00897 }
00898 #endif
00899
00903 void SetAttribute( const char * name, int value );
00904
00908 void SetDoubleAttribute( const char * name, double value );
00909
00912 void RemoveAttribute( const char * name );
00913 #ifdef TIXML_USE_STL
00914 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
00915 #endif
00916
00917 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
00918 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
00919 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
00920 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
00921
00923 virtual TiXmlNode* Clone() const;
00924
00925 virtual void Print( FILE* cfile, int depth ) const;
00926
00927
00928
00929
00930 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00931
00932 protected:
00933
00934 void CopyTo( TiXmlElement* target ) const;
00935 void ClearThis();
00936
00937
00938 #ifdef TIXML_USE_STL
00939 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00940 #endif
00941 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00942
00943
00944
00945
00946
00947 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
00948
00949 private:
00950
00951 TiXmlAttributeSet attributeSet;
00952 };
00953
00954
00957 class TiXmlComment : public TiXmlNode
00958 {
00959 public:
00961 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
00962 TiXmlComment( const TiXmlComment& );
00963 void operator=( const TiXmlComment& base );
00964
00965 virtual ~TiXmlComment() {}
00966
00968 virtual TiXmlNode* Clone() const;
00970 virtual void Print( FILE* cfile, int depth ) const;
00971
00972
00973
00974
00975 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00976
00977 protected:
00978 void CopyTo( TiXmlComment* target ) const;
00979
00980
00981 #ifdef TIXML_USE_STL
00982 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00983 #endif
00984 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00985
00986 private:
00987
00988 };
00989
00990
00993 class TiXmlText : public TiXmlNode
00994 {
00995 friend class TiXmlElement;
00996 public:
00998 TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
00999 {
01000 SetValue( initValue );
01001 }
01002 virtual ~TiXmlText() {}
01003
01004 #ifdef TIXML_USE_STL
01005
01006 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01007 {
01008 SetValue( initValue );
01009 }
01010 #endif
01011
01012 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01013 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01014
01016 virtual void Print( FILE* cfile, int depth ) const;
01017
01018 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01019
01020 protected :
01022 virtual TiXmlNode* Clone() const;
01023 void CopyTo( TiXmlText* target ) const;
01024
01025 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01026 bool Blank() const;
01027
01028 #ifdef TIXML_USE_STL
01029 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01030 #endif
01031
01032 private:
01033 };
01034
01035
01049 class TiXmlDeclaration : public TiXmlNode
01050 {
01051 public:
01053 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01054
01055 #ifdef TIXML_USE_STL
01056
01057 TiXmlDeclaration( const std::string& _version,
01058 const std::string& _encoding,
01059 const std::string& _standalone );
01060 #endif
01061
01063 TiXmlDeclaration( const char* _version,
01064 const char* _encoding,
01065 const char* _standalone );
01066
01067 TiXmlDeclaration( const TiXmlDeclaration& copy );
01068 void operator=( const TiXmlDeclaration& copy );
01069
01070 virtual ~TiXmlDeclaration() {}
01071
01073 const char *Version() const { return version.c_str (); }
01075 const char *Encoding() const { return encoding.c_str (); }
01077 const char *Standalone() const { return standalone.c_str (); }
01078
01080 virtual TiXmlNode* Clone() const;
01082 virtual void Print( FILE* cfile, int depth ) const;
01083
01084 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01085
01086 protected:
01087 void CopyTo( TiXmlDeclaration* target ) const;
01088
01089 #ifdef TIXML_USE_STL
01090 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01091 #endif
01092 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01093
01094 private:
01095
01096 TIXML_STRING version;
01097 TIXML_STRING encoding;
01098 TIXML_STRING standalone;
01099 };
01100
01101
01109 class TiXmlUnknown : public TiXmlNode
01110 {
01111 public:
01112 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01113 virtual ~TiXmlUnknown() {}
01114
01115 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01116 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01117
01119 virtual TiXmlNode* Clone() const;
01121 virtual void Print( FILE* cfile, int depth ) const;
01122
01123 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01124
01125 protected:
01126 void CopyTo( TiXmlUnknown* target ) const;
01127
01128 #ifdef TIXML_USE_STL
01129 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01130 #endif
01131 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01132
01133 private:
01134
01135 };
01136
01137
01142 class TiXmlDocument : public TiXmlNode
01143 {
01144 public:
01146 TiXmlDocument();
01148 TiXmlDocument( const char * documentName );
01149
01150 #ifdef TIXML_USE_STL
01151
01152 TiXmlDocument( const std::string& documentName );
01153 #endif
01154
01155 TiXmlDocument( const TiXmlDocument& copy );
01156 void operator=( const TiXmlDocument& copy );
01157
01158 virtual ~TiXmlDocument() {}
01159
01164 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01166 bool SaveFile() const;
01168 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01170 bool SaveFile( const char * filename ) const;
01171
01172 #ifdef TIXML_USE_STL
01173 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01174 {
01175 StringToBuffer f( filename );
01176 return ( f.buffer && LoadFile( f.buffer, encoding ));
01177 }
01178 bool SaveFile( const std::string& filename ) const
01179 {
01180 StringToBuffer f( filename );
01181 return ( f.buffer && SaveFile( f.buffer ));
01182 }
01183 #endif
01184
01189 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01190
01195 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01196 TiXmlElement* RootElement() { return FirstChildElement(); }
01197
01203 bool Error() const { return error; }
01204
01206 const char * ErrorDesc() const { return errorDesc.c_str (); }
01207
01211 const int ErrorId() const { return errorId; }
01212
01220 int ErrorRow() { return errorLocation.row+1; }
01221 int ErrorCol() { return errorLocation.col+1; }
01222
01243 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01244
01245 int TabSize() const { return tabsize; }
01246
01250 void ClearError() { error = false;
01251 errorId = 0;
01252 errorDesc = "";
01253 errorLocation.row = errorLocation.col = 0;
01254
01255 }
01256
01258 void Print() const { Print( stdout, 0 ); }
01259
01261 virtual void Print( FILE* cfile, int depth = 0 ) const;
01262
01263 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01264
01265 protected :
01266 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01267
01268 virtual TiXmlNode* Clone() const;
01269 #ifdef TIXML_USE_STL
01270 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01271 #endif
01272
01273 private:
01274 void CopyTo( TiXmlDocument* target ) const;
01275
01276 bool error;
01277 int errorId;
01278 TIXML_STRING errorDesc;
01279 int tabsize;
01280 TiXmlCursor errorLocation;
01281 };
01282
01283
01364 class TiXmlHandle
01365 {
01366 public:
01368 TiXmlHandle( TiXmlNode* node ) { this->node = node; }
01370 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01371 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01372
01374 TiXmlHandle FirstChild() const;
01376 TiXmlHandle FirstChild( const char * value ) const;
01378 TiXmlHandle FirstChildElement() const;
01380 TiXmlHandle FirstChildElement( const char * value ) const;
01381
01385 TiXmlHandle Child( const char* value, int index ) const;
01389 TiXmlHandle Child( int index ) const;
01394 TiXmlHandle ChildElement( const char* value, int index ) const;
01399 TiXmlHandle ChildElement( int index ) const;
01400
01401 #ifdef TIXML_USE_STL
01402 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01403 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01404
01405 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01406 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01407 #endif
01408
01410 TiXmlNode* Node() const { return node; }
01412 TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01414 TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01416 TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01417
01418 private:
01419 TiXmlNode* node;
01420 };
01421
01422
01423 #endif
01424