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 TINYXML_INCLUDED
00027 #define TINYXML_INCLUDED
00028
00029 #ifdef _MSC_VER
00030 #pragma warning( push )
00031 #pragma warning( disable : 4530 )
00032 #pragma warning( disable : 4786 )
00033 #endif
00034
00035 #include <ctype.h>
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039 #include <assert.h>
00040
00041
00042 #if defined( _DEBUG ) && !defined( DEBUG )
00043 #define DEBUG
00044 #endif
00045
00046 #ifdef TIXML_USE_STL
00047 #include <string>
00048 #include <iostream>
00049 #define TIXML_STRING std::string
00050 #define TIXML_ISTREAM std::istream
00051 #define TIXML_OSTREAM std::ostream
00052 #else
00053 #include "tinystr.h"
00054 #define TIXML_STRING TiXmlString
00055 #define TIXML_OSTREAM TiXmlOutStream
00056 #endif
00057
00058
00059
00060
00061
00062
00063 #define TIXML_SAFE // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress.
00064 #ifdef TIXML_SAFE
00065 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
00066
00067 #define TIXML_SNPRINTF _snprintf_s
00068 #define TIXML_SNSCANF _snscanf_s
00069 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
00070
00071
00072 #define TIXML_SNPRINTF _snprintf
00073 #define TIXML_SNSCANF _snscanf
00074 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00075
00076
00077 #define TIXML_SNPRINTF snprintf
00078 #define TIXML_SNSCANF snscanf
00079 #endif
00080 #endif
00081
00082 namespace CEGUITinyXML
00083 {
00084
00085 class TiXmlDocument;
00086 class TiXmlElement;
00087 class TiXmlComment;
00088 class TiXmlUnknown;
00089 class TiXmlAttribute;
00090 class TiXmlText;
00091 class TiXmlDeclaration;
00092 class TiXmlParsingData;
00093
00094 const int TIXML_MAJOR_VERSION = 2;
00095 const int TIXML_MINOR_VERSION = 4;
00096 const int TIXML_PATCH_VERSION = 3;
00097
00098
00099
00100
00101 struct TiXmlCursor
00102 {
00103 TiXmlCursor() { Clear(); }
00104 void Clear() { row = col = -1; }
00105
00106 int row;
00107 int col;
00108 };
00109
00110
00111
00112 enum
00113 {
00114 TIXML_SUCCESS,
00115 TIXML_NO_ATTRIBUTE,
00116 TIXML_WRONG_TYPE
00117 };
00118
00119
00120
00121 enum TiXmlEncoding
00122 {
00123 TIXML_ENCODING_UNKNOWN,
00124 TIXML_ENCODING_UTF8,
00125 TIXML_ENCODING_LEGACY
00126 };
00127
00128 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00129
00152 class TiXmlBase
00153 {
00154 friend class TiXmlNode;
00155 friend class TiXmlElement;
00156 friend class TiXmlDocument;
00157
00158 public:
00159 TiXmlBase() : userData(0) {}
00160 virtual ~TiXmlBase() {}
00161
00167 virtual void Print( FILE* cfile, int depth ) const = 0;
00168
00175 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00176
00178 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00179
00198 int Row() const { return location.row + 1; }
00199 int Column() const { return location.col + 1; }
00200
00201 void SetUserData( void* user ) { userData = user; }
00202 void* GetUserData() { return userData; }
00203
00204
00205
00206 static const int utf8ByteTable[256];
00207
00208 virtual const char* Parse( const char* p,
00209 TiXmlParsingData* data,
00210 TiXmlEncoding encoding ) = 0;
00211
00212 enum
00213 {
00214 TIXML_NO_ERROR = 0,
00215 TIXML_ERROR,
00216 TIXML_ERROR_OPENING_FILE,
00217 TIXML_ERROR_OUT_OF_MEMORY,
00218 TIXML_ERROR_PARSING_ELEMENT,
00219 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00220 TIXML_ERROR_READING_ELEMENT_VALUE,
00221 TIXML_ERROR_READING_ATTRIBUTES,
00222 TIXML_ERROR_PARSING_EMPTY,
00223 TIXML_ERROR_READING_END_TAG,
00224 TIXML_ERROR_PARSING_UNKNOWN,
00225 TIXML_ERROR_PARSING_COMMENT,
00226 TIXML_ERROR_PARSING_DECLARATION,
00227 TIXML_ERROR_DOCUMENT_EMPTY,
00228 TIXML_ERROR_EMBEDDED_NULL,
00229 TIXML_ERROR_PARSING_CDATA,
00230
00231 TIXML_ERROR_STRING_COUNT
00232 };
00233
00234 protected:
00235
00236
00237
00238 class StringToBuffer
00239 {
00240 public:
00241 StringToBuffer( const TIXML_STRING& str );
00242 ~StringToBuffer();
00243 char* buffer;
00244 };
00245
00246 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00247 inline static bool IsWhiteSpace( char c )
00248 {
00249 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00250 }
00251 inline static bool IsWhiteSpace( int c )
00252 {
00253 if ( c < 256 )
00254 return IsWhiteSpace( (char) c );
00255 return false;
00256 }
00257
00258 virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00259
00260 #ifdef TIXML_USE_STL
00261 static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00262 static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00263 #endif
00264
00265
00266
00267
00268
00269 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00270
00271
00272
00273
00274 static const char* ReadText( const char* in,
00275 TIXML_STRING* text,
00276 bool ignoreWhiteSpace,
00277 const char* endTag,
00278 bool ignoreCase,
00279 TiXmlEncoding encoding );
00280
00281
00282 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00283
00284
00285
00286 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00287 {
00288 assert( p );
00289 if ( encoding == TIXML_ENCODING_UTF8 )
00290 {
00291 *length = utf8ByteTable[ *((unsigned char*)p) ];
00292 assert( *length >= 0 && *length < 5 );
00293 }
00294 else
00295 {
00296 *length = 1;
00297 }
00298
00299 if ( *length == 1 )
00300 {
00301 if ( *p == '&' )
00302 return GetEntity( p, _value, length, encoding );
00303 *_value = *p;
00304 return p+1;
00305 }
00306 else if ( *length )
00307 {
00308
00309
00310 for( int i=0; p[i] && i<*length; ++i ) {
00311 _value[i] = p[i];
00312 }
00313 return p + (*length);
00314 }
00315 else
00316 {
00317
00318 return 0;
00319 }
00320 }
00321
00322
00323
00324 static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00325
00326 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00327
00328
00329
00330
00331 static bool StringEqual( const char* p,
00332 const char* endTag,
00333 bool ignoreCase,
00334 TiXmlEncoding encoding );
00335
00336 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00337
00338 TiXmlCursor location;
00339
00341 void* userData;
00342
00343
00344
00345 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00346 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00347 inline static int ToLower( int v, TiXmlEncoding encoding )
00348 {
00349 if ( encoding == TIXML_ENCODING_UTF8 )
00350 {
00351 if ( v < 128 ) return tolower( v );
00352 return v;
00353 }
00354 else
00355 {
00356 return tolower( v );
00357 }
00358 }
00359 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00360
00361 private:
00362 TiXmlBase( const TiXmlBase& );
00363 void operator=( const TiXmlBase& base );
00364
00365 struct Entity
00366 {
00367 const char* str;
00368 unsigned int strLength;
00369 char chr;
00370 };
00371 enum
00372 {
00373 NUM_ENTITY = 5,
00374 MAX_ENTITY_LENGTH = 6
00375
00376 };
00377 static Entity entity[ NUM_ENTITY ];
00378 static bool condenseWhiteSpace;
00379 };
00380
00381
00388 class TiXmlNode : public TiXmlBase
00389 {
00390 friend class TiXmlDocument;
00391 friend class TiXmlElement;
00392
00393 public:
00394 #ifdef TIXML_USE_STL
00395
00399 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00400
00417 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00418
00420 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00421
00422 #else
00423
00424 friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00425 #endif
00426
00430 enum NodeType
00431 {
00432 DOCUMENT,
00433 ELEMENT,
00434 COMMENT,
00435 UNKNOWN,
00436 TEXT,
00437 DECLARATION,
00438 TYPECOUNT
00439 };
00440
00441 virtual ~TiXmlNode();
00442
00455 const char *Value() const { return value.c_str (); }
00456
00457 #ifdef TIXML_USE_STL
00458
00462 const std::string& ValueStr() const { return value; }
00463 #endif
00464
00474 void SetValue(const char * _value) { value = _value;}
00475
00476 #ifdef TIXML_USE_STL
00478 void SetValue( const std::string& _value ) { value = _value; }
00479 #endif
00480
00482 void Clear();
00483
00485 TiXmlNode* Parent() { return parent; }
00486 const TiXmlNode* Parent() const { return parent; }
00487
00488 const TiXmlNode* FirstChild() const { return firstChild; }
00489 TiXmlNode* FirstChild() { return firstChild; }
00490 const TiXmlNode* FirstChild( const char * value ) const;
00491 TiXmlNode* FirstChild( const char * value );
00492
00493 const TiXmlNode* LastChild() const { return lastChild; }
00494 TiXmlNode* LastChild() { return lastChild; }
00495 const TiXmlNode* LastChild( const char * value ) const;
00496 TiXmlNode* LastChild( const char * value );
00497
00498 #ifdef TIXML_USE_STL
00499 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00500 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00501 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00502 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00503 #endif
00504
00521 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00522 TiXmlNode* IterateChildren( TiXmlNode* previous );
00523
00525 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00526 TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous );
00527
00528 #ifdef TIXML_USE_STL
00529 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00530 TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
00531 #endif
00532
00536 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00537
00538
00548 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00549
00553 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00554
00558 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00559
00563 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00564
00566 bool RemoveChild( TiXmlNode* removeThis );
00567
00569 const TiXmlNode* PreviousSibling() const { return prev; }
00570 TiXmlNode* PreviousSibling() { return prev; }
00571
00573 const TiXmlNode* PreviousSibling( const char * ) const;
00574 TiXmlNode* PreviousSibling( const char * );
00575
00576 #ifdef TIXML_USE_STL
00577 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00578 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00579 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00580 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00581 #endif
00582
00584 const TiXmlNode* NextSibling() const { return next; }
00585 TiXmlNode* NextSibling() { return next; }
00586
00588 const TiXmlNode* NextSibling( const char * ) const;
00589 TiXmlNode* NextSibling( const char * );
00590
00595 const TiXmlElement* NextSiblingElement() const;
00596 TiXmlElement* NextSiblingElement();
00597
00602 const TiXmlElement* NextSiblingElement( const char * ) const;
00603 TiXmlElement* NextSiblingElement( const char * );
00604
00605 #ifdef TIXML_USE_STL
00606 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00607 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
00608 #endif
00609
00611 const TiXmlElement* FirstChildElement() const;
00612 TiXmlElement* FirstChildElement();
00613
00615 const TiXmlElement* FirstChildElement( const char * value ) const;
00616 TiXmlElement* FirstChildElement( const char * value );
00617
00618 #ifdef TIXML_USE_STL
00619 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00620 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
00621 #endif
00622
00627 int Type() const { return type; }
00628
00632 const TiXmlDocument* GetDocument() const;
00633 TiXmlDocument* GetDocument();
00634
00636 bool NoChildren() const { return !firstChild; }
00637
00638 virtual const TiXmlDocument* ToDocument() const { return 0; }
00639 virtual const TiXmlElement* ToElement() const { return 0; }
00640 virtual const TiXmlComment* ToComment() const { return 0; }
00641 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
00642 virtual const TiXmlText* ToText() const { return 0; }
00643 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
00644
00645 virtual TiXmlDocument* ToDocument() { return 0; }
00646 virtual TiXmlElement* ToElement() { return 0; }
00647 virtual TiXmlComment* ToComment() { return 0; }
00648 virtual TiXmlUnknown* ToUnknown() { return 0; }
00649 virtual TiXmlText* ToText() { return 0; }
00650 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
00651
00655 virtual TiXmlNode* Clone() const = 0;
00656
00657 protected:
00658 TiXmlNode( NodeType _type );
00659
00660
00661
00662 void CopyTo( TiXmlNode* target ) const;
00663
00664 #ifdef TIXML_USE_STL
00665
00666 virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00667 #endif
00668
00669
00670 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00671
00672 TiXmlNode* parent;
00673 NodeType type;
00674
00675 TiXmlNode* firstChild;
00676 TiXmlNode* lastChild;
00677
00678 TIXML_STRING value;
00679
00680 TiXmlNode* prev;
00681 TiXmlNode* next;
00682
00683 private:
00684 TiXmlNode( const TiXmlNode& );
00685 void operator=( const TiXmlNode& base );
00686 };
00687
00688
00696 class TiXmlAttribute : public TiXmlBase
00697 {
00698 friend class TiXmlAttributeSet;
00699
00700 public:
00702 TiXmlAttribute() : TiXmlBase()
00703 {
00704 document = 0;
00705 prev = next = 0;
00706 }
00707
00708 #ifdef TIXML_USE_STL
00710 TiXmlAttribute( const std::string& _name, const std::string& _value )
00711 {
00712 name = _name;
00713 value = _value;
00714 document = 0;
00715 prev = next = 0;
00716 }
00717 #endif
00718
00720 TiXmlAttribute( const char * _name, const char * _value )
00721 {
00722 name = _name;
00723 value = _value;
00724 document = 0;
00725 prev = next = 0;
00726 }
00727
00728 const char* Name() const { return name.c_str (); }
00729 const char* Value() const { return value.c_str (); }
00730 int IntValue() const;
00731 double DoubleValue() const;
00732
00733
00734 const TIXML_STRING& NameTStr() const { return name; }
00735
00745 int QueryIntValue( int* _value ) const;
00747 int QueryDoubleValue( double* _value ) const;
00748
00749 void SetName( const char* _name ) { name = _name; }
00750 void SetValue( const char* _value ) { value = _value; }
00751
00752 void SetIntValue( int _value );
00753 void SetDoubleValue( double _value );
00754
00755 #ifdef TIXML_USE_STL
00757 void SetName( const std::string& _name ) { name = _name; }
00759 void SetValue( const std::string& _value ) { value = _value; }
00760 #endif
00761
00763 const TiXmlAttribute* Next() const;
00764 TiXmlAttribute* Next();
00766 const TiXmlAttribute* Previous() const;
00767 TiXmlAttribute* Previous();
00768
00769 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00770 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00771 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00772
00773
00774
00775
00776 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00777
00778
00779 virtual void Print( FILE* cfile, int depth ) const;
00780
00781 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00782
00783
00784 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00785
00786 private:
00787 TiXmlAttribute( const TiXmlAttribute& );
00788 void operator=( const TiXmlAttribute& base );
00789
00790 TiXmlDocument* document;
00791 TIXML_STRING name;
00792 TIXML_STRING value;
00793 TiXmlAttribute* prev;
00794 TiXmlAttribute* next;
00795 };
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810 class TiXmlAttributeSet
00811 {
00812 public:
00813 TiXmlAttributeSet();
00814 ~TiXmlAttributeSet();
00815
00816 void Add( TiXmlAttribute* attribute );
00817 void Remove( TiXmlAttribute* attribute );
00818
00819 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00820 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00821 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00822 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00823
00824 const TiXmlAttribute* Find( const TIXML_STRING& name ) const;
00825 TiXmlAttribute* Find( const TIXML_STRING& name );
00826
00827 private:
00828
00829
00830 TiXmlAttributeSet( const TiXmlAttributeSet& );
00831 void operator=( const TiXmlAttributeSet& );
00832
00833 TiXmlAttribute sentinel;
00834 };
00835
00836
00841 class TiXmlElement : public TiXmlNode
00842 {
00843 public:
00845 TiXmlElement (const char * in_value);
00846
00847 #ifdef TIXML_USE_STL
00849 TiXmlElement( const std::string& _value );
00850 #endif
00851
00852 TiXmlElement( const TiXmlElement& );
00853
00854 void operator=( const TiXmlElement& base );
00855
00856 virtual ~TiXmlElement();
00857
00861 const char* Attribute( const char* name ) const;
00862
00869 const char* Attribute( const char* name, int* i ) const;
00870
00877 const char* Attribute( const char* name, double* d ) const;
00878
00886 int QueryIntAttribute( const char* name, int* _value ) const;
00888 int QueryDoubleAttribute( const char* name, double* _value ) const;
00890 int QueryFloatAttribute( const char* name, float* _value ) const {
00891 double d;
00892 int result = QueryDoubleAttribute( name, &d );
00893 if ( result == TIXML_SUCCESS ) {
00894 *_value = (float)d;
00895 }
00896 return result;
00897 }
00898
00902 void SetAttribute( const char* name, const char * _value );
00903
00904 #ifdef TIXML_USE_STL
00905 const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
00906 const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
00907 const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); }
00908 int QueryIntAttribute( const std::string& name, int* _value ) const { return QueryIntAttribute( name.c_str(), _value ); }
00909 int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); }
00910
00912 void SetAttribute( const std::string& name, const std::string& _value );
00914 void SetAttribute( const std::string& name, int _value );
00915 #endif
00916
00920 void SetAttribute( const char * name, int value );
00921
00925 void SetDoubleAttribute( const char * name, double value );
00926
00929 void RemoveAttribute( const char * name );
00930 #ifdef TIXML_USE_STL
00931 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
00932 #endif
00933
00934 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
00935 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
00936 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
00937 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
00938
00971 const char* GetText() const;
00972
00974 virtual TiXmlNode* Clone() const;
00975
00976 virtual void Print( FILE* cfile, int depth ) const;
00977
00978
00979
00980
00981 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00982
00983 virtual const TiXmlElement* ToElement() const { return this; }
00984 virtual TiXmlElement* ToElement() { return this; }
00985
00986 protected:
00987
00988 void CopyTo( TiXmlElement* target ) const;
00989 void ClearThis();
00990
00991
00992 #ifdef TIXML_USE_STL
00993 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00994 #endif
00995 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00996
00997
00998
00999
01000
01001 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01002
01003 private:
01004
01005 TiXmlAttributeSet attributeSet;
01006 };
01007
01008
01011 class TiXmlComment : public TiXmlNode
01012 {
01013 public:
01015 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01016 TiXmlComment( const TiXmlComment& );
01017 void operator=( const TiXmlComment& base );
01018
01019 virtual ~TiXmlComment() {}
01020
01022 virtual TiXmlNode* Clone() const;
01024 virtual void Print( FILE* cfile, int depth ) const;
01025
01026
01027
01028
01029 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01030
01031 virtual const TiXmlComment* ToComment() const { return this; }
01032 virtual TiXmlComment* ToComment() { return this; }
01033
01034 protected:
01035 void CopyTo( TiXmlComment* target ) const;
01036
01037
01038 #ifdef TIXML_USE_STL
01039 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01040 #endif
01041 virtual void StreamOut( TIXML_OSTREAM * out ) const;
01042
01043 private:
01044
01045 };
01046
01047
01053 class TiXmlText : public TiXmlNode
01054 {
01055 friend class TiXmlElement;
01056 public:
01061 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01062 {
01063 SetValue( initValue );
01064 cdata = false;
01065 }
01066 virtual ~TiXmlText() {}
01067
01068 #ifdef TIXML_USE_STL
01070 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01071 {
01072 SetValue( initValue );
01073 cdata = false;
01074 }
01075 #endif
01076
01077 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01078 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01079
01081 virtual void Print( FILE* cfile, int depth ) const;
01082
01084 bool CDATA() { return cdata; }
01086 void SetCDATA( bool _cdata ) { cdata = _cdata; }
01087
01088 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01089
01090 virtual const TiXmlText* ToText() const { return this; }
01091 virtual TiXmlText* ToText() { return this; }
01092
01093 protected :
01095 virtual TiXmlNode* Clone() const;
01096 void CopyTo( TiXmlText* target ) const;
01097
01098 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01099 bool Blank() const;
01100
01101 #ifdef TIXML_USE_STL
01102 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01103 #endif
01104
01105 private:
01106 bool cdata;
01107 };
01108
01109
01123 class TiXmlDeclaration : public TiXmlNode
01124 {
01125 public:
01127 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01128
01129 #ifdef TIXML_USE_STL
01131 TiXmlDeclaration( const std::string& _version,
01132 const std::string& _encoding,
01133 const std::string& _standalone );
01134 #endif
01135
01137 TiXmlDeclaration( const char* _version,
01138 const char* _encoding,
01139 const char* _standalone );
01140
01141 TiXmlDeclaration( const TiXmlDeclaration& copy );
01142 void operator=( const TiXmlDeclaration& copy );
01143
01144 virtual ~TiXmlDeclaration() {}
01145
01147 const char *Version() const { return version.c_str (); }
01149 const char *Encoding() const { return encoding.c_str (); }
01151 const char *Standalone() const { return standalone.c_str (); }
01152
01154 virtual TiXmlNode* Clone() const;
01156 virtual void Print( FILE* cfile, int depth ) const;
01157
01158 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01159
01160 virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
01161 virtual TiXmlDeclaration* ToDeclaration() { return this; }
01162
01163 protected:
01164 void CopyTo( TiXmlDeclaration* target ) const;
01165
01166 #ifdef TIXML_USE_STL
01167 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01168 #endif
01169 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01170
01171 private:
01172
01173 TIXML_STRING version;
01174 TIXML_STRING encoding;
01175 TIXML_STRING standalone;
01176 };
01177
01178
01186 class TiXmlUnknown : public TiXmlNode
01187 {
01188 public:
01189 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01190 virtual ~TiXmlUnknown() {}
01191
01192 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01193 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01194
01196 virtual TiXmlNode* Clone() const;
01198 virtual void Print( FILE* cfile, int depth ) const;
01199
01200 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01201
01202 virtual const TiXmlUnknown* ToUnknown() const { return this; }
01203 virtual TiXmlUnknown* ToUnknown() { return this; }
01204
01205 protected:
01206 void CopyTo( TiXmlUnknown* target ) const;
01207
01208 #ifdef TIXML_USE_STL
01209 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01210 #endif
01211 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01212
01213 private:
01214
01215 };
01216
01217
01222 class TiXmlDocument : public TiXmlNode
01223 {
01224 public:
01226 TiXmlDocument();
01228 TiXmlDocument( const char * documentName );
01229
01230 #ifdef TIXML_USE_STL
01232 TiXmlDocument( const std::string& documentName );
01233 #endif
01234
01235 TiXmlDocument( const TiXmlDocument& copy );
01236 void operator=( const TiXmlDocument& copy );
01237
01238 virtual ~TiXmlDocument() {}
01239
01244 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01246 bool SaveFile() const;
01248 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01250 bool SaveFile( const char * filename ) const;
01256 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01258 bool SaveFile( FILE* ) const;
01259
01260 #ifdef TIXML_USE_STL
01261 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01262 {
01263 StringToBuffer f( filename );
01264 return ( f.buffer && LoadFile( f.buffer, encoding ));
01265 }
01266 bool SaveFile( const std::string& filename ) const
01267 {
01268 StringToBuffer f( filename );
01269 return ( f.buffer && SaveFile( f.buffer ));
01270 }
01271 #endif
01272
01277 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01278
01283 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01284 TiXmlElement* RootElement() { return FirstChildElement(); }
01285
01291 bool Error() const { return error; }
01292
01294 const char * ErrorDesc() const { return errorDesc.c_str (); }
01295
01299 int ErrorId() const { return errorId; }
01300
01308 int ErrorRow() { return errorLocation.row+1; }
01309 int ErrorCol() { return errorLocation.col+1; }
01310
01335 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01336
01337 int TabSize() const { return tabsize; }
01338
01342 void ClearError() { error = false;
01343 errorId = 0;
01344 errorDesc = "";
01345 errorLocation.row = errorLocation.col = 0;
01346
01347 }
01348
01350 void Print() const { Print( stdout, 0 ); }
01351
01353 virtual void Print( FILE* cfile, int depth = 0 ) const;
01354
01355 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01356
01357 virtual const TiXmlDocument* ToDocument() const { return this; }
01358 virtual TiXmlDocument* ToDocument() { return this; }
01359
01360 protected :
01361 virtual void StreamOut ( TIXML_OSTREAM * out) const;
01362
01363 virtual TiXmlNode* Clone() const;
01364 #ifdef TIXML_USE_STL
01365 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01366 #endif
01367
01368 private:
01369 void CopyTo( TiXmlDocument* target ) const;
01370
01371 bool error;
01372 int errorId;
01373 TIXML_STRING errorDesc;
01374 int tabsize;
01375 TiXmlCursor errorLocation;
01376 bool useMicrosoftBOM;
01377 };
01378
01379
01460 class TiXmlHandle
01461 {
01462 public:
01464 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01466 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01467 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01468
01470 TiXmlHandle FirstChild() const;
01472 TiXmlHandle FirstChild( const char * value ) const;
01474 TiXmlHandle FirstChildElement() const;
01476 TiXmlHandle FirstChildElement( const char * value ) const;
01477
01481 TiXmlHandle Child( const char* value, int index ) const;
01485 TiXmlHandle Child( int index ) const;
01490 TiXmlHandle ChildElement( const char* value, int index ) const;
01495 TiXmlHandle ChildElement( int index ) const;
01496
01497 #ifdef TIXML_USE_STL
01498 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01499 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01500
01501 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01502 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01503 #endif
01504
01506 TiXmlNode* Node() const { return node; }
01508 TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01510 TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01512 TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01513
01514 private:
01515 TiXmlNode* node;
01516 };
01517
01518 }
01519 #ifdef _MSC_VER
01520 #pragma warning( pop )
01521 #endif
01522
01523 #endif
01524