File indexing completed on 2026-09-27 09:31:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #ifndef PANDORA_TINYXML_INCLUDED
0027 #define PANDORA_TINYXML_INCLUDED
0028
0029 #ifndef TIXML_USE_STL
0030 #define TIXML_USE_STL
0031 #endif
0032
0033 #ifdef _MSC_VER
0034 #pragma warning( push )
0035 #pragma warning( disable : 4530 )
0036 #pragma warning( disable : 4786 )
0037 #endif
0038
0039 #include <ctype.h>
0040 #include <stdio.h>
0041 #include <stdlib.h>
0042 #include <string.h>
0043 #include <assert.h>
0044
0045
0046 #if defined( _DEBUG ) && !defined( DEBUG )
0047 #define DEBUG
0048 #endif
0049
0050 #ifdef TIXML_USE_STL
0051 #include <string>
0052 #include <iostream>
0053 #include <sstream>
0054 #define TIXML_STRING std::string
0055 #else
0056 #include "tinystr.h"
0057 #define TIXML_STRING TiXmlString
0058 #endif
0059
0060
0061
0062
0063
0064 #define TIXML_SAFE
0065
0066 #ifdef TIXML_SAFE
0067 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
0068
0069 #define TIXML_SNPRINTF _snprintf_s
0070 #define TIXML_SSCANF sscanf_s
0071 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
0072
0073
0074 #define TIXML_SNPRINTF _snprintf
0075 #define TIXML_SSCANF sscanf
0076 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
0077
0078
0079 #define TIXML_SNPRINTF snprintf
0080 #define TIXML_SSCANF sscanf
0081 #else
0082 #define TIXML_SNPRINTF snprintf
0083 #define TIXML_SSCANF sscanf
0084 #endif
0085 #endif
0086
0087 namespace pandora
0088 {
0089
0090 class TiXmlDocument;
0091 class TiXmlElement;
0092 class TiXmlComment;
0093 class TiXmlUnknown;
0094 class TiXmlAttribute;
0095 class TiXmlText;
0096 class TiXmlDeclaration;
0097 class TiXmlParsingData;
0098
0099 const int TIXML_MAJOR_VERSION = 2;
0100 const int TIXML_MINOR_VERSION = 6;
0101 const int TIXML_PATCH_VERSION = 2;
0102
0103
0104
0105
0106 struct TiXmlCursor
0107 {
0108 TiXmlCursor() { Clear(); }
0109 void Clear() { row = col = -1; }
0110
0111 int row;
0112 int col;
0113 };
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135 class TiXmlVisitor
0136 {
0137 public:
0138 virtual ~TiXmlVisitor() {}
0139
0140
0141 virtual bool VisitEnter( const TiXmlDocument& ) { return true; }
0142
0143 virtual bool VisitExit( const TiXmlDocument& ) { return true; }
0144
0145
0146 virtual bool VisitEnter( const TiXmlElement& , const TiXmlAttribute* ) { return true; }
0147
0148 virtual bool VisitExit( const TiXmlElement& ) { return true; }
0149
0150
0151 virtual bool Visit( const TiXmlDeclaration& ) { return true; }
0152
0153 virtual bool Visit( const TiXmlText& ) { return true; }
0154
0155 virtual bool Visit( const TiXmlComment& ) { return true; }
0156
0157 virtual bool Visit( const TiXmlUnknown& ) { return true; }
0158 };
0159
0160
0161 enum
0162 {
0163 TIXML_SUCCESS,
0164 TIXML_NO_ATTRIBUTE,
0165 TIXML_WRONG_TYPE
0166 };
0167
0168
0169
0170 enum TiXmlEncoding
0171 {
0172 TIXML_ENCODING_UNKNOWN,
0173 TIXML_ENCODING_UTF8,
0174 TIXML_ENCODING_LEGACY
0175 };
0176
0177 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 class TiXmlBase
0202 {
0203 friend class TiXmlNode;
0204 friend class TiXmlElement;
0205 friend class TiXmlDocument;
0206
0207 public:
0208 TiXmlBase() : userData(0) {}
0209 virtual ~TiXmlBase() {}
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220 virtual void Print( FILE* cfile, int depth ) const = 0;
0221
0222
0223
0224
0225
0226
0227
0228 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
0229
0230
0231 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 int Row() const { return location.row + 1; }
0252 int Column() const { return location.col + 1; }
0253
0254 void SetUserData( void* user ) { userData = user; }
0255 void* GetUserData() { return userData; }
0256 const void* GetUserData() const { return userData; }
0257
0258
0259
0260 static const int utf8ByteTable[256];
0261
0262 virtual const char* Parse( const char* p,
0263 TiXmlParsingData* data,
0264 TiXmlEncoding encoding ) = 0;
0265
0266
0267
0268
0269 static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
0270
0271 enum
0272 {
0273 TIXML_NO_ERROR = 0,
0274 TIXML_ERROR,
0275 TIXML_ERROR_OPENING_FILE,
0276 TIXML_ERROR_PARSING_ELEMENT,
0277 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
0278 TIXML_ERROR_READING_ELEMENT_VALUE,
0279 TIXML_ERROR_READING_ATTRIBUTES,
0280 TIXML_ERROR_PARSING_EMPTY,
0281 TIXML_ERROR_READING_END_TAG,
0282 TIXML_ERROR_PARSING_UNKNOWN,
0283 TIXML_ERROR_PARSING_COMMENT,
0284 TIXML_ERROR_PARSING_DECLARATION,
0285 TIXML_ERROR_DOCUMENT_EMPTY,
0286 TIXML_ERROR_EMBEDDED_NULL,
0287 TIXML_ERROR_PARSING_CDATA,
0288 TIXML_ERROR_DOCUMENT_TOP_ONLY,
0289
0290 TIXML_ERROR_STRING_COUNT
0291 };
0292
0293 protected:
0294
0295 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
0296
0297 inline static bool IsWhiteSpace( char c )
0298 {
0299 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
0300 }
0301 inline static bool IsWhiteSpace( int c )
0302 {
0303 if ( c < 256 )
0304 return IsWhiteSpace( (char) c );
0305 return false;
0306 }
0307
0308 #ifdef TIXML_USE_STL
0309 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
0310 static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
0311 #endif
0312
0313
0314
0315
0316
0317 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
0318
0319
0320
0321
0322 static const char* ReadText( const char* in,
0323 TIXML_STRING* text,
0324 bool ignoreWhiteSpace,
0325 const char* endTag,
0326 bool ignoreCase,
0327 TiXmlEncoding encoding );
0328
0329
0330 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
0331
0332
0333
0334 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
0335 {
0336 assert( p );
0337 if ( encoding == TIXML_ENCODING_UTF8 )
0338 {
0339 *length = utf8ByteTable[ *((const unsigned char*)p) ];
0340 assert( *length >= 0 && *length < 5 );
0341 }
0342 else
0343 {
0344 *length = 1;
0345 }
0346
0347 if ( *length == 1 )
0348 {
0349 if ( *p == '&' )
0350 return GetEntity( p, _value, length, encoding );
0351 *_value = *p;
0352 return p+1;
0353 }
0354 else if ( *length )
0355 {
0356
0357
0358 for( int i=0; p[i] && i<*length; ++i ) {
0359 _value[i] = p[i];
0360 }
0361 return p + (*length);
0362 }
0363 else
0364 {
0365
0366 return 0;
0367 }
0368 }
0369
0370
0371
0372
0373 static bool StringEqual( const char* p,
0374 const char* endTag,
0375 bool ignoreCase,
0376 TiXmlEncoding encoding );
0377
0378 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
0379
0380 TiXmlCursor location;
0381
0382
0383 void* userData;
0384
0385
0386
0387 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
0388 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
0389 inline static int ToLower( int v, TiXmlEncoding encoding )
0390 {
0391 if ( encoding == TIXML_ENCODING_UTF8 )
0392 {
0393 if ( v < 128 ) return tolower( v );
0394 return v;
0395 }
0396 else
0397 {
0398 return tolower( v );
0399 }
0400 }
0401 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
0402
0403 private:
0404 TiXmlBase( const TiXmlBase& );
0405 void operator=( const TiXmlBase& base );
0406
0407 struct Entity
0408 {
0409 const char* str;
0410 unsigned int strLength;
0411 char chr;
0412 };
0413 enum
0414 {
0415 NUM_ENTITY = 5,
0416 MAX_ENTITY_LENGTH = 6
0417
0418 };
0419 static Entity entity[ NUM_ENTITY ];
0420 static bool condenseWhiteSpace;
0421 };
0422
0423
0424
0425
0426
0427
0428
0429
0430 class TiXmlNode : public TiXmlBase
0431 {
0432 friend class TiXmlDocument;
0433 friend class TiXmlElement;
0434
0435 public:
0436 #ifdef TIXML_USE_STL
0437
0438
0439
0440
0441 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
0460
0461
0462 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
0463
0464 #endif
0465
0466
0467
0468
0469 enum NodeType
0470 {
0471 TINYXML_DOCUMENT,
0472 TINYXML_ELEMENT,
0473 TINYXML_COMMENT,
0474 TINYXML_UNKNOWN,
0475 TINYXML_TEXT,
0476 TINYXML_DECLARATION,
0477 TINYXML_TYPECOUNT
0478 };
0479
0480 virtual ~TiXmlNode();
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494 const char *Value() const { return value.c_str (); }
0495
0496 #ifdef TIXML_USE_STL
0497
0498
0499
0500
0501 const std::string& ValueStr() const { return value; }
0502 #endif
0503
0504 const TIXML_STRING& ValueTStr() const { return value; }
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515 void SetValue(const char * _value) { value = _value;}
0516
0517 #ifdef TIXML_USE_STL
0518
0519 void SetValue( const std::string& _value ) { value = _value; }
0520 #endif
0521
0522
0523 void Clear();
0524
0525
0526 TiXmlNode* Parent() { return parent; }
0527 const TiXmlNode* Parent() const { return parent; }
0528
0529 const TiXmlNode* FirstChild() const { return firstChild; }
0530 TiXmlNode* FirstChild() { return firstChild; }
0531 const TiXmlNode* FirstChild( const char * value ) const;
0532
0533 TiXmlNode* FirstChild( const char * _value ) {
0534
0535
0536 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
0537 }
0538 const TiXmlNode* LastChild() const { return lastChild; }
0539 TiXmlNode* LastChild() { return lastChild; }
0540
0541 const TiXmlNode* LastChild( const char * value ) const;
0542 TiXmlNode* LastChild( const char * _value ) {
0543 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
0544 }
0545
0546 #ifdef TIXML_USE_STL
0547 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
0548 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
0549 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
0550 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
0551 #endif
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
0570 TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
0571 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
0572 }
0573
0574
0575 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
0576 TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
0577 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
0578 }
0579
0580 #ifdef TIXML_USE_STL
0581 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
0582 TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
0583 #endif
0584
0585
0586
0587
0588 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
0601
0602
0603
0604
0605 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
0606
0607
0608
0609
0610 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
0611
0612
0613
0614
0615 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
0616
0617
0618 bool RemoveChild( TiXmlNode* removeThis );
0619
0620
0621 const TiXmlNode* PreviousSibling() const { return prev; }
0622 TiXmlNode* PreviousSibling() { return prev; }
0623
0624
0625 const TiXmlNode* PreviousSibling( const char * ) const;
0626 TiXmlNode* PreviousSibling( const char *_prev ) {
0627 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
0628 }
0629
0630 #ifdef TIXML_USE_STL
0631 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
0632 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
0633 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
0634 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
0635 #endif
0636
0637
0638 const TiXmlNode* NextSibling() const { return next; }
0639 TiXmlNode* NextSibling() { return next; }
0640
0641
0642 const TiXmlNode* NextSibling( const char * ) const;
0643 TiXmlNode* NextSibling( const char* _next ) {
0644 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
0645 }
0646
0647
0648
0649
0650
0651 const TiXmlElement* NextSiblingElement() const;
0652 TiXmlElement* NextSiblingElement() {
0653 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
0654 }
0655
0656
0657
0658
0659
0660 const TiXmlElement* NextSiblingElement( const char * ) const;
0661 TiXmlElement* NextSiblingElement( const char *_next ) {
0662 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
0663 }
0664
0665 #ifdef TIXML_USE_STL
0666 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
0667 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
0668 #endif
0669
0670
0671 const TiXmlElement* FirstChildElement() const;
0672 TiXmlElement* FirstChildElement() {
0673 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
0674 }
0675
0676
0677 const TiXmlElement* FirstChildElement( const char * _value ) const;
0678 TiXmlElement* FirstChildElement( const char * _value ) {
0679 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
0680 }
0681
0682 #ifdef TIXML_USE_STL
0683 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
0684 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
0685 #endif
0686
0687
0688
0689
0690
0691 int Type() const { return type; }
0692
0693
0694
0695
0696 const TiXmlDocument* GetDocument() const;
0697 TiXmlDocument* GetDocument() {
0698 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
0699 }
0700
0701
0702 bool NoChildren() const { return !firstChild; }
0703
0704 virtual const TiXmlDocument* ToDocument() const { return 0; }
0705 virtual const TiXmlElement* ToElement() const { return 0; }
0706 virtual const TiXmlComment* ToComment() const { return 0; }
0707 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
0708 virtual const TiXmlText* ToText() const { return 0; }
0709 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
0710
0711 virtual TiXmlDocument* ToDocument() { return 0; }
0712 virtual TiXmlElement* ToElement() { return 0; }
0713 virtual TiXmlComment* ToComment() { return 0; }
0714 virtual TiXmlUnknown* ToUnknown() { return 0; }
0715 virtual TiXmlText* ToText() { return 0; }
0716 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
0717
0718
0719
0720
0721 virtual TiXmlNode* Clone() const = 0;
0722
0723
0724
0725
0726
0727
0728
0729
0730
0731
0732
0733
0734
0735
0736
0737
0738
0739
0740
0741
0742
0743
0744
0745 virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
0746
0747 protected:
0748 TiXmlNode( NodeType _type );
0749
0750
0751
0752 void CopyTo( TiXmlNode* target ) const;
0753
0754 #ifdef TIXML_USE_STL
0755
0756 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
0757 #endif
0758
0759
0760 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
0761
0762 TiXmlNode* parent;
0763 NodeType type;
0764
0765 TiXmlNode* firstChild;
0766 TiXmlNode* lastChild;
0767
0768 TIXML_STRING value;
0769
0770 TiXmlNode* prev;
0771 TiXmlNode* next;
0772
0773 private:
0774 TiXmlNode( const TiXmlNode& );
0775 void operator=( const TiXmlNode& base );
0776 };
0777
0778
0779
0780
0781
0782
0783
0784
0785
0786 class TiXmlAttribute : public TiXmlBase
0787 {
0788 friend class TiXmlAttributeSet;
0789
0790 public:
0791
0792 TiXmlAttribute() : TiXmlBase()
0793 {
0794 document = 0;
0795 prev = next = 0;
0796 }
0797
0798 #ifdef TIXML_USE_STL
0799
0800 TiXmlAttribute( const std::string& _name, const std::string& _value )
0801 {
0802 name = _name;
0803 value = _value;
0804 document = 0;
0805 prev = next = 0;
0806 }
0807 #endif
0808
0809
0810 TiXmlAttribute( const char * _name, const char * _value )
0811 {
0812 name = _name;
0813 value = _value;
0814 document = 0;
0815 prev = next = 0;
0816 }
0817
0818 const char* Name() const { return name.c_str(); }
0819 const char* Value() const { return value.c_str(); }
0820 #ifdef TIXML_USE_STL
0821 const std::string& ValueStr() const { return value; }
0822 #endif
0823 int IntValue() const;
0824 double DoubleValue() const;
0825
0826
0827 const TIXML_STRING& NameTStr() const { return name; }
0828
0829
0830
0831
0832
0833
0834
0835
0836
0837
0838 int QueryIntValue( int* _value ) const;
0839
0840 int QueryDoubleValue( double* _value ) const;
0841
0842 void SetName( const char* _name ) { name = _name; }
0843 void SetValue( const char* _value ) { value = _value; }
0844
0845 void SetIntValue( int _value );
0846 void SetDoubleValue( double _value );
0847
0848 #ifdef TIXML_USE_STL
0849
0850 void SetName( const std::string& _name ) { name = _name; }
0851
0852 void SetValue( const std::string& _value ) { value = _value; }
0853 #endif
0854
0855
0856 const TiXmlAttribute* Next() const;
0857 TiXmlAttribute* Next() {
0858 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
0859 }
0860
0861
0862 const TiXmlAttribute* Previous() const;
0863 TiXmlAttribute* Previous() {
0864 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
0865 }
0866
0867 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
0868 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
0869 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
0870
0871
0872
0873
0874 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
0875
0876
0877 virtual void Print( FILE* cfile, int depth ) const {
0878 Print( cfile, depth, 0 );
0879 }
0880 void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
0881
0882
0883
0884 void SetDocument( TiXmlDocument* doc ) { document = doc; }
0885
0886 private:
0887 TiXmlAttribute( const TiXmlAttribute& );
0888 void operator=( const TiXmlAttribute& base );
0889
0890 TiXmlDocument* document;
0891 TIXML_STRING name;
0892 TIXML_STRING value;
0893 TiXmlAttribute* prev;
0894 TiXmlAttribute* next;
0895 };
0896
0897
0898
0899
0900
0901
0902
0903
0904
0905
0906
0907
0908
0909
0910 class TiXmlAttributeSet
0911 {
0912 public:
0913 TiXmlAttributeSet();
0914 ~TiXmlAttributeSet();
0915
0916 void Add( TiXmlAttribute* attribute );
0917 void Remove( TiXmlAttribute* attribute );
0918
0919 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
0920 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
0921 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
0922 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
0923
0924 TiXmlAttribute* Find( const char* _name ) const;
0925 TiXmlAttribute* FindOrCreate( const char* _name );
0926
0927 # ifdef TIXML_USE_STL
0928 TiXmlAttribute* Find( const std::string& _name ) const;
0929 TiXmlAttribute* FindOrCreate( const std::string& _name );
0930 # endif
0931
0932
0933 private:
0934
0935
0936 TiXmlAttributeSet( const TiXmlAttributeSet& );
0937 void operator=( const TiXmlAttributeSet& );
0938
0939 TiXmlAttribute sentinel;
0940 };
0941
0942
0943
0944
0945
0946
0947 class TiXmlElement : public TiXmlNode
0948 {
0949 public:
0950
0951 TiXmlElement (const char * in_value);
0952
0953 #ifdef TIXML_USE_STL
0954
0955 TiXmlElement( const std::string& _value );
0956 #endif
0957
0958 TiXmlElement( const TiXmlElement& );
0959
0960 TiXmlElement& operator=( const TiXmlElement& base );
0961
0962 virtual ~TiXmlElement();
0963
0964
0965
0966
0967 const char* Attribute( const char* name ) const;
0968
0969
0970
0971
0972
0973
0974
0975 const char* Attribute( const char* name, int* i ) const;
0976
0977
0978
0979
0980
0981
0982
0983 const char* Attribute( const char* name, double* d ) const;
0984
0985
0986
0987
0988
0989
0990
0991
0992 int QueryIntAttribute( const char* name, int* _value ) const;
0993
0994 int QueryUnsignedAttribute( const char* name, unsigned* _value ) const;
0995
0996
0997
0998
0999 int QueryBoolAttribute( const char* name, bool* _value ) const;
1000
1001 int QueryDoubleAttribute( const char* name, double* _value ) const;
1002
1003 int QueryFloatAttribute( const char* name, float* _value ) const {
1004 double d;
1005 int result = QueryDoubleAttribute( name, &d );
1006 if ( result == TIXML_SUCCESS ) {
1007 *_value = (float)d;
1008 }
1009 return result;
1010 }
1011
1012 #ifdef TIXML_USE_STL
1013
1014 int QueryStringAttribute( const char* name, std::string* _value ) const {
1015 const char* cstr = Attribute( name );
1016 if ( cstr ) {
1017 *_value = std::string( cstr );
1018 return TIXML_SUCCESS;
1019 }
1020 return TIXML_NO_ATTRIBUTE;
1021 }
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031 template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
1032 {
1033 const TiXmlAttribute* node = attributeSet.Find( name );
1034 if ( !node )
1035 return TIXML_NO_ATTRIBUTE;
1036
1037 std::stringstream sstream( node->ValueStr() );
1038 sstream >> *outValue;
1039 if ( !sstream.fail() )
1040 return TIXML_SUCCESS;
1041 return TIXML_WRONG_TYPE;
1042 }
1043
1044 int QueryValueAttribute( const std::string& name, std::string* outValue ) const
1045 {
1046 const TiXmlAttribute* node = attributeSet.Find( name );
1047 if ( !node )
1048 return TIXML_NO_ATTRIBUTE;
1049 *outValue = node->ValueStr();
1050 return TIXML_SUCCESS;
1051 }
1052 #endif
1053
1054
1055
1056
1057 void SetAttribute( const char* name, const char * _value );
1058
1059 #ifdef TIXML_USE_STL
1060 const std::string* Attribute( const std::string& name ) const;
1061 const std::string* Attribute( const std::string& name, int* i ) const;
1062 const std::string* Attribute( const std::string& name, double* d ) const;
1063 int QueryIntAttribute( const std::string& name, int* _value ) const;
1064 int QueryDoubleAttribute( const std::string& name, double* _value ) const;
1065
1066
1067 void SetAttribute( const std::string& name, const std::string& _value );
1068
1069 void SetAttribute( const std::string& name, int _value );
1070
1071 void SetDoubleAttribute( const std::string& name, double value );
1072 #endif
1073
1074
1075
1076
1077 void SetAttribute( const char * name, int value );
1078
1079
1080
1081
1082 void SetDoubleAttribute( const char * name, double value );
1083
1084
1085
1086 void RemoveAttribute( const char * name );
1087 #ifdef TIXML_USE_STL
1088 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
1089 #endif
1090
1091 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
1092 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
1093 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
1094 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128 const char* GetText() const;
1129
1130
1131 virtual TiXmlNode* Clone() const;
1132
1133 virtual void Print( FILE* cfile, int depth ) const;
1134
1135
1136
1137
1138 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1139
1140 virtual const TiXmlElement* ToElement() const { return this; }
1141 virtual TiXmlElement* ToElement() { return this; }
1142
1143
1144
1145 virtual bool Accept( TiXmlVisitor* visitor ) const;
1146
1147 protected:
1148
1149 void CopyTo( TiXmlElement* target ) const;
1150 void ClearThis();
1151
1152
1153 #ifdef TIXML_USE_STL
1154 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1155 #endif
1156
1157
1158
1159
1160 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1161
1162 private:
1163 TiXmlAttributeSet attributeSet;
1164 };
1165
1166
1167
1168
1169 class TiXmlComment : public TiXmlNode
1170 {
1171 public:
1172
1173 TiXmlComment() : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {}
1174
1175 TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {
1176 SetValue( _value );
1177 }
1178 TiXmlComment( const TiXmlComment& );
1179 TiXmlComment& operator=( const TiXmlComment& base );
1180
1181 virtual ~TiXmlComment() {}
1182
1183
1184 virtual TiXmlNode* Clone() const;
1185
1186 virtual void Print( FILE* cfile, int depth ) const;
1187
1188
1189
1190
1191 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1192
1193 virtual const TiXmlComment* ToComment() const { return this; }
1194 virtual TiXmlComment* ToComment() { return this; }
1195
1196
1197
1198 virtual bool Accept( TiXmlVisitor* visitor ) const;
1199
1200 protected:
1201 void CopyTo( TiXmlComment* target ) const;
1202
1203
1204 #ifdef TIXML_USE_STL
1205 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1206 #endif
1207
1208
1209 private:
1210
1211 };
1212
1213
1214
1215
1216
1217
1218
1219 class TiXmlText : public TiXmlNode
1220 {
1221 friend class TiXmlElement;
1222 public:
1223
1224
1225
1226
1227 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT)
1228 {
1229 SetValue( initValue );
1230 cdata = false;
1231 }
1232 virtual ~TiXmlText() {}
1233
1234 #ifdef TIXML_USE_STL
1235
1236 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT)
1237 {
1238 SetValue( initValue );
1239 cdata = false;
1240 }
1241 #endif
1242
1243 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_TEXT ) { copy.CopyTo( this ); }
1244 TiXmlText& operator=( const TiXmlText& base ) { base.CopyTo( this ); return *this; }
1245
1246
1247 virtual void Print( FILE* cfile, int depth ) const;
1248
1249
1250 bool CDATA() const { return cdata; }
1251
1252 void SetCDATA( bool _cdata ) { cdata = _cdata; }
1253
1254 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1255
1256 virtual const TiXmlText* ToText() const { return this; }
1257 virtual TiXmlText* ToText() { return this; }
1258
1259
1260
1261 virtual bool Accept( TiXmlVisitor* content ) const;
1262
1263 protected :
1264
1265 virtual TiXmlNode* Clone() const;
1266 void CopyTo( TiXmlText* target ) const;
1267
1268 bool Blank() const;
1269
1270 #ifdef TIXML_USE_STL
1271 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1272 #endif
1273
1274 private:
1275 bool cdata;
1276 };
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292 class TiXmlDeclaration : public TiXmlNode
1293 {
1294 public:
1295
1296 TiXmlDeclaration() : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) {}
1297
1298 #ifdef TIXML_USE_STL
1299
1300 TiXmlDeclaration( const std::string& _version,
1301 const std::string& _encoding,
1302 const std::string& _standalone );
1303 #endif
1304
1305
1306 TiXmlDeclaration( const char* _version,
1307 const char* _encoding,
1308 const char* _standalone );
1309
1310 TiXmlDeclaration( const TiXmlDeclaration& copy );
1311 TiXmlDeclaration& operator=( const TiXmlDeclaration& copy );
1312
1313 virtual ~TiXmlDeclaration() {}
1314
1315
1316 const char *Version() const { return version.c_str (); }
1317
1318 const char *Encoding() const { return encoding.c_str (); }
1319
1320 const char *Standalone() const { return standalone.c_str (); }
1321
1322
1323 virtual TiXmlNode* Clone() const;
1324
1325 virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
1326 virtual void Print( FILE* cfile, int depth ) const {
1327 Print( cfile, depth, 0 );
1328 }
1329
1330 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1331
1332 virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
1333 virtual TiXmlDeclaration* ToDeclaration() { return this; }
1334
1335
1336
1337 virtual bool Accept( TiXmlVisitor* visitor ) const;
1338
1339 protected:
1340 void CopyTo( TiXmlDeclaration* target ) const;
1341
1342 #ifdef TIXML_USE_STL
1343 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1344 #endif
1345
1346 private:
1347
1348 TIXML_STRING version;
1349 TIXML_STRING encoding;
1350 TIXML_STRING standalone;
1351 };
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361 class TiXmlUnknown : public TiXmlNode
1362 {
1363 public:
1364 TiXmlUnknown() : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) {}
1365 virtual ~TiXmlUnknown() {}
1366
1367 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) { copy.CopyTo( this ); }
1368 TiXmlUnknown& operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); return *this; }
1369
1370
1371 virtual TiXmlNode* Clone() const;
1372
1373 virtual void Print( FILE* cfile, int depth ) const;
1374
1375 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1376
1377 virtual const TiXmlUnknown* ToUnknown() const { return this; }
1378 virtual TiXmlUnknown* ToUnknown() { return this; }
1379
1380
1381
1382 virtual bool Accept( TiXmlVisitor* content ) const;
1383
1384 protected:
1385 void CopyTo( TiXmlUnknown* target ) const;
1386
1387 #ifdef TIXML_USE_STL
1388 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1389 #endif
1390
1391 private:
1392
1393 };
1394
1395
1396
1397
1398
1399
1400 class TiXmlDocument : public TiXmlNode
1401 {
1402 public:
1403
1404 TiXmlDocument();
1405
1406 TiXmlDocument( const char * documentName );
1407
1408 #ifdef TIXML_USE_STL
1409
1410 TiXmlDocument( const std::string& documentName );
1411 #endif
1412
1413 TiXmlDocument( const TiXmlDocument& copy );
1414 TiXmlDocument& operator=( const TiXmlDocument& copy );
1415
1416 virtual ~TiXmlDocument() {}
1417
1418
1419
1420
1421
1422 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1423
1424 bool SaveFile() const;
1425
1426 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1427
1428 bool SaveFile( const char * filename ) const;
1429
1430
1431
1432
1433
1434 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1435
1436 bool SaveFile( FILE* ) const;
1437
1438 #ifdef TIXML_USE_STL
1439 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
1440 {
1441 return LoadFile( filename.c_str(), encoding );
1442 }
1443 bool SaveFile( const std::string& filename ) const
1444 {
1445 return SaveFile( filename.c_str() );
1446 }
1447 #endif
1448
1449
1450
1451
1452
1453 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1454
1455
1456
1457
1458
1459 const TiXmlElement* RootElement() const { return FirstChildElement(); }
1460 TiXmlElement* RootElement() { return FirstChildElement(); }
1461
1462
1463
1464
1465
1466
1467 bool Error() const { return error; }
1468
1469
1470 const char * ErrorDesc() const { return errorDesc.c_str (); }
1471
1472
1473
1474
1475 int ErrorId() const { return errorId; }
1476
1477
1478
1479
1480
1481
1482
1483
1484 int ErrorRow() const { return errorLocation.row+1; }
1485 int ErrorCol() const { return errorLocation.col+1; }
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
1512
1513 int TabSize() const { return tabsize; }
1514
1515
1516
1517
1518 void ClearError() { error = false;
1519 errorId = 0;
1520 errorDesc = "";
1521 errorLocation.row = errorLocation.col = 0;
1522
1523 }
1524
1525
1526 void Print() const { Print( stdout, 0 ); }
1527
1528
1529
1530
1531
1532
1533
1534
1535 virtual void Print( FILE* cfile, int depth = 0 ) const;
1536
1537 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1538
1539 virtual const TiXmlDocument* ToDocument() const { return this; }
1540 virtual TiXmlDocument* ToDocument() { return this; }
1541
1542
1543
1544 virtual bool Accept( TiXmlVisitor* content ) const;
1545
1546 protected :
1547
1548 virtual TiXmlNode* Clone() const;
1549 #ifdef TIXML_USE_STL
1550 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1551 #endif
1552
1553 private:
1554 void CopyTo( TiXmlDocument* target ) const;
1555
1556 bool error;
1557 int errorId;
1558 TIXML_STRING errorDesc;
1559 int tabsize;
1560 TiXmlCursor errorLocation;
1561 bool useMicrosoftBOM;
1562 };
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645 class TiXmlHandle
1646 {
1647 public:
1648
1649 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
1650
1651 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
1652 TiXmlHandle operator=( const TiXmlHandle& ref ) { if ( &ref != this ) this->node = ref.node; return *this; }
1653
1654
1655 TiXmlHandle FirstChild() const;
1656
1657 TiXmlHandle FirstChild( const char * value ) const;
1658
1659 TiXmlHandle FirstChildElement() const;
1660
1661 TiXmlHandle FirstChildElement( const char * value ) const;
1662
1663
1664
1665
1666 TiXmlHandle Child( const char* value, int index ) const;
1667
1668
1669
1670 TiXmlHandle Child( int index ) const;
1671
1672
1673
1674
1675 TiXmlHandle ChildElement( const char* value, int index ) const;
1676
1677
1678
1679
1680 TiXmlHandle ChildElement( int index ) const;
1681
1682 #ifdef TIXML_USE_STL
1683 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
1684 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
1685
1686 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
1687 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
1688 #endif
1689
1690
1691
1692 TiXmlNode* ToNode() const { return node; }
1693
1694
1695 TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
1696
1697
1698 TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
1699
1700
1701 TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
1702
1703
1704
1705
1706 TiXmlNode* Node() const { return ToNode(); }
1707
1708
1709
1710 TiXmlElement* Element() const { return ToElement(); }
1711
1712
1713
1714 TiXmlText* Text() const { return ToText(); }
1715
1716
1717
1718 TiXmlUnknown* Unknown() const { return ToUnknown(); }
1719
1720 private:
1721 TiXmlNode* node;
1722 };
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744 class TiXmlPrinter : public TiXmlVisitor
1745 {
1746 public:
1747 TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
1748 buffer(), indent( " " ), lineBreak( "\n" ) {}
1749
1750 virtual bool VisitEnter( const TiXmlDocument& doc );
1751 virtual bool VisitExit( const TiXmlDocument& doc );
1752
1753 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
1754 virtual bool VisitExit( const TiXmlElement& element );
1755
1756 virtual bool Visit( const TiXmlDeclaration& declaration );
1757 virtual bool Visit( const TiXmlText& text );
1758 virtual bool Visit( const TiXmlComment& comment );
1759 virtual bool Visit( const TiXmlUnknown& unknown );
1760
1761
1762
1763
1764 void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
1765
1766 const char* Indent() { return indent.c_str(); }
1767
1768
1769
1770
1771 void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
1772
1773 const char* LineBreak() { return lineBreak.c_str(); }
1774
1775
1776
1777
1778 void SetStreamPrinting() { indent = "";
1779 lineBreak = "";
1780 }
1781
1782 const char* CStr() { return buffer.c_str(); }
1783
1784 size_t Size() { return buffer.size(); }
1785
1786 #ifdef TIXML_USE_STL
1787
1788 const std::string& Str() { return buffer; }
1789 #endif
1790
1791 private:
1792 void DoIndent() {
1793 for( int i=0; i<depth; ++i )
1794 buffer += indent;
1795 }
1796 void DoLineBreak() {
1797 buffer += lineBreak;
1798 }
1799
1800 int depth;
1801 bool simpleTextPrint;
1802 TIXML_STRING buffer;
1803 TIXML_STRING indent;
1804 TIXML_STRING lineBreak;
1805 };
1806
1807
1808 #ifdef _MSC_VER
1809 #pragma warning( pop )
1810 #endif
1811
1812 }
1813
1814 #endif