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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef TINYXML_INCLUDED
00053 #define TINYXML_INCLUDED
00054
00055
00057
00058 #define DOTSCENEINTERFACE_API
00059 #define TIXML_USE_STL
00061
00062
00063 #ifdef _MSC_VER
00064 #pragma warning( disable : 4530 )
00065 #pragma warning( disable : 4786 )
00066 #endif
00067
00068 #include <ctype.h>
00069 #include <stdio.h>
00070 #include <stdlib.h>
00071 #include <string.h>
00072 #include <assert.h>
00073
00074
00075 #if defined( _DEBUG ) && !defined( DEBUG )
00076 #define DEBUG
00077 #endif
00078
00079 #if defined( DEBUG ) && defined( _MSC_VER )
00080 #define NOMINMAX
00081 #include <windows.h>
00082 #define TIXML_LOG OutputDebugString
00083 #else
00084 #define TIXML_LOG printf
00085 #endif
00086
00087
00088 #ifdef TIXML_USE_STL
00089 #include <string>
00090 #include <iostream>
00091 #define TIXML_STRING std::string
00092 #define TIXML_ISTREAM std::istream
00093 #define TIXML_OSTREAM std::ostream
00094 #else
00095 #include "tinystr.h"
00096 #define TIXML_STRING TiXmlString
00097 #define TIXML_OSTREAM TiXmlOutStream
00098 #endif
00099
00100 class TiXmlDocument;
00101 class TiXmlElement;
00102 class TiXmlComment;
00103 class TiXmlUnknown;
00104 class TiXmlAttribute;
00105 class TiXmlText;
00106 class TiXmlDeclaration;
00107
00108
00131 class DOTSCENEINTERFACE_API TiXmlBase
00132 {
00133 friend class TiXmlNode;
00134 friend class TiXmlElement;
00135 friend class TiXmlDocument;
00136
00137 public:
00138 TiXmlBase() {}
00139 virtual ~TiXmlBase() {}
00140
00146 virtual void Print( FILE* cfile, int depth ) const = 0;
00147
00154 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
00155
00157 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
00158
00159 protected:
00160
00161 static const char* SkipWhiteSpace( const char* );
00162 inline static bool IsWhiteSpace( int c ) { return ( isspace( c ) || c == '\n' || c == '\r' ); }
00163
00164 virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00165
00166 #ifdef TIXML_USE_STL
00167 static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00168 static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00169 #endif
00170
00171
00172
00173
00174
00175 static const char* ReadName( const char* p, TIXML_STRING* name );
00176
00177
00178
00179
00180 static const char* ReadText( const char* in,
00181 TIXML_STRING* text,
00182 bool ignoreWhiteSpace,
00183 const char* endTag,
00184 bool ignoreCase );
00185 virtual const char* Parse( const char* p ) = 0;
00186
00187
00188 static const char* GetEntity( const char* in, char* value );
00189
00190
00191 inline static const char* GetChar( const char* p, char* value )
00192 {
00193 assert( p );
00194 if ( *p == '&' )
00195 {
00196 return GetEntity( p, value );
00197 }
00198 else
00199 {
00200 *value = *p;
00201 return p+1;
00202 }
00203 }
00204
00205
00206
00207 static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00208
00209 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00210
00211
00212 bool static StringEqual( const char* p,
00213 const char* endTag,
00214 bool ignoreCase );
00215
00216
00217 enum
00218 {
00219 TIXML_NO_ERROR = 0,
00220 TIXML_ERROR,
00221 TIXML_ERROR_OPENING_FILE,
00222 TIXML_ERROR_OUT_OF_MEMORY,
00223 TIXML_ERROR_PARSING_ELEMENT,
00224 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00225 TIXML_ERROR_READING_ELEMENT_VALUE,
00226 TIXML_ERROR_READING_ATTRIBUTES,
00227 TIXML_ERROR_PARSING_EMPTY,
00228 TIXML_ERROR_READING_END_TAG,
00229 TIXML_ERROR_PARSING_UNKNOWN,
00230 TIXML_ERROR_PARSING_COMMENT,
00231 TIXML_ERROR_PARSING_DECLARATION,
00232 TIXML_ERROR_DOCUMENT_EMPTY,
00233
00234 TIXML_ERROR_STRING_COUNT
00235 };
00236 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00237
00238 private:
00239 struct Entity
00240 {
00241 const char* str;
00242 unsigned int strLength;
00243 char chr;
00244 };
00245 enum
00246 {
00247 NUM_ENTITY = 5,
00248 MAX_ENTITY_LENGTH = 6
00249
00250 };
00251 static Entity entity[ NUM_ENTITY ];
00252 static bool condenseWhiteSpace;
00253 };
00254
00255
00262 class DOTSCENEINTERFACE_API TiXmlNode : public TiXmlBase
00263 {
00264 friend class TiXmlDocument;
00265 friend class TiXmlElement;
00266
00267 public:
00268 #ifdef TIXML_USE_STL
00269
00273 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00274
00290 friend std::ostream & operator<< (std::ostream& out, const TiXmlNode& base);
00291
00292 #else
00293
00294 friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00295 #endif
00296
00300 enum NodeType
00301 {
00302 DOCUMENT,
00303 ELEMENT,
00304 COMMENT,
00305 UNKNOWN,
00306 TEXT,
00307 DECLARATION,
00308 TYPECOUNT
00309 };
00310
00311 virtual ~TiXmlNode();
00312
00325 const char * Value () const { return value.c_str (); }
00326
00336 void SetValue (const char * _value) { value = _value;}
00337
00338 #ifdef TIXML_USE_STL
00340 void SetValue( const std::string& value )
00341 {
00342 SetValue( value.c_str() );
00343 }
00344 #endif
00345
00347 void Clear();
00348
00350 TiXmlNode* Parent() const { return parent; }
00351
00352 TiXmlNode* FirstChild() const { return firstChild; }
00353 TiXmlNode* FirstChild( const char * value ) const;
00354
00355 TiXmlNode* LastChild() const { return lastChild; }
00356 TiXmlNode* LastChild( const char * value ) const;
00357
00358 #ifdef TIXML_USE_STL
00359 TiXmlNode* FirstChild( const std::string& value ) const { return FirstChild (value.c_str ()); }
00360 TiXmlNode* LastChild( const std::string& value ) const { return LastChild (value.c_str ()); }
00361 #endif
00362
00379 TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
00380
00382 TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
00383
00384 #ifdef TIXML_USE_STL
00385 TiXmlNode* IterateChildren( const std::string& value, TiXmlNode* previous ) const { return IterateChildren (value.c_str (), previous); }
00386 #endif
00387
00391 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00392
00396 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00397
00401 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
00402
00406 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00407
00409 bool RemoveChild( TiXmlNode* removeThis );
00410
00412 TiXmlNode* PreviousSibling() const { return prev; }
00413
00415 TiXmlNode* PreviousSibling( const char * ) const;
00416
00417 #ifdef TIXML_USE_STL
00418 TiXmlNode* PreviousSibling( const std::string& value ) const { return PreviousSibling (value.c_str ()); }
00419 TiXmlNode* NextSibling( const std::string& value) const { return NextSibling (value.c_str ()); }
00420 #endif
00421
00423 TiXmlNode* NextSibling() const { return next; }
00424
00426 TiXmlNode* NextSibling( const char * ) const;
00427
00432 TiXmlElement* NextSiblingElement() const;
00433
00438 TiXmlElement* NextSiblingElement( const char * ) const;
00439
00440 #ifdef TIXML_USE_STL
00441 TiXmlElement* NextSiblingElement( const std::string& value) const { return NextSiblingElement (value.c_str ()); }
00442 #endif
00443
00445 TiXmlElement* FirstChildElement() const;
00446
00448 TiXmlElement* FirstChildElement( const char * value ) const;
00449
00450 #ifdef TIXML_USE_STL
00451 TiXmlElement* FirstChildElement( const std::string& value ) const { return FirstChildElement (value.c_str ()); }
00452 #endif
00453
00455 virtual int Type() const { return type; }
00456
00460 TiXmlDocument* GetDocument() const;
00461
00463 bool NoChildren() const { return !firstChild; }
00464
00465 TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
00466 TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
00467 TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
00468 TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
00469 TiXmlText* ToText() const { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
00470 TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
00471
00472 virtual TiXmlNode* Clone() const = 0;
00473
00474 void SetUserData( void* user ) { userData = user; }
00475 void* GetUserData() { return userData; }
00476
00477 protected:
00478 TiXmlNode( NodeType type );
00479
00480 #ifdef TIXML_USE_STL
00481
00482 virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00483 #endif
00484
00485
00486 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00487
00488
00489 TiXmlNode* Identify( const char* start );
00490 void CopyToClone( TiXmlNode* target ) const { target->SetValue (value.c_str() );
00491 target->userData = userData; }
00492
00493
00494 TIXML_STRING SValue() const { return value ; }
00495
00496 TiXmlNode* parent;
00497 NodeType type;
00498
00499 TiXmlNode* firstChild;
00500 TiXmlNode* lastChild;
00501
00502 TIXML_STRING value;
00503
00504 TiXmlNode* prev;
00505 TiXmlNode* next;
00506 void* userData;
00507 };
00508
00509
00519 class DOTSCENEINTERFACE_API TiXmlAttribute : public TiXmlBase
00520 {
00521 friend class TiXmlAttributeSet;
00522
00523 public:
00525 TiXmlAttribute() : prev( 0 ), next( 0 ) {}
00526
00527 #ifdef TIXML_USE_STL
00529 TiXmlAttribute( const std::string& _name, const std::string& _value )
00530 {
00531 name = _name;
00532 value = _value;
00533 }
00534 #endif
00535
00537 TiXmlAttribute( const char * _name, const char * _value ): name( _name ), value( _value ), prev( 0 ), next( 0 ) {}
00538 const char* Name() const { return name.c_str (); }
00539 const char* Value() const { return value.c_str (); }
00540 const int IntValue() const;
00541 const double DoubleValue() const;
00542
00543 void SetName( const char* _name ) { name = _name; }
00544 void SetValue( const char* _value ) { value = _value; }
00545
00546 void SetIntValue( int value );
00547 void SetDoubleValue( double value );
00548
00549 #ifdef TIXML_USE_STL
00551 void SetName( const std::string& _name )
00552 {
00553 SetName(_name.c_str() );
00554 }
00556 void SetValue( const std::string& _value )
00557 {
00558 SetValue( _value.c_str() );
00559 }
00560 #endif
00561
00563 TiXmlAttribute* Next() const;
00565 TiXmlAttribute* Previous() const;
00566
00567 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00568 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
00569 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
00570
00571
00572
00573
00574
00575 virtual const char* Parse( const char* p );
00576
00577
00578 virtual void Print( FILE* cfile, int depth ) const;
00579
00580 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00581
00582
00583 void SetDocument( TiXmlDocument* doc ) { document = doc; }
00584
00585 private:
00586 TiXmlDocument* document;
00587 TIXML_STRING name;
00588 TIXML_STRING value;
00589 TiXmlAttribute* prev;
00590 TiXmlAttribute* next;
00591 };
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606 class DOTSCENEINTERFACE_API TiXmlAttributeSet
00607 {
00608 public:
00609 TiXmlAttributeSet();
00610 ~TiXmlAttributeSet();
00611
00612 void Add( TiXmlAttribute* attribute );
00613 void Remove( TiXmlAttribute* attribute );
00614
00615 TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00616 TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00617 TiXmlAttribute* Find( const char * name ) const;
00618
00619 private:
00620 TiXmlAttribute sentinel;
00621 };
00622
00623
00628 class DOTSCENEINTERFACE_API TiXmlElement : public TiXmlNode
00629 {
00630 public:
00632 TiXmlElement (const char * in_value);
00633
00634 #ifdef TIXML_USE_STL
00636 TiXmlElement( const std::string& _value ) : TiXmlNode( TiXmlNode::ELEMENT )
00637 {
00638 firstChild = lastChild = 0;
00639 value = _value;
00640 }
00641 #endif
00642
00643 virtual ~TiXmlElement();
00644
00645
00646
00647 #ifndef TIXML_USE_STL
00648
00652 const char* Attribute( const char* name ) const;
00653
00660 const char* Attribute( const char* name, int* i ) const;
00661
00665 void SetAttribute( const char* name, const char * value );
00666
00667 #endif
00668
00669 #ifdef TIXML_USE_STL
00670 const char* Attribute( const std::string& name ) const;
00671 const char* Attribute( const std::string& name, int* i ) const;
00672
00674 void SetAttribute( const std::string& name, const std::string& value );
00676 void SetAttribute( const std::string& name, int value );
00677 #endif
00678
00682 void SetAttribute( const char * name, int value );
00683
00686 void RemoveAttribute( const char * name );
00687 #ifdef TIXML_USE_STL
00688 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
00689 #endif
00690
00691 TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
00692 TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
00693
00694
00695 virtual TiXmlNode* Clone() const;
00696
00697
00698 virtual void Print( FILE* cfile, int depth ) const;
00699
00700 protected:
00701
00702
00703 #ifdef TIXML_USE_STL
00704 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00705 #endif
00706 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00707
00708
00709
00710
00711
00712 virtual const char* Parse( const char* p );
00713
00714
00715
00716
00717
00718 const char* ReadValue( const char* in );
00719
00720 private:
00721 TiXmlAttributeSet attributeSet;
00722 };
00723
00724
00727 class DOTSCENEINTERFACE_API TiXmlComment : public TiXmlNode
00728 {
00729 public:
00731 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
00732 virtual ~TiXmlComment() {}
00733
00734
00735 virtual TiXmlNode* Clone() const;
00736
00737 virtual void Print( FILE* cfile, int depth ) const;
00738 protected:
00739
00740 #ifdef TIXML_USE_STL
00741 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00742 #endif
00743 virtual void StreamOut( TIXML_OSTREAM * out ) const;
00744
00745
00746
00747
00748 virtual const char* Parse( const char* p );
00749 };
00750
00751
00754 class DOTSCENEINTERFACE_API TiXmlText : public TiXmlNode
00755 {
00756 friend class TiXmlElement;
00757 public:
00759 TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
00760 {
00761 SetValue( initValue );
00762 }
00763 virtual ~TiXmlText() {}
00764
00765 #ifdef TIXML_USE_STL
00767 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
00768 {
00769 SetValue( initValue );
00770 }
00771 #endif
00772
00773 protected :
00774
00775 virtual TiXmlNode* Clone() const;
00776
00777 virtual void Print( FILE* cfile, int depth ) const;
00778 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00779
00780 bool Blank() const;
00781
00782
00783
00784
00785 virtual const char* Parse( const char* p );
00786
00787 #ifdef TIXML_USE_STL
00788 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00789 #endif
00790 };
00791
00792
00806 class DOTSCENEINTERFACE_API TiXmlDeclaration : public TiXmlNode
00807 {
00808 public:
00810 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
00811
00812 #ifdef TIXML_USE_STL
00814 TiXmlDeclaration(
00815 const std::string& _version,
00816 const std::string& _encoding,
00817 const std::string& _standalone )
00818 : TiXmlNode( TiXmlNode::DECLARATION )
00819 {
00820 version = _version;
00821 encoding = _encoding;
00822 standalone = _standalone;
00823 }
00824 #endif
00825
00827 TiXmlDeclaration( const char * _version,
00828 const char * _encoding,
00829 const char * _standalone );
00830
00831 virtual ~TiXmlDeclaration() {}
00832
00834 const char * Version() const { return version.c_str (); }
00836 const char * Encoding() const { return encoding.c_str (); }
00838 const char * Standalone() const { return standalone.c_str (); }
00839
00840
00841 virtual TiXmlNode* Clone() const;
00842
00843 virtual void Print( FILE* cfile, int depth ) const;
00844
00845 protected:
00846
00847 #ifdef TIXML_USE_STL
00848 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00849 #endif
00850 virtual void StreamOut ( TIXML_OSTREAM * out) const;
00851
00852
00853
00854
00855 virtual const char* Parse( const char* p );
00856
00857 private:
00858 TIXML_STRING version;
00859 TIXML_STRING encoding;
00860 TIXML_STRING standalone;
00861 };
00862
00863
00869 class DOTSCENEINTERFACE_API TiXmlUnknown : public TiXmlNode
00870 {
00871 public:
00872 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
00873 virtual ~TiXmlUnknown() {}
00874
00875
00876 virtual TiXmlNode* Clone() const;
00877
00878 virtual void Print( FILE* cfile, int depth ) const;
00879 protected:
00880
00881 #ifdef TIXML_USE_STL
00882 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00883 #endif
00884 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00885
00886
00887
00888
00889 virtual const char* Parse( const char* p );
00890 };
00891
00892
00897 class DOTSCENEINTERFACE_API TiXmlDocument : public TiXmlNode
00898 {
00899 public:
00901 TiXmlDocument();
00903 TiXmlDocument( const char * documentName );
00904
00905 #ifdef TIXML_USE_STL
00907 TiXmlDocument( const std::string& documentName ) :
00908 TiXmlNode( TiXmlNode::DOCUMENT )
00909 {
00910 value = documentName;
00911 error = false;
00912 }
00913 #endif
00914
00915 virtual ~TiXmlDocument() {}
00916
00921 bool LoadFile();
00923 bool SaveFile() const;
00925 bool LoadFile( const char * filename );
00927 bool SaveFile( const char * filename ) const;
00928
00929 #ifdef TIXML_USE_STL
00930 bool LoadFile( const std::string& filename )
00931 {
00932 return ( LoadFile( filename.c_str() ));
00933 }
00934 bool SaveFile( const std::string& filename ) const
00935 {
00936
00937 return ( SaveFile( filename.c_str() ));
00938 }
00939 #endif
00940
00942 virtual const char* Parse( const char* p );
00943
00948 TiXmlElement* RootElement() const { return FirstChildElement(); }
00949
00951 bool Error() const { return error; }
00952
00954 const char * ErrorDesc() const { return errorDesc.c_str (); }
00955
00959 const int ErrorId() const { return errorId; }
00960
00962 void ClearError() { error = false; errorId = 0; errorDesc = ""; }
00963
00965 void Print() const { Print( stdout, 0 ); }
00966
00967
00968 virtual void Print( FILE* cfile, int depth = 0 ) const;
00969
00970 void SetError( int err ) { assert( err > 0 && err < TIXML_ERROR_STRING_COUNT );
00971 error = true;
00972 errorId = err;
00973 errorDesc = errorString[ errorId ]; }
00974
00975 protected :
00976 virtual void StreamOut ( TIXML_OSTREAM * out) const;
00977
00978 virtual TiXmlNode* Clone() const;
00979 #ifdef TIXML_USE_STL
00980 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00981 #endif
00982
00983 private:
00984 bool error;
00985 int errorId;
00986 TIXML_STRING errorDesc;
00987 };
00988
00989 #endif
00990