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
00422 struct Entity
00423 {
00424 const char* str;
00425 unsigned int strLength;
00426 char chr;
00427 };
00428 enum
00429 {
00430 NUM_ENTITY = 5,
00431 MAX_ENTITY_LENGTH = 6
00432
00433 };
00434 static Entity entity[ NUM_ENTITY ];
00435 static bool condenseWhiteSpace;
00436 };
00437
00438
00449 class EDELIB_API TiXmlNode : public TiXmlBase
00450 {
00451 friend class TiXmlDocument;
00452 friend class TiXmlElement;
00453
00454 public:
00455 #ifdef TIXML_USE_STL
00456
00461 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00462
00480 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00481
00483 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00484
00485 #endif
00486
00491 enum NodeType
00492 {
00493 DOCUMENT,
00494 ELEMENT,
00495 COMMENT,
00496 UNKNOWN,
00497 TEXT,
00498 DECLARATION,
00499 TYPECOUNT
00500 };
00501
00502 virtual ~TiXmlNode();
00503
00516 const char *Value() const { return value.c_str (); }
00517
00518 #ifdef TIXML_USE_STL
00519
00524 const std::string& ValueStr() const { return value; }
00525 #endif
00526
00537 void SetValue(const char * _value) { value = _value;}
00538
00539 #ifdef TIXML_USE_STL
00540
00541 void SetValue( const std::string& _value ) { value = _value; }
00542 #endif
00543
00545 void Clear();
00546
00548 TiXmlNode* Parent() { return parent; }
00550 const TiXmlNode* Parent() const { return parent; }
00551
00553 const TiXmlNode* FirstChild() const { return firstChild; }
00555 TiXmlNode* FirstChild() { return firstChild; }
00556
00558 const TiXmlNode* FirstChild( const char * value ) const;
00560 TiXmlNode* FirstChild( const char * _value ) {
00561
00562
00563
00564 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00565 }
00566
00568 const TiXmlNode* LastChild() const { return lastChild; }
00569
00571 TiXmlNode* LastChild() { return lastChild; }
00572
00574 const TiXmlNode* LastChild( const char * value ) const;
00575
00577 TiXmlNode* LastChild( const char * _value ) {
00578 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00579 }
00580
00581 #ifdef TIXML_USE_STL
00582
00583 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00585 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00587 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00589 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00590 #endif
00591
00609 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00610
00612 TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
00613 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00614 }
00615
00617 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00619 TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
00620 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00621 }
00622
00623 #ifdef TIXML_USE_STL
00624
00625 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const {
00626 return IterateChildren (_value.c_str (), previous);
00627 }
00628
00630 TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) {
00631 return IterateChildren (_value.c_str (), previous);
00632 }
00633 #endif
00634
00639 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00640
00651 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00652
00657 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00658
00663 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00664
00669 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00670
00674 bool RemoveChild( TiXmlNode* removeThis );
00675
00679 const TiXmlNode* PreviousSibling() const { return prev; }
00680
00684 TiXmlNode* PreviousSibling() { return prev; }
00685
00687 const TiXmlNode* PreviousSibling( const char * ) const;
00689 TiXmlNode* PreviousSibling( const char *_prev ) {
00690 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00691 }
00692
00693 #ifdef TIXML_USE_STL
00694
00695 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00697 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00699 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00701 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00702 #endif
00703
00705 const TiXmlNode* NextSibling() const { return next; }
00707 TiXmlNode* NextSibling() { return next; }
00708
00710 const TiXmlNode* NextSibling( const char * ) const;
00712 TiXmlNode* NextSibling( const char* _next ) {
00713 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
00714 }
00715
00722 const TiXmlElement* NextSiblingElement() const;
00723
00725 TiXmlElement* NextSiblingElement() {
00726 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
00727 }
00728
00735 const TiXmlElement* NextSiblingElement( const char * ) const;
00736
00738 TiXmlElement* NextSiblingElement( const char *_next ) {
00739 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00740 }
00741
00742 #ifdef TIXML_USE_STL
00743
00744 const TiXmlElement* NextSiblingElement( const std::string& _value) const {
00745 return NextSiblingElement (_value.c_str ());
00746 }
00748 TiXmlElement* NextSiblingElement( const std::string& _value) {
00749 return NextSiblingElement (_value.c_str ());
00750 }
00751 #endif
00752
00754 const TiXmlElement* FirstChildElement() const;
00756 TiXmlElement* FirstChildElement() {
00757 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00758 }
00760 const TiXmlElement* FirstChildElement( const char * _value ) const;
00762 TiXmlElement* FirstChildElement( const char * _value ) {
00763 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00764 }
00765
00766 #ifdef TIXML_USE_STL
00767
00768 const TiXmlElement* FirstChildElement( const std::string& _value ) const {
00769 return FirstChildElement (_value.c_str ());
00770 }
00771
00773 TiXmlElement* FirstChildElement( const std::string& _value ) {
00774 return FirstChildElement (_value.c_str ());
00775 }
00776 #endif
00777
00783 int Type() const { return type; }
00784
00789 const TiXmlDocument* GetDocument() const;
00790
00792 TiXmlDocument* GetDocument() {
00793 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00794 }
00795
00797 bool NoChildren() const { return !firstChild; }
00799 virtual const TiXmlDocument* ToDocument() const { return 0; }
00801 virtual const TiXmlElement* ToElement() const { return 0; }
00803 virtual const TiXmlComment* ToComment() const { return 0; }
00805 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
00807 virtual const TiXmlText* ToText() const { return 0; }
00809 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
00810
00812 virtual TiXmlDocument* ToDocument() { return 0; }
00814 virtual TiXmlElement* ToElement() { return 0; }
00816 virtual TiXmlComment* ToComment() { return 0; }
00818 virtual TiXmlUnknown* ToUnknown() { return 0; }
00820 virtual TiXmlText* ToText() { return 0; }
00822 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
00823
00828 virtual TiXmlNode* Clone() const = 0;
00829
00853 virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
00854
00855 protected:
00857 TiXmlNode( NodeType _type );
00858
00863 void CopyTo( TiXmlNode* target ) const;
00864
00865 #ifdef TIXML_USE_STL
00866
00867 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
00868 #endif
00869
00871 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00872 #ifndef SKIP_DOCS
00873 TiXmlNode* parent;
00874 NodeType type;
00875
00876 TiXmlNode* firstChild;
00877 TiXmlNode* lastChild;
00878
00879 TIXML_STRING value;
00880
00881 TiXmlNode* prev;
00882 TiXmlNode* next;
00883 #endif
00884
00885 private:
00886 TiXmlNode( const TiXmlNode& );
00887 void operator=( const TiXmlNode& base );
00888 };
00889
00890
00902 class EDELIB_API TiXmlAttribute : public TiXmlBase
00903 {
00904 friend class TiXmlAttributeSet;
00905
00906 public:
00908 TiXmlAttribute() : TiXmlBase()
00909 {
00910 document = 0;
00911 prev = next = 0;
00912 }
00913
00914 #ifdef TIXML_USE_STL
00915
00916 TiXmlAttribute( const std::string& _name, const std::string& _value )
00917 {
00918 name = _name;
00919 value = _value;
00920 document = 0;
00921 prev = next = 0;
00922 }
00923 #endif
00924
00926 TiXmlAttribute( const char * _name, const char * _value )
00927 {
00928 name = _name;
00929 value = _value;
00930 document = 0;
00931 prev = next = 0;
00932 }
00933
00935 const char* Name() const { return name.c_str(); }
00937 const char* Value() const { return value.c_str(); }
00938 #ifdef TIXML_USE_STL
00939
00940 const std::string& ValueStr() const { return value; }
00941 #endif
00942
00943 int IntValue() const;
00945 double DoubleValue() const;
00946
00948 const TIXML_STRING& NameTStr() const { return name; }
00949
00960 int QueryIntValue( int* _value ) const;
00962 int QueryDoubleValue( double* _value ) const;
00963
00965 void SetName( const char* _name ) { name = _name; }
00967 void SetValue( const char* _value ) { value = _value; }
00968
00970 void SetIntValue( int _value );
00972 void SetDoubleValue( double _value );
00973
00974 #ifdef TIXML_USE_STL
00975
00976 void SetName( const std::string& _name ) { name = _name; }
00978 void SetValue( const std::string& _value ) { value = _value; }
00979 #endif
00980
00982 const TiXmlAttribute* Next() const;
00984 TiXmlAttribute* Next() {
00985 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
00986 }
00987
00989 const TiXmlAttribute* Previous() const;
00991 TiXmlAttribute* Previous() {
00992 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
00993 }
00994
00996 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00998 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
01000 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
01001
01006 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01007
01009 virtual void Print( FILE* cfile, int depth ) const {
01010 Print( cfile, depth, 0 );
01011 }
01013 void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01014
01015 #ifndef SKIP_DOCS
01016
01017
01018 void SetDocument( TiXmlDocument* doc ) { document = doc; }
01019 #endif
01020
01021 private:
01022 TiXmlAttribute( const TiXmlAttribute& );
01023 void operator=( const TiXmlAttribute& base );
01024
01025 TiXmlDocument* document;
01026 TIXML_STRING name;
01027 TIXML_STRING value;
01028 TiXmlAttribute* prev;
01029 TiXmlAttribute* next;
01030 };
01031
01032 #ifndef SKIP_DOCS
01033
01046 class TiXmlAttributeSet
01047 {
01048 public:
01049 TiXmlAttributeSet();
01050 ~TiXmlAttributeSet();
01051
01052 void Add( TiXmlAttribute* attribute );
01053 void Remove( TiXmlAttribute* attribute );
01054
01055 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
01056 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
01057 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
01058 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
01059
01060 const TiXmlAttribute* Find( const char* _name ) const;
01061 TiXmlAttribute* Find( const char* _name ) {
01062 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
01063 }
01064 #ifdef TIXML_USE_STL
01065 const TiXmlAttribute* Find( const std::string& _name ) const;
01066 TiXmlAttribute* Find( const std::string& _name ) {
01067 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
01068 }
01069 #endif
01070
01071 private:
01072
01073
01074 TiXmlAttributeSet( const TiXmlAttributeSet& );
01075 void operator=( const TiXmlAttributeSet& );
01076
01077 TiXmlAttribute sentinel;
01078 };
01079
01080 #endif // SKIP_DOCS
01081
01082
01091 class EDELIB_API TiXmlElement : public TiXmlNode
01092 {
01093 public:
01095 TiXmlElement (const char * in_value);
01096
01097 #ifdef TIXML_USE_STL
01098
01099 TiXmlElement( const std::string& _value );
01100 #endif
01101
01103 TiXmlElement( const TiXmlElement& );
01104
01106 void operator=( const TiXmlElement& base );
01107
01109 virtual ~TiXmlElement();
01110
01115 const char* Attribute( const char* name ) const;
01116
01124 const char* Attribute( const char* name, int* i ) const;
01125
01133 const char* Attribute( const char* name, double* d ) const;
01134
01143 int QueryIntAttribute( const char* name, int* _value ) const;
01145 int QueryDoubleAttribute( const char* name, double* _value ) const;
01147 int QueryFloatAttribute( const char* name, float* _value ) const {
01148 double d;
01149 int result = QueryDoubleAttribute( name, &d );
01150 if ( result == TIXML_SUCCESS ) {
01151 *_value = (float)d;
01152 }
01153 return result;
01154 }
01155 #ifdef TIXML_USE_STL
01156
01163 template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
01164 {
01165 const TiXmlAttribute* node = attributeSet.Find( name );
01166 if ( !node )
01167 return TIXML_NO_ATTRIBUTE;
01168
01169 std::stringstream sstream( node->ValueStr() );
01170 sstream >> *outValue;
01171 if ( !sstream.fail() )
01172 return TIXML_SUCCESS;
01173 return TIXML_WRONG_TYPE;
01174 }
01175 #endif
01176
01181 void SetAttribute( const char* name, const char * _value );
01182
01183 #ifdef TIXML_USE_STL
01184
01185 const std::string* Attribute( const std::string& name ) const;
01187 const std::string* Attribute( const std::string& name, int* i ) const;
01189 const std::string* Attribute( const std::string& name, double* d ) const;
01191 int QueryIntAttribute( const std::string& name, int* _value ) const;
01193 int QueryDoubleAttribute( const std::string& name, double* _value ) const;
01194
01196 void SetAttribute( const std::string& name, const std::string& _value );
01198 void SetAttribute( const std::string& name, int _value );
01199 #endif
01200
01205 void SetAttribute( const char * name, int value );
01206
01211 void SetDoubleAttribute( const char * name, double value );
01212
01214 void RemoveAttribute( const char * name );
01215 #ifdef TIXML_USE_STL
01216
01217 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
01218 #endif
01219
01221 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
01223 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
01224
01226 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
01228 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
01229
01263 const char* GetText() const;
01264
01266 virtual TiXmlNode* Clone() const;
01268 virtual void Print( FILE* cfile, int depth ) const;
01269
01274 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01275
01277 virtual const TiXmlElement* ToElement() const { return this; }
01279 virtual TiXmlElement* ToElement() { return this; }
01280
01282 virtual bool Accept( TiXmlVisitor* visitor ) const;
01283
01284 protected:
01285 #ifndef SKIP_DOCS
01286 void CopyTo( TiXmlElement* target ) const;
01287 void ClearThis();
01288
01289
01290 #ifdef TIXML_USE_STL
01291 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01292 #endif
01293
01298 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01299 #endif
01300
01301 private:
01302
01303 TiXmlAttributeSet attributeSet;
01304 };
01305
01306
01311 class EDELIB_API TiXmlComment : public TiXmlNode
01312 {
01313 public:
01315 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01317 TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
01318 SetValue( _value );
01319 }
01321 TiXmlComment( const TiXmlComment& );
01323 void operator=( const TiXmlComment& base );
01324
01326 virtual ~TiXmlComment() {}
01327
01329 virtual TiXmlNode* Clone() const;
01331 virtual void Print( FILE* cfile, int depth ) const;
01332
01337 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01338
01340 virtual const TiXmlComment* ToComment() const { return this; }
01342 virtual TiXmlComment* ToComment() { return this; }
01343
01345 virtual bool Accept( TiXmlVisitor* visitor ) const;
01346
01347 protected:
01348 #ifndef SKIP_DOCS
01349 void CopyTo( TiXmlComment* target ) const;
01350
01351
01352 #ifdef TIXML_USE_STL
01353 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01354 #endif
01355
01356 #endif
01357
01358 };
01359
01360
01370 class EDELIB_API TiXmlText : public TiXmlNode
01371 {
01372 friend class TiXmlElement;
01373 public:
01379 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01380 {
01381 SetValue( initValue );
01382 cdata = false;
01383 }
01384 virtual ~TiXmlText() {}
01385
01386 #ifdef TIXML_USE_STL
01387
01388 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01389 {
01390 SetValue( initValue );
01391 cdata = false;
01392 }
01393 #endif
01394
01395 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01397 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01398
01400 virtual void Print( FILE* cfile, int depth ) const;
01401
01403 bool CDATA() const { return cdata; }
01405 void SetCDATA( bool _cdata ) { cdata = _cdata; }
01406
01407 #ifndef SKIP_DOCS
01408 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01409 #endif
01410
01411 virtual const TiXmlText* ToText() const { return this; }
01413 virtual TiXmlText* ToText() { return this; }
01414
01416 virtual bool Accept( TiXmlVisitor* content ) const;
01417
01418 protected :
01419 #ifndef SKIP_DOCS
01421 virtual TiXmlNode* Clone() const;
01422 void CopyTo( TiXmlText* target ) const;
01423
01424 bool Blank() const;
01425
01426 #ifdef TIXML_USE_STL
01427 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01428 #endif
01429
01430 #endif
01431
01432 private:
01433 bool cdata;
01434 };
01435
01436
01454 class EDELIB_API TiXmlDeclaration : public TiXmlNode
01455 {
01456 public:
01458 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01459
01460 #ifdef TIXML_USE_STL
01461
01462 TiXmlDeclaration( const std::string& _version,
01463 const std::string& _encoding,
01464 const std::string& _standalone );
01465 #endif
01466
01468 TiXmlDeclaration( const char* _version,
01469 const char* _encoding,
01470 const char* _standalone );
01471
01473 TiXmlDeclaration( const TiXmlDeclaration& copy );
01475 void operator=( const TiXmlDeclaration& copy );
01476
01477 #ifndef SKIP_DOCS
01478 virtual ~TiXmlDeclaration() {}
01479 #endif
01480
01482 const char *Version() const { return version.c_str (); }
01484 const char *Encoding() const { return encoding.c_str (); }
01486 const char *Standalone() const { return standalone.c_str (); }
01487
01489 virtual TiXmlNode* Clone() const;
01490
01492 virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01494 virtual void Print( FILE* cfile, int depth ) const {
01495 Print( cfile, depth, 0 );
01496 }
01497 #ifndef SKIP_DOCS
01498 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01499 #endif
01500
01501 virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
01503 virtual TiXmlDeclaration* ToDeclaration() { return this; }
01504
01506 virtual bool Accept( TiXmlVisitor* visitor ) const;
01507
01508 protected:
01509 #ifndef SKIP_DOCS
01510 void CopyTo( TiXmlDeclaration* target ) const;
01511
01512 #ifdef TIXML_USE_STL
01513 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01514 #endif
01515
01516 #endif
01517
01518 private:
01519
01520 TIXML_STRING version;
01521 TIXML_STRING encoding;
01522 TIXML_STRING standalone;
01523 };
01524
01525
01537 class TiXmlUnknown : public TiXmlNode
01538 {
01539 public:
01541 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01542 #ifndef SKIP_DOCS
01543 virtual ~TiXmlUnknown() {}
01544 #endif
01545
01547 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01549 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01550
01552 virtual TiXmlNode* Clone() const;
01554 virtual void Print( FILE* cfile, int depth ) const;
01555 #ifndef SKIP_DOCS
01556 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01557 #endif
01558
01559 virtual const TiXmlUnknown* ToUnknown() const { return this; }
01561 virtual TiXmlUnknown* ToUnknown() { return this; }
01562
01564 virtual bool Accept( TiXmlVisitor* content ) const;
01565
01566 protected:
01567 #ifndef SKIP_DOCS
01568 void CopyTo( TiXmlUnknown* target ) const;
01569
01570 #ifdef TIXML_USE_STL
01571 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01572 #endif
01573
01574 #endif
01575
01576 private:
01577
01578 };
01579
01580
01589 class EDELIB_API TiXmlDocument : public TiXmlNode
01590 {
01591 public:
01593 TiXmlDocument();
01595 TiXmlDocument( const char * documentName );
01596
01597 #ifdef TIXML_USE_STL
01598
01599 TiXmlDocument( const std::string& documentName );
01600 #endif
01601
01603 TiXmlDocument( const TiXmlDocument& copy );
01605 void operator=( const TiXmlDocument& copy );
01606
01607 #ifndef SKIP_DOCS
01608 virtual ~TiXmlDocument() {}
01609 #endif
01610
01616 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01618 bool SaveFile() const;
01620 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01622 bool SaveFile( const char * filename ) const;
01629 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01631 bool SaveFile( FILE* ) const;
01632
01633 #ifdef TIXML_USE_STL
01634
01635 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01636 {
01637 return LoadFile( filename.c_str(), encoding );
01638 }
01639
01641 bool SaveFile( const std::string& filename ) const
01642 {
01643 return SaveFile( filename.c_str() );
01644 }
01645 #endif
01646
01652 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01653
01659 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01661 TiXmlElement* RootElement() { return FirstChildElement(); }
01662
01669 bool Error() const { return error; }
01670
01672 const char * ErrorDesc() const { return errorDesc.c_str (); }
01673
01678 int ErrorId() const { return errorId; }
01679
01688 int ErrorRow() const { return errorLocation.row+1; }
01689
01691 int ErrorCol() const { return errorLocation.col+1; }
01692
01718 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01719
01721 int TabSize() const { return tabsize; }
01722
01727 void ClearError() { error = false;
01728 errorId = 0;
01729 errorDesc = "";
01730 errorLocation.row = errorLocation.col = 0;
01731
01732 }
01733
01735 void Print() const { Print( stdout, 0 ); }
01736
01742
01743
01745 virtual void Print( FILE* cfile, int depth = 0 ) const;
01746 #ifndef SKIP_DOCS
01747
01748 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01749 #endif
01750
01751 virtual const TiXmlDocument* ToDocument() const { return this; }
01753 virtual TiXmlDocument* ToDocument() { return this; }
01754
01756 virtual bool Accept( TiXmlVisitor* content ) const;
01757
01758 protected :
01759 #ifndef SKIP_DOCS
01760
01761 virtual TiXmlNode* Clone() const;
01762 #ifdef TIXML_USE_STL
01763 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01764 #endif
01765
01766 #endif
01767
01768 private:
01769 void CopyTo( TiXmlDocument* target ) const;
01770
01771 bool error;
01772 int errorId;
01773 TIXML_STRING errorDesc;
01774 int tabsize;
01775 TiXmlCursor errorLocation;
01776 bool useMicrosoftBOM;
01777 };
01778
01779
01865 class EDELIB_API TiXmlHandle
01866 {
01867 public:
01869 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01871 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01873 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01874
01876 TiXmlHandle FirstChild() const;
01878 TiXmlHandle FirstChild( const char * value ) const;
01880 TiXmlHandle FirstChildElement() const;
01882 TiXmlHandle FirstChildElement( const char * value ) const;
01883
01888 TiXmlHandle Child( const char* value, int index ) const;
01893 TiXmlHandle Child( int index ) const;
01899 TiXmlHandle ChildElement( const char* value, int index ) const;
01905 TiXmlHandle ChildElement( int index ) const;
01906
01907 #ifdef TIXML_USE_STL
01908
01909 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01911 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01912
01914 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01916 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01917 #endif
01918
01920 TiXmlNode* ToNode() const { return node; }
01922 TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01924 TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01926 TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01927
01932 TiXmlNode* Node() const { return ToNode(); }
01937 TiXmlElement* Element() const { return ToElement(); }
01942 TiXmlText* Text() const { return ToText(); }
01947 TiXmlUnknown* Unknown() const { return ToUnknown(); }
01948
01949 private:
01950 TiXmlNode* node;
01951 };
01952
01953
01977 class TiXmlPrinter : public TiXmlVisitor
01978 {
01979 public:
01981 TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
01982 buffer(), indent( " " ), lineBreak( "\n" ) {}
01983 #ifndef SKIP_DOCS
01984 virtual bool VisitEnter( const TiXmlDocument& doc );
01985 virtual bool VisitExit( const TiXmlDocument& doc );
01986
01987 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
01988 virtual bool VisitExit( const TiXmlElement& element );
01989
01990 virtual bool Visit( const TiXmlDeclaration& declaration );
01991 virtual bool Visit( const TiXmlText& text );
01992 virtual bool Visit( const TiXmlComment& comment );
01993 virtual bool Visit( const TiXmlUnknown& unknown );
01994 #endif
01995
02000 void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
02002 const char* Indent() { return indent.c_str(); }
02003
02009 void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
02010
02012 const char* LineBreak() { return lineBreak.c_str(); }
02013
02018 void SetStreamPrinting() { indent = ""; lineBreak = ""; }
02020 const char* CStr() { return buffer.c_str(); }
02022 size_t Size() { return buffer.length(); }
02023
02024 #ifdef TIXML_USE_STL
02025
02026 const std::string& Str() { return buffer; }
02027 #endif
02028
02029 private:
02030 void DoIndent() {
02031 for( int i=0; i<depth; ++i )
02032 buffer += indent;
02033 }
02034 void DoLineBreak() {
02035 buffer += lineBreak;
02036 }
02037
02038 int depth;
02039 bool simpleTextPrint;
02040 TIXML_STRING buffer;
02041 TIXML_STRING indent;
02042 TIXML_STRING lineBreak;
02043 };
02044
02045
02046 #ifdef _MSC_VER
02047 #pragma warning( pop )
02048 #endif
02049
02050 #endif