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 ROSPACK_TINYXML_INCLUDED
00027 #define ROSPACK_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_BUILD_STATIC_LIBS)
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 namespace rospack_tinyxml {
00098
00099 class TiXmlDocument;
00100 class TiXmlElement;
00101 class TiXmlComment;
00102 class TiXmlUnknown;
00103 class TiXmlAttribute;
00104 class TiXmlText;
00105 class TiXmlDeclaration;
00106 class TiXmlParsingData;
00107
00108 const int TIXML_MAJOR_VERSION = 2;
00109 const int TIXML_MINOR_VERSION = 5;
00110 const int TIXML_PATCH_VERSION = 3;
00111
00112
00113
00114
00115 struct TiXmlCursor
00116 {
00117 TiXmlCursor() { Clear(); }
00118 void Clear() { row = col = -1; }
00119
00120 int row;
00121 int col;
00122 };
00123
00124
00143 class TINYXML_EXPORT TiXmlVisitor
00144 {
00145 public:
00146 virtual ~TiXmlVisitor() {}
00147
00149 virtual bool VisitEnter( const TiXmlDocument& ) { return true; }
00151 virtual bool VisitExit( const TiXmlDocument& ) { return true; }
00152
00154 virtual bool VisitEnter( const TiXmlElement& , const TiXmlAttribute* ) { return true; }
00156 virtual bool VisitExit( const TiXmlElement& ) { return true; }
00157
00159 virtual bool Visit( const TiXmlDeclaration& ) { return true; }
00161 virtual bool Visit( const TiXmlText& ) { return true; }
00163 virtual bool Visit( const TiXmlComment& ) { return true; }
00165 virtual bool Visit( const TiXmlUnknown& ) { return true; }
00166 };
00167
00168
00169 enum
00170 {
00171 TIXML_SUCCESS,
00172 TIXML_NO_ATTRIBUTE,
00173 TIXML_WRONG_TYPE
00174 };
00175
00176
00177
00178 enum TiXmlEncoding
00179 {
00180 TIXML_ENCODING_UNKNOWN,
00181 TIXML_ENCODING_UTF8,
00182 TIXML_ENCODING_LEGACY
00183 };
00184
00185 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00186
00209 class TINYXML_EXPORT TiXmlBase
00210 {
00211 friend class TiXmlNode;
00212 friend class TiXmlElement;
00213 friend class TiXmlDocument;
00214
00215 public:
00216 TiXmlBase() : userData(0) {}
00217 virtual ~TiXmlBase() {}
00218
00228 virtual void Print( FILE* cfile, int depth ) const = 0;
00229
00236 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00237
00239 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00240
00259 int Row() const { return location.row + 1; }
00260 int Column() const { return location.col + 1; }
00261
00262 void SetUserData( void* user ) { userData = user; }
00263 void* GetUserData() { return userData; }
00264 const void* GetUserData() const { return userData; }
00265
00266
00267
00268 static const int utf8ByteTable[256];
00269
00270 virtual const char* Parse( const char* p,
00271 TiXmlParsingData* data,
00272 TiXmlEncoding encoding ) = 0;
00273
00277 static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
00278
00279 enum
00280 {
00281 TIXML_NO_ERROR = 0,
00282 TIXML_ERROR,
00283 TIXML_ERROR_OPENING_FILE,
00284 TIXML_ERROR_OUT_OF_MEMORY,
00285 TIXML_ERROR_PARSING_ELEMENT,
00286 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00287 TIXML_ERROR_READING_ELEMENT_VALUE,
00288 TIXML_ERROR_READING_ATTRIBUTES,
00289 TIXML_ERROR_PARSING_EMPTY,
00290 TIXML_ERROR_READING_END_TAG,
00291 TIXML_ERROR_PARSING_UNKNOWN,
00292 TIXML_ERROR_PARSING_COMMENT,
00293 TIXML_ERROR_PARSING_DECLARATION,
00294 TIXML_ERROR_DOCUMENT_EMPTY,
00295 TIXML_ERROR_EMBEDDED_NULL,
00296 TIXML_ERROR_PARSING_CDATA,
00297 TIXML_ERROR_DOCUMENT_TOP_ONLY,
00298
00299 TIXML_ERROR_STRING_COUNT
00300 };
00301
00302 protected:
00303
00304 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00305 inline static bool IsWhiteSpace( char c )
00306 {
00307 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00308 }
00309 inline static bool IsWhiteSpace( int c )
00310 {
00311 if ( c < 256 )
00312 return IsWhiteSpace( (char) c );
00313 return false;
00314 }
00315
00316 #ifdef TIXML_USE_STL
00317 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
00318 static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
00319 #endif
00320
00321
00322
00323
00324
00325 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00326
00327
00328
00329
00330 static const char* ReadText( const char* in,
00331 TIXML_STRING* text,
00332 bool ignoreWhiteSpace,
00333 const char* endTag,
00334 bool ignoreCase,
00335 TiXmlEncoding encoding );
00336
00337
00338 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00339
00340
00341
00342 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00343 {
00344 assert( p );
00345 if ( encoding == TIXML_ENCODING_UTF8 )
00346 {
00347 *length = utf8ByteTable[ *((const unsigned char*)p) ];
00348 assert( *length >= 0 && *length < 5 );
00349 }
00350 else
00351 {
00352 *length = 1;
00353 }
00354
00355 if ( *length == 1 )
00356 {
00357 if ( *p == '&' )
00358 return GetEntity( p, _value, length, encoding );
00359 *_value = *p;
00360 return p+1;
00361 }
00362 else if ( *length )
00363 {
00364
00365
00366 for( int i=0; p[i] && i<*length; ++i ) {
00367 _value[i] = p[i];
00368 }
00369 return p + (*length);
00370 }
00371 else
00372 {
00373
00374 return 0;
00375 }
00376 }
00377
00378
00379
00380
00381 static bool StringEqual( const char* p,
00382 const char* endTag,
00383 bool ignoreCase,
00384 TiXmlEncoding encoding );
00385
00386 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00387
00388 TiXmlCursor location;
00389
00391 void* userData;
00392
00393
00394
00395 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00396 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00397 inline static int ToLower( int v, TiXmlEncoding encoding )
00398 {
00399 if ( encoding == TIXML_ENCODING_UTF8 )
00400 {
00401 if ( v < 128 ) return tolower( v );
00402 return v;
00403 }
00404 else
00405 {
00406 return tolower( v );
00407 }
00408 }
00409 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00410
00411 private:
00412 TiXmlBase( const TiXmlBase& );
00413 void operator=( const TiXmlBase& base );
00414
00415 struct Entity
00416 {
00417 const char* str;
00418 unsigned int strLength;
00419 char chr;
00420 };
00421 enum
00422 {
00423 NUM_ENTITY = 5,
00424 MAX_ENTITY_LENGTH = 6
00425
00426 };
00427 static Entity entity[ NUM_ENTITY ];
00428 static bool condenseWhiteSpace;
00429 };
00430
00431
00438 class TINYXML_EXPORT TiXmlNode : public TiXmlBase
00439 {
00440 friend class TiXmlDocument;
00441 friend class TiXmlElement;
00442
00443 public:
00444 #ifdef TIXML_USE_STL
00445
00449 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00450
00467 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00468
00470 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00471
00472 #endif
00473
00477 enum NodeType
00478 {
00479 DOCUMENT,
00480 ELEMENT,
00481 COMMENT,
00482 UNKNOWN,
00483 TEXT,
00484 DECLARATION,
00485 TYPECOUNT
00486 };
00487
00488 virtual ~TiXmlNode();
00489
00502 const char *Value() const { return value.c_str (); }
00503
00504 #ifdef TIXML_USE_STL
00505
00509 const std::string& ValueStr() const { return value; }
00510 #endif
00511
00512 const TIXML_STRING& ValueTStr() const { return value; }
00513
00523 void SetValue(const char * _value) { value = _value;}
00524
00525 #ifdef TIXML_USE_STL
00526
00527 void SetValue( const std::string& _value ) { value = _value; }
00528 #endif
00529
00531 void Clear();
00532
00534 TiXmlNode* Parent() { return parent; }
00535 const TiXmlNode* Parent() const { return parent; }
00536
00537 const TiXmlNode* FirstChild() const { return firstChild; }
00538 TiXmlNode* FirstChild() { return firstChild; }
00539 const TiXmlNode* FirstChild( const char * value ) const;
00540
00541 TiXmlNode* FirstChild( const char * _value ) {
00542
00543
00544 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00545 }
00546 const TiXmlNode* LastChild() const { return lastChild; }
00547 TiXmlNode* LastChild() { return lastChild; }
00548
00549 const TiXmlNode* LastChild( const char * value ) const;
00550 TiXmlNode* LastChild( const char * _value ) {
00551 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00552 }
00553
00554 #ifdef TIXML_USE_STL
00555 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
00556 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
00557 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
00558 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
00559 #endif
00560
00577 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00578 TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
00579 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00580 }
00581
00583 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00584 TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
00585 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00586 }
00587
00588 #ifdef TIXML_USE_STL
00589 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
00590 TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
00591 #endif
00592
00596 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00597
00598
00608 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00609
00613 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00614
00618 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00619
00623 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00624
00626 bool RemoveChild( TiXmlNode* removeThis );
00627
00629 const TiXmlNode* PreviousSibling() const { return prev; }
00630 TiXmlNode* PreviousSibling() { return prev; }
00631
00633 const TiXmlNode* PreviousSibling( const char * ) const;
00634 TiXmlNode* PreviousSibling( const char *_prev ) {
00635 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00636 }
00637
00638 #ifdef TIXML_USE_STL
00639 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
00640 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
00641 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
00642 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
00643 #endif
00644
00646 const TiXmlNode* NextSibling() const { return next; }
00647 TiXmlNode* NextSibling() { return next; }
00648
00650 const TiXmlNode* NextSibling( const char * ) const;
00651 TiXmlNode* NextSibling( const char* _next ) {
00652 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
00653 }
00654
00659 const TiXmlElement* NextSiblingElement() const;
00660 TiXmlElement* NextSiblingElement() {
00661 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
00662 }
00663
00668 const TiXmlElement* NextSiblingElement( const char * ) const;
00669 TiXmlElement* NextSiblingElement( const char *_next ) {
00670 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00671 }
00672
00673 #ifdef TIXML_USE_STL
00674 const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
00675 TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
00676 #endif
00677
00679 const TiXmlElement* FirstChildElement() const;
00680 TiXmlElement* FirstChildElement() {
00681 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00682 }
00683
00685 const TiXmlElement* FirstChildElement( const char * _value ) const;
00686 TiXmlElement* FirstChildElement( const char * _value ) {
00687 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00688 }
00689
00690 #ifdef TIXML_USE_STL
00691 const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
00692 TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
00693 #endif
00694
00699 int Type() const { return type; }
00700
00704 const TiXmlDocument* GetDocument() const;
00705 TiXmlDocument* GetDocument() {
00706 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00707 }
00708
00710 bool NoChildren() const { return !firstChild; }
00711
00712 virtual const TiXmlDocument* ToDocument() const { return 0; }
00713 virtual const TiXmlElement* ToElement() const { return 0; }
00714 virtual const TiXmlComment* ToComment() const { return 0; }
00715 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
00716 virtual const TiXmlText* ToText() const { return 0; }
00717 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
00718
00719 virtual TiXmlDocument* ToDocument() { return 0; }
00720 virtual TiXmlElement* ToElement() { return 0; }
00721 virtual TiXmlComment* ToComment() { return 0; }
00722 virtual TiXmlUnknown* ToUnknown() { return 0; }
00723 virtual TiXmlText* ToText() { return 0; }
00724 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
00725
00729 virtual TiXmlNode* Clone() const = 0;
00730
00753 virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
00754
00755 protected:
00756 TiXmlNode( NodeType _type );
00757
00758
00759
00760 void CopyTo( TiXmlNode* target ) const;
00761
00762 #ifdef TIXML_USE_STL
00763
00764 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
00765 #endif
00766
00767
00768 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00769
00770 TiXmlNode* parent;
00771 NodeType type;
00772
00773 TiXmlNode* firstChild;
00774 TiXmlNode* lastChild;
00775
00776 TIXML_STRING value;
00777
00778 TiXmlNode* prev;
00779 TiXmlNode* next;
00780
00781 private:
00782 TiXmlNode( const TiXmlNode& );
00783 void operator=( const TiXmlNode& base );
00784 };
00785
00786
00794 class TINYXML_EXPORT TiXmlAttribute : public TiXmlBase
00795 {
00796 friend class TiXmlAttributeSet;
00797
00798 public:
00800 TiXmlAttribute() : TiXmlBase()
00801 {
00802 document = 0;
00803 prev = next = 0;
00804 }
00805
00806 #ifdef TIXML_USE_STL
00807
00808 TiXmlAttribute( const std::string& _name, const std::string& _value )
00809 {
00810 name = _name;
00811 value = _value;
00812 document = 0;
00813 prev = next = 0;
00814 }
00815 #endif
00816
00818 TiXmlAttribute( const char * _name, const char * _value )
00819 {
00820 name = _name;
00821 value = _value;
00822 document = 0;
00823 prev = next = 0;
00824 }
00825
00826 const char* Name() const { return name.c_str(); }
00827 const char* Value() const { return value.c_str(); }
00828 #ifdef TIXML_USE_STL
00829 const std::string& ValueStr() const { return value; }
00830 #endif
00831 int IntValue() const;
00832 double DoubleValue() const;
00833
00834
00835 const TIXML_STRING& NameTStr() const { return name; }
00836
00846 int QueryIntValue( int* _value ) const;
00848 int QueryDoubleValue( double* _value ) const;
00849
00850 void SetName( const char* _name ) { name = _name; }
00851 void SetValue( const char* _value ) { value = _value; }
00852
00853 void SetIntValue( int _value );
00854 void SetDoubleValue( double _value );
00855
00856 #ifdef TIXML_USE_STL
00857
00858 void SetName( const std::string& _name ) { name = _name; }
00860 void SetValue( const std::string& _value ) { value = _value; }
00861 #endif
00862
00864 const TiXmlAttribute* Next() const;
00865 TiXmlAttribute* Next() {
00866 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
00867 }
00868
00870 const TiXmlAttribute* Previous() const;
00871 TiXmlAttribute* Previous() {
00872 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
00873 }
00874
00875 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00876 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00877 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00878
00879
00880
00881
00882 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00883
00884
00885 virtual void Print( FILE* cfile, int depth ) const {
00886 Print( cfile, depth, 0 );
00887 }
00888 void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
00889
00890
00891
00892 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00893
00894 private:
00895 TiXmlAttribute( const TiXmlAttribute& );
00896 void operator=( const TiXmlAttribute& base );
00897
00898 TiXmlDocument* document;
00899 TIXML_STRING name;
00900 TIXML_STRING value;
00901 TiXmlAttribute* prev;
00902 TiXmlAttribute* next;
00903 };
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918 class TINYXML_EXPORT TiXmlAttributeSet
00919 {
00920 public:
00921 TiXmlAttributeSet();
00922 ~TiXmlAttributeSet();
00923
00924 void Add( TiXmlAttribute* attribute );
00925 void Remove( TiXmlAttribute* attribute );
00926
00927 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00928 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00929 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00930 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00931
00932 const TiXmlAttribute* Find( const char* _name ) const;
00933 TiXmlAttribute* Find( const char* _name ) {
00934 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00935 }
00936 #ifdef TIXML_USE_STL
00937 const TiXmlAttribute* Find( const std::string& _name ) const;
00938 TiXmlAttribute* Find( const std::string& _name ) {
00939 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
00940 }
00941
00942 #endif
00943
00944 private:
00945
00946
00947 TiXmlAttributeSet( const TiXmlAttributeSet& );
00948 void operator=( const TiXmlAttributeSet& );
00949
00950 TiXmlAttribute sentinel;
00951 };
00952
00953
00958 class TINYXML_EXPORT TiXmlElement : public TiXmlNode
00959 {
00960 public:
00962 TiXmlElement (const char * in_value);
00963
00964 #ifdef TIXML_USE_STL
00965
00966 TiXmlElement( const std::string& _value );
00967 #endif
00968
00969 TiXmlElement( const TiXmlElement& );
00970
00971 void operator=( const TiXmlElement& base );
00972
00973 virtual ~TiXmlElement();
00974
00978 const char* Attribute( const char* name ) const;
00979
00986 const char* Attribute( const char* name, int* i ) const;
00987
00994 const char* Attribute( const char* name, double* d ) const;
00995
01003 int QueryIntAttribute( const char* name, int* _value ) const;
01005 int QueryDoubleAttribute( const char* name, double* _value ) const;
01007 int QueryFloatAttribute( const char* name, float* _value ) const {
01008 double d;
01009 int result = QueryDoubleAttribute( name, &d );
01010 if ( result == TIXML_SUCCESS ) {
01011 *_value = (float)d;
01012 }
01013 return result;
01014 }
01015
01016 #ifdef TIXML_USE_STL
01017
01025 template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
01026 {
01027 const TiXmlAttribute* node = attributeSet.Find( name );
01028 if ( !node )
01029 return TIXML_NO_ATTRIBUTE;
01030
01031 std::stringstream sstream( node->ValueStr() );
01032 sstream >> *outValue;
01033 if ( !sstream.fail() )
01034 return TIXML_SUCCESS;
01035 return TIXML_WRONG_TYPE;
01036 }
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052 #endif
01053
01057 void SetAttribute( const char* name, const char * _value );
01058
01059 #ifdef TIXML_USE_STL
01060 const std::string* Attribute( const std::string& name ) const;
01061 const std::string* Attribute( const std::string& name, int* i ) const;
01062 const std::string* Attribute( const std::string& name, double* d ) const;
01063 int QueryIntAttribute( const std::string& name, int* _value ) const;
01064 int QueryDoubleAttribute( const std::string& name, double* _value ) const;
01065
01067 void SetAttribute( const std::string& name, const std::string& _value );
01069 void SetAttribute( const std::string& name, int _value );
01070 #endif
01071
01075 void SetAttribute( const char * name, int value );
01076
01080 void SetDoubleAttribute( const char * name, double value );
01081
01084 void RemoveAttribute( const char * name );
01085 #ifdef TIXML_USE_STL
01086 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
01087 #endif
01088
01089 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
01090 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
01091 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
01092 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
01093
01126 const char* GetText() const;
01127
01129 virtual TiXmlNode* Clone() const;
01130
01131 virtual void Print( FILE* cfile, int depth ) const;
01132
01133
01134
01135
01136 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01137
01138 virtual const TiXmlElement* ToElement() const { return this; }
01139 virtual TiXmlElement* ToElement() { return this; }
01140
01143 virtual bool Accept( TiXmlVisitor* visitor ) const;
01144
01145 protected:
01146
01147 void CopyTo( TiXmlElement* target ) const;
01148 void ClearThis();
01149
01150
01151 #ifdef TIXML_USE_STL
01152 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01153 #endif
01154
01155
01156
01157
01158 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01159
01160 private:
01161
01162 TiXmlAttributeSet attributeSet;
01163 };
01164
01165
01168 class TINYXML_EXPORT TiXmlComment : public TiXmlNode
01169 {
01170 public:
01172 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01174 TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
01175 SetValue( _value );
01176 }
01177 TiXmlComment( const TiXmlComment& );
01178 void operator=( const TiXmlComment& base );
01179
01180 virtual ~TiXmlComment() {}
01181
01183 virtual TiXmlNode* Clone() const;
01184
01185 virtual void Print( FILE* cfile, int depth ) const;
01186
01187
01188
01189
01190 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01191
01192 virtual const TiXmlComment* ToComment() const { return this; }
01193 virtual TiXmlComment* ToComment() { return this; }
01194
01197 virtual bool Accept( TiXmlVisitor* visitor ) const;
01198
01199 protected:
01200 void CopyTo( TiXmlComment* target ) const;
01201
01202
01203 #ifdef TIXML_USE_STL
01204 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01205 #endif
01206
01207
01208 private:
01209
01210 };
01211
01212
01218 class TINYXML_EXPORT TiXmlText : public TiXmlNode
01219 {
01220 friend class TiXmlElement;
01221 public:
01226 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01227 {
01228 SetValue( initValue );
01229 cdata = false;
01230 }
01231 virtual ~TiXmlText() {}
01232
01233 #ifdef TIXML_USE_STL
01234
01235 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01236 {
01237 SetValue( initValue );
01238 cdata = false;
01239 }
01240 #endif
01241
01242 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
01243 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
01244
01245
01246 virtual void Print( FILE* cfile, int depth ) const;
01247
01249 bool CDATA() const { return cdata; }
01251 void SetCDATA( bool _cdata ) { cdata = _cdata; }
01252
01253 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01254
01255 virtual const TiXmlText* ToText() const { return this; }
01256 virtual TiXmlText* ToText() { return this; }
01257
01260 virtual bool Accept( TiXmlVisitor* content ) const;
01261
01262 protected :
01264 virtual TiXmlNode* Clone() const;
01265 void CopyTo( TiXmlText* target ) const;
01266
01267 bool Blank() const;
01268
01269 #ifdef TIXML_USE_STL
01270 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01271 #endif
01272
01273 private:
01274 bool cdata;
01275 };
01276
01277
01291 class TINYXML_EXPORT TiXmlDeclaration : public TiXmlNode
01292 {
01293 public:
01295 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
01296
01297 #ifdef TIXML_USE_STL
01298
01299 TiXmlDeclaration( const std::string& _version,
01300 const std::string& _encoding,
01301 const std::string& _standalone );
01302 #endif
01303
01305 TiXmlDeclaration( const char* _version,
01306 const char* _encoding,
01307 const char* _standalone );
01308
01309 TiXmlDeclaration( const TiXmlDeclaration& copy );
01310 void operator=( const TiXmlDeclaration& copy );
01311
01312 virtual ~TiXmlDeclaration() {}
01313
01315 const char *Version() const { return version.c_str (); }
01317 const char *Encoding() const { return encoding.c_str (); }
01319 const char *Standalone() const { return standalone.c_str (); }
01320
01322 virtual TiXmlNode* Clone() const;
01323
01324 virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01325 virtual void Print( FILE* cfile, int depth ) const {
01326 Print( cfile, depth, 0 );
01327 }
01328
01329 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01330
01331 virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
01332 virtual TiXmlDeclaration* ToDeclaration() { return this; }
01333
01336 virtual bool Accept( TiXmlVisitor* visitor ) const;
01337
01338 protected:
01339 void CopyTo( TiXmlDeclaration* target ) const;
01340
01341 #ifdef TIXML_USE_STL
01342 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01343 #endif
01344
01345 private:
01346
01347 TIXML_STRING version;
01348 TIXML_STRING encoding;
01349 TIXML_STRING standalone;
01350 };
01351
01352
01360 class TINYXML_EXPORT TiXmlUnknown : public TiXmlNode
01361 {
01362 public:
01363 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
01364 virtual ~TiXmlUnknown() {}
01365
01366 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
01367 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
01368
01370 virtual TiXmlNode* Clone() const;
01371
01372 virtual void Print( FILE* cfile, int depth ) const;
01373
01374 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01375
01376 virtual const TiXmlUnknown* ToUnknown() const { return this; }
01377 virtual TiXmlUnknown* ToUnknown() { return this; }
01378
01381 virtual bool Accept( TiXmlVisitor* content ) const;
01382
01383 protected:
01384 void CopyTo( TiXmlUnknown* target ) const;
01385
01386 #ifdef TIXML_USE_STL
01387 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01388 #endif
01389
01390 private:
01391
01392 };
01393
01394
01399 class TINYXML_EXPORT TiXmlDocument : public TiXmlNode
01400 {
01401 public:
01403 TiXmlDocument();
01405 TiXmlDocument( const char * documentName );
01406
01407 #ifdef TIXML_USE_STL
01408
01409 TiXmlDocument( const std::string& documentName );
01410 #endif
01411
01412 TiXmlDocument( const TiXmlDocument& copy );
01413 void operator=( const TiXmlDocument& copy );
01414
01415 virtual ~TiXmlDocument() {}
01416
01421 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01423 bool SaveFile() const;
01425 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01427 bool SaveFile( const char * filename ) const;
01433 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01435 bool SaveFile( FILE* ) const;
01436
01437 #ifdef TIXML_USE_STL
01438 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
01439 {
01440
01441
01442 return LoadFile( filename.c_str(), encoding );
01443 }
01444 bool SaveFile( const std::string& filename ) const
01445 {
01446
01447
01448 return SaveFile( filename.c_str() );
01449 }
01450 #endif
01451
01456 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01457
01462 const TiXmlElement* RootElement() const { return FirstChildElement(); }
01463 TiXmlElement* RootElement() { return FirstChildElement(); }
01464
01470 bool Error() const { return error; }
01471
01473 const char * ErrorDesc() const { return errorDesc.c_str (); }
01474
01478 int ErrorId() const { return errorId; }
01479
01487 int ErrorRow() const { return errorLocation.row+1; }
01488 int ErrorCol() const { return errorLocation.col+1; }
01489
01514 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
01515
01516 int TabSize() const { return tabsize; }
01517
01521 void ClearError() { error = false;
01522 errorId = 0;
01523 errorDesc = "";
01524 errorLocation.row = errorLocation.col = 0;
01525
01526 }
01527
01529 void Print() const { Print( stdout, 0 ); }
01530
01531
01532
01533
01534
01535
01536
01538 virtual void Print( FILE* cfile, int depth = 0 ) const;
01539
01540 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01541
01542 virtual const TiXmlDocument* ToDocument() const { return this; }
01543 virtual TiXmlDocument* ToDocument() { return this; }
01544
01547 virtual bool Accept( TiXmlVisitor* content ) const;
01548
01549 protected :
01550
01551 virtual TiXmlNode* Clone() const;
01552 #ifdef TIXML_USE_STL
01553 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01554 #endif
01555
01556 private:
01557 void CopyTo( TiXmlDocument* target ) const;
01558
01559 bool error;
01560 int errorId;
01561 TIXML_STRING errorDesc;
01562 int tabsize;
01563 TiXmlCursor errorLocation;
01564 bool useMicrosoftBOM;
01565 };
01566
01567
01648 class TINYXML_EXPORT TiXmlHandle
01649 {
01650 public:
01652 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
01654 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
01655 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01656
01658 TiXmlHandle FirstChild() const;
01660 TiXmlHandle FirstChild( const char * value ) const;
01662 TiXmlHandle FirstChildElement() const;
01664 TiXmlHandle FirstChildElement( const char * value ) const;
01665
01669 TiXmlHandle Child( const char* value, int index ) const;
01673 TiXmlHandle Child( int index ) const;
01678 TiXmlHandle ChildElement( const char* value, int index ) const;
01683 TiXmlHandle ChildElement( int index ) const;
01684
01685 #ifdef TIXML_USE_STL
01686 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
01687 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
01688
01689 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
01690 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
01691 #endif
01692
01695 TiXmlNode* ToNode() const { return node; }
01698 TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01701 TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01704 TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01705
01709 TiXmlNode* Node() const { return ToNode(); }
01713 TiXmlElement* Element() const { return ToElement(); }
01717 TiXmlText* Text() const { return ToText(); }
01721 TiXmlUnknown* Unknown() const { return ToUnknown(); }
01722
01723 private:
01724 TiXmlNode* node;
01725 };
01726
01727
01747 class TINYXML_EXPORT TiXmlPrinter : public TiXmlVisitor
01748 {
01749 public:
01750 TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
01751 buffer(), indent( " " ), lineBreak( "\n" ) {}
01752
01753 virtual bool VisitEnter( const TiXmlDocument& doc );
01754 virtual bool VisitExit( const TiXmlDocument& doc );
01755
01756 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
01757 virtual bool VisitExit( const TiXmlElement& element );
01758
01759 virtual bool Visit( const TiXmlDeclaration& declaration );
01760 virtual bool Visit( const TiXmlText& text );
01761 virtual bool Visit( const TiXmlComment& comment );
01762 virtual bool Visit( const TiXmlUnknown& unknown );
01763
01767 void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
01769 const char* Indent() { return indent.c_str(); }
01774 void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
01776 const char* LineBreak() { return lineBreak.c_str(); }
01777
01781 void SetStreamPrinting() { indent = "";
01782 lineBreak = "";
01783 }
01785 const char* CStr() { return buffer.c_str(); }
01787 size_t Size() { return buffer.size(); }
01788
01789 #ifdef TIXML_USE_STL
01790
01791 const std::string& Str() { return buffer; }
01792 #endif
01793
01794 private:
01795 void DoIndent() {
01796 for( int i=0; i<depth; ++i )
01797 buffer += indent;
01798 }
01799 void DoLineBreak() {
01800 buffer += lineBreak;
01801 }
01802
01803 int depth;
01804 bool simpleTextPrint;
01805 TIXML_STRING buffer;
01806 TIXML_STRING indent;
01807 TIXML_STRING lineBreak;
01808 };
01809
01810 }
01811
01812 #ifdef _MSC_VER
01813 #pragma warning( pop )
01814 #endif
01815
01816 #endif
01817