Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/XML/tinyxml.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #ifndef XML_TINYXML_H
0002 #define XML_TINYXML_H
0003 
0004 /*
0005   www.sourceforge.net/projects/tinyxml
0006   Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com)
0007 
0008   This software is provided 'as-is', without any express or implied
0009   warranty. In no event will the authors be held liable for any
0010   damages arising from the use of this software.
0011 
0012   Permission is granted to anyone to use this software for any
0013   purpose, including commercial applications, and to alter it and
0014   redistribute it freely, subject to the following restrictions:
0015 
0016   1. The origin of this software must not be misrepresented; you must
0017   not claim that you wrote the original software. If you use this
0018   software in a product, an acknowledgment in the product documentation
0019   would be appreciated but is not required.
0020 
0021   2. Altered source versions must be plainly marked as such, and
0022   must not be misrepresented as being the original software.
0023 
0024   3. This notice may not be removed or altered from any source
0025   distribution.
0026 
0027 
0028   F.Gaede, DESY : added #define TIXML_USE_STL  for use with marlin
0029 */
0030 
0031 #ifndef TIXML_USE_STL
0032 #define TIXML_USE_STL
0033 #endif
0034 
0035 #ifndef TINYXML_INCLUDED
0036 #define TINYXML_INCLUDED
0037 
0038 #ifdef _MSC_VER
0039 #pragma warning( push )
0040 #pragma warning( disable : 4530 )
0041 #pragma warning( disable : 4786 )
0042 #endif
0043 
0044 #include <ctype.h>
0045 #include <stdio.h>
0046 #include <stdlib.h>
0047 #include <string.h>
0048 #include <assert.h>
0049 
0050 // Help out windows:
0051 #if defined( _DEBUG ) && !defined( DEBUG )
0052 #define DEBUG
0053 #endif
0054 
0055 #ifdef TIXML_USE_STL
0056 #include <string>
0057 #include <iostream>
0058 #include <sstream>
0059 #define TIXML_STRING            std::string
0060 #else
0061 #include "tinystr.h"
0062 #define TIXML_STRING            TiXmlString
0063 #endif
0064 
0065 // Deprecated library function hell. Compilers want to use the
0066 // new safe versions. This probably doesn't fully address the problem,
0067 // but it gets closer. There are too many compilers for me to fully
0068 // test. If you get compilation troubles, undefine TIXML_SAFE
0069 #define TIXML_SAFE
0070 
0071 #ifdef TIXML_SAFE
0072 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
0073 // Microsoft visual studio, version 2005 and higher.
0074 #define TIXML_SNPRINTF _snprintf_s
0075 #define TIXML_SNSCANF  _snscanf_s
0076 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
0077 // Microsoft visual studio, version 6 and higher.
0078 //#pragma message( "Using _sn* functions." )
0079 #define TIXML_SNPRINTF _snprintf
0080 #define TIXML_SNSCANF  _snscanf
0081 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
0082 // GCC version 3 and higher.s
0083 //#warning( "Using sn* functions." )
0084 #define TIXML_SNPRINTF snprintf
0085 #define TIXML_SNSCANF  snscanf
0086 #endif
0087 #endif
0088 
0089 class TiXmlDocument;
0090 class TiXmlElement;
0091 class TiXmlComment;
0092 class TiXmlUnknown;
0093 class TiXmlAttribute;
0094 class TiXmlText;
0095 class TiXmlDeclaration;
0096 class TiXmlParsingData;
0097 
0098 const int TIXML_MAJOR_VERSION = 2;
0099 const int TIXML_MINOR_VERSION = 5;
0100 const int TIXML_PATCH_VERSION = 2;
0101 
0102 /*      Internal structure for tracking location of items
0103         in the XML file.
0104 */
0105 struct TiXmlCursor {
0106   TiXmlCursor() {
0107     Clear();
0108   }
0109   void Clear() {
0110     row = col = -1;
0111   }
0112 
0113   int row;   // 0 based.
0114   int col;   // 0 based.
0115 };
0116 
0117 /**
0118    If you call the Accept() method, it requires being passed a TiXmlVisitor
0119    class to handle callbacks. For nodes that contain other nodes (Document, Element)
0120    you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves
0121    are simple called with Visit().
0122 
0123    If you return 'true' from a Visit method, recursive parsing will continue. If you return
0124    false, <b>no children of this node or its sibilings</b> will be Visited.
0125 
0126    All flavors of Visit methods have a default implementation that returns 'true' (continue
0127    visiting). You need to only override methods that are interesting to you.
0128 
0129    Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting.
0130 
0131    You should never change the document from a callback.
0132 
0133    @sa TiXmlNode::Accept()
0134 */
0135 class TiXmlVisitor {
0136 public:
0137   virtual ~TiXmlVisitor() {
0138   }
0139 
0140   /// Visit a document.
0141   virtual bool VisitEnter(const TiXmlDocument& /* doc */) {
0142     return true;
0143   }
0144   /// Visit a document.
0145   virtual bool VisitExit(const TiXmlDocument& /* doc */) {
0146     return true;
0147   }
0148 
0149   /// Visit an element.
0150   virtual bool VisitEnter(const TiXmlElement& /* element */, const TiXmlAttribute* /* firstAttribute */) {
0151     return true;
0152   }
0153   /// Visit an element.
0154   virtual bool VisitExit(const TiXmlElement& /* element */) {
0155     return true;
0156   }
0157 
0158   /// Visit a declaration
0159   virtual bool Visit(const TiXmlDeclaration& /* declaration */) {
0160     return true;
0161   }
0162   /// Visit a text node
0163   virtual bool Visit(const TiXmlText& /* text */) {
0164     return true;
0165   }
0166   /// Visit a comment node
0167   virtual bool Visit(const TiXmlComment& /* comment */) {
0168     return true;
0169   }
0170   /// Visit an unknow node
0171   virtual bool Visit(const TiXmlUnknown& /* unknown */) {
0172     return true;
0173   }
0174 };
0175 
0176 // Only used by Attribute::Query functions
0177 enum {
0178   TIXML_SUCCESS, TIXML_NO_ATTRIBUTE, TIXML_WRONG_TYPE
0179 };
0180 
0181 // Used by the parsing routines.
0182 enum TiXmlEncoding {
0183   TIXML_ENCODING_UNKNOWN, TIXML_ENCODING_UTF8, TIXML_ENCODING_LEGACY
0184 };
0185 
0186 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
0187 
0188 /** TiXmlBase is a base class for every class in TinyXml.
0189     It does little except to establish that TinyXml classes
0190     can be printed and provide some utility functions.
0191 
0192     In XML, the document and elements can contain
0193     other elements and other types of nodes.
0194 
0195     @verbatim
0196     A Document can contain:     Element (container or leaf)
0197     Comment (leaf)
0198     Unknown (leaf)
0199     Declaration( leaf )
0200 
0201     An Element can contain:     Element (container or leaf)
0202     Text        (leaf)
0203     Attributes (not on tree)
0204     Comment (leaf)
0205     Unknown (leaf)
0206 
0207     A Decleration contains: Attributes (not on tree)
0208     @endverbatim
0209 */
0210 class TiXmlBase {
0211   friend class TiXmlNode;
0212   friend class TiXmlElement;
0213   friend class TiXmlDocument;
0214 
0215 public:
0216   TiXmlBase()
0217     : userData(0) {
0218   }
0219   virtual ~TiXmlBase() {
0220   }
0221 
0222   /**   All TinyXml classes can print themselves to a filestream
0223         or the string class (TiXmlString in non-STL mode, std::string
0224         in STL mode.) Either or both cfile and str can be null.
0225 
0226         This is a formatted print, and will insert
0227         tabs and newlines.
0228 
0229         (For an unformatted stream, use the << operator.)
0230   */
0231   virtual void Print(FILE* cfile, int depth) const = 0;
0232 
0233   /**   The world does not agree on whether white space should be kept or
0234         not. In order to make everyone happy, these global, static functions
0235         are provided to set whether or not TinyXml will condense all white space
0236         into a single space or not. The default is to condense. Note changing this
0237         value is not thread safe.
0238   */
0239   static void SetCondenseWhiteSpace(bool condense) {
0240     condenseWhiteSpace = condense;
0241   }
0242 
0243   /// Return the current white space setting.
0244   static bool IsWhiteSpaceCondensed() {
0245     return condenseWhiteSpace;
0246   }
0247 
0248   /** Return the position, in the original source file, of this node or attribute.
0249       The row and column are 1-based. (That is the first row and first column is
0250       1,1). If the returns values are 0 or less, then the parser does not have
0251       a row and column value.
0252 
0253       Generally, the row and column value will be set when the TiXmlDocument::Load(),
0254       TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set
0255       when the DOM was created from operator>>.
0256 
0257       The values reflect the initial load. Once the DOM is modified programmatically
0258       (by adding or changing nodes and attributes) the new values will NOT update to
0259       reflect changes in the document.
0260 
0261       There is a minor performance cost to computing the row and column. Computation
0262       can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value.
0263 
0264       @sa TiXmlDocument::SetTabSize()
0265   */
0266   int Row() const {
0267     return location.row + 1;
0268   }
0269   int Column() const {
0270     return location.col + 1;
0271   }   ///< See Row()
0272 
0273   void SetUserData(void* user) {
0274     userData = user;
0275   }   ///< Set a pointer to arbitrary user data.
0276   void* GetUserData() {
0277     return userData;
0278   }   ///< Get a pointer to arbitrary user data.
0279   const void* GetUserData() const {
0280     return userData;
0281   }   ///< Get a pointer to arbitrary user data.
0282 
0283   // Table that returs, for a given lead byte, the total number of bytes
0284   // in the UTF-8 sequence.
0285   static const int utf8ByteTable[256];
0286 
0287   virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */) = 0;
0288 
0289   enum {
0290     TIXML_NO_ERROR = 0,
0291     TIXML_ERROR,
0292     TIXML_ERROR_OPENING_FILE,
0293     TIXML_ERROR_OUT_OF_MEMORY,
0294     TIXML_ERROR_PARSING_ELEMENT,
0295     TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
0296     TIXML_ERROR_READING_ELEMENT_VALUE,
0297     TIXML_ERROR_READING_ATTRIBUTES,
0298     TIXML_ERROR_PARSING_EMPTY,
0299     TIXML_ERROR_READING_END_TAG,
0300     TIXML_ERROR_PARSING_UNKNOWN,
0301     TIXML_ERROR_PARSING_COMMENT,
0302     TIXML_ERROR_PARSING_DECLARATION,
0303     TIXML_ERROR_DOCUMENT_EMPTY,
0304     TIXML_ERROR_EMBEDDED_NULL,
0305     TIXML_ERROR_PARSING_CDATA,
0306     TIXML_ERROR_DOCUMENT_TOP_ONLY,
0307 
0308     TIXML_ERROR_STRING_COUNT
0309   };
0310 
0311 protected:
0312 
0313   static const char* SkipWhiteSpace(const char*, TiXmlEncoding encoding);
0314   inline static bool IsWhiteSpace(char c) {
0315     return (isspace((unsigned char) c) || c == '\n' || c == '\r');
0316   }
0317   inline static bool IsWhiteSpace(int c) {
0318     if (c < 256)
0319       return IsWhiteSpace((char) c);
0320     return false;   // Again, only truly correct for English/Latin...but usually works.
0321   }
0322 
0323 #ifdef TIXML_USE_STL
0324   static bool StreamWhiteSpace(std::istream * in, TIXML_STRING * tag);
0325   static bool StreamTo(std::istream * in, int character, TIXML_STRING * tag);
0326 #endif
0327 
0328   /*    Reads an XML name into the string provided. Returns
0329         a pointer just past the last character of the name,
0330         or 0 if the function has an error.
0331   */
0332   static const char* ReadName(const char* p, TIXML_STRING* name, TiXmlEncoding encoding);
0333 
0334   /*    Reads text. Returns a pointer past the given end tag.
0335         Wickedly complex options, but it keeps the (sensitive) code in one place.
0336   */
0337   static const char* ReadText(const char* in,                           // where to start
0338                               TIXML_STRING* text,                       // the string read
0339                               bool ignoreWhiteSpace,            // whether to keep the white space
0340                               const char* endTag,                       // what ends this text
0341                               bool ignoreCase,                  // whether to ignore case in the end tag
0342                               TiXmlEncoding encoding);   // the current encoding
0343 
0344   // If an entity has been found, transform it into a character.
0345   static const char* GetEntity(const char* in, char* value, int* length, TiXmlEncoding encoding);
0346 
0347   // Get a character, while interpreting entities.
0348   // The length can be from 0 to 4 bytes.
0349   inline static const char* GetChar(const char* p, char* _value, int* length, TiXmlEncoding encoding) {
0350     assert( p);
0351     if (encoding == TIXML_ENCODING_UTF8) {
0352       *length = utf8ByteTable[*((const unsigned char*) p)];
0353       assert( *length >= 0 && *length < 5);
0354     }
0355     else {
0356       *length = 1;
0357     }
0358 
0359     if (*length == 1) {
0360       if (*p == '&')
0361         return GetEntity(p, _value, length, encoding);
0362       *_value = *p;
0363       return p + 1;
0364     }
0365     else if (*length) {
0366       //strncpy( _value, p, *length );  // lots of compilers don't like this function (unsafe),
0367       // and the null terminator isn't needed
0368       for (int i = 0; p[i] && i < *length; ++i) {
0369         _value[i] = p[i];
0370       }
0371       return p + (*length);
0372     }
0373     else {
0374       // Not valid text.
0375       return 0;
0376     }
0377   }
0378 
0379   // Puts a string to a stream, expanding entities as it goes.
0380   // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
0381   static void PutString(const TIXML_STRING& str, TIXML_STRING* out);
0382 
0383   // Return true if the next characters in the stream are any of the endTag sequences.
0384   // Ignore case only works for english, and should only be relied on when comparing
0385   // to English words: StringEqual( p, "version", true ) is fine.
0386   static bool StringEqual(const char* p, const char* endTag, bool ignoreCase, TiXmlEncoding encoding);
0387 
0388   static const char* errorString[TIXML_ERROR_STRING_COUNT];
0389 
0390   TiXmlCursor location;
0391 
0392   /// Field containing a generic user pointer
0393   void* userData;
0394 
0395   // None of these methods are reliable for any language except English.
0396   // Good for approximation, not great for accuracy.
0397   static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding);
0398   static int IsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding);
0399   inline static int ToLower(int v, TiXmlEncoding encoding) {
0400     if (encoding == TIXML_ENCODING_UTF8) {
0401       if (v < 128)
0402         return tolower(v);
0403       return v;
0404     }
0405     else {
0406       return tolower(v);
0407     }
0408   }
0409   static void ConvertUTF32ToUTF8(unsigned long input, char* output, int* length);
0410 
0411 private:
0412   TiXmlBase(const TiXmlBase&);                          // not implemented.
0413   void operator=(const TiXmlBase& base);   // not allowed.
0414 
0415   struct Entity {
0416     const char* str;
0417     unsigned int strLength;
0418     char chr;
0419   };
0420   enum {
0421     NUM_ENTITY = 5, MAX_ENTITY_LENGTH = 6
0422 
0423   };
0424   static Entity entity[NUM_ENTITY];
0425   static bool condenseWhiteSpace;
0426 };
0427 
0428 /** The parent class for everything in the Document Object Model.
0429     (Except for attributes).
0430     Nodes have siblings, a parent, and children. A node can be
0431     in a document, or stand on its own. The type of a TiXmlNode
0432     can be queried, and it can be cast to its more defined type.
0433 */
0434 class TiXmlNode: public TiXmlBase {
0435   friend class TiXmlDocument;
0436   friend class TiXmlElement;
0437 
0438 public:
0439 #ifdef TIXML_USE_STL
0440 
0441   /** An input stream operator, for every class. Tolerant of newlines and
0442       formatting, but doesn't expect them.
0443   */
0444   friend std::istream& operator >>(std::istream& in, TiXmlNode& base);
0445 
0446   /** An output stream operator, for every class. Note that this outputs
0447       without any newlines or formatting, as opposed to Print(), which
0448       includes tabs and new lines.
0449 
0450       The operator<< and operator>> are not completely symmetric. Writing
0451       a node to a stream is very well defined. You'll get a nice stream
0452       of output, without any extra whitespace or newlines.
0453 
0454       But reading is not as well defined. (As it always is.) If you create
0455       a TiXmlElement (for example) and read that from an input stream,
0456       the text needs to define an element or junk will result. This is
0457       true of all input streams, but it's worth keeping in mind.
0458 
0459       A TiXmlDocument will read nodes until it reads a root element, and
0460       all the children of that root element.
0461   */
0462   friend std::ostream& operator<<(std::ostream& out, const TiXmlNode& base);
0463 
0464   /// Appends the XML node or attribute to a std::string.
0465   friend std::string& operator<<(std::string& out, const TiXmlNode& base);
0466 
0467 #endif
0468 
0469   /** The types of XML nodes supported by TinyXml. (All the
0470       unsupported types are picked up by UNKNOWN.)
0471   */
0472   enum NodeType {
0473     DOCUMENT, ELEMENT, COMMENT, UNKNOWN, TEXT, DECLARATION, TYPECOUNT
0474   };
0475 
0476   virtual ~TiXmlNode();
0477 
0478   /** The meaning of 'value' changes for the specific type of
0479       TiXmlNode.
0480       @verbatim
0481       Document: filename of the xml file
0482       Element:  name of the element
0483       Comment:  the comment text
0484       Unknown:  the tag contents
0485       Text:             the text string
0486       @endverbatim
0487 
0488       The subclasses will wrap this function.
0489   */
0490   const char *Value() const {
0491     return value.c_str();
0492   }
0493 
0494 #ifdef TIXML_USE_STL
0495   /** Return Value() as a std::string. If you only use STL,
0496       this is more efficient than calling Value().
0497       Only available in STL mode.
0498   */
0499   const std::string& ValueStr() const {
0500     return value;
0501   }
0502 #endif
0503 
0504   /** Changes the value of the node. Defined as:
0505       @verbatim
0506       Document: filename of the xml file
0507       Element:  name of the element
0508       Comment:  the comment text
0509       Unknown:  the tag contents
0510       Text:             the text string
0511       @endverbatim
0512   */
0513   void SetValue(const char * _value) {
0514     value = _value;
0515   }
0516 
0517 #ifdef TIXML_USE_STL
0518   /// STL std::string form.
0519   void SetValue(const std::string& _value) {
0520     value = _value;
0521   }
0522 #endif
0523 
0524   /// Delete all the children of this node. Does not affect 'this'.
0525   void Clear();
0526 
0527   /// One step up the DOM.
0528   TiXmlNode* Parent() {
0529     return parent;
0530   }
0531   const TiXmlNode* Parent() const {
0532     return parent;
0533   }
0534 
0535   const TiXmlNode* FirstChild() const {
0536     return firstChild;
0537   }             ///< The first child of this node. Will be null if there are no children.
0538   TiXmlNode* FirstChild() {
0539     return firstChild;
0540   }
0541   const TiXmlNode* FirstChild(const char * value) const;        ///< The first child of this node with the matching 'value'. Will be null if none found.
0542   /// The first child of this node with the matching 'value'. Will be null if none found.
0543   TiXmlNode* FirstChild(const char * _value) {
0544     // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe)
0545     // call the method, cast the return back to non-const.
0546     return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->FirstChild(_value));
0547   }
0548   const TiXmlNode* LastChild() const {
0549     return lastChild;
0550   }             /// The last child of this node. Will be null if there are no children.
0551   TiXmlNode* LastChild() {
0552     return lastChild;
0553   }
0554 
0555   const TiXmlNode* LastChild(const char * value) const;         /// The last child of this node matching 'value'. Will be null if there are no children.
0556   TiXmlNode* LastChild(const char * _value) {
0557     return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->LastChild(_value));
0558   }
0559 
0560 #ifdef TIXML_USE_STL
0561   const TiXmlNode* FirstChild(const std::string& _value) const {
0562     return FirstChild(_value.c_str());
0563   }   ///< STL std::string form.
0564   TiXmlNode* FirstChild(const std::string& _value) {
0565     return FirstChild(_value.c_str());
0566   }   ///< STL std::string form.
0567   const TiXmlNode* LastChild(const std::string& _value) const {
0568     return LastChild(_value.c_str());
0569   }   ///< STL std::string form.
0570   TiXmlNode* LastChild(const std::string& _value) {
0571     return LastChild(_value.c_str());
0572   }   ///< STL std::string form.
0573 #endif
0574 
0575   /** An alternate way to walk the children of a node.
0576       One way to iterate over nodes is:
0577       @verbatim
0578       for( child = parent->FirstChild(); child; child = child->NextSibling() )
0579       @endverbatim
0580 
0581       IterateChildren does the same thing with the syntax:
0582       @verbatim
0583       child = 0;
0584       while( child = parent->IterateChildren( child ) )
0585       @endverbatim
0586 
0587       IterateChildren takes the previous child as input and finds
0588       the next one. If the previous child is null, it returns the
0589       first. IterateChildren will return null when done.
0590   */
0591   const TiXmlNode* IterateChildren(const TiXmlNode* previous) const;
0592   TiXmlNode* IterateChildren(const TiXmlNode* previous) {
0593     return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->IterateChildren(previous));
0594   }
0595 
0596   /// This flavor of IterateChildren searches for children with a particular 'value'
0597   const TiXmlNode* IterateChildren(const char * value, const TiXmlNode* previous) const;
0598   TiXmlNode* IterateChildren(const char * _value, const TiXmlNode* previous) {
0599     return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->IterateChildren(_value, previous));
0600   }
0601 
0602 #ifdef TIXML_USE_STL
0603   const TiXmlNode* IterateChildren(const std::string& _value, const TiXmlNode* previous) const {
0604     return IterateChildren(_value.c_str(), previous);
0605   }   ///< STL std::string form.
0606   TiXmlNode* IterateChildren(const std::string& _value, const TiXmlNode* previous) {
0607     return IterateChildren(_value.c_str(), previous);
0608   }   ///< STL std::string form.
0609 #endif
0610 
0611   /** Add a new node related to this. Adds a child past the LastChild.
0612       Returns a pointer to the new object or NULL if an error occured.
0613   */
0614   TiXmlNode* InsertEndChild(const TiXmlNode& addThis);
0615 
0616   /** Add a new node related to this. Adds a child past the LastChild.
0617 
0618       NOTE: the node to be added is passed by pointer, and will be
0619       henceforth owned (and deleted) by tinyXml. This method is efficient
0620       and avoids an extra copy, but should be used with care as it
0621       uses a different memory model than the other insert functions.
0622 
0623       @sa InsertEndChild
0624   */
0625   TiXmlNode* LinkEndChild(TiXmlNode* addThis);
0626 
0627   /** Add a new node related to this. Adds a child before the specified child.
0628       Returns a pointer to the new object or NULL if an error occured.
0629   */
0630   TiXmlNode* InsertBeforeChild(TiXmlNode* beforeThis, const TiXmlNode& addThis);
0631 
0632   /** Add a new node related to this. Adds a child after the specified child.
0633       Returns a pointer to the new object or NULL if an error occured.
0634   */
0635   TiXmlNode* InsertAfterChild(TiXmlNode* afterThis, const TiXmlNode& addThis);
0636 
0637   /** Replace a child of this node.
0638       Returns a pointer to the new object or NULL if an error occured.
0639   */
0640   TiXmlNode* ReplaceChild(TiXmlNode* replaceThis, const TiXmlNode& withThis);
0641 
0642   /// Delete a child of this node.
0643   bool RemoveChild(TiXmlNode* removeThis);
0644 
0645   /// Navigate to a sibling node.
0646   const TiXmlNode* PreviousSibling() const {
0647     return prev;
0648   }
0649   TiXmlNode* PreviousSibling() {
0650     return prev;
0651   }
0652 
0653   /// Navigate to a sibling node.
0654   const TiXmlNode* PreviousSibling(const char *) const;
0655   TiXmlNode* PreviousSibling(const char *_prev) {
0656     return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->PreviousSibling(_prev));
0657   }
0658 
0659 #ifdef TIXML_USE_STL
0660   const TiXmlNode* PreviousSibling(const std::string& _value) const {
0661     return PreviousSibling(_value.c_str());
0662   }   ///< STL std::string form.
0663   TiXmlNode* PreviousSibling(const std::string& _value) {
0664     return PreviousSibling(_value.c_str());
0665   }   ///< STL std::string form.
0666   const TiXmlNode* NextSibling(const std::string& _value) const {
0667     return NextSibling(_value.c_str());
0668   }   ///< STL std::string form.
0669   TiXmlNode* NextSibling(const std::string& _value) {
0670     return NextSibling(_value.c_str());
0671   }   ///< STL std::string form.
0672 #endif
0673 
0674   /// Navigate to a sibling node.
0675   const TiXmlNode* NextSibling() const {
0676     return next;
0677   }
0678   TiXmlNode* NextSibling() {
0679     return next;
0680   }
0681 
0682   /// Navigate to a sibling node with the given 'value'.
0683   const TiXmlNode* NextSibling(const char *) const;
0684   TiXmlNode* NextSibling(const char* _next) {
0685     return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->NextSibling(_next));
0686   }
0687 
0688   /** Convenience function to get through elements.
0689       Calls NextSibling and ToElement. Will skip all non-Element
0690       nodes. Returns 0 if there is not another element.
0691   */
0692   const TiXmlElement* NextSiblingElement() const;
0693   TiXmlElement* NextSiblingElement() {
0694     return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->NextSiblingElement());
0695   }
0696 
0697   /** Convenience function to get through elements.
0698       Calls NextSibling and ToElement. Will skip all non-Element
0699       nodes. Returns 0 if there is not another element.
0700   */
0701   const TiXmlElement* NextSiblingElement(const char *) const;
0702   TiXmlElement* NextSiblingElement(const char *_next) {
0703     return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->NextSiblingElement(_next));
0704   }
0705 
0706   /** Convenience function to get through elements.
0707       Calls PreviousSibling and ToElement. Will skip all non-Element
0708       nodes. Returns 0 if there is not another element.
0709   */
0710   const TiXmlElement* PreviousSiblingElement() const;
0711   TiXmlElement* PreviousSiblingElement() {
0712     return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->PreviousSiblingElement());
0713   }
0714 
0715   /** Convenience function to get through elements.
0716       Calls PreviousSibling and ToElement. Will skip all non-Element
0717       nodes. Returns 0 if there is not another element.
0718   */
0719   const TiXmlElement* PreviousSiblingElement(const char *) const;
0720   TiXmlElement* PreviousSiblingElement(const char *_next) {
0721     return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->PreviousSiblingElement(_next));
0722   }
0723 
0724 #ifdef TIXML_USE_STL
0725   const TiXmlElement* NextSiblingElement(const std::string& _value) const {
0726     return NextSiblingElement(_value.c_str());
0727   }   ///< STL std::string form.
0728   TiXmlElement* NextSiblingElement(const std::string& _value) {
0729     return NextSiblingElement(_value.c_str());
0730   }   ///< STL std::string form.
0731 #endif
0732 
0733   /// Convenience function to get through elements.
0734   const TiXmlElement* FirstChildElement() const;
0735   TiXmlElement* FirstChildElement() {
0736     return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->FirstChildElement());
0737   }
0738 
0739   /// Convenience function to get through elements.
0740   const TiXmlElement* FirstChildElement(const char * _value) const;
0741   TiXmlElement* FirstChildElement(const char * _value) {
0742     return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->FirstChildElement(_value));
0743   }
0744 
0745 #ifdef TIXML_USE_STL
0746   const TiXmlElement* FirstChildElement(const std::string& _value) const {
0747     return FirstChildElement(_value.c_str());
0748   }   ///< STL std::string form.
0749   TiXmlElement* FirstChildElement(const std::string& _value) {
0750     return FirstChildElement(_value.c_str());
0751   }   ///< STL std::string form.
0752 #endif
0753 
0754   /** Query the type (as an enumerated value, above) of this node.
0755       The possible types are: DOCUMENT, ELEMENT, COMMENT,
0756       UNKNOWN, TEXT, and DECLARATION.
0757   */
0758   int Type() const {
0759     return type;
0760   }
0761 
0762   /** Return a pointer to the Document this node lives in.
0763       Returns null if not in a document.
0764   */
0765   const TiXmlDocument* GetDocument() const;
0766   TiXmlDocument* GetDocument() {
0767     return const_cast<TiXmlDocument*>((const_cast<const TiXmlNode*>(this))->GetDocument());
0768   }
0769 
0770   /// Returns true if this node has no children.
0771   bool NoChildren() const {
0772     return !firstChild;
0773   }
0774 
0775   virtual const TiXmlDocument* ToDocument() const {
0776     return 0;
0777   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0778   virtual const TiXmlElement* ToElement() const {
0779     return 0;
0780   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0781   virtual const TiXmlComment* ToComment() const {
0782     return 0;
0783   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0784   virtual const TiXmlUnknown* ToUnknown() const {
0785     return 0;
0786   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0787   virtual const TiXmlText* ToText() const {
0788     return 0;
0789   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0790   virtual const TiXmlDeclaration* ToDeclaration() const {
0791     return 0;
0792   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0793 
0794   virtual TiXmlDocument* ToDocument() {
0795     return 0;
0796   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0797   virtual TiXmlElement* ToElement() {
0798     return 0;
0799   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0800   virtual TiXmlComment* ToComment() {
0801     return 0;
0802   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0803   virtual TiXmlUnknown* ToUnknown() {
0804     return 0;
0805   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0806   virtual TiXmlText* ToText() {
0807     return 0;
0808   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0809   virtual TiXmlDeclaration* ToDeclaration() {
0810     return 0;
0811   }   ///< Cast to a more defined type. Will return null if not of the requested type.
0812 
0813   /** Create an exact duplicate of this node and return it. The memory must be deleted
0814       by the caller.
0815   */
0816   virtual TiXmlNode* Clone() const = 0;
0817 
0818   /** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the
0819       XML tree will be conditionally visited and the host will be called back
0820       via the TiXmlVisitor interface.
0821 
0822       This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse
0823       the XML for the callbacks, so the performance of TinyXML is unchanged by using this
0824       interface versus any other.)
0825 
0826       The interface has been based on ideas from:
0827 
0828       - http://www.saxproject.org/
0829       - http://c2.com/cgi/wiki?HierarchicalVisitorPattern
0830 
0831       Which are both good references for "visiting".
0832 
0833       An example of using Accept():
0834       @verbatim
0835       TiXmlPrinter printer;
0836       tinyxmlDoc.Accept( &printer );
0837       const char* xmlcstr = printer.CStr();
0838       @endverbatim
0839   */
0840   virtual bool Accept(TiXmlVisitor* visitor) const = 0;
0841 
0842 protected:
0843   TiXmlNode(NodeType _type);
0844 
0845   // Copy to the allocated object. Shared functionality between Clone, Copy constructor,
0846   // and the assignment operator.
0847   void CopyTo(TiXmlNode* target) const;
0848 
0849 #ifdef TIXML_USE_STL
0850   // The real work of the input operator.
0851   virtual void StreamIn(std::istream* in, TIXML_STRING* tag) = 0;
0852 #endif
0853 
0854   // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
0855   TiXmlNode* Identify(const char* start, TiXmlEncoding encoding);
0856 
0857   TiXmlNode* parent;
0858   NodeType type;
0859 
0860   TiXmlNode* firstChild;
0861   TiXmlNode* lastChild;
0862 
0863   TIXML_STRING value;
0864 
0865   TiXmlNode* prev;
0866   TiXmlNode* next;
0867 
0868 private:
0869   TiXmlNode(const TiXmlNode&);                          // not implemented.
0870   void operator=(const TiXmlNode& base);   // not allowed.
0871 };
0872 
0873 /** An attribute is a name-value pair. Elements have an arbitrary
0874     number of attributes, each with a unique name.
0875 
0876     @note The attributes are not TiXmlNodes, since they are not
0877     part of the tinyXML document object model. There are other
0878     suggested ways to look at this problem.
0879 */
0880 class TiXmlAttribute: public TiXmlBase {
0881   friend class TiXmlAttributeSet;
0882 
0883 public:
0884   /// Construct an empty attribute.
0885   TiXmlAttribute()
0886     : TiXmlBase() {
0887     document = 0;
0888     prev = next = 0;
0889   }
0890 
0891 #ifdef TIXML_USE_STL
0892   /// std::string constructor.
0893   TiXmlAttribute(const std::string& _name, const std::string& _value) {
0894     name = _name;
0895     value = _value;
0896     document = 0;
0897     prev = next = 0;
0898   }
0899 #endif
0900 
0901   /// Construct an attribute with a name and value.
0902   TiXmlAttribute(const char * _name, const char * _value) {
0903     name = _name;
0904     value = _value;
0905     document = 0;
0906     prev = next = 0;
0907   }
0908 
0909   const char* Name() const {
0910     return name.c_str();
0911   }             ///< Return the name of this attribute.
0912   const char* Value() const {
0913     return value.c_str();
0914   }             ///< Return the value of this attribute.
0915 #ifdef TIXML_USE_STL
0916   const std::string& ValueStr() const {
0917     return value;
0918   }                             ///< Return the value of this attribute.
0919 #endif
0920   int IntValue() const;                                                                 ///< Return the value of this attribute, converted to an integer.
0921   double DoubleValue() const;                                                           ///< Return the value of this attribute, converted to a double.
0922 
0923   // Get the tinyxml string representation
0924   const TIXML_STRING& NameTStr() const {
0925     return name;
0926   }
0927 
0928   /** QueryIntValue examines the value string. It is an alternative to the
0929       IntValue() method with richer error checking.
0930       If the value is an integer, it is stored in 'value' and
0931       the call returns TIXML_SUCCESS. If it is not
0932       an integer, it returns TIXML_WRONG_TYPE.
0933 
0934       A specialized but useful call. Note that for success it returns 0,
0935       which is the opposite of almost all other TinyXml calls.
0936   */
0937   int QueryIntValue(int* _value) const;
0938   /// QueryDoubleValue examines the value string. See QueryIntValue().
0939   int QueryDoubleValue(double* _value) const;
0940 
0941   void SetName(const char* _name) {
0942     name = _name;
0943   }                             ///< Set the name of this attribute.
0944   void SetValue(const char* _value) {
0945     value = _value;
0946   }                             ///< Set the value.
0947 
0948   void SetIntValue(int _value);                                                                         ///< Set the value from an integer.
0949   void SetDoubleValue(double _value);                                                           ///< Set the value from a double.
0950 
0951 #ifdef TIXML_USE_STL
0952   /// STL std::string form.
0953   void SetName(const std::string& _name) {
0954     name = _name;
0955   }
0956   /// STL std::string form.
0957   void SetValue(const std::string& _value) {
0958     value = _value;
0959   }
0960 #endif
0961 
0962   /// Get the next sibling attribute in the DOM. Returns null at end.
0963   const TiXmlAttribute* Next() const;
0964   TiXmlAttribute* Next() {
0965     return const_cast<TiXmlAttribute*>((const_cast<const TiXmlAttribute*>(this))->Next());
0966   }
0967 
0968   /// Get the previous sibling attribute in the DOM. Returns null at beginning.
0969   const TiXmlAttribute* Previous() const;
0970   TiXmlAttribute* Previous() {
0971     return const_cast<TiXmlAttribute*>((const_cast<const TiXmlAttribute*>(this))->Previous());
0972   }
0973 
0974   bool operator==(const TiXmlAttribute& rhs) const {
0975     return rhs.name == name;
0976   }
0977   bool operator<(const TiXmlAttribute& rhs) const {
0978     return name < rhs.name;
0979   }
0980   bool operator>(const TiXmlAttribute& rhs) const {
0981     return name > rhs.name;
0982   }
0983 
0984   /*    Attribute parsing starts: first letter of the name
0985         returns: the next char after the value end quote
0986   */
0987   virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)  override;
0988 
0989   // Prints this Attribute to a FILE stream.
0990   virtual void Print(FILE* cfile, int depth) const   override  {
0991     Print(cfile, depth, 0);
0992   }
0993   void Print(FILE* cfile, int depth, TIXML_STRING* str) const;
0994 
0995   // [internal use]
0996   // Set the document pointer so the attribute can report errors.
0997   void SetDocument(TiXmlDocument* doc) {
0998     document = doc;
0999   }
1000 
1001 private:
1002   TiXmlAttribute(const TiXmlAttribute&);                                // not implemented.
1003   void operator=(const TiXmlAttribute& base);   // not allowed.
1004 
1005   TiXmlDocument* document;   // A pointer back to a document, for error reporting.
1006   TIXML_STRING name;TIXML_STRING value;
1007   TiXmlAttribute* prev;
1008   TiXmlAttribute* next;
1009 };
1010 
1011 /*      A class used to manage a group of attributes.
1012         It is only used internally, both by the ELEMENT and the DECLARATION.
1013 
1014         The set can be changed transparent to the Element and Declaration
1015         classes that use it, but NOT transparent to the Attribute
1016         which has to implement a next() and previous() method. Which makes
1017         it a bit problematic and prevents the use of STL.
1018 
1019         This version is implemented with circular lists because:
1020         - I like circular lists
1021         - it demonstrates some independence from the (typical) doubly linked list.
1022 */
1023 class TiXmlAttributeSet {
1024 public:
1025   TiXmlAttributeSet();
1026   ~TiXmlAttributeSet();
1027 
1028   void Add(TiXmlAttribute* attribute);
1029   void Remove(TiXmlAttribute* attribute);
1030 
1031   const TiXmlAttribute* First() const {
1032     return (sentinel.next == &sentinel) ? 0 : sentinel.next;
1033   }
1034   TiXmlAttribute* First() {
1035     return (sentinel.next == &sentinel) ? 0 : sentinel.next;
1036   }
1037   const TiXmlAttribute* Last() const {
1038     return (sentinel.prev == &sentinel) ? 0 : sentinel.prev;
1039   }
1040   TiXmlAttribute* Last() {
1041     return (sentinel.prev == &sentinel) ? 0 : sentinel.prev;
1042   }
1043 
1044   const TiXmlAttribute* Find(const char* _name) const;
1045   TiXmlAttribute* Find(const char* _name) {
1046     return const_cast<TiXmlAttribute*>((const_cast<const TiXmlAttributeSet*>(this))->Find(_name));
1047   }
1048 #ifdef TIXML_USE_STL
1049   const TiXmlAttribute* Find(const std::string& _name) const;
1050   TiXmlAttribute* Find(const std::string& _name) {
1051     return const_cast<TiXmlAttribute*>((const_cast<const TiXmlAttributeSet*>(this))->Find(_name));
1052   }
1053 
1054 #endif
1055 
1056 private:
1057   //*ME:        Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),
1058   //*ME:        this class must be also use a hidden/disabled copy-constructor !!!
1059   TiXmlAttributeSet(const TiXmlAttributeSet&);   // not allowed
1060   void operator=(const TiXmlAttributeSet&);   // not allowed (as TiXmlAttribute)
1061 
1062   TiXmlAttribute sentinel;
1063 };
1064 
1065 /** The element is a container class. It has a value, the element name,
1066     and can contain other elements, text, comments, and unknowns.
1067     Elements also contain an arbitrary number of attributes.
1068 */
1069 class TiXmlElement: public TiXmlNode {
1070 public:
1071   /// Construct an element.
1072   TiXmlElement(const char * in_value);
1073 
1074 #ifdef TIXML_USE_STL
1075   /// std::string constructor.
1076   TiXmlElement(const std::string& _value);
1077 #endif
1078 
1079   TiXmlElement(const TiXmlElement&);
1080 
1081   void operator=(const TiXmlElement& base);
1082 
1083   virtual ~TiXmlElement();
1084 
1085   /** Given an attribute name, Attribute() returns the attribute
1086       with that name, or null if none exists.
1087   */
1088   const TiXmlAttribute* AttributeNode(const char* name) const {
1089     return attributeSet.Find(name);
1090   }
1091 
1092   /** Given an attribute name, Attribute() returns the attribute value
1093       with that name, or null if none exists.
1094   */
1095   const char* Attribute(const char* name) const;
1096 
1097   /** Clear all attribute nodes of this node.
1098    */
1099   void ClearAttributes();
1100 
1101   /** Given an attribute name, Attribute() returns the value
1102       for the attribute of that name, or null if none exists.
1103       If the attribute exists and can be converted to an integer,
1104       the integer value will be put in the return 'i', if 'i'
1105       is non-null.
1106   */
1107   const char* Attribute(const char* name, int* i) const;
1108 
1109   /** Given an attribute name, Attribute() returns the value
1110       for the attribute of that name, or null if none exists.
1111       If the attribute exists and can be converted to an double,
1112       the double value will be put in the return 'd', if 'd'
1113       is non-null.
1114   */
1115   const char* Attribute(const char* name, double* d) const;
1116 
1117   /** QueryIntAttribute examines the attribute - it is an alternative to the
1118       Attribute() method with richer error checking.
1119       If the attribute is an integer, it is stored in 'value' and
1120       the call returns TIXML_SUCCESS. If it is not
1121       an integer, it returns TIXML_WRONG_TYPE. If the attribute
1122       does not exist, then TIXML_NO_ATTRIBUTE is returned.
1123   */
1124   int QueryIntAttribute(const char* name, int* _value) const;
1125   /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
1126   int QueryDoubleAttribute(const char* name, double* _value) const;
1127   /// QueryFloatAttribute examines the attribute - see QueryIntAttribute().
1128   int QueryFloatAttribute(const char* name, float* _value) const {
1129     double d;
1130     int result = QueryDoubleAttribute(name, &d);
1131     if (result == TIXML_SUCCESS) {
1132       *_value = (float) d;
1133     }
1134     return result;
1135   }
1136 #ifdef TIXML_USE_STL
1137   /** Template form of the attribute query which will try to read the
1138       attribute into the specified type. Very easy, very powerful, but
1139       be careful to make sure to call this with the correct type.
1140 
1141       @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE
1142   */
1143   template <typename T> int QueryValueAttribute(const std::string& name, T* outValue) const {
1144     const TiXmlAttribute* node = attributeSet.Find(name);
1145     if (!node)
1146       return TIXML_NO_ATTRIBUTE;
1147 
1148     std::stringstream sstream(node->ValueStr());
1149     sstream >> *outValue;
1150     if (!sstream.fail())
1151       return TIXML_SUCCESS;
1152     return TIXML_WRONG_TYPE;
1153   }
1154 #endif
1155 
1156   /** Sets an attribute of name to a given value. The attribute
1157       will be created if it does not exist, or changed if it does.
1158   */
1159   void SetAttribute(const char* name, const char * _value);
1160 
1161 #ifdef TIXML_USE_STL
1162   const std::string* Attribute(const std::string& name) const;
1163   const std::string* Attribute(const std::string& name, int* i) const;
1164   const std::string* Attribute(const std::string& name, double* d) const;
1165   int QueryIntAttribute(const std::string& name, int* _value) const;
1166   int QueryDoubleAttribute(const std::string& name, double* _value) const;
1167 
1168   /// STL std::string form.
1169   void SetAttribute(const std::string& name, const std::string& _value);
1170   ///< STL std::string form.
1171   void SetAttribute(const std::string& name, int _value);
1172 #endif
1173 
1174   /** Sets an attribute of name to a given value. The attribute
1175       will be created if it does not exist, or changed if it does.
1176   */
1177   void SetAttribute(const char * name, int value);
1178 
1179   /** Sets an attribute of name to a given value. The attribute
1180       will be created if it does not exist, or changed if it does.
1181   */
1182   void SetDoubleAttribute(const char * name, double value);
1183 
1184   /** Deletes an attribute with the given name.
1185    */
1186   void RemoveAttribute(const char * name);
1187 #ifdef TIXML_USE_STL
1188   void RemoveAttribute(const std::string& name) {
1189     RemoveAttribute(name.c_str());
1190   }   ///< STL std::string form.
1191 #endif
1192 
1193   const TiXmlAttribute* FirstAttribute() const {
1194     return attributeSet.First();
1195   }             ///< Access the first attribute in this element.
1196   TiXmlAttribute* FirstAttribute() {
1197     return attributeSet.First();
1198   }
1199   const TiXmlAttribute* LastAttribute() const {
1200     return attributeSet.Last();
1201   }             ///< Access the last attribute in this element.
1202   TiXmlAttribute* LastAttribute() {
1203     return attributeSet.Last();
1204   }
1205 
1206   /** Convenience function for easy access to the text inside an element. Although easy
1207       and concise, GetText() is limited compared to getting the TiXmlText child
1208       and accessing it directly.
1209 
1210       If the first child of 'this' is a TiXmlText, the GetText()
1211       returns the character string of the Text node, else null is returned.
1212 
1213       This is a convenient method for getting the text of simple contained text:
1214       @verbatim
1215       <foo>This is text</foo>
1216       const char* str = fooElement->GetText();
1217       @endverbatim
1218 
1219       'str' will be a pointer to "This is text".
1220 
1221       Note that this function can be misleading. If the element foo was created from
1222       this XML:
1223       @verbatim
1224       <foo><b>This is text</b></foo>
1225       @endverbatim
1226 
1227       then the value of str would be null. The first child node isn't a text node, it is
1228       another element. From this XML:
1229       @verbatim
1230       <foo>This is <b>text</b></foo>
1231       @endverbatim
1232       GetText() will return "This is ".
1233 
1234       WARNING: GetText() accesses a child node - don't become confused with the
1235       similarly named TiXmlHandle_t::Text() and TiXmlNode::ToText() which are
1236       safe type casts on the referenced node.
1237   */
1238   const char* GetText() const;
1239 
1240   /// Creates a new Element and returns it - the returned element is a copy.
1241   virtual TiXmlNode* Clone() const override;
1242   // Print the Element to a FILE stream.
1243   virtual void Print(FILE* cfile, int depth) const override;
1244 
1245   /*    Attribtue parsing starts: next char past '<'
1246         returns: next char past '>'
1247   */
1248   virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding) override;
1249 
1250   virtual const TiXmlElement* ToElement() const override {
1251     return this;
1252   }   ///< Cast to a more defined type. Will return null not of the requested type.
1253   virtual TiXmlElement* ToElement()  override {
1254     return this;
1255   }   ///< Cast to a more defined type. Will return null not of the requested type.
1256 
1257   /** Walk the XML tree visiting this node and all of its children.
1258    */
1259   virtual bool Accept(TiXmlVisitor* visitor) const  override;
1260 
1261 protected:
1262 
1263   void CopyTo(TiXmlElement* target) const;
1264   void ClearThis();   // like clear, but initializes 'this' object as well
1265 
1266   // Used to be public [internal use]
1267 #ifdef TIXML_USE_STL
1268   virtual void StreamIn(std::istream * in, TIXML_STRING * tag) override;
1269 #endif
1270   /*    [internal use]
1271         Reads the "value" of the element -- another element, or text.
1272         This should terminate with the current end tag.
1273   */
1274   const char* ReadValue(const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding);
1275 
1276 private:
1277 
1278   TiXmlAttributeSet attributeSet;
1279 };
1280 
1281 /**     An XML comment.
1282  */
1283 class TiXmlComment: public TiXmlNode {
1284 public:
1285   /// Constructs an empty comment.
1286   TiXmlComment()
1287     : TiXmlNode(TiXmlNode::COMMENT) {
1288   }
1289   /// Construct a comment from text.
1290   TiXmlComment(const char* _value)
1291     : TiXmlNode(TiXmlNode::COMMENT) {
1292     SetValue(_value);
1293   }
1294   TiXmlComment(const TiXmlComment&);
1295   void operator=(const TiXmlComment& base);
1296 
1297   virtual ~TiXmlComment() {
1298   }
1299 
1300   /// Returns a copy of this Comment.
1301   virtual TiXmlNode* Clone() const   override;
1302   // Write this Comment to a FILE stream.
1303   virtual void Print(FILE* cfile, int depth) const  override;
1304 
1305   /*    Attribtue parsing starts: at the ! of the !--
1306         returns: next char past '>'
1307   */
1308   virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding) override;
1309 
1310   virtual const TiXmlComment* ToComment() const  override  {
1311     return this;
1312   }   ///< Cast to a more defined type. Will return null not of the requested type.
1313   virtual TiXmlComment* ToComment()  override  {
1314     return this;
1315   }   ///< Cast to a more defined type. Will return null not of the requested type.
1316 
1317   /** Walk the XML tree visiting this node and all of its children.
1318    */
1319   virtual bool Accept(TiXmlVisitor* visitor) const override;
1320 
1321 protected:
1322   void CopyTo(TiXmlComment* target) const;
1323 
1324   // used to be public
1325 #ifdef TIXML_USE_STL
1326   virtual void StreamIn(std::istream * in, TIXML_STRING * tag)  override;
1327 #endif
1328   //    virtual void StreamOut( TIXML_OSTREAM * out ) const;
1329 
1330 private:
1331 
1332 };
1333 
1334 /** XML text. A text node can have 2 ways to output the next. "normal" output
1335     and CDATA. It will default to the mode it was parsed from the XML file and
1336     you generally want to leave it alone, but you can change the output mode with
1337     SetCDATA() and query it with CDATA().
1338 */
1339 class TiXmlText: public TiXmlNode {
1340   friend class TiXmlElement;
1341 public:
1342   /** Constructor for text element. By default, it is treated as
1343       normal, encoded text. If you want it be output as a CDATA text
1344       element, set the parameter _cdata to 'true'
1345   */
1346   TiXmlText(const char * initValue)
1347     : TiXmlNode(TiXmlNode::TEXT) {
1348     SetValue(initValue);
1349     cdata = false;
1350   }
1351   virtual ~TiXmlText() {
1352   }
1353 
1354 #ifdef TIXML_USE_STL
1355   /// Constructor.
1356   TiXmlText(const std::string& initValue)
1357     : TiXmlNode(TiXmlNode::TEXT) {
1358     SetValue(initValue);
1359     cdata = false;
1360   }
1361 #endif
1362 
1363   TiXmlText(const TiXmlText& copy)
1364     : TiXmlNode(TiXmlNode::TEXT) {
1365     copy.CopyTo(this);
1366   }
1367   void operator=(const TiXmlText& base) {
1368     base.CopyTo(this);
1369   }
1370 
1371   // Write this text object to a FILE stream.
1372   virtual void Print(FILE* cfile, int depth) const  override;
1373 
1374   /// Queries whether this represents text using a CDATA section.
1375   bool CDATA() const {
1376     return cdata;
1377   }
1378   /// Turns on or off a CDATA representation of text.
1379   void SetCDATA(bool _cdata) {
1380     cdata = _cdata;
1381   }
1382 
1383   virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)  override;
1384 
1385   virtual const TiXmlText* ToText() const  override {
1386     return this;
1387   }   ///< Cast to a more defined type. Will return null not of the requested type.
1388   virtual TiXmlText* ToText()   override  {
1389     return this;
1390   }   ///< Cast to a more defined type. Will return null not of the requested type.
1391 
1392   /** Walk the XML tree visiting this node and all of its children.
1393    */
1394   virtual bool Accept(TiXmlVisitor* content) const  override;
1395 
1396 protected:
1397   ///  [internal use] Creates a new Element and returns it.
1398   virtual TiXmlNode* Clone() const   override;
1399   void CopyTo(TiXmlText* target) const;
1400 
1401   bool Blank() const;   // returns true if all white space and new lines
1402   // [internal use]
1403 #ifdef TIXML_USE_STL
1404   virtual void StreamIn(std::istream * in, TIXML_STRING * tag)  override;
1405 #endif
1406 
1407 private:
1408   bool cdata;                   // true if this should be input and output as a CDATA style text element
1409 };
1410 
1411 /** In correct XML the declaration is the first entry in the file.
1412     @verbatim
1413     <?xml version="1.0" standalone="yes"?>
1414     @endverbatim
1415 
1416     TinyXml will happily read or write files without a declaration,
1417     however. There are 3 possible attributes to the declaration:
1418     version, encoding, and standalone.
1419 
1420     Note: In this version of the code, the attributes are
1421     handled as special cases, not generic attributes, simply
1422     because there can only be at most 3 and they are always the same.
1423 */
1424 class TiXmlDeclaration: public TiXmlNode {
1425 public:
1426   /// Construct an empty declaration.
1427   TiXmlDeclaration()
1428     : TiXmlNode(TiXmlNode::DECLARATION) {
1429   }
1430 
1431 #ifdef TIXML_USE_STL
1432   /// Constructor.
1433   TiXmlDeclaration(const std::string& _version, const std::string& _encoding, const std::string& _standalone);
1434 #endif
1435 
1436   /// Construct.
1437   TiXmlDeclaration(const char* _version, const char* _encoding, const char* _standalone);
1438 
1439   TiXmlDeclaration(const TiXmlDeclaration& copy);
1440   void operator=(const TiXmlDeclaration& copy);
1441 
1442   virtual ~TiXmlDeclaration() {
1443   }
1444 
1445   /// Version. Will return an empty string if none was found.
1446   const char *Version() const {
1447     return version.c_str();
1448   }
1449   /// Encoding. Will return an empty string if none was found.
1450   const char *Encoding() const {
1451     return encoding.c_str();
1452   }
1453   /// Is this a standalone document?
1454   const char *Standalone() const {
1455     return standalone.c_str();
1456   }
1457 
1458   /// Creates a copy of this Declaration and returns it.
1459   virtual TiXmlNode* Clone() const   override;
1460   // Print this declaration to a FILE stream.
1461   virtual void Print(FILE* cfile, int depth, TIXML_STRING* str) const;
1462   virtual void Print(FILE* cfile, int depth) const   override  {
1463     Print(cfile, depth, 0);
1464   }
1465 
1466   virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)  override;
1467 
1468   virtual const TiXmlDeclaration* ToDeclaration() const   override  {
1469     return this;
1470   }   ///< Cast to a more defined type. Will return null not of the requested type.
1471   virtual TiXmlDeclaration* ToDeclaration()  override {
1472     return this;
1473   }   ///< Cast to a more defined type. Will return null not of the requested type.
1474 
1475   /** Walk the XML tree visiting this node and all of its children.
1476    */
1477   virtual bool Accept(TiXmlVisitor* visitor) const  override;
1478 
1479 protected:
1480   void CopyTo(TiXmlDeclaration* target) const;
1481   // used to be public
1482 #ifdef TIXML_USE_STL
1483   virtual void StreamIn(std::istream * in, TIXML_STRING * tag)  override;
1484 #endif
1485 
1486 private:
1487 
1488   TIXML_STRING version;TIXML_STRING encoding;TIXML_STRING standalone;
1489 };
1490 
1491 /** Any tag that tinyXml doesn't recognize is saved as an
1492     unknown. It is a tag of text, but should not be modified.
1493     It will be written back to the XML, unchanged, when the file
1494     is saved.
1495 
1496     DTD tags get thrown into TiXmlUnknowns.
1497 */
1498 class TiXmlUnknown: public TiXmlNode {
1499 public:
1500   TiXmlUnknown()
1501     : TiXmlNode(TiXmlNode::UNKNOWN) {
1502   }
1503   virtual ~TiXmlUnknown() {
1504   }
1505 
1506   TiXmlUnknown(const TiXmlUnknown& copy)
1507     : TiXmlNode(TiXmlNode::UNKNOWN) {
1508     copy.CopyTo(this);
1509   }
1510   void operator=(const TiXmlUnknown& copy) {
1511     copy.CopyTo(this);
1512   }
1513 
1514   /// Creates a copy of this Unknown and returns it.
1515   virtual TiXmlNode* Clone() const   override;
1516   // Print this Unknown to a FILE stream.
1517   virtual void Print(FILE* cfile, int depth) const   override;
1518 
1519   virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)  override;
1520 
1521   virtual const TiXmlUnknown* ToUnknown() const    override  {
1522     return this;
1523   }   ///< Cast to a more defined type. Will return null not of the requested type.
1524   virtual TiXmlUnknown* ToUnknown()    override{
1525     return this;
1526   }   ///< Cast to a more defined type. Will return null not of the requested type.
1527 
1528   /** Walk the XML tree visiting this node and all of its children.
1529    */
1530   virtual bool Accept(TiXmlVisitor* content) const  override;
1531 
1532 protected:
1533   void CopyTo(TiXmlUnknown* target) const;
1534 
1535 #ifdef TIXML_USE_STL
1536   virtual void StreamIn(std::istream * in, TIXML_STRING * tag)  override;
1537 #endif
1538 
1539 private:
1540 
1541 };
1542 
1543 /** Always the top level node. A document binds together all the
1544     XML pieces. It can be saved, loaded, and printed to the screen.
1545     The 'value' of a document node is the xml file name.
1546 */
1547 class TiXmlDocument: public TiXmlNode {
1548 public:
1549   /// Create an empty document, that has no name.
1550   TiXmlDocument();
1551   /// Create a document with a name. The name of the document is also the filename of the xml.
1552   TiXmlDocument(const char * documentName);
1553 
1554 #ifdef TIXML_USE_STL
1555   /// Constructor.
1556   TiXmlDocument(const std::string& documentName);
1557 #endif
1558 
1559   TiXmlDocument(const TiXmlDocument& copy);
1560   void operator=(const TiXmlDocument& copy);
1561 
1562   virtual ~TiXmlDocument() {
1563   }
1564 
1565   /** Load a file using the current document value.
1566       Returns true if successful. Will delete any existing
1567       document data before loading.
1568   */
1569   bool LoadFile(TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
1570   /// Save a file using the current document value. Returns true if successful.
1571   bool SaveFile() const;
1572   /// Load a file using the given filename. Returns true if successful.
1573   bool LoadFile(const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
1574   /// Save a file using the given filename. Returns true if successful.
1575   bool SaveFile(const char * filename) const;
1576   /** Load a file using the given FILE*. Returns true if successful. Note that this method
1577       doesn't stream - the entire object pointed at by the FILE*
1578       will be interpreted as an XML file. TinyXML doesn't stream in XML from the current
1579       file location. Streaming may be added in the future.
1580   */
1581   bool LoadFile(FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
1582   /// Save a file using the given FILE*. Returns true if successful.
1583   bool SaveFile(FILE*) const;
1584 
1585 #ifdef TIXML_USE_STL
1586   bool LoadFile(const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING)                   ///< STL std::string version.
1587   {
1588     //          StringToBuffer f( filename );
1589     //          return ( f.buffer && LoadFile( f.buffer, encoding ));
1590     return LoadFile(filename.c_str(), encoding);
1591   }
1592   bool SaveFile(const std::string& filename) const              ///< STL std::string version.
1593   {
1594     //          StringToBuffer f( filename );
1595     //          return ( f.buffer && SaveFile( f.buffer ));
1596     return SaveFile(filename.c_str());
1597   }
1598 #endif
1599 
1600   /** Parse the given null terminated block of xml data. Passing in an encoding to this
1601       method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml
1602       to use that encoding, regardless of what TinyXml might otherwise try to detect.
1603   */
1604   virtual const char* Parse(const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING)  override;
1605 
1606   /** Get the root element -- the only top level element -- of the document.
1607       In well formed XML, there should only be one. TinyXml is tolerant of
1608       multiple elements at the document level.
1609   */
1610   const TiXmlElement* RootElement() const {
1611     return FirstChildElement();
1612   }
1613   TiXmlElement* RootElement() {
1614     return FirstChildElement();
1615   }
1616 
1617   /** If an error occurs, Error will be set to true. Also,
1618       - The ErrorId() will contain the integer identifier of the error (not generally useful)
1619       - The ErrorDesc() method will return the name of the error. (very useful)
1620       - The ErrorRow() and ErrorCol() will return the location of the error (if known)
1621   */
1622   bool Error() const {
1623     return error;
1624   }
1625 
1626   /// Contains a textual (english) description of the error if one occurs.
1627   const char * ErrorDesc() const {
1628     return errorDesc.c_str();
1629   }
1630 
1631   /** Generally, you probably want the error string ( ErrorDesc() ). But if you
1632       prefer the ErrorId, this function will fetch it.
1633   */
1634   int ErrorId() const {
1635     return errorId;
1636   }
1637 
1638   /** Returns the location (if known) of the error. The first column is column 1,
1639       and the first row is row 1. A value of 0 means the row and column wasn't applicable
1640       (memory errors, for example, have no row/column) or the parser lost the error. (An
1641       error in the error reporting, in that case.)
1642 
1643       @sa SetTabSize, Row, Column
1644   */
1645   int ErrorRow() const {
1646     return errorLocation.row + 1;
1647   }
1648   int ErrorCol() const {
1649     return errorLocation.col + 1;
1650   }   ///< The column where the error occured. See ErrorRow()
1651 
1652   /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol())
1653       to report the correct values for row and column. It does not change the output
1654       or input in any way.
1655 
1656       By calling this method, with a tab size
1657       greater than 0, the row and column of each node and attribute is stored
1658       when the file is loaded. Very useful for tracking the DOM back in to
1659       the source file.
1660 
1661       The tab size is required for calculating the location of nodes. If not
1662       set, the default of 4 is used. The tabsize is set per document. Setting
1663       the tabsize to 0 disables row/column tracking.
1664 
1665       Note that row and column tracking is not supported when using operator>>.
1666 
1667       The tab size needs to be enabled before the parse or load. Correct usage:
1668       @verbatim
1669       TiXmlDocument doc;
1670       doc.SetTabSize( 8 );
1671       doc.Load( "myfile.xml" );
1672       @endverbatim
1673 
1674       @sa Row, Column
1675   */
1676   void SetTabSize(int _tabsize) {
1677     tabsize = _tabsize;
1678   }
1679 
1680   int TabSize() const {
1681     return tabsize;
1682   }
1683 
1684   /** If you have handled the error, it can be reset with this call. The error
1685       state is automatically cleared if you Parse a new XML block.
1686   */
1687   void ClearError() {
1688     error = false;
1689     errorId = 0;
1690     errorDesc = "";
1691     errorLocation.row = errorLocation.col = 0;
1692     //errorLocation.last = 0;
1693   }
1694 
1695   /** Write the document to standard out using formatted printing ("pretty print"). */
1696   void Print() const    {
1697     Print(stdout, 0);
1698   }
1699 
1700   /* Write the document to a string using formatted printing ("pretty print"). This
1701      will allocate a character array (new char[]) and return it as a pointer. The
1702      calling code pust call delete[] on the return char* to avoid a memory leak.
1703   */
1704   //char* PrintToMemory() const;
1705   /// Print this Document to a FILE stream.
1706   virtual void Print(FILE* cfile, int depth = 0) const   override;
1707   // [internal use]
1708   void SetError(int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding);
1709 
1710   virtual const TiXmlDocument* ToDocument() const override  {
1711     return this;
1712   }   ///< Cast to a more defined type. Will return null not of the requested type.
1713   virtual TiXmlDocument* ToDocument()   override  {
1714     return this;
1715   }   ///< Cast to a more defined type. Will return null not of the requested type.
1716 
1717   /** Walk the XML tree visiting this node and all of its children.
1718    */
1719   virtual bool Accept(TiXmlVisitor* content) const  override;
1720 
1721 protected:
1722   // [internal use]
1723   virtual TiXmlNode* Clone() const   override;
1724 #ifdef TIXML_USE_STL
1725   virtual void StreamIn(std::istream * in, TIXML_STRING * tag)  override;
1726 #endif
1727 
1728 private:
1729   void CopyTo(TiXmlDocument* target) const;
1730 
1731   bool error;
1732   int errorId;TIXML_STRING errorDesc;
1733   int tabsize;
1734   TiXmlCursor errorLocation;
1735   bool useMicrosoftBOM;         // the UTF-8 BOM were found when read. Note this, and try to write.
1736 };
1737 
1738 /**
1739    A TiXmlHandle_t is a class that wraps a node pointer with null checks; this is
1740    an incredibly useful thing. Note that TiXmlHandle_t is not part of the TinyXml
1741    DOM structure. It is a separate utility class.
1742 
1743    Take an example:
1744    @verbatim
1745    <Document>
1746    <Element attributeA = "valueA">
1747    <Child attributeB = "value1" />
1748    <Child attributeB = "value2" />
1749    </Element>
1750    <Document>
1751    @endverbatim
1752 
1753    Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very
1754    easy to write a *lot* of code that looks like:
1755 
1756    @verbatim
1757    TiXmlElement* root = document.FirstChildElement( "Document" );
1758    if ( root )
1759    {
1760    TiXmlElement* element = root->FirstChildElement( "Element" );
1761    if ( element )
1762    {
1763    TiXmlElement* child = element->FirstChildElement( "Child" );
1764    if ( child )
1765    {
1766    TiXmlElement* child2 = child->NextSiblingElement( "Child" );
1767    if ( child2 )
1768    {
1769    // Finally do something useful.
1770    @endverbatim
1771 
1772    And that doesn't even cover "else" cases. TiXmlHandle_t addresses the verbosity
1773    of such code. A TiXmlHandle_t checks for null  pointers so it is perfectly safe
1774    and correct to use:
1775 
1776    @verbatim
1777    TiXmlHandle_t docHandle_t( &document );
1778    TiXmlElement* child2 = docHandle_t.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement();
1779    if ( child2 )
1780    {
1781    // do something useful
1782    @endverbatim
1783 
1784    Which is MUCH more concise and useful.
1785 
1786    It is also safe to copy handles - internally they are nothing more than node pointers.
1787    @verbatim
1788    TiXmlHandle_t handleCopy = handle;
1789    @endverbatim
1790 
1791    What they should not be used for is iteration:
1792 
1793    @verbatim
1794    int i=0;
1795    while ( true )
1796    {
1797    TiXmlElement* child = docHandle_t.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement();
1798    if ( !child )
1799    break;
1800    // do something
1801    ++i;
1802    }
1803    @endverbatim
1804 
1805    It seems reasonable, but it is in fact two embedded while loops. The Child method is
1806    a linear walk to find the element, so this code would iterate much more than it needs
1807    to. Instead, prefer:
1808 
1809    @verbatim
1810    TiXmlElement* child = docHandle_t.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement();
1811 
1812    for( child; child; child=child->NextSiblingElement() )
1813    {
1814    // do something
1815    }
1816    @endverbatim
1817 */
1818 class TiXmlHandle_t {
1819 public:
1820   /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
1821   TiXmlHandle_t(TiXmlNode* _node) {
1822     this->node = _node;
1823   }
1824   /// Copy constructor
1825   TiXmlHandle_t(const TiXmlHandle_t& ref) {
1826     this->node = ref.node;
1827   }
1828   TiXmlHandle_t operator=(const TiXmlHandle_t& ref) {
1829     this->node = ref.node;
1830     return *this;
1831   }
1832 
1833   /// Return a handle to the first child node.
1834   TiXmlHandle_t FirstChild() const;
1835   /// Return a handle to the first child node with the given name.
1836   TiXmlHandle_t FirstChild(const char * value) const;
1837   /// Return a handle to the first child element.
1838   TiXmlHandle_t FirstChildElement() const;
1839   /// Return a handle to the first child element with the given name.
1840   TiXmlHandle_t FirstChildElement(const char * value) const;
1841 
1842   /** Return a handle to the "index" child with the given name.
1843       The first child is 0, the second 1, etc.
1844   */
1845   TiXmlHandle_t Child(const char* value, int index) const;
1846   /** Return a handle to the "index" child.
1847       The first child is 0, the second 1, etc.
1848   */
1849   TiXmlHandle_t Child(int index) const;
1850   /** Return a handle to the "index" child element with the given name.
1851       The first child element is 0, the second 1, etc. Note that only TiXmlElements
1852       are indexed: other types are not counted.
1853   */
1854   TiXmlHandle_t ChildElement(const char* value, int index) const;
1855   /** Return a handle to the "index" child element.
1856       The first child element is 0, the second 1, etc. Note that only TiXmlElements
1857       are indexed: other types are not counted.
1858   */
1859   TiXmlHandle_t ChildElement(int index) const;
1860 
1861 #ifdef TIXML_USE_STL
1862   TiXmlHandle_t FirstChild(const std::string& _value) const {
1863     return FirstChild(_value.c_str());
1864   }
1865   TiXmlHandle_t FirstChildElement(const std::string& _value) const {
1866     return FirstChildElement(_value.c_str());
1867   }
1868 
1869   TiXmlHandle_t Child(const std::string& _value, int index) const {
1870     return Child(_value.c_str(), index);
1871   }
1872   TiXmlHandle_t ChildElement(const std::string& _value, int index) const {
1873     return ChildElement(_value.c_str(), index);
1874   }
1875 #endif
1876 
1877   /** Return the handle as a TiXmlNode. This may return null.
1878    */
1879   TiXmlNode* ToNode() const {
1880     return node;
1881   }
1882   /** Return the handle as a TiXmlElement. This may return null.
1883    */
1884   TiXmlElement* ToElement() const {
1885     return ((node && node->ToElement()) ? node->ToElement() : 0);
1886   }
1887   /**   Return the handle as a TiXmlText. This may return null.
1888    */
1889   TiXmlText* ToText() const {
1890     return ((node && node->ToText()) ? node->ToText() : 0);
1891   }
1892   /** Return the handle as a TiXmlUnknown. This may return null.
1893    */
1894   TiXmlUnknown* ToUnknown() const {
1895     return ((node && node->ToUnknown()) ? node->ToUnknown() : 0);
1896   }
1897 
1898   /** @deprecated use ToNode.
1899       Return the handle as a TiXmlNode. This may return null.
1900   */
1901   TiXmlNode* Node() const {
1902     return ToNode();
1903   }
1904   /** @deprecated use ToElement.
1905       Return the handle as a TiXmlElement. This may return null.
1906   */
1907   TiXmlElement* Element() const {
1908     return ToElement();
1909   }
1910   /**   @deprecated use ToText()
1911         Return the handle as a TiXmlText. This may return null.
1912   */
1913   TiXmlText* Text() const {
1914     return ToText();
1915   }
1916   /** @deprecated use ToUnknown()
1917       Return the handle as a TiXmlUnknown. This may return null.
1918   */
1919   TiXmlUnknown* Unknown() const {
1920     return ToUnknown();
1921   }
1922 
1923 private:
1924   TiXmlNode* node;
1925 };
1926 
1927 /** Print to memory functionality. The TiXmlPrinter is useful when you need to:
1928 
1929     -# Print to memory (especially in non-STL mode)
1930     -# Control formatting (line endings, etc.)
1931 
1932     When constructed, the TiXmlPrinter is in its default "pretty printing" mode.
1933     Before calling Accept() you can call methods to control the printing
1934     of the XML document. After TiXmlNode::Accept() is called, the printed document can
1935     be accessed via the CStr(), Str(), and Size() methods.
1936 
1937     TiXmlPrinter uses the Visitor API.
1938     @verbatim
1939     TiXmlPrinter printer;
1940     printer.SetIndent( "\t" );
1941 
1942     doc.Accept( &printer );
1943     fprintf( stdout, "%s", printer.CStr() );
1944     @endverbatim
1945 */
1946 class TiXmlPrinter: public TiXmlVisitor {
1947 public:
1948   TiXmlPrinter()
1949     : depth(0), simpleTextPrint(false), buffer(), indent("    "), lineBreak("\n") {
1950   }
1951 
1952   virtual bool VisitEnter(const TiXmlDocument& doc)  override;
1953   virtual bool VisitExit(const TiXmlDocument& doc)  override;
1954 
1955   virtual bool VisitEnter(const TiXmlElement& element, const TiXmlAttribute* firstAttribute)  override;
1956   virtual bool VisitExit(const TiXmlElement& element)  override;
1957 
1958   virtual bool Visit(const TiXmlDeclaration& declaration)  override;
1959   virtual bool Visit(const TiXmlText& text)  override;
1960   virtual bool Visit(const TiXmlComment& comment)  override;
1961   virtual bool Visit(const TiXmlUnknown& unknown)  override;
1962 
1963   /** Set the indent characters for printing. By default 4 spaces
1964       but tab (\t) is also useful, or null/empty string for no indentation.
1965   */
1966   void SetIndent(const char* _indent) {
1967     indent = _indent ? _indent : "";
1968   }
1969   /// Query the indention string.
1970   const char* Indent() {
1971     return indent.c_str();
1972   }
1973   /** Set the line breaking string. By default set to newline (\n).
1974       Some operating systems prefer other characters, or can be
1975       set to the null/empty string for no indenation.
1976   */
1977   void SetLineBreak(const char* _lineBreak) {
1978     lineBreak = _lineBreak ? _lineBreak : "";
1979   }
1980   /// Query the current line breaking string.
1981   const char* LineBreak() {
1982     return lineBreak.c_str();
1983   }
1984 
1985   /** Switch over to "stream printing" which is the most dense formatting without
1986       linebreaks. Common when the XML is needed for network transmission.
1987   */
1988   void SetStreamPrinting() {
1989     indent = "";
1990     lineBreak = "";
1991   }
1992   /// Return the result.
1993   const char* CStr() {
1994     return buffer.c_str();
1995   }
1996   /// Return the length of the result string.
1997   size_t Size() {
1998     return buffer.size();
1999   }
2000 
2001 #ifdef TIXML_USE_STL
2002   /// Return the result.
2003   const std::string& Str() {
2004     return buffer;
2005   }
2006 #endif
2007 
2008 private:
2009   void DoIndent() {
2010     for (int i = 0; i < depth; ++i)
2011       buffer += indent;
2012   }
2013   void DoLineBreak() {
2014     buffer += lineBreak;
2015   }
2016 
2017   int depth;
2018   bool simpleTextPrint;TIXML_STRING buffer;TIXML_STRING indent;TIXML_STRING lineBreak;
2019 };
2020 
2021 #ifdef _MSC_VER
2022 #pragma warning( pop )
2023 #endif
2024 
2025 #endif
2026 
2027 
2028 #endif