Panda3D

tinyxml.h

00001 /*
00002 www.sourceforge.net/projects/tinyxml
00003 Original code (2.0 and earlier )copyright (c) 2000-2006 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( push )
00031 #pragma warning( disable : 4530 )
00032 #pragma warning( disable : 4786 )
00033 #endif
00034 
00035 #include <ctype.h>
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039 #include <assert.h>
00040 
00041 // Help out windows:
00042 #if defined( _DEBUG ) && !defined( DEBUG )
00043 #define DEBUG
00044 #endif
00045 
00046 #ifdef TIXML_USE_STL
00047   #include <string>
00048   #include <iostream>
00049   #include <sstream>
00050   #define TIXML_STRING    std::string
00051 #else
00052   #include "tinystr.h"
00053   #define TIXML_STRING    TiXmlString
00054 #endif
00055 
00056 // Deprecated library function hell. Compilers want to use the
00057 // new safe versions. This probably doesn't fully address the problem,
00058 // but it gets closer. There are too many compilers for me to fully
00059 // test. If you get compilation troubles, undefine TIXML_SAFE
00060 #define TIXML_SAFE
00061 
00062 #ifdef TIXML_SAFE
00063   #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
00064     // Microsoft visual studio, version 2005 and higher.
00065     #define TIXML_SNPRINTF _snprintf_s
00066     #define TIXML_SSCANF   sscanf_s
00067   #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
00068     // Microsoft visual studio, version 6 and higher.
00069     //#pragma message( "Using _sn* functions." )
00070     #define TIXML_SNPRINTF _snprintf
00071     #define TIXML_SSCANF   sscanf
00072   #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00073     // GCC version 3 and higher.s
00074     //#warning( "Using sn* functions." )
00075     #define TIXML_SNPRINTF snprintf
00076     #define TIXML_SSCANF   sscanf
00077   #else
00078     #define TIXML_SNPRINTF snprintf
00079     #define TIXML_SSCANF   sscanf
00080   #endif
00081 #endif  
00082 
00083 class TiXmlDocument;
00084 class TiXmlElement;
00085 class TiXmlComment;
00086 class TiXmlUnknown;
00087 class TiXmlAttribute;
00088 class TiXmlText;
00089 class TiXmlDeclaration;
00090 class TiXmlParsingData;
00091 
00092 const int TIXML_MAJOR_VERSION = 2;
00093 const int TIXML_MINOR_VERSION = 6;
00094 const int TIXML_PATCH_VERSION = 1;
00095 
00096 /*  Internal structure for tracking location of items 
00097   in the XML file.
00098 */
00099 struct TiXmlCursor
00100 {
00101   TiXmlCursor()   { Clear(); }
00102   void Clear()    { row = col = -1; }
00103 
00104   int row;  // 0 based.
00105   int col;  // 0 based.
00106 };
00107 
00108 
00109 /**
00110   Implements the interface to the "Visitor pattern" (see the Accept() method.)
00111   If you call the Accept() method, it requires being passed a TiXmlVisitor
00112   class to handle callbacks. For nodes that contain other nodes (Document, Element)
00113   you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves
00114   are simply called with Visit().
00115 
00116   If you return 'true' from a Visit method, recursive parsing will continue. If you return
00117   false, <b>no children of this node or its sibilings</b> will be Visited.
00118 
00119   All flavors of Visit methods have a default implementation that returns 'true' (continue 
00120   visiting). You need to only override methods that are interesting to you.
00121 
00122   Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting.
00123 
00124   You should never change the document from a callback.
00125 
00126   @sa TiXmlNode::Accept()
00127 */
00128 class TiXmlVisitor
00129 {
00130 public:
00131   virtual ~TiXmlVisitor() {}
00132 
00133   /// Visit a document.
00134   virtual bool VisitEnter( const TiXmlDocument& /*doc*/ )     { return true; }
00135   /// Visit a document.
00136   virtual bool VisitExit( const TiXmlDocument& /*doc*/ )      { return true; }
00137 
00138   /// Visit an element.
00139   virtual bool VisitEnter( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ )  { return true; }
00140   /// Visit an element.
00141   virtual bool VisitExit( const TiXmlElement& /*element*/ )   { return true; }
00142 
00143   /// Visit a declaration
00144   virtual bool Visit( const TiXmlDeclaration& /*declaration*/ ) { return true; }
00145   /// Visit a text node
00146   virtual bool Visit( const TiXmlText& /*text*/ )         { return true; }
00147   /// Visit a comment node
00148   virtual bool Visit( const TiXmlComment& /*comment*/ )     { return true; }
00149   /// Visit an unknow node
00150   virtual bool Visit( const TiXmlUnknown& /*unknown*/ )     { return true; }
00151 };
00152 
00153 // Only used by Attribute::Query functions
00154 enum 
00155 { 
00156   TIXML_SUCCESS,
00157   TIXML_NO_ATTRIBUTE,
00158   TIXML_WRONG_TYPE
00159 };
00160 
00161 
00162 // Used by the parsing routines.
00163 enum TiXmlEncoding
00164 {
00165   TIXML_ENCODING_UNKNOWN,
00166   TIXML_ENCODING_UTF8,
00167   TIXML_ENCODING_LEGACY
00168 };
00169 
00170 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00171 
00172 /** TiXmlBase is a base class for every class in TinyXml.
00173   It does little except to establish that TinyXml classes
00174   can be printed and provide some utility functions.
00175 
00176   In XML, the document and elements can contain
00177   other elements and other types of nodes.
00178 
00179   @verbatim
00180   A Document can contain: Element (container or leaf)
00181               Comment (leaf)
00182               Unknown (leaf)
00183               Declaration( leaf )
00184 
00185   An Element can contain: Element (container or leaf)
00186               Text  (leaf)
00187               Attributes (not on tree)
00188               Comment (leaf)
00189               Unknown (leaf)
00190 
00191   A Decleration contains: Attributes (not on tree)
00192   @endverbatim
00193 */
00194 class TiXmlBase
00195 {
00196   friend class TiXmlNode;
00197   friend class TiXmlElement;
00198   friend class TiXmlDocument;
00199 
00200 public:
00201   TiXmlBase() : userData(0)   {}
00202   virtual ~TiXmlBase()      {}
00203 
00204   /** All TinyXml classes can print themselves to a filestream
00205     or the string class (TiXmlString in non-STL mode, std::string
00206     in STL mode.) Either or both cfile and str can be null.
00207     
00208     This is a formatted print, and will insert 
00209     tabs and newlines.
00210     
00211     (For an unformatted stream, use the << operator.)
00212   */
00213   virtual void Print( FILE* cfile, int depth ) const = 0;
00214 
00215   /** The world does not agree on whether white space should be kept or
00216     not. In order to make everyone happy, these global, static functions
00217     are provided to set whether or not TinyXml will condense all white space
00218     into a single space or not. The default is to condense. Note changing this
00219     value is not thread safe.
00220   */
00221   static void SetCondenseWhiteSpace( bool condense )    { condenseWhiteSpace = condense; }
00222 
00223   /// Return the current white space setting.
00224   static bool IsWhiteSpaceCondensed()           { return condenseWhiteSpace; }
00225 
00226   /** Return the position, in the original source file, of this node or attribute.
00227     The row and column are 1-based. (That is the first row and first column is
00228     1,1). If the returns values are 0 or less, then the parser does not have
00229     a row and column value.
00230 
00231     Generally, the row and column value will be set when the TiXmlDocument::Load(),
00232     TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set
00233     when the DOM was created from operator>>.
00234 
00235     The values reflect the initial load. Once the DOM is modified programmatically
00236     (by adding or changing nodes and attributes) the new values will NOT update to
00237     reflect changes in the document.
00238 
00239     There is a minor performance cost to computing the row and column. Computation
00240     can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value.
00241 
00242     @sa TiXmlDocument::SetTabSize()
00243   */
00244   int Row() const     { return location.row + 1; }
00245   int Column() const    { return location.col + 1; }  ///< See Row()
00246 
00247   void  SetUserData( void* user )     { userData = user; }  ///< Set a pointer to arbitrary user data.
00248   void* GetUserData()           { return userData; }  ///< Get a pointer to arbitrary user data.
00249   const void* GetUserData() const     { return userData; }  ///< Get a pointer to arbitrary user data.
00250 
00251   // Table that returs, for a given lead byte, the total number of bytes
00252   // in the UTF-8 sequence.
00253   static const int utf8ByteTable[256];
00254 
00255   virtual const char* Parse(  const char* p, 
00256                 TiXmlParsingData* data, 
00257                 TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
00258 
00259   /** Expands entities in a string. Note this should not contian the tag's '<', '>', etc, 
00260     or they will be transformed into entities!
00261   */
00262   static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
00263 
00264   enum
00265   {
00266     TIXML_NO_ERROR = 0,
00267     TIXML_ERROR,
00268     TIXML_ERROR_OPENING_FILE,
00269     TIXML_ERROR_PARSING_ELEMENT,
00270     TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00271     TIXML_ERROR_READING_ELEMENT_VALUE,
00272     TIXML_ERROR_READING_ATTRIBUTES,
00273     TIXML_ERROR_PARSING_EMPTY,
00274     TIXML_ERROR_READING_END_TAG,
00275     TIXML_ERROR_PARSING_UNKNOWN,
00276     TIXML_ERROR_PARSING_COMMENT,
00277     TIXML_ERROR_PARSING_DECLARATION,
00278     TIXML_ERROR_DOCUMENT_EMPTY,
00279     TIXML_ERROR_EMBEDDED_NULL,
00280     TIXML_ERROR_PARSING_CDATA,
00281     TIXML_ERROR_DOCUMENT_TOP_ONLY,
00282 
00283     TIXML_ERROR_STRING_COUNT
00284   };
00285 
00286 protected:
00287 
00288   static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00289 
00290   inline static bool IsWhiteSpace( char c )   
00291   { 
00292     return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); 
00293   }
00294   inline static bool IsWhiteSpace( int c )
00295   {
00296     if ( c < 256 )
00297       return IsWhiteSpace( (char) c );
00298     return false; // Again, only truly correct for English/Latin...but usually works.
00299   }
00300 
00301   #ifdef TIXML_USE_STL
00302   static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
00303   static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
00304   #endif
00305 
00306   /*  Reads an XML name into the string provided. Returns
00307     a pointer just past the last character of the name,
00308     or 0 if the function has an error.
00309   */
00310   static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00311 
00312   /*  Reads text. Returns a pointer past the given end tag.
00313     Wickedly complex options, but it keeps the (sensitive) code in one place.
00314   */
00315   static const char* ReadText(  const char* in,       // where to start
00316                   TIXML_STRING* text,     // the string read
00317                   bool ignoreWhiteSpace,    // whether to keep the white space
00318                   const char* endTag,     // what ends this text
00319                   bool ignoreCase,      // whether to ignore case in the end tag
00320                   TiXmlEncoding encoding ); // the current encoding
00321 
00322   // If an entity has been found, transform it into a character.
00323   static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00324 
00325   // Get a character, while interpreting entities.
00326   // The length can be from 0 to 4 bytes.
00327   inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00328   {
00329     assert( p );
00330     if ( encoding == TIXML_ENCODING_UTF8 )
00331     {
00332       *length = utf8ByteTable[ *((const unsigned char*)p) ];
00333       assert( *length >= 0 && *length < 5 );
00334     }
00335     else
00336     {
00337       *length = 1;
00338     }
00339 
00340     if ( *length == 1 )
00341     {
00342       if ( *p == '&' )
00343         return GetEntity( p, _value, length, encoding );
00344       *_value = *p;
00345       return p+1;
00346     }
00347     else if ( *length )
00348     {
00349       //strncpy( _value, p, *length );  // lots of compilers don't like this function (unsafe),
00350                         // and the null terminator isn't needed
00351       for( int i=0; p[i] && i<*length; ++i ) {
00352         _value[i] = p[i];
00353       }
00354       return p + (*length);
00355     }
00356     else
00357     {
00358       // Not valid text.
00359       return 0;
00360     }
00361   }
00362 
00363   // Return true if the next characters in the stream are any of the endTag sequences.
00364   // Ignore case only works for english, and should only be relied on when comparing
00365   // to English words: StringEqual( p, "version", true ) is fine.
00366   static bool StringEqual(  const char* p,
00367                 const char* endTag,
00368                 bool ignoreCase,
00369                 TiXmlEncoding encoding );
00370 
00371   static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00372 
00373   TiXmlCursor location;
00374 
00375     /// Field containing a generic user pointer
00376   void*     userData;
00377   
00378   // None of these methods are reliable for any language except English.
00379   // Good for approximation, not great for accuracy.
00380   static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00381   static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00382   inline static int ToLower( int v, TiXmlEncoding encoding )
00383   {
00384     if ( encoding == TIXML_ENCODING_UTF8 )
00385     {
00386       if ( v < 128 ) return tolower( v );
00387       return v;
00388     }
00389     else
00390     {
00391       return tolower( v );
00392     }
00393   }
00394   static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00395 
00396 private:
00397   TiXmlBase( const TiXmlBase& );        // not implemented.
00398   void operator=( const TiXmlBase& base );  // not allowed.
00399 
00400   struct Entity
00401   {
00402     const char*     str;
00403     unsigned int  strLength;
00404     char        chr;
00405   };
00406   enum
00407   {
00408     NUM_ENTITY = 5,
00409     MAX_ENTITY_LENGTH = 6
00410 
00411   };
00412   static Entity entity[ NUM_ENTITY ];
00413   static bool condenseWhiteSpace;
00414 };
00415 
00416 
00417 /** The parent class for everything in the Document Object Model.
00418   (Except for attributes).
00419   Nodes have siblings, a parent, and children. A node can be
00420   in a document, or stand on its own. The type of a TiXmlNode
00421   can be queried, and it can be cast to its more defined type.
00422 */
00423 class TiXmlNode : public TiXmlBase
00424 {
00425   friend class TiXmlDocument;
00426   friend class TiXmlElement;
00427 
00428 public:
00429   #ifdef TIXML_USE_STL  
00430 
00431       /** An input stream operator, for every class. Tolerant of newlines and
00432         formatting, but doesn't expect them.
00433       */
00434       friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00435 
00436       /** An output stream operator, for every class. Note that this outputs
00437         without any newlines or formatting, as opposed to Print(), which
00438         includes tabs and new lines.
00439 
00440         The operator<< and operator>> are not completely symmetric. Writing
00441         a node to a stream is very well defined. You'll get a nice stream
00442         of output, without any extra whitespace or newlines.
00443         
00444         But reading is not as well defined. (As it always is.) If you create
00445         a TiXmlElement (for example) and read that from an input stream,
00446         the text needs to define an element or junk will result. This is
00447         true of all input streams, but it's worth keeping in mind.
00448 
00449         A TiXmlDocument will read nodes until it reads a root element, and
00450       all the children of that root element.
00451       */  
00452       friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00453 
00454     /// Appends the XML node or attribute to a std::string.
00455     friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00456 
00457   #endif
00458 
00459   /** The types of XML nodes supported by TinyXml. (All the
00460       unsupported types are picked up by UNKNOWN.)
00461   */
00462   enum NodeType
00463   {
00464     TINYXML_DOCUMENT,
00465     TINYXML_ELEMENT,
00466     TINYXML_COMMENT,
00467     TINYXML_UNKNOWN,
00468     TINYXML_TEXT,
00469     TINYXML_DECLARATION,
00470     TINYXML_TYPECOUNT
00471   };
00472 
00473   virtual ~TiXmlNode();
00474 
00475   /** The meaning of 'value' changes for the specific type of
00476     TiXmlNode.
00477     @verbatim
00478     Document: filename of the xml file
00479     Element:  name of the element
00480     Comment:  the comment text
00481     Unknown:  the tag contents
00482     Text:   the text string
00483     @endverbatim
00484 
00485     The subclasses will wrap this function.
00486   */
00487   const char *Value() const { return value.c_str (); }
00488 
00489     #ifdef TIXML_USE_STL
00490   /** Return Value() as a std::string. If you only use STL,
00491       this is more efficient than calling Value().
00492     Only available in STL mode.
00493   */
00494   const std::string& ValueStr() const { return value; }
00495   #endif
00496 
00497   const TIXML_STRING& ValueTStr() const { return value; }
00498 
00499   /** Changes the value of the node. Defined as:
00500     @verbatim
00501     Document: filename of the xml file
00502     Element:  name of the element
00503     Comment:  the comment text
00504     Unknown:  the tag contents
00505     Text:   the text string
00506     @endverbatim
00507   */
00508   void SetValue(const char * _value) { value = _value;}
00509 
00510     #ifdef TIXML_USE_STL
00511   /// STL std::string form.
00512   void SetValue( const std::string& _value )  { value = _value; }
00513   #endif
00514 
00515   /// Delete all the children of this node. Does not affect 'this'.
00516   void Clear();
00517 
00518   /// One step up the DOM.
00519   TiXmlNode* Parent()             { return parent; }
00520   const TiXmlNode* Parent() const       { return parent; }
00521 
00522   const TiXmlNode* FirstChild() const   { return firstChild; }  ///< The first child of this node. Will be null if there are no children.
00523   TiXmlNode* FirstChild()           { return firstChild; }
00524   const TiXmlNode* FirstChild( const char * value ) const;      ///< The first child of this node with the matching 'value'. Will be null if none found.
00525   /// The first child of this node with the matching 'value'. Will be null if none found.
00526   TiXmlNode* FirstChild( const char * _value ) {
00527     // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe)
00528     // call the method, cast the return back to non-const.
00529     return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
00530   }
00531   const TiXmlNode* LastChild() const  { return lastChild; }   /// The last child of this node. Will be null if there are no children.
00532   TiXmlNode* LastChild()  { return lastChild; }
00533   
00534   const TiXmlNode* LastChild( const char * value ) const;     /// The last child of this node matching 'value'. Will be null if there are no children.
00535   TiXmlNode* LastChild( const char * _value ) {
00536     return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
00537   }
00538 
00539     #ifdef TIXML_USE_STL
00540   const TiXmlNode* FirstChild( const std::string& _value ) const  { return FirstChild (_value.c_str ());  } ///< STL std::string form.
00541   TiXmlNode* FirstChild( const std::string& _value )        { return FirstChild (_value.c_str ());  } ///< STL std::string form.
00542   const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form.
00543   TiXmlNode* LastChild( const std::string& _value )       { return LastChild (_value.c_str ()); } ///< STL std::string form.
00544   #endif
00545 
00546   /** An alternate way to walk the children of a node.
00547     One way to iterate over nodes is:
00548     @verbatim
00549       for( child = parent->FirstChild(); child; child = child->NextSibling() )
00550     @endverbatim
00551 
00552     IterateChildren does the same thing with the syntax:
00553     @verbatim
00554       child = 0;
00555       while( child = parent->IterateChildren( child ) )
00556     @endverbatim
00557 
00558     IterateChildren takes the previous child as input and finds
00559     the next one. If the previous child is null, it returns the
00560     first. IterateChildren will return null when done.
00561   */
00562   const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00563   TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
00564     return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
00565   }
00566 
00567   /// This flavor of IterateChildren searches for children with a particular 'value'
00568   const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00569   TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
00570     return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
00571   }
00572 
00573     #ifdef TIXML_USE_STL
00574   const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const  { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form.
00575   TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) {  return IterateChildren (_value.c_str (), previous); } ///< STL std::string form.
00576   #endif
00577 
00578   /** Add a new node related to this. Adds a child past the LastChild.
00579     Returns a pointer to the new object or NULL if an error occured.
00580   */
00581   TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00582 
00583 
00584   /** Add a new node related to this. Adds a child past the LastChild.
00585 
00586     NOTE: the node to be added is passed by pointer, and will be
00587     henceforth owned (and deleted) by tinyXml. This method is efficient
00588     and avoids an extra copy, but should be used with care as it
00589     uses a different memory model than the other insert functions.
00590 
00591     @sa InsertEndChild
00592   */
00593   TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00594 
00595   /** Add a new node related to this. Adds a child before the specified child.
00596     Returns a pointer to the new object or NULL if an error occured.
00597   */
00598   TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00599 
00600   /** Add a new node related to this. Adds a child after the specified child.
00601     Returns a pointer to the new object or NULL if an error occured.
00602   */
00603   TiXmlNode* InsertAfterChild(  TiXmlNode* afterThis, const TiXmlNode& addThis );
00604 
00605   /** Replace a child of this node.
00606     Returns a pointer to the new object or NULL if an error occured.
00607   */
00608   TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00609 
00610   /// Delete a child of this node.
00611   bool RemoveChild( TiXmlNode* removeThis );
00612 
00613   /// Navigate to a sibling node.
00614   const TiXmlNode* PreviousSibling() const      { return prev; }
00615   TiXmlNode* PreviousSibling()            { return prev; }
00616 
00617   /// Navigate to a sibling node.
00618   const TiXmlNode* PreviousSibling( const char * ) const;
00619   TiXmlNode* PreviousSibling( const char *_prev ) {
00620     return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
00621   }
00622 
00623     #ifdef TIXML_USE_STL
00624   const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form.
00625   TiXmlNode* PreviousSibling( const std::string& _value )       { return PreviousSibling (_value.c_str ()); } ///< STL std::string form.
00626   const TiXmlNode* NextSibling( const std::string& _value) const    { return NextSibling (_value.c_str ()); } ///< STL std::string form.
00627   TiXmlNode* NextSibling( const std::string& _value)          { return NextSibling (_value.c_str ()); } ///< STL std::string form.
00628   #endif
00629 
00630   /// Navigate to a sibling node.
00631   const TiXmlNode* NextSibling() const        { return next; }
00632   TiXmlNode* NextSibling()              { return next; }
00633 
00634   /// Navigate to a sibling node with the given 'value'.
00635   const TiXmlNode* NextSibling( const char * ) const;
00636   TiXmlNode* NextSibling( const char* _next ) {
00637     return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
00638   }
00639 
00640   /** Convenience function to get through elements.
00641     Calls NextSibling and ToElement. Will skip all non-Element
00642     nodes. Returns 0 if there is not another element.
00643   */
00644   const TiXmlElement* NextSiblingElement() const;
00645   TiXmlElement* NextSiblingElement() {
00646     return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
00647   }
00648 
00649   /** Convenience function to get through elements.
00650     Calls NextSibling and ToElement. Will skip all non-Element
00651     nodes. Returns 0 if there is not another element.
00652   */
00653   const TiXmlElement* NextSiblingElement( const char * ) const;
00654   TiXmlElement* NextSiblingElement( const char *_next ) {
00655     return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
00656   }
00657 
00658     #ifdef TIXML_USE_STL
00659   const TiXmlElement* NextSiblingElement( const std::string& _value) const  { return NextSiblingElement (_value.c_str ());  } ///< STL std::string form.
00660   TiXmlElement* NextSiblingElement( const std::string& _value)        { return NextSiblingElement (_value.c_str ());  } ///< STL std::string form.
00661   #endif
00662 
00663   /// Convenience function to get through elements.
00664   const TiXmlElement* FirstChildElement() const;
00665   TiXmlElement* FirstChildElement() {
00666     return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
00667   }
00668 
00669   /// Convenience function to get through elements.
00670   const TiXmlElement* FirstChildElement( const char * _value ) const;
00671   TiXmlElement* FirstChildElement( const char * _value ) {
00672     return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
00673   }
00674 
00675     #ifdef TIXML_USE_STL
00676   const TiXmlElement* FirstChildElement( const std::string& _value ) const  { return FirstChildElement (_value.c_str ()); } ///< STL std::string form.
00677   TiXmlElement* FirstChildElement( const std::string& _value )        { return FirstChildElement (_value.c_str ()); } ///< STL std::string form.
00678   #endif
00679 
00680   /** Query the type (as an enumerated value, above) of this node.
00681     The possible types are: DOCUMENT, ELEMENT, COMMENT,
00682                 UNKNOWN, TEXT, and DECLARATION.
00683   */
00684   int Type() const  { return type; }
00685 
00686   /** Return a pointer to the Document this node lives in.
00687     Returns null if not in a document.
00688   */
00689   const TiXmlDocument* GetDocument() const;
00690   TiXmlDocument* GetDocument() {
00691     return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
00692   }
00693 
00694   /// Returns true if this node has no children.
00695   bool NoChildren() const           { return !firstChild; }
00696 
00697   virtual const TiXmlDocument*    ToDocument()    const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00698   virtual const TiXmlElement*     ToElement()     const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00699   virtual const TiXmlComment*     ToComment()     const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00700   virtual const TiXmlUnknown*     ToUnknown()     const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00701   virtual const TiXmlText*        ToText()        const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00702   virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00703 
00704   virtual TiXmlDocument*          ToDocument()    { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00705   virtual TiXmlElement*           ToElement()     { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00706   virtual TiXmlComment*           ToComment()     { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00707   virtual TiXmlUnknown*           ToUnknown()     { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00708   virtual TiXmlText*              ToText()        { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00709   virtual TiXmlDeclaration*       ToDeclaration() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
00710 
00711   /** Create an exact duplicate of this node and return it. The memory must be deleted
00712     by the caller. 
00713   */
00714   virtual TiXmlNode* Clone() const = 0;
00715 
00716   /** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the 
00717     XML tree will be conditionally visited and the host will be called back
00718     via the TiXmlVisitor interface.
00719 
00720     This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse
00721     the XML for the callbacks, so the performance of TinyXML is unchanged by using this
00722     interface versus any other.)
00723 
00724     The interface has been based on ideas from:
00725 
00726     - http://www.saxproject.org/
00727     - http://c2.com/cgi/wiki?HierarchicalVisitorPattern 
00728 
00729     Which are both good references for "visiting".
00730 
00731     An example of using Accept():
00732     @verbatim
00733     TiXmlPrinter printer;
00734     tinyxmlDoc.Accept( &printer );
00735     const char* xmlcstr = printer.CStr();
00736     @endverbatim
00737   */
00738   virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
00739 
00740 protected:
00741   TiXmlNode( NodeType _type );
00742 
00743   // Copy to the allocated object. Shared functionality between Clone, Copy constructor,
00744   // and the assignment operator.
00745   void CopyTo( TiXmlNode* target ) const;
00746 
00747   #ifdef TIXML_USE_STL
00748       // The real work of the input operator.
00749   virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
00750   #endif
00751 
00752   // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
00753   TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00754 
00755   TiXmlNode*    parent;
00756   NodeType    type;
00757 
00758   TiXmlNode*    firstChild;
00759   TiXmlNode*    lastChild;
00760 
00761   TIXML_STRING  value;
00762 
00763   TiXmlNode*    prev;
00764   TiXmlNode*    next;
00765 
00766 private:
00767   TiXmlNode( const TiXmlNode& );        // not implemented.
00768   void operator=( const TiXmlNode& base );  // not allowed.
00769 };
00770 
00771 
00772 /** An attribute is a name-value pair. Elements have an arbitrary
00773   number of attributes, each with a unique name.
00774 
00775   @note The attributes are not TiXmlNodes, since they are not
00776       part of the tinyXML document object model. There are other
00777       suggested ways to look at this problem.
00778 */
00779 class TiXmlAttribute : public TiXmlBase
00780 {
00781   friend class TiXmlAttributeSet;
00782 
00783 public:
00784   /// Construct an empty attribute.
00785   TiXmlAttribute() : TiXmlBase()
00786   {
00787     document = 0;
00788     prev = next = 0;
00789   }
00790 
00791   #ifdef TIXML_USE_STL
00792   /// std::string constructor.
00793   TiXmlAttribute( const std::string& _name, const std::string& _value )
00794   {
00795     name = _name;
00796     value = _value;
00797     document = 0;
00798     prev = next = 0;
00799   }
00800   #endif
00801 
00802   /// Construct an attribute with a name and value.
00803   TiXmlAttribute( const char * _name, const char * _value )
00804   {
00805     name = _name;
00806     value = _value;
00807     document = 0;
00808     prev = next = 0;
00809   }
00810 
00811   const char*   Name()  const   { return name.c_str(); }    ///< Return the name of this attribute.
00812   const char*   Value() const   { return value.c_str(); }   ///< Return the value of this attribute.
00813   #ifdef TIXML_USE_STL
00814   const std::string& ValueStr() const { return value; }       ///< Return the value of this attribute.
00815   #endif
00816   int       IntValue() const;                 ///< Return the value of this attribute, converted to an integer.
00817   double      DoubleValue() const;                ///< Return the value of this attribute, converted to a double.
00818 
00819   // Get the tinyxml string representation
00820   const TIXML_STRING& NameTStr() const { return name; }
00821 
00822   /** QueryIntValue examines the value string. It is an alternative to the
00823     IntValue() method with richer error checking.
00824     If the value is an integer, it is stored in 'value' and 
00825     the call returns TIXML_SUCCESS. If it is not
00826     an integer, it returns TIXML_WRONG_TYPE.
00827 
00828     A specialized but useful call. Note that for success it returns 0,
00829     which is the opposite of almost all other TinyXml calls.
00830   */
00831   int QueryIntValue( int* _value ) const;
00832   /// QueryDoubleValue examines the value string. See QueryIntValue().
00833   int QueryDoubleValue( double* _value ) const;
00834 
00835   void SetName( const char* _name ) { name = _name; }       ///< Set the name of this attribute.
00836   void SetValue( const char* _value ) { value = _value; }       ///< Set the value.
00837 
00838   void SetIntValue( int _value );                   ///< Set the value from an integer.
00839   void SetDoubleValue( double _value );               ///< Set the value from a double.
00840 
00841     #ifdef TIXML_USE_STL
00842   /// STL std::string form.
00843   void SetName( const std::string& _name )  { name = _name; } 
00844   /// STL std::string form. 
00845   void SetValue( const std::string& _value )  { value = _value; }
00846   #endif
00847 
00848   /// Get the next sibling attribute in the DOM. Returns null at end.
00849   const TiXmlAttribute* Next() const;
00850   TiXmlAttribute* Next() {
00851     return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() ); 
00852   }
00853 
00854   /// Get the previous sibling attribute in the DOM. Returns null at beginning.
00855   const TiXmlAttribute* Previous() const;
00856   TiXmlAttribute* Previous() {
00857     return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() ); 
00858   }
00859 
00860   bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00861   bool operator<( const TiXmlAttribute& rhs )  const { return name < rhs.name; }
00862   bool operator>( const TiXmlAttribute& rhs )  const { return name > rhs.name; }
00863 
00864   /*  Attribute parsing starts: first letter of the name
00865              returns: the next char after the value end quote
00866   */
00867   virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00868 
00869   // Prints this Attribute to a FILE stream.
00870   virtual void Print( FILE* cfile, int depth ) const {
00871     Print( cfile, depth, 0 );
00872   }
00873   void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
00874 
00875   // [internal use]
00876   // Set the document pointer so the attribute can report errors.
00877   void SetDocument( TiXmlDocument* doc )  { document = doc; }
00878 
00879 private:
00880   TiXmlAttribute( const TiXmlAttribute& );        // not implemented.
00881   void operator=( const TiXmlAttribute& base ); // not allowed.
00882 
00883   TiXmlDocument*  document; // A pointer back to a document, for error reporting.
00884   TIXML_STRING name;
00885   TIXML_STRING value;
00886   TiXmlAttribute* prev;
00887   TiXmlAttribute* next;
00888 };
00889 
00890 
00891 /*  A class used to manage a group of attributes.
00892   It is only used internally, both by the ELEMENT and the DECLARATION.
00893   
00894   The set can be changed transparent to the Element and Declaration
00895   classes that use it, but NOT transparent to the Attribute
00896   which has to implement a next() and previous() method. Which makes
00897   it a bit problematic and prevents the use of STL.
00898 
00899   This version is implemented with circular lists because:
00900     - I like circular lists
00901     - it demonstrates some independence from the (typical) doubly linked list.
00902 */
00903 class TiXmlAttributeSet
00904 {
00905 public:
00906   TiXmlAttributeSet();
00907   ~TiXmlAttributeSet();
00908 
00909   void Add( TiXmlAttribute* attribute );
00910   void Remove( TiXmlAttribute* attribute );
00911 
00912   const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00913   TiXmlAttribute* First()         { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00914   const TiXmlAttribute* Last() const    { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00915   TiXmlAttribute* Last()          { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00916 
00917   TiXmlAttribute* Find( const char* _name ) const;
00918   TiXmlAttribute* FindOrCreate( const char* _name );
00919 
00920 # ifdef TIXML_USE_STL
00921   TiXmlAttribute* Find( const std::string& _name ) const;
00922   TiXmlAttribute* FindOrCreate( const std::string& _name );
00923 # endif
00924 
00925 
00926 private:
00927   //*ME:  Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),
00928   //*ME:  this class must be also use a hidden/disabled copy-constructor !!!
00929   TiXmlAttributeSet( const TiXmlAttributeSet& );  // not allowed
00930   void operator=( const TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute)
00931 
00932   TiXmlAttribute sentinel;
00933 };
00934 
00935 
00936 /** The element is a container class. It has a value, the element name,
00937   and can contain other elements, text, comments, and unknowns.
00938   Elements also contain an arbitrary number of attributes.
00939 */
00940 class TiXmlElement : public TiXmlNode
00941 {
00942 public:
00943   /// Construct an element.
00944   TiXmlElement (const char * in_value);
00945 
00946   #ifdef TIXML_USE_STL
00947   /// std::string constructor.
00948   TiXmlElement( const std::string& _value );
00949   #endif
00950 
00951   TiXmlElement( const TiXmlElement& );
00952 
00953   void operator=( const TiXmlElement& base );
00954 
00955   virtual ~TiXmlElement();
00956 
00957   /** Given an attribute name, Attribute() returns the value
00958     for the attribute of that name, or null if none exists.
00959   */
00960   const char* Attribute( const char* name ) const;
00961 
00962   /** Given an attribute name, Attribute() returns the value
00963     for the attribute of that name, or null if none exists.
00964     If the attribute exists and can be converted to an integer,
00965     the integer value will be put in the return 'i', if 'i'
00966     is non-null.
00967   */
00968   const char* Attribute( const char* name, int* i ) const;
00969 
00970   /** Given an attribute name, Attribute() returns the value
00971     for the attribute of that name, or null if none exists.
00972     If the attribute exists and can be converted to an double,
00973     the double value will be put in the return 'd', if 'd'
00974     is non-null.
00975   */
00976   const char* Attribute( const char* name, double* d ) const;
00977 
00978   /** QueryIntAttribute examines the attribute - it is an alternative to the
00979     Attribute() method with richer error checking.
00980     If the attribute is an integer, it is stored in 'value' and 
00981     the call returns TIXML_SUCCESS. If it is not
00982     an integer, it returns TIXML_WRONG_TYPE. If the attribute
00983     does not exist, then TIXML_NO_ATTRIBUTE is returned.
00984   */  
00985   int QueryIntAttribute( const char* name, int* _value ) const;
00986   /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
00987   int QueryDoubleAttribute( const char* name, double* _value ) const;
00988   /// QueryFloatAttribute examines the attribute - see QueryIntAttribute().
00989   int QueryFloatAttribute( const char* name, float* _value ) const {
00990     double d;
00991     int result = QueryDoubleAttribute( name, &d );
00992     if ( result == TIXML_SUCCESS ) {
00993       *_value = (float)d;
00994     }
00995     return result;
00996   }
00997 
00998     #ifdef TIXML_USE_STL
00999   /// QueryStringAttribute examines the attribute - see QueryIntAttribute().
01000   int QueryStringAttribute( const char* name, std::string* _value ) const {
01001     const char* cstr = Attribute( name );
01002     if ( cstr ) {
01003       *_value = std::string( cstr );
01004       return TIXML_SUCCESS;
01005     }
01006     return TIXML_NO_ATTRIBUTE;
01007   }
01008 
01009   /** Template form of the attribute query which will try to read the
01010     attribute into the specified type. Very easy, very powerful, but
01011     be careful to make sure to call this with the correct type.
01012     
01013     NOTE: This method doesn't work correctly for 'string' types that contain spaces.
01014 
01015     @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE
01016   */
01017   template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
01018   {
01019     const TiXmlAttribute* node = attributeSet.Find( name );
01020     if ( !node )
01021       return TIXML_NO_ATTRIBUTE;
01022 
01023     std::stringstream sstream( node->ValueStr() );
01024     sstream >> *outValue;
01025     if ( !sstream.fail() )
01026       return TIXML_SUCCESS;
01027     return TIXML_WRONG_TYPE;
01028   }
01029 
01030   int QueryValueAttribute( const std::string& name, std::string* outValue ) const
01031   {
01032     const TiXmlAttribute* node = attributeSet.Find( name );
01033     if ( !node )
01034       return TIXML_NO_ATTRIBUTE;
01035     *outValue = node->ValueStr();
01036     return TIXML_SUCCESS;
01037   }
01038   #endif
01039 
01040   /** Sets an attribute of name to a given value. The attribute
01041     will be created if it does not exist, or changed if it does.
01042   */
01043   void SetAttribute( const char* name, const char * _value );
01044 
01045     #ifdef TIXML_USE_STL
01046   const std::string* Attribute( const std::string& name ) const;
01047   const std::string* Attribute( const std::string& name, int* i ) const;
01048   const std::string* Attribute( const std::string& name, double* d ) const;
01049   int QueryIntAttribute( const std::string& name, int* _value ) const;
01050   int QueryDoubleAttribute( const std::string& name, double* _value ) const;
01051 
01052   /// STL std::string form.
01053   void SetAttribute( const std::string& name, const std::string& _value );
01054   ///< STL std::string form.
01055   void SetAttribute( const std::string& name, int _value );
01056   ///< STL std::string form.
01057   void SetDoubleAttribute( const std::string& name, double value );
01058   #endif
01059 
01060   /** Sets an attribute of name to a given value. The attribute
01061     will be created if it does not exist, or changed if it does.
01062   */
01063   void SetAttribute( const char * name, int value );
01064 
01065   /** Sets an attribute of name to a given value. The attribute
01066     will be created if it does not exist, or changed if it does.
01067   */
01068   void SetDoubleAttribute( const char * name, double value );
01069 
01070   /** Deletes an attribute with the given name.
01071   */
01072   void RemoveAttribute( const char * name );
01073     #ifdef TIXML_USE_STL
01074   void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ());  } ///< STL std::string form.
01075   #endif
01076 
01077   const TiXmlAttribute* FirstAttribute() const  { return attributeSet.First(); }    ///< Access the first attribute in this element.
01078   TiXmlAttribute* FirstAttribute()        { return attributeSet.First(); }
01079   const TiXmlAttribute* LastAttribute() const   { return attributeSet.Last(); }   ///< Access the last attribute in this element.
01080   TiXmlAttribute* LastAttribute()         { return attributeSet.Last(); }
01081 
01082   /** Convenience function for easy access to the text inside an element. Although easy
01083     and concise, GetText() is limited compared to getting the TiXmlText child
01084     and accessing it directly.
01085   
01086     If the first child of 'this' is a TiXmlText, the GetText()
01087     returns the character string of the Text node, else null is returned.
01088 
01089     This is a convenient method for getting the text of simple contained text:
01090     @verbatim
01091     <foo>This is text</foo>
01092     const char* str = fooElement->GetText();
01093     @endverbatim
01094 
01095     'str' will be a pointer to "This is text". 
01096     
01097     Note that this function can be misleading. If the element foo was created from
01098     this XML:
01099     @verbatim
01100     <foo><b>This is text</b></foo> 
01101     @endverbatim
01102 
01103     then the value of str would be null. The first child node isn't a text node, it is
01104     another element. From this XML:
01105     @verbatim
01106     <foo>This is <b>text</b></foo> 
01107     @endverbatim
01108     GetText() will return "This is ".
01109 
01110     WARNING: GetText() accesses a child node - don't become confused with the 
01111          similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are 
01112          safe type casts on the referenced node.
01113   */
01114   const char* GetText() const;
01115 
01116   /// Creates a new Element and returns it - the returned element is a copy.
01117   virtual TiXmlNode* Clone() const;
01118   // Print the Element to a FILE stream.
01119   virtual void Print( FILE* cfile, int depth ) const;
01120 
01121   /*  Attribtue parsing starts: next char past '<'
01122              returns: next char past '>'
01123   */
01124   virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01125 
01126   virtual const TiXmlElement*     ToElement()     const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01127   virtual TiXmlElement*           ToElement()           { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01128 
01129   /** Walk the XML tree visiting this node and all of its children. 
01130   */
01131   virtual bool Accept( TiXmlVisitor* visitor ) const;
01132 
01133 protected:
01134 
01135   void CopyTo( TiXmlElement* target ) const;
01136   void ClearThis(); // like clear, but initializes 'this' object as well
01137 
01138   // Used to be public [internal use]
01139   #ifdef TIXML_USE_STL
01140   virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01141   #endif
01142   /*  [internal use]
01143     Reads the "value" of the element -- another element, or text.
01144     This should terminate with the current end tag.
01145   */
01146   const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01147 
01148 private:
01149   TiXmlAttributeSet attributeSet;
01150 };
01151 
01152 
01153 /** An XML comment.
01154 */
01155 class TiXmlComment : public TiXmlNode
01156 {
01157 public:
01158   /// Constructs an empty comment.
01159   TiXmlComment() : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {}
01160   /// Construct a comment from text.
01161   TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {
01162     SetValue( _value );
01163   }
01164   TiXmlComment( const TiXmlComment& );
01165   void operator=( const TiXmlComment& base );
01166 
01167   virtual ~TiXmlComment() {}
01168 
01169   /// Returns a copy of this Comment.
01170   virtual TiXmlNode* Clone() const;
01171   // Write this Comment to a FILE stream.
01172   virtual void Print( FILE* cfile, int depth ) const;
01173 
01174   /*  Attribtue parsing starts: at the ! of the !--
01175              returns: next char past '>'
01176   */
01177   virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01178 
01179   virtual const TiXmlComment*  ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01180   virtual TiXmlComment*  ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01181 
01182   /** Walk the XML tree visiting this node and all of its children. 
01183   */
01184   virtual bool Accept( TiXmlVisitor* visitor ) const;
01185 
01186 protected:
01187   void CopyTo( TiXmlComment* target ) const;
01188 
01189   // used to be public
01190   #ifdef TIXML_USE_STL
01191   virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01192   #endif
01193 //  virtual void StreamOut( TIXML_OSTREAM * out ) const;
01194 
01195 private:
01196 
01197 };
01198 
01199 
01200 /** XML text. A text node can have 2 ways to output the next. "normal" output 
01201   and CDATA. It will default to the mode it was parsed from the XML file and
01202   you generally want to leave it alone, but you can change the output mode with 
01203   SetCDATA() and query it with CDATA().
01204 */
01205 class TiXmlText : public TiXmlNode
01206 {
01207   friend class TiXmlElement;
01208 public:
01209   /** Constructor for text element. By default, it is treated as 
01210     normal, encoded text. If you want it be output as a CDATA text
01211     element, set the parameter _cdata to 'true'
01212   */
01213   TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT)
01214   {
01215     SetValue( initValue );
01216     cdata = false;
01217   }
01218   virtual ~TiXmlText() {}
01219 
01220   #ifdef TIXML_USE_STL
01221   /// Constructor.
01222   TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT)
01223   {
01224     SetValue( initValue );
01225     cdata = false;
01226   }
01227   #endif
01228 
01229   TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_TEXT ) { copy.CopyTo( this ); }
01230   void operator=( const TiXmlText& base )               { base.CopyTo( this ); }
01231 
01232   // Write this text object to a FILE stream.
01233   virtual void Print( FILE* cfile, int depth ) const;
01234 
01235   /// Queries whether this represents text using a CDATA section.
01236   bool CDATA() const        { return cdata; }
01237   /// Turns on or off a CDATA representation of text.
01238   void SetCDATA( bool _cdata )  { cdata = _cdata; }
01239 
01240   virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01241 
01242   virtual const TiXmlText* ToText() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01243   virtual TiXmlText*       ToText()       { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01244 
01245   /** Walk the XML tree visiting this node and all of its children. 
01246   */
01247   virtual bool Accept( TiXmlVisitor* content ) const;
01248 
01249 protected :
01250   ///  [internal use] Creates a new Element and returns it.
01251   virtual TiXmlNode* Clone() const;
01252   void CopyTo( TiXmlText* target ) const;
01253 
01254   bool Blank() const; // returns true if all white space and new lines
01255   // [internal use]
01256   #ifdef TIXML_USE_STL
01257   virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01258   #endif
01259 
01260 private:
01261   bool cdata;     // true if this should be input and output as a CDATA style text element
01262 };
01263 
01264 
01265 /** In correct XML the declaration is the first entry in the file.
01266   @verbatim
01267     <?xml version="1.0" standalone="yes"?>
01268   @endverbatim
01269 
01270   TinyXml will happily read or write files without a declaration,
01271   however. There are 3 possible attributes to the declaration:
01272   version, encoding, and standalone.
01273 
01274   Note: In this version of the code, the attributes are
01275   handled as special cases, not generic attributes, simply
01276   because there can only be at most 3 and they are always the same.
01277 */
01278 class TiXmlDeclaration : public TiXmlNode
01279 {
01280 public:
01281   /// Construct an empty declaration.
01282   TiXmlDeclaration()   : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) {}
01283 
01284 #ifdef TIXML_USE_STL
01285   /// Constructor.
01286   TiXmlDeclaration( const std::string& _version,
01287             const std::string& _encoding,
01288             const std::string& _standalone );
01289 #endif
01290 
01291   /// Construct.
01292   TiXmlDeclaration( const char* _version,
01293             const char* _encoding,
01294             const char* _standalone );
01295 
01296   TiXmlDeclaration( const TiXmlDeclaration& copy );
01297   void operator=( const TiXmlDeclaration& copy );
01298 
01299   virtual ~TiXmlDeclaration() {}
01300 
01301   /// Version. Will return an empty string if none was found.
01302   const char *Version() const     { return version.c_str (); }
01303   /// Encoding. Will return an empty string if none was found.
01304   const char *Encoding() const    { return encoding.c_str (); }
01305   /// Is this a standalone document?
01306   const char *Standalone() const    { return standalone.c_str (); }
01307 
01308   /// Creates a copy of this Declaration and returns it.
01309   virtual TiXmlNode* Clone() const;
01310   // Print this declaration to a FILE stream.
01311   virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
01312   virtual void Print( FILE* cfile, int depth ) const {
01313     Print( cfile, depth, 0 );
01314   }
01315 
01316   virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01317 
01318   virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01319   virtual TiXmlDeclaration*       ToDeclaration()       { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01320 
01321   /** Walk the XML tree visiting this node and all of its children. 
01322   */
01323   virtual bool Accept( TiXmlVisitor* visitor ) const;
01324 
01325 protected:
01326   void CopyTo( TiXmlDeclaration* target ) const;
01327   // used to be public
01328   #ifdef TIXML_USE_STL
01329   virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01330   #endif
01331 
01332 private:
01333 
01334   TIXML_STRING version;
01335   TIXML_STRING encoding;
01336   TIXML_STRING standalone;
01337 };
01338 
01339 
01340 /** Any tag that tinyXml doesn't recognize is saved as an
01341   unknown. It is a tag of text, but should not be modified.
01342   It will be written back to the XML, unchanged, when the file
01343   is saved.
01344 
01345   DTD tags get thrown into TiXmlUnknowns.
01346 */
01347 class TiXmlUnknown : public TiXmlNode
01348 {
01349 public:
01350   TiXmlUnknown() : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN )  {}
01351   virtual ~TiXmlUnknown() {}
01352 
01353   TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN )    { copy.CopyTo( this ); }
01354   void operator=( const TiXmlUnknown& copy )                    { copy.CopyTo( this ); }
01355 
01356   /// Creates a copy of this Unknown and returns it.
01357   virtual TiXmlNode* Clone() const;
01358   // Print this Unknown to a FILE stream.
01359   virtual void Print( FILE* cfile, int depth ) const;
01360 
01361   virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01362 
01363   virtual const TiXmlUnknown*     ToUnknown()     const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01364   virtual TiXmlUnknown*           ToUnknown()     { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01365 
01366   /** Walk the XML tree visiting this node and all of its children. 
01367   */
01368   virtual bool Accept( TiXmlVisitor* content ) const;
01369 
01370 protected:
01371   void CopyTo( TiXmlUnknown* target ) const;
01372 
01373   #ifdef TIXML_USE_STL
01374   virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01375   #endif
01376 
01377 private:
01378 
01379 };
01380 
01381 
01382 /** Always the top level node. A document binds together all the
01383   XML pieces. It can be saved, loaded, and printed to the screen.
01384   The 'value' of a document node is the xml file name.
01385 */
01386 class TiXmlDocument : public TiXmlNode
01387 {
01388 public:
01389   /// Create an empty document, that has no name.
01390   TiXmlDocument();
01391   /// Create a document with a name. The name of the document is also the filename of the xml.
01392   TiXmlDocument( const char * documentName );
01393 
01394   #ifdef TIXML_USE_STL
01395   /// Constructor.
01396   TiXmlDocument( const std::string& documentName );
01397   #endif
01398 
01399   TiXmlDocument( const TiXmlDocument& copy );
01400   void operator=( const TiXmlDocument& copy );
01401 
01402   virtual ~TiXmlDocument() {}
01403 
01404   /** Load a file using the current document value.
01405     Returns true if successful. Will delete any existing
01406     document data before loading.
01407   */
01408   bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01409   /// Save a file using the current document value. Returns true if successful.
01410   bool SaveFile() const;
01411   /// Load a file using the given filename. Returns true if successful.
01412   bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01413   /// Save a file using the given filename. Returns true if successful.
01414   bool SaveFile( const char * filename ) const;
01415   /** Load a file using the given FILE*. Returns true if successful. Note that this method
01416     doesn't stream - the entire object pointed at by the FILE*
01417     will be interpreted as an XML file. TinyXML doesn't stream in XML from the current
01418     file location. Streaming may be added in the future.
01419   */
01420   bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01421   /// Save a file using the given FILE*. Returns true if successful.
01422   bool SaveFile( FILE* ) const;
01423 
01424   #ifdef TIXML_USE_STL
01425   bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )     ///< STL std::string version.
01426   {
01427     return LoadFile( filename.c_str(), encoding );
01428   }
01429   bool SaveFile( const std::string& filename ) const    ///< STL std::string version.
01430   {
01431     return SaveFile( filename.c_str() );
01432   }
01433   #endif
01434 
01435   /** Parse the given null terminated block of xml data. Passing in an encoding to this
01436     method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml
01437     to use that encoding, regardless of what TinyXml might otherwise try to detect.
01438   */
01439   virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01440 
01441   /** Get the root element -- the only top level element -- of the document.
01442     In well formed XML, there should only be one. TinyXml is tolerant of
01443     multiple elements at the document level.
01444   */
01445   const TiXmlElement* RootElement() const   { return FirstChildElement(); }
01446   TiXmlElement* RootElement()         { return FirstChildElement(); }
01447 
01448   /** If an error occurs, Error will be set to true. Also,
01449     - The ErrorId() will contain the integer identifier of the error (not generally useful)
01450     - The ErrorDesc() method will return the name of the error. (very useful)
01451     - The ErrorRow() and ErrorCol() will return the location of the error (if known)
01452   */  
01453   bool Error() const            { return error; }
01454 
01455   /// Contains a textual (english) description of the error if one occurs.
01456   const char * ErrorDesc() const  { return errorDesc.c_str (); }
01457 
01458   /** Generally, you probably want the error string ( ErrorDesc() ). But if you
01459     prefer the ErrorId, this function will fetch it.
01460   */
01461   int ErrorId() const       { return errorId; }
01462 
01463   /** Returns the location (if known) of the error. The first column is column 1, 
01464     and the first row is row 1. A value of 0 means the row and column wasn't applicable
01465     (memory errors, for example, have no row/column) or the parser lost the error. (An
01466     error in the error reporting, in that case.)
01467 
01468     @sa SetTabSize, Row, Column
01469   */
01470   int ErrorRow() const  { return errorLocation.row+1; }
01471   int ErrorCol() const  { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow()
01472 
01473   /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol())
01474     to report the correct values for row and column. It does not change the output
01475     or input in any way.
01476     
01477     By calling this method, with a tab size
01478     greater than 0, the row and column of each node and attribute is stored
01479     when the file is loaded. Very useful for tracking the DOM back in to
01480     the source file.
01481 
01482     The tab size is required for calculating the location of nodes. If not
01483     set, the default of 4 is used. The tabsize is set per document. Setting
01484     the tabsize to 0 disables row/column tracking.
01485 
01486     Note that row and column tracking is not supported when using operator>>.
01487 
01488     The tab size needs to be enabled before the parse or load. Correct usage:
01489     @verbatim
01490     TiXmlDocument doc;
01491     doc.SetTabSize( 8 );
01492     doc.Load( "myfile.xml" );
01493     @endverbatim
01494 
01495     @sa Row, Column
01496   */
01497   void SetTabSize( int _tabsize )   { tabsize = _tabsize; }
01498 
01499   int TabSize() const { return tabsize; }
01500 
01501   /** If you have handled the error, it can be reset with this call. The error
01502     state is automatically cleared if you Parse a new XML block.
01503   */
01504   void ClearError()           { error = false; 
01505                         errorId = 0; 
01506                         errorDesc = ""; 
01507                         errorLocation.row = errorLocation.col = 0; 
01508                         //errorLocation.last = 0; 
01509                       }
01510 
01511   /** Write the document to standard out using formatted printing ("pretty print"). */
01512   void Print() const            { Print( stdout, 0 ); }
01513 
01514   /* Write the document to a string using formatted printing ("pretty print"). This
01515     will allocate a character array (new char[]) and return it as a pointer. The
01516     calling code pust call delete[] on the return char* to avoid a memory leak.
01517   */
01518   //char* PrintToMemory() const; 
01519 
01520   /// Print this Document to a FILE stream.
01521   virtual void Print( FILE* cfile, int depth = 0 ) const;
01522   // [internal use]
01523   void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01524 
01525   virtual const TiXmlDocument*    ToDocument()    const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01526   virtual TiXmlDocument*          ToDocument()          { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
01527 
01528   /** Walk the XML tree visiting this node and all of its children. 
01529   */
01530   virtual bool Accept( TiXmlVisitor* content ) const;
01531 
01532 protected :
01533   // [internal use]
01534   virtual TiXmlNode* Clone() const;
01535   #ifdef TIXML_USE_STL
01536   virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
01537   #endif
01538 
01539 private:
01540   void CopyTo( TiXmlDocument* target ) const;
01541 
01542   bool error;
01543   int  errorId;
01544   TIXML_STRING errorDesc;
01545   int tabsize;
01546   TiXmlCursor errorLocation;
01547   bool useMicrosoftBOM;   // the UTF-8 BOM were found when read. Note this, and try to write.
01548 };
01549 
01550 
01551 /**
01552   A TiXmlHandle is a class that wraps a node pointer with null checks; this is
01553   an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml
01554   DOM structure. It is a separate utility class.
01555 
01556   Take an example:
01557   @verbatim
01558   <Document>
01559     <Element attributeA = "valueA">
01560       <Child attributeB = "value1" />
01561       <Child attributeB = "value2" />
01562     </Element>
01563   <Document>
01564   @endverbatim
01565 
01566   Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very 
01567   easy to write a *lot* of code that looks like:
01568 
01569   @verbatim
01570   TiXmlElement* root = document.FirstChildElement( "Document" );
01571   if ( root )
01572   {
01573     TiXmlElement* element = root->FirstChildElement( "Element" );
01574     if ( element )
01575     {
01576       TiXmlElement* child = element->FirstChildElement( "Child" );
01577       if ( child )
01578       {
01579         TiXmlElement* child2 = child->NextSiblingElement( "Child" );
01580         if ( child2 )
01581         {
01582           // Finally do something useful.
01583   @endverbatim
01584 
01585   And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity
01586   of such code. A TiXmlHandle checks for null pointers so it is perfectly safe 
01587   and correct to use:
01588 
01589   @verbatim
01590   TiXmlHandle docHandle( &document );
01591   TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement();
01592   if ( child2 )
01593   {
01594     // do something useful
01595   @endverbatim
01596 
01597   Which is MUCH more concise and useful.
01598 
01599   It is also safe to copy handles - internally they are nothing more than node pointers.
01600   @verbatim
01601   TiXmlHandle handleCopy = handle;
01602   @endverbatim
01603 
01604   What they should not be used for is iteration:
01605 
01606   @verbatim
01607   int i=0; 
01608   while ( true )
01609   {
01610     TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement();
01611     if ( !child )
01612       break;
01613     // do something
01614     ++i;
01615   }
01616   @endverbatim
01617 
01618   It seems reasonable, but it is in fact two embedded while loops. The Child method is 
01619   a linear walk to find the element, so this code would iterate much more than it needs 
01620   to. Instead, prefer:
01621 
01622   @verbatim
01623   TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement();
01624 
01625   for( child; child; child=child->NextSiblingElement() )
01626   {
01627     // do something
01628   }
01629   @endverbatim
01630 */
01631 class TiXmlHandle
01632 {
01633 public:
01634   /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
01635   TiXmlHandle( TiXmlNode* _node )         { this->node = _node; }
01636   /// Copy constructor
01637   TiXmlHandle( const TiXmlHandle& ref )     { this->node = ref.node; }
01638   TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01639 
01640   /// Return a handle to the first child node.
01641   TiXmlHandle FirstChild() const;
01642   /// Return a handle to the first child node with the given name.
01643   TiXmlHandle FirstChild( const char * value ) const;
01644   /// Return a handle to the first child element.
01645   TiXmlHandle FirstChildElement() const;
01646   /// Return a handle to the first child element with the given name.
01647   TiXmlHandle FirstChildElement( const char * value ) const;
01648 
01649   /** Return a handle to the "index" child with the given name. 
01650     The first child is 0, the second 1, etc.
01651   */
01652   TiXmlHandle Child( const char* value, int index ) const;
01653   /** Return a handle to the "index" child. 
01654     The first child is 0, the second 1, etc.
01655   */
01656   TiXmlHandle Child( int index ) const;
01657   /** Return a handle to the "index" child element with the given name. 
01658     The first child element is 0, the second 1, etc. Note that only TiXmlElements
01659     are indexed: other types are not counted.
01660   */
01661   TiXmlHandle ChildElement( const char* value, int index ) const;
01662   /** Return a handle to the "index" child element. 
01663     The first child element is 0, the second 1, etc. Note that only TiXmlElements
01664     are indexed: other types are not counted.
01665   */
01666   TiXmlHandle ChildElement( int index ) const;
01667 
01668   #ifdef TIXML_USE_STL
01669   TiXmlHandle FirstChild( const std::string& _value ) const       { return FirstChild( _value.c_str() ); }
01670   TiXmlHandle FirstChildElement( const std::string& _value ) const    { return FirstChildElement( _value.c_str() ); }
01671 
01672   TiXmlHandle Child( const std::string& _value, int index ) const     { return Child( _value.c_str(), index ); }
01673   TiXmlHandle ChildElement( const std::string& _value, int index ) const  { return ChildElement( _value.c_str(), index ); }
01674   #endif
01675 
01676   /** Return the handle as a TiXmlNode. This may return null.
01677   */
01678   TiXmlNode* ToNode() const     { return node; } 
01679   /** Return the handle as a TiXmlElement. This may return null.
01680   */
01681   TiXmlElement* ToElement() const   { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01682   /** Return the handle as a TiXmlText. This may return null.
01683   */
01684   TiXmlText* ToText() const     { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01685   /** Return the handle as a TiXmlUnknown. This may return null.
01686   */
01687   TiXmlUnknown* ToUnknown() const   { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01688 
01689   /** @deprecated use ToNode. 
01690     Return the handle as a TiXmlNode. This may return null.
01691   */
01692   TiXmlNode* Node() const     { return ToNode(); } 
01693   /** @deprecated use ToElement. 
01694     Return the handle as a TiXmlElement. This may return null.
01695   */
01696   TiXmlElement* Element() const { return ToElement(); }
01697   /** @deprecated use ToText()
01698     Return the handle as a TiXmlText. This may return null.
01699   */
01700   TiXmlText* Text() const     { return ToText(); }
01701   /** @deprecated use ToUnknown()
01702     Return the handle as a TiXmlUnknown. This may return null.
01703   */
01704   TiXmlUnknown* Unknown() const { return ToUnknown(); }
01705 
01706 private:
01707   TiXmlNode* node;
01708 };
01709 
01710 
01711 /** Print to memory functionality. The TiXmlPrinter is useful when you need to:
01712 
01713   -# Print to memory (especially in non-STL mode)
01714   -# Control formatting (line endings, etc.)
01715 
01716   When constructed, the TiXmlPrinter is in its default "pretty printing" mode.
01717   Before calling Accept() you can call methods to control the printing
01718   of the XML document. After TiXmlNode::Accept() is called, the printed document can
01719   be accessed via the CStr(), Str(), and Size() methods.
01720 
01721   TiXmlPrinter uses the Visitor API.
01722   @verbatim
01723   TiXmlPrinter printer;
01724   printer.SetIndent( "\t" );
01725 
01726   doc.Accept( &printer );
01727   fprintf( stdout, "%s", printer.CStr() );
01728   @endverbatim
01729 */
01730 class TiXmlPrinter : public TiXmlVisitor
01731 {
01732 public:
01733   TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
01734            buffer(), indent( "    " ), lineBreak( "\n" ) {}
01735 
01736   virtual bool VisitEnter( const TiXmlDocument& doc );
01737   virtual bool VisitExit( const TiXmlDocument& doc );
01738 
01739   virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
01740   virtual bool VisitExit( const TiXmlElement& element );
01741 
01742   virtual bool Visit( const TiXmlDeclaration& declaration );
01743   virtual bool Visit( const TiXmlText& text );
01744   virtual bool Visit( const TiXmlComment& comment );
01745   virtual bool Visit( const TiXmlUnknown& unknown );
01746 
01747   /** Set the indent characters for printing. By default 4 spaces
01748     but tab (\t) is also useful, or null/empty string for no indentation.
01749   */
01750   void SetIndent( const char* _indent )     { indent = _indent ? _indent : "" ; }
01751   /// Query the indention string.
01752   const char* Indent()              { return indent.c_str(); }
01753   /** Set the line breaking string. By default set to newline (\n). 
01754     Some operating systems prefer other characters, or can be
01755     set to the null/empty string for no indenation.
01756   */
01757   void SetLineBreak( const char* _lineBreak )   { lineBreak = _lineBreak ? _lineBreak : ""; }
01758   /// Query the current line breaking string.
01759   const char* LineBreak()             { return lineBreak.c_str(); }
01760 
01761   /** Switch over to "stream printing" which is the most dense formatting without 
01762     linebreaks. Common when the XML is needed for network transmission.
01763   */
01764   void SetStreamPrinting()            { indent = "";
01765                             lineBreak = "";
01766                           } 
01767   /// Return the result.
01768   const char* CStr()                { return buffer.c_str(); }
01769   /// Return the length of the result string.
01770   size_t Size()                 { return buffer.size(); }
01771 
01772   #ifdef TIXML_USE_STL
01773   /// Return the result.
01774   const std::string& Str()            { return buffer; }
01775   #endif
01776 
01777 private:
01778   void DoIndent() {
01779     for( int i=0; i<depth; ++i )
01780       buffer += indent;
01781   }
01782   void DoLineBreak() {
01783     buffer += lineBreak;
01784   }
01785 
01786   int depth;
01787   bool simpleTextPrint;
01788   TIXML_STRING buffer;
01789   TIXML_STRING indent;
01790   TIXML_STRING lineBreak;
01791 };
01792 
01793 
01794 #ifdef _MSC_VER
01795 #pragma warning( pop )
01796 #endif
01797 
01798 #endif
01799 
 All Classes Functions Variables Enumerations