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
00028 #ifndef TIXML_USE_STL
00029 #define TIXML_USE_STL
00030 #endif
00031
00032
00033 #ifndef TINYXML_INCLUDED
00034 #define TINYXML_INCLUDED
00035
00036 #ifdef _MSC_VER
00037 #pragma warning( push )
00038 #pragma warning( disable : 4530 )
00039 #pragma warning( disable : 4786 )
00040 #endif
00041
00042 #include <ctype.h>
00043 #include <stdio.h>
00044 #include <stdlib.h>
00045 #include <string.h>
00046 #include <assert.h>
00047
00048
00049 #if defined( _DEBUG ) && !defined( DEBUG )
00050 #define DEBUG
00051 #endif
00052
00053 #ifdef TIXML_USE_STL
00054 #include <string>
00055 #include <iostream>
00056 #include <sstream>
00057 #define TIXML_STRING std::string
00058 #else
00059 #include "tinystr.h"
00060 #define TIXML_STRING TiXmlString
00061 #endif
00062
00063
00064
00065
00066
00067 #define TIXML_SAFE
00068
00069 #ifdef TIXML_SAFE
00070 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
00071
00072 #define TIXML_SNPRINTF _snprintf_s
00073 #define TIXML_SNSCANF _snscanf_s
00074 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
00075
00076
00077 #define TIXML_SNPRINTF _snprintf
00078 #define TIXML_SNSCANF _snscanf
00079 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00080
00081
00082 #define TIXML_SNPRINTF snprintf
00083 #define TIXML_SNSCANF snscanf
00084 #endif
00085 #endif
00086
00087 class TiXmlDocument;
00088 class TiXmlElement;
00089 class TiXmlComment;
00090 class TiXmlUnknown;
00091 class TiXmlAttribute;
00092 class TiXmlText;
00093 class TiXmlDeclaration;
00094 class TiXmlParsingData;
00095
00096 const int TIXML_MAJOR_VERSION = 2;
00097 const int TIXML_MINOR_VERSION = 5;
00098 const int TIXML_PATCH_VERSION = 2;
00099
00100
00101
00102
00103 struct TiXmlCursor
00104 {
00105 TiXmlCursor() { Clear(); }
00106 void Clear() { row = col = -1; }
00107
00108 int row;
00109 int col;
00110 };
00111
00112
00131 class TiXmlVisitor
00132 {
00133 public:
00134 virtual ~TiXmlVisitor() {}
00135
00137 virtual bool VisitEnter( const TiXmlDocument& doc ) { return true; }
00139 virtual bool VisitExit( const TiXmlDocument& doc ) { return true; }
00140
00142 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ) { return true; }
00144 virtual bool VisitExit( const TiXmlElement& element ) { return true; }
00145
00147 virtual bool Visit( const TiXmlDeclaration& declaration ) { return true; }
00149 virtual bool Visit( const TiXmlText& text ) { return true; }
00151 virtual bool Visit( const TiXmlComment& comment ) { return true; }
00153 virtual bool Visit( const TiXmlUnknown& unknown ) { return true; }
00154 };
00155
00156
00157 enum
00158 {
00159 TIXML_SUCCESS,
00160 TIXML_NO_ATTRIBUTE,
00161 TIXML_WRONG_TYPE
00162 };
00163
00164
00165
00166 enum TiXmlEncoding
00167 {
00168 TIXML_ENCODING_UNKNOWN,
00169 TIXML_ENCODING_UTF8,
00170 TIXML_ENCODING_LEGACY
00171 };
00172
00173 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00174
00197 class TiXmlBase
00198 {
00199 friend class TiXmlNode;
00200 friend class TiXmlElement;
00201 friend class TiXmlDocument;
00202
00203 public:
00204 TiXmlBase() : userData(0) {}
00205 virtual ~TiXmlBase() {}
00206
00216 virtual void Print( FILE* cfile, int depth ) const = 0;
00217
00224 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00225
00227 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00228
00247 int Row() const { return location.row + 1; }
00248 int Column() const { return location.col + 1; }
00249
00250 void SetUserData( void* user ) { userData = user; }
00251 void* GetUserData() { return userData; }
00252 const void* GetUserData() const { return userData; }
00253
00254
00255
00256 static const int utf8ByteTable[256];
00257
00258 virtual const char* Parse( const char* p,
00259 TiXmlParsingData* data,
00260 TiXmlEncoding encoding ) = 0;
00261
00262 enum
00263 {
00264 TIXML_NO_ERROR = 0,
00265 TIXML_ERROR,
00266 TIXML_ERROR_OPENING_FILE,
00267 TIXML_ERROR_OUT_OF_MEMORY,
00268 TIXML_ERROR_PARSING_ELEMENT,
00269 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00270 TIXML_ERROR_READING_ELEMENT_VALUE,
00271 TIXML_ERROR_READING_ATTRIBUTES,
00272 TIXML_ERROR_PARSING_EMPTY,
00273 TIXML_ERROR_READING_END_TAG,
00274 TIXML_ERROR_PARSING_UNKNOWN,
00275 TIXML_ERROR_PARSING_COMMENT,
00276 TIXML_ERROR_PARSING_DECLARATION,
00277 TIXML_ERROR_DOCUMENT_EMPTY,
00278 TIXML_ERROR_EMBEDDED_NULL,
00279 TIXML_ERROR_PARSING_CDATA,
00280 TIXML_ERROR_DOCUMENT_TOP_ONLY,
00281
00282 TIXML_ERROR_STRING_COUNT
00283 };
00284
00285 protected:
00286
00287 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00288 inline static bool IsWhiteSpace( char c )
00289 {
00290 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00291 }
00292 inline static bool IsWhiteSpace( int c )
00293 {
00294 if ( c < 256 )
00295 return IsWhiteSpace( (char) c );
00296 return false;
00297 }
00298
00299 #ifdef TIXML_USE_STL
00300 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
00301 static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
00302 #endif
00303
00304
00305
00306
00307
00308 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00309
00310
00311
00312
00313 static const char* ReadText( const char* in,
00314 TIXML_STRING* text,
00315 bool ignoreWhiteSpace,
00316 const char* endTag,
00317 bool ignoreCase,
00318 TiXmlEncoding encoding );
00319
00320
00321 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00322
00323
00324
00325 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00326 {
00327 assert( p );
00328 if ( encoding == TIXML_ENCODING_UTF8 )
00329 {
00330 *length = utf8ByteTable[ *((const unsigned char*)p) ];
00331 assert( *length >= 0 && *length < 5 );
00332 }
00333 else
00334 {
00335 *length = 1;
00336 }
00337
00338 if ( *length == 1 )
00339 {
00340 if ( *p == '&' )
00341 return GetEntity( p, _value, length, encoding );
00342 *_value = *p;
00343 return p+1;
00344 }
00345 else if ( *length )
00346 {
00347
00348
00349 for( int i=0; p[i] && i<*length; ++i ) {
00350 _value[i] = p[i];
00351 }
00352 return p + (*length);
00353 }
00354 else
00355 {
00356
00357 return 0;
00358 }
00359 }
00360
00361
00362
00363 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
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
00508 void SetValue(const char * _value) { value = _value;}
00509
00510 #ifdef TIXML_USE_STL
00511
00512 void SetValue( const std::string& _value ) { value = _value; }
00513 #endif
00514
00516 void Clear();
00517
00519 TiXmlNode* Parent() { return parent; }
00520 const TiXmlNode* Parent() const { return parent; }
00521
00522 const TiXmlNode* FirstChild() const { return firstChild; }
00523 TiXmlNode* FirstChild() { return firstChild; }
00524 const TiXmlNode* FirstChild( const char * value ) const;
00525
00526 TiXmlNode* FirstChild( const char * _value ) {
00527
00528
00529 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00530 }
00531 const TiXmlNode* LastChild() const { return lastChild; }
00532 TiXmlNode* LastChild() { return lastChild; }
00533
00534 const TiXmlNode* LastChild( const char * value ) const;
00535 TiXmlNode* LastChild( const char * _value ) {
00536 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00537 }
00538
00539 #ifdef TIXML_USE_STL
00540 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00541 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00542 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00543 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00544 #endif
00545
00562 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00563 TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
00564 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00565 }
00566
00568 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00569 TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
00570 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00571 }
00572
00573 #ifdef TIXML_USE_STL
00574 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00575 TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
00576 #endif
00577
00581 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00582
00583
00593 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00594
00598 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00599
00603 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00604
00608 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00609
00611 bool RemoveChild( TiXmlNode* removeThis );
00612
00614 const TiXmlNode* PreviousSibling() const { return prev; }
00615 TiXmlNode* PreviousSibling() { return prev; }
00616
00618 const TiXmlNode* PreviousSibling( const char * ) const;
00619 TiXmlNode* PreviousSibling( const char *_prev ) {
00620 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00621 }
00622
00623 #ifdef TIXML_USE_STL
00624 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00625 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00626 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00627 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00628 #endif
00629
00631 const TiXmlNode* NextSibling() const { return next; }
00632 TiXmlNode* NextSibling() { return next; }
00633
00635 const TiXmlNode* NextSibling( const char * ) const;
00636 TiXmlNode* NextSibling( const char* _next ) {
00637 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
00638 }
00639
00644 const TiXmlElement* NextSiblingElement() const;
00645 TiXmlElement* NextSiblingElement() {
00646 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
00647 }
00648
00653 const TiXmlElement* NextSiblingElement( const char * ) const;
00654 TiXmlElement* NextSiblingElement( const char *_next ) {
00655 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00656 }
00657
00658 #ifdef TIXML_USE_STL
00659 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00660 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
00661 #endif
00662
00664 const TiXmlElement* FirstChildElement() const;
00665 TiXmlElement* FirstChildElement() {
00666 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00667 }
00668
00670 const TiXmlElement* FirstChildElement( const char * _value ) const;
00671 TiXmlElement* FirstChildElement( const char * _value ) {
00672 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00673 }
00674
00675 #ifdef TIXML_USE_STL
00676 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00677 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
00678 #endif
00679
00684 int Type() const { return type; }
00685
00689 const TiXmlDocument* GetDocument() const;
00690 TiXmlDocument* GetDocument() {
00691 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00692 }
00693
00695 bool NoChildren() const { return !firstChild; }
00696
00697 virtual const TiXmlDocument* ToDocument() const { return 0; }
00698 virtual const TiXmlElement* ToElement() const { return 0; }
00699 virtual const TiXmlComment* ToComment() const { return 0; }
00700 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
00701 virtual const TiXmlText* ToText() const { return 0; }
00702 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
00703
00704 virtual TiXmlDocument* ToDocument() { return 0; }
00705 virtual TiXmlElement* ToElement() { return 0; }
00706 virtual TiXmlComment* ToComment() { return 0; }
00707 virtual TiXmlUnknown* ToUnknown() { return 0; }
00708 virtual TiXmlText* ToText() { return 0; }
00709 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
00710
00714 virtual TiXmlNode* Clone() const = 0;
00715
00738 virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
00739
00740 protected:
00741 TiXmlNode( NodeType _type );
00742
00743
00744
00745 void CopyTo( TiXmlNode* target ) const;
00746
00747 #ifdef TIXML_USE_STL
00748
00749 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
00750 #endif
00751
00752
00753 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00754
00755 TiXmlNode* parent;
00756 NodeType type;
00757
00758 TiXmlNode* firstChild;
00759 TiXmlNode* lastChild;
00760
00761 TIXML_STRING value;
00762
00763 TiXmlNode* prev;
00764 TiXmlNode* next;
00765
00766 private:
00767 TiXmlNode( const TiXmlNode& );
00768 void operator=( const TiXmlNode& base );
00769 };
00770
00771
00779 class TiXmlAttribute : public TiXmlBase
00780 {
00781 friend class TiXmlAttributeSet;
00782
00783 public:
00785 TiXmlAttribute() : TiXmlBase()
00786 {
00787 document = 0;
00788 prev = next = 0;
00789 }
00790
00791 #ifdef TIXML_USE_STL
00792
00793 TiXmlAttribute( const std::string& _name, const std::string& _value )
00794 {
00795 name = _name;
00796 value = _value;
00797 document = 0;
00798 prev = next = 0;
00799 }
00800 #endif
00801
00803 TiXmlAttribute( const char * _name, const char * _value )
00804 {
00805 name = _name;
00806 value = _value;
00807 document = 0;
00808 prev = next = 0;
00809 }
00810
00811 const char* Name() const { return name.c_str(); }
00812 const char* Value() const { return value.c_str(); }
00813 #ifdef TIXML_USE_STL
00814 const std::string& ValueStr() const { return value; }
00815 #endif
00816 int IntValue() const;
00817 double DoubleValue() const;
00818
00819
00820 const TIXML_STRING& NameTStr() const { return name; }
00821
00831 int QueryIntValue( int* _value ) const;
00833 int QueryDoubleValue( double* _value ) const;
00834
00835 void SetName( const char* _name ) { name = _name; }
00836 void SetValue( const char* _value ) { value = _value; }
00837
00838 void SetIntValue( int _value );
00839 void SetDoubleValue( double _value );
00840
00841 #ifdef TIXML_USE_STL
00842
00843 void SetName( const std::string& _name ) { name = _name; }
00845 void SetValue( const std::string& _value ) { value = _value; }
00846 #endif
00847
00849 const TiXmlAttribute* Next() const;
00850 TiXmlAttribute* Next() {
00851 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
00852 }
00853
00855 const TiXmlAttribute* Previous() const;
00856 TiXmlAttribute* Previous() {
00857 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
00858 }
00859
00860 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00861 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00862 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00863
00864
00865
00866
00867 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00868
00869
00870 virtual void Print( FILE* cfile, int depth ) const {
00871 Print( cfile, depth, 0 );
00872 }
00873 void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
00874
00875
00876
00877 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00878
00879 private:
00880 TiXmlAttribute( const TiXmlAttribute& );
00881 void operator=( const TiXmlAttribute& base );
00882
00883 TiXmlDocument* document;
00884 TIXML_STRING name;
00885 TIXML_STRING value;
00886 TiXmlAttribute* prev;
00887 TiXmlAttribute* next;
00888 };
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903 class TiXmlAttributeSet
00904 {
00905 public:
00906 TiXmlAttributeSet();
00907 ~TiXmlAttributeSet();
00908
00909 void Add( TiXmlAttribute* attribute );
00910 void Remove( TiXmlAttribute* attribute );
00911
00912 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00913 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00914 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00915 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00916
00917 const TiXmlAttribute* Find( const char* _name ) const;
00918 TiXmlAttribute* Find( const char* _name ) {
00919 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00920 }
00921 #ifdef TIXML_USE_STL
00922 const TiXmlAttribute* Find( const std::string& _name ) const;
00923 TiXmlAttribute* Find( const std::string& _name ) {
00924 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00925 }
00926
00927 #endif
00928
00929 private:
00930
00931
00932 TiXmlAttributeSet( const TiXmlAttributeSet& );
00933 void operator=( const TiXmlAttributeSet& );
00934
00935 TiXmlAttribute sentinel;
00936 };
00937
00938
00943 class TiXmlElement : public TiXmlNode
00944 {
00945 public:
00947 TiXmlElement (const char * in_value);
00948
00949 #ifdef TIXML_USE_STL
00950
00951 TiXmlElement( const std::string& _value );
00952 #endif
00953
00954 TiXmlElement( const TiXmlElement& );
00955
00956 void operator=( const TiXmlElement& base );
00957
00958 virtual ~TiXmlElement();
00959
00963 const char* Attribute( const char* name ) const;
00964
00971 const char* Attribute( const char* name, int* i ) const;
00972
00979 const char* Attribute( const char* name, double* d ) const;
00980
00988 int QueryIntAttribute( const char* name, int* _value ) const;
00990 int QueryDoubleAttribute( const char* name, double* _value ) const;
00992 int QueryFloatAttribute( const char* name, float* _value ) const {
00993 double d;
00994 int result = QueryDoubleAttribute( name, &d );
00995 if ( result == TIXML_SUCCESS ) {
00996 *_value = (float)d;
00997 }
00998 return result;
00999 }
01000 #ifdef TIXML_USE_STL
01001
01007 template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
01008 {
01009 const TiXmlAttribute* node = attributeSet.Find( name );
01010 if ( !node )
01011 return TIXML_NO_ATTRIBUTE;
01012
01013 std::stringstream sstream( node->ValueStr() );
01014 sstream >> *outValue;
01015 if ( !sstream.fail() )
01016 return TIXML_SUCCESS;
01017 return TIXML_WRONG_TYPE;
01018 }
01019 #endif
01020
01024 void SetAttribute( const char* name, const char * _value );
01025
01026 #ifdef TIXML_USE_STL
01027 const std::string* Attribute( const std::string& name ) const;
01028 const std::string* Attribute( const std::string& name, int* i ) const;
01029 const std::string* Attribute( const std::string& name, double* d ) const;
01030 int QueryIntAttribute( const std::string& name, int* _value ) const;
01031 int QueryDoubleAttribute( const std::string& name, double* _value ) const;
01032
01034 void SetAttribute( const std::string& name, const std::string& _value );
01036 void SetAttribute( const std::string& name, int _value );
01037 #endif
01038
01042 void SetAttribute( const char * name, int value );
01043
01047 void SetDoubleAttribute( const char * name, double value );
01048
01051 void RemoveAttribute( const char * name );
01052 #ifdef TIXML_USE_STL
01053 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
01054 #endif
01055
01056 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
01057 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
01058 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
01059 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
01060
01093 const char* GetText() const;
01094
01096 virtual TiXmlNode* Clone() const;
01097
01098 virtual void Print( FILE* cfile, int depth ) const;
01099
01100
01101
01102
01103 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01104
01105 virtual const TiXmlElement* ToElement() const { return this; }
01106 virtual TiXmlElement* ToElement() { return this; }
01107
01110 virtual bool Accept( TiXmlVisitor* visitor ) const;
01111
01112 protected:
01113
01114 void CopyTo( TiXmlElement* target ) const;
01115 void ClearThis();
01116
01117
01118 #ifdef TIXML_USE_STL
01119 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01120 #endif
01121
01122
01123
01124
01125 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01126
01127 private:
01128
01129 TiXmlAttributeSet attributeSet;
01130 };
01131
01132
01135 class TiXmlComment : public TiXmlNode
01136 {
01137 public:
01139 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01141 TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
01142 SetValue( _value );
01143 }
01144 TiXmlComment( const TiXmlComment& );
01145 void operator=( const TiXmlComment& base );
01146
01147 virtual ~TiXmlComment() {}
01148
01150 virtual TiXmlNode* Clone() const;
01151
01152 virtual void Print( FILE* cfile, int depth ) const;
01153
01154
01155
01156
01157 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01158
01159 virtual const TiXmlComment* ToComment() const { return this; }
01160 virtual TiXmlComment* ToComment() { return this; }
01161
01164 virtual bool Accept( TiXmlVisitor* visitor ) const;
01165
01166 protected:
01167 void CopyTo( TiXmlComment* target ) const;
01168
01169
01170 #ifdef TIXML_USE_STL
01171 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01172 #endif
01173
01174
01175 private:
01176
01177 };
01178
01179
01185 class TiXmlText : public TiXmlNode
01186 {
01187 friend class TiXmlElement;
01188 public:
01193 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01194 {
01195 SetValue( initValue );
01196 cdata = false;
01197 }
01198 virtual ~TiXmlText() {}
01199
01200 #ifdef TIXML_USE_STL
01201
01202 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01203 {
01204 SetValue( initValue );
01205 cdata = false;
01206 }
01207 #endif
01208
01209 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01210 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01211
01212
01213 virtual void Print( FILE* cfile, int depth ) const;
01214
01216 bool CDATA() const { return cdata; }
01218 void SetCDATA( bool _cdata ) { cdata = _cdata; }
01219
01220 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01221
01222 virtual const TiXmlText* ToText() const { return this; }
01223 virtual TiXmlText* ToText() { return this; }
01224
01227 virtual bool Accept( TiXmlVisitor* content ) const;
01228
01229 protected :
01231 virtual TiXmlNode* Clone() const;
01232 void CopyTo( TiXmlText* target ) const;
01233
01234 bool Blank() const;
01235
01236 #ifdef TIXML_USE_STL
01237 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01238 #endif
01239
01240 private:
01241 bool cdata;
01242 };
01243
01244
01258 class TiXmlDeclaration : public TiXmlNode
01259 {
01260 public:
01262 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01263
01264 #ifdef TIXML_USE_STL
01265
01266 TiXmlDeclaration( const std::string& _version,
01267 const std::string& _encoding,
01268 const std::string& _standalone );
01269 #endif
01270
01272 TiXmlDeclaration( const char* _version,
01273 const char* _encoding,
01274 const char* _standalone );
01275
01276 TiXmlDeclaration( const TiXmlDeclaration& copy );
01277 void operator=( const TiXmlDeclaration& copy );
01278
01279 virtual ~TiXmlDeclaration() {}
01280
01282 const char *Version() const { return version.c_str (); }
01284 const char *Encoding() const { return encoding.c_str (); }
01286 const char *Standalone() const { return standalone.c_str (); }
01287
01289 virtual TiXmlNode* Clone() const;
01290
01291 virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01292 virtual void Print( FILE* cfile, int depth ) const {
01293 Print( cfile, depth, 0 );
01294 }
01295
01296 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01297
01298 virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
01299 virtual TiXmlDeclaration* ToDeclaration() { return this; }
01300
01303 virtual bool Accept( TiXmlVisitor* visitor ) const;
01304
01305 protected:
01306 void CopyTo( TiXmlDeclaration* target ) const;
01307
01308 #ifdef TIXML_USE_STL
01309 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01310 #endif
01311
01312 private:
01313
01314 TIXML_STRING version;
01315 TIXML_STRING encoding;
01316 TIXML_STRING standalone;
01317 };
01318
01319
01327 class TiXmlUnknown : public TiXmlNode
01328 {
01329 public:
01330 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01331 virtual ~TiXmlUnknown() {}
01332
01333 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01334 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01335
01337 virtual TiXmlNode* Clone() const;
01338
01339 virtual void Print( FILE* cfile, int depth ) const;
01340
01341 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01342
01343 virtual const TiXmlUnknown* ToUnknown() const { return this; }
01344 virtual TiXmlUnknown* ToUnknown() { return this; }
01345
01348 virtual bool Accept( TiXmlVisitor* content ) const;
01349
01350 protected:
01351 void CopyTo( TiXmlUnknown* target ) const;
01352
01353 #ifdef TIXML_USE_STL
01354 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01355 #endif
01356
01357 private:
01358
01359 };
01360
01361
01366 class TiXmlDocument : public TiXmlNode
01367 {
01368 public:
01370 TiXmlDocument();
01372 TiXmlDocument( const char * documentName );
01373
01374 #ifdef TIXML_USE_STL
01375
01376 TiXmlDocument( const std::string& documentName );
01377 #endif
01378
01379 TiXmlDocument( const TiXmlDocument& copy );
01380 void operator=( const TiXmlDocument& copy );
01381
01382 virtual ~TiXmlDocument() {}
01383
01388 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01390 bool SaveFile() const;
01392 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01394 bool SaveFile( const char * filename ) const;
01400 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01402 bool SaveFile( FILE* ) const;
01403
01404 #ifdef TIXML_USE_STL
01405 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01406 {
01407
01408
01409 return LoadFile( filename.c_str(), encoding );
01410 }
01411 bool SaveFile( const std::string& filename ) const
01412 {
01413
01414
01415 return SaveFile( filename.c_str() );
01416 }
01417 #endif
01418
01423 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01424
01429 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01430 TiXmlElement* RootElement() { return FirstChildElement(); }
01431
01437 bool Error() const { return error; }
01438
01440 const char * ErrorDesc() const { return errorDesc.c_str (); }
01441
01445 int ErrorId() const { return errorId; }
01446
01454 int ErrorRow() const { return errorLocation.row+1; }
01455 int ErrorCol() const { return errorLocation.col+1; }
01456
01481 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01482
01483 int TabSize() const { return tabsize; }
01484
01488 void ClearError() { error = false;
01489 errorId = 0;
01490 errorDesc = "";
01491 errorLocation.row = errorLocation.col = 0;
01492
01493 }
01494
01496 void Print() const { Print( stdout, 0 ); }
01497
01498
01499
01500
01501
01502
01503
01505 virtual void Print( FILE* cfile, int depth = 0 ) const;
01506
01507 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01508
01509 virtual const TiXmlDocument* ToDocument() const { return this; }
01510 virtual TiXmlDocument* ToDocument() { return this; }
01511
01514 virtual bool Accept( TiXmlVisitor* content ) const;
01515
01516 protected :
01517
01518 virtual TiXmlNode* Clone() const;
01519 #ifdef TIXML_USE_STL
01520 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01521 #endif
01522
01523 private:
01524 void CopyTo( TiXmlDocument* target ) const;
01525
01526 bool error;
01527 int errorId;
01528 TIXML_STRING errorDesc;
01529 int tabsize;
01530 TiXmlCursor errorLocation;
01531 bool useMicrosoftBOM;
01532 };
01533
01534
01615 class TiXmlHandle
01616 {
01617 public:
01619 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01621 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01622 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01623
01625 TiXmlHandle FirstChild() const;
01627 TiXmlHandle FirstChild( const char * value ) const;
01629 TiXmlHandle FirstChildElement() const;
01631 TiXmlHandle FirstChildElement( const char * value ) const;
01632
01636 TiXmlHandle Child( const char* value, int index ) const;
01640 TiXmlHandle Child( int index ) const;
01645 TiXmlHandle ChildElement( const char* value, int index ) const;
01650 TiXmlHandle ChildElement( int index ) const;
01651
01652 #ifdef TIXML_USE_STL
01653 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01654 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01655
01656 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01657 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01658 #endif
01659
01662 TiXmlNode* ToNode() const { return node; }
01665 TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01668 TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01671 TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01672
01676 TiXmlNode* Node() const { return ToNode(); }
01680 TiXmlElement* Element() const { return ToElement(); }
01684 TiXmlText* Text() const { return ToText(); }
01688 TiXmlUnknown* Unknown() const { return ToUnknown(); }
01689
01690 private:
01691 TiXmlNode* node;
01692 };
01693
01694
01714 class TiXmlPrinter : public TiXmlVisitor
01715 {
01716 public:
01717 TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
01718 buffer(), indent( " " ), lineBreak( "\n" ) {}
01719
01720 virtual bool VisitEnter( const TiXmlDocument& doc );
01721 virtual bool VisitExit( const TiXmlDocument& doc );
01722
01723 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
01724 virtual bool VisitExit( const TiXmlElement& element );
01725
01726 virtual bool Visit( const TiXmlDeclaration& declaration );
01727 virtual bool Visit( const TiXmlText& text );
01728 virtual bool Visit( const TiXmlComment& comment );
01729 virtual bool Visit( const TiXmlUnknown& unknown );
01730
01734 void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
01736 const char* Indent() { return indent.c_str(); }
01741 void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
01743 const char* LineBreak() { return lineBreak.c_str(); }
01744
01748 void SetStreamPrinting() { indent = "";
01749 lineBreak = "";
01750 }
01752 const char* CStr() { return buffer.c_str(); }
01754 size_t Size() { return buffer.size(); }
01755
01756 #ifdef TIXML_USE_STL
01757
01758 const std::string& Str() { return buffer; }
01759 #endif
01760
01761 private:
01762 void DoIndent() {
01763 for( int i=0; i<depth; ++i )
01764 buffer += indent;
01765 }
01766 void DoLineBreak() {
01767 buffer += lineBreak;
01768 }
01769
01770 int depth;
01771 bool simpleTextPrint;
01772 TIXML_STRING buffer;
01773 TIXML_STRING indent;
01774 TIXML_STRING lineBreak;
01775 };
01776
01777
01778 #ifdef _MSC_VER
01779 #pragma warning( pop )
01780 #endif
01781
01782 #endif
01783