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 #include <sstream>
00050 #define TIXML_STRING std::string
00051 #else
00052 #include "tinystr.h"
00053 #define TIXML_STRING TiXmlString
00054 #endif
00055
00056
00057
00058
00059
00060 #define TIXML_SAFE
00061
00062 #ifdef TIXML_SAFE
00063 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
00064
00065 #define TIXML_SNPRINTF _snprintf_s
00066 #define TIXML_SNSCANF _snscanf_s
00067 #define TIXML_SSCANF sscanf_s
00068 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
00069
00070
00071 #define TIXML_SNPRINTF _snprintf
00072 #define TIXML_SNSCANF _snscanf
00073 #define TIXML_SSCANF sscanf
00074 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00075
00076
00077 #define TIXML_SNPRINTF snprintf
00078 #define TIXML_SNSCANF snscanf
00079 #define TIXML_SSCANF sscanf
00080 #else
00081 #define TIXML_SSCANF sscanf
00082 #endif
00083 #endif
00084
00085 #if defined(WIN32)
00086 #if defined(ROS_STATIC)
00087 #define TINYXML_EXPORT
00088 #elif defined(rospack_EXPORTS) || defined(rosstack_EXPORTS)
00089 #define TINYXML_EXPORT __declspec(dllexport)
00090 #else
00091 #define TINYXML_EXPORT __declspec(dllimport)
00092 #endif
00093 #else
00094 #define TINYXML_EXPORT
00095 #endif
00096
00097 class TiXmlDocument;
00098 class TiXmlElement;
00099 class TiXmlComment;
00100 class TiXmlUnknown;
00101 class TiXmlAttribute;
00102 class TiXmlText;
00103 class TiXmlDeclaration;
00104 class TiXmlParsingData;
00105
00106 const int TIXML_MAJOR_VERSION = 2;
00107 const int TIXML_MINOR_VERSION = 5;
00108 const int TIXML_PATCH_VERSION = 3;
00109
00110
00111
00112
00113 struct TiXmlCursor
00114 {
00115 TiXmlCursor() { Clear(); }
00116 void Clear() { row = col = -1; }
00117
00118 int row;
00119 int col;
00120 };
00121
00122
00141 class TINYXML_EXPORT TiXmlVisitor
00142 {
00143 public:
00144 virtual ~TiXmlVisitor() {}
00145
00147 virtual bool VisitEnter( const TiXmlDocument& ) { return true; }
00149 virtual bool VisitExit( const TiXmlDocument& ) { return true; }
00150
00152 virtual bool VisitEnter( const TiXmlElement& , const TiXmlAttribute* ) { return true; }
00154 virtual bool VisitExit( const TiXmlElement& ) { return true; }
00155
00157 virtual bool Visit( const TiXmlDeclaration& ) { return true; }
00159 virtual bool Visit( const TiXmlText& ) { return true; }
00161 virtual bool Visit( const TiXmlComment& ) { return true; }
00163 virtual bool Visit( const TiXmlUnknown& ) { return true; }
00164 };
00165
00166
00167 enum
00168 {
00169 TIXML_SUCCESS,
00170 TIXML_NO_ATTRIBUTE,
00171 TIXML_WRONG_TYPE
00172 };
00173
00174
00175
00176 enum TiXmlEncoding
00177 {
00178 TIXML_ENCODING_UNKNOWN,
00179 TIXML_ENCODING_UTF8,
00180 TIXML_ENCODING_LEGACY
00181 };
00182
00183 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00184
00207 class TINYXML_EXPORT TiXmlBase
00208 {
00209 friend class TiXmlNode;
00210 friend class TiXmlElement;
00211 friend class TiXmlDocument;
00212
00213 public:
00214 TiXmlBase() : userData(0) {}
00215 virtual ~TiXmlBase() {}
00216
00226 virtual void Print( FILE* cfile, int depth ) const = 0;
00227
00234 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00235
00237 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00238
00257 int Row() const { return location.row + 1; }
00258 int Column() const { return location.col + 1; }
00259
00260 void SetUserData( void* user ) { userData = user; }
00261 void* GetUserData() { return userData; }
00262 const void* GetUserData() const { return userData; }
00263
00264
00265
00266 static const int utf8ByteTable[256];
00267
00268 virtual const char* Parse( const char* p,
00269 TiXmlParsingData* data,
00270 TiXmlEncoding encoding ) = 0;
00271
00275 static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
00276
00277 enum
00278 {
00279 TIXML_NO_ERROR = 0,
00280 TIXML_ERROR,
00281 TIXML_ERROR_OPENING_FILE,
00282 TIXML_ERROR_OUT_OF_MEMORY,
00283 TIXML_ERROR_PARSING_ELEMENT,
00284 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00285 TIXML_ERROR_READING_ELEMENT_VALUE,
00286 TIXML_ERROR_READING_ATTRIBUTES,
00287 TIXML_ERROR_PARSING_EMPTY,
00288 TIXML_ERROR_READING_END_TAG,
00289 TIXML_ERROR_PARSING_UNKNOWN,
00290 TIXML_ERROR_PARSING_COMMENT,
00291 TIXML_ERROR_PARSING_DECLARATION,
00292 TIXML_ERROR_DOCUMENT_EMPTY,
00293 TIXML_ERROR_EMBEDDED_NULL,
00294 TIXML_ERROR_PARSING_CDATA,
00295 TIXML_ERROR_DOCUMENT_TOP_ONLY,
00296
00297 TIXML_ERROR_STRING_COUNT
00298 };
00299
00300 protected:
00301
00302 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00303 inline static bool IsWhiteSpace( char c )
00304 {
00305 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00306 }
00307 inline static bool IsWhiteSpace( int c )
00308 {
00309 if ( c < 256 )
00310 return IsWhiteSpace( (char) c );
00311 return false;
00312 }
00313
00314 #ifdef TIXML_USE_STL
00315 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
00316 static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
00317 #endif
00318
00319
00320
00321
00322
00323 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00324
00325
00326
00327
00328 static const char* ReadText( const char* in,
00329 TIXML_STRING* text,
00330 bool ignoreWhiteSpace,
00331 const char* endTag,
00332 bool ignoreCase,
00333 TiXmlEncoding encoding );
00334
00335
00336 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00337
00338
00339
00340 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00341 {
00342 assert( p );
00343 if ( encoding == TIXML_ENCODING_UTF8 )
00344 {
00345 *length = utf8ByteTable[ *((const unsigned char*)p) ];
00346 assert( *length >= 0 && *length < 5 );
00347 }
00348 else
00349 {
00350 *length = 1;
00351 }
00352
00353 if ( *length == 1 )
00354 {
00355 if ( *p == '&' )
00356 return GetEntity( p, _value, length, encoding );
00357 *_value = *p;
00358 return p+1;
00359 }
00360 else if ( *length )
00361 {
00362
00363
00364 for( int i=0; p[i] && i<*length; ++i ) {
00365 _value[i] = p[i];
00366 }
00367 return p + (*length);
00368 }
00369 else
00370 {
00371
00372 return 0;
00373 }
00374 }
00375
00376
00377
00378
00379 static bool StringEqual( const char* p,
00380 const char* endTag,
00381 bool ignoreCase,
00382 TiXmlEncoding encoding );
00383
00384 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00385
00386 TiXmlCursor location;
00387
00389 void* userData;
00390
00391
00392
00393 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00394 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00395 inline static int ToLower( int v, TiXmlEncoding encoding )
00396 {
00397 if ( encoding == TIXML_ENCODING_UTF8 )
00398 {
00399 if ( v < 128 ) return tolower( v );
00400 return v;
00401 }
00402 else
00403 {
00404 return tolower( v );
00405 }
00406 }
00407 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00408
00409 private:
00410 TiXmlBase( const TiXmlBase& );
00411 void operator=( const TiXmlBase& base );
00412
00413 struct Entity
00414 {
00415 const char* str;
00416 unsigned int strLength;
00417 char chr;
00418 };
00419 enum
00420 {
00421 NUM_ENTITY = 5,
00422 MAX_ENTITY_LENGTH = 6
00423
00424 };
00425 static Entity entity[ NUM_ENTITY ];
00426 static bool condenseWhiteSpace;
00427 };
00428
00429
00436 class TINYXML_EXPORT TiXmlNode : public TiXmlBase
00437 {
00438 friend class TiXmlDocument;
00439 friend class TiXmlElement;
00440
00441 public:
00442 #ifdef TIXML_USE_STL
00443
00447 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00448
00465 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00466
00468 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00469
00470 #endif
00471
00475 enum NodeType
00476 {
00477 DOCUMENT,
00478 ELEMENT,
00479 COMMENT,
00480 UNKNOWN,
00481 TEXT,
00482 DECLARATION,
00483 TYPECOUNT
00484 };
00485
00486 virtual ~TiXmlNode();
00487
00500 const char *Value() const { return value.c_str (); }
00501
00502 #ifdef TIXML_USE_STL
00503
00507 const std::string& ValueStr() const { return value; }
00508 #endif
00509
00510 const TIXML_STRING& ValueTStr() const { return value; }
00511
00521 void SetValue(const char * _value) { value = _value;}
00522
00523 #ifdef TIXML_USE_STL
00524
00525 void SetValue( const std::string& _value ) { value = _value; }
00526 #endif
00527
00529 void Clear();
00530
00532 TiXmlNode* Parent() { return parent; }
00533 const TiXmlNode* Parent() const { return parent; }
00534
00535 const TiXmlNode* FirstChild() const { return firstChild; }
00536 TiXmlNode* FirstChild() { return firstChild; }
00537 const TiXmlNode* FirstChild( const char * value ) const;
00538
00539 TiXmlNode* FirstChild( const char * _value ) {
00540
00541
00542 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00543 }
00544 const TiXmlNode* LastChild() const { return lastChild; }
00545 TiXmlNode* LastChild() { return lastChild; }
00546
00547 const TiXmlNode* LastChild( const char * value ) const;
00548 TiXmlNode* LastChild( const char * _value ) {
00549 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00550 }
00551
00552 #ifdef TIXML_USE_STL
00553 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00554 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00555 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00556 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00557 #endif
00558
00575 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00576 TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
00577 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00578 }
00579
00581 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00582 TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
00583 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00584 }
00585
00586 #ifdef TIXML_USE_STL
00587 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00588 TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
00589 #endif
00590
00594 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00595
00596
00606 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00607
00611 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00612
00616 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00617
00621 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00622
00624 bool RemoveChild( TiXmlNode* removeThis );
00625
00627 const TiXmlNode* PreviousSibling() const { return prev; }
00628 TiXmlNode* PreviousSibling() { return prev; }
00629
00631 const TiXmlNode* PreviousSibling( const char * ) const;
00632 TiXmlNode* PreviousSibling( const char *_prev ) {
00633 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00634 }
00635
00636 #ifdef TIXML_USE_STL
00637 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00638 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00639 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00640 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00641 #endif
00642
00644 const TiXmlNode* NextSibling() const { return next; }
00645 TiXmlNode* NextSibling() { return next; }
00646
00648 const TiXmlNode* NextSibling( const char * ) const;
00649 TiXmlNode* NextSibling( const char* _next ) {
00650 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
00651 }
00652
00657 const TiXmlElement* NextSiblingElement() const;
00658 TiXmlElement* NextSiblingElement() {
00659 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
00660 }
00661
00666 const TiXmlElement* NextSiblingElement( const char * ) const;
00667 TiXmlElement* NextSiblingElement( const char *_next ) {
00668 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00669 }
00670
00671 #ifdef TIXML_USE_STL
00672 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00673 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
00674 #endif
00675
00677 const TiXmlElement* FirstChildElement() const;
00678 TiXmlElement* FirstChildElement() {
00679 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00680 }
00681
00683 const TiXmlElement* FirstChildElement( const char * _value ) const;
00684 TiXmlElement* FirstChildElement( const char * _value ) {
00685 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00686 }
00687
00688 #ifdef TIXML_USE_STL
00689 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00690 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
00691 #endif
00692
00697 int Type() const { return type; }
00698
00702 const TiXmlDocument* GetDocument() const;
00703 TiXmlDocument* GetDocument() {
00704 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00705 }
00706
00708 bool NoChildren() const { return !firstChild; }
00709
00710 virtual const TiXmlDocument* ToDocument() const { return 0; }
00711 virtual const TiXmlElement* ToElement() const { return 0; }
00712 virtual const TiXmlComment* ToComment() const { return 0; }
00713 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
00714 virtual const TiXmlText* ToText() const { return 0; }
00715 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
00716
00717 virtual TiXmlDocument* ToDocument() { return 0; }
00718 virtual TiXmlElement* ToElement() { return 0; }
00719 virtual TiXmlComment* ToComment() { return 0; }
00720 virtual TiXmlUnknown* ToUnknown() { return 0; }
00721 virtual TiXmlText* ToText() { return 0; }
00722 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
00723
00727 virtual TiXmlNode* Clone() const = 0;
00728
00751 virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
00752
00753 protected:
00754 TiXmlNode( NodeType _type );
00755
00756
00757
00758 void CopyTo( TiXmlNode* target ) const;
00759
00760 #ifdef TIXML_USE_STL
00761
00762 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
00763 #endif
00764
00765
00766 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00767
00768 TiXmlNode* parent;
00769 NodeType type;
00770
00771 TiXmlNode* firstChild;
00772 TiXmlNode* lastChild;
00773
00774 TIXML_STRING value;
00775
00776 TiXmlNode* prev;
00777 TiXmlNode* next;
00778
00779 private:
00780 TiXmlNode( const TiXmlNode& );
00781 void operator=( const TiXmlNode& base );
00782 };
00783
00784
00792 class TINYXML_EXPORT TiXmlAttribute : public TiXmlBase
00793 {
00794 friend class TiXmlAttributeSet;
00795
00796 public:
00798 TiXmlAttribute() : TiXmlBase()
00799 {
00800 document = 0;
00801 prev = next = 0;
00802 }
00803
00804 #ifdef TIXML_USE_STL
00805
00806 TiXmlAttribute( const std::string& _name, const std::string& _value )
00807 {
00808 name = _name;
00809 value = _value;
00810 document = 0;
00811 prev = next = 0;
00812 }
00813 #endif
00814
00816 TiXmlAttribute( const char * _name, const char * _value )
00817 {
00818 name = _name;
00819 value = _value;
00820 document = 0;
00821 prev = next = 0;
00822 }
00823
00824 const char* Name() const { return name.c_str(); }
00825 const char* Value() const { return value.c_str(); }
00826 #ifdef TIXML_USE_STL
00827 const std::string& ValueStr() const { return value; }
00828 #endif
00829 int IntValue() const;
00830 double DoubleValue() const;
00831
00832
00833 const TIXML_STRING& NameTStr() const { return name; }
00834
00844 int QueryIntValue( int* _value ) const;
00846 int QueryDoubleValue( double* _value ) const;
00847
00848 void SetName( const char* _name ) { name = _name; }
00849 void SetValue( const char* _value ) { value = _value; }
00850
00851 void SetIntValue( int _value );
00852 void SetDoubleValue( double _value );
00853
00854 #ifdef TIXML_USE_STL
00855
00856 void SetName( const std::string& _name ) { name = _name; }
00858 void SetValue( const std::string& _value ) { value = _value; }
00859 #endif
00860
00862 const TiXmlAttribute* Next() const;
00863 TiXmlAttribute* Next() {
00864 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
00865 }
00866
00868 const TiXmlAttribute* Previous() const;
00869 TiXmlAttribute* Previous() {
00870 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
00871 }
00872
00873 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00874 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00875 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00876
00877
00878
00879
00880 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00881
00882
00883 virtual void Print( FILE* cfile, int depth ) const {
00884 Print( cfile, depth, 0 );
00885 }
00886 void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
00887
00888
00889
00890 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00891
00892 private:
00893 TiXmlAttribute( const TiXmlAttribute& );
00894 void operator=( const TiXmlAttribute& base );
00895
00896 TiXmlDocument* document;
00897 TIXML_STRING name;
00898 TIXML_STRING value;
00899 TiXmlAttribute* prev;
00900 TiXmlAttribute* next;
00901 };
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916 class TINYXML_EXPORT TiXmlAttributeSet
00917 {
00918 public:
00919 TiXmlAttributeSet();
00920 ~TiXmlAttributeSet();
00921
00922 void Add( TiXmlAttribute* attribute );
00923 void Remove( TiXmlAttribute* attribute );
00924
00925 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00926 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00927 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00928 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00929
00930 const TiXmlAttribute* Find( const char* _name ) const;
00931 TiXmlAttribute* Find( const char* _name ) {
00932 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00933 }
00934 #ifdef TIXML_USE_STL
00935 const TiXmlAttribute* Find( const std::string& _name ) const;
00936 TiXmlAttribute* Find( const std::string& _name ) {
00937 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00938 }
00939
00940 #endif
00941
00942 private:
00943
00944
00945 TiXmlAttributeSet( const TiXmlAttributeSet& );
00946 void operator=( const TiXmlAttributeSet& );
00947
00948 TiXmlAttribute sentinel;
00949 };
00950
00951
00956 class TINYXML_EXPORT TiXmlElement : public TiXmlNode
00957 {
00958 public:
00960 TiXmlElement (const char * in_value);
00961
00962 #ifdef TIXML_USE_STL
00963
00964 TiXmlElement( const std::string& _value );
00965 #endif
00966
00967 TiXmlElement( const TiXmlElement& );
00968
00969 void operator=( const TiXmlElement& base );
00970
00971 virtual ~TiXmlElement();
00972
00976 const char* Attribute( const char* name ) const;
00977
00984 const char* Attribute( const char* name, int* i ) const;
00985
00992 const char* Attribute( const char* name, double* d ) const;
00993
01001 int QueryIntAttribute( const char* name, int* _value ) const;
01003 int QueryDoubleAttribute( const char* name, double* _value ) const;
01005 int QueryFloatAttribute( const char* name, float* _value ) const {
01006 double d;
01007 int result = QueryDoubleAttribute( name, &d );
01008 if ( result == TIXML_SUCCESS ) {
01009 *_value = (float)d;
01010 }
01011 return result;
01012 }
01013
01014 #ifdef TIXML_USE_STL
01015
01023 template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
01024 {
01025 const TiXmlAttribute* node = attributeSet.Find( name );
01026 if ( !node )
01027 return TIXML_NO_ATTRIBUTE;
01028
01029 std::stringstream sstream( node->ValueStr() );
01030 sstream >> *outValue;
01031 if ( !sstream.fail() )
01032 return TIXML_SUCCESS;
01033 return TIXML_WRONG_TYPE;
01034 }
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050 #endif
01051
01055 void SetAttribute( const char* name, const char * _value );
01056
01057 #ifdef TIXML_USE_STL
01058 const std::string* Attribute( const std::string& name ) const;
01059 const std::string* Attribute( const std::string& name, int* i ) const;
01060 const std::string* Attribute( const std::string& name, double* d ) const;
01061 int QueryIntAttribute( const std::string& name, int* _value ) const;
01062 int QueryDoubleAttribute( const std::string& name, double* _value ) const;
01063
01065 void SetAttribute( const std::string& name, const std::string& _value );
01067 void SetAttribute( const std::string& name, int _value );
01068 #endif
01069
01073 void SetAttribute( const char * name, int value );
01074
01078 void SetDoubleAttribute( const char * name, double value );
01079
01082 void RemoveAttribute( const char * name );
01083 #ifdef TIXML_USE_STL
01084 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
01085 #endif
01086
01087 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
01088 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
01089 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
01090 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
01091
01124 const char* GetText() const;
01125
01127 virtual TiXmlNode* Clone() const;
01128
01129 virtual void Print( FILE* cfile, int depth ) const;
01130
01131
01132
01133
01134 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01135
01136 virtual const TiXmlElement* ToElement() const { return this; }
01137 virtual TiXmlElement* ToElement() { return this; }
01138
01141 virtual bool Accept( TiXmlVisitor* visitor ) const;
01142
01143 protected:
01144
01145 void CopyTo( TiXmlElement* target ) const;
01146 void ClearThis();
01147
01148
01149 #ifdef TIXML_USE_STL
01150 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01151 #endif
01152
01153
01154
01155
01156 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01157
01158 private:
01159
01160 TiXmlAttributeSet attributeSet;
01161 };
01162
01163
01166 class TINYXML_EXPORT TiXmlComment : public TiXmlNode
01167 {
01168 public:
01170 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01172 TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
01173 SetValue( _value );
01174 }
01175 TiXmlComment( const TiXmlComment& );
01176 void operator=( const TiXmlComment& base );
01177
01178 virtual ~TiXmlComment() {}
01179
01181 virtual TiXmlNode* Clone() const;
01182
01183 virtual void Print( FILE* cfile, int depth ) const;
01184
01185
01186
01187
01188 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01189
01190 virtual const TiXmlComment* ToComment() const { return this; }
01191 virtual TiXmlComment* ToComment() { return this; }
01192
01195 virtual bool Accept( TiXmlVisitor* visitor ) const;
01196
01197 protected:
01198 void CopyTo( TiXmlComment* target ) const;
01199
01200
01201 #ifdef TIXML_USE_STL
01202 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01203 #endif
01204
01205
01206 private:
01207
01208 };
01209
01210
01216 class TINYXML_EXPORT TiXmlText : public TiXmlNode
01217 {
01218 friend class TiXmlElement;
01219 public:
01224 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01225 {
01226 SetValue( initValue );
01227 cdata = false;
01228 }
01229 virtual ~TiXmlText() {}
01230
01231 #ifdef TIXML_USE_STL
01232
01233 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01234 {
01235 SetValue( initValue );
01236 cdata = false;
01237 }
01238 #endif
01239
01240 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01241 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01242
01243
01244 virtual void Print( FILE* cfile, int depth ) const;
01245
01247 bool CDATA() const { return cdata; }
01249 void SetCDATA( bool _cdata ) { cdata = _cdata; }
01250
01251 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01252
01253 virtual const TiXmlText* ToText() const { return this; }
01254 virtual TiXmlText* ToText() { return this; }
01255
01258 virtual bool Accept( TiXmlVisitor* content ) const;
01259
01260 protected :
01262 virtual TiXmlNode* Clone() const;
01263 void CopyTo( TiXmlText* target ) const;
01264
01265 bool Blank() const;
01266
01267 #ifdef TIXML_USE_STL
01268 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01269 #endif
01270
01271 private:
01272 bool cdata;
01273 };
01274
01275
01289 class TINYXML_EXPORT TiXmlDeclaration : public TiXmlNode
01290 {
01291 public:
01293 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01294
01295 #ifdef TIXML_USE_STL
01296
01297 TiXmlDeclaration( const std::string& _version,
01298 const std::string& _encoding,
01299 const std::string& _standalone );
01300 #endif
01301
01303 TiXmlDeclaration( const char* _version,
01304 const char* _encoding,
01305 const char* _standalone );
01306
01307 TiXmlDeclaration( const TiXmlDeclaration& copy );
01308 void operator=( const TiXmlDeclaration& copy );
01309
01310 virtual ~TiXmlDeclaration() {}
01311
01313 const char *Version() const { return version.c_str (); }
01315 const char *Encoding() const { return encoding.c_str (); }
01317 const char *Standalone() const { return standalone.c_str (); }
01318
01320 virtual TiXmlNode* Clone() const;
01321
01322 virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01323 virtual void Print( FILE* cfile, int depth ) const {
01324 Print( cfile, depth, 0 );
01325 }
01326
01327 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01328
01329 virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
01330 virtual TiXmlDeclaration* ToDeclaration() { return this; }
01331
01334 virtual bool Accept( TiXmlVisitor* visitor ) const;
01335
01336 protected:
01337 void CopyTo( TiXmlDeclaration* target ) const;
01338
01339 #ifdef TIXML_USE_STL
01340 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01341 #endif
01342
01343 private:
01344
01345 TIXML_STRING version;
01346 TIXML_STRING encoding;
01347 TIXML_STRING standalone;
01348 };
01349
01350
01358 class TINYXML_EXPORT TiXmlUnknown : public TiXmlNode
01359 {
01360 public:
01361 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01362 virtual ~TiXmlUnknown() {}
01363
01364 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01365 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01366
01368 virtual TiXmlNode* Clone() const;
01369
01370 virtual void Print( FILE* cfile, int depth ) const;
01371
01372 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01373
01374 virtual const TiXmlUnknown* ToUnknown() const { return this; }
01375 virtual TiXmlUnknown* ToUnknown() { return this; }
01376
01379 virtual bool Accept( TiXmlVisitor* content ) const;
01380
01381 protected:
01382 void CopyTo( TiXmlUnknown* target ) const;
01383
01384 #ifdef TIXML_USE_STL
01385 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01386 #endif
01387
01388 private:
01389
01390 };
01391
01392
01397 class TINYXML_EXPORT TiXmlDocument : public TiXmlNode
01398 {
01399 public:
01401 TiXmlDocument();
01403 TiXmlDocument( const char * documentName );
01404
01405 #ifdef TIXML_USE_STL
01406
01407 TiXmlDocument( const std::string& documentName );
01408 #endif
01409
01410 TiXmlDocument( const TiXmlDocument& copy );
01411 void operator=( const TiXmlDocument& copy );
01412
01413 virtual ~TiXmlDocument() {}
01414
01419 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01421 bool SaveFile() const;
01423 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01425 bool SaveFile( const char * filename ) const;
01431 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01433 bool SaveFile( FILE* ) const;
01434
01435 #ifdef TIXML_USE_STL
01436 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01437 {
01438
01439
01440 return LoadFile( filename.c_str(), encoding );
01441 }
01442 bool SaveFile( const std::string& filename ) const
01443 {
01444
01445
01446 return SaveFile( filename.c_str() );
01447 }
01448 #endif
01449
01454 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01455
01460 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01461 TiXmlElement* RootElement() { return FirstChildElement(); }
01462
01468 bool Error() const { return error; }
01469
01471 const char * ErrorDesc() const { return errorDesc.c_str (); }
01472
01476 int ErrorId() const { return errorId; }
01477
01485 int ErrorRow() const { return errorLocation.row+1; }
01486 int ErrorCol() const { return errorLocation.col+1; }
01487
01512 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01513
01514 int TabSize() const { return tabsize; }
01515
01519 void ClearError() { error = false;
01520 errorId = 0;
01521 errorDesc = "";
01522 errorLocation.row = errorLocation.col = 0;
01523
01524 }
01525
01527 void Print() const { Print( stdout, 0 ); }
01528
01529
01530
01531
01532
01533
01534
01536 virtual void Print( FILE* cfile, int depth = 0 ) const;
01537
01538 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01539
01540 virtual const TiXmlDocument* ToDocument() const { return this; }
01541 virtual TiXmlDocument* ToDocument() { return this; }
01542
01545 virtual bool Accept( TiXmlVisitor* content ) const;
01546
01547 protected :
01548
01549 virtual TiXmlNode* Clone() const;
01550 #ifdef TIXML_USE_STL
01551 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01552 #endif
01553
01554 private:
01555 void CopyTo( TiXmlDocument* target ) const;
01556
01557 bool error;
01558 int errorId;
01559 TIXML_STRING errorDesc;
01560 int tabsize;
01561 TiXmlCursor errorLocation;
01562 bool useMicrosoftBOM;
01563 };
01564
01565
01646 class TINYXML_EXPORT TiXmlHandle
01647 {
01648 public:
01650 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01652 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01653 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01654
01656 TiXmlHandle FirstChild() const;
01658 TiXmlHandle FirstChild( const char * value ) const;
01660 TiXmlHandle FirstChildElement() const;
01662 TiXmlHandle FirstChildElement( const char * value ) const;
01663
01667 TiXmlHandle Child( const char* value, int index ) const;
01671 TiXmlHandle Child( int index ) const;
01676 TiXmlHandle ChildElement( const char* value, int index ) const;
01681 TiXmlHandle ChildElement( int index ) const;
01682
01683 #ifdef TIXML_USE_STL
01684 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01685 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01686
01687 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01688 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01689 #endif
01690
01693 TiXmlNode* ToNode() const { return node; }
01696 TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01699 TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01702 TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01703
01707 TiXmlNode* Node() const { return ToNode(); }
01711 TiXmlElement* Element() const { return ToElement(); }
01715 TiXmlText* Text() const { return ToText(); }
01719 TiXmlUnknown* Unknown() const { return ToUnknown(); }
01720
01721 private:
01722 TiXmlNode* node;
01723 };
01724
01725
01745 class TINYXML_EXPORT TiXmlPrinter : public TiXmlVisitor
01746 {
01747 public:
01748 TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
01749 buffer(), indent( " " ), lineBreak( "\n" ) {}
01750
01751 virtual bool VisitEnter( const TiXmlDocument& doc );
01752 virtual bool VisitExit( const TiXmlDocument& doc );
01753
01754 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
01755 virtual bool VisitExit( const TiXmlElement& element );
01756
01757 virtual bool Visit( const TiXmlDeclaration& declaration );
01758 virtual bool Visit( const TiXmlText& text );
01759 virtual bool Visit( const TiXmlComment& comment );
01760 virtual bool Visit( const TiXmlUnknown& unknown );
01761
01765 void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
01767 const char* Indent() { return indent.c_str(); }
01772 void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
01774 const char* LineBreak() { return lineBreak.c_str(); }
01775
01779 void SetStreamPrinting() { indent = "";
01780 lineBreak = "";
01781 }
01783 const char* CStr() { return buffer.c_str(); }
01785 size_t Size() { return buffer.size(); }
01786
01787 #ifdef TIXML_USE_STL
01788
01789 const std::string& Str() { return buffer; }
01790 #endif
01791
01792 private:
01793 void DoIndent() {
01794 for( int i=0; i<depth; ++i )
01795 buffer += indent;
01796 }
01797 void DoLineBreak() {
01798 buffer += lineBreak;
01799 }
01800
01801 int depth;
01802 bool simpleTextPrint;
01803 TIXML_STRING buffer;
01804 TIXML_STRING indent;
01805 TIXML_STRING lineBreak;
01806 };
01807
01808
01809 #ifdef _MSC_VER
01810 #pragma warning( pop )
01811 #endif
01812
01813 #endif
01814