00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef TINYXML_INCLUDED
00027 #define TINYXML_INCLUDED
00028 
00029 #ifdef _MSC_VER
00030 #pragma warning( push )
00031 #pragma warning( disable : 4530 )
00032 #pragma warning( disable : 4786 )
00033 #endif
00034 
00035 #include <ctype.h>
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039 #include <assert.h>
00040 
00041 
00042 #if defined( _DEBUG ) && !defined( DEBUG )
00043 #define DEBUG
00044 #endif
00045 
00046 #ifdef TIXML_USE_STL
00047         #include <string>
00048         #include <iostream>
00049         #define TIXML_STRING    std::string
00050         #define TIXML_ISTREAM   std::istream
00051         #define TIXML_OSTREAM   std::ostream
00052 #else
00053         #include "tinystr.h"
00054         #define TIXML_STRING    TiXmlString
00055         #define TIXML_OSTREAM   TiXmlOutStream
00056 #endif
00057 
00058 
00059 
00060 
00061 
00062 
00063 #define TIXML_SAFE              // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress.
00064 #ifdef TIXML_SAFE
00065         #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
00066                 
00067                 #define TIXML_SNPRINTF _snprintf_s
00068                 #define TIXML_SNSCANF  _snscanf_s
00069         #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
00070                 
00071                 
00072                 #define TIXML_SNPRINTF _snprintf
00073                 #define TIXML_SNSCANF  _snscanf
00074         #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00075                 
00076                 
00077                 #define TIXML_SNPRINTF snprintf
00078                 #define TIXML_SNSCANF  snscanf
00079         #endif
00080 #endif  
00081 
00082 class TiXmlDocument;
00083 class TiXmlElement;
00084 class TiXmlComment;
00085 class TiXmlUnknown;
00086 class TiXmlAttribute;
00087 class TiXmlText;
00088 class TiXmlDeclaration;
00089 class TiXmlParsingData;
00090 
00091 const int TIXML_MAJOR_VERSION = 2;
00092 const int TIXML_MINOR_VERSION = 4;
00093 const int TIXML_PATCH_VERSION = 3;
00094 
00095 
00096 
00097 
00098 struct TiXmlCursor
00099 {
00100         TiXmlCursor()           { Clear(); }
00101         void Clear()            { row = col = -1; }
00102 
00103         int row;        
00104         int col;        
00105 };
00106 
00107 
00108 
00109 enum 
00110 { 
00111         TIXML_SUCCESS,
00112         TIXML_NO_ATTRIBUTE,
00113         TIXML_WRONG_TYPE
00114 };
00115 
00116 
00117 
00118 enum TiXmlEncoding
00119 {
00120         TIXML_ENCODING_UNKNOWN,
00121         TIXML_ENCODING_UTF8,
00122         TIXML_ENCODING_LEGACY
00123 };
00124 
00125 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 class TiXmlBase
00150 {
00151         friend class TiXmlNode;
00152         friend class TiXmlElement;
00153         friend class TiXmlDocument;
00154 
00155 public:
00156         TiXmlBase()     :       userData(0) {}
00157         virtual ~TiXmlBase()                                    {}
00158 
00159 
00160 
00161 
00162 
00163 
00164         virtual void Print( FILE* cfile, int depth ) const = 0;
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172         static void SetCondenseWhiteSpace( bool condense )              { condenseWhiteSpace = condense; }
00173 
00174 
00175         static bool IsWhiteSpaceCondensed()                                             { return condenseWhiteSpace; }
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195         int Row() const                 { return location.row + 1; }
00196         int Column() const              { return location.col + 1; }    
00197 
00198         void  SetUserData( void* user )                 { userData = user; }
00199         void* GetUserData()                                             { return userData; }
00200 
00201         
00202         
00203         static const int utf8ByteTable[256];
00204 
00205         virtual const char* Parse(      const char* p, 
00206                                                                 TiXmlParsingData* data, 
00207                                                                 TiXmlEncoding encoding  ) = 0;
00208 
00209         enum
00210         {
00211                 TIXML_NO_ERROR = 0,
00212                 TIXML_ERROR,
00213                 TIXML_ERROR_OPENING_FILE,
00214                 TIXML_ERROR_OUT_OF_MEMORY,
00215                 TIXML_ERROR_PARSING_ELEMENT,
00216                 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00217                 TIXML_ERROR_READING_ELEMENT_VALUE,
00218                 TIXML_ERROR_READING_ATTRIBUTES,
00219                 TIXML_ERROR_PARSING_EMPTY,
00220                 TIXML_ERROR_READING_END_TAG,
00221                 TIXML_ERROR_PARSING_UNKNOWN,
00222                 TIXML_ERROR_PARSING_COMMENT,
00223                 TIXML_ERROR_PARSING_DECLARATION,
00224                 TIXML_ERROR_DOCUMENT_EMPTY,
00225                 TIXML_ERROR_EMBEDDED_NULL,
00226                 TIXML_ERROR_PARSING_CDATA,
00227 
00228                 TIXML_ERROR_STRING_COUNT
00229         };
00230 
00231 protected:
00232 
00233         
00234         
00235         class StringToBuffer
00236         {
00237           public:
00238                 StringToBuffer( const TIXML_STRING& str );
00239                 ~StringToBuffer();
00240                 char* buffer;
00241         };
00242 
00243         static const char*      SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00244         inline static bool      IsWhiteSpace( char c )          
00245         { 
00246                 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); 
00247         }
00248         inline static bool      IsWhiteSpace( int c )
00249         {
00250                 if ( c < 256 )
00251                         return IsWhiteSpace( (char) c );
00252                 return false;   
00253         }
00254 
00255         virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00256 
00257         #ifdef TIXML_USE_STL
00258             static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00259             static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00260         #endif
00261 
00262         
00263 
00264 
00265 
00266         static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00267 
00268         
00269 
00270 
00271         static const char* ReadText(    const char* in,                         
00272                                                                         TIXML_STRING* text,                     
00273                                                                         bool ignoreWhiteSpace,          
00274                                                                         const char* endTag,                     
00275                                                                         bool ignoreCase,                        
00276                                                                         TiXmlEncoding encoding );       
00277 
00278         
00279         static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00280 
00281         
00282         
00283         inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00284         {
00285                 assert( p );
00286                 if ( encoding == TIXML_ENCODING_UTF8 )
00287                 {
00288                         *length = utf8ByteTable[ *((unsigned char*)p) ];
00289                         assert( *length >= 0 && *length < 5 );
00290                 }
00291                 else
00292                 {
00293                         *length = 1;
00294                 }
00295 
00296                 if ( *length == 1 )
00297                 {
00298                         if ( *p == '&' )
00299                                 return GetEntity( p, _value, length, encoding );
00300                         *_value = *p;
00301                         return p+1;
00302                 }
00303                 else if ( *length )
00304                 {
00305                         
00306                                                                                                 
00307                         for( int i=0; p[i] && i<*length; ++i ) {
00308                                 _value[i] = p[i];
00309                         }
00310                         return p + (*length);
00311                 }
00312                 else
00313                 {
00314                         
00315                         return 0;
00316                 }
00317         }
00318 
00319         
00320         
00321         static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00322 
00323         static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00324 
00325         
00326         
00327         
00328         static bool StringEqual(        const char* p,
00329                                                                 const char* endTag,
00330                                                                 bool ignoreCase,
00331                                                                 TiXmlEncoding encoding );
00332 
00333         static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00334 
00335         TiXmlCursor location;
00336 
00337 
00338         void*                   userData;
00339         
00340         
00341         
00342         static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00343         static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00344         inline static int ToLower( int v, TiXmlEncoding encoding )
00345         {
00346                 if ( encoding == TIXML_ENCODING_UTF8 )
00347                 {
00348                         if ( v < 128 ) return tolower( v );
00349                         return v;
00350                 }
00351                 else
00352                 {
00353                         return tolower( v );
00354                 }
00355         }
00356         static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00357 
00358 private:
00359         TiXmlBase( const TiXmlBase& );                          
00360         void operator=( const TiXmlBase& base );        
00361 
00362         struct Entity
00363         {
00364                 const char*     str;
00365                 unsigned int    strLength;
00366                 char                chr;
00367         };
00368         enum
00369         {
00370                 NUM_ENTITY = 5,
00371                 MAX_ENTITY_LENGTH = 6
00372 
00373         };
00374         static Entity entity[ NUM_ENTITY ];
00375         static bool condenseWhiteSpace;
00376 };
00377 
00378 
00379 
00380 
00381 
00382 
00383 
00384 
00385 class TiXmlNode : public TiXmlBase
00386 {
00387         friend class TiXmlDocument;
00388         friend class TiXmlElement;
00389 
00390 public:
00391         #ifdef TIXML_USE_STL    
00392 
00393 
00394 
00395 
00396             friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00397 
00398 
00399 
00400 
00401 
00402 
00403 
00404 
00405 
00406 
00407 
00408 
00409 
00410 
00411 
00412 
00413   
00414             friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00415 
00416 
00417                 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00418 
00419         #else
00420             
00421             friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00422         #endif
00423 
00424 
00425 
00426 
00427         enum NodeType
00428         {
00429                 DOCUMENT,
00430                 ELEMENT,
00431                 COMMENT,
00432                 UNKNOWN,
00433                 TEXT,
00434                 DECLARATION,
00435                 TYPECOUNT
00436         };
00437 
00438         virtual ~TiXmlNode();
00439 
00440 
00441 
00442 
00443 
00444 
00445 
00446 
00447 
00448 
00449 
00450 
00451 
00452         const char *Value() const { return value.c_str (); }
00453 
00454     #ifdef TIXML_USE_STL
00455 
00456 
00457 
00458 
00459         const std::string& ValueStr() const { return value; }
00460         #endif
00461 
00462 
00463 
00464 
00465 
00466 
00467 
00468 
00469 
00470 
00471         void SetValue(const char * _value) { value = _value;}
00472 
00473     #ifdef TIXML_USE_STL
00474 
00475         void SetValue( const std::string& _value )      { value = _value; }
00476         #endif
00477 
00478 
00479         void Clear();
00480 
00481 
00482         TiXmlNode* Parent()                                                     { return parent; }
00483         const TiXmlNode* Parent() const                         { return parent; }
00484 
00485         const TiXmlNode* FirstChild()   const   { return firstChild; }          
00486         TiXmlNode* FirstChild()                                 { return firstChild; }
00487         const TiXmlNode* FirstChild( const char * value ) const;                        
00488         TiXmlNode* FirstChild( const char * value );                                            
00489 
00490         const TiXmlNode* LastChild() const      { return lastChild; }           
00491         TiXmlNode* LastChild()  { return lastChild; }
00492         const TiXmlNode* LastChild( const char * value ) const;                 
00493         TiXmlNode* LastChild( const char * value );     
00494 
00495     #ifdef TIXML_USE_STL
00496         const TiXmlNode* FirstChild( const std::string& _value ) const  {       return FirstChild (_value.c_str ());    }       
00497         TiXmlNode* FirstChild( const std::string& _value )                              {       return FirstChild (_value.c_str ());    }       
00498         const TiXmlNode* LastChild( const std::string& _value ) const   {       return LastChild (_value.c_str ());     }       
00499         TiXmlNode* LastChild( const std::string& _value )                               {       return LastChild (_value.c_str ());     }       
00500         #endif
00501 
00502 
00503 
00504 
00505 
00506 
00507 
00508 
00509 
00510 
00511 
00512 
00513 
00514 
00515 
00516 
00517 
00518         const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00519         TiXmlNode* IterateChildren( TiXmlNode* previous );
00520 
00521 
00522         const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00523         TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous );
00524 
00525     #ifdef TIXML_USE_STL
00526         const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const  {       return IterateChildren (_value.c_str (), previous);     }       
00527         TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) {  return IterateChildren (_value.c_str (), previous);     }       
00528         #endif
00529 
00530 
00531 
00532 
00533         TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00534 
00535 
00536 
00537 
00538 
00539 
00540 
00541 
00542 
00543 
00544 
00545         TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00546 
00547 
00548 
00549 
00550         TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00551 
00552 
00553 
00554 
00555         TiXmlNode* InsertAfterChild(  TiXmlNode* afterThis, const TiXmlNode& addThis );
00556 
00557 
00558 
00559 
00560         TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00561 
00562 
00563         bool RemoveChild( TiXmlNode* removeThis );
00564 
00565 
00566         const TiXmlNode* PreviousSibling() const                        { return prev; }
00567         TiXmlNode* PreviousSibling()                                            { return prev; }
00568 
00569 
00570         const TiXmlNode* PreviousSibling( const char * ) const;
00571         TiXmlNode* PreviousSibling( const char * );
00572 
00573     #ifdef TIXML_USE_STL
00574         const TiXmlNode* PreviousSibling( const std::string& _value ) const     {       return PreviousSibling (_value.c_str ());       }       
00575         TiXmlNode* PreviousSibling( const std::string& _value )                         {       return PreviousSibling (_value.c_str ());       }       
00576         const TiXmlNode* NextSibling( const std::string& _value) const          {       return NextSibling (_value.c_str ());   }       
00577         TiXmlNode* NextSibling( const std::string& _value)                                      {       return NextSibling (_value.c_str ());   }       
00578         #endif
00579 
00580 
00581         const TiXmlNode* NextSibling() const                            { return next; }
00582         TiXmlNode* NextSibling()                                                        { return next; }
00583 
00584 
00585         const TiXmlNode* NextSibling( const char * ) const;
00586         TiXmlNode* NextSibling( const char * );
00587 
00588 
00589 
00590 
00591 
00592         const TiXmlElement* NextSiblingElement() const;
00593         TiXmlElement* NextSiblingElement();
00594 
00595 
00596 
00597 
00598 
00599         const TiXmlElement* NextSiblingElement( const char * ) const;
00600         TiXmlElement* NextSiblingElement( const char * );
00601 
00602     #ifdef TIXML_USE_STL
00603         const TiXmlElement* NextSiblingElement( const std::string& _value) const        {       return NextSiblingElement (_value.c_str ());    }       
00604         TiXmlElement* NextSiblingElement( const std::string& _value)                            {       return NextSiblingElement (_value.c_str ());    }       
00605         #endif
00606 
00607 
00608         const TiXmlElement* FirstChildElement() const;
00609         TiXmlElement* FirstChildElement();
00610 
00611 
00612         const TiXmlElement* FirstChildElement( const char * value ) const;
00613         TiXmlElement* FirstChildElement( const char * value );
00614 
00615     #ifdef TIXML_USE_STL
00616         const TiXmlElement* FirstChildElement( const std::string& _value ) const        {       return FirstChildElement (_value.c_str ());     }       
00617         TiXmlElement* FirstChildElement( const std::string& _value )                            {       return FirstChildElement (_value.c_str ());     }       
00618         #endif
00619 
00620 
00621 
00622 
00623 
00624         int Type() const        { return type; }
00625 
00626 
00627 
00628 
00629         const TiXmlDocument* GetDocument() const;
00630         TiXmlDocument* GetDocument();
00631 
00632 
00633         bool NoChildren() const                                         { return !firstChild; }
00634 
00635         virtual const TiXmlDocument*    ToDocument()    const { return 0; } 
00636         virtual const TiXmlElement*     ToElement()     const { return 0; } 
00637         virtual const TiXmlComment*     ToComment()     const { return 0; } 
00638         virtual const TiXmlUnknown*     ToUnknown()     const { return 0; } 
00639         virtual const TiXmlText*        ToText()        const { return 0; } 
00640         virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } 
00641 
00642         virtual TiXmlDocument*          ToDocument()    { return 0; } 
00643         virtual TiXmlElement*           ToElement()         { return 0; } 
00644         virtual TiXmlComment*           ToComment()     { return 0; } 
00645         virtual TiXmlUnknown*           ToUnknown()         { return 0; } 
00646         virtual TiXmlText*                  ToText()        { return 0; } 
00647         virtual TiXmlDeclaration*       ToDeclaration() { return 0; } 
00648 
00649 
00650 
00651 
00652         virtual TiXmlNode* Clone() const = 0;
00653 
00654 protected:
00655         TiXmlNode( NodeType _type );
00656 
00657         
00658         
00659         void CopyTo( TiXmlNode* target ) const;
00660 
00661         #ifdef TIXML_USE_STL
00662             
00663             virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00664         #endif
00665 
00666         
00667         TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00668 
00669         TiXmlNode*              parent;
00670         NodeType                type;
00671 
00672         TiXmlNode*              firstChild;
00673         TiXmlNode*              lastChild;
00674 
00675         TIXML_STRING    value;
00676 
00677         TiXmlNode*              prev;
00678         TiXmlNode*              next;
00679 
00680 private:
00681         TiXmlNode( const TiXmlNode& );                          
00682         void operator=( const TiXmlNode& base );        
00683 };
00684 
00685 
00686 
00687 
00688 
00689 
00690 
00691 
00692 
00693 class TiXmlAttribute : public TiXmlBase
00694 {
00695         friend class TiXmlAttributeSet;
00696 
00697 public:
00698 
00699         TiXmlAttribute() : TiXmlBase()
00700         {
00701                 document = 0;
00702                 prev = next = 0;
00703         }
00704 
00705         #ifdef TIXML_USE_STL
00706 
00707         TiXmlAttribute( const std::string& _name, const std::string& _value )
00708         {
00709                 name = _name;
00710                 value = _value;
00711                 document = 0;
00712                 prev = next = 0;
00713         }
00714         #endif
00715 
00716 
00717         TiXmlAttribute( const char * _name, const char * _value )
00718         {
00719                 name = _name;
00720                 value = _value;
00721                 document = 0;
00722                 prev = next = 0;
00723         }
00724 
00725         const char*             Name()  const           { return name.c_str (); }               
00726         const char*             Value() const           { return value.c_str (); }              
00727         int                             IntValue() const;                                                                       
00728         double                  DoubleValue() const;                                                            
00729 
00730         
00731         const TIXML_STRING& NameTStr() const { return name; }
00732 
00733 
00734 
00735 
00736 
00737 
00738 
00739 
00740 
00741 
00742         int QueryIntValue( int* _value ) const;
00743 
00744         int QueryDoubleValue( double* _value ) const;
00745 
00746         void SetName( const char* _name )       { name = _name; }                               
00747         void SetValue( const char* _value )     { value = _value; }                             
00748 
00749         void SetIntValue( int _value );                                                                         
00750         void SetDoubleValue( double _value );                                                           
00751 
00752     #ifdef TIXML_USE_STL
00753 
00754         void SetName( const std::string& _name )        { name = _name; }       
00755 
00756         void SetValue( const std::string& _value )      { value = _value; }
00757         #endif
00758 
00759 
00760         const TiXmlAttribute* Next() const;
00761         TiXmlAttribute* Next();
00762 
00763         const TiXmlAttribute* Previous() const;
00764         TiXmlAttribute* Previous();
00765 
00766         bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00767         bool operator<( const TiXmlAttribute& rhs )      const { return name < rhs.name; }
00768         bool operator>( const TiXmlAttribute& rhs )  const { return name > rhs.name; }
00769 
00770         
00771 
00772 
00773         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00774 
00775         
00776         virtual void Print( FILE* cfile, int depth ) const;
00777 
00778         virtual void StreamOut( TIXML_OSTREAM * out ) const;
00779         
00780         
00781         void SetDocument( TiXmlDocument* doc )  { document = doc; }
00782 
00783 private:
00784         TiXmlAttribute( const TiXmlAttribute& );                                
00785         void operator=( const TiXmlAttribute& base );   
00786 
00787         TiXmlDocument*  document;       
00788         TIXML_STRING name;
00789         TIXML_STRING value;
00790         TiXmlAttribute* prev;
00791         TiXmlAttribute* next;
00792 };
00793 
00794 
00795 
00796 
00797 
00798 
00799 
00800 
00801 
00802 
00803 
00804 
00805 
00806 
00807 class TiXmlAttributeSet
00808 {
00809 public:
00810         TiXmlAttributeSet();
00811         ~TiXmlAttributeSet();
00812 
00813         void Add( TiXmlAttribute* attribute );
00814         void Remove( TiXmlAttribute* attribute );
00815 
00816         const TiXmlAttribute* First()   const   { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00817         TiXmlAttribute* First()                                 { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00818         const TiXmlAttribute* Last() const              { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00819         TiXmlAttribute* Last()                                  { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00820 
00821         const TiXmlAttribute*   Find( const TIXML_STRING& name ) const;
00822         TiXmlAttribute* Find( const TIXML_STRING& name );
00823 
00824 private:
00825         
00826         
00827         TiXmlAttributeSet( const TiXmlAttributeSet& );  
00828         void operator=( const TiXmlAttributeSet& );     
00829 
00830         TiXmlAttribute sentinel;
00831 };
00832 
00833 
00834 
00835 
00836 
00837 
00838 class TiXmlElement : public TiXmlNode
00839 {
00840 public:
00841 
00842         TiXmlElement (const char * in_value);
00843 
00844         #ifdef TIXML_USE_STL
00845 
00846         TiXmlElement( const std::string& _value );
00847         #endif
00848 
00849         TiXmlElement( const TiXmlElement& );
00850 
00851         void operator=( const TiXmlElement& base );
00852 
00853         virtual ~TiXmlElement();
00854 
00855 
00856 
00857 
00858         const char* Attribute( const char* name ) const;
00859 
00860 
00861 
00862 
00863 
00864 
00865 
00866         const char* Attribute( const char* name, int* i ) const;
00867 
00868 
00869 
00870 
00871 
00872 
00873 
00874         const char* Attribute( const char* name, double* d ) const;
00875 
00876 
00877 
00878 
00879 
00880 
00881 
00882       
00883         int QueryIntAttribute( const char* name, int* _value ) const;
00884 
00885         int QueryDoubleAttribute( const char* name, double* _value ) const;
00886 
00887         int QueryFloatAttribute( const char* name, float* _value ) const {
00888                 double d;
00889                 int result = QueryDoubleAttribute( name, &d );
00890                 if ( result == TIXML_SUCCESS ) {
00891                         *_value = (float)d;
00892                 }
00893                 return result;
00894         }
00895 
00896 
00897 
00898 
00899         void SetAttribute( const char* name, const char * _value );
00900 
00901     #ifdef TIXML_USE_STL
00902         const char* Attribute( const std::string& name ) const                          { return Attribute( name.c_str() ); }
00903         const char* Attribute( const std::string& name, int* i ) const          { return Attribute( name.c_str(), i ); }
00904         const char* Attribute( const std::string& name, double* d ) const       { return Attribute( name.c_str(), d ); }
00905         int QueryIntAttribute( const std::string& name, int* _value ) const     { return QueryIntAttribute( name.c_str(), _value ); }
00906         int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); }
00907 
00908 
00909         void SetAttribute( const std::string& name, const std::string& _value );
00910 
00911         void SetAttribute( const std::string& name, int _value );
00912         #endif
00913 
00914 
00915 
00916 
00917         void SetAttribute( const char * name, int value );
00918 
00919 
00920 
00921 
00922         void SetDoubleAttribute( const char * name, double value );
00923 
00924 
00925 
00926         void RemoveAttribute( const char * name );
00927     #ifdef TIXML_USE_STL
00928         void RemoveAttribute( const std::string& name ) {       RemoveAttribute (name.c_str ());        }       
00929         #endif
00930 
00931         const TiXmlAttribute* FirstAttribute() const    { return attributeSet.First(); }                
00932         TiXmlAttribute* FirstAttribute()                                { return attributeSet.First(); }
00933         const TiXmlAttribute* LastAttribute()   const   { return attributeSet.Last(); }         
00934         TiXmlAttribute* LastAttribute()                                 { return attributeSet.Last(); }
00935 
00936 
00937 
00938 
00939 
00940 
00941 
00942 
00943 
00944 
00945 
00946 
00947 
00948 
00949 
00950 
00951 
00952 
00953 
00954 
00955 
00956 
00957 
00958 
00959 
00960 
00961 
00962 
00963 
00964 
00965 
00966 
00967 
00968         const char* GetText() const;
00969 
00970 
00971         virtual TiXmlNode* Clone() const;
00972         
00973         virtual void Print( FILE* cfile, int depth ) const;
00974 
00975         
00976 
00977 
00978         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00979 
00980         virtual const TiXmlElement*     ToElement()     const { return this; } 
00981         virtual TiXmlElement*           ToElement()               { return this; } 
00982         
00983 protected:
00984 
00985         void CopyTo( TiXmlElement* target ) const;
00986         void ClearThis();       
00987 
00988         
00989         #ifdef TIXML_USE_STL
00990             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00991         #endif
00992         virtual void StreamOut( TIXML_OSTREAM * out ) const;
00993 
00994         
00995 
00996 
00997 
00998         const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
00999 
01000 private:
01001 
01002         TiXmlAttributeSet attributeSet;
01003 };
01004 
01005 
01006 
01007 
01008 class TiXmlComment : public TiXmlNode
01009 {
01010 public:
01011 
01012         TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01013         TiXmlComment( const TiXmlComment& );
01014         void operator=( const TiXmlComment& base );
01015 
01016         virtual ~TiXmlComment() {}
01017 
01018 
01019         virtual TiXmlNode* Clone() const;
01020 
01021         virtual void Print( FILE* cfile, int depth ) const;
01022 
01023         
01024 
01025 
01026         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01027 
01028         virtual const TiXmlComment*  ToComment() const { return this; } 
01029         virtual TiXmlComment*  ToComment() { return this; } 
01030 
01031 protected:
01032         void CopyTo( TiXmlComment* target ) const;
01033 
01034         
01035         #ifdef TIXML_USE_STL
01036             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01037         #endif
01038         virtual void StreamOut( TIXML_OSTREAM * out ) const;
01039 
01040 private:
01041 
01042 };
01043 
01044 
01045 
01046 
01047 
01048 
01049 
01050 class TiXmlText : public TiXmlNode
01051 {
01052         friend class TiXmlElement;
01053 public:
01054 
01055 
01056 
01057 
01058         TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01059         {
01060                 SetValue( initValue );
01061                 cdata = false;
01062         }
01063         virtual ~TiXmlText() {}
01064 
01065         #ifdef TIXML_USE_STL
01066 
01067         TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01068         {
01069                 SetValue( initValue );
01070                 cdata = false;
01071         }
01072         #endif
01073 
01074         TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT )       { copy.CopyTo( this ); }
01075         void operator=( const TiXmlText& base )                                                         { base.CopyTo( this ); }
01076 
01077 
01078         virtual void Print( FILE* cfile, int depth ) const;
01079 
01080 
01081         bool CDATA()                                    { return cdata; }
01082 
01083         void SetCDATA( bool _cdata )    { cdata = _cdata; }
01084 
01085         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01086 
01087         virtual const TiXmlText* ToText() const { return this; } 
01088         virtual TiXmlText*       ToText()       { return this; } 
01089 
01090 protected :
01091 
01092         virtual TiXmlNode* Clone() const;
01093         void CopyTo( TiXmlText* target ) const;
01094 
01095         virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01096         bool Blank() const;     
01097         
01098         #ifdef TIXML_USE_STL
01099             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01100         #endif
01101 
01102 private:
01103         bool cdata;                     
01104 };
01105 
01106 
01107 
01108 
01109 
01110 
01111 
01112 
01113 
01114 
01115 
01116 
01117 
01118 
01119 
01120 class TiXmlDeclaration : public TiXmlNode
01121 {
01122 public:
01123 
01124         TiXmlDeclaration()   : TiXmlNode( TiXmlNode::DECLARATION ) {}
01125 
01126 #ifdef TIXML_USE_STL
01127 
01128         TiXmlDeclaration(       const std::string& _version,
01129                                                 const std::string& _encoding,
01130                                                 const std::string& _standalone );
01131 #endif
01132 
01133 
01134         TiXmlDeclaration(       const char* _version,
01135                                                 const char* _encoding,
01136                                                 const char* _standalone );
01137 
01138         TiXmlDeclaration( const TiXmlDeclaration& copy );
01139         void operator=( const TiXmlDeclaration& copy );
01140 
01141         virtual ~TiXmlDeclaration()     {}
01142 
01143 
01144         const char *Version() const                     { return version.c_str (); }
01145 
01146         const char *Encoding() const            { return encoding.c_str (); }
01147 
01148         const char *Standalone() const          { return standalone.c_str (); }
01149 
01150 
01151         virtual TiXmlNode* Clone() const;
01152 
01153         virtual void Print( FILE* cfile, int depth ) const;
01154 
01155         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01156 
01157         virtual const TiXmlDeclaration* ToDeclaration() const { return this; } 
01158         virtual TiXmlDeclaration*       ToDeclaration()       { return this; } 
01159 
01160 protected:
01161         void CopyTo( TiXmlDeclaration* target ) const;
01162         
01163         #ifdef TIXML_USE_STL
01164             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01165         #endif
01166         virtual void StreamOut ( TIXML_OSTREAM * out) const;
01167 
01168 private:
01169 
01170         TIXML_STRING version;
01171         TIXML_STRING encoding;
01172         TIXML_STRING standalone;
01173 };
01174 
01175 
01176 
01177 
01178 
01179 
01180 
01181 
01182 
01183 class TiXmlUnknown : public TiXmlNode
01184 {
01185 public:
01186         TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN )        {}
01187         virtual ~TiXmlUnknown() {}
01188 
01189         TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN )              { copy.CopyTo( this ); }
01190         void operator=( const TiXmlUnknown& copy )                                                                              { copy.CopyTo( this ); }
01191 
01192 
01193         virtual TiXmlNode* Clone() const;
01194 
01195         virtual void Print( FILE* cfile, int depth ) const;
01196 
01197         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01198 
01199         virtual const TiXmlUnknown*     ToUnknown()     const { return this; } 
01200         virtual TiXmlUnknown*           ToUnknown()         { return this; } 
01201 
01202 protected:
01203         void CopyTo( TiXmlUnknown* target ) const;
01204 
01205         #ifdef TIXML_USE_STL
01206             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01207         #endif
01208         virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01209 
01210 private:
01211 
01212 };
01213 
01214 
01215 
01216 
01217 
01218 
01219 class TiXmlDocument : public TiXmlNode
01220 {
01221 public:
01222 
01223         TiXmlDocument();
01224 
01225         TiXmlDocument( const char * documentName );
01226 
01227         #ifdef TIXML_USE_STL
01228 
01229         TiXmlDocument( const std::string& documentName );
01230         #endif
01231 
01232         TiXmlDocument( const TiXmlDocument& copy );
01233         void operator=( const TiXmlDocument& copy );
01234 
01235         virtual ~TiXmlDocument() {}
01236 
01237 
01238 
01239 
01240 
01241         bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01242 
01243         bool SaveFile() const;
01244 
01245         bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01246 
01247         bool SaveFile( const char * filename ) const;
01248 
01249 
01250 
01251 
01252 
01253         bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01254 
01255         bool SaveFile( FILE* ) const;
01256 
01257         #ifdef TIXML_USE_STL
01258         bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )                   
01259         {
01260                 StringToBuffer f( filename );
01261                 return ( f.buffer && LoadFile( f.buffer, encoding ));
01262         }
01263         bool SaveFile( const std::string& filename ) const              
01264         {
01265                 StringToBuffer f( filename );
01266                 return ( f.buffer && SaveFile( f.buffer ));
01267         }
01268         #endif
01269 
01270 
01271 
01272 
01273 
01274         virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01275 
01276 
01277 
01278 
01279 
01280         const TiXmlElement* RootElement() const         { return FirstChildElement(); }
01281         TiXmlElement* RootElement()                                     { return FirstChildElement(); }
01282 
01283 
01284 
01285 
01286 
01287       
01288         bool Error() const                                              { return error; }
01289 
01290 
01291         const char * ErrorDesc() const  { return errorDesc.c_str (); }
01292 
01293 
01294 
01295 
01296         int ErrorId()   const                           { return errorId; }
01297 
01298 
01299 
01300 
01301 
01302 
01303 
01304 
01305         int ErrorRow()  { return errorLocation.row+1; }
01306         int ErrorCol()  { return errorLocation.col+1; } 
01307 
01308 
01309 
01310 
01311 
01312 
01313 
01314 
01315 
01316 
01317 
01318 
01319 
01320 
01321 
01322 
01323 
01324 
01325 
01326 
01327 
01328 
01329 
01330 
01331 
01332         void SetTabSize( int _tabsize )         { tabsize = _tabsize; }
01333 
01334         int TabSize() const     { return tabsize; }
01335 
01336 
01337 
01338 
01339         void ClearError()                                               {       error = false; 
01340                                                                                                 errorId = 0; 
01341                                                                                                 errorDesc = ""; 
01342                                                                                                 errorLocation.row = errorLocation.col = 0; 
01343                                                                                                 
01344                                                                                         }
01345 
01346 
01347         void Print() const                                              { Print( stdout, 0 ); }
01348 
01349 
01350         virtual void Print( FILE* cfile, int depth = 0 ) const;
01351         
01352         void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01353 
01354         virtual const TiXmlDocument*    ToDocument()    const { return this; } 
01355         virtual TiXmlDocument*          ToDocument()          { return this; } 
01356 
01357 protected :
01358         virtual void StreamOut ( TIXML_OSTREAM * out) const;
01359         
01360         virtual TiXmlNode* Clone() const;
01361         #ifdef TIXML_USE_STL
01362             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01363         #endif
01364 
01365 private:
01366         void CopyTo( TiXmlDocument* target ) const;
01367 
01368         bool error;
01369         int  errorId;
01370         TIXML_STRING errorDesc;
01371         int tabsize;
01372         TiXmlCursor errorLocation;
01373         bool useMicrosoftBOM;           
01374 };
01375 
01376 
01377 
01378 
01379 
01380 
01381 
01382 
01383 
01384 
01385 
01386 
01387 
01388 
01389 
01390 
01391 
01392 
01393 
01394 
01395 
01396 
01397 
01398 
01399 
01400 
01401 
01402 
01403 
01404 
01405 
01406 
01407 
01408 
01409 
01410 
01411 
01412 
01413 
01414 
01415 
01416 
01417 
01418 
01419 
01420 
01421 
01422 
01423 
01424 
01425 
01426 
01427 
01428 
01429 
01430 
01431 
01432 
01433 
01434 
01435 
01436 
01437 
01438 
01439 
01440 
01441 
01442 
01443 
01444 
01445 
01446 
01447 
01448 
01449 
01450 
01451 
01452 
01453 
01454 
01455 
01456 
01457 class TiXmlHandle
01458 {
01459 public:
01460 
01461         TiXmlHandle( TiXmlNode* _node )                                 { this->node = _node; }
01462 
01463         TiXmlHandle( const TiXmlHandle& ref )                   { this->node = ref.node; }
01464         TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01465 
01466 
01467         TiXmlHandle FirstChild() const;
01468 
01469         TiXmlHandle FirstChild( const char * value ) const;
01470 
01471         TiXmlHandle FirstChildElement() const;
01472 
01473         TiXmlHandle FirstChildElement( const char * value ) const;
01474 
01475 
01476 
01477 
01478         TiXmlHandle Child( const char* value, int index ) const;
01479 
01480 
01481 
01482         TiXmlHandle Child( int index ) const;
01483 
01484 
01485 
01486 
01487         TiXmlHandle ChildElement( const char* value, int index ) const;
01488 
01489 
01490 
01491 
01492         TiXmlHandle ChildElement( int index ) const;
01493 
01494         #ifdef TIXML_USE_STL
01495         TiXmlHandle FirstChild( const std::string& _value ) const                               { return FirstChild( _value.c_str() ); }
01496         TiXmlHandle FirstChildElement( const std::string& _value ) const                { return FirstChildElement( _value.c_str() ); }
01497 
01498         TiXmlHandle Child( const std::string& _value, int index ) const                 { return Child( _value.c_str(), index ); }
01499         TiXmlHandle ChildElement( const std::string& _value, int index ) const  { return ChildElement( _value.c_str(), index ); }
01500         #endif
01501 
01502 
01503         TiXmlNode* Node() const                 { return node; } 
01504 
01505         TiXmlElement* Element() const   { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01506 
01507         TiXmlText* Text() const                 { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01508 
01509         TiXmlUnknown* Unknown() const                   { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01510 
01511 private:
01512         TiXmlNode* node;
01513 };
01514 
01515 #ifdef _MSC_VER
01516 #pragma warning( pop )
01517 #endif
01518 
01519 #endif
01520