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