00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __EDELIB_TIXML_H__
00027 #define __EDELIB_TIXML_H__
00028
00029 #include <ctype.h>
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <assert.h>
00034
00035
00036 #if defined( _DEBUG ) && !defined( DEBUG )
00037 #define DEBUG
00038 #endif
00039
00040 #ifdef TIXML_USE_STL
00041 #include <string>
00042 #include <iostream>
00043 #include <sstream>
00044 #define TIXML_STRING std::string
00045 #else
00046 #include "String.h"
00047 #define TIXML_STRING EDELIB_NS_PREPEND(String)
00048 #endif
00049
00050
00051
00052
00053
00054 #define TIXML_SAFE
00055
00056 #ifdef TIXML_SAFE
00057 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
00058
00059 #define TIXML_SNPRINTF _snprintf_s
00060 #define TIXML_SNSCANF _snscanf_s
00061 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
00062
00063
00064 #define TIXML_SNPRINTF _snprintf
00065 #define TIXML_SNSCANF _snscanf
00066 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00067
00068
00069 #define TIXML_SNPRINTF snprintf
00070 #define TIXML_SNSCANF snscanf
00071 #endif
00072 #endif
00073
00074 class TiXmlDocument;
00075 class TiXmlElement;
00076 class TiXmlComment;
00077 class TiXmlUnknown;
00078 class TiXmlAttribute;
00079 class TiXmlText;
00080 class TiXmlDeclaration;
00081 class TiXmlParsingData;
00082
00083 const int TIXML_MAJOR_VERSION = 2;
00084 const int TIXML_MINOR_VERSION = 5;
00085 const int TIXML_PATCH_VERSION = 2;
00086
00087 #ifndef SKIP_DOCS
00088
00089
00090
00091
00092 struct TiXmlCursor
00093 {
00094 TiXmlCursor() { Clear(); }
00095 void Clear() { row = col = -1; }
00096
00097 int row;
00098 int col;
00099 };
00100 #endif
00101
00123 class TiXmlVisitor
00124 {
00125 public:
00127 virtual ~TiXmlVisitor() {}
00128
00130 virtual bool VisitEnter( const TiXmlDocument& doc ) { return true; }
00132 virtual bool VisitExit( const TiXmlDocument& doc ) { return true; }
00134 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ) { return true; }
00136 virtual bool VisitExit( const TiXmlElement& element ) { return true; }
00138 virtual bool Visit( const TiXmlDeclaration& declaration ) { return true; }
00140 virtual bool Visit( const TiXmlText& text ) { return true; }
00142 virtual bool Visit( const TiXmlComment& comment ) { return true; }
00144 virtual bool Visit( const TiXmlUnknown& unknown ) { return true; }
00145 };
00146
00147
00148 enum
00149 {
00150 TIXML_SUCCESS,
00151 TIXML_NO_ATTRIBUTE,
00152 TIXML_WRONG_TYPE
00153 };
00154
00155
00156 enum TiXmlEncoding
00157 {
00158 TIXML_ENCODING_UNKNOWN,
00159 TIXML_ENCODING_UTF8,
00160 TIXML_ENCODING_LEGACY
00161 };
00162
00163 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00164
00194 class TiXmlBase
00195 {
00196 friend class TiXmlNode;
00197 friend class TiXmlElement;
00198 friend class TiXmlDocument;
00199
00200 public:
00201 TiXmlBase() : userData(0) {}
00202 virtual ~TiXmlBase() {}
00203
00214 virtual void Print( FILE* cfile, int depth ) const = 0;
00215
00223 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00224
00226 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00227
00246 int Row() const { return location.row + 1; }
00248 int Column() const { return location.col + 1; }
00250 void SetUserData( void* user ) { userData = user; }
00252 void* GetUserData() { return userData; }
00254 const void* GetUserData() const { return userData; }
00255 #ifndef SKIP_DOCS
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 #endif
00264
00265 enum
00266 {
00267 TIXML_NO_ERROR = 0,
00268 TIXML_ERROR,
00269 TIXML_ERROR_OPENING_FILE,
00270 TIXML_ERROR_OUT_OF_MEMORY,
00271 TIXML_ERROR_PARSING_ELEMENT,
00272 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00273 TIXML_ERROR_READING_ELEMENT_VALUE,
00274 TIXML_ERROR_READING_ATTRIBUTES,
00275 TIXML_ERROR_PARSING_EMPTY,
00276 TIXML_ERROR_READING_END_TAG,
00277 TIXML_ERROR_PARSING_UNKNOWN,
00278 TIXML_ERROR_PARSING_COMMENT,
00279 TIXML_ERROR_PARSING_DECLARATION,
00280 TIXML_ERROR_DOCUMENT_EMPTY,
00281 TIXML_ERROR_EMBEDDED_NULL,
00282 TIXML_ERROR_PARSING_CDATA,
00283 TIXML_ERROR_DOCUMENT_TOP_ONLY,
00284
00285 TIXML_ERROR_STRING_COUNT
00286 };
00287
00288 protected:
00289 #ifndef SKIP_DOCS
00290 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00291 inline static bool IsWhiteSpace( char c )
00292 {
00293 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00294 }
00295 inline static bool IsWhiteSpace( int c )
00296 {
00297 if ( c < 256 )
00298 return IsWhiteSpace( (char) c );
00299 return false;
00300 }
00301
00302 #ifdef TIXML_USE_STL
00303 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
00304 static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
00305 #endif
00306
00307 #endif
00308
00314 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00315
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
00328 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00329
00334 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00335 {
00336 assert( p );
00337 if ( encoding == TIXML_ENCODING_UTF8 )
00338 {
00339 *length = utf8ByteTable[ *((const unsigned char*)p) ];
00340 assert( *length >= 0 && *length < 5 );
00341 }
00342 else
00343 {
00344 *length = 1;
00345 }
00346
00347 if ( *length == 1 )
00348 {
00349 if ( *p == '&' )
00350 return GetEntity( p, _value, length, encoding );
00351 *_value = *p;
00352 return p+1;
00353 }
00354 else if ( *length )
00355 {
00356
00357
00358 for( int i=0; p[i] && i<*length; ++i ) {
00359 _value[i] = p[i];
00360 }
00361 return p + (*length);
00362 }
00363 else
00364 {
00365
00366 return 0;
00367 }
00368 }
00369
00374 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00375
00381 static bool StringEqual( const char* p,
00382 const char* endTag,
00383 bool ignoreCase,
00384 TiXmlEncoding encoding );
00385
00387 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00388
00390 TiXmlCursor location;
00391
00393 void* userData;
00394
00399 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00401 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00403 inline static int ToLower( int v, TiXmlEncoding encoding )
00404 {
00405 if ( encoding == TIXML_ENCODING_UTF8 )
00406 {
00407 if ( v < 128 ) return tolower( v );
00408 return v;
00409 }
00410 else
00411 {
00412 return tolower( v );
00413 }
00414 }
00416 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00417
00418 private:
00419 TiXmlBase( const TiXmlBase& );
00420 void operator=( const TiXmlBase& base );
00421 #ifndef SKIP_DOCS
00422 struct Entity
00423 {
00424 const char* str;
00425 unsigned int strLength;
00426 char chr;
00427 };
00428 #endif
00429 enum
00430 {
00431 NUM_ENTITY = 5,
00432 MAX_ENTITY_LENGTH = 6
00433
00434 };
00435 static Entity entity[ NUM_ENTITY ];
00436 static bool condenseWhiteSpace;
00437 };
00438
00439
00450 class EDELIB_API TiXmlNode : public TiXmlBase
00451 {
00452 friend class TiXmlDocument;
00453 friend class TiXmlElement;
00454
00455 public:
00456 #ifdef TIXML_USE_STL
00457
00462 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00463
00481 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00482
00484 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00485
00486 #endif
00487
00492 enum NodeType
00493 {
00494 DOCUMENT,
00495 ELEMENT,
00496 COMMENT,
00497 UNKNOWN,
00498 TEXT,
00499 DECLARATION,
00500 TYPECOUNT
00501 };
00502
00503 virtual ~TiXmlNode();
00504
00517 const char *Value() const { return value.c_str (); }
00518
00519 #ifdef TIXML_USE_STL
00520
00525 const std::string& ValueStr() const { return value; }
00526 #endif
00527
00538 void SetValue(const char * _value) { value = _value;}
00539
00540 #ifdef TIXML_USE_STL
00541
00542 void SetValue( const std::string& _value ) { value = _value; }
00543 #endif
00544
00546 void Clear();
00547
00549 TiXmlNode* Parent() { return parent; }
00551 const TiXmlNode* Parent() const { return parent; }
00552
00554 const TiXmlNode* FirstChild() const { return firstChild; }
00556 TiXmlNode* FirstChild() { return firstChild; }
00557
00559 const TiXmlNode* FirstChild( const char * value ) const;
00561 TiXmlNode* FirstChild( const char * _value ) {
00562
00563
00564
00565 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00566 }
00567
00569 const TiXmlNode* LastChild() const { return lastChild; }
00570
00572 TiXmlNode* LastChild() { return lastChild; }
00573
00575 const TiXmlNode* LastChild( const char * value ) const;
00576
00578 TiXmlNode* LastChild( const char * _value ) {
00579 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00580 }
00581
00582 #ifdef TIXML_USE_STL
00583
00584 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00586 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00588 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00590 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00591 #endif
00592
00610 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00611
00613 TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
00614 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00615 }
00616
00618 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00620 TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
00621 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00622 }
00623
00624 #ifdef TIXML_USE_STL
00625
00626 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const {
00627 return IterateChildren (_value.c_str (), previous);
00628 }
00629
00631 TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) {
00632 return IterateChildren (_value.c_str (), previous);
00633 }
00634 #endif
00635
00640 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00641
00652 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00653
00658 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00659
00664 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00665
00670 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00671
00675 bool RemoveChild( TiXmlNode* removeThis );
00676
00680 const TiXmlNode* PreviousSibling() const { return prev; }
00681
00685 TiXmlNode* PreviousSibling() { return prev; }
00686
00688 const TiXmlNode* PreviousSibling( const char * ) const;
00690 TiXmlNode* PreviousSibling( const char *_prev ) {
00691 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00692 }
00693
00694 #ifdef TIXML_USE_STL
00695
00696 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00698 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00700 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00702 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00703 #endif
00704
00706 const TiXmlNode* NextSibling() const { return next; }
00708 TiXmlNode* NextSibling() { return next; }
00709
00711 const TiXmlNode* NextSibling( const char * ) const;
00713 TiXmlNode* NextSibling( const char* _next ) {
00714 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
00715 }
00716
00723 const TiXmlElement* NextSiblingElement() const;
00724
00726 TiXmlElement* NextSiblingElement() {
00727 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
00728 }
00729
00736 const TiXmlElement* NextSiblingElement( const char * ) const;
00737
00739 TiXmlElement* NextSiblingElement( const char *_next ) {
00740 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00741 }
00742
00743 #ifdef TIXML_USE_STL
00744
00745 const TiXmlElement* NextSiblingElement( const std::string& _value) const {
00746 return NextSiblingElement (_value.c_str ());
00747 }
00749 TiXmlElement* NextSiblingElement( const std::string& _value) {
00750 return NextSiblingElement (_value.c_str ());
00751 }
00752 #endif
00753
00755 const TiXmlElement* FirstChildElement() const;
00757 TiXmlElement* FirstChildElement() {
00758 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00759 }
00761 const TiXmlElement* FirstChildElement( const char * _value ) const;
00763 TiXmlElement* FirstChildElement( const char * _value ) {
00764 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00765 }
00766
00767 #ifdef TIXML_USE_STL
00768
00769 const TiXmlElement* FirstChildElement( const std::string& _value ) const {
00770 return FirstChildElement (_value.c_str ());
00771 }
00772
00774 TiXmlElement* FirstChildElement( const std::string& _value ) {
00775 return FirstChildElement (_value.c_str ());
00776 }
00777 #endif
00778
00784 int Type() const { return type; }
00785
00790 const TiXmlDocument* GetDocument() const;
00791
00793 TiXmlDocument* GetDocument() {
00794 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00795 }
00796
00798 bool NoChildren() const { return !firstChild; }
00800 virtual const TiXmlDocument* ToDocument() const { return 0; }
00802 virtual const TiXmlElement* ToElement() const { return 0; }
00804 virtual const TiXmlComment* ToComment() const { return 0; }
00806 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
00808 virtual const TiXmlText* ToText() const { return 0; }
00810 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
00811
00813 virtual TiXmlDocument* ToDocument() { return 0; }
00815 virtual TiXmlElement* ToElement() { return 0; }
00817 virtual TiXmlComment* ToComment() { return 0; }
00819 virtual TiXmlUnknown* ToUnknown() { return 0; }
00821 virtual TiXmlText* ToText() { return 0; }
00823 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
00824
00829 virtual TiXmlNode* Clone() const = 0;
00830
00854 virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
00855
00856 protected:
00858 TiXmlNode( NodeType _type );
00859
00864 void CopyTo( TiXmlNode* target ) const;
00865
00866 #ifdef TIXML_USE_STL
00867
00868 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
00869 #endif
00870
00872 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00873 #ifndef SKIP_DOCS
00874 TiXmlNode* parent;
00875 NodeType type;
00876
00877 TiXmlNode* firstChild;
00878 TiXmlNode* lastChild;
00879
00880 TIXML_STRING value;
00881
00882 TiXmlNode* prev;
00883 TiXmlNode* next;
00884 #endif
00885
00886 private:
00887 TiXmlNode( const TiXmlNode& );
00888 void operator=( const TiXmlNode& base );
00889 };
00890
00891
00903 class EDELIB_API TiXmlAttribute : public TiXmlBase
00904 {
00905 friend class TiXmlAttributeSet;
00906
00907 public:
00909 TiXmlAttribute() : TiXmlBase()
00910 {
00911 document = 0;
00912 prev = next = 0;
00913 }
00914
00915 #ifdef TIXML_USE_STL
00916
00917 TiXmlAttribute( const std::string& _name, const std::string& _value )
00918 {
00919 name = _name;
00920 value = _value;
00921 document = 0;
00922 prev = next = 0;
00923 }
00924 #endif
00925
00927 TiXmlAttribute( const char * _name, const char * _value )
00928 {
00929 name = _name;
00930 value = _value;
00931 document = 0;
00932 prev = next = 0;
00933 }
00934
00936 const char* Name() const { return name.c_str(); }
00938 const char* Value() const { return value.c_str(); }
00939 #ifdef TIXML_USE_STL
00940
00941 const std::string& ValueStr() const { return value; }
00942 #endif
00943
00944 int IntValue() const;
00946 double DoubleValue() const;
00947
00949 const TIXML_STRING& NameTStr() const { return name; }
00950
00961 int QueryIntValue( int* _value ) const;
00963 int QueryDoubleValue( double* _value ) const;
00964
00966 void SetName( const char* _name ) { name = _name; }
00968 void SetValue( const char* _value ) { value = _value; }
00969
00971 void SetIntValue( int _value );
00973 void SetDoubleValue( double _value );
00974
00975 #ifdef TIXML_USE_STL
00976
00977 void SetName( const std::string& _name ) { name = _name; }
00979 void SetValue( const std::string& _value ) { value = _value; }
00980 #endif
00981
00983 const TiXmlAttribute* Next() const;
00985 TiXmlAttribute* Next() {
00986 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
00987 }
00988
00990 const TiXmlAttribute* Previous() const;
00992 TiXmlAttribute* Previous() {
00993 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
00994 }
00995
00997 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00999 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
01001 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
01002
01007 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01008
01010 virtual void Print( FILE* cfile, int depth ) const {
01011 Print( cfile, depth, 0 );
01012 }
01014 void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01015
01016 #ifndef SKIP_DOCS
01017
01018
01019 void SetDocument( TiXmlDocument* doc ) { document = doc; }
01020 #endif
01021
01022 private:
01023 TiXmlAttribute( const TiXmlAttribute& );
01024 void operator=( const TiXmlAttribute& base );
01025
01026 TiXmlDocument* document;
01027 TIXML_STRING name;
01028 TIXML_STRING value;
01029 TiXmlAttribute* prev;
01030 TiXmlAttribute* next;
01031 };
01032
01033 #ifndef SKIP_DOCS
01034
01047 class TiXmlAttributeSet
01048 {
01049 public:
01050 TiXmlAttributeSet();
01051 ~TiXmlAttributeSet();
01052
01053 void Add( TiXmlAttribute* attribute );
01054 void Remove( TiXmlAttribute* attribute );
01055
01056 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
01057 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
01058 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
01059 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
01060
01061 const TiXmlAttribute* Find( const char* _name ) const;
01062 TiXmlAttribute* Find( const char* _name ) {
01063 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
01064 }
01065 #ifdef TIXML_USE_STL
01066 const TiXmlAttribute* Find( const std::string& _name ) const;
01067 TiXmlAttribute* Find( const std::string& _name ) {
01068 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
01069 }
01070 #endif
01071
01072 private:
01073
01074
01075 TiXmlAttributeSet( const TiXmlAttributeSet& );
01076 void operator=( const TiXmlAttributeSet& );
01077
01078 TiXmlAttribute sentinel;
01079 };
01080
01081 #endif // SKIP_DOCS
01082
01083
01092 class EDELIB_API TiXmlElement : public TiXmlNode
01093 {
01094 public:
01096 TiXmlElement (const char * in_value);
01097
01098 #ifdef TIXML_USE_STL
01099
01100 TiXmlElement( const std::string& _value );
01101 #endif
01102
01104 TiXmlElement( const TiXmlElement& );
01105
01107 void operator=( const TiXmlElement& base );
01108
01110 virtual ~TiXmlElement();
01111
01116 const char* Attribute( const char* name ) const;
01117
01125 const char* Attribute( const char* name, int* i ) const;
01126
01134 const char* Attribute( const char* name, double* d ) const;
01135
01144 int QueryIntAttribute( const char* name, int* _value ) const;
01146 int QueryDoubleAttribute( const char* name, double* _value ) const;
01148 int QueryFloatAttribute( const char* name, float* _value ) const {
01149 double d;
01150 int result = QueryDoubleAttribute( name, &d );
01151 if ( result == TIXML_SUCCESS ) {
01152 *_value = (float)d;
01153 }
01154 return result;
01155 }
01156 #ifdef TIXML_USE_STL
01157
01164 template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
01165 {
01166 const TiXmlAttribute* node = attributeSet.Find( name );
01167 if ( !node )
01168 return TIXML_NO_ATTRIBUTE;
01169
01170 std::stringstream sstream( node->ValueStr() );
01171 sstream >> *outValue;
01172 if ( !sstream.fail() )
01173 return TIXML_SUCCESS;
01174 return TIXML_WRONG_TYPE;
01175 }
01176 #endif
01177
01182 void SetAttribute( const char* name, const char * _value );
01183
01184 #ifdef TIXML_USE_STL
01185
01186 const std::string* Attribute( const std::string& name ) const;
01188 const std::string* Attribute( const std::string& name, int* i ) const;
01190 const std::string* Attribute( const std::string& name, double* d ) const;
01192 int QueryIntAttribute( const std::string& name, int* _value ) const;
01194 int QueryDoubleAttribute( const std::string& name, double* _value ) const;
01195
01197 void SetAttribute( const std::string& name, const std::string& _value );
01199 void SetAttribute( const std::string& name, int _value );
01200 #endif
01201
01206 void SetAttribute( const char * name, int value );
01207
01212 void SetDoubleAttribute( const char * name, double value );
01213
01215 void RemoveAttribute( const char * name );
01216 #ifdef TIXML_USE_STL
01217
01218 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
01219 #endif
01220
01222 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
01224 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
01225
01227 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
01229 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
01230
01264 const char* GetText() const;
01265
01267 virtual TiXmlNode* Clone() const;
01269 virtual void Print( FILE* cfile, int depth ) const;
01270
01275 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01276
01278 virtual const TiXmlElement* ToElement() const { return this; }
01280 virtual TiXmlElement* ToElement() { return this; }
01281
01283 virtual bool Accept( TiXmlVisitor* visitor ) const;
01284
01285 protected:
01286 #ifndef SKIP_DOCS
01287 void CopyTo( TiXmlElement* target ) const;
01288 void ClearThis();
01289
01290
01291 #ifdef TIXML_USE_STL
01292 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01293 #endif
01294
01299 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01300 #endif
01301
01302 private:
01303
01304 TiXmlAttributeSet attributeSet;
01305 };
01306
01307
01312 class EDELIB_API TiXmlComment : public TiXmlNode
01313 {
01314 public:
01316 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01318 TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
01319 SetValue( _value );
01320 }
01322 TiXmlComment( const TiXmlComment& );
01324 void operator=( const TiXmlComment& base );
01325
01327 virtual ~TiXmlComment() {}
01328
01330 virtual TiXmlNode* Clone() const;
01332 virtual void Print( FILE* cfile, int depth ) const;
01333
01338 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01339
01341 virtual const TiXmlComment* ToComment() const { return this; }
01343 virtual TiXmlComment* ToComment() { return this; }
01344
01346 virtual bool Accept( TiXmlVisitor* visitor ) const;
01347
01348 protected:
01349 #ifndef SKIP_DOCS
01350 void CopyTo( TiXmlComment* target ) const;
01351
01352
01353 #ifdef TIXML_USE_STL
01354 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01355 #endif
01356
01357 #endif
01358
01359 };
01360
01361
01371 class EDELIB_API TiXmlText : public TiXmlNode
01372 {
01373 friend class TiXmlElement;
01374 public:
01380 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01381 {
01382 SetValue( initValue );
01383 cdata = false;
01384 }
01385 virtual ~TiXmlText() {}
01386
01387 #ifdef TIXML_USE_STL
01388
01389 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01390 {
01391 SetValue( initValue );
01392 cdata = false;
01393 }
01394 #endif
01395
01396 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01398 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01399
01401 virtual void Print( FILE* cfile, int depth ) const;
01402
01404 bool CDATA() const { return cdata; }
01406 void SetCDATA( bool _cdata ) { cdata = _cdata; }
01407
01408 #ifndef SKIP_DOCS
01409 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01410 #endif
01411
01412 virtual const TiXmlText* ToText() const { return this; }
01414 virtual TiXmlText* ToText() { return this; }
01415
01417 virtual bool Accept( TiXmlVisitor* content ) const;
01418
01419 protected :
01420 #ifndef SKIP_DOCS
01422 virtual TiXmlNode* Clone() const;
01423 void CopyTo( TiXmlText* target ) const;
01424
01425 bool Blank() const;
01426
01427 #ifdef TIXML_USE_STL
01428 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01429 #endif
01430
01431 #endif
01432
01433 private:
01434 bool cdata;
01435 };
01436
01437
01455 class EDELIB_API TiXmlDeclaration : public TiXmlNode
01456 {
01457 public:
01459 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01460
01461 #ifdef TIXML_USE_STL
01462
01463 TiXmlDeclaration( const std::string& _version,
01464 const std::string& _encoding,
01465 const std::string& _standalone );
01466 #endif
01467
01469 TiXmlDeclaration( const char* _version,
01470 const char* _encoding,
01471 const char* _standalone );
01472
01474 TiXmlDeclaration( const TiXmlDeclaration& copy );
01476 void operator=( const TiXmlDeclaration& copy );
01477
01478 #ifndef SKIP_DOCS
01479 virtual ~TiXmlDeclaration() {}
01480 #endif
01481
01483 const char *Version() const { return version.c_str (); }
01485 const char *Encoding() const { return encoding.c_str (); }
01487 const char *Standalone() const { return standalone.c_str (); }
01488
01490 virtual TiXmlNode* Clone() const;
01491
01493 virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01495 virtual void Print( FILE* cfile, int depth ) const {
01496 Print( cfile, depth, 0 );
01497 }
01498 #ifndef SKIP_DOCS
01499 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01500 #endif
01501
01502 virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
01504 virtual TiXmlDeclaration* ToDeclaration() { return this; }
01505
01507 virtual bool Accept( TiXmlVisitor* visitor ) const;
01508
01509 protected:
01510 #ifndef SKIP_DOCS
01511 void CopyTo( TiXmlDeclaration* target ) const;
01512
01513 #ifdef TIXML_USE_STL
01514 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01515 #endif
01516
01517 #endif
01518
01519 private:
01520
01521 TIXML_STRING version;
01522 TIXML_STRING encoding;
01523 TIXML_STRING standalone;
01524 };
01525
01526
01538 class TiXmlUnknown : public TiXmlNode
01539 {
01540 public:
01542 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01543 #ifndef SKIP_DOCS
01544 virtual ~TiXmlUnknown() {}
01545 #endif
01546
01548 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01550 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01551
01553 virtual TiXmlNode* Clone() const;
01555 virtual void Print( FILE* cfile, int depth ) const;
01556 #ifndef SKIP_DOCS
01557 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01558 #endif
01559
01560 virtual const TiXmlUnknown* ToUnknown() const { return this; }
01562 virtual TiXmlUnknown* ToUnknown() { return this; }
01563
01565 virtual bool Accept( TiXmlVisitor* content ) const;
01566
01567 protected:
01568 #ifndef SKIP_DOCS
01569 void CopyTo( TiXmlUnknown* target ) const;
01570
01571 #ifdef TIXML_USE_STL
01572 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01573 #endif
01574
01575 #endif
01576
01577 private:
01578
01579 };
01580
01581
01590 class EDELIB_API TiXmlDocument : public TiXmlNode
01591 {
01592 public:
01594 TiXmlDocument();
01596 TiXmlDocument( const char * documentName );
01597
01598 #ifdef TIXML_USE_STL
01599
01600 TiXmlDocument( const std::string& documentName );
01601 #endif
01602
01604 TiXmlDocument( const TiXmlDocument& copy );
01606 void operator=( const TiXmlDocument& copy );
01607
01608 #ifndef SKIP_DOCS
01609 virtual ~TiXmlDocument() {}
01610 #endif
01611
01617 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01619 bool SaveFile() const;
01621 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01623 bool SaveFile( const char * filename ) const;
01630 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01632 bool SaveFile( FILE* ) const;
01633
01634 #ifdef TIXML_USE_STL
01635
01636 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01637 {
01638 return LoadFile( filename.c_str(), encoding );
01639 }
01640
01642 bool SaveFile( const std::string& filename ) const
01643 {
01644 return SaveFile( filename.c_str() );
01645 }
01646 #endif
01647
01653 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01654
01660 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01662 TiXmlElement* RootElement() { return FirstChildElement(); }
01663
01670 bool Error() const { return error; }
01671
01673 const char * ErrorDesc() const { return errorDesc.c_str (); }
01674
01679 int ErrorId() const { return errorId; }
01680
01689 int ErrorRow() const { return errorLocation.row+1; }
01690
01692 int ErrorCol() const { return errorLocation.col+1; }
01693
01719 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01720
01722 int TabSize() const { return tabsize; }
01723
01728 void ClearError() { error = false;
01729 errorId = 0;
01730 errorDesc = "";
01731 errorLocation.row = errorLocation.col = 0;
01732
01733 }
01734
01736 void Print() const { Print( stdout, 0 ); }
01737
01743
01744
01746 virtual void Print( FILE* cfile, int depth = 0 ) const;
01747 #ifndef SKIP_DOCS
01748
01749 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01750 #endif
01751
01752 virtual const TiXmlDocument* ToDocument() const { return this; }
01754 virtual TiXmlDocument* ToDocument() { return this; }
01755
01757 virtual bool Accept( TiXmlVisitor* content ) const;
01758
01759 protected :
01760 #ifndef SKIP_DOCS
01761
01762 virtual TiXmlNode* Clone() const;
01763 #ifdef TIXML_USE_STL
01764 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01765 #endif
01766
01767 #endif
01768
01769 private:
01770 void CopyTo( TiXmlDocument* target ) const;
01771
01772 bool error;
01773 int errorId;
01774 TIXML_STRING errorDesc;
01775 int tabsize;
01776 TiXmlCursor errorLocation;
01777 bool useMicrosoftBOM;
01778 };
01779
01780
01866 class EDELIB_API TiXmlHandle
01867 {
01868 public:
01870 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01872 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01874 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01875
01877 TiXmlHandle FirstChild() const;
01879 TiXmlHandle FirstChild( const char * value ) const;
01881 TiXmlHandle FirstChildElement() const;
01883 TiXmlHandle FirstChildElement( const char * value ) const;
01884
01889 TiXmlHandle Child( const char* value, int index ) const;
01894 TiXmlHandle Child( int index ) const;
01900 TiXmlHandle ChildElement( const char* value, int index ) const;
01906 TiXmlHandle ChildElement( int index ) const;
01907
01908 #ifdef TIXML_USE_STL
01909
01910 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01912 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01913
01915 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01917 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01918 #endif
01919
01921 TiXmlNode* ToNode() const { return node; }
01923 TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01925 TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01927 TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01928
01933 TiXmlNode* Node() const { return ToNode(); }
01938 TiXmlElement* Element() const { return ToElement(); }
01943 TiXmlText* Text() const { return ToText(); }
01948 TiXmlUnknown* Unknown() const { return ToUnknown(); }
01949
01950 private:
01951 TiXmlNode* node;
01952 };
01953
01954
01978 class TiXmlPrinter : public TiXmlVisitor
01979 {
01980 public:
01982 TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
01983 buffer(), indent( " " ), lineBreak( "\n" ) {}
01984 #ifndef SKIP_DOCS
01985 virtual bool VisitEnter( const TiXmlDocument& doc );
01986 virtual bool VisitExit( const TiXmlDocument& doc );
01987
01988 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
01989 virtual bool VisitExit( const TiXmlElement& element );
01990
01991 virtual bool Visit( const TiXmlDeclaration& declaration );
01992 virtual bool Visit( const TiXmlText& text );
01993 virtual bool Visit( const TiXmlComment& comment );
01994 virtual bool Visit( const TiXmlUnknown& unknown );
01995 #endif
01996
02001 void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
02003 const char* Indent() { return indent.c_str(); }
02004
02010 void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
02011
02013 const char* LineBreak() { return lineBreak.c_str(); }
02014
02019 void SetStreamPrinting() { indent = ""; lineBreak = ""; }
02021 const char* CStr() { return buffer.c_str(); }
02023 size_t Size() { return buffer.length(); }
02024
02025 #ifdef TIXML_USE_STL
02026
02027 const std::string& Str() { return buffer; }
02028 #endif
02029
02030 private:
02031 void DoIndent() {
02032 for( int i=0; i<depth; ++i )
02033 buffer += indent;
02034 }
02035 void DoLineBreak() {
02036 buffer += lineBreak;
02037 }
02038
02039 int depth;
02040 bool simpleTextPrint;
02041 TIXML_STRING buffer;
02042 TIXML_STRING indent;
02043 TIXML_STRING lineBreak;
02044 };
02045
02046
02047 #ifdef _MSC_VER
02048 #pragma warning( pop )
02049 #endif
02050
02051 #endif