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( push )
00031 #pragma warning( disable : 4530 )
00032 #pragma warning( disable : 4786 )
00033 #endif
00034
00035 #include <ctype.h>
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039 #include <assert.h>
00040
00041
00042 #if defined( _DEBUG ) && !defined( DEBUG )
00043 #define DEBUG
00044 #endif
00045
00046 #ifdef TIXML_USE_TICPP
00047 #ifndef TIXML_USE_STL
00048 #define TIXML_USE_STL
00049 #endif
00050 #endif
00051
00052 #ifdef TIXML_USE_STL
00053 #include <string>
00054 #include <iostream>
00055 #include <sstream>
00056 #define TIXML_STRING std::string
00057 #else
00058 #include "tinystr.h"
00059 #define TIXML_STRING TiXmlString
00060 #endif
00061
00062
00063
00064
00065
00066 #define TIXML_SAFE
00067
00068 #ifdef TIXML_SAFE
00069 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
00070
00071 #define TIXML_SNPRINTF _snprintf_s
00072 #define TIXML_SNSCANF _snscanf_s
00073 #define TIXML_SSCANF sscanf_s
00074 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
00075
00076
00077 #define TIXML_SNPRINTF _snprintf
00078 #define TIXML_SNSCANF _snscanf
00079 #define TIXML_SSCANF sscanf
00080 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00081
00082
00083 #define TIXML_SNPRINTF snprintf
00084 #define TIXML_SNSCANF snscanf
00085 #define TIXML_SSCANF sscanf
00086 #else
00087 #define TIXML_SSCANF sscanf
00088 #endif
00089 #endif
00090
00091 class TiXmlDocument;
00092 class TiXmlElement;
00093 class TiXmlComment;
00094 class TiXmlUnknown;
00095 class TiXmlAttribute;
00096 class TiXmlText;
00097 class TiXmlDeclaration;
00098 class TiXmlStylesheetReference;
00099 class TiXmlParsingData;
00100
00101 const int TIXML_MAJOR_VERSION = 2;
00102 const int TIXML_MINOR_VERSION = 5;
00103 const int TIXML_PATCH_VERSION = 3;
00104
00105
00106
00107
00108 struct TiXmlCursor
00109 {
00110 TiXmlCursor() { Clear(); }
00111 void Clear() { row = col = -1; }
00112
00113 int row;
00114 int col;
00115 };
00116
00117
00136 class TiXmlVisitor
00137 {
00138 public:
00139 virtual ~TiXmlVisitor() {}
00140
00142 virtual bool VisitEnter( const TiXmlDocument& ) { return true; }
00144 virtual bool VisitExit( const TiXmlDocument& ) { return true; }
00145
00147 virtual bool VisitEnter( const TiXmlElement& , const TiXmlAttribute* ) { return true; }
00149 virtual bool VisitExit( const TiXmlElement& ) { return true; }
00150
00152 virtual bool Visit( const TiXmlDeclaration& ) { return true; }
00154 virtual bool Visit( const TiXmlStylesheetReference& ) { return true; }
00156 virtual bool Visit( const TiXmlText& ) { return true; }
00158 virtual bool Visit( const TiXmlComment& ) { return true; }
00160 virtual bool Visit( const TiXmlUnknown& ) { return true; }
00161 };
00162
00163
00164 enum
00165 {
00166 TIXML_SUCCESS,
00167 TIXML_NO_ATTRIBUTE,
00168 TIXML_WRONG_TYPE
00169 };
00170
00171
00172
00173 enum TiXmlEncoding
00174 {
00175 TIXML_ENCODING_UNKNOWN,
00176 TIXML_ENCODING_UTF8,
00177 TIXML_ENCODING_LEGACY
00178 };
00179
00180 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00181
00204 #ifdef TIXML_USE_TICPP
00205 #include "ticpprc.h"
00206 class TiXmlBase : public TiCppRC
00207 #else
00208 class TiXmlBase
00209 #endif
00210 {
00211 friend class TiXmlNode;
00212 friend class TiXmlElement;
00213 friend class TiXmlDocument;
00214
00215 public:
00216 TiXmlBase() : userData(0) {}
00217 virtual ~TiXmlBase() {}
00218
00228 virtual void Print( FILE* cfile, int depth ) const = 0;
00229
00236 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00237
00239 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00240
00259 int Row() const { return location.row + 1; }
00260 int Column() const { return location.col + 1; }
00261
00262 void SetUserData( void* user ) { userData = user; }
00263 void* GetUserData() { return userData; }
00264 const void* GetUserData() const { return userData; }
00265
00266
00267
00268 static const int utf8ByteTable[256];
00269
00270 virtual const char* Parse( const char* p,
00271 TiXmlParsingData* data,
00272 TiXmlEncoding encoding ) = 0;
00273
00277 static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
00278
00279 enum
00280 {
00281 TIXML_NO_ERROR = 0,
00282 TIXML_ERROR,
00283 TIXML_ERROR_OPENING_FILE,
00284 TIXML_ERROR_OUT_OF_MEMORY,
00285 TIXML_ERROR_PARSING_ELEMENT,
00286 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00287 TIXML_ERROR_READING_ELEMENT_VALUE,
00288 TIXML_ERROR_READING_ATTRIBUTES,
00289 TIXML_ERROR_PARSING_EMPTY,
00290 TIXML_ERROR_READING_END_TAG,
00291 TIXML_ERROR_PARSING_UNKNOWN,
00292 TIXML_ERROR_PARSING_COMMENT,
00293 TIXML_ERROR_PARSING_DECLARATION,
00294 TIXML_ERROR_DOCUMENT_EMPTY,
00295 TIXML_ERROR_EMBEDDED_NULL,
00296 TIXML_ERROR_PARSING_CDATA,
00297 TIXML_ERROR_DOCUMENT_TOP_ONLY,
00298
00299 TIXML_ERROR_STRING_COUNT
00300 };
00301
00302 protected:
00303
00304 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00305 inline static bool IsWhiteSpace( char c )
00306 {
00307 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00308 }
00309 inline static bool IsWhiteSpace( int c )
00310 {
00311 if ( c < 256 )
00312 return IsWhiteSpace( (char) c );
00313 return false;
00314 }
00315
00316 #ifdef TIXML_USE_STL
00317 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
00318 static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
00319 #endif
00320
00321
00322
00323
00324
00325 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00326
00327
00328
00329
00330 static const char* ReadText( const char* in,
00331 TIXML_STRING* text,
00332 bool ignoreWhiteSpace,
00333 const char* endTag,
00334 bool ignoreCase,
00335 TiXmlEncoding encoding );
00336
00337
00338 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00339
00340
00341
00342 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00343 {
00344 assert( p );
00345 if ( encoding == TIXML_ENCODING_UTF8 )
00346 {
00347 *length = utf8ByteTable[ *((const unsigned char*)p) ];
00348 assert( *length >= 0 && *length < 5 );
00349 }
00350 else
00351 {
00352 *length = 1;
00353 }
00354
00355 if ( *length == 1 )
00356 {
00357 if ( *p == '&' )
00358 return GetEntity( p, _value, length, encoding );
00359 *_value = *p;
00360 return p+1;
00361 }
00362 else if ( *length )
00363 {
00364
00365
00366 for( int i=0; p[i] && i<*length; ++i ) {
00367 _value[i] = p[i];
00368 }
00369 return p + (*length);
00370 }
00371 else
00372 {
00373
00374 return 0;
00375 }
00376 }
00377
00378
00379
00380
00381 static bool StringEqual( const char* p,
00382 const char* endTag,
00383 bool ignoreCase,
00384 TiXmlEncoding encoding );
00385
00386 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00387
00388 TiXmlCursor location;
00389
00391 void* userData;
00392
00393
00394
00395 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00396 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00397 inline static int ToLower( int v, TiXmlEncoding encoding )
00398 {
00399 if ( encoding == TIXML_ENCODING_UTF8 )
00400 {
00401 if ( v < 128 ) return tolower( v );
00402 return v;
00403 }
00404 else
00405 {
00406 return tolower( v );
00407 }
00408 }
00409 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00410
00411 private:
00412 TiXmlBase( const TiXmlBase& );
00413 void operator=( const TiXmlBase& base );
00414
00415 struct Entity
00416 {
00417 const char* str;
00418 unsigned int strLength;
00419 char chr;
00420 };
00421 enum
00422 {
00423 NUM_ENTITY = 5,
00424 MAX_ENTITY_LENGTH = 6
00425
00426 };
00427 static Entity entity[ NUM_ENTITY ];
00428 static bool condenseWhiteSpace;
00429 };
00430
00431
00438 class TiXmlNode : public TiXmlBase
00439 {
00440 friend class TiXmlDocument;
00441 friend class TiXmlElement;
00442
00443 public:
00444 #ifdef TIXML_USE_STL
00445
00449 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00450
00467 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00468
00470 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00471
00472 #endif
00473
00477 enum NodeType
00478 {
00479 DOCUMENT,
00480 ELEMENT,
00481 COMMENT,
00482 UNKNOWN,
00483 TEXT,
00484 DECLARATION,
00485 STYLESHEETREFERENCE,
00486 TYPECOUNT
00487 };
00488
00489 virtual ~TiXmlNode();
00490
00503 const char *Value() const { return value.c_str (); }
00504
00505 #ifdef TIXML_USE_STL
00506
00510 const std::string& ValueStr() const { return value; }
00511 #endif
00512
00513 const TIXML_STRING& ValueTStr() const { return value; }
00514
00524 void SetValue(const char * _value) { value = _value;}
00525
00526 #ifdef TIXML_USE_STL
00528 void SetValue( const std::string& _value ) { value = _value; }
00529 #endif
00530
00532 void Clear();
00533
00535 TiXmlNode* Parent() { return parent; }
00536 const TiXmlNode* Parent() const { return parent; }
00537
00538 const TiXmlNode* FirstChild() const { return firstChild; }
00539 TiXmlNode* FirstChild() { return firstChild; }
00540 const TiXmlNode* FirstChild( const char * value ) const;
00541
00542 TiXmlNode* FirstChild( const char * _value ) {
00543
00544
00545 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00546 }
00547 const TiXmlNode* LastChild() const { return lastChild; }
00548 TiXmlNode* LastChild() { return lastChild; }
00549
00550 const TiXmlNode* LastChild( const char * value ) const;
00551 TiXmlNode* LastChild( const char * _value ) {
00552 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00553 }
00554
00555 #ifdef TIXML_USE_STL
00556 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00557 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00558 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00559 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00560 #endif
00561
00578 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00579 TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
00580 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00581 }
00582
00584 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00585 TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
00586 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00587 }
00588
00589 #ifdef TIXML_USE_STL
00590 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00591 TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
00592 #endif
00593
00597 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00598
00599
00609 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00610
00614 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00615
00619 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00620
00624 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00625
00627 bool RemoveChild( TiXmlNode* removeThis );
00628
00630 const TiXmlNode* PreviousSibling() const { return prev; }
00631 TiXmlNode* PreviousSibling() { return prev; }
00632
00634 const TiXmlNode* PreviousSibling( const char * ) const;
00635 TiXmlNode* PreviousSibling( const char *_prev ) {
00636 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00637 }
00638
00639 #ifdef TIXML_USE_STL
00640 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00641 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00642 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00643 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00644 #endif
00645
00647 const TiXmlNode* NextSibling() const { return next; }
00648 TiXmlNode* NextSibling() { return next; }
00649
00651 const TiXmlNode* NextSibling( const char * ) const;
00652 TiXmlNode* NextSibling( const char* _next ) {
00653 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
00654 }
00655
00660 const TiXmlElement* NextSiblingElement() const;
00661 TiXmlElement* NextSiblingElement() {
00662 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
00663 }
00664
00669 const TiXmlElement* NextSiblingElement( const char * ) const;
00670 TiXmlElement* NextSiblingElement( const char *_next ) {
00671 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00672 }
00673
00674 #ifdef TIXML_USE_STL
00675 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00676 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
00677 #endif
00678
00680 const TiXmlElement* FirstChildElement() const;
00681 TiXmlElement* FirstChildElement() {
00682 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00683 }
00684
00686 const TiXmlElement* FirstChildElement( const char * _value ) const;
00687 TiXmlElement* FirstChildElement( const char * _value ) {
00688 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00689 }
00690
00691 #ifdef TIXML_USE_STL
00692 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00693 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
00694 #endif
00695
00700 int Type() const { return type; }
00701
00705 const TiXmlDocument* GetDocument() const;
00706 TiXmlDocument* GetDocument() {
00707 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00708 }
00709
00711 bool NoChildren() const { return !firstChild; }
00712
00713 virtual const TiXmlDocument* ToDocument() const { return 0; }
00714 virtual const TiXmlElement* ToElement() const { return 0; }
00715 virtual const TiXmlComment* ToComment() const { return 0; }
00716 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
00717 virtual const TiXmlText* ToText() const { return 0; }
00718 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
00719 virtual const TiXmlStylesheetReference* ToStylesheetReference() const { return 0; }
00720
00721 virtual TiXmlDocument* ToDocument() { return 0; }
00722 virtual TiXmlElement* ToElement() { return 0; }
00723 virtual TiXmlComment* ToComment() { return 0; }
00724 virtual TiXmlUnknown* ToUnknown() { return 0; }
00725 virtual TiXmlText* ToText() { return 0; }
00726 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
00727 virtual TiXmlStylesheetReference* ToStylesheetReference() { return 0; }
00728
00732 virtual TiXmlNode* Clone() const = 0;
00733
00756 virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
00757
00758 protected:
00759 TiXmlNode( NodeType _type );
00760
00761
00762
00763 void CopyTo( TiXmlNode* target ) const;
00764
00765 #ifdef TIXML_USE_STL
00766
00767 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
00768 #endif
00769
00770
00771 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00772
00773 TiXmlNode* parent;
00774 NodeType type;
00775
00776 TiXmlNode* firstChild;
00777 TiXmlNode* lastChild;
00778
00779 TIXML_STRING value;
00780
00781 TiXmlNode* prev;
00782 TiXmlNode* next;
00783
00784 private:
00785 TiXmlNode( const TiXmlNode& );
00786 void operator=( const TiXmlNode& base );
00787 };
00788
00789
00797 class TiXmlAttribute : public TiXmlBase
00798 {
00799 friend class TiXmlAttributeSet;
00800
00801 public:
00803 TiXmlAttribute() : TiXmlBase()
00804 {
00805 document = 0;
00806 prev = next = 0;
00807 }
00808
00809 #ifdef TIXML_USE_STL
00811 TiXmlAttribute( const std::string& _name, const std::string& _value )
00812 {
00813 name = _name;
00814 value = _value;
00815 document = 0;
00816 prev = next = 0;
00817 }
00818 #endif
00819
00821 TiXmlAttribute( const char * _name, const char * _value )
00822 {
00823 name = _name;
00824 value = _value;
00825 document = 0;
00826 prev = next = 0;
00827 }
00828
00829 const char* Name() const { return name.c_str(); }
00830 const char* Value() const { return value.c_str(); }
00831 #ifdef TIXML_USE_STL
00832 const std::string& ValueStr() const { return value; }
00833 #endif
00834 int IntValue() const;
00835 double DoubleValue() const;
00836
00837
00838 const TIXML_STRING& NameTStr() const { return name; }
00839
00849 int QueryIntValue( int* _value ) const;
00851 int QueryDoubleValue( double* _value ) const;
00852
00853 void SetName( const char* _name ) { name = _name; }
00854 void SetValue( const char* _value ) { value = _value; }
00855
00856 void SetIntValue( int _value );
00857 void SetDoubleValue( double _value );
00858
00859 #ifdef TIXML_USE_STL
00861 void SetName( const std::string& _name ) { name = _name; }
00863 void SetValue( const std::string& _value ) { value = _value; }
00864 #endif
00865
00867 const TiXmlAttribute* Next() const;
00868 TiXmlAttribute* Next() {
00869 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
00870 }
00871
00873 const TiXmlAttribute* Previous() const;
00874 TiXmlAttribute* Previous() {
00875 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
00876 }
00877
00878 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00879 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00880 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00881
00882
00883
00884
00885 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00886
00887
00888 virtual void Print( FILE* cfile, int depth ) const {
00889 Print( cfile, depth, 0 );
00890 }
00891 void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
00892
00893
00894
00895 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00896
00897 private:
00898 TiXmlAttribute( const TiXmlAttribute& );
00899 void operator=( const TiXmlAttribute& base );
00900
00901 TiXmlDocument* document;
00902 TIXML_STRING name;
00903 TIXML_STRING value;
00904 TiXmlAttribute* prev;
00905 TiXmlAttribute* next;
00906 };
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921 class TiXmlAttributeSet
00922 {
00923 public:
00924 TiXmlAttributeSet();
00925 ~TiXmlAttributeSet();
00926
00927 void Add( TiXmlAttribute* attribute );
00928 void Remove( TiXmlAttribute* attribute );
00929
00930 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00931 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00932 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00933 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00934
00935 const TiXmlAttribute* Find( const char* _name ) const;
00936 TiXmlAttribute* Find( const char* _name ) {
00937 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00938 }
00939 #ifdef TIXML_USE_STL
00940 const TiXmlAttribute* Find( const std::string& _name ) const;
00941 TiXmlAttribute* Find( const std::string& _name ) {
00942 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00943 }
00944
00945 #endif
00946
00947 private:
00948
00949
00950 TiXmlAttributeSet( const TiXmlAttributeSet& );
00951 void operator=( const TiXmlAttributeSet& );
00952
00953 TiXmlAttribute sentinel;
00954 };
00955
00956
00961 class TiXmlElement : public TiXmlNode
00962 {
00963 public:
00965 TiXmlElement (const char * in_value);
00966
00967 #ifdef TIXML_USE_STL
00969 TiXmlElement( const std::string& _value );
00970 #endif
00971
00972 TiXmlElement( const TiXmlElement& );
00973
00974 void operator=( const TiXmlElement& base );
00975
00976 virtual ~TiXmlElement();
00977
00981 const char* Attribute( const char* name ) const;
00982
00989 const char* Attribute( const char* name, int* i ) const;
00990
00997 const char* Attribute( const char* name, double* d ) const;
00998
01006 int QueryIntAttribute( const char* name, int* _value ) const;
01008 int QueryDoubleAttribute( const char* name, double* _value ) const;
01010 int QueryFloatAttribute( const char* name, float* _value ) const {
01011 double d;
01012 int result = QueryDoubleAttribute( name, &d );
01013 if ( result == TIXML_SUCCESS ) {
01014 *_value = (float)d;
01015 }
01016 return result;
01017 }
01018
01019 #ifdef TIXML_USE_STL
01020
01028 template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
01029 {
01030 const TiXmlAttribute* node = attributeSet.Find( name );
01031 if ( !node )
01032 return TIXML_NO_ATTRIBUTE;
01033
01034 std::stringstream sstream( node->ValueStr() );
01035 sstream >> *outValue;
01036 if ( !sstream.fail() )
01037 return TIXML_SUCCESS;
01038 return TIXML_WRONG_TYPE;
01039 }
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055 #endif
01056
01060 void SetAttribute( const char* name, const char * _value );
01061
01062 #ifdef TIXML_USE_STL
01063 const std::string* Attribute( const std::string& name ) const;
01064 const std::string* Attribute( const std::string& name, int* i ) const;
01065 const std::string* Attribute( const std::string& name, double* d ) const;
01066 int QueryIntAttribute( const std::string& name, int* _value ) const;
01067 int QueryDoubleAttribute( const std::string& name, double* _value ) const;
01068
01070 void SetAttribute( const std::string& name, const std::string& _value );
01072 void SetAttribute( const std::string& name, int _value );
01073 #endif
01074
01078 void SetAttribute( const char * name, int value );
01079
01083 void SetDoubleAttribute( const char * name, double value );
01084
01087 void RemoveAttribute( const char * name );
01088 #ifdef TIXML_USE_STL
01089 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
01090 #endif
01091
01092 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
01093 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
01094 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
01095 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
01096
01129 const char* GetText() const;
01130
01132 virtual TiXmlNode* Clone() const;
01133
01134 virtual void Print( FILE* cfile, int depth ) const;
01135
01136
01137
01138
01139 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01140
01141 virtual const TiXmlElement* ToElement() const { return this; }
01142 virtual TiXmlElement* ToElement() { return this; }
01143
01146 virtual bool Accept( TiXmlVisitor* visitor ) const;
01147
01148 protected:
01149
01150 void CopyTo( TiXmlElement* target ) const;
01151 void ClearThis();
01152
01153
01154 #ifdef TIXML_USE_STL
01155 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01156 #endif
01157
01158
01159
01160
01161 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01162
01163 private:
01164
01165 TiXmlAttributeSet attributeSet;
01166 };
01167
01168
01171 class TiXmlComment : public TiXmlNode
01172 {
01173 public:
01175 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01177 TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
01178 SetValue( _value );
01179 }
01180 TiXmlComment( const TiXmlComment& );
01181 void operator=( const TiXmlComment& base );
01182
01183 virtual ~TiXmlComment() {}
01184
01186 virtual TiXmlNode* Clone() const;
01187
01188 virtual void Print( FILE* cfile, int depth ) const;
01189
01190
01191
01192
01193 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01194
01195 virtual const TiXmlComment* ToComment() const { return this; }
01196 virtual TiXmlComment* ToComment() { return this; }
01197
01200 virtual bool Accept( TiXmlVisitor* visitor ) const;
01201
01202 protected:
01203 void CopyTo( TiXmlComment* target ) const;
01204
01205
01206 #ifdef TIXML_USE_STL
01207 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01208 #endif
01209
01210
01211 private:
01212
01213 };
01214
01215
01221 class TiXmlText : public TiXmlNode
01222 {
01223 friend class TiXmlElement;
01224 public:
01229 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01230 {
01231 SetValue( initValue );
01232 cdata = false;
01233 }
01234 virtual ~TiXmlText() {}
01235
01236 #ifdef TIXML_USE_STL
01238 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01239 {
01240 SetValue( initValue );
01241 cdata = false;
01242 }
01243 #endif
01244
01245 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01246 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01247
01248
01249 virtual void Print( FILE* cfile, int depth ) const;
01250
01252 bool CDATA() const { return cdata; }
01254 void SetCDATA( bool _cdata ) { cdata = _cdata; }
01255
01256 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01257
01258 virtual const TiXmlText* ToText() const { return this; }
01259 virtual TiXmlText* ToText() { return this; }
01260
01263 virtual bool Accept( TiXmlVisitor* content ) const;
01264
01265 protected :
01267 virtual TiXmlNode* Clone() const;
01268 void CopyTo( TiXmlText* target ) const;
01269
01270 bool Blank() const;
01271
01272 #ifdef TIXML_USE_STL
01273 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01274 #endif
01275
01276 private:
01277 bool cdata;
01278 };
01279
01280
01294 class TiXmlDeclaration : public TiXmlNode
01295 {
01296 public:
01298 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01299
01300 #ifdef TIXML_USE_STL
01302 TiXmlDeclaration( const std::string& _version,
01303 const std::string& _encoding,
01304 const std::string& _standalone );
01305 #endif
01306
01308 TiXmlDeclaration( const char* _version,
01309 const char* _encoding,
01310 const char* _standalone );
01311
01312 TiXmlDeclaration( const TiXmlDeclaration& copy );
01313 void operator=( const TiXmlDeclaration& copy );
01314
01315 virtual ~TiXmlDeclaration() {}
01316
01318 const char *Version() const { return version.c_str (); }
01320 const char *Encoding() const { return encoding.c_str (); }
01322 const char *Standalone() const { return standalone.c_str (); }
01323
01325 virtual TiXmlNode* Clone() const;
01326
01327 virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01328 virtual void Print( FILE* cfile, int depth ) const {
01329 Print( cfile, depth, 0 );
01330 }
01331
01332 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01333
01334 virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
01335 virtual TiXmlDeclaration* ToDeclaration() { return this; }
01336
01339 virtual bool Accept( TiXmlVisitor* visitor ) const;
01340
01341 protected:
01342 void CopyTo( TiXmlDeclaration* target ) const;
01343
01344 #ifdef TIXML_USE_STL
01345 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01346 #endif
01347
01348 private:
01349
01350 TIXML_STRING version;
01351 TIXML_STRING encoding;
01352 TIXML_STRING standalone;
01353 };
01354
01364 class TiXmlStylesheetReference : public TiXmlNode
01365 {
01366 public:
01368 TiXmlStylesheetReference() : TiXmlNode( TiXmlNode::STYLESHEETREFERENCE ) {}
01369
01370 #ifdef TIXML_USE_STL
01372 TiXmlStylesheetReference( const std::string& _type,
01373 const std::string& _href );
01374 #endif
01375
01377 TiXmlStylesheetReference( const char* _type,
01378 const char* _href );
01379
01380 TiXmlStylesheetReference( const TiXmlStylesheetReference& copy );
01381 void operator=( const TiXmlStylesheetReference& copy );
01382
01383 virtual ~TiXmlStylesheetReference() {}
01384
01386 const char *Type() const { return type.c_str (); }
01388 const char *Href() const { return href.c_str (); }
01389
01391 virtual TiXmlNode* Clone() const;
01392
01393 virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01394 virtual void Print( FILE* cfile, int depth ) const {
01395 Print( cfile, depth, 0 );
01396 }
01397
01398 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01399
01400 virtual const TiXmlStylesheetReference* ToStylesheetReference() const { return this; }
01401 virtual TiXmlStylesheetReference* ToStylesheetReference() { return this; }
01402
01405 virtual bool Accept( TiXmlVisitor* visitor ) const;
01406
01407 protected:
01408 void CopyTo( TiXmlStylesheetReference* target ) const;
01409
01410 #ifdef TIXML_USE_STL
01411 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01412 #endif
01413
01414 private:
01415
01416 TIXML_STRING type;
01417 TIXML_STRING href;
01418 };
01419
01427 class TiXmlUnknown : public TiXmlNode
01428 {
01429 public:
01430 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01431 virtual ~TiXmlUnknown() {}
01432
01433 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01434 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01435
01437 virtual TiXmlNode* Clone() const;
01438
01439 virtual void Print( FILE* cfile, int depth ) const;
01440
01441 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01442
01443 virtual const TiXmlUnknown* ToUnknown() const { return this; }
01444 virtual TiXmlUnknown* ToUnknown() { return this; }
01445
01448 virtual bool Accept( TiXmlVisitor* content ) const;
01449
01450 protected:
01451 void CopyTo( TiXmlUnknown* target ) const;
01452
01453 #ifdef TIXML_USE_STL
01454 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01455 #endif
01456
01457 private:
01458
01459 };
01460
01461
01466 class TiXmlDocument : public TiXmlNode
01467 {
01468 public:
01470 TiXmlDocument();
01472 TiXmlDocument( const char * documentName );
01473
01474 #ifdef TIXML_USE_STL
01476 TiXmlDocument( const std::string& documentName );
01477 #endif
01478
01479 TiXmlDocument( const TiXmlDocument& copy );
01480 void operator=( const TiXmlDocument& copy );
01481
01482 virtual ~TiXmlDocument() {}
01483
01488 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01490 bool SaveFile() const;
01492 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01494 bool SaveFile( const char * filename ) const;
01500 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01502 bool SaveFile( FILE* ) const;
01503
01504 #ifdef TIXML_USE_STL
01505 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01506 {
01507
01508
01509 return LoadFile( filename.c_str(), encoding );
01510 }
01511 bool SaveFile( const std::string& filename ) const
01512 {
01513
01514
01515 return SaveFile( filename.c_str() );
01516 }
01517 #endif
01518
01523 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01524
01529 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01530 TiXmlElement* RootElement() { return FirstChildElement(); }
01531
01537 bool Error() const { return error; }
01538
01540 const char * ErrorDesc() const { return errorDesc.c_str (); }
01541
01545 int ErrorId() const { return errorId; }
01546
01554 int ErrorRow() const { return errorLocation.row+1; }
01555 int ErrorCol() const { return errorLocation.col+1; }
01556
01581 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01582
01583 int TabSize() const { return tabsize; }
01584
01588 void ClearError() { error = false;
01589 errorId = 0;
01590 errorDesc = "";
01591 errorLocation.row = errorLocation.col = 0;
01592
01593 }
01594
01596 void Print() const { Print( stdout, 0 ); }
01597
01598
01599
01600
01601
01602
01603
01605 virtual void Print( FILE* cfile, int depth = 0 ) const;
01606
01607 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01608
01609 virtual const TiXmlDocument* ToDocument() const { return this; }
01610 virtual TiXmlDocument* ToDocument() { return this; }
01611
01614 virtual bool Accept( TiXmlVisitor* content ) const;
01615
01616 protected :
01617
01618 virtual TiXmlNode* Clone() const;
01619 #ifdef TIXML_USE_STL
01620 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01621 #endif
01622
01623 private:
01624 void CopyTo( TiXmlDocument* target ) const;
01625
01626 bool error;
01627 int errorId;
01628 TIXML_STRING errorDesc;
01629 int tabsize;
01630 TiXmlCursor errorLocation;
01631 bool useMicrosoftBOM;
01632 };
01633
01634
01715 class TiXmlHandle
01716 {
01717 public:
01719 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01721 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01722 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01723
01725 TiXmlHandle FirstChild() const;
01727 TiXmlHandle FirstChild( const char * value ) const;
01729 TiXmlHandle FirstChildElement() const;
01731 TiXmlHandle FirstChildElement( const char * value ) const;
01732
01736 TiXmlHandle Child( const char* value, int index ) const;
01740 TiXmlHandle Child( int index ) const;
01745 TiXmlHandle ChildElement( const char* value, int index ) const;
01750 TiXmlHandle ChildElement( int index ) const;
01751
01752 #ifdef TIXML_USE_STL
01753 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01754 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01755
01756 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01757 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01758 #endif
01759
01762 TiXmlNode* ToNode() const { return node; }
01765 TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01768 TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01771 TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01772
01776 TiXmlNode* Node() const { return ToNode(); }
01780 TiXmlElement* Element() const { return ToElement(); }
01784 TiXmlText* Text() const { return ToText(); }
01788 TiXmlUnknown* Unknown() const { return ToUnknown(); }
01789
01790 private:
01791 TiXmlNode* node;
01792 };
01793
01794
01814 class TiXmlPrinter : public TiXmlVisitor
01815 {
01816 public:
01817 TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
01818 buffer(), indent( " " ), lineBreak( "\n" ) {}
01819
01820 virtual bool VisitEnter( const TiXmlDocument& doc );
01821 virtual bool VisitExit( const TiXmlDocument& doc );
01822
01823 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
01824 virtual bool VisitExit( const TiXmlElement& element );
01825
01826 virtual bool Visit( const TiXmlDeclaration& declaration );
01827 virtual bool Visit( const TiXmlText& text );
01828 virtual bool Visit( const TiXmlComment& comment );
01829 virtual bool Visit( const TiXmlUnknown& unknown );
01830
01834 void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
01836 const char* Indent() { return indent.c_str(); }
01841 void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
01843 const char* LineBreak() { return lineBreak.c_str(); }
01844
01848 void SetStreamPrinting() { indent = "";
01849 lineBreak = "";
01850 }
01852 const char* CStr() { return buffer.c_str(); }
01854 size_t Size() { return buffer.size(); }
01855
01856 #ifdef TIXML_USE_STL
01858 const std::string& Str() { return buffer; }
01859 #endif
01860
01861 private:
01862 void DoIndent() {
01863 for( int i=0; i<depth; ++i )
01864 buffer += indent;
01865 }
01866 void DoLineBreak() {
01867 buffer += lineBreak;
01868 }
01869
01870 int depth;
01871 bool simpleTextPrint;
01872 TIXML_STRING buffer;
01873 TIXML_STRING indent;
01874 TIXML_STRING lineBreak;
01875 };
01876
01877
01878 #ifdef _MSC_VER
01879 #pragma warning( pop )
01880 #endif
01881
01882 #endif
01883