- Cal3D 0.11 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     #define TIXML_STRING    std::string
00060     #define TIXML_ISTREAM   std::istream
00061     #define TIXML_OSTREAM   std::ostream
00062 #else
00063     #include "tinystr.h"
00064     #define TIXML_STRING    TiXmlString
00065     #define TIXML_OSTREAM   TiXmlOutStream
00066 #endif
00067 
00068 namespace cal3d
00069 {
00070 
00071     class TiXmlDocument;
00072     class TiXmlElement;
00073     class TiXmlComment;
00074     class TiXmlUnknown;
00075     class TiXmlAttribute;
00076     class TiXmlAttributeSet;
00077     class TiXmlText;
00078     class TiXmlDeclaration;
00079 
00080     class TiXmlParsingData;
00081 
00082     /*  Internal structure for tracking location of items 
00083         in the XML file.
00084     */
00085     struct CAL3D_API TiXmlCursor
00086     {
00087         TiXmlCursor()       { Clear(); }
00088         void Clear()        { row = col = -1; }
00089 
00090         int row;    // 0 based.
00091         int col;    // 0 based.
00092     };
00093 
00094 
00095     // Only used by Attribute::Query functions
00096     enum 
00097     { 
00098         TIXML_SUCCESS,
00099         TIXML_NO_ATTRIBUTE,
00100         TIXML_WRONG_TYPE
00101     };
00102 
00125     class CAL3D_API TiXmlBase
00126     {
00127         friend class TiXmlNode;
00128         friend class TiXmlElement;
00129         friend class TiXmlDocument;
00130 
00131     public:
00132         TiXmlBase()                             {}
00133         virtual ~TiXmlBase()                    {}
00134 
00140         virtual void Print( FILE* cfile, int depth ) const = 0;
00141 
00148         static void SetCondenseWhiteSpace( bool condense )      { condenseWhiteSpace = condense; }
00149 
00151         static bool IsWhiteSpaceCondensed()                     { return condenseWhiteSpace; }
00152 
00171         int Row() const         { return location.row + 1; }
00172         int Column() const      { return location.col + 1; }    
00173 
00174     protected:
00175         // See STL_STRING_BUG
00176         // Utility class to overcome a bug.
00177         class StringToBuffer
00178         {
00179         public:
00180             StringToBuffer( const TIXML_STRING& str );
00181             ~StringToBuffer();
00182             char* buffer;
00183         };
00184 
00185         static const char*  SkipWhiteSpace( const char* );
00186         inline static bool  IsWhiteSpace( int c )       { return ( isspace( c ) || c == '\n' || c == '\r' ); }
00187 
00188         virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00189 
00190         #ifdef TIXML_USE_STL
00191             static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00192             static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00193         #endif
00194 
00195         /*  Reads an XML name into the string provided. Returns
00196             a pointer just past the last character of the name,
00197             or 0 if the function has an error.
00198         */
00199         static const char* ReadName( const char* p, TIXML_STRING* name );
00200 
00201         /*  Reads text. Returns a pointer past the given end tag.
00202             Wickedly complex options, but it keeps the (sensitive) code in one place.
00203         */
00204         static const char* ReadText(    const char* in,             // where to start
00205                                         TIXML_STRING* text,         // the string read
00206                                         bool ignoreWhiteSpace,      // whether to keep the white space
00207                                         const char* endTag,         // what ends this text
00208                                         bool ignoreCase );          // whether to ignore case in the end tag
00209 
00210         virtual const char* Parse( const char* p, TiXmlParsingData* data ) = 0;
00211 
00212         // If an entity has been found, transform it into a character.
00213         static const char* GetEntity( const char* in, char* value );
00214 
00215         // Get a character, while interpreting entities.
00216         inline static const char* GetChar( const char* p, char* _value )
00217         {
00218             assert( p );
00219             if ( *p == '&' )
00220             {
00221                 return GetEntity( p, _value );
00222             }
00223             else
00224             {
00225                 *_value = *p;
00226                 return p+1;
00227             }
00228         }
00229 
00230         // Puts a string to a stream, expanding entities as it goes.
00231         // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
00232         static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00233 
00234         static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00235 
00236         // Return true if the next characters in the stream are any of the endTag sequences.
00237         static bool StringEqual(    const char* p,
00238                                     const char* endTag,
00239                                     bool ignoreCase );
00240 
00241 
00242         enum
00243         {
00244             TIXML_NO_ERROR = 0,
00245             TIXML_ERROR,
00246             TIXML_ERROR_OPENING_FILE,
00247             TIXML_ERROR_OUT_OF_MEMORY,
00248             TIXML_ERROR_PARSING_ELEMENT,
00249             TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00250             TIXML_ERROR_READING_ELEMENT_VALUE,
00251             TIXML_ERROR_READING_ATTRIBUTES,
00252             TIXML_ERROR_PARSING_EMPTY,
00253             TIXML_ERROR_READING_END_TAG,
00254             TIXML_ERROR_PARSING_UNKNOWN,
00255             TIXML_ERROR_PARSING_COMMENT,
00256             TIXML_ERROR_PARSING_DECLARATION,
00257             TIXML_ERROR_DOCUMENT_EMPTY,
00258 
00259             TIXML_ERROR_STRING_COUNT
00260         };
00261         static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00262 
00263         TiXmlCursor location;
00264 
00265     private:
00266         struct Entity
00267         {
00268             const char*     str;
00269             unsigned int    strLength;
00270             char            chr;
00271         };
00272         enum
00273         {
00274             NUM_ENTITY = 5,
00275             MAX_ENTITY_LENGTH = 6
00276 
00277         };
00278         static Entity entity[ NUM_ENTITY ];
00279         static bool condenseWhiteSpace;
00280     };
00281 
00282 
00289     class CAL3D_API TiXmlNode : public TiXmlBase
00290     {
00291         friend class TiXmlDocument;
00292         friend class TiXmlElement;
00293 
00294     public:
00295         #ifdef TIXML_USE_STL    
00296 
00300             friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00301 
00318             friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00319 
00321             friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00322 
00323         #else
00324             // Used internally, not part of the public API.
00325             friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00326         #endif
00327 
00331         enum NodeType
00332         {
00333             DOCUMENT,
00334             ELEMENT,
00335             COMMENT,
00336             UNKNOWN,
00337             TEXT,
00338             DECLARATION,
00339             TYPECOUNT
00340         };
00341 
00342         virtual ~TiXmlNode();
00343 
00356         const char * Value() const { return value.c_str (); }
00357 
00367         void SetValue(const char * _value) { value = _value;}
00368 
00369         #ifdef TIXML_USE_STL
00370 
00371         void SetValue( const std::string& _value )    
00372         {     
00373             StringToBuffer buf( _value );
00374             SetValue( buf.buffer ? buf.buffer : "" );       
00375         }   
00376         #endif
00377 
00379         void Clear();
00380 
00382         TiXmlNode* Parent() const                   { return parent; }
00383 
00384         TiXmlNode* FirstChild() const   { return firstChild; }      
00385         TiXmlNode* FirstChild( const char * value ) const;          
00386 
00387         TiXmlNode* LastChild() const    { return lastChild; }       
00388         TiXmlNode* LastChild( const char * value ) const;           
00389 
00390         #ifdef TIXML_USE_STL
00391         TiXmlNode* FirstChild( const std::string& _value ) const    {   return FirstChild (_value.c_str ());    }   
00392         TiXmlNode* LastChild( const std::string& _value ) const     {   return LastChild (_value.c_str ()); }   
00393         #endif
00394 
00411         TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
00412 
00414         TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
00415 
00416         #ifdef TIXML_USE_STL
00417         TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const  {   return IterateChildren (_value.c_str (), previous); }   
00418         #endif
00419 
00423         TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00424 
00425 
00435         TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00436 
00440         TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00441 
00445         TiXmlNode* InsertAfterChild(  TiXmlNode* afterThis, const TiXmlNode& addThis );
00446 
00450         TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00451 
00453         bool RemoveChild( TiXmlNode* removeThis );
00454 
00456         TiXmlNode* PreviousSibling() const          { return prev; }
00457 
00459         TiXmlNode* PreviousSibling( const char * ) const;
00460 
00461         #ifdef TIXML_USE_STL
00462         TiXmlNode* PreviousSibling( const std::string& _value ) const   {   return PreviousSibling (_value.c_str ());   }   
00463         TiXmlNode* NextSibling( const std::string& _value) const        {   return NextSibling (_value.c_str ());   }   
00464         #endif
00465 
00467         TiXmlNode* NextSibling() const              { return next; }
00468 
00470         TiXmlNode* NextSibling( const char * ) const;
00471 
00476         TiXmlElement* NextSiblingElement() const;
00477 
00482         TiXmlElement* NextSiblingElement( const char * ) const;
00483 
00484         #ifdef TIXML_USE_STL
00485         TiXmlElement* NextSiblingElement( const std::string& _value) const  {   return NextSiblingElement (_value.c_str ());    }   
00486         #endif
00487 
00489         TiXmlElement* FirstChildElement()   const;
00490 
00492         TiXmlElement* FirstChildElement( const char * value ) const;
00493 
00494         #ifdef TIXML_USE_STL
00495         TiXmlElement* FirstChildElement( const std::string& _value ) const  {   return FirstChildElement (_value.c_str ()); }   
00496         #endif
00497 
00502         virtual int Type() const    { return type; }
00503 
00507         TiXmlDocument* GetDocument() const;
00508 
00510         bool NoChildren() const                     { return !firstChild; }
00511 
00512         TiXmlDocument* ToDocument() const       { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; } 
00513         TiXmlElement*  ToElement() const        { return ( this && type == ELEMENT  ) ? (TiXmlElement*)  this : 0; } 
00514         TiXmlComment*  ToComment() const        { return ( this && type == COMMENT  ) ? (TiXmlComment*)  this : 0; } 
00515         TiXmlUnknown*  ToUnknown() const        { return ( this && type == UNKNOWN  ) ? (TiXmlUnknown*)  this : 0; } 
00516         TiXmlText*     ToText()    const        { return ( this && type == TEXT     ) ? (TiXmlText*)     this : 0; } 
00517         TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; } 
00518 
00519         virtual TiXmlNode* Clone() const = 0;
00520 
00521         void  SetUserData( void* user )         { userData = user; }
00522         void* GetUserData()                     { return userData; }
00523 
00524     protected:
00525         TiXmlNode( NodeType type );
00526 
00527         #ifdef TIXML_USE_STL
00528             // The real work of the input operator.
00529             virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00530         #endif
00531 
00532         // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
00533         TiXmlNode* Identify( const char* start );
00534         void CopyToClone( TiXmlNode* target ) const { target->SetValue (value.c_str() );
00535                                                     target->userData = userData; }
00536 
00537         // Internal Value function returning a TIXML_STRING
00538         TIXML_STRING SValue() const { return value ; }
00539 
00540         TiXmlNode*      parent;
00541         NodeType        type;
00542 
00543         TiXmlNode*      firstChild;
00544         TiXmlNode*      lastChild;
00545 
00546         TIXML_STRING    value;
00547 
00548         TiXmlNode*      prev;
00549         TiXmlNode*      next;
00550         void*           userData;
00551     };
00552 
00553 
00561     class CAL3D_API TiXmlAttribute : public TiXmlBase
00562     {
00563         friend class TiXmlAttributeSet;
00564 
00565     public:
00567         TiXmlAttribute()
00568         {
00569             document = 0;
00570             prev = next = 0;
00571         }
00572 
00573         #ifdef TIXML_USE_STL
00574 
00575         TiXmlAttribute( const std::string& _name, const std::string& _value )
00576         {
00577             name = _name;
00578             value = _value;
00579             document = 0;
00580             prev = next = 0;
00581         }
00582         #endif
00583 
00585         TiXmlAttribute( const char * _name, const char * _value )
00586         {
00587             name = _name;
00588             value = _value;
00589             document = 0;
00590             prev = next = 0;
00591         }
00592 
00593         const char*     Name()  const       { return name.c_str (); }       
00594         const char*     Value() const       { return value.c_str (); }      
00595         const int       IntValue() const;                                   
00596         const double    DoubleValue() const;                                
00597 
00607         int QueryIntValue( int* value ) const;
00609         int QueryDoubleValue( double* value ) const;
00610 
00611         void SetName( const char* _name )   { name = _name; }               
00612         void SetValue( const char* _value ) { value = _value; }             
00613 
00614         void SetIntValue( int value );                                      
00615         void SetDoubleValue( double value );                                
00616 
00617         #ifdef TIXML_USE_STL
00618 
00619         void SetName( const std::string& _name )    
00620         {   
00621             StringToBuffer buf( _name );
00622             SetName ( buf.buffer ? buf.buffer : "error" );  
00623         }
00625         void SetValue( const std::string& _value )  
00626         {   
00627             StringToBuffer buf( _value );
00628             SetValue( buf.buffer ? buf.buffer : "error" );  
00629         }
00630         #endif
00631 
00633         TiXmlAttribute* Next() const;
00635         TiXmlAttribute* Previous() const;
00636 
00637         bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00638         bool operator<( const TiXmlAttribute& rhs )  const { return name < rhs.name; }
00639         bool operator>( const TiXmlAttribute& rhs )  const { return name > rhs.name; }
00640 
00641         /*  [internal use]
00642             Attribtue parsing starts: first letter of the name
00643                             returns: the next char after the value end quote
00644         */
00645         virtual const char* Parse( const char* p, TiXmlParsingData* data );
00646 
00647         // [internal use]
00648         virtual void Print( FILE* cfile, int depth ) const;
00649 
00650         virtual void StreamOut( TIXML_OSTREAM * out ) const;
00651         // [internal use]
00652         // Set the document pointer so the attribute can report errors.
00653         void SetDocument( TiXmlDocument* doc )  { document = doc; }
00654 
00655     private:
00656         TiXmlDocument*  document;   // A pointer back to a document, for error reporting.
00657         TIXML_STRING name;
00658         TIXML_STRING value;
00659         TiXmlAttribute* prev;
00660         TiXmlAttribute* next;
00661     };
00662 
00663 
00664     /*  A class used to manage a group of attributes.
00665         It is only used internally, both by the ELEMENT and the DECLARATION.
00666         
00667         The set can be changed transparent to the Element and Declaration
00668         classes that use it, but NOT transparent to the Attribute
00669         which has to implement a next() and previous() method. Which makes
00670         it a bit problematic and prevents the use of STL.
00671 
00672         This version is implemented with circular lists because:
00673             - I like circular lists
00674             - it demonstrates some independence from the (typical) doubly linked list.
00675     */
00676     class CAL3D_API TiXmlAttributeSet
00677     {
00678     public:
00679         TiXmlAttributeSet();
00680         ~TiXmlAttributeSet();
00681 
00682         void Add( TiXmlAttribute* attribute );
00683         void Remove( TiXmlAttribute* attribute );
00684 
00685         TiXmlAttribute* First() const   { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00686         TiXmlAttribute* Last()  const   { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00687         TiXmlAttribute* Find( const char * name ) const;
00688 
00689     private:
00690         TiXmlAttribute sentinel;
00691     };
00692 
00693 
00698     class CAL3D_API TiXmlElement : public TiXmlNode
00699     {
00700     public:
00702         TiXmlElement (const char * in_value);
00703 
00704         #ifdef TIXML_USE_STL
00705 
00706         TiXmlElement( const std::string& _value ) :     TiXmlNode( TiXmlNode::ELEMENT )
00707         {
00708             firstChild = lastChild = 0;
00709             value = _value;
00710         }
00711         #endif
00712 
00713         virtual ~TiXmlElement();
00714 
00718         const char* Attribute( const char* name ) const;
00719 
00726         const char* Attribute( const char* name, int* i ) const;
00727 
00734         const char* Attribute( const char* name, double* d ) const;
00735 
00743         int QueryIntAttribute( const char* name, int* value ) const;
00745         int QueryDoubleAttribute( const char* name, double* value ) const;
00746 
00750         void SetAttribute( const char* name, const char * value );
00751 
00752         #ifdef TIXML_USE_STL
00753         const char* Attribute( const std::string& name ) const              { return Attribute( name.c_str() ); }
00754         const char* Attribute( const std::string& name, int* i ) const      { return Attribute( name.c_str(), i ); }
00755 
00757         void SetAttribute( const std::string& name, const std::string& _value ) 
00758         {   
00759             StringToBuffer n( name );
00760             StringToBuffer v( _value );
00761             if ( n.buffer && v.buffer )
00762                 SetAttribute (n.buffer, v.buffer ); 
00763         }   
00765         void SetAttribute( const std::string& name, int _value )    
00766         {   
00767             StringToBuffer n( name );
00768             if ( n.buffer )
00769                 SetAttribute (n.buffer, _value);    
00770         }   
00771         #endif
00772 
00776         void SetAttribute( const char * name, int value );
00777 
00780         void RemoveAttribute( const char * name );
00781         #ifdef TIXML_USE_STL
00782         void RemoveAttribute( const std::string& name ) {   RemoveAttribute (name.c_str ());    }   
00783         #endif
00784 
00785         TiXmlAttribute* FirstAttribute() const  { return attributeSet.First(); }        
00786         TiXmlAttribute* LastAttribute() const   { return attributeSet.Last(); }     
00787 
00788         // [internal use] Creates a new Element and returs it.
00789         virtual TiXmlNode* Clone() const;
00790         // [internal use]
00791 
00792         virtual void Print( FILE* cfile, int depth ) const;
00793 
00794     protected:
00795 
00796         // Used to be public [internal use]
00797         #ifdef TIXML_USE_STL
00798             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00799         #endif
00800         virtual void StreamOut( TIXML_OSTREAM * out ) const;
00801 
00802         /*  [internal use]
00803             Attribtue parsing starts: next char past '<'
00804                             returns: next char past '>'
00805         */
00806         virtual const char* Parse( const char* p, TiXmlParsingData* data );
00807 
00808         /*  [internal use]
00809             Reads the "value" of the element -- another element, or text.
00810             This should terminate with the current end tag.
00811         */
00812         const char* ReadValue( const char* in, TiXmlParsingData* prevData );
00813 
00814     private:
00815         TiXmlAttributeSet attributeSet;
00816     };
00817 
00818 
00821     class CAL3D_API TiXmlComment : public TiXmlNode
00822     {
00823     public:
00825         TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
00826         virtual ~TiXmlComment() {}
00827 
00828         // [internal use] Creates a new Element and returs it.
00829         virtual TiXmlNode* Clone() const;
00830         // [internal use]
00831         virtual void Print( FILE* cfile, int depth ) const;
00832     protected:
00833         // used to be public
00834         #ifdef TIXML_USE_STL
00835             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00836         #endif
00837         virtual void StreamOut( TIXML_OSTREAM * out ) const;
00838         /*  [internal use]
00839             Attribtue parsing starts: at the ! of the !--
00840                             returns: next char past '>'
00841         */
00842         virtual const char* Parse( const char* p, TiXmlParsingData* data );
00843     };
00844 
00845 
00848     class CAL3D_API TiXmlText : public TiXmlNode
00849     {
00850         friend class TiXmlElement;
00851     public:
00853         TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
00854         {
00855             SetValue( initValue );
00856         }
00857         virtual ~TiXmlText() {}
00858 
00859         #ifdef TIXML_USE_STL
00860 
00861         TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
00862         {
00863             SetValue( initValue );
00864         }
00865         #endif
00866 
00867         // [internal use]
00868         virtual void Print( FILE* cfile, int depth ) const;
00869 
00870     protected :
00871         // [internal use] Creates a new Element and returns it.
00872         virtual TiXmlNode* Clone() const;
00873         virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00874         // [internal use]
00875         bool Blank() const; // returns true if all white space and new lines
00876         /*  [internal use]
00877                 Attribtue parsing starts: First char of the text
00878                                 returns: next char past '>'
00879         */
00880         virtual const char* Parse( const char* p, TiXmlParsingData* data );
00881         // [internal use]
00882         #ifdef TIXML_USE_STL
00883             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00884         #endif
00885     };
00886 
00887 
00901     class CAL3D_API TiXmlDeclaration : public TiXmlNode
00902     {
00903     public:
00905         TiXmlDeclaration()   : TiXmlNode( TiXmlNode::DECLARATION ) {}
00906 
00907     #ifdef TIXML_USE_STL
00908 
00909         TiXmlDeclaration(   const std::string& _version,
00910                             const std::string& _encoding,
00911                             const std::string& _standalone )
00912                 : TiXmlNode( TiXmlNode::DECLARATION )
00913         {
00914             version = _version;
00915             encoding = _encoding;
00916             standalone = _standalone;
00917         }
00918     #endif
00919 
00921         TiXmlDeclaration(   const char* _version,
00922                             const char* _encoding,
00923                             const char* _standalone );
00924 
00925         virtual ~TiXmlDeclaration() {}
00926 
00928         const char * Version() const        { return version.c_str (); }
00930         const char * Encoding() const       { return encoding.c_str (); }
00932         const char * Standalone() const     { return standalone.c_str (); }
00933 
00934         // [internal use] Creates a new Element and returs it.
00935         virtual TiXmlNode* Clone() const;
00936         // [internal use]
00937         virtual void Print( FILE* cfile, int depth ) const;
00938 
00939     protected:
00940         // used to be public
00941         #ifdef TIXML_USE_STL
00942             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00943         #endif
00944         virtual void StreamOut ( TIXML_OSTREAM * out) const;
00945         //  [internal use]
00946         //  Attribtue parsing starts: next char past '<'
00947         //                   returns: next char past '>'
00948 
00949         virtual const char* Parse( const char* p, TiXmlParsingData* data );
00950 
00951     private:
00952         TIXML_STRING version;
00953         TIXML_STRING encoding;
00954         TIXML_STRING standalone;
00955     };
00956 
00957 
00963     class CAL3D_API TiXmlUnknown : public TiXmlNode
00964     {
00965     public:
00966         TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
00967         virtual ~TiXmlUnknown() {}
00968 
00969         // [internal use]
00970         virtual TiXmlNode* Clone() const;
00971         // [internal use]
00972         virtual void Print( FILE* cfile, int depth ) const;
00973     protected:
00974         #ifdef TIXML_USE_STL
00975             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00976         #endif
00977         virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00978         /*  [internal use]
00979             Attribute parsing starts: First char of the text
00980                             returns: next char past '>'
00981         */
00982         virtual const char* Parse( const char* p, TiXmlParsingData* data );
00983     };
00984 
00985 
00990     class CAL3D_API TiXmlDocument : public TiXmlNode
00991     {
00992     public:
00994         TiXmlDocument();
00996         TiXmlDocument( const char * documentName );
00997 
00998         #ifdef TIXML_USE_STL
00999 
01000         TiXmlDocument( const std::string& documentName ) :
01001             TiXmlNode( TiXmlNode::DOCUMENT )
01002         {
01003             tabsize = 4;
01004             value = documentName;
01005             error = false;
01006         }
01007         #endif
01008 
01009         virtual ~TiXmlDocument() {}
01010 
01015         bool LoadFile();
01017         bool SaveFile() const;
01019         bool LoadFile( const char * filename );
01021         bool SaveFile( const char * filename ) const;
01022 
01023         #ifdef TIXML_USE_STL
01024         bool LoadFile( const std::string& filename )            
01025         {
01026             StringToBuffer f( filename );
01027             return ( f.buffer && LoadFile( f.buffer ));
01028         }
01029         bool SaveFile( const std::string& filename ) const      
01030         {
01031             StringToBuffer f( filename );
01032             return ( f.buffer && SaveFile( f.buffer ));
01033         }
01034         #endif
01035 
01038         virtual const char* Parse( const char* p, TiXmlParsingData* data = 0 );
01039 
01044         TiXmlElement* RootElement() const       { return FirstChildElement(); }
01045 
01051         bool Error() const                      { return error; }
01052 
01054         const char * ErrorDesc() const  { return errorDesc.c_str (); }
01055 
01059         const int ErrorId() const               { return errorId; }
01060 
01068         int ErrorRow()  { return errorLocation.row+1; }
01069         int ErrorCol()  { return errorLocation.col+1; } 
01070 
01091         void SetTabSize( int _tabsize )     { tabsize = _tabsize; }
01092 
01093         int TabSize() const { return tabsize; }
01094 
01098         void ClearError()                       {   error = false; 
01099                                                     errorId = 0; 
01100                                                     errorDesc = ""; 
01101                                                     errorLocation.row = errorLocation.col = 0; 
01102                                                     //errorLocation.last = 0; 
01103                                                 }
01104 
01106         void Print() const                      { Print( stdout, 0 ); }
01107 
01108         // [internal use]
01109         virtual void Print( FILE* cfile, int depth = 0 ) const;
01110         // [internal use]
01111         void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData );
01112 
01113     protected :
01114         virtual void StreamOut ( TIXML_OSTREAM * out) const;
01115         // [internal use]
01116         virtual TiXmlNode* Clone() const;
01117         #ifdef TIXML_USE_STL
01118             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01119         #endif
01120 
01121     private:
01122         bool error;
01123         int  errorId;
01124         TIXML_STRING errorDesc;
01125         int tabsize;
01126         TiXmlCursor errorLocation;
01127     };
01128 
01129 
01210     class CAL3D_API TiXmlHandle
01211     {
01212     public:
01214         TiXmlHandle( TiXmlNode* node )          { this->node = node; }
01216         TiXmlHandle( const TiXmlHandle& ref )   { this->node = ref.node; }
01217 
01219         TiXmlHandle FirstChild() const;
01221         TiXmlHandle FirstChild( const char * value ) const;
01223         TiXmlHandle FirstChildElement() const;
01225         TiXmlHandle FirstChildElement( const char * value ) const;
01226 
01230         TiXmlHandle Child( const char* value, int index ) const;
01234         TiXmlHandle Child( int index ) const;
01239         TiXmlHandle ChildElement( const char* value, int index ) const;
01244         TiXmlHandle ChildElement( int index ) const;
01245 
01246         #ifdef TIXML_USE_STL
01247         TiXmlHandle FirstChild( const std::string& _value ) const           { return FirstChild( _value.c_str() ); }
01248         TiXmlHandle FirstChildElement( const std::string& _value ) const        { return FirstChildElement( _value.c_str() ); }
01249 
01250         TiXmlHandle Child( const std::string& _value, int index ) const         { return Child( _value.c_str(), index ); }
01251         TiXmlHandle ChildElement( const std::string& _value, int index ) const  { return ChildElement( _value.c_str(), index ); }
01252         #endif
01253 
01255         TiXmlNode* Node() const         { return node; } 
01257         TiXmlElement* Element() const   { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01259         TiXmlText* Text() const         { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01260 
01261     private:
01262         TiXmlNode* node;
01263     };
01264 
01265 }
01266 
01267 #endif
01268 
01269 

Generated by The Cal3D Team with Doxygen 1.7.3