Main Page   Class Hierarchy   Compound List   File List   Compound Members  

tinyxml.h

00001 /*
00002 www.sourceforge.net/projects/tinyxml
00003 Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
00004 
00005 This software is provided 'as-is', without any express or implied
00006 warranty. In no event will the authors be held liable for any
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to anyone to use this software for any
00010 purpose, including commercial applications, and to alter it and
00011 redistribute it freely, subject to the following restrictions:
00012 
00013 1. The origin of this software must not be misrepresented; you must
00014 not claim that you wrote the original software. If you use this
00015 software in a product, an acknowledgment in the product documentation
00016 would be appreciated but is not required.
00017 
00018 2. Altered source versions must be plainly marked as such, and
00019 must not be misrepresented as being the original software.
00020 
00021 3. This notice may not be removed or altered from any source
00022 distribution.
00023 */
00024 
00025 
00026 #ifndef TINYXML_INCLUDED
00027 #define TINYXML_INCLUDED
00028 
00029 #ifdef _MSC_VER
00030 #pragma warning( disable : 4530 )
00031 #pragma warning( disable : 4786 )
00032 #endif
00033 
00034 #include <ctype.h>
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038 #include <assert.h>
00039 
00040 // Help out windows:
00041 #if defined( _DEBUG ) && !defined( DEBUG )
00042 #define DEBUG
00043 #endif
00044 
00045 #if defined( DEBUG ) && defined( _MSC_VER )
00046 #include <windows.h>
00047 #define TIXML_LOG OutputDebugString
00048 #else
00049 #define TIXML_LOG printf
00050 #endif
00051 
00052 #ifdef TIXML_USE_STL
00053     #include <string>
00054     #include <iostream>
00055     //#include <ostream>
00056     #define TIXML_STRING    std::string
00057     #define TIXML_ISTREAM   std::istream
00058     #define TIXML_OSTREAM   std::ostream
00059 #else
00060     #include "tinystr.h"
00061     #define TIXML_STRING    TiXmlString
00062     #define TIXML_OSTREAM   TiXmlOutStream
00063 #endif
00064 
00065 class TiXmlDocument;
00066 class TiXmlElement;
00067 class TiXmlComment;
00068 class TiXmlUnknown;
00069 class TiXmlAttribute;
00070 class TiXmlText;
00071 class TiXmlDeclaration;
00072 
00073 class TiXmlParsingData;
00074 
00075 /*  Internal structure for tracking location of items 
00076     in the XML file.
00077 */
00078 struct TiXmlCursor
00079 {
00080     TiXmlCursor()       { Clear(); }
00081     void Clear()        { row = col = -1; }
00082 
00083     int row;    // 0 based.
00084     int col;    // 0 based.
00085 };
00086 
00087 
00088 // Only used by Attribute::Query functions
00089 enum 
00090 { 
00091     TIXML_SUCCESS,
00092     TIXML_NO_ATTRIBUTE,
00093     TIXML_WRONG_TYPE
00094 };
00095 
00118 class TiXmlBase
00119 {
00120     friend class TiXmlNode;
00121     friend class TiXmlElement;
00122     friend class TiXmlDocument;
00123 
00124 public:
00125     TiXmlBase()                             {}
00126     virtual ~TiXmlBase()                    {}
00127 
00133     virtual void Print( FILE* cfile, int depth ) const = 0;
00134 
00141     static void SetCondenseWhiteSpace( bool condense )      { condenseWhiteSpace = condense; }
00142 
00144     static bool IsWhiteSpaceCondensed()                     { return condenseWhiteSpace; }
00145 
00164     int Row() const         { return location.row + 1; }
00165     int Column() const      { return location.col + 1; }    
00166 
00167 protected:
00168     // See STL_STRING_BUG
00169     // Utility class to overcome a bug.
00170     class StringToBuffer
00171     {
00172       public:
00173         StringToBuffer( const TIXML_STRING& str );
00174         ~StringToBuffer();
00175         char* buffer;
00176     };
00177 
00178     static const char*  SkipWhiteSpace( const char* );
00179     inline static bool  IsWhiteSpace( int c )       { return ( isspace( c ) || c == '\n' || c == '\r' ); }
00180 
00181     virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00182 
00183     #ifdef TIXML_USE_STL
00184         static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00185         static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00186     #endif
00187 
00188     /*  Reads an XML name into the string provided. Returns
00189         a pointer just past the last character of the name,
00190         or 0 if the function has an error.
00191     */
00192     static const char* ReadName( const char* p, TIXML_STRING* name );
00193 
00194     /*  Reads text. Returns a pointer past the given end tag.
00195         Wickedly complex options, but it keeps the (sensitive) code in one place.
00196     */
00197     static const char* ReadText(    const char* in,             // where to start
00198                                     TIXML_STRING* text,         // the string read
00199                                     bool ignoreWhiteSpace,      // whether to keep the white space
00200                                     const char* endTag,         // what ends this text
00201                                     bool ignoreCase );          // whether to ignore case in the end tag
00202 
00203     virtual const char* Parse( const char* p, TiXmlParsingData* data ) = 0;
00204 
00205     // If an entity has been found, transform it into a character.
00206     static const char* GetEntity( const char* in, char* value );
00207 
00208     // Get a character, while interpreting entities.
00209     inline static const char* GetChar( const char* p, char* _value )
00210     {
00211         assert( p );
00212         if ( *p == '&' )
00213         {
00214             return GetEntity( p, _value );
00215         }
00216         else
00217         {
00218             *_value = *p;
00219             return p+1;
00220         }
00221     }
00222 
00223     // Puts a string to a stream, expanding entities as it goes.
00224     // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
00225     static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00226 
00227     static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00228 
00229     // Return true if the next characters in the stream are any of the endTag sequences.
00230     static bool StringEqual(    const char* p,
00231                                 const char* endTag,
00232                                 bool ignoreCase );
00233 
00234 
00235     enum
00236     {
00237         TIXML_NO_ERROR = 0,
00238         TIXML_ERROR,
00239         TIXML_ERROR_OPENING_FILE,
00240         TIXML_ERROR_OUT_OF_MEMORY,
00241         TIXML_ERROR_PARSING_ELEMENT,
00242         TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00243         TIXML_ERROR_READING_ELEMENT_VALUE,
00244         TIXML_ERROR_READING_ATTRIBUTES,
00245         TIXML_ERROR_PARSING_EMPTY,
00246         TIXML_ERROR_READING_END_TAG,
00247         TIXML_ERROR_PARSING_UNKNOWN,
00248         TIXML_ERROR_PARSING_COMMENT,
00249         TIXML_ERROR_PARSING_DECLARATION,
00250         TIXML_ERROR_DOCUMENT_EMPTY,
00251 
00252         TIXML_ERROR_STRING_COUNT
00253     };
00254     static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00255 
00256     TiXmlCursor location;
00257 
00258 private:
00259     struct Entity
00260     {
00261         const char*     str;
00262         unsigned int    strLength;
00263         char            chr;
00264     };
00265     enum
00266     {
00267         NUM_ENTITY = 5,
00268         MAX_ENTITY_LENGTH = 6
00269 
00270     };
00271     static Entity entity[ NUM_ENTITY ];
00272     static bool condenseWhiteSpace;
00273 };
00274 
00275 
00282 class TiXmlNode : public TiXmlBase
00283 {
00284     friend class TiXmlDocument;
00285     friend class TiXmlElement;
00286 
00287 public:
00288     #ifdef TIXML_USE_STL    
00289 
00293         friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00294 
00311         friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00312 
00314         friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00315 
00316     #else
00317         // Used internally, not part of the public API.
00318         friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00319     #endif
00320 
00324     enum NodeType
00325     {
00326         DOCUMENT,
00327         ELEMENT,
00328         COMMENT,
00329         UNKNOWN,
00330         TEXT,
00331         DECLARATION,
00332         TYPECOUNT
00333     };
00334 
00335     virtual ~TiXmlNode();
00336 
00349     const char * Value() const { return value.c_str (); }
00350 
00360     void SetValue(const char * _value) { value = _value;}
00361 
00362     #ifdef TIXML_USE_STL
00363 
00364     void SetValue( const std::string& _value )    
00365     {     
00366         StringToBuffer buf( _value );
00367         SetValue( buf.buffer ? buf.buffer : "" );       
00368     }   
00369     #endif
00370 
00372     void Clear();
00373 
00375     TiXmlNode* Parent() const                   { return parent; }
00376 
00377     TiXmlNode* FirstChild() const   { return firstChild; }      
00378     TiXmlNode* FirstChild( const char * value ) const;          
00379 
00380     TiXmlNode* LastChild() const    { return lastChild; }       
00381     TiXmlNode* LastChild( const char * value ) const;           
00382 
00383     #ifdef TIXML_USE_STL
00384     TiXmlNode* FirstChild( const std::string& _value ) const    {   return FirstChild (_value.c_str ());    }   
00385     TiXmlNode* LastChild( const std::string& _value ) const     {   return LastChild (_value.c_str ()); }   
00386     #endif
00387 
00404     TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
00405 
00407     TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
00408 
00409     #ifdef TIXML_USE_STL
00410     TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const  {   return IterateChildren (_value.c_str (), previous); }   
00411     #endif
00412 
00416     TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00417 
00418 
00428     TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00429 
00433     TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00434 
00438     TiXmlNode* InsertAfterChild(  TiXmlNode* afterThis, const TiXmlNode& addThis );
00439 
00443     TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00444 
00446     bool RemoveChild( TiXmlNode* removeThis );
00447 
00449     TiXmlNode* PreviousSibling() const          { return prev; }
00450 
00452     TiXmlNode* PreviousSibling( const char * ) const;
00453 
00454     #ifdef TIXML_USE_STL
00455     TiXmlNode* PreviousSibling( const std::string& _value ) const   {   return PreviousSibling (_value.c_str ());   }   
00456     TiXmlNode* NextSibling( const std::string& _value) const        {   return NextSibling (_value.c_str ());   }   
00457     #endif
00458 
00460     TiXmlNode* NextSibling() const              { return next; }
00461 
00463     TiXmlNode* NextSibling( const char * ) const;
00464 
00469     TiXmlElement* NextSiblingElement() const;
00470 
00475     TiXmlElement* NextSiblingElement( const char * ) const;
00476 
00477     #ifdef TIXML_USE_STL
00478     TiXmlElement* NextSiblingElement( const std::string& _value) const  {   return NextSiblingElement (_value.c_str ());    }   
00479     #endif
00480 
00482     TiXmlElement* FirstChildElement()   const;
00483 
00485     TiXmlElement* FirstChildElement( const char * value ) const;
00486 
00487     #ifdef TIXML_USE_STL
00488     TiXmlElement* FirstChildElement( const std::string& _value ) const  {   return FirstChildElement (_value.c_str ()); }   
00489     #endif
00490 
00495     virtual int Type() const    { return type; }
00496 
00500     TiXmlDocument* GetDocument() const;
00501 
00503     bool NoChildren() const                     { return !firstChild; }
00504 
00505     TiXmlDocument* ToDocument() const       { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; } 
00506     TiXmlElement*  ToElement() const        { return ( this && type == ELEMENT  ) ? (TiXmlElement*)  this : 0; } 
00507     TiXmlComment*  ToComment() const        { return ( this && type == COMMENT  ) ? (TiXmlComment*)  this : 0; } 
00508     TiXmlUnknown*  ToUnknown() const        { return ( this && type == UNKNOWN  ) ? (TiXmlUnknown*)  this : 0; } 
00509     TiXmlText*     ToText()    const        { return ( this && type == TEXT     ) ? (TiXmlText*)     this : 0; } 
00510     TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; } 
00511 
00512     virtual TiXmlNode* Clone() const = 0;
00513 
00514     void  SetUserData( void* user )         { userData = user; }
00515     void* GetUserData()                     { return userData; }
00516 
00517 protected:
00518     TiXmlNode( NodeType type );
00519 
00520     #ifdef TIXML_USE_STL
00521         // The real work of the input operator.
00522         virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00523     #endif
00524 
00525     // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
00526     TiXmlNode* Identify( const char* start );
00527     void CopyToClone( TiXmlNode* target ) const { target->SetValue (value.c_str() );
00528                                                   target->userData = userData; }
00529 
00530     // Internal Value function returning a TIXML_STRING
00531     TIXML_STRING SValue() const { return value ; }
00532 
00533     TiXmlNode*      parent;
00534     NodeType        type;
00535 
00536     TiXmlNode*      firstChild;
00537     TiXmlNode*      lastChild;
00538 
00539     TIXML_STRING    value;
00540 
00541     TiXmlNode*      prev;
00542     TiXmlNode*      next;
00543     void*           userData;
00544 };
00545 
00546 
00554 class TiXmlAttribute : public TiXmlBase
00555 {
00556     friend class TiXmlAttributeSet;
00557 
00558 public:
00560     TiXmlAttribute()
00561     {
00562         document = 0;
00563         prev = next = 0;
00564     }
00565 
00566     #ifdef TIXML_USE_STL
00567 
00568     TiXmlAttribute( const std::string& _name, const std::string& _value )
00569     {
00570         name = _name;
00571         value = _value;
00572         document = 0;
00573         prev = next = 0;
00574     }
00575     #endif
00576 
00578     TiXmlAttribute( const char * _name, const char * _value )
00579     {
00580         name = _name;
00581         value = _value;
00582         document = 0;
00583         prev = next = 0;
00584     }
00585 
00586     const char*     Name()  const       { return name.c_str (); }       
00587     const char*     Value() const       { return value.c_str (); }      
00588     const int       IntValue() const;                                   
00589     const double    DoubleValue() const;                                
00590 
00600     int QueryIntValue( int* value ) const;
00602     int QueryDoubleValue( double* value ) const;
00603 
00604     void SetName( const char* _name )   { name = _name; }               
00605     void SetValue( const char* _value ) { value = _value; }             
00606 
00607     void SetIntValue( int value );                                      
00608     void SetDoubleValue( double value );                                
00609 
00610     #ifdef TIXML_USE_STL
00611 
00612     void SetName( const std::string& _name )    
00613     {   
00614         StringToBuffer buf( _name );
00615         SetName ( buf.buffer ? buf.buffer : "error" );  
00616     }
00618     void SetValue( const std::string& _value )  
00619     {   
00620         StringToBuffer buf( _value );
00621         SetValue( buf.buffer ? buf.buffer : "error" );  
00622     }
00623     #endif
00624 
00626     TiXmlAttribute* Next() const;
00628     TiXmlAttribute* Previous() const;
00629 
00630     bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00631     bool operator<( const TiXmlAttribute& rhs )  const { return name < rhs.name; }
00632     bool operator>( const TiXmlAttribute& rhs )  const { return name > rhs.name; }
00633 
00634     /*  [internal use]
00635         Attribtue parsing starts: first letter of the name
00636                          returns: the next char after the value end quote
00637     */
00638     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00639 
00640     // [internal use]
00641     virtual void Print( FILE* cfile, int depth ) const;
00642 
00643     virtual void StreamOut( TIXML_OSTREAM * out ) const;
00644     // [internal use]
00645     // Set the document pointer so the attribute can report errors.
00646     void SetDocument( TiXmlDocument* doc )  { document = doc; }
00647 
00648 private:
00649     TiXmlDocument*  document;   // A pointer back to a document, for error reporting.
00650     TIXML_STRING name;
00651     TIXML_STRING value;
00652     TiXmlAttribute* prev;
00653     TiXmlAttribute* next;
00654 };
00655 
00656 
00657 /*  A class used to manage a group of attributes.
00658     It is only used internally, both by the ELEMENT and the DECLARATION.
00659     
00660     The set can be changed transparent to the Element and Declaration
00661     classes that use it, but NOT transparent to the Attribute
00662     which has to implement a next() and previous() method. Which makes
00663     it a bit problematic and prevents the use of STL.
00664 
00665     This version is implemented with circular lists because:
00666         - I like circular lists
00667         - it demonstrates some independence from the (typical) doubly linked list.
00668 */
00669 class TiXmlAttributeSet
00670 {
00671 public:
00672     TiXmlAttributeSet();
00673     ~TiXmlAttributeSet();
00674 
00675     void Add( TiXmlAttribute* attribute );
00676     void Remove( TiXmlAttribute* attribute );
00677 
00678     TiXmlAttribute* First() const   { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00679     TiXmlAttribute* Last()  const   { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00680     TiXmlAttribute* Find( const char * name ) const;
00681 
00682 private:
00683     TiXmlAttribute sentinel;
00684 };
00685 
00686 
00691 class TiXmlElement : public TiXmlNode
00692 {
00693 public:
00695     TiXmlElement (const char * in_value);
00696 
00697     #ifdef TIXML_USE_STL
00698 
00699     TiXmlElement( const std::string& _value ) :     TiXmlNode( TiXmlNode::ELEMENT )
00700     {
00701         firstChild = lastChild = 0;
00702         value = _value;
00703     }
00704     #endif
00705 
00706     virtual ~TiXmlElement();
00707 
00711     const char* Attribute( const char* name ) const;
00712 
00719     const char* Attribute( const char* name, int* i ) const;
00720 
00727     const char* Attribute( const char* name, double* d ) const;
00728 
00736     int QueryIntAttribute( const char* name, int* value ) const;
00738     int QueryDoubleAttribute( const char* name, double* value ) const;
00739 
00743     void SetAttribute( const char* name, const char * value );
00744 
00745     #ifdef TIXML_USE_STL
00746     const char* Attribute( const std::string& name ) const              { return Attribute( name.c_str() ); }
00747     const char* Attribute( const std::string& name, int* i ) const      { return Attribute( name.c_str(), i ); }
00748 
00750     void SetAttribute( const std::string& name, const std::string& _value ) 
00751     {   
00752         StringToBuffer n( name );
00753         StringToBuffer v( _value );
00754         if ( n.buffer && v.buffer )
00755             SetAttribute (n.buffer, v.buffer ); 
00756     }   
00758     void SetAttribute( const std::string& name, int _value )    
00759     {   
00760         StringToBuffer n( name );
00761         if ( n.buffer )
00762             SetAttribute (n.buffer, _value);    
00763     }   
00764     #endif
00765 
00769     void SetAttribute( const char * name, int value );
00770 
00773     void RemoveAttribute( const char * name );
00774     #ifdef TIXML_USE_STL
00775     void RemoveAttribute( const std::string& name ) {   RemoveAttribute (name.c_str ());    }   
00776     #endif
00777 
00778     TiXmlAttribute* FirstAttribute() const  { return attributeSet.First(); }        
00779     TiXmlAttribute* LastAttribute() const   { return attributeSet.Last(); }     
00780 
00781     // [internal use] Creates a new Element and returs it.
00782     virtual TiXmlNode* Clone() const;
00783     // [internal use]
00784 
00785     virtual void Print( FILE* cfile, int depth ) const;
00786 
00787 protected:
00788 
00789     // Used to be public [internal use]
00790     #ifdef TIXML_USE_STL
00791         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00792     #endif
00793     virtual void StreamOut( TIXML_OSTREAM * out ) const;
00794 
00795     /*  [internal use]
00796         Attribtue parsing starts: next char past '<'
00797                          returns: next char past '>'
00798     */
00799     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00800 
00801     /*  [internal use]
00802         Reads the "value" of the element -- another element, or text.
00803         This should terminate with the current end tag.
00804     */
00805     const char* ReadValue( const char* in, TiXmlParsingData* prevData );
00806 
00807 private:
00808     TiXmlAttributeSet attributeSet;
00809 };
00810 
00811 
00814 class TiXmlComment : public TiXmlNode
00815 {
00816 public:
00818     TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
00819     virtual ~TiXmlComment() {}
00820 
00821     // [internal use] Creates a new Element and returs it.
00822     virtual TiXmlNode* Clone() const;
00823     // [internal use]
00824     virtual void Print( FILE* cfile, int depth ) const;
00825 protected:
00826     // used to be public
00827     #ifdef TIXML_USE_STL
00828         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00829     #endif
00830     virtual void StreamOut( TIXML_OSTREAM * out ) const;
00831     /*  [internal use]
00832         Attribtue parsing starts: at the ! of the !--
00833                          returns: next char past '>'
00834     */
00835     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00836 };
00837 
00838 
00841 class TiXmlText : public TiXmlNode
00842 {
00843     friend class TiXmlElement;
00844 public:
00846     TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
00847     {
00848         SetValue( initValue );
00849     }
00850     virtual ~TiXmlText() {}
00851 
00852     #ifdef TIXML_USE_STL
00853 
00854     TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
00855     {
00856         SetValue( initValue );
00857     }
00858     #endif
00859 
00860     // [internal use]
00861     virtual void Print( FILE* cfile, int depth ) const;
00862 
00863 protected :
00864     // [internal use] Creates a new Element and returns it.
00865     virtual TiXmlNode* Clone() const;
00866     virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00867     // [internal use]
00868     bool Blank() const; // returns true if all white space and new lines
00869     /*  [internal use]
00870             Attribtue parsing starts: First char of the text
00871                              returns: next char past '>'
00872     */
00873     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00874     // [internal use]
00875     #ifdef TIXML_USE_STL
00876         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00877     #endif
00878 };
00879 
00880 
00894 class TiXmlDeclaration : public TiXmlNode
00895 {
00896 public:
00898     TiXmlDeclaration()   : TiXmlNode( TiXmlNode::DECLARATION ) {}
00899 
00900 #ifdef TIXML_USE_STL
00901 
00902     TiXmlDeclaration(   const std::string& _version,
00903                         const std::string& _encoding,
00904                         const std::string& _standalone )
00905             : TiXmlNode( TiXmlNode::DECLARATION )
00906     {
00907         version = _version;
00908         encoding = _encoding;
00909         standalone = _standalone;
00910     }
00911 #endif
00912 
00914     TiXmlDeclaration(   const char* _version,
00915                         const char* _encoding,
00916                         const char* _standalone );
00917 
00918     virtual ~TiXmlDeclaration() {}
00919 
00921     const char * Version() const        { return version.c_str (); }
00923     const char * Encoding() const       { return encoding.c_str (); }
00925     const char * Standalone() const     { return standalone.c_str (); }
00926 
00927     // [internal use] Creates a new Element and returs it.
00928     virtual TiXmlNode* Clone() const;
00929     // [internal use]
00930     virtual void Print( FILE* cfile, int depth ) const;
00931 
00932 protected:
00933     // used to be public
00934     #ifdef TIXML_USE_STL
00935         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00936     #endif
00937     virtual void StreamOut ( TIXML_OSTREAM * out) const;
00938     //  [internal use]
00939     //  Attribtue parsing starts: next char past '<'
00940     //                   returns: next char past '>'
00941 
00942     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00943 
00944 private:
00945     TIXML_STRING version;
00946     TIXML_STRING encoding;
00947     TIXML_STRING standalone;
00948 };
00949 
00950 
00956 class TiXmlUnknown : public TiXmlNode
00957 {
00958 public:
00959     TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
00960     virtual ~TiXmlUnknown() {}
00961 
00962     // [internal use]
00963     virtual TiXmlNode* Clone() const;
00964     // [internal use]
00965     virtual void Print( FILE* cfile, int depth ) const;
00966 protected:
00967     #ifdef TIXML_USE_STL
00968         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00969     #endif
00970     virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00971     /*  [internal use]
00972         Attribute parsing starts: First char of the text
00973                          returns: next char past '>'
00974     */
00975     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00976 };
00977 
00978 
00983 class TiXmlDocument : public TiXmlNode
00984 {
00985 public:
00987     TiXmlDocument();
00989     TiXmlDocument( const char * documentName );
00990 
00991     #ifdef TIXML_USE_STL
00992 
00993     TiXmlDocument( const std::string& documentName ) :
00994         TiXmlNode( TiXmlNode::DOCUMENT )
00995     {
00996         value = documentName;
00997         error = false;
00998     }
00999     #endif
01000 
01001     virtual ~TiXmlDocument() {}
01002 
01007     bool LoadFile();
01009     bool SaveFile() const;
01011     bool LoadFile( const char * filename );
01013     bool SaveFile( const char * filename ) const;
01014 
01015     #ifdef TIXML_USE_STL
01016     bool LoadFile( const std::string& filename )            
01017     {
01018         StringToBuffer f( filename );
01019         return ( f.buffer && LoadFile( f.buffer ));
01020     }
01021     bool SaveFile( const std::string& filename ) const      
01022     {
01023         StringToBuffer f( filename );
01024         return ( f.buffer && SaveFile( f.buffer ));
01025     }
01026     #endif
01027 
01030     virtual const char* Parse( const char* p, TiXmlParsingData* data = 0 );
01031 
01036     TiXmlElement* RootElement() const       { return FirstChildElement(); }
01037 
01043     bool Error() const                      { return error; }
01044 
01046     const char * ErrorDesc() const  { return errorDesc.c_str (); }
01047 
01051     const int ErrorId() const               { return errorId; }
01052 
01060     int ErrorRow()  { return errorLocation.row+1; }
01061     int ErrorCol()  { return errorLocation.col+1; } 
01062 
01083     void SetTabSize( int _tabsize )     { tabsize = _tabsize; }
01084 
01085     int TabSize() const { return tabsize; }
01086 
01090     void ClearError()                       {   error = false; 
01091                                                 errorId = 0; 
01092                                                 errorDesc = ""; 
01093                                                 errorLocation.row = errorLocation.col = 0; 
01094                                                 //errorLocation.last = 0; 
01095                                             }
01096 
01098     void Print() const                      { Print( stdout, 0 ); }
01099 
01100     // [internal use]
01101     virtual void Print( FILE* cfile, int depth = 0 ) const;
01102     // [internal use]
01103     void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData );
01104 
01105 protected :
01106     virtual void StreamOut ( TIXML_OSTREAM * out) const;
01107     // [internal use]
01108     virtual TiXmlNode* Clone() const;
01109     #ifdef TIXML_USE_STL
01110         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01111     #endif
01112 
01113 private:
01114     bool error;
01115     int  errorId;
01116     TIXML_STRING errorDesc;
01117     int tabsize;
01118     TiXmlCursor errorLocation;
01119 };
01120 
01121 
01202 class TiXmlHandle
01203 {
01204 public:
01206     TiXmlHandle( TiXmlNode* node )          { this->node = node; }
01208     TiXmlHandle( const TiXmlHandle& ref )   { this->node = ref.node; }
01209 
01211     TiXmlHandle FirstChild() const;
01213     TiXmlHandle FirstChild( const char * value ) const;
01215     TiXmlHandle FirstChildElement() const;
01217     TiXmlHandle FirstChildElement( const char * value ) const;
01218 
01222     TiXmlHandle Child( const char* value, int index ) const;
01226     TiXmlHandle Child( int index ) const;
01231     TiXmlHandle ChildElement( const char* value, int index ) const;
01236     TiXmlHandle ChildElement( int index ) const;
01237 
01238     #ifdef TIXML_USE_STL
01239     TiXmlHandle FirstChild( const std::string& _value ) const           { return FirstChild( _value.c_str() ); }
01240     TiXmlHandle FirstChildElement( const std::string& _value ) const        { return FirstChildElement( _value.c_str() ); }
01241 
01242     TiXmlHandle Child( const std::string& _value, int index ) const         { return Child( _value.c_str(), index ); }
01243     TiXmlHandle ChildElement( const std::string& _value, int index ) const  { return ChildElement( _value.c_str(), index ); }
01244     #endif
01245 
01247     TiXmlNode* Node() const         { return node; } 
01249     TiXmlElement* Element() const   { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01251     TiXmlText* Text() const         { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01252 
01253 private:
01254     TiXmlNode* node;
01255 };
01256 
01257 
01258 #endif
01259 

Generated on Fri Dec 19 18:28:21 2003 for TinyXml by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001