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 #define TIXML_USE_STL
00026
00027 #ifndef TINYXML_INCLUDED
00028 #define TINYXML_INCLUDED
00029
00030 #ifdef _MSC_VER
00031 #pragma warning( push )
00032 #pragma warning( disable : 4530 )
00033 #pragma warning( disable : 4786 )
00034 #endif
00035
00036 #include <ctype.h>
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include <assert.h>
00041
00042
00043 #if defined( _DEBUG ) && !defined( DEBUG )
00044 #define DEBUG
00045 #endif
00046
00047 #ifdef TIXML_USE_STL
00048 #include <string>
00049 #include <iostream>
00050 #include <sstream>
00051 #define TIXML_STRING std::string
00052 #else
00053 #include "tinystr.h"
00054 #define TIXML_STRING TiXmlString
00055 #endif
00056
00057
00058
00059
00060
00061 #define TIXML_SAFE
00062
00063 #ifdef TIXML_SAFE
00064 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
00065
00066 #define TIXML_SNPRINTF _snprintf_s
00067 #define TIXML_SNSCANF _snscanf_s
00068 #define TIXML_SSCANF sscanf_s
00069 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
00070
00071
00072 #define TIXML_SNPRINTF _snprintf
00073 #define TIXML_SNSCANF _snscanf
00074 #define TIXML_SSCANF sscanf
00075 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00076
00077
00078 #define TIXML_SNPRINTF snprintf
00079 #define TIXML_SNSCANF snscanf
00080 #define TIXML_SSCANF sscanf
00081 #else
00082 #define TIXML_SSCANF sscanf
00083 #endif
00084 #endif
00085
00086 class TiXmlDocument;
00087 class TiXmlElement;
00088 class TiXmlComment;
00089 class TiXmlUnknown;
00090 class TiXmlAttribute;
00091 class TiXmlText;
00092 class TiXmlDeclaration;
00093 class TiXmlParsingData;
00094
00095 const int TIXML_MAJOR_VERSION = 2;
00096 const int TIXML_MINOR_VERSION = 5;
00097 const int TIXML_PATCH_VERSION = 3;
00098
00099
00100
00101
00102 struct TiXmlCursor
00103 {
00104 TiXmlCursor() { Clear(); }
00105 void Clear() { row = col = -1; }
00106
00107 int row;
00108 int col;
00109 };
00110
00111
00130 class TiXmlVisitor
00131 {
00132 public:
00133 virtual ~TiXmlVisitor() {}
00134
00136 virtual bool VisitEnter( const TiXmlDocument& ) { return true; }
00138 virtual bool VisitExit( const TiXmlDocument& ) { return true; }
00139
00141 virtual bool VisitEnter( const TiXmlElement& , const TiXmlAttribute* ) { return true; }
00143 virtual bool VisitExit( const TiXmlElement& ) { return true; }
00144
00146 virtual bool Visit( const TiXmlDeclaration& ) { return true; }
00148 virtual bool Visit( const TiXmlText& ) { return true; }
00150 virtual bool Visit( const TiXmlComment& ) { return true; }
00152 virtual bool Visit( const TiXmlUnknown& ) { return true; }
00153 };
00154
00155
00156 enum
00157 {
00158 TIXML_SUCCESS,
00159 TIXML_NO_ATTRIBUTE,
00160 TIXML_WRONG_TYPE
00161 };
00162
00163
00164
00165 enum TiXmlEncoding
00166 {
00167 TIXML_ENCODING_UNKNOWN,
00168 TIXML_ENCODING_UTF8,
00169 TIXML_ENCODING_LEGACY
00170 };
00171
00172 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00173
00196 class TiXmlBase
00197 {
00198 friend class TiXmlNode;
00199 friend class TiXmlElement;
00200 friend class TiXmlDocument;
00201
00202 public:
00203 TiXmlBase() : userData(0) {}
00204 virtual ~TiXmlBase() {}
00205
00215 virtual void Print( FILE* cfile, int depth ) const = 0;
00216
00223 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00224
00226 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00227
00246 int Row() const { return location.row + 1; }
00247 int Column() const { return location.col + 1; }
00248
00249 void SetUserData( void* user ) { userData = user; }
00250 void* GetUserData() { return userData; }
00251 const void* GetUserData() const { return userData; }
00252
00253
00254
00255 static const int utf8ByteTable[256];
00256
00257 virtual const char* Parse( const char* p,
00258 TiXmlParsingData* data,
00259 TiXmlEncoding encoding ) = 0;
00260
00264 static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
00265
00266 enum
00267 {
00268 TIXML_NO_ERROR = 0,
00269 TIXML_ERROR,
00270 TIXML_ERROR_OPENING_FILE,
00271 TIXML_ERROR_OUT_OF_MEMORY,
00272 TIXML_ERROR_PARSING_ELEMENT,
00273 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00274 TIXML_ERROR_READING_ELEMENT_VALUE,
00275 TIXML_ERROR_READING_ATTRIBUTES,
00276 TIXML_ERROR_PARSING_EMPTY,
00277 TIXML_ERROR_READING_END_TAG,
00278 TIXML_ERROR_PARSING_UNKNOWN,
00279 TIXML_ERROR_PARSING_COMMENT,
00280 TIXML_ERROR_PARSING_DECLARATION,
00281 TIXML_ERROR_DOCUMENT_EMPTY,
00282 TIXML_ERROR_EMBEDDED_NULL,
00283 TIXML_ERROR_PARSING_CDATA,
00284 TIXML_ERROR_DOCUMENT_TOP_ONLY,
00285
00286 TIXML_ERROR_STRING_COUNT
00287 };
00288
00289 protected:
00290
00291 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00292 inline static bool IsWhiteSpace( char c )
00293 {
00294 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00295 }
00296 inline static bool IsWhiteSpace( int c )
00297 {
00298 if ( c < 256 )
00299 return IsWhiteSpace( (char) c );
00300 return false;
00301 }
00302
00303 #ifdef TIXML_USE_STL
00304 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
00305 static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
00306 #endif
00307
00308
00309
00310
00311
00312 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00313
00314
00315
00316
00317 static const char* ReadText( const char* in,
00318 TIXML_STRING* text,
00319 bool ignoreWhiteSpace,
00320 const char* endTag,
00321 bool ignoreCase,
00322 TiXmlEncoding encoding );
00323
00324
00325 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00326
00327
00328
00329 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00330 {
00331 assert( p );
00332 if ( encoding == TIXML_ENCODING_UTF8 )
00333 {
00334 *length = utf8ByteTable[ *((const unsigned char*)p) ];
00335 assert( *length >= 0 && *length < 5 );
00336 }
00337 else
00338 {
00339 *length = 1;
00340 }
00341
00342 if ( *length == 1 )
00343 {
00344 if ( *p == '&' )
00345 return GetEntity( p, _value, length, encoding );
00346 *_value = *p;
00347 return p+1;
00348 }
00349 else if ( *length )
00350 {
00351
00352
00353 for( int i=0; p[i] && i<*length; ++i ) {
00354 _value[i] = p[i];
00355 }
00356 return p + (*length);
00357 }
00358 else
00359 {
00360
00361 return 0;
00362 }
00363 }
00364
00365
00366
00367
00368 static bool StringEqual( const char* p,
00369 const char* endTag,
00370 bool ignoreCase,
00371 TiXmlEncoding encoding );
00372
00373 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00374
00375 TiXmlCursor location;
00376
00378 void* userData;
00379
00380
00381
00382 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00383 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00384 inline static int ToLower( int v, TiXmlEncoding encoding )
00385 {
00386 if ( encoding == TIXML_ENCODING_UTF8 )
00387 {
00388 if ( v < 128 ) return tolower( v );
00389 return v;
00390 }
00391 else
00392 {
00393 return tolower( v );
00394 }
00395 }
00396 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00397
00398 private:
00399 TiXmlBase( const TiXmlBase& );
00400 void operator=( const TiXmlBase& base );
00401
00402 struct Entity
00403 {
00404 const char* str;
00405 unsigned int strLength;
00406 char chr;
00407 };
00408 enum
00409 {
00410 NUM_ENTITY = 5,
00411 MAX_ENTITY_LENGTH = 6
00412
00413 };
00414 static Entity entity[ NUM_ENTITY ];
00415 static bool condenseWhiteSpace;
00416 };
00417
00418
00425 class TiXmlNode : public TiXmlBase
00426 {
00427 friend class TiXmlDocument;
00428 friend class TiXmlElement;
00429
00430 public:
00431 #ifdef TIXML_USE_STL
00432
00436 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00437
00454 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00455
00457 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00458
00459 #endif
00460
00464 enum NodeType
00465 {
00466 DOCUMENT,
00467 ELEMENT,
00468 COMMENT,
00469 UNKNOWN,
00470 TEXT,
00471 DECLARATION,
00472 TYPECOUNT
00473 };
00474
00475 virtual ~TiXmlNode();
00476
00489 const char *Value() const { return value.c_str (); }
00490
00491 #ifdef TIXML_USE_STL
00492
00496 const std::string& ValueStr() const { return value; }
00497 #endif
00498
00499 const TIXML_STRING& ValueTStr() const { return value; }
00500
00510 void SetValue(const char * _value) { value = _value;}
00511
00512 #ifdef TIXML_USE_STL
00513
00514 void SetValue( const std::string& _value ) { value = _value; }
00515 #endif
00516
00518 void Clear();
00519
00521 TiXmlNode* Parent() { return parent; }
00522 const TiXmlNode* Parent() const { return parent; }
00523
00524 const TiXmlNode* FirstChild() const { return firstChild; }
00525 TiXmlNode* FirstChild() { return firstChild; }
00526 const TiXmlNode* FirstChild( const char * value ) const;
00527
00528 TiXmlNode* FirstChild( const char * _value ) {
00529
00530
00531 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00532 }
00533 const TiXmlNode* LastChild() const { return lastChild; }
00534 TiXmlNode* LastChild() { return lastChild; }
00535
00536 const TiXmlNode* LastChild( const char * value ) const;
00537 TiXmlNode* LastChild( const char * _value ) {
00538 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00539 }
00540
00541 #ifdef TIXML_USE_STL
00542 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00543 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00544 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00545 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00546 #endif
00547
00564 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00565 TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
00566 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00567 }
00568
00570 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00571 TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
00572 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00573 }
00574
00575 #ifdef TIXML_USE_STL
00576 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00577 TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
00578 #endif
00579
00583 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00584
00585
00595 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00596
00600 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00601
00605 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00606
00610 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00611
00613 bool RemoveChild( TiXmlNode* removeThis );
00614
00616 const TiXmlNode* PreviousSibling() const { return prev; }
00617 TiXmlNode* PreviousSibling() { return prev; }
00618
00620 const TiXmlNode* PreviousSibling( const char * ) const;
00621 TiXmlNode* PreviousSibling( const char *_prev ) {
00622 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00623 }
00624
00625 #ifdef TIXML_USE_STL
00626 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00627 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00628 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00629 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00630 #endif
00631
00633 const TiXmlNode* NextSibling() const { return next; }
00634 TiXmlNode* NextSibling() { return next; }
00635
00637 const TiXmlNode* NextSibling( const char * ) const;
00638 TiXmlNode* NextSibling( const char* _next ) {
00639 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
00640 }
00641
00646 const TiXmlElement* NextSiblingElement() const;
00647 TiXmlElement* NextSiblingElement() {
00648 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
00649 }
00650
00655 const TiXmlElement* NextSiblingElement( const char * ) const;
00656 TiXmlElement* NextSiblingElement( const char *_next ) {
00657 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00658 }
00659
00660 #ifdef TIXML_USE_STL
00661 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00662 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
00663 #endif
00664
00666 const TiXmlElement* FirstChildElement() const;
00667 TiXmlElement* FirstChildElement() {
00668 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00669 }
00670
00672 const TiXmlElement* FirstChildElement( const char * _value ) const;
00673 TiXmlElement* FirstChildElement( const char * _value ) {
00674 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00675 }
00676
00677 #ifdef TIXML_USE_STL
00678 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00679 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
00680 #endif
00681
00686 int Type() const { return type; }
00687
00691 const TiXmlDocument* GetDocument() const;
00692 TiXmlDocument* GetDocument() {
00693 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00694 }
00695
00697 bool NoChildren() const { return !firstChild; }
00698
00699 virtual const TiXmlDocument* ToDocument() const { return 0; }
00700 virtual const TiXmlElement* ToElement() const { return 0; }
00701 virtual const TiXmlComment* ToComment() const { return 0; }
00702 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
00703 virtual const TiXmlText* ToText() const { return 0; }
00704 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
00705
00706 virtual TiXmlDocument* ToDocument() { return 0; }
00707 virtual TiXmlElement* ToElement() { return 0; }
00708 virtual TiXmlComment* ToComment() { return 0; }
00709 virtual TiXmlUnknown* ToUnknown() { return 0; }
00710 virtual TiXmlText* ToText() { return 0; }
00711 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
00712
00716 virtual TiXmlNode* Clone() const = 0;
00717
00740 virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
00741
00742 protected:
00743 TiXmlNode( NodeType _type );
00744
00745
00746
00747 void CopyTo( TiXmlNode* target ) const;
00748
00749 #ifdef TIXML_USE_STL
00750
00751 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
00752 #endif
00753
00754
00755 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00756
00757 TiXmlNode* parent;
00758 NodeType type;
00759
00760 TiXmlNode* firstChild;
00761 TiXmlNode* lastChild;
00762
00763 TIXML_STRING value;
00764
00765 TiXmlNode* prev;
00766 TiXmlNode* next;
00767
00768 private:
00769 TiXmlNode( const TiXmlNode& );
00770 void operator=( const TiXmlNode& base );
00771 };
00772
00773
00781 class TiXmlAttribute : public TiXmlBase
00782 {
00783 friend class TiXmlAttributeSet;
00784
00785 public:
00787 TiXmlAttribute() : TiXmlBase()
00788 {
00789 document = 0;
00790 prev = next = 0;
00791 }
00792
00793 #ifdef TIXML_USE_STL
00794
00795 TiXmlAttribute( const std::string& _name, const std::string& _value )
00796 {
00797 name = _name;
00798 value = _value;
00799 document = 0;
00800 prev = next = 0;
00801 }
00802 #endif
00803
00805 TiXmlAttribute( const char * _name, const char * _value )
00806 {
00807 name = _name;
00808 value = _value;
00809 document = 0;
00810 prev = next = 0;
00811 }
00812
00813 const char* Name() const { return name.c_str(); }
00814 const char* Value() const { return value.c_str(); }
00815 #ifdef TIXML_USE_STL
00816 const std::string& ValueStr() const { return value; }
00817 #endif
00818 int IntValue() const;
00819 double DoubleValue() const;
00820
00821
00822 const TIXML_STRING& NameTStr() const { return name; }
00823
00833 int QueryIntValue( int* _value ) const;
00835 int QueryDoubleValue( double* _value ) const;
00836
00837 void SetName( const char* _name ) { name = _name; }
00838 void SetValue( const char* _value ) { value = _value; }
00839
00840 void SetIntValue( int _value );
00841 void SetDoubleValue( double _value );
00842
00843 #ifdef TIXML_USE_STL
00844
00845 void SetName( const std::string& _name ) { name = _name; }
00847 void SetValue( const std::string& _value ) { value = _value; }
00848 #endif
00849
00851 const TiXmlAttribute* Next() const;
00852 TiXmlAttribute* Next() {
00853 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
00854 }
00855
00857 const TiXmlAttribute* Previous() const;
00858 TiXmlAttribute* Previous() {
00859 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
00860 }
00861
00862 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00863 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00864 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00865
00866
00867
00868
00869 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00870
00871
00872 virtual void Print( FILE* cfile, int depth ) const {
00873 Print( cfile, depth, 0 );
00874 }
00875 void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
00876
00877
00878
00879 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00880
00881 private:
00882 TiXmlAttribute( const TiXmlAttribute& );
00883 void operator=( const TiXmlAttribute& base );
00884
00885 TiXmlDocument* document;
00886 TIXML_STRING name;
00887 TIXML_STRING value;
00888 TiXmlAttribute* prev;
00889 TiXmlAttribute* next;
00890 };
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905 class TiXmlAttributeSet
00906 {
00907 public:
00908 TiXmlAttributeSet();
00909 ~TiXmlAttributeSet();
00910
00911 void Add( TiXmlAttribute* attribute );
00912 void Remove( TiXmlAttribute* attribute );
00913
00914 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00915 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00916 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00917 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00918
00919 const TiXmlAttribute* Find( const char* _name ) const;
00920 TiXmlAttribute* Find( const char* _name ) {
00921 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00922 }
00923 #ifdef TIXML_USE_STL
00924 const TiXmlAttribute* Find( const std::string& _name ) const;
00925 TiXmlAttribute* Find( const std::string& _name ) {
00926 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00927 }
00928
00929 #endif
00930
00931 private:
00932
00933
00934 TiXmlAttributeSet( const TiXmlAttributeSet& );
00935 void operator=( const TiXmlAttributeSet& );
00936
00937 TiXmlAttribute sentinel;
00938 };
00939
00940
00945 class TiXmlElement : public TiXmlNode
00946 {
00947 public:
00949 TiXmlElement (const char * in_value);
00950
00951 #ifdef TIXML_USE_STL
00952
00953 TiXmlElement( const std::string& _value );
00954 #endif
00955
00956 TiXmlElement( const TiXmlElement& );
00957
00958 void operator=( const TiXmlElement& base );
00959
00960 virtual ~TiXmlElement();
00961
00965 const char* Attribute( const char* name ) const;
00966
00973 const char* Attribute( const char* name, int* i ) const;
00974
00981 const char* Attribute( const char* name, double* d ) const;
00982
00990 int QueryIntAttribute( const char* name, int* _value ) const;
00992 int QueryDoubleAttribute( const char* name, double* _value ) const;
00994 int QueryFloatAttribute( const char* name, float* _value ) const {
00995 double d;
00996 int result = QueryDoubleAttribute( name, &d );
00997 if ( result == TIXML_SUCCESS ) {
00998 *_value = (float)d;
00999 }
01000 return result;
01001 }
01002
01003 #ifdef TIXML_USE_STL
01004
01012 template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
01013 {
01014 const TiXmlAttribute* node = attributeSet.Find( name );
01015 if ( !node )
01016 return TIXML_NO_ATTRIBUTE;
01017
01018 std::stringstream sstream( node->ValueStr() );
01019 sstream >> *outValue;
01020 if ( !sstream.fail() )
01021 return TIXML_SUCCESS;
01022 return TIXML_WRONG_TYPE;
01023 }
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039 #endif
01040
01044 void SetAttribute( const char* name, const char * _value );
01045
01046 #ifdef TIXML_USE_STL
01047 const std::string* Attribute( const std::string& name ) const;
01048 const std::string* Attribute( const std::string& name, int* i ) const;
01049 const std::string* Attribute( const std::string& name, double* d ) const;
01050 int QueryIntAttribute( const std::string& name, int* _value ) const;
01051 int QueryDoubleAttribute( const std::string& name, double* _value ) const;
01052
01054 void SetAttribute( const std::string& name, const std::string& _value );
01056 void SetAttribute( const std::string& name, int _value );
01057 #endif
01058
01062 void SetAttribute( const char * name, int value );
01063
01067 void SetDoubleAttribute( const char * name, double value );
01068
01071 void RemoveAttribute( const char * name );
01072 #ifdef TIXML_USE_STL
01073 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
01074 #endif
01075
01076 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
01077 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
01078 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
01079 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
01080
01113 const char* GetText() const;
01114
01116 virtual TiXmlNode* Clone() const;
01117
01118 virtual void Print( FILE* cfile, int depth ) const;
01119
01120
01121
01122
01123 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01124
01125 virtual const TiXmlElement* ToElement() const { return this; }
01126 virtual TiXmlElement* ToElement() { return this; }
01127
01130 virtual bool Accept( TiXmlVisitor* visitor ) const;
01131
01132 protected:
01133
01134 void CopyTo( TiXmlElement* target ) const;
01135 void ClearThis();
01136
01137
01138 #ifdef TIXML_USE_STL
01139 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01140 #endif
01141
01142
01143
01144
01145 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01146
01147 private:
01148
01149 TiXmlAttributeSet attributeSet;
01150 };
01151
01152
01155 class TiXmlComment : public TiXmlNode
01156 {
01157 public:
01159 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01161 TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
01162 SetValue( _value );
01163 }
01164 TiXmlComment( const TiXmlComment& );
01165 void operator=( const TiXmlComment& base );
01166
01167 virtual ~TiXmlComment() {}
01168
01170 virtual TiXmlNode* Clone() const;
01171
01172 virtual void Print( FILE* cfile, int depth ) const;
01173
01174
01175
01176
01177 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01178
01179 virtual const TiXmlComment* ToComment() const { return this; }
01180 virtual TiXmlComment* ToComment() { return this; }
01181
01184 virtual bool Accept( TiXmlVisitor* visitor ) const;
01185
01186 protected:
01187 void CopyTo( TiXmlComment* target ) const;
01188
01189
01190 #ifdef TIXML_USE_STL
01191 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01192 #endif
01193
01194
01195 private:
01196
01197 };
01198
01199
01205 class TiXmlText : public TiXmlNode
01206 {
01207 friend class TiXmlElement;
01208 public:
01213 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01214 {
01215 SetValue( initValue );
01216 cdata = false;
01217 }
01218 virtual ~TiXmlText() {}
01219
01220 #ifdef TIXML_USE_STL
01221
01222 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01223 {
01224 SetValue( initValue );
01225 cdata = false;
01226 }
01227 #endif
01228
01229 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01230 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01231
01232
01233 virtual void Print( FILE* cfile, int depth ) const;
01234
01236 bool CDATA() const { return cdata; }
01238 void SetCDATA( bool _cdata ) { cdata = _cdata; }
01239
01240 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01241
01242 virtual const TiXmlText* ToText() const { return this; }
01243 virtual TiXmlText* ToText() { return this; }
01244
01247 virtual bool Accept( TiXmlVisitor* content ) const;
01248
01249 protected :
01251 virtual TiXmlNode* Clone() const;
01252 void CopyTo( TiXmlText* target ) const;
01253
01254 bool Blank() const;
01255
01256 #ifdef TIXML_USE_STL
01257 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01258 #endif
01259
01260 private:
01261 bool cdata;
01262 };
01263
01264
01278 class TiXmlDeclaration : public TiXmlNode
01279 {
01280 public:
01282 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01283
01284 #ifdef TIXML_USE_STL
01285
01286 TiXmlDeclaration( const std::string& _version,
01287 const std::string& _encoding,
01288 const std::string& _standalone );
01289 #endif
01290
01292 TiXmlDeclaration( const char* _version,
01293 const char* _encoding,
01294 const char* _standalone );
01295
01296 TiXmlDeclaration( const TiXmlDeclaration& copy );
01297 void operator=( const TiXmlDeclaration& copy );
01298
01299 virtual ~TiXmlDeclaration() {}
01300
01302 const char *Version() const { return version.c_str (); }
01304 const char *Encoding() const { return encoding.c_str (); }
01306 const char *Standalone() const { return standalone.c_str (); }
01307
01309 virtual TiXmlNode* Clone() const;
01310
01311 virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01312 virtual void Print( FILE* cfile, int depth ) const {
01313 Print( cfile, depth, 0 );
01314 }
01315
01316 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01317
01318 virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
01319 virtual TiXmlDeclaration* ToDeclaration() { return this; }
01320
01323 virtual bool Accept( TiXmlVisitor* visitor ) const;
01324
01325 protected:
01326 void CopyTo( TiXmlDeclaration* target ) const;
01327
01328 #ifdef TIXML_USE_STL
01329 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01330 #endif
01331
01332 private:
01333
01334 TIXML_STRING version;
01335 TIXML_STRING encoding;
01336 TIXML_STRING standalone;
01337 };
01338
01339
01347 class TiXmlUnknown : public TiXmlNode
01348 {
01349 public:
01350 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01351 virtual ~TiXmlUnknown() {}
01352
01353 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01354 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01355
01357 virtual TiXmlNode* Clone() const;
01358
01359 virtual void Print( FILE* cfile, int depth ) const;
01360
01361 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01362
01363 virtual const TiXmlUnknown* ToUnknown() const { return this; }
01364 virtual TiXmlUnknown* ToUnknown() { return this; }
01365
01368 virtual bool Accept( TiXmlVisitor* content ) const;
01369
01370 protected:
01371 void CopyTo( TiXmlUnknown* target ) const;
01372
01373 #ifdef TIXML_USE_STL
01374 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01375 #endif
01376
01377 private:
01378
01379 };
01380
01381
01386 class TiXmlDocument : public TiXmlNode
01387 {
01388 public:
01390 TiXmlDocument();
01392 TiXmlDocument( const char * documentName );
01393
01394 #ifdef TIXML_USE_STL
01395
01396 TiXmlDocument( const std::string& documentName );
01397 #endif
01398
01399 TiXmlDocument( const TiXmlDocument& copy );
01400 void operator=( const TiXmlDocument& copy );
01401
01402 virtual ~TiXmlDocument() {}
01403
01408 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01410 bool SaveFile() const;
01412 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01414 bool SaveFile( const char * filename ) const;
01420 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01422 bool SaveFile( FILE* ) const;
01423
01424 #ifdef TIXML_USE_STL
01425 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01426 {
01427
01428
01429 return LoadFile( filename.c_str(), encoding );
01430 }
01431 bool SaveFile( const std::string& filename ) const
01432 {
01433
01434
01435 return SaveFile( filename.c_str() );
01436 }
01437 #endif
01438
01443 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01444
01449 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01450 TiXmlElement* RootElement() { return FirstChildElement(); }
01451
01457 bool Error() const { return error; }
01458
01460 const char * ErrorDesc() const { return errorDesc.c_str (); }
01461
01465 int ErrorId() const { return errorId; }
01466
01474 int ErrorRow() const { return errorLocation.row+1; }
01475 int ErrorCol() const { return errorLocation.col+1; }
01476
01501 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01502
01503 int TabSize() const { return tabsize; }
01504
01508 void ClearError() { error = false;
01509 errorId = 0;
01510 errorDesc = "";
01511 errorLocation.row = errorLocation.col = 0;
01512
01513 }
01514
01516 void Print() const { Print( stdout, 0 ); }
01517
01518
01519
01520
01521
01522
01523
01525 virtual void Print( FILE* cfile, int depth = 0 ) const;
01526
01527 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01528
01529 virtual const TiXmlDocument* ToDocument() const { return this; }
01530 virtual TiXmlDocument* ToDocument() { return this; }
01531
01534 virtual bool Accept( TiXmlVisitor* content ) const;
01535
01536 protected :
01537
01538 virtual TiXmlNode* Clone() const;
01539 #ifdef TIXML_USE_STL
01540 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01541 #endif
01542
01543 private:
01544 void CopyTo( TiXmlDocument* target ) const;
01545
01546 bool error;
01547 int errorId;
01548 TIXML_STRING errorDesc;
01549 int tabsize;
01550 TiXmlCursor errorLocation;
01551 bool useMicrosoftBOM;
01552 };
01553
01554
01635 class TiXmlHandle
01636 {
01637 public:
01639 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01641 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01642 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01643
01645 TiXmlHandle FirstChild() const;
01647 TiXmlHandle FirstChild( const char * value ) const;
01649 TiXmlHandle FirstChildElement() const;
01651 TiXmlHandle FirstChildElement( const char * value ) const;
01652
01656 TiXmlHandle Child( const char* value, int index ) const;
01660 TiXmlHandle Child( int index ) const;
01665 TiXmlHandle ChildElement( const char* value, int index ) const;
01670 TiXmlHandle ChildElement( int index ) const;
01671
01672 #ifdef TIXML_USE_STL
01673 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01674 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01675
01676 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01677 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01678 #endif
01679
01682 TiXmlNode* ToNode() const { return node; }
01685 TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01688 TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01691 TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01692
01696 TiXmlNode* Node() const { return ToNode(); }
01700 TiXmlElement* Element() const { return ToElement(); }
01704 TiXmlText* Text() const { return ToText(); }
01708 TiXmlUnknown* Unknown() const { return ToUnknown(); }
01709
01710 private:
01711 TiXmlNode* node;
01712 };
01713
01714
01734 class TiXmlPrinter : public TiXmlVisitor
01735 {
01736 public:
01737 TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
01738 buffer(), indent( " " ), lineBreak( "\n" ) {}
01739
01740 virtual bool VisitEnter( const TiXmlDocument& doc );
01741 virtual bool VisitExit( const TiXmlDocument& doc );
01742
01743 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
01744 virtual bool VisitExit( const TiXmlElement& element );
01745
01746 virtual bool Visit( const TiXmlDeclaration& declaration );
01747 virtual bool Visit( const TiXmlText& text );
01748 virtual bool Visit( const TiXmlComment& comment );
01749 virtual bool Visit( const TiXmlUnknown& unknown );
01750
01754 void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
01756 const char* Indent() { return indent.c_str(); }
01761 void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
01763 const char* LineBreak() { return lineBreak.c_str(); }
01764
01768 void SetStreamPrinting() { indent = "";
01769 lineBreak = "";
01770 }
01772 const char* CStr() { return buffer.c_str(); }
01774 size_t Size() { return buffer.size(); }
01775
01776 #ifdef TIXML_USE_STL
01777
01778 const std::string& Str() { return buffer; }
01779 #endif
01780
01781 private:
01782 void DoIndent() {
01783 for( int i=0; i<depth; ++i )
01784 buffer += indent;
01785 }
01786 void DoLineBreak() {
01787 buffer += lineBreak;
01788 }
01789
01790 int depth;
01791 bool simpleTextPrint;
01792 TIXML_STRING buffer;
01793 TIXML_STRING indent;
01794 TIXML_STRING lineBreak;
01795 };
01796
01797
01798 #ifdef _MSC_VER
01799 #pragma warning( pop )
01800 #endif
01801
01802 #endif
01803