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

Generated at Thu Jun 29 19:03:59 2006 by The Cal3D Team with Doxygen 1.4.6