tinyxml.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This program is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU General Public License as published by the Free  *
00007 * Software Foundation; either version 2 of the License, or (at your option)   *
00008 * any later version.                                                          *
00009 *                                                                             *
00010 * This program is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    *
00013 * more details.                                                               *
00014 *                                                                             *
00015 * You should have received a copy of the GNU General Public License along     *
00016 * with this program; if not, write to the Free Software Foundation, Inc., 51  *
00017 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.                   *
00018 *******************************************************************************
00019 *                            SOFA :: Applications                             *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 /*
00028 www.sourceforge.net/projects/tinyxml
00029 Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
00030 
00031 This software is provided 'as-is', without any express or implied
00032 warranty. In no event will the authors be held liable for any
00033 damages arising from the use of this software.
00034 
00035 Permission is granted to anyone to use this software for any
00036 purpose, including commercial applications, and to alter it and
00037 redistribute it freely, subject to the following restrictions:
00038 
00039 1. The origin of this software must not be misrepresented; you must
00040 not claim that you wrote the original software. If you use this
00041 software in a product, an acknowledgment in the product documentation
00042 would be appreciated but is not required.
00043 
00044 2. Altered source versions must be plainly marked as such, and
00045 must not be misrepresented as being the original software.
00046 
00047 3. This notice may not be removed or altered from any source
00048 distribution.
00049 */
00050 
00051 
00052 #ifndef TINYXML_INCLUDED
00053 #define TINYXML_INCLUDED
00054 
00055 /***************************************************************************************************/
00057 //#include "dotSceneInterfacePrerequisites.h"
00058 #define DOTSCENEINTERFACE_API
00059 #define TIXML_USE_STL
00061 /***************************************************************************************************/
00062 
00063 #ifdef _MSC_VER
00064 #pragma warning( disable : 4530 )
00065 #pragma warning( disable : 4786 )
00066 #endif
00067 
00068 #include <ctype.h>
00069 #include <stdio.h>
00070 #include <stdlib.h>
00071 #include <string.h>
00072 #include <assert.h>
00073 
00074 // Help out windows:
00075 #if defined( _DEBUG ) && !defined( DEBUG )
00076 #define DEBUG
00077 #endif
00078 
00079 #if defined( DEBUG ) && defined( _MSC_VER )
00080 #define NOMINMAX
00081 #include <windows.h>
00082 #define TIXML_LOG OutputDebugString
00083 #else
00084 #define TIXML_LOG printf
00085 #endif
00086 
00087 
00088 #ifdef TIXML_USE_STL
00089     #include <string>
00090     #include <iostream>
00091     #define TIXML_STRING    std::string
00092     #define TIXML_ISTREAM   std::istream
00093     #define TIXML_OSTREAM   std::ostream
00094 #else
00095     #include "tinystr.h"
00096     #define TIXML_STRING    TiXmlString
00097     #define TIXML_OSTREAM   TiXmlOutStream
00098 #endif
00099 
00100 class TiXmlDocument;
00101 class TiXmlElement;
00102 class TiXmlComment;
00103 class TiXmlUnknown;
00104 class TiXmlAttribute;
00105 class TiXmlText;
00106 class TiXmlDeclaration;
00107 
00108 
00131 class DOTSCENEINTERFACE_API TiXmlBase
00132 {
00133     friend class TiXmlNode;
00134     friend class TiXmlElement;
00135     friend class TiXmlDocument;
00136 
00137 public:
00138     TiXmlBase()                             {}
00139     virtual ~TiXmlBase()                    {}
00140 
00146     virtual void Print( FILE* cfile, int depth ) const = 0;
00147 
00154     static void SetCondenseWhiteSpace( bool condense )      { condenseWhiteSpace = condense; }
00155 
00157     static bool IsWhiteSpaceCondensed()                     { return condenseWhiteSpace; }
00158 
00159 protected:
00160 
00161     static const char*  SkipWhiteSpace( const char* );
00162     inline static bool  IsWhiteSpace( int c )       { return ( isspace( c ) || c == '\n' || c == '\r' ); }
00163 
00164     virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00165 
00166     #ifdef TIXML_USE_STL
00167         static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00168         static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00169     #endif
00170 
00171     /*  Reads an XML name into the string provided. Returns
00172         a pointer just past the last character of the name,
00173         or 0 if the function has an error.
00174     */
00175     static const char* ReadName( const char* p, TIXML_STRING* name );
00176 
00177     /*  Reads text. Returns a pointer past the given end tag.
00178         Wickedly complex options, but it keeps the (sensitive) code in one place.
00179     */
00180     static const char* ReadText(    const char* in,             // where to start
00181                                     TIXML_STRING* text,         // the string read
00182                                     bool ignoreWhiteSpace,      // whether to keep the white space
00183                                     const char* endTag,         // what ends this text
00184                                     bool ignoreCase );          // whether to ignore case in the end tag
00185     virtual const char* Parse( const char* p ) = 0;
00186 
00187     // If an entity has been found, transform it into a character.
00188     static const char* GetEntity( const char* in, char* value );
00189 
00190     // Get a character, while interpreting entities.
00191     inline static const char* GetChar( const char* p, char* value )
00192     {
00193         assert( p );
00194         if ( *p == '&' )
00195         {
00196             return GetEntity( p, value );
00197         }
00198         else
00199         {
00200             *value = *p;
00201             return p+1;
00202         }
00203     }
00204 
00205     // Puts a string to a stream, expanding entities as it goes.
00206     // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
00207     static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00208 
00209     static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00210 
00211     // Return true if the next characters in the stream are any of the endTag sequences.
00212     bool static StringEqual(    const char* p,
00213                                 const char* endTag,
00214                                 bool ignoreCase );
00215 
00216 
00217     enum
00218     {
00219         TIXML_NO_ERROR = 0,
00220         TIXML_ERROR,
00221         TIXML_ERROR_OPENING_FILE,
00222         TIXML_ERROR_OUT_OF_MEMORY,
00223         TIXML_ERROR_PARSING_ELEMENT,
00224         TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00225         TIXML_ERROR_READING_ELEMENT_VALUE,
00226         TIXML_ERROR_READING_ATTRIBUTES,
00227         TIXML_ERROR_PARSING_EMPTY,
00228         TIXML_ERROR_READING_END_TAG,
00229         TIXML_ERROR_PARSING_UNKNOWN,
00230         TIXML_ERROR_PARSING_COMMENT,
00231         TIXML_ERROR_PARSING_DECLARATION,
00232         TIXML_ERROR_DOCUMENT_EMPTY,
00233 
00234         TIXML_ERROR_STRING_COUNT
00235     };
00236     static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00237 
00238 private:
00239     struct Entity
00240     {
00241         const char*     str;
00242         unsigned int    strLength;
00243         char            chr;
00244     };
00245     enum
00246     {
00247         NUM_ENTITY = 5,
00248         MAX_ENTITY_LENGTH = 6
00249 
00250     };
00251     static Entity entity[ NUM_ENTITY ];
00252     static bool condenseWhiteSpace;
00253 };
00254 
00255 
00262 class DOTSCENEINTERFACE_API TiXmlNode : public TiXmlBase
00263 {
00264     friend class TiXmlDocument;
00265     friend class TiXmlElement;
00266 
00267 public:
00268     #ifdef TIXML_USE_STL    
00269 
00273         friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00274 
00290         friend std::ostream & operator<< (std::ostream& out, const TiXmlNode& base);
00291 
00292     #else
00293         // Used internally, not part of the public API.
00294         friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00295     #endif
00296 
00300     enum NodeType
00301     {
00302         DOCUMENT,
00303         ELEMENT,
00304         COMMENT,
00305         UNKNOWN,
00306         TEXT,
00307         DECLARATION,
00308         TYPECOUNT
00309     };
00310 
00311     virtual ~TiXmlNode();
00312 
00325     const char * Value () const { return value.c_str (); }
00326 
00336     void SetValue (const char * _value) { value = _value;}
00337 
00338     #ifdef TIXML_USE_STL
00340     void SetValue( const std::string& value )    
00341     {     
00342         SetValue( value.c_str() );      
00343     }   
00344     #endif
00345 
00347     void Clear();
00348 
00350     TiXmlNode* Parent() const                   { return parent; }
00351 
00352     TiXmlNode* FirstChild() const   { return firstChild; }      
00353     TiXmlNode* FirstChild( const char * value ) const;          
00354 
00355     TiXmlNode* LastChild() const    { return lastChild; }       
00356     TiXmlNode* LastChild( const char * value ) const;           
00357 
00358     #ifdef TIXML_USE_STL
00359     TiXmlNode* FirstChild( const std::string& value ) const {   return FirstChild (value.c_str ()); }   
00360     TiXmlNode* LastChild( const std::string& value ) const  {   return LastChild (value.c_str ());  }   
00361     #endif
00362 
00379     TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
00380 
00382     TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
00383 
00384     #ifdef TIXML_USE_STL
00385     TiXmlNode* IterateChildren( const std::string& value, TiXmlNode* previous ) const   {   return IterateChildren (value.c_str (), previous);  }   
00386     #endif
00387 
00391     TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00392 
00396     TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00397 
00401     TiXmlNode* InsertAfterChild(  TiXmlNode* afterThis, const TiXmlNode& addThis );
00402 
00406     TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00407 
00409     bool RemoveChild( TiXmlNode* removeThis );
00410 
00412     TiXmlNode* PreviousSibling() const          { return prev; }
00413 
00415     TiXmlNode* PreviousSibling( const char * ) const;
00416 
00417     #ifdef TIXML_USE_STL
00418     TiXmlNode* PreviousSibling( const std::string& value ) const    {   return PreviousSibling (value.c_str ());    }   
00419     TiXmlNode* NextSibling( const std::string& value) const {   return NextSibling (value.c_str ());    }   
00420     #endif
00421 
00423     TiXmlNode* NextSibling() const              { return next; }
00424 
00426     TiXmlNode* NextSibling( const char * ) const;
00427 
00432     TiXmlElement* NextSiblingElement() const;
00433 
00438     TiXmlElement* NextSiblingElement( const char * ) const;
00439 
00440     #ifdef TIXML_USE_STL
00441     TiXmlElement* NextSiblingElement( const std::string& value) const   {   return NextSiblingElement (value.c_str ()); }   
00442     #endif
00443 
00445     TiXmlElement* FirstChildElement()   const;
00446 
00448     TiXmlElement* FirstChildElement( const char * value ) const;
00449 
00450     #ifdef TIXML_USE_STL
00451     TiXmlElement* FirstChildElement( const std::string& value ) const   {   return FirstChildElement (value.c_str ());  }   
00452     #endif
00453 
00455     virtual int Type() const    { return type; }
00456 
00460     TiXmlDocument* GetDocument() const;
00461 
00463     bool NoChildren() const                     { return !firstChild; }
00464 
00465     TiXmlDocument* ToDocument() const       { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; } 
00466     TiXmlElement*  ToElement() const        { return ( this && type == ELEMENT  ) ? (TiXmlElement*)  this : 0; } 
00467     TiXmlComment*  ToComment() const        { return ( this && type == COMMENT  ) ? (TiXmlComment*)  this : 0; } 
00468     TiXmlUnknown*  ToUnknown() const        { return ( this && type == UNKNOWN  ) ? (TiXmlUnknown*)  this : 0; } 
00469     TiXmlText*     ToText()    const        { return ( this && type == TEXT     ) ? (TiXmlText*)     this : 0; } 
00470     TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; } 
00471 
00472     virtual TiXmlNode* Clone() const = 0;
00473 
00474     void  SetUserData( void* user )         { userData = user; }
00475     void* GetUserData()                     { return userData; }
00476 
00477 protected:
00478     TiXmlNode( NodeType type );
00479 
00480     #ifdef TIXML_USE_STL
00481         // The real work of the input operator.
00482         virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00483     #endif
00484 
00485     // The node is passed in by ownership. This object will delete it.
00486     TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00487 
00488     // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
00489     TiXmlNode* Identify( const char* start );
00490     void CopyToClone( TiXmlNode* target ) const { target->SetValue (value.c_str() );
00491                                                   target->userData = userData; }
00492 
00493     // Internal Value function returning a TIXML_STRING
00494     TIXML_STRING SValue() const { return value ; }
00495 
00496     TiXmlNode*      parent;
00497     NodeType        type;
00498 
00499     TiXmlNode*      firstChild;
00500     TiXmlNode*      lastChild;
00501 
00502     TIXML_STRING    value;
00503 
00504     TiXmlNode*      prev;
00505     TiXmlNode*      next;
00506     void*           userData;
00507 };
00508 
00509 
00519 class DOTSCENEINTERFACE_API TiXmlAttribute : public TiXmlBase
00520 {
00521     friend class TiXmlAttributeSet;
00522 
00523 public:
00525     TiXmlAttribute() : prev( 0 ), next( 0 ) {}
00526 
00527     #ifdef TIXML_USE_STL
00529     TiXmlAttribute( const std::string& _name, const std::string& _value )
00530     {
00531         name = _name;
00532         value = _value;
00533     }
00534     #endif
00535 
00537     TiXmlAttribute( const char * _name, const char * _value ): name( _name ), value( _value ), prev( 0 ), next( 0 ) {}
00538     const char*     Name()  const       { return name.c_str (); }       
00539     const char*     Value() const       { return value.c_str (); }      
00540     const int       IntValue() const;                                   
00541     const double    DoubleValue() const;                                
00542 
00543     void SetName( const char* _name )   { name = _name; }               
00544     void SetValue( const char* _value ) { value = _value; }             
00545 
00546     void SetIntValue( int value );                                      
00547     void SetDoubleValue( double value );                                
00548 
00549     #ifdef TIXML_USE_STL
00551     void SetName( const std::string& _name )    
00552     {   
00553         SetName(_name.c_str() );    
00554     }
00556     void SetValue( const std::string& _value )  
00557     {   
00558         SetValue( _value.c_str() ); 
00559     }
00560     #endif
00561 
00563     TiXmlAttribute* Next() const;
00565     TiXmlAttribute* Previous() const;
00566 
00567     bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00568     bool operator<( const TiXmlAttribute& rhs )  const { return name < rhs.name; }
00569     bool operator>( const TiXmlAttribute& rhs )  const { return name > rhs.name; }
00570 
00571     /*  [internal use]
00572         Attribtue parsing starts: first letter of the name
00573                          returns: the next char after the value end quote
00574     */
00575     virtual const char* Parse( const char* p );
00576 
00577     // [internal use]
00578     virtual void Print( FILE* cfile, int depth ) const;
00579 
00580     virtual void StreamOut( TIXML_OSTREAM * out ) const;
00581     // [internal use]
00582     // Set the document pointer so the attribute can report errors.
00583     void SetDocument( TiXmlDocument* doc )  { document = doc; }
00584 
00585 private:
00586     TiXmlDocument*  document;   // A pointer back to a document, for error reporting.
00587     TIXML_STRING name;
00588     TIXML_STRING value;
00589     TiXmlAttribute* prev;
00590     TiXmlAttribute* next;
00591 };
00592 
00593 
00594 /*  A class used to manage a group of attributes.
00595     It is only used internally, both by the ELEMENT and the DECLARATION.
00596     
00597     The set can be changed transparent to the Element and Declaration
00598     classes that use it, but NOT transparent to the Attribute
00599     which has to implement a next() and previous() method. Which makes
00600     it a bit problematic and prevents the use of STL.
00601 
00602     This version is implemented with circular lists because:
00603         - I like circular lists
00604         - it demonstrates some independence from the (typical) doubly linked list.
00605 */
00606 class DOTSCENEINTERFACE_API TiXmlAttributeSet
00607 {
00608 public:
00609     TiXmlAttributeSet();
00610     ~TiXmlAttributeSet();
00611 
00612     void Add( TiXmlAttribute* attribute );
00613     void Remove( TiXmlAttribute* attribute );
00614 
00615     TiXmlAttribute* First() const   { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00616     TiXmlAttribute* Last()  const   { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00617     TiXmlAttribute* Find( const char * name ) const;
00618 
00619 private:
00620     TiXmlAttribute sentinel;
00621 };
00622 
00623 
00628 class DOTSCENEINTERFACE_API TiXmlElement : public TiXmlNode
00629 {
00630 public:
00632     TiXmlElement (const char * in_value);
00633 
00634     #ifdef TIXML_USE_STL
00636     TiXmlElement( const std::string& _value ) :     TiXmlNode( TiXmlNode::ELEMENT )
00637     {
00638         firstChild = lastChild = 0;
00639         value = _value;
00640     }
00641     #endif
00642 
00643     virtual ~TiXmlElement();
00644 
00645 // OGRE CHANGE 
00646 // Resolve ambiguity of std::string / const char* conversion of Ogre::String
00647 #ifndef TIXML_USE_STL
00648 // OGRE CHANGE
00652     const char* Attribute( const char* name ) const;
00653 
00660     const char* Attribute( const char* name, int* i ) const;
00661 
00665     void SetAttribute( const char* name, const char * value );
00666 // OGRE CHANGE
00667 #endif
00668 // OGRE CHANGE
00669     #ifdef TIXML_USE_STL
00670     const char* Attribute( const std::string& name ) const;
00671     const char* Attribute( const std::string& name, int* i ) const;
00672 
00674     void SetAttribute( const std::string& name, const std::string& value );
00676     void SetAttribute( const std::string& name, int value );
00677     #endif
00678 
00682     void SetAttribute( const char * name, int value );
00683 
00686     void RemoveAttribute( const char * name );
00687     #ifdef TIXML_USE_STL
00688     void RemoveAttribute( const std::string& name ) {   RemoveAttribute (name.c_str ());    }   
00689     #endif
00690 
00691     TiXmlAttribute* FirstAttribute() const  { return attributeSet.First(); }        
00692     TiXmlAttribute* LastAttribute() const   { return attributeSet.Last(); }     
00693 
00694     // [internal use] Creates a new Element and returs it.
00695     virtual TiXmlNode* Clone() const;
00696     // [internal use]
00697 
00698     virtual void Print( FILE* cfile, int depth ) const;
00699 
00700 protected:
00701 
00702     // Used to be public [internal use]
00703     #ifdef TIXML_USE_STL
00704         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00705     #endif
00706     virtual void StreamOut( TIXML_OSTREAM * out ) const;
00707 
00708     /*  [internal use]
00709         Attribtue parsing starts: next char past '<'
00710                          returns: next char past '>'
00711     */
00712     virtual const char* Parse( const char* p );
00713 
00714     /*  [internal use]
00715         Reads the "value" of the element -- another element, or text.
00716         This should terminate with the current end tag.
00717     */
00718     const char* ReadValue( const char* in );
00719 
00720 private:
00721     TiXmlAttributeSet attributeSet;
00722 };
00723 
00724 
00727 class DOTSCENEINTERFACE_API TiXmlComment : public TiXmlNode
00728 {
00729 public:
00731     TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
00732     virtual ~TiXmlComment() {}
00733 
00734     // [internal use] Creates a new Element and returs it.
00735     virtual TiXmlNode* Clone() const;
00736     // [internal use]
00737     virtual void Print( FILE* cfile, int depth ) const;
00738 protected:
00739     // used to be public
00740     #ifdef TIXML_USE_STL
00741         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00742     #endif
00743     virtual void StreamOut( TIXML_OSTREAM * out ) const;
00744     /*  [internal use]
00745         Attribtue parsing starts: at the ! of the !--
00746                          returns: next char past '>'
00747     */
00748     virtual const char* Parse( const char* p );
00749 };
00750 
00751 
00754 class DOTSCENEINTERFACE_API TiXmlText : public TiXmlNode
00755 {
00756     friend class TiXmlElement;
00757 public:
00759     TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
00760     {
00761         SetValue( initValue );
00762     }
00763     virtual ~TiXmlText() {}
00764 
00765     #ifdef TIXML_USE_STL
00767     TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
00768     {
00769         SetValue( initValue );
00770     }
00771     #endif
00772 
00773 protected :
00774     // [internal use] Creates a new Element and returns it.
00775     virtual TiXmlNode* Clone() const;
00776     // [internal use]
00777     virtual void Print( FILE* cfile, int depth ) const;
00778     virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00779     // [internal use]
00780     bool Blank() const; // returns true if all white space and new lines
00781     /*  [internal use]
00782             Attribtue parsing starts: First char of the text
00783                              returns: next char past '>'
00784         */
00785     virtual const char* Parse( const char* p );
00786     // [internal use]
00787     #ifdef TIXML_USE_STL
00788         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00789     #endif
00790 };
00791 
00792 
00806 class DOTSCENEINTERFACE_API TiXmlDeclaration : public TiXmlNode
00807 {
00808 public:
00810     TiXmlDeclaration()   : TiXmlNode( TiXmlNode::DECLARATION ) {}
00811 
00812 #ifdef TIXML_USE_STL
00814     TiXmlDeclaration(
00815                         const std::string& _version,
00816                         const std::string& _encoding,
00817                         const std::string& _standalone )
00818                     : TiXmlNode( TiXmlNode::DECLARATION )
00819     {
00820         version = _version;
00821         encoding = _encoding;
00822         standalone = _standalone;
00823     }
00824 #endif
00825 
00827     TiXmlDeclaration( const char * _version,
00828                                         const char * _encoding,
00829                                         const char * _standalone );
00830 
00831     virtual ~TiXmlDeclaration() {}
00832 
00834     const char * Version() const        { return version.c_str (); }
00836     const char * Encoding() const       { return encoding.c_str (); }
00838     const char * Standalone() const     { return standalone.c_str (); }
00839 
00840     // [internal use] Creates a new Element and returs it.
00841     virtual TiXmlNode* Clone() const;
00842     // [internal use]
00843     virtual void Print( FILE* cfile, int depth ) const;
00844 
00845 protected:
00846     // used to be public
00847     #ifdef TIXML_USE_STL
00848         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00849     #endif
00850     virtual void StreamOut ( TIXML_OSTREAM * out) const;
00851     //  [internal use]
00852     //  Attribtue parsing starts: next char past '<'
00853     //                   returns: next char past '>'
00854 
00855     virtual const char* Parse( const char* p );
00856 
00857 private:
00858     TIXML_STRING version;
00859     TIXML_STRING encoding;
00860     TIXML_STRING standalone;
00861 };
00862 
00863 
00869 class DOTSCENEINTERFACE_API TiXmlUnknown : public TiXmlNode
00870 {
00871 public:
00872     TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
00873     virtual ~TiXmlUnknown() {}
00874 
00875     // [internal use]
00876     virtual TiXmlNode* Clone() const;
00877     // [internal use]
00878     virtual void Print( FILE* cfile, int depth ) const;
00879 protected:
00880     // used to be public
00881     #ifdef TIXML_USE_STL
00882         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00883     #endif
00884     virtual void StreamOut ( TIXML_OSTREAM * out ) const;
00885     /*  [internal use]
00886         Attribute parsing starts: First char of the text
00887                          returns: next char past '>'
00888     */
00889     virtual const char* Parse( const char* p );
00890 };
00891 
00892 
00897 class DOTSCENEINTERFACE_API TiXmlDocument : public TiXmlNode
00898 {
00899 public:
00901     TiXmlDocument();
00903     TiXmlDocument( const char * documentName );
00904 
00905     #ifdef TIXML_USE_STL
00907     TiXmlDocument( const std::string& documentName ) :
00908         TiXmlNode( TiXmlNode::DOCUMENT )
00909     {
00910         value = documentName;
00911         error = false;
00912     }
00913     #endif
00914 
00915     virtual ~TiXmlDocument() {}
00916 
00921     bool LoadFile();
00923     bool SaveFile() const;
00925     bool LoadFile( const char * filename );
00927     bool SaveFile( const char * filename ) const;
00928 
00929     #ifdef TIXML_USE_STL
00930     bool LoadFile( const std::string& filename )            
00931     {
00932         return ( LoadFile( filename.c_str() ));
00933     }
00934     bool SaveFile( const std::string& filename ) const      
00935     {
00936         //StringToBuffer f( filename );
00937         return ( SaveFile( filename.c_str() ));
00938     }
00939     #endif
00940 
00942     virtual const char* Parse( const char* p );
00943 
00948     TiXmlElement* RootElement() const       { return FirstChildElement(); }
00949 
00951     bool Error() const                      { return error; }
00952 
00954     const char * ErrorDesc() const  { return errorDesc.c_str (); }
00955 
00959     const int ErrorId() const               { return errorId; }
00960 
00962     void ClearError()                       { error = false; errorId = 0; errorDesc = ""; }
00963 
00965     void Print() const                      { Print( stdout, 0 ); }
00966 
00967     // [internal use]
00968     virtual void Print( FILE* cfile, int depth = 0 ) const;
00969     // [internal use]
00970     void SetError( int err ) {      assert( err > 0 && err < TIXML_ERROR_STRING_COUNT );
00971         error   = true;
00972         errorId = err;
00973     errorDesc = errorString[ errorId ]; }
00974 
00975 protected :
00976     virtual void StreamOut ( TIXML_OSTREAM * out) const;
00977     // [internal use]
00978     virtual TiXmlNode* Clone() const;
00979     #ifdef TIXML_USE_STL
00980         virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
00981     #endif
00982 
00983 private:
00984     bool error;
00985     int  errorId;
00986     TIXML_STRING errorDesc;
00987 };
00988 
00989 #endif
00990 

Generated on Sun Nov 23 02:28:38 2008 for Sofa by  doxygen 1.5.7.1