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
00027 #ifndef TINYXML_INCLUDED
00028 #define TINYXML_INCLUDED
00029
00030 #ifndef TIXML_USE_STL
00031 #define TIXML_USE_STL
00032 #endif
00033
00034 #ifdef _MSC_VER
00035 #pragma warning( push )
00036 #pragma warning( disable : 4530 )
00037 #pragma warning( disable : 4786 )
00038 #endif
00039
00040 #include <ctype.h>
00041 #include <stdio.h>
00042 #include <stdlib.h>
00043 #include <string.h>
00044 #include <assert.h>
00045
00046
00047 #if defined( _DEBUG ) && !defined( DEBUG )
00048 #define DEBUG
00049 #endif
00050
00051 #ifdef TIXML_USE_STL
00052 #include <string>
00053 #include <iostream>
00054 #include <sstream>
00055 #define TIXML_STRING std::string
00056 #else
00057 #include "tinystr.h"
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_SSCANF sscanf_s
00072 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
00073
00074
00075 #define TIXML_SNPRINTF _snprintf
00076 #define TIXML_SSCANF sscanf
00077 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00078
00079
00080 #define TIXML_SNPRINTF snprintf
00081 #define TIXML_SSCANF sscanf
00082 #else
00083 #define TIXML_SNPRINTF snprintf
00084 #define TIXML_SSCANF sscanf
00085 #endif
00086 #endif
00087
00088 class TiXmlDocument;
00089 class TiXmlElement;
00090 class TiXmlComment;
00091 class TiXmlUnknown;
00092 class TiXmlAttribute;
00093 class TiXmlText;
00094 class TiXmlDeclaration;
00095 class TiXmlParsingData;
00096
00097 const int TIXML_MAJOR_VERSION = 2;
00098 const int TIXML_MINOR_VERSION = 6;
00099 const int TIXML_PATCH_VERSION = 1;
00100
00101
00102
00103
00104 struct TiXmlCursor
00105 {
00106 TiXmlCursor() { Clear(); }
00107 void Clear() { row = col = -1; }
00108
00109 int row;
00110 int col;
00111 };
00112
00113
00133 class TiXmlVisitor
00134 {
00135 public:
00136 virtual ~TiXmlVisitor() {}
00137
00139 virtual bool VisitEnter( const TiXmlDocument& ) { return true; }
00141 virtual bool VisitExit( const TiXmlDocument& ) { return true; }
00142
00144 virtual bool VisitEnter( const TiXmlElement& , const TiXmlAttribute* ) { return true; }
00146 virtual bool VisitExit( const TiXmlElement& ) { return true; }
00147
00149 virtual bool Visit( const TiXmlDeclaration& ) { return true; }
00151 virtual bool Visit( const TiXmlText& ) { return true; }
00153 virtual bool Visit( const TiXmlComment& ) { return true; }
00155 virtual bool Visit( const TiXmlUnknown& ) { return true; }
00156 };
00157
00158
00159 enum
00160 {
00161 TIXML_SUCCESS,
00162 TIXML_NO_ATTRIBUTE,
00163 TIXML_WRONG_TYPE
00164 };
00165
00166
00167
00168 enum TiXmlEncoding
00169 {
00170 TIXML_ENCODING_UNKNOWN,
00171 TIXML_ENCODING_UTF8,
00172 TIXML_ENCODING_LEGACY
00173 };
00174
00175 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00176
00199 class TiXmlBase
00200 {
00201 friend class TiXmlNode;
00202 friend class TiXmlElement;
00203 friend class TiXmlDocument;
00204
00205 public:
00206 TiXmlBase() : userData(0) {}
00207 virtual ~TiXmlBase() {}
00208
00218 virtual void Print( FILE* cfile, int depth ) const = 0;
00219
00226 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00227
00229 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00230
00249 int Row() const { return location.row + 1; }
00250 int Column() const { return location.col + 1; }
00251
00252 void SetUserData( void* user ) { userData = user; }
00253 void* GetUserData() { return userData; }
00254 const void* GetUserData() const { return userData; }
00255
00256
00257
00258 static const int utf8ByteTable[256];
00259
00260 virtual const char* Parse( const char* p,
00261 TiXmlParsingData* data,
00262 TiXmlEncoding encoding ) = 0;
00263
00267 static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
00268
00269 enum
00270 {
00271 TIXML_NO_ERROR = 0,
00272 TIXML_ERROR,
00273 TIXML_ERROR_OPENING_FILE,
00274 TIXML_ERROR_PARSING_ELEMENT,
00275 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00276 TIXML_ERROR_READING_ELEMENT_VALUE,
00277 TIXML_ERROR_READING_ATTRIBUTES,
00278 TIXML_ERROR_PARSING_EMPTY,
00279 TIXML_ERROR_READING_END_TAG,
00280 TIXML_ERROR_PARSING_UNKNOWN,
00281 TIXML_ERROR_PARSING_COMMENT,
00282 TIXML_ERROR_PARSING_DECLARATION,
00283 TIXML_ERROR_DOCUMENT_EMPTY,
00284 TIXML_ERROR_EMBEDDED_NULL,
00285 TIXML_ERROR_PARSING_CDATA,
00286 TIXML_ERROR_DOCUMENT_TOP_ONLY,
00287
00288 TIXML_ERROR_STRING_COUNT
00289 };
00290
00291 protected:
00292
00293 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00294
00295 inline static bool IsWhiteSpace( char c )
00296 {
00297 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00298 }
00299 inline static bool IsWhiteSpace( int c )
00300 {
00301 if ( c < 256 )
00302 return IsWhiteSpace( (char) c );
00303 return false;
00304 }
00305
00306 #ifdef TIXML_USE_STL
00307 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
00308 static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
00309 #endif
00310
00311
00312
00313
00314
00315 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00316
00317
00318
00319
00320 static const char* ReadText( const char* in,
00321 TIXML_STRING* text,
00322 bool ignoreWhiteSpace,
00323 const char* endTag,
00324 bool ignoreCase,
00325 TiXmlEncoding encoding );
00326
00327
00328 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00329
00330
00331
00332 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00333 {
00334 assert( p );
00335 if ( encoding == TIXML_ENCODING_UTF8 )
00336 {
00337 *length = utf8ByteTable[ *((const unsigned char*)p) ];
00338 assert( *length >= 0 && *length < 5 );
00339 }
00340 else
00341 {
00342 *length = 1;
00343 }
00344
00345 if ( *length == 1 )
00346 {
00347 if ( *p == '&' )
00348 return GetEntity( p, _value, length, encoding );
00349 *_value = *p;
00350 return p+1;
00351 }
00352 else if ( *length )
00353 {
00354
00355
00356 for( int i=0; p[i] && i<*length; ++i ) {
00357 _value[i] = p[i];
00358 }
00359 return p + (*length);
00360 }
00361 else
00362 {
00363
00364 return 0;
00365 }
00366 }
00367
00368
00369
00370
00371 static bool StringEqual( const char* p,
00372 const char* endTag,
00373 bool ignoreCase,
00374 TiXmlEncoding encoding );
00375
00376 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00377
00378 TiXmlCursor location;
00379
00381 void* userData;
00382
00383
00384
00385 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00386 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00387 inline static int ToLower( int v, TiXmlEncoding encoding )
00388 {
00389 if ( encoding == TIXML_ENCODING_UTF8 )
00390 {
00391 if ( v < 128 ) return tolower( v );
00392 return v;
00393 }
00394 else
00395 {
00396 return tolower( v );
00397 }
00398 }
00399 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00400
00401 private:
00402 TiXmlBase( const TiXmlBase& );
00403 void operator=( const TiXmlBase& base );
00404
00405 struct Entity
00406 {
00407 const char* str;
00408 unsigned int strLength;
00409 char chr;
00410 };
00411 enum
00412 {
00413 NUM_ENTITY = 5,
00414 MAX_ENTITY_LENGTH = 6
00415
00416 };
00417 static Entity entity[ NUM_ENTITY ];
00418 static bool condenseWhiteSpace;
00419 };
00420
00421
00428 class TiXmlNode : public TiXmlBase
00429 {
00430 friend class TiXmlDocument;
00431 friend class TiXmlElement;
00432
00433 public:
00434 #ifdef TIXML_USE_STL
00435
00439 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00440
00457 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00458
00460 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00461
00462 #endif
00463
00467 enum NodeType
00468 {
00469 TINYXML_DOCUMENT,
00470 TINYXML_ELEMENT,
00471 TINYXML_COMMENT,
00472 TINYXML_UNKNOWN,
00473 TINYXML_TEXT,
00474 TINYXML_DECLARATION,
00475 TINYXML_TYPECOUNT
00476 };
00477
00478 virtual ~TiXmlNode();
00479
00492 const char *Value() const { return value.c_str (); }
00493
00494 #ifdef TIXML_USE_STL
00495
00499 const std::string& ValueStr() const { return value; }
00500 #endif
00501
00502 const TIXML_STRING& ValueTStr() const { return value; }
00503
00513 void SetValue(const char * _value) { value = _value;}
00514
00515 #ifdef TIXML_USE_STL
00516
00517 void SetValue( const std::string& _value ) { value = _value; }
00518 #endif
00519
00521 void Clear();
00522
00524 TiXmlNode* Parent() { return parent; }
00525 const TiXmlNode* Parent() const { return parent; }
00526
00527 const TiXmlNode* FirstChild() const { return firstChild; }
00528 TiXmlNode* FirstChild() { return firstChild; }
00529 const TiXmlNode* FirstChild( const char * value ) const;
00530
00531 TiXmlNode* FirstChild( const char * _value ) {
00532
00533
00534 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00535 }
00536 const TiXmlNode* LastChild() const { return lastChild; }
00537 TiXmlNode* LastChild() { return lastChild; }
00538
00539 const TiXmlNode* LastChild( const char * value ) const;
00540 TiXmlNode* LastChild( const char * _value ) {
00541 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00542 }
00543
00544 #ifdef TIXML_USE_STL
00545 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00546 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00547 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00548 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00549 #endif
00550
00567 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00568 TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
00569 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00570 }
00571
00573 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00574 TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
00575 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00576 }
00577
00578 #ifdef TIXML_USE_STL
00579 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00580 TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
00581 #endif
00582
00586 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00587
00588
00598 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00599
00603 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00604
00608 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00609
00613 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00614
00616 bool RemoveChild( TiXmlNode* removeThis );
00617
00619 const TiXmlNode* PreviousSibling() const { return prev; }
00620 TiXmlNode* PreviousSibling() { return prev; }
00621
00623 const TiXmlNode* PreviousSibling( const char * ) const;
00624 TiXmlNode* PreviousSibling( const char *_prev ) {
00625 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00626 }
00627
00628 #ifdef TIXML_USE_STL
00629 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00630 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00631 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00632 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00633 #endif
00634
00636 const TiXmlNode* NextSibling() const { return next; }
00637 TiXmlNode* NextSibling() { return next; }
00638
00640 const TiXmlNode* NextSibling( const char * ) const;
00641 TiXmlNode* NextSibling( const char* _next ) {
00642 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
00643 }
00644
00649 const TiXmlElement* NextSiblingElement() const;
00650 TiXmlElement* NextSiblingElement() {
00651 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
00652 }
00653
00658 const TiXmlElement* NextSiblingElement( const char * ) const;
00659 TiXmlElement* NextSiblingElement( const char *_next ) {
00660 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00661 }
00662
00663 #ifdef TIXML_USE_STL
00664 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00665 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
00666 #endif
00667
00669 const TiXmlElement* FirstChildElement() const;
00670 TiXmlElement* FirstChildElement() {
00671 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00672 }
00673
00675 const TiXmlElement* FirstChildElement( const char * _value ) const;
00676 TiXmlElement* FirstChildElement( const char * _value ) {
00677 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00678 }
00679
00680 #ifdef TIXML_USE_STL
00681 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00682 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
00683 #endif
00684
00689 int Type() const { return type; }
00690
00694 const TiXmlDocument* GetDocument() const;
00695 TiXmlDocument* GetDocument() {
00696 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00697 }
00698
00700 bool NoChildren() const { return !firstChild; }
00701
00702 virtual const TiXmlDocument* ToDocument() const { return 0; }
00703 virtual const TiXmlElement* ToElement() const { return 0; }
00704 virtual const TiXmlComment* ToComment() const { return 0; }
00705 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
00706 virtual const TiXmlText* ToText() const { return 0; }
00707 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
00708
00709 virtual TiXmlDocument* ToDocument() { return 0; }
00710 virtual TiXmlElement* ToElement() { return 0; }
00711 virtual TiXmlComment* ToComment() { return 0; }
00712 virtual TiXmlUnknown* ToUnknown() { return 0; }
00713 virtual TiXmlText* ToText() { return 0; }
00714 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
00715
00719 virtual TiXmlNode* Clone() const = 0;
00720
00743 virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
00744
00745 protected:
00746 TiXmlNode( NodeType _type );
00747
00748
00749
00750 void CopyTo( TiXmlNode* target ) const;
00751
00752 #ifdef TIXML_USE_STL
00753
00754 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
00755 #endif
00756
00757
00758 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00759
00760 TiXmlNode* parent;
00761 NodeType type;
00762
00763 TiXmlNode* firstChild;
00764 TiXmlNode* lastChild;
00765
00766 TIXML_STRING value;
00767
00768 TiXmlNode* prev;
00769 TiXmlNode* next;
00770
00771 private:
00772 TiXmlNode( const TiXmlNode& );
00773 void operator=( const TiXmlNode& base );
00774 };
00775
00776
00784 class TiXmlAttribute : public TiXmlBase
00785 {
00786 friend class TiXmlAttributeSet;
00787
00788 public:
00790 TiXmlAttribute() : TiXmlBase()
00791 {
00792 document = 0;
00793 prev = next = 0;
00794 }
00795
00796 #ifdef TIXML_USE_STL
00797
00798 TiXmlAttribute( const std::string& _name, const std::string& _value )
00799 {
00800 name = _name;
00801 value = _value;
00802 document = 0;
00803 prev = next = 0;
00804 }
00805 #endif
00806
00808 TiXmlAttribute( const char * _name, const char * _value )
00809 {
00810 name = _name;
00811 value = _value;
00812 document = 0;
00813 prev = next = 0;
00814 }
00815
00816 const char* Name() const { return name.c_str(); }
00817 const char* Value() const { return value.c_str(); }
00818 #ifdef TIXML_USE_STL
00819 const std::string& ValueStr() const { return value; }
00820 #endif
00821 int IntValue() const;
00822 double DoubleValue() const;
00823
00824
00825 const TIXML_STRING& NameTStr() const { return name; }
00826
00836 int QueryIntValue( int* _value ) const;
00838 int QueryDoubleValue( double* _value ) const;
00839
00840 void SetName( const char* _name ) { name = _name; }
00841 void SetValue( const char* _value ) { value = _value; }
00842
00843 void SetIntValue( int _value );
00844 void SetDoubleValue( double _value );
00845
00846 #ifdef TIXML_USE_STL
00847
00848 void SetName( const std::string& _name ) { name = _name; }
00850 void SetValue( const std::string& _value ) { value = _value; }
00851 #endif
00852
00854 const TiXmlAttribute* Next() const;
00855 TiXmlAttribute* Next() {
00856 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
00857 }
00858
00860 const TiXmlAttribute* Previous() const;
00861 TiXmlAttribute* Previous() {
00862 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
00863 }
00864
00865 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00866 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00867 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00868
00869
00870
00871
00872 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00873
00874
00875 virtual void Print( FILE* cfile, int depth ) const {
00876 Print( cfile, depth, 0 );
00877 }
00878 void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
00879
00880
00881
00882 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00883
00884 private:
00885 TiXmlAttribute( const TiXmlAttribute& );
00886 void operator=( const TiXmlAttribute& base );
00887
00888 TiXmlDocument* document;
00889 TIXML_STRING name;
00890 TIXML_STRING value;
00891 TiXmlAttribute* prev;
00892 TiXmlAttribute* next;
00893 };
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908 class TiXmlAttributeSet
00909 {
00910 public:
00911 TiXmlAttributeSet();
00912 ~TiXmlAttributeSet();
00913
00914 void Add( TiXmlAttribute* attribute );
00915 void Remove( TiXmlAttribute* attribute );
00916
00917 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00918 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00919 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00920 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00921
00922 TiXmlAttribute* Find( const char* _name ) const;
00923 TiXmlAttribute* FindOrCreate( const char* _name );
00924
00925 # ifdef TIXML_USE_STL
00926 TiXmlAttribute* Find( const std::string& _name ) const;
00927 TiXmlAttribute* FindOrCreate( const std::string& _name );
00928 # endif
00929
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
01005 int QueryStringAttribute( const char* name, std::string* _value ) const {
01006 const char* cstr = Attribute( name );
01007 if ( cstr ) {
01008 *_value = std::string( cstr );
01009 return TIXML_SUCCESS;
01010 }
01011 return TIXML_NO_ATTRIBUTE;
01012 }
01013
01022 template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
01023 {
01024 const TiXmlAttribute* node = attributeSet.Find( name );
01025 if ( !node )
01026 return TIXML_NO_ATTRIBUTE;
01027
01028 std::stringstream sstream( node->ValueStr() );
01029 sstream >> *outValue;
01030 if ( !sstream.fail() )
01031 return TIXML_SUCCESS;
01032 return TIXML_WRONG_TYPE;
01033 }
01034
01035 int QueryValueAttribute( const std::string& name, std::string* outValue ) const
01036 {
01037 const TiXmlAttribute* node = attributeSet.Find( name );
01038 if ( !node )
01039 return TIXML_NO_ATTRIBUTE;
01040 *outValue = node->ValueStr();
01041 return TIXML_SUCCESS;
01042 }
01043 #endif
01044
01048 void SetAttribute( const char* name, const char * _value );
01049
01050 #ifdef TIXML_USE_STL
01051 const std::string* Attribute( const std::string& name ) const;
01052 const std::string* Attribute( const std::string& name, int* i ) const;
01053 const std::string* Attribute( const std::string& name, double* d ) const;
01054 int QueryIntAttribute( const std::string& name, int* _value ) const;
01055 int QueryDoubleAttribute( const std::string& name, double* _value ) const;
01056
01058 void SetAttribute( const std::string& name, const std::string& _value );
01060 void SetAttribute( const std::string& name, int _value );
01062 void SetDoubleAttribute( const std::string& name, double value );
01063 #endif
01064
01068 void SetAttribute( const char * name, int value );
01069
01073 void SetDoubleAttribute( const char * name, double value );
01074
01077 void RemoveAttribute( const char * name );
01078 #ifdef TIXML_USE_STL
01079 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
01080 #endif
01081
01082 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
01083 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
01084 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
01085 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
01086
01119 const char* GetText() const;
01120
01122 virtual TiXmlNode* Clone() const;
01123
01124 virtual void Print( FILE* cfile, int depth ) const;
01125
01126
01127
01128
01129 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01130
01131 virtual const TiXmlElement* ToElement() const { return this; }
01132 virtual TiXmlElement* ToElement() { return this; }
01133
01136 virtual bool Accept( TiXmlVisitor* visitor ) const;
01137
01138 protected:
01139
01140 void CopyTo( TiXmlElement* target ) const;
01141 void ClearThis();
01142
01143
01144 #ifdef TIXML_USE_STL
01145 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01146 #endif
01147
01148
01149
01150
01151 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01152
01153 private:
01154 TiXmlAttributeSet attributeSet;
01155 };
01156
01157
01160 class TiXmlComment : public TiXmlNode
01161 {
01162 public:
01164 TiXmlComment() : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {}
01166 TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::TINYXML_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::TINYXML_TEXT)
01219 {
01220 SetValue( initValue );
01221 cdata = false;
01222 }
01223 virtual ~TiXmlText() {}
01224
01225 #ifdef TIXML_USE_STL
01226
01227 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT)
01228 {
01229 SetValue( initValue );
01230 cdata = false;
01231 }
01232 #endif
01233
01234 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_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::TINYXML_DECLARATION ) {}
01288
01289 #ifdef TIXML_USE_STL
01290
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::TINYXML_UNKNOWN ) {}
01356 virtual ~TiXmlUnknown() {}
01357
01358 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_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
01400
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 return LoadFile( filename.c_str(), encoding );
01433 }
01434 bool SaveFile( const std::string& filename ) const
01435 {
01436 return SaveFile( filename.c_str() );
01437 }
01438 #endif
01439
01444 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01445
01450 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01451 TiXmlElement* RootElement() { return FirstChildElement(); }
01452
01458 bool Error() const { return error; }
01459
01461 const char * ErrorDesc() const { return errorDesc.c_str (); }
01462
01466 int ErrorId() const { return errorId; }
01467
01475 int ErrorRow() const { return errorLocation.row+1; }
01476 int ErrorCol() const { return errorLocation.col+1; }
01477
01502 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01503
01504 int TabSize() const { return tabsize; }
01505
01509 void ClearError() { error = false;
01510 errorId = 0;
01511 errorDesc = "";
01512 errorLocation.row = errorLocation.col = 0;
01513
01514 }
01515
01517 void Print() const { Print( stdout, 0 ); }
01518
01519
01520
01521
01522
01523
01524
01526 virtual void Print( FILE* cfile, int depth = 0 ) const;
01527
01528 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01529
01530 virtual const TiXmlDocument* ToDocument() const { return this; }
01531 virtual TiXmlDocument* ToDocument() { return this; }
01532
01535 virtual bool Accept( TiXmlVisitor* content ) const;
01536
01537 protected :
01538
01539 virtual TiXmlNode* Clone() const;
01540 #ifdef TIXML_USE_STL
01541 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01542 #endif
01543
01544 private:
01545 void CopyTo( TiXmlDocument* target ) const;
01546
01547 bool error;
01548 int errorId;
01549 TIXML_STRING errorDesc;
01550 int tabsize;
01551 TiXmlCursor errorLocation;
01552 bool useMicrosoftBOM;
01553 };
01554
01555
01636 class TiXmlHandle
01637 {
01638 public:
01640 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01642 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01643 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01644
01646 TiXmlHandle FirstChild() const;
01648 TiXmlHandle FirstChild( const char * value ) const;
01650 TiXmlHandle FirstChildElement() const;
01652 TiXmlHandle FirstChildElement( const char * value ) const;
01653
01657 TiXmlHandle Child( const char* value, int index ) const;
01661 TiXmlHandle Child( int index ) const;
01666 TiXmlHandle ChildElement( const char* value, int index ) const;
01671 TiXmlHandle ChildElement( int index ) const;
01672
01673 #ifdef TIXML_USE_STL
01674 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01675 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01676
01677 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01678 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01679 #endif
01680
01683 TiXmlNode* ToNode() const { return node; }
01686 TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01689 TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01692 TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01693
01697 TiXmlNode* Node() const { return ToNode(); }
01701 TiXmlElement* Element() const { return ToElement(); }
01705 TiXmlText* Text() const { return ToText(); }
01709 TiXmlUnknown* Unknown() const { return ToUnknown(); }
01710
01711 private:
01712 TiXmlNode* node;
01713 };
01714
01715
01735 class TiXmlPrinter : public TiXmlVisitor
01736 {
01737 public:
01738 TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
01739 buffer(), indent( " " ), lineBreak( "\n" ) {}
01740
01741 virtual bool VisitEnter( const TiXmlDocument& doc );
01742 virtual bool VisitExit( const TiXmlDocument& doc );
01743
01744 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
01745 virtual bool VisitExit( const TiXmlElement& element );
01746
01747 virtual bool Visit( const TiXmlDeclaration& declaration );
01748 virtual bool Visit( const TiXmlText& text );
01749 virtual bool Visit( const TiXmlComment& comment );
01750 virtual bool Visit( const TiXmlUnknown& unknown );
01751
01755 void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
01757 const char* Indent() { return indent.c_str(); }
01762 void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
01764 const char* LineBreak() { return lineBreak.c_str(); }
01765
01769 void SetStreamPrinting() { indent = "";
01770 lineBreak = "";
01771 }
01773 const char* CStr() { return buffer.c_str(); }
01775 size_t Size() { return buffer.size(); }
01776
01777 #ifdef TIXML_USE_STL
01778
01779 const std::string& Str() { return buffer; }
01780 #endif
01781
01782 private:
01783 void DoIndent() {
01784 for( int i=0; i<depth; ++i )
01785 buffer += indent;
01786 }
01787 void DoLineBreak() {
01788 buffer += lineBreak;
01789 }
01790
01791 int depth;
01792 bool simpleTextPrint;
01793 TIXML_STRING buffer;
01794 TIXML_STRING indent;
01795 TIXML_STRING lineBreak;
01796 };
01797
01798
01799 #ifdef _MSC_VER
01800 #pragma warning( pop )
01801 #endif
01802
01803 #endif
01804