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 OBTTINYXML_H
00027 #define OBTTINYXML_H
00028
00029 #ifndef TIXML_USE_STL
00030 #define TIXML_USE_STL
00031 #endif
00032
00033 #ifdef _MSC_VER
00034 #pragma warning( push )
00035 #pragma warning( disable : 4530 )
00036 #pragma warning( disable : 4786 )
00037 #endif
00038
00039 #include <ctype.h>
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <string.h>
00043 #include <assert.h>
00044
00045
00046 #if defined( _DEBUG ) && !defined( DEBUG )
00047 #define DEBUG
00048 #endif
00049
00050 #ifdef TIXML_USE_STL
00051 #include <string>
00052 #include <iostream>
00053 #include <sstream>
00054 #define TIXML_STRING std::string
00055 #else
00056 #error "TIXML_USE_STL must be defined"
00057
00058 #define TIXML_STRING TiXmlString
00059 #endif
00060
00061
00062
00063
00064
00065 #define TIXML_SAFE
00066
00067 #ifdef TIXML_SAFE
00068 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
00069
00070 #define TIXML_SNPRINTF _snprintf_s
00071 #define TIXML_SNSCANF _snscanf_s
00072 #define TIXML_SSCANF sscanf_s
00073 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
00074
00075
00076 #define TIXML_SNPRINTF _snprintf
00077 #define TIXML_SNSCANF _snscanf
00078 #define TIXML_SSCANF sscanf
00079 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00080
00081
00082 #define TIXML_SNPRINTF snprintf
00083 #define TIXML_SNSCANF snscanf
00084 #define TIXML_SSCANF sscanf
00085 #else
00086 #define TIXML_SSCANF sscanf
00087 #endif
00088 #endif
00089
00090 namespace OBT
00091 {
00092 class TiXmlDocument;
00093 class TiXmlElement;
00094 class TiXmlComment;
00095 class TiXmlUnknown;
00096 class TiXmlAttribute;
00097 class TiXmlText;
00098 class TiXmlDeclaration;
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 TiXmlText& ) { return true; }
00156 virtual bool Visit( const TiXmlComment& ) { return true; }
00158 virtual bool Visit( const TiXmlUnknown& ) { return true; }
00159 };
00160
00161
00162 enum
00163 {
00164 TIXML_SUCCESS,
00165 TIXML_NO_ATTRIBUTE,
00166 TIXML_WRONG_TYPE
00167 };
00168
00169
00170
00171 enum TiXmlEncoding
00172 {
00173 TIXML_ENCODING_UNKNOWN,
00174 TIXML_ENCODING_UTF8,
00175 TIXML_ENCODING_LEGACY
00176 };
00177
00178 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00179
00202 class TiXmlBase
00203 {
00204 friend class TiXmlNode;
00205 friend class TiXmlElement;
00206 friend class TiXmlDocument;
00207
00208 public:
00209 TiXmlBase() : userData(0) {}
00210 virtual ~TiXmlBase() {}
00211
00221 virtual void Print( FILE* cfile, int depth ) const = 0;
00222
00229 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00230
00232 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00233
00252 int Row() const { return location.row + 1; }
00253 int Column() const { return location.col + 1; }
00254
00255 void SetUserData( void* user ) { userData = user; }
00256 void* GetUserData() { return userData; }
00257 const void* GetUserData() const { return userData; }
00258
00259
00260
00261 static const int utf8ByteTable[256];
00262
00263 virtual const char* Parse( const char* p,
00264 TiXmlParsingData* data,
00265 TiXmlEncoding encoding ) = 0;
00266
00270 static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
00271
00272 enum
00273 {
00274 TIXML_NO_ERROR = 0,
00275 TIXML_ERROR,
00276 TIXML_ERROR_OPENING_FILE,
00277 TIXML_ERROR_OUT_OF_MEMORY,
00278 TIXML_ERROR_PARSING_ELEMENT,
00279 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00280 TIXML_ERROR_READING_ELEMENT_VALUE,
00281 TIXML_ERROR_READING_ATTRIBUTES,
00282 TIXML_ERROR_PARSING_EMPTY,
00283 TIXML_ERROR_READING_END_TAG,
00284 TIXML_ERROR_PARSING_UNKNOWN,
00285 TIXML_ERROR_PARSING_COMMENT,
00286 TIXML_ERROR_PARSING_DECLARATION,
00287 TIXML_ERROR_DOCUMENT_EMPTY,
00288 TIXML_ERROR_EMBEDDED_NULL,
00289 TIXML_ERROR_PARSING_CDATA,
00290 TIXML_ERROR_DOCUMENT_TOP_ONLY,
00291
00292 TIXML_ERROR_STRING_COUNT
00293 };
00294
00295 protected:
00296
00297 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00298 inline static bool IsWhiteSpace( char c )
00299 {
00300 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00301 }
00302 inline static bool IsWhiteSpace( int c )
00303 {
00304 if ( c < 256 )
00305 return IsWhiteSpace( (char) c );
00306 return false;
00307 }
00308
00309 #ifdef TIXML_USE_STL
00310 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
00311 static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
00312 #endif
00313
00314
00315
00316
00317
00318 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00319
00320
00321
00322
00323 static const char* ReadText( const char* in,
00324 TIXML_STRING* text,
00325 bool ignoreWhiteSpace,
00326 const char* endTag,
00327 bool ignoreCase,
00328 TiXmlEncoding encoding );
00329
00330
00331 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00332
00333
00334
00335 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00336 {
00337 assert( p );
00338 if ( encoding == TIXML_ENCODING_UTF8 )
00339 {
00340 *length = utf8ByteTable[ *((const unsigned char*)p) ];
00341 assert( *length >= 0 && *length < 5 );
00342 }
00343 else
00344 {
00345 *length = 1;
00346 }
00347
00348 if ( *length == 1 )
00349 {
00350 if ( *p == '&' )
00351 return GetEntity( p, _value, length, encoding );
00352 *_value = *p;
00353 return p+1;
00354 }
00355 else if ( *length )
00356 {
00357
00358
00359 for( int i=0; p[i] && i<*length; ++i ) {
00360 _value[i] = p[i];
00361 }
00362 return p + (*length);
00363 }
00364 else
00365 {
00366
00367 return 0;
00368 }
00369 }
00370
00371
00372
00373
00374 static bool StringEqual( const char* p,
00375 const char* endTag,
00376 bool ignoreCase,
00377 TiXmlEncoding encoding );
00378
00379 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00380
00381 TiXmlCursor location;
00382
00384 void* userData;
00385
00386
00387
00388 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00389 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00390 inline static int ToLower( int v, TiXmlEncoding encoding )
00391 {
00392 if ( encoding == TIXML_ENCODING_UTF8 )
00393 {
00394 if ( v < 128 ) return tolower( v );
00395 return v;
00396 }
00397 else
00398 {
00399 return tolower( v );
00400 }
00401 }
00402 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00403
00404 private:
00405 TiXmlBase( const TiXmlBase& );
00406 void operator=( const TiXmlBase& base );
00407
00408 struct Entity
00409 {
00410 const char* str;
00411 unsigned int strLength;
00412 char chr;
00413 };
00414 enum
00415 {
00416 NUM_ENTITY = 5,
00417 MAX_ENTITY_LENGTH = 6
00418
00419 };
00420 static Entity entity[ NUM_ENTITY ];
00421 static bool condenseWhiteSpace;
00422 };
00423
00424
00431 class TiXmlNode : public TiXmlBase
00432 {
00433 friend class TiXmlDocument;
00434 friend class TiXmlElement;
00435
00436 public:
00437 #ifdef TIXML_USE_STL
00438
00442 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00443
00460 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00461
00463 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00464
00465 #endif
00466
00470 enum NodeType
00471 {
00472 DOCUMENT,
00473 ELEMENT,
00474 COMMENT,
00475 UNKNOWN,
00476 TEXT,
00477 DECLARATION,
00478 TYPECOUNT
00479 };
00480
00481 virtual ~TiXmlNode();
00482
00495 const char *Value() const { return value.c_str (); }
00496
00497 #ifdef TIXML_USE_STL
00498
00502 const std::string& ValueStr() const { return value; }
00503 #endif
00504
00505 const TIXML_STRING& ValueTStr() const { return value; }
00506
00516 void SetValue(const char * _value) { value = _value;}
00517
00518 #ifdef TIXML_USE_STL
00520 void SetValue( const std::string& _value ) { value = _value; }
00521 #endif
00522
00524 void Clear();
00525
00527 TiXmlNode* Parent() { return parent; }
00528 const TiXmlNode* Parent() const { return parent; }
00529
00530 const TiXmlNode* FirstChild() const { return firstChild; }
00531 TiXmlNode* FirstChild() { return firstChild; }
00532 const TiXmlNode* FirstChild( const char * value ) const;
00533
00534 TiXmlNode* FirstChild( const char * _value ) {
00535
00536
00537 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00538 }
00539 const TiXmlNode* LastChild() const { return lastChild; }
00540 TiXmlNode* LastChild() { return lastChild; }
00541
00542 const TiXmlNode* LastChild( const char * value ) const;
00543 TiXmlNode* LastChild( const char * _value ) {
00544 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00545 }
00546
00547 #ifdef TIXML_USE_STL
00548 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00549 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00550 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00551 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00552 #endif
00553
00570 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00571 TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
00572 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00573 }
00574
00576 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00577 TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
00578 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00579 }
00580
00581 #ifdef TIXML_USE_STL
00582 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00583 TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
00584 #endif
00585
00589 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00590
00591
00601 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00602
00606 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00607
00611 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00612
00616 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00617
00619 bool RemoveChild( TiXmlNode* removeThis );
00620
00622 const TiXmlNode* PreviousSibling() const { return prev; }
00623 TiXmlNode* PreviousSibling() { return prev; }
00624
00626 const TiXmlNode* PreviousSibling( const char * ) const;
00627 TiXmlNode* PreviousSibling( const char *_prev ) {
00628 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00629 }
00630
00631 #ifdef TIXML_USE_STL
00632 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00633 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00634 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00635 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00636 #endif
00637
00639 const TiXmlNode* NextSibling() const { return next; }
00640 TiXmlNode* NextSibling() { return next; }
00641
00643 const TiXmlNode* NextSibling( const char * ) const;
00644 TiXmlNode* NextSibling( const char* _next ) {
00645 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
00646 }
00647
00652 const TiXmlElement* NextSiblingElement() const;
00653 TiXmlElement* NextSiblingElement() {
00654 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
00655 }
00656
00661 const TiXmlElement* NextSiblingElement( const char * ) const;
00662 TiXmlElement* NextSiblingElement( const char *_next ) {
00663 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00664 }
00665
00666 #ifdef TIXML_USE_STL
00667 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00668 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
00669 #endif
00670
00672 const TiXmlElement* FirstChildElement() const;
00673 TiXmlElement* FirstChildElement() {
00674 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00675 }
00676
00678 const TiXmlElement* FirstChildElement( const char * _value ) const;
00679 TiXmlElement* FirstChildElement( const char * _value ) {
00680 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00681 }
00682
00683 #ifdef TIXML_USE_STL
00684 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00685 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
00686 #endif
00687
00692 int Type() const { return type; }
00693
00697 const TiXmlDocument* GetDocument() const;
00698 TiXmlDocument* GetDocument() {
00699 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00700 }
00701
00703 bool NoChildren() const { return !firstChild; }
00704
00705 virtual const TiXmlDocument* ToDocument() const { return 0; }
00706 virtual const TiXmlElement* ToElement() const { return 0; }
00707 virtual const TiXmlComment* ToComment() const { return 0; }
00708 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
00709 virtual const TiXmlText* ToText() const { return 0; }
00710 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
00711
00712 virtual TiXmlDocument* ToDocument() { return 0; }
00713 virtual TiXmlElement* ToElement() { return 0; }
00714 virtual TiXmlComment* ToComment() { return 0; }
00715 virtual TiXmlUnknown* ToUnknown() { return 0; }
00716 virtual TiXmlText* ToText() { return 0; }
00717 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
00718
00722 virtual TiXmlNode* Clone() const = 0;
00723
00746 virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
00747
00748 protected:
00749 TiXmlNode( NodeType _type );
00750
00751
00752
00753 void CopyTo( TiXmlNode* target ) const;
00754
00755 #ifdef TIXML_USE_STL
00756
00757 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
00758 #endif
00759
00760
00761 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00762
00763 TiXmlNode* parent;
00764 NodeType type;
00765
00766 TiXmlNode* firstChild;
00767 TiXmlNode* lastChild;
00768
00769 TIXML_STRING value;
00770
00771 TiXmlNode* prev;
00772 TiXmlNode* next;
00773
00774 private:
00775 TiXmlNode( const TiXmlNode& );
00776 void operator=( const TiXmlNode& base );
00777 };
00778
00786 class TiXmlAttribute : public TiXmlBase
00787 {
00788 friend class TiXmlAttributeSet;
00789
00790 public:
00792 TiXmlAttribute() : TiXmlBase()
00793 {
00794 document = 0;
00795 prev = next = 0;
00796 }
00797
00798 #ifdef TIXML_USE_STL
00800 TiXmlAttribute( const std::string& _name, const std::string& _value )
00801 {
00802 name = _name;
00803 value = _value;
00804 document = 0;
00805 prev = next = 0;
00806 }
00807 #endif
00808
00810 TiXmlAttribute( const char * _name, const char * _value )
00811 {
00812 name = _name;
00813 value = _value;
00814 document = 0;
00815 prev = next = 0;
00816 }
00817
00818 const char* Name() const { return name.c_str(); }
00819 const char* Value() const { return value.c_str(); }
00820 #ifdef TIXML_USE_STL
00821 const std::string& ValueStr() const { return value; }
00822 #endif
00823 int IntValue() const;
00824 double DoubleValue() const;
00825
00826
00827 const TIXML_STRING& NameTStr() const { return name; }
00828
00838 int QueryIntValue( int* _value ) const;
00840 int QueryDoubleValue( double* _value ) const;
00841
00842 void SetName( const char* _name ) { name = _name; }
00843 void SetValue( const char* _value ) { value = _value; }
00844
00845 void SetIntValue( int _value );
00846 void SetDoubleValue( double _value );
00847
00848 #ifdef TIXML_USE_STL
00850 void SetName( const std::string& _name ) { name = _name; }
00852 void SetValue( const std::string& _value ) { value = _value; }
00853 #endif
00854
00856 const TiXmlAttribute* Next() const;
00857 TiXmlAttribute* Next() {
00858 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
00859 }
00860
00862 const TiXmlAttribute* Previous() const;
00863 TiXmlAttribute* Previous() {
00864 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
00865 }
00866
00867 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00868 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00869 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00870
00871
00872
00873
00874 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00875
00876
00877 virtual void Print( FILE* cfile, int depth ) const {
00878 Print( cfile, depth, 0 );
00879 }
00880 void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
00881
00882
00883
00884 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00885
00886 private:
00887 TiXmlAttribute( const TiXmlAttribute& );
00888 void operator=( const TiXmlAttribute& base );
00889
00890 TiXmlDocument* document;
00891 TIXML_STRING name;
00892 TIXML_STRING value;
00893 TiXmlAttribute* prev;
00894 TiXmlAttribute* next;
00895 };
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910 class TiXmlAttributeSet
00911 {
00912 public:
00913 TiXmlAttributeSet();
00914 ~TiXmlAttributeSet();
00915
00916 void Add( TiXmlAttribute* attribute );
00917 void Remove( TiXmlAttribute* attribute );
00918
00919 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00920 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00921 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00922 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00923
00924 const TiXmlAttribute* Find( const char* _name ) const;
00925 TiXmlAttribute* Find( const char* _name ) {
00926 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00927 }
00928 #ifdef TIXML_USE_STL
00929 const TiXmlAttribute* Find( const std::string& _name ) const;
00930 TiXmlAttribute* Find( const std::string& _name ) {
00931 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00932 }
00933
00934 #endif
00935
00936 private:
00937
00938
00939 TiXmlAttributeSet( const TiXmlAttributeSet& );
00940 void operator=( const TiXmlAttributeSet& );
00941
00942 TiXmlAttribute sentinel;
00943 };
00944
00945
00950 class TiXmlElement : public TiXmlNode
00951 {
00952 public:
00954 TiXmlElement (const char * in_value);
00955
00956 #ifdef TIXML_USE_STL
00958 TiXmlElement( const std::string& _value );
00959 #endif
00960
00961 TiXmlElement( const TiXmlElement& );
00962
00963 void operator=( const TiXmlElement& base );
00964
00965 virtual ~TiXmlElement();
00966
00970 const char* Attribute( const char* name ) const;
00971
00978 const char* Attribute( const char* name, int* i ) const;
00979
00986 const char* Attribute( const char* name, double* d ) const;
00987
00995 int QueryIntAttribute( const char* name, int* _value ) const;
00997 int QueryDoubleAttribute( const char* name, double* _value ) const;
00999 int QueryFloatAttribute( const char* name, float* _value ) const {
01000 double d;
01001 int result = QueryDoubleAttribute( name, &d );
01002 if ( result == TIXML_SUCCESS ) {
01003 *_value = (float)d;
01004 }
01005 return result;
01006 }
01007
01008 #ifdef TIXML_USE_STL
01009
01017 template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
01018 {
01019 const TiXmlAttribute* node = attributeSet.Find( name );
01020 if ( !node )
01021 return TIXML_NO_ATTRIBUTE;
01022
01023 std::stringstream sstream( node->ValueStr() );
01024 sstream >> *outValue;
01025 if ( !sstream.fail() )
01026 return TIXML_SUCCESS;
01027 return TIXML_WRONG_TYPE;
01028 }
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044 #endif
01045
01049 void SetAttribute( const char* name, const char * _value );
01050
01051 #ifdef TIXML_USE_STL
01052 const std::string* Attribute( const std::string& name ) const;
01053 const std::string* Attribute( const std::string& name, int* i ) const;
01054 const std::string* Attribute( const std::string& name, double* d ) const;
01055 int QueryIntAttribute( const std::string& name, int* _value ) const;
01056 int QueryDoubleAttribute( const std::string& name, double* _value ) const;
01057
01059 void SetAttribute( const std::string& name, const std::string& _value );
01061 void SetAttribute( const std::string& name, int _value );
01062 #endif
01063
01067 void SetAttribute( const char * name, int value );
01068
01072 void SetDoubleAttribute( const char * name, double value );
01073
01076 void RemoveAttribute( const char * name );
01077 #ifdef TIXML_USE_STL
01078 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
01079 #endif
01080
01081 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
01082 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
01083 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
01084 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
01085
01118 const char* GetText() const;
01119
01121 virtual TiXmlNode* Clone() const;
01122
01123 virtual void Print( FILE* cfile, int depth ) const;
01124
01125
01126
01127
01128 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01129
01130 virtual const TiXmlElement* ToElement() const { return this; }
01131 virtual TiXmlElement* ToElement() { return this; }
01132
01135 virtual bool Accept( TiXmlVisitor* visitor ) const;
01136
01137 protected:
01138
01139 void CopyTo( TiXmlElement* target ) const;
01140 void ClearThis();
01141
01142
01143 #ifdef TIXML_USE_STL
01144 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01145 #endif
01146
01147
01148
01149
01150 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01151
01152 private:
01153
01154 TiXmlAttributeSet attributeSet;
01155 };
01156
01157
01160 class TiXmlComment : public TiXmlNode
01161 {
01162 public:
01164 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01166 TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
01167 SetValue( _value );
01168 }
01169 TiXmlComment( const TiXmlComment& );
01170 void operator=( const TiXmlComment& base );
01171
01172 virtual ~TiXmlComment() {}
01173
01175 virtual TiXmlNode* Clone() const;
01176
01177 virtual void Print( FILE* cfile, int depth ) const;
01178
01179
01180
01181
01182 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01183
01184 virtual const TiXmlComment* ToComment() const { return this; }
01185 virtual TiXmlComment* ToComment() { return this; }
01186
01189 virtual bool Accept( TiXmlVisitor* visitor ) const;
01190
01191 protected:
01192 void CopyTo( TiXmlComment* target ) const;
01193
01194
01195 #ifdef TIXML_USE_STL
01196 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01197 #endif
01198
01199
01200 private:
01201
01202 };
01203
01204
01210 class TiXmlText : public TiXmlNode
01211 {
01212 friend class TiXmlElement;
01213 public:
01218 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01219 {
01220 SetValue( initValue );
01221 cdata = false;
01222 }
01223 virtual ~TiXmlText() {}
01224
01225 #ifdef TIXML_USE_STL
01227 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01228 {
01229 SetValue( initValue );
01230 cdata = false;
01231 }
01232 #endif
01233
01234 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01235 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01236
01237
01238 virtual void Print( FILE* cfile, int depth ) const;
01239
01241 bool CDATA() const { return cdata; }
01243 void SetCDATA( bool _cdata ) { cdata = _cdata; }
01244
01245 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01246
01247 virtual const TiXmlText* ToText() const { return this; }
01248 virtual TiXmlText* ToText() { return this; }
01249
01252 virtual bool Accept( TiXmlVisitor* content ) const;
01253
01254 protected :
01256 virtual TiXmlNode* Clone() const;
01257 void CopyTo( TiXmlText* target ) const;
01258
01259 bool Blank() const;
01260
01261 #ifdef TIXML_USE_STL
01262 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01263 #endif
01264
01265 private:
01266 bool cdata;
01267 };
01268
01269
01283 class TiXmlDeclaration : public TiXmlNode
01284 {
01285 public:
01287 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01288
01289 #ifdef TIXML_USE_STL
01291 TiXmlDeclaration( const std::string& _version,
01292 const std::string& _encoding,
01293 const std::string& _standalone );
01294 #endif
01295
01297 TiXmlDeclaration( const char* _version,
01298 const char* _encoding,
01299 const char* _standalone );
01300
01301 TiXmlDeclaration( const TiXmlDeclaration& copy );
01302 void operator=( const TiXmlDeclaration& copy );
01303
01304 virtual ~TiXmlDeclaration() {}
01305
01307 const char *Version() const { return version.c_str (); }
01309 const char *Encoding() const { return encoding.c_str (); }
01311 const char *Standalone() const { return standalone.c_str (); }
01312
01314 virtual TiXmlNode* Clone() const;
01315
01316 virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01317 virtual void Print( FILE* cfile, int depth ) const {
01318 Print( cfile, depth, 0 );
01319 }
01320
01321 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01322
01323 virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
01324 virtual TiXmlDeclaration* ToDeclaration() { return this; }
01325
01328 virtual bool Accept( TiXmlVisitor* visitor ) const;
01329
01330 protected:
01331 void CopyTo( TiXmlDeclaration* target ) const;
01332
01333 #ifdef TIXML_USE_STL
01334 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01335 #endif
01336
01337 private:
01338
01339 TIXML_STRING version;
01340 TIXML_STRING encoding;
01341 TIXML_STRING standalone;
01342 };
01343
01344
01352 class TiXmlUnknown : public TiXmlNode
01353 {
01354 public:
01355 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01356 virtual ~TiXmlUnknown() {}
01357
01358 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01359 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01360
01362 virtual TiXmlNode* Clone() const;
01363
01364 virtual void Print( FILE* cfile, int depth ) const;
01365
01366 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01367
01368 virtual const TiXmlUnknown* ToUnknown() const { return this; }
01369 virtual TiXmlUnknown* ToUnknown() { return this; }
01370
01373 virtual bool Accept( TiXmlVisitor* content ) const;
01374
01375 protected:
01376 void CopyTo( TiXmlUnknown* target ) const;
01377
01378 #ifdef TIXML_USE_STL
01379 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01380 #endif
01381
01382 private:
01383
01384 };
01385
01386
01391 class TiXmlDocument : public TiXmlNode
01392 {
01393 public:
01395 TiXmlDocument();
01397 TiXmlDocument( const char * documentName );
01398
01399 #ifdef TIXML_USE_STL
01401 TiXmlDocument( const std::string& documentName );
01402 #endif
01403
01404 TiXmlDocument( const TiXmlDocument& copy );
01405 void operator=( const TiXmlDocument& copy );
01406
01407 virtual ~TiXmlDocument() {}
01408
01413 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01415 bool SaveFile() const;
01417 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01419 bool SaveFile( const char * filename ) const;
01425 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01427 bool SaveFile( FILE* ) const;
01428
01429 #ifdef TIXML_USE_STL
01430 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01431 {
01432
01433
01434 return LoadFile( filename.c_str(), encoding );
01435 }
01436 bool SaveFile( const std::string& filename ) const
01437 {
01438
01439
01440 return SaveFile( filename.c_str() );
01441 }
01442 #endif
01443
01448 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01449
01454 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01455 TiXmlElement* RootElement() { return FirstChildElement(); }
01456
01462 bool Error() const { return error; }
01463
01465 const char * ErrorDesc() const { return errorDesc.c_str (); }
01466
01470 int ErrorId() const { return errorId; }
01471
01479 int ErrorRow() const { return errorLocation.row+1; }
01480 int ErrorCol() const { return errorLocation.col+1; }
01481
01506 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01507
01508 int TabSize() const { return tabsize; }
01509
01513 void ClearError() { error = false;
01514 errorId = 0;
01515 errorDesc = "";
01516 errorLocation.row = errorLocation.col = 0;
01517
01518 }
01519
01521 void Print() const { Print( stdout, 0 ); }
01522
01523
01524
01525
01526
01527
01528
01530 virtual void Print( FILE* cfile, int depth = 0 ) const;
01531
01532 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01533
01534 virtual const TiXmlDocument* ToDocument() const { return this; }
01535 virtual TiXmlDocument* ToDocument() { return this; }
01536
01539 virtual bool Accept( TiXmlVisitor* content ) const;
01540
01541 protected :
01542
01543 virtual TiXmlNode* Clone() const;
01544 #ifdef TIXML_USE_STL
01545 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01546 #endif
01547
01548 private:
01549 void CopyTo( TiXmlDocument* target ) const;
01550
01551 bool error;
01552 int errorId;
01553 TIXML_STRING errorDesc;
01554 int tabsize;
01555 TiXmlCursor errorLocation;
01556 bool useMicrosoftBOM;
01557 };
01558
01559
01640 class TiXmlHandle
01641 {
01642 public:
01644 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01646 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01647 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01648
01650 TiXmlHandle FirstChild() const;
01652 TiXmlHandle FirstChild( const char * value ) const;
01654 TiXmlHandle FirstChildElement() const;
01656 TiXmlHandle FirstChildElement( const char * value ) const;
01657
01661 TiXmlHandle Child( const char* value, int index ) const;
01665 TiXmlHandle Child( int index ) const;
01670 TiXmlHandle ChildElement( const char* value, int index ) const;
01675 TiXmlHandle ChildElement( int index ) const;
01676
01677 #ifdef TIXML_USE_STL
01678 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01679 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01680
01681 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01682 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01683 #endif
01684
01687 TiXmlNode* ToNode() const { return node; }
01690 TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01693 TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01696 TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01697
01701 TiXmlNode* Node() const { return ToNode(); }
01705 TiXmlElement* Element() const { return ToElement(); }
01709 TiXmlText* Text() const { return ToText(); }
01713 TiXmlUnknown* Unknown() const { return ToUnknown(); }
01714
01715 private:
01716 TiXmlNode* node;
01717 };
01718
01719
01739 class TiXmlPrinter : public TiXmlVisitor
01740 {
01741 public:
01742 TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
01743 buffer(), indent( " " ), lineBreak( "\n" ) {}
01744
01745 virtual bool VisitEnter( const TiXmlDocument& doc );
01746 virtual bool VisitExit( const TiXmlDocument& doc );
01747
01748 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
01749 virtual bool VisitExit( const TiXmlElement& element );
01750
01751 virtual bool Visit( const TiXmlDeclaration& declaration );
01752 virtual bool Visit( const TiXmlText& text );
01753 virtual bool Visit( const TiXmlComment& comment );
01754 virtual bool Visit( const TiXmlUnknown& unknown );
01755
01759 void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
01761 const char* Indent() { return indent.c_str(); }
01766 void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
01768 const char* LineBreak() { return lineBreak.c_str(); }
01769
01773 void SetStreamPrinting() { indent = "";
01774 lineBreak = "";
01775 }
01777 const char* CStr() { return buffer.c_str(); }
01779 size_t Size() { return buffer.size(); }
01780
01781 #ifdef TIXML_USE_STL
01783 const std::string& Str() { return buffer; }
01784 #endif
01785
01786 private:
01787 void DoIndent() {
01788 for( int i=0; i<depth; ++i )
01789 buffer += indent;
01790 }
01791 void DoLineBreak() {
01792 buffer += lineBreak;
01793 }
01794
01795 int depth;
01796 bool simpleTextPrint;
01797 TIXML_STRING buffer;
01798 TIXML_STRING indent;
01799 TIXML_STRING lineBreak;
01800 };
01801
01802
01803 #ifdef _MSC_VER
01804 #pragma warning( pop )
01805 #endif
01806 }
01807 #endif
01808