- Cal3D 0.9 API Reference -

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 #include "cal3d/platform.h"
00041 
00042 // Help out windows:
00043 #if defined( _DEBUG ) && !defined( DEBUG )
00044 #define DEBUG
00045 #endif
00046 
00047 #if defined( DEBUG ) && defined( _MSC_VER )
00048 #include <windows.h>
00049 #define TIXML_LOG OutputDebugString
00050 #else
00051 #define TIXML_LOG printf
00052 #endif
00053 
00054 #define TIXML_USE_STL
00055 
00056 #ifdef TIXML_USE_STL
00057     #include <string>
00058     #include <iostream>
00059     //#include <ostream>
00060     #define TIXML_STRING    std::string
00061     #define TIXML_ISTREAM   std::istream
00062     #define TIXML_OSTREAM   std::ostream
00063 #else
00064     #include "tinystr.h"
00065     #define TIXML_STRING    TiXmlString
00066     #define TIXML_OSTREAM   TiXmlOutStream
00067 #endif
00068 
00069 class TiXmlDocument;
00070 class TiXmlElement;
00071 class TiXmlComment;
00072 class TiXmlUnknown;
00073 class TiXmlAttribute;
00074 class TiXmlText;
00075 class TiXmlDeclaration;
00076 
00077 class TiXmlParsingData;
00078 
00079 /*  Internal structure for tracking location of items 
00080     in the XML file.
00081 */
00082 struct CAL3D_API TiXmlCursor
00083 {
00084     TiXmlCursor()       { Clear(); }
00085     void Clear()        { row = col = -1; }
00086 
00087     int row;    // 0 based.
00088     int col;    // 0 based.
00089 };
00090 
00091 
00092 // Only used by Attribute::Query functions
00093 enum 
00094 { 
00095     TIXML_SUCCESS,
00096     TIXML_NO_ATTRIBUTE,
00097     TIXML_WRONG_TYPE
00098 };
00099 
00122 class CAL3D_API TiXmlBase
00123 {
00124     friend class TiXmlNode;
00125     friend class TiXmlElement;
00126     friend class TiXmlDocument;
00127 
00128 public:
00129     TiXmlBase()                             {}
00130     virtual ~TiXmlBase()                    {}
00131 
00137     virtual void Print( FILE* cfile, int depth ) const = 0;
00138 
00145     static void SetCondenseWhiteSpace( bool condense )      { condenseWhiteSpace = condense; }
00146 
00148     static bool IsWhiteSpaceCondensed()                     { return condenseWhiteSpace; }
00149 
00168     int Row() const         { return location.row + 1; }
00169     int Column() const      { return location.col + 1; }    
00170 
00171 protected:
00172     // See STL_STRING_BUG
00173     // Utility class to overcome a bug.
00174     class StringToBuffer
00175     {
00176       public:
00177         StringToBuffer( const TIXML_STRING& str );
00178         ~StringToBuffer();
00179         char* buffer;
00180     };
00181 
00182     static const char*  SkipWhiteSpace( const char* );
00183     inline static bool  IsWhiteSpace( int c )       { return ( isspace( c ) || c == '\n' || c == '\r' ); }
00184 
00185     virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00186 
00187     #ifdef TIXML_USE_STL
00188         static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00189         static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00190     #endif
00191 
00192     /*  Reads an XML name into the string provided. Returns
00193         a pointer just past the last character of the name,
00194         or 0 if the function has an error.
00195     */
00196     static const char* ReadName( const char* p, TIXML_STRING* name );
00197 
00198     /*  Reads text. Returns a pointer past the given end tag.
00199         Wickedly complex options, but it keeps the (sensitive) code in one place.
00200     */
00201     static const char* ReadText(    const char* in,             // where to start
00202                                     TIXML_STRING* text,         // the string read
00203                                     bool ignoreWhiteSpace,      // whether to keep the white space
00204                                     const char* endTag,         // what ends this text
00205                                     bool ignoreCase );          // whether to ignore case in the end tag
00206 
00207     virtual const char* Parse( const char* p, TiXmlParsingData* data ) = 0;
00208 
00209     // If an entity has been found, transform it into a character.
00210     static const char* GetEntity( const char* in, char* value );
00211 
00212     // Get a character, while interpreting entities.
00213     inline static const char* GetChar( const char* p, char* _value )
00214     {
00215         assert( p );
00216         if ( *p == '&' )
00217         {
00218             return GetEntity( p, _value );
00219         }
00220         else
00221         {
00222             *_value = *p;
00223             return p+1;
00224         }
00225     }
00226 
00227     // Puts a string to a stream, expanding entities as it goes.
00228     // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
00229     static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00230 
00231     static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00232 
00233     // Return true if the next characters in the stream are any of the endTag sequences.
00234     static bool StringEqual(    const char* p,
00235                                 const char* endTag,
00236                                 bool ignoreCase );
00237 
00238 
00239     enum
00240     {
00241         TIXML_NO_ERROR = 0,
00242         TIXML_ERROR,
00243         TIXML_ERROR_OPENING_FILE,
00244         TIXML_ERROR_OUT_OF_MEMORY,
00245         TIXML_ERROR_PARSING_ELEMENT,
00246         TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00247         TIXML_ERROR_READING_ELEMENT_VALUE,
00248         TIXML_ERROR_READING_ATTRIBUTES,
00249         TIXML_ERROR_PARSING_EMPTY,
00250         TIXML_ERROR_READING_END_TAG,
00251         TIXML_ERROR_PARSING_UNKNOWN,
00252         TIXML_ERROR_PARSING_COMMENT,
00253         TIXML_ERROR_PARSING_DECLARATION,
00254         TIXML_ERROR_DOCUMENT_EMPTY,
00255 
00256         TIXML_ERROR_STRING_COUNT
00257     };
00258     static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00259 
00260     TiXmlCursor location;
00261 
00262 private:
00263     struct Entity
00264     {
00265         const char*     str;
00266         unsigned int    strLength;
00267         char            chr;
00268     };
00269     enum
00270     {
00271         NUM_ENTITY = 5,
00272         MAX_ENTITY_LENGTH = 6
00273 
00274     };
00275     static Entity entity[ NUM_ENTITY ];
00276     static bool condenseWhiteSpace;
00277 };
00278 
00279 
00286 class CAL3D_API TiXmlNode : public TiXmlBase
00287 {
00288     friend class TiXmlDocument;
00289     friend class TiXmlElement;
00290 
00291 public:
00292     #ifdef TIXML_USE_STL    
00293 
00297         friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00298 
00315         friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00316 
00318         friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00319 
00320     #else
00321         // Used internally, not part of the public API.
00322         friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00323     #endif
00324 
00328     enum NodeType
00329     {
00330         DOCUMENT,
00331         ELEMENT,
00332         COMMENT,
00333         UNKNOWN,
00334         TEXT,
00335         DECLARATION,
00336         TYPECOUNT
00337     };
00338 
00339     virtual ~TiXmlNode();
00340 
00353     const char * Value() const { return value.c_str (); }
00354 
00364     void SetValue(const char * _value) { value = _value;}
00365 
00366     #ifdef TIXML_USE_STL
00367 
00368     void SetValue( const std::string& _value )    
00369     {     
00370         StringToBuffer buf( _value );
00371         SetValue( buf.buffer ? buf.buffer : "" );       
00372     }   
00373     #endif
00374 
00376     void Clear();
00377 
00379     TiXmlNode* Parent() const                   { return parent; }
00380 
00381     TiXmlNode* FirstChild() const   { return firstChild; }      
00382     TiXmlNode* FirstChild( const char * value ) const;          
00383 
00384     TiXmlNode* LastChild() const    { return lastChild; }       
00385     TiXmlNode* LastChild( const char * value ) const;           
00386 
00387     #ifdef TIXML_USE_STL
00388     TiXmlNode* FirstChild( const std::string& _value ) const    {   return FirstChild (_value.c_str ());    }   
00389     TiXmlNode* LastChild( const std::string& _value ) const     {   return LastChild (_value.c_str ()); }   
00390     #endif
00391 
00408     TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
00409 
00411     TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
00412 
00413     #ifdef TIXML_USE_STL
00414     TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const  {   return IterateChildren (_value.c_str (), previous); }   
00415     #endif
00416 
00420     TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00421 
00422 
00432     TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00433 
00437     TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00438 
00442     TiXmlNode* InsertAfterChild(  TiXmlNode* afterThis, const TiXmlNode& addThis );
00443 
00447     TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00448 
00450     bool RemoveChild( TiXmlNode* removeThis );
00451 
00453     TiXmlNode* PreviousSibling() const          { return prev; }
00454 
00456     TiXmlNode* PreviousSibling( const char * ) const;
00457 
00458     #ifdef TIXML_USE_STL
00459     TiXmlNode* PreviousSibling( const std::string& _value ) const   {   return PreviousSibling (_value.c_str ());   }   
00460     TiXmlNode* NextSibling( const std::string& _value) const        {   return NextSibling (_value.c_str ());   }   
00461     #endif
00462 
00464     TiXmlNode* NextSibling() const              { return next; }
00465 
00467     TiXmlNode* NextSibling( const char * ) const;
00468 
00473     TiXmlElement* NextSiblingElement() const;
00474 
00479     TiXmlElement* NextSiblingElement( const char * ) const;
00480 
00481     #ifdef TIXML_USE_STL
00482     TiXmlElement* NextSiblingElement( const std::string& _value) const  {   return NextSiblingElement (_value.c_str ());    }   
00483     #endif
00484 
00486     TiXmlElement* FirstChildElement()   const;
00487 
00489     TiXmlElement* FirstChildElement( const char * value ) const;
00490 
00491     #ifdef TIXML_USE_STL
00492     TiXmlElement* FirstChildElement( const std::string& _value ) const  {   return FirstChildElement (_value.c_str ()); }   
00493     #endif
00494 
00499     virtual int Type() const    { return type; }
00500 
00504     TiXmlDocument* GetDocument() const;
00505 
00507     bool NoChildren() const                     { return !firstChild; }
00508 
00509     TiXmlDocument* ToDocument() const       { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; } 
00510     TiXmlElement*  ToElement() const        { return ( this && type == ELEMENT  ) ? (TiXmlElement*)  this : 0; } 
00511     TiXmlComment*  ToComment() const        { return ( this && type == COMMENT  ) ? (TiXmlComment*)  this : 0; } 
00512     TiXmlUnknown*  ToUnknown() const        { return ( this && type == UNKNOWN  ) ? (TiXmlUnknown*)  this : 0; } 
00513     TiXmlText*     ToText()    const        { return ( this && type == TEXT     ) ? (TiXmlText*)     this : 0; } 
00514     TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; } 
00515 
00516     virtual TiXmlNode* Clone() const = 0;
00517 
00518     void  SetUserData( void* user )         { userData = user; }
00519     void* GetUserData()                     { return userData; }
00520 
00521 protected:
00522     TiXmlNode( NodeType type );
00523 
00524     #ifdef TIXML_USE_STL
00525         // The real work of the input operator.
00526         virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00527     #endif
00528 
00529     // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
00530     TiXmlNode* Identify( const char* start );
00531     void CopyToClone( TiXmlNode* target ) const { target->SetValue (value.c_str() );
00532                                                   target->userData = userData; }
00533 
00534     // Internal Value function returning a TIXML_STRING
00535     TIXML_STRING SValue() const { return value ; }
00536 
00537     TiXmlNode*      parent;
00538     NodeType        type;
00539 
00540     TiXmlNode*      firstChild;
00541     TiXmlNode*      lastChild;
00542 
00543     TIXML_STRING    value;
00544 
00545     TiXmlNode*      prev;
00546     TiXmlNode*      next;
00547     void*           userData;
00548 };
00549 
00550 
00558 class CAL3D_API TiXmlAttribute : public TiXmlBase
00559 {
00560     friend class TiXmlAttributeSet;
00561 
00562 public:
00564     TiXmlAttribute()
00565     {
00566         document = 0;
00567         prev = next = 0;
00568     }
00569 
00570     #ifdef TIXML_USE_STL
00571 
00572     TiXmlAttribute( const std::string& _name, const std::string& _value )
00573     {
00574         name = _name;
00575         value = _value;
00576         document = 0;
00577         prev = next = 0;
00578     }
00579     #endif
00580 
00582     TiXmlAttribute( const char * _name, const char * _value )
00583     {
00584         name = _name;
00585         value = _value;
00586         document = 0;
00587         prev = next = 0;
00588     }
00589 
00590     const char*     Name()  const       { return name.c_str (); }       
00591     const char*     Value() const       { return value.c_str (); }      
00592     const int       IntValue() const;                                   
00593     const double    DoubleValue() const;                                
00594 
00604     int QueryIntValue( int* value ) const;
00606     int QueryDoubleValue( double* value ) const;
00607 
00608     void SetName( const char* _name )   { name = _name; }               
00609     void SetValue( const char* _value ) { value = _value; }             
00610 
00611     void SetIntValue( int value );                                      
00612     void SetDoubleValue( double value );                                
00613 
00614     #ifdef TIXML_USE_STL
00615 
00616     void SetName( const std::string& _name )    
00617     {   
00618         StringToBuffer buf( _name );
00619         SetName ( buf.buffer ? buf.buffer : "error" );  
00620     }
00622     void SetValue( const std::string& _value )  
00623     {   
00624         StringToBuffer buf( _value );
00625         SetValue( buf.buffer ? buf.buffer : "error" );  
00626     }
00627     #endif
00628 
00630     TiXmlAttribute* Next() const;
00632     TiXmlAttribute* Previous() const;
00633 
00634     bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00635     bool operator<( const TiXmlAttribute& rhs )  const { return name < rhs.name; }
00636     bool operator>( const TiXmlAttribute& rhs )  const { return name > rhs.name; }
00637 
00638     /*  [internal use]
00639         Attribtue parsing starts: first letter of the name
00640                          returns: the next char after the value end quote
00641     */
00642     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00643 
00644     // [internal use]
00645     virtual void Print( FILE* cfile, int depth ) const;
00646 
00647     virtual void StreamOut( TIXML_OSTREAM * out ) const;
00648     // [internal use]
00649     // Set the document pointer so the attribute can report errors.
00650     void SetDocument( TiXmlDocument* doc )  { document = doc; }
00651 
00652 private:
00653     TiXmlDocument*  document;   // A pointer back to a document, for error reporting.
00654     TIXML_STRING name;
00655     TIXML_STRING value;
00656     TiXmlAttribute* prev;
00657     TiXmlAttribute* next;
00658 };
00659 
00660 
00661 /*  A class used to manage a group of attributes.
00662     It is only used internally, both by the ELEMENT and the DECLARATION.
00663     
00664     The set can be changed transparent to the Element and Declaration
00665     classes that use it, but NOT transparent to the Attribute
00666     which has to implement a next() and previous() method. Which makes
00667     it a bit problematic and prevents the use of STL.
00668 
00669     This version is implemented with circular lists because:
00670         - I like circular lists
00671         - it demonstrates some independence from the (typical) doubly linked list.
00672 */
00673 class CAL3D_API TiXmlAttributeSet
00674 {
00675 public:
00676     TiXmlAttributeSet();
00677     ~TiXmlAttributeSet();
00678 
00679     void Add( TiXmlAttribute* attribute );
00680     void Remove( TiXmlAttribute* attribute );
00681 
00682     TiXmlAttribute* First() const   { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00683     TiXmlAttribute* Last()  const   { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00684     TiXmlAttribute* Find( const char * name ) const;
00685 
00686 private:
00687     TiXmlAttribute sentinel;
00688 };
00689 
00690 
00695 class CAL3D_API TiXmlElement : public TiXmlNode
00696 {
00697 public:
00699     TiXmlElement (const char * in_value);
00700 
00701     #ifdef TIXML_USE_STL
00702 
00703     TiXmlElement( const std::string& _value ) :     TiXmlNode( TiXmlNode::ELEMENT )
00704     {
00705         firstChild = lastChild = 0;
00706         value = _value;
00707     }
00708     #endif
00709 
00710     virtual ~TiXmlElement();
00711 
00715     const char* Attribute( const char* name ) const;
00716 
00723     const char* Attribute( const char* name, int* i ) const;
00724 
00731     const char* Attribute( const char* name, double* d ) const;
00732 
00740     int QueryIntAttribute( const char* name, int* value ) const;
00742     int QueryDoubleAttribute( const char* name, double* value ) const;
00743 
00747     void SetAttribute( const char* name, const char * value );
00748 
00749     #ifdef TIXML_USE_STL
00750     const char* Attribute( const std::string& name ) const              { return Attribute( name.c_str() ); }
00751     const char* Attribute( const std::string& name, int* i ) const      { return Attribute( name.c_str(), i ); }
00752 
00754     void SetAttribute( const std::string& name, const std::string& _value ) 
00755     {   
00756         StringToBuffer n( name );
00757         StringToBuffer v( _value );
00758         if ( n.buffer && v.buffer )
00759             SetAttribute (n.buffer, v.buffer ); 
00760     }   
00762     void SetAttribute( const std::string& name, int _value )    
00763     {   
00764         StringToBuffer n( name );
00765         if ( n.buffer )
00766             SetAttribute (n.buffer, _value);    
00767     }   
00768     #endif
00769 
00773     void SetAttribute( const char * name, int value );
00774 
00777     void RemoveAttribute( const char * name );
00778     #ifdef TIXML_USE_STL
00779     void RemoveAttribute( const std::string& name ) {   RemoveAttribute (name.c_str ());    }   
00780     #endif
00781 
00782     TiXmlAttribute* FirstAttribute() const  { return attributeSet.First(); }        
00783     TiXmlAttribute* LastAttribute() const   { return attributeSet.Last(); }     
00784 
00785     // [internal use] Creates a new Element and returs it.
00786     virtual TiXmlNode* Clone() const;
00787     // [internal use]
00788 
00789     virtual void Print( FILE* cfile, int depth ) const;
00790 
00791 protected:
00792 
00793     // Used to be public [internal use]
00794     #ifdef TIXML_USE_STL
00795         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00796     #endif
00797     virtual void StreamOut( TIXML_OSTREAM * out ) const;
00798 
00799     /*  [internal use]
00800         Attribtue parsing starts: next char past '<'
00801                          returns: next char past '>'
00802     */
00803     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00804 
00805     /*  [internal use]
00806         Reads the "value" of the element -- another element, or text.
00807         This should terminate with the current end tag.
00808     */
00809     const char* ReadValue( const char* in, TiXmlParsingData* prevData );
00810 
00811 private:
00812     TiXmlAttributeSet attributeSet;
00813 };
00814 
00815 
00818 class CAL3D_API TiXmlComment : public TiXmlNode
00819 {
00820 public:
00822     TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
00823     virtual ~TiXmlComment() {}
00824 
00825     // [internal use] Creates a new Element and returs it.
00826     virtual TiXmlNode* Clone() const;
00827     // [internal use]
00828     virtual void Print( FILE* cfile, int depth ) const;
00829 protected:
00830     // used to be public
00831     #ifdef TIXML_USE_STL
00832         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00833     #endif
00834     virtual void StreamOut( TIXML_OSTREAM * out ) const;
00835     /*  [internal use]
00836         Attribtue parsing starts: at the ! of the !--
00837                          returns: next char past '>'
00838     */
00839     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00840 };
00841 
00842 
00845 class CAL3D_API TiXmlText : public TiXmlNode
00846 {
00847     friend class TiXmlElement;
00848 public:
00850     TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
00851     {
00852         SetValue( initValue );
00853     }
00854     virtual ~TiXmlText() {}
00855 
00856     #ifdef TIXML_USE_STL
00857 
00858     TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
00859     {
00860         SetValue( initValue );
00861     }
00862     #endif
00863 
00864     // [internal use]
00865     virtual void Print( FILE* cfile, int depth ) const;
00866 
00867 protected :
00868     // [internal use] Creates a new Element and returns it.
00869     virtual TiXmlNode* Clone() const;
00870     virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00871     // [internal use]
00872     bool Blank() const; // returns true if all white space and new lines
00873     /*  [internal use]
00874             Attribtue parsing starts: First char of the text
00875                              returns: next char past '>'
00876     */
00877     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00878     // [internal use]
00879     #ifdef TIXML_USE_STL
00880         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00881     #endif
00882 };
00883 
00884 
00898 class CAL3D_API TiXmlDeclaration : public TiXmlNode
00899 {
00900 public:
00902     TiXmlDeclaration()   : TiXmlNode( TiXmlNode::DECLARATION ) {}
00903 
00904 #ifdef TIXML_USE_STL
00905 
00906     TiXmlDeclaration(   const std::string& _version,
00907                         const std::string& _encoding,
00908                         const std::string& _standalone )
00909             : TiXmlNode( TiXmlNode::DECLARATION )
00910     {
00911         version = _version;
00912         encoding = _encoding;
00913         standalone = _standalone;
00914     }
00915 #endif
00916 
00918     TiXmlDeclaration(   const char* _version,
00919                         const char* _encoding,
00920                         const char* _standalone );
00921 
00922     virtual ~TiXmlDeclaration() {}
00923 
00925     const char * Version() const        { return version.c_str (); }
00927     const char * Encoding() const       { return encoding.c_str (); }
00929     const char * Standalone() const     { return standalone.c_str (); }
00930 
00931     // [internal use] Creates a new Element and returs it.
00932     virtual TiXmlNode* Clone() const;
00933     // [internal use]
00934     virtual void Print( FILE* cfile, int depth ) const;
00935 
00936 protected:
00937     // used to be public
00938     #ifdef TIXML_USE_STL
00939         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00940     #endif
00941     virtual void StreamOut ( TIXML_OSTREAM * out) const;
00942     //  [internal use]
00943     //  Attribtue parsing starts: next char past '<'
00944     //                   returns: next char past '>'
00945 
00946     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00947 
00948 private:
00949     TIXML_STRING version;
00950     TIXML_STRING encoding;
00951     TIXML_STRING standalone;
00952 };
00953 
00954 
00960 class CAL3D_API TiXmlUnknown : public TiXmlNode
00961 {
00962 public:
00963     TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
00964     virtual ~TiXmlUnknown() {}
00965 
00966     // [internal use]
00967     virtual TiXmlNode* Clone() const;
00968     // [internal use]
00969     virtual void Print( FILE* cfile, int depth ) const;
00970 protected:
00971     #ifdef TIXML_USE_STL
00972         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00973     #endif
00974     virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00975     /*  [internal use]
00976         Attribute parsing starts: First char of the text
00977                          returns: next char past '>'
00978     */
00979     virtual const char* Parse( const char* p, TiXmlParsingData* data );
00980 };
00981 
00982 
00987 class CAL3D_API TiXmlDocument : public TiXmlNode
00988 {
00989 public:
00991     TiXmlDocument();
00993     TiXmlDocument( const char * documentName );
00994 
00995     #ifdef TIXML_USE_STL
00996 
00997     TiXmlDocument( const std::string& documentName ) :
00998         TiXmlNode( TiXmlNode::DOCUMENT )
00999     {
01000         tabsize = 4;
01001         value = documentName;
01002         error = false;
01003     }
01004     #endif
01005 
01006     virtual ~TiXmlDocument() {}
01007 
01012     bool LoadFile();
01014     bool SaveFile() const;
01016     bool LoadFile( const char * filename );
01018     bool SaveFile( const char * filename ) const;
01019 
01020     #ifdef TIXML_USE_STL
01021     bool LoadFile( const std::string& filename )            
01022     {
01023         StringToBuffer f( filename );
01024         return ( f.buffer && LoadFile( f.buffer ));
01025     }
01026     bool SaveFile( const std::string& filename ) const      
01027     {
01028         StringToBuffer f( filename );
01029         return ( f.buffer && SaveFile( f.buffer ));
01030     }
01031     #endif
01032 
01035     virtual const char* Parse( const char* p, TiXmlParsingData* data = 0 );
01036 
01041     TiXmlElement* RootElement() const       { return FirstChildElement(); }
01042 
01048     bool Error() const                      { return error; }
01049 
01051     const char * ErrorDesc() const  { return errorDesc.c_str (); }
01052 
01056     const int ErrorId() const               { return errorId; }
01057 
01065     int ErrorRow()  { return errorLocation.row+1; }
01066     int ErrorCol()  { return errorLocation.col+1; } 
01067 
01088     void SetTabSize( int _tabsize )     { tabsize = _tabsize; }
01089 
01090     int TabSize() const { return tabsize; }
01091 
01095     void ClearError()                       {   error = false; 
01096                                                 errorId = 0; 
01097                                                 errorDesc = ""; 
01098                                                 errorLocation.row = errorLocation.col = 0; 
01099                                                 //errorLocation.last = 0; 
01100                                             }
01101 
01103     void Print() const                      { Print( stdout, 0 ); }
01104 
01105     // [internal use]
01106     virtual void Print( FILE* cfile, int depth = 0 ) const;
01107     // [internal use]
01108     void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData );
01109 
01110 protected :
01111     virtual void StreamOut ( TIXML_OSTREAM * out) const;
01112     // [internal use]
01113     virtual TiXmlNode* Clone() const;
01114     #ifdef TIXML_USE_STL
01115         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01116     #endif
01117 
01118 private:
01119     bool error;
01120     int  errorId;
01121     TIXML_STRING errorDesc;
01122     int tabsize;
01123     TiXmlCursor errorLocation;
01124 };
01125 
01126 
01207 class CAL3D_API TiXmlHandle
01208 {
01209 public:
01211     TiXmlHandle( TiXmlNode* node )          { this->node = node; }
01213     TiXmlHandle( const TiXmlHandle& ref )   { this->node = ref.node; }
01214 
01216     TiXmlHandle FirstChild() const;
01218     TiXmlHandle FirstChild( const char * value ) const;
01220     TiXmlHandle FirstChildElement() const;
01222     TiXmlHandle FirstChildElement( const char * value ) const;
01223 
01227     TiXmlHandle Child( const char* value, int index ) const;
01231     TiXmlHandle Child( int index ) const;
01236     TiXmlHandle ChildElement( const char* value, int index ) const;
01241     TiXmlHandle ChildElement( int index ) const;
01242 
01243     #ifdef TIXML_USE_STL
01244     TiXmlHandle FirstChild( const std::string& _value ) const           { return FirstChild( _value.c_str() ); }
01245     TiXmlHandle FirstChildElement( const std::string& _value ) const        { return FirstChildElement( _value.c_str() ); }
01246 
01247     TiXmlHandle Child( const std::string& _value, int index ) const         { return Child( _value.c_str(), index ); }
01248     TiXmlHandle ChildElement( const std::string& _value, int index ) const  { return ChildElement( _value.c_str(), index ); }
01249     #endif
01250 
01252     TiXmlNode* Node() const         { return node; } 
01254     TiXmlElement* Element() const   { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01256     TiXmlText* Text() const         { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01257 
01258 private:
01259     TiXmlNode* node;
01260 };
01261 
01262 
01263 #endif
01264 

Generated at Sat Dec 10 22:17:30 2005 by The Cal3D Team with doxygen 1.4.5 © 1997-2001 Dimitri van Heesch