]> git.cworth.org Git - vogl/blob - src/voglgen/tinyxml/tinyxml.h
Initial vogl checkin
[vogl] / src / voglgen / tinyxml / tinyxml.h
1 /*\r
2 www.sourceforge.net/projects/tinyxml\r
3 Original code by Lee Thomason (www.grinninglizard.com)\r
4 \r
5 This software is provided 'as-is', without any express or implied\r
6 warranty. In no event will the authors be held liable for any\r
7 damages arising from the use of this software.\r
8 \r
9 Permission is granted to anyone to use this software for any\r
10 purpose, including commercial applications, and to alter it and\r
11 redistribute it freely, subject to the following restrictions:\r
12 \r
13 1. The origin of this software must not be misrepresented; you must\r
14 not claim that you wrote the original software. If you use this\r
15 software in a product, an acknowledgment in the product documentation\r
16 would be appreciated but is not required.\r
17 \r
18 2. Altered source versions must be plainly marked as such, and\r
19 must not be misrepresented as being the original software.\r
20 \r
21 3. This notice may not be removed or altered from any source\r
22 distribution.\r
23 */\r
24 \r
25 #ifndef TINYXML_INCLUDED\r
26 #define TINYXML_INCLUDED\r
27 \r
28 #ifdef _MSC_VER\r
29 #pragma warning(push)\r
30 #pragma warning(disable : 4530)\r
31 #pragma warning(disable : 4786)\r
32 #endif\r
33 \r
34 #include <ctype.h>\r
35 #include <stdio.h>\r
36 #include <stdlib.h>\r
37 #include <string.h>\r
38 #include <assert.h>\r
39 \r
40 // Help out windows:\r
41 #if defined(_DEBUG) && !defined(DEBUG)\r
42 #define DEBUG\r
43 #endif\r
44 \r
45 #ifdef TIXML_USE_STL\r
46 #include <string>\r
47 #include <iostream>\r
48 #include <sstream>\r
49 #define TIXML_STRING std::string\r
50 #else\r
51 #include "tinystr.h"\r
52 #define TIXML_STRING TiXmlString\r
53 #endif\r
54 \r
55 // Deprecated library function hell. Compilers want to use the\r
56 // new safe versions. This probably doesn't fully address the problem,\r
57 // but it gets closer. There are too many compilers for me to fully\r
58 // test. If you get compilation troubles, undefine TIXML_SAFE\r
59 #define TIXML_SAFE\r
60 \r
61 #ifdef TIXML_SAFE\r
62 #if defined(_MSC_VER) && (_MSC_VER >= 1400)\r
63 // Microsoft visual studio, version 2005 and higher.\r
64 #define TIXML_SNPRINTF _snprintf_s\r
65 #define TIXML_SSCANF sscanf_s\r
66 #elif defined(_MSC_VER) && (_MSC_VER >= 1200)\r
67 // Microsoft visual studio, version 6 and higher.\r
68 //#pragma message( "Using _sn* functions." )\r
69 #define TIXML_SNPRINTF _snprintf\r
70 #define TIXML_SSCANF sscanf\r
71 #elif defined(__GNUC__) && (__GNUC__ >= 3)\r
72 // GCC version 3 and higher.s\r
73 //#warning( "Using sn* functions." )\r
74 #define TIXML_SNPRINTF snprintf\r
75 #define TIXML_SSCANF sscanf\r
76 #else\r
77 #define TIXML_SNPRINTF snprintf\r
78 #define TIXML_SSCANF sscanf\r
79 #endif\r
80 #endif\r
81 \r
82 class TiXmlDocument;\r
83 class TiXmlElement;\r
84 class TiXmlComment;\r
85 class TiXmlUnknown;\r
86 class TiXmlAttribute;\r
87 class TiXmlText;\r
88 class TiXmlDeclaration;\r
89 class TiXmlParsingData;\r
90 \r
91 const int TIXML_MAJOR_VERSION = 2;\r
92 const int TIXML_MINOR_VERSION = 6;\r
93 const int TIXML_PATCH_VERSION = 2;\r
94 \r
95 /*      Internal structure for tracking location of items\r
96         in the XML file.\r
97 */\r
98 struct TiXmlCursor\r
99 {\r
100     TiXmlCursor()\r
101     {\r
102         Clear();\r
103     }\r
104     void Clear()\r
105     {\r
106         row = col = -1;\r
107     }\r
108 \r
109     int row; // 0 based.\r
110     int col; // 0 based.\r
111 };\r
112 \r
113 /**\r
114         Implements the interface to the "Visitor pattern" (see the Accept() method.)\r
115         If you call the Accept() method, it requires being passed a TiXmlVisitor\r
116         class to handle callbacks. For nodes that contain other nodes (Document, Element)\r
117         you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves\r
118         are simply called with Visit().\r
119 \r
120         If you return 'true' from a Visit method, recursive parsing will continue. If you return\r
121         false, <b>no children of this node or its sibilings</b> will be Visited.\r
122 \r
123         All flavors of Visit methods have a default implementation that returns 'true' (continue\r
124         visiting). You need to only override methods that are interesting to you.\r
125 \r
126         Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting.\r
127 \r
128         You should never change the document from a callback.\r
129 \r
130         @sa TiXmlNode::Accept()\r
131 */\r
132 class TiXmlVisitor\r
133 {\r
134 public:\r
135     virtual ~TiXmlVisitor()\r
136     {\r
137     }\r
138 \r
139     /// Visit a document.\r
140     virtual bool VisitEnter(const TiXmlDocument & /*doc*/)\r
141     {\r
142         return true;\r
143     }\r
144     /// Visit a document.\r
145     virtual bool VisitExit(const TiXmlDocument & /*doc*/)\r
146     {\r
147         return true;\r
148     }\r
149 \r
150     /// Visit an element.\r
151     virtual bool VisitEnter(const TiXmlElement & /*element*/, const TiXmlAttribute * /*firstAttribute*/)\r
152     {\r
153         return true;\r
154     }\r
155     /// Visit an element.\r
156     virtual bool VisitExit(const TiXmlElement & /*element*/)\r
157     {\r
158         return true;\r
159     }\r
160 \r
161     /// Visit a declaration\r
162     virtual bool Visit(const TiXmlDeclaration & /*declaration*/)\r
163     {\r
164         return true;\r
165     }\r
166     /// Visit a text node\r
167     virtual bool Visit(const TiXmlText & /*text*/)\r
168     {\r
169         return true;\r
170     }\r
171     /// Visit a comment node\r
172     virtual bool Visit(const TiXmlComment & /*comment*/)\r
173     {\r
174         return true;\r
175     }\r
176     /// Visit an unknown node\r
177     virtual bool Visit(const TiXmlUnknown & /*unknown*/)\r
178     {\r
179         return true;\r
180     }\r
181 };\r
182 \r
183 // Only used by Attribute::Query functions\r
184 enum\r
185 {\r
186     TIXML_SUCCESS,\r
187     TIXML_NO_ATTRIBUTE,\r
188     TIXML_WRONG_TYPE\r
189 };\r
190 \r
191 // Used by the parsing routines.\r
192 enum TiXmlEncoding\r
193 {\r
194     TIXML_ENCODING_UNKNOWN,\r
195     TIXML_ENCODING_UTF8,\r
196     TIXML_ENCODING_LEGACY\r
197 };\r
198 \r
199 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;\r
200 \r
201 /** TiXmlBase is a base class for every class in TinyXml.\r
202         It does little except to establish that TinyXml classes\r
203         can be printed and provide some utility functions.\r
204 \r
205         In XML, the document and elements can contain\r
206         other elements and other types of nodes.\r
207 \r
208         @verbatim\r
209         A Document can contain: Element (container or leaf)\r
210                                                         Comment (leaf)\r
211                                                         Unknown (leaf)\r
212                                                         Declaration( leaf )\r
213 \r
214         An Element can contain: Element (container or leaf)\r
215                                                         Text    (leaf)\r
216                                                         Attributes (not on tree)\r
217                                                         Comment (leaf)\r
218                                                         Unknown (leaf)\r
219 \r
220         A Decleration contains: Attributes (not on tree)\r
221         @endverbatim\r
222 */\r
223 class TiXmlBase\r
224 {\r
225     friend class TiXmlNode;\r
226     friend class TiXmlElement;\r
227     friend class TiXmlDocument;\r
228 \r
229 public:\r
230     TiXmlBase()\r
231         : userData(0)\r
232     {\r
233     }\r
234     virtual ~TiXmlBase()\r
235     {\r
236     }\r
237 \r
238     /** All TinyXml classes can print themselves to a filestream\r
239                 or the string class (TiXmlString in non-STL mode, std::string\r
240                 in STL mode.) Either or both cfile and str can be null.\r
241 \r
242                 This is a formatted print, and will insert\r
243                 tabs and newlines.\r
244 \r
245                 (For an unformatted stream, use the << operator.)\r
246         */\r
247     virtual void Print(FILE *cfile, int depth) const = 0;\r
248 \r
249     /** The world does not agree on whether white space should be kept or\r
250                 not. In order to make everyone happy, these global, static functions\r
251                 are provided to set whether or not TinyXml will condense all white space\r
252                 into a single space or not. The default is to condense. Note changing this\r
253                 value is not thread safe.\r
254         */\r
255     static void SetCondenseWhiteSpace(bool condense)\r
256     {\r
257         condenseWhiteSpace = condense;\r
258     }\r
259 \r
260     /// Return the current white space setting.\r
261     static bool IsWhiteSpaceCondensed()\r
262     {\r
263         return condenseWhiteSpace;\r
264     }\r
265 \r
266     /** Return the position, in the original source file, of this node or attribute.\r
267                 The row and column are 1-based. (That is the first row and first column is\r
268                 1,1). If the returns values are 0 or less, then the parser does not have\r
269                 a row and column value.\r
270 \r
271                 Generally, the row and column value will be set when the TiXmlDocument::Load(),\r
272                 TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set\r
273                 when the DOM was created from operator>>.\r
274 \r
275                 The values reflect the initial load. Once the DOM is modified programmatically\r
276                 (by adding or changing nodes and attributes) the new values will NOT update to\r
277                 reflect changes in the document.\r
278 \r
279                 There is a minor performance cost to computing the row and column. Computation\r
280                 can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value.\r
281 \r
282                 @sa TiXmlDocument::SetTabSize()\r
283         */\r
284     int Row() const\r
285     {\r
286         return location.row + 1;\r
287     }\r
288     int Column() const\r
289     {\r
290         return location.col + 1; ///< See Row()\r
291     }\r
292 \r
293     void SetUserData(void *user)\r
294     {\r
295         userData = user; ///< Set a pointer to arbitrary user data.\r
296     }\r
297     void *GetUserData()\r
298     {\r
299         return userData; ///< Get a pointer to arbitrary user data.\r
300     }\r
301     const void *GetUserData() const\r
302     {\r
303         return userData; ///< Get a pointer to arbitrary user data.\r
304     }\r
305 \r
306     // Table that returs, for a given lead byte, the total number of bytes\r
307     // in the UTF-8 sequence.\r
308     static const int utf8ByteTable[256];\r
309 \r
310     virtual const char *Parse(const char *p,\r
311                               TiXmlParsingData *data,\r
312                               TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */) = 0;\r
313 \r
314     /** Expands entities in a string. Note this should not contian the tag's '<', '>', etc,\r
315                 or they will be transformed into entities!\r
316         */\r
317     static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out);\r
318 \r
319     enum\r
320     {\r
321         TIXML_NO_ERROR = 0,\r
322         TIXML_ERROR,\r
323         TIXML_ERROR_OPENING_FILE,\r
324         TIXML_ERROR_PARSING_ELEMENT,\r
325         TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,\r
326         TIXML_ERROR_READING_ELEMENT_VALUE,\r
327         TIXML_ERROR_READING_ATTRIBUTES,\r
328         TIXML_ERROR_PARSING_EMPTY,\r
329         TIXML_ERROR_READING_END_TAG,\r
330         TIXML_ERROR_PARSING_UNKNOWN,\r
331         TIXML_ERROR_PARSING_COMMENT,\r
332         TIXML_ERROR_PARSING_DECLARATION,\r
333         TIXML_ERROR_DOCUMENT_EMPTY,\r
334         TIXML_ERROR_EMBEDDED_NULL,\r
335         TIXML_ERROR_PARSING_CDATA,\r
336         TIXML_ERROR_DOCUMENT_TOP_ONLY,\r
337         TIXML_ERROR_STRING_COUNT\r
338     };\r
339 \r
340 protected:\r
341     static const char *SkipWhiteSpace(const char *, TiXmlEncoding encoding);\r
342 \r
343     inline static bool IsWhiteSpace(char c)\r
344     {\r
345         return (isspace((unsigned char)c) || c == '\n' || c == '\r');\r
346     }\r
347     inline static bool IsWhiteSpace(int c)\r
348     {\r
349         if (c < 256)\r
350             return IsWhiteSpace((char)c);\r
351         return false; // Again, only truly correct for English/Latin...but usually works.\r
352     }\r
353 \r
354 #ifdef TIXML_USE_STL\r
355     static bool StreamWhiteSpace(std::istream *in, TIXML_STRING *tag);\r
356     static bool StreamTo(std::istream *in, int character, TIXML_STRING *tag);\r
357 #endif\r
358 \r
359     /*  Reads an XML name into the string provided. Returns\r
360                 a pointer just past the last character of the name,\r
361                 or 0 if the function has an error.\r
362         */\r
363     static const char *ReadName(const char *p, TIXML_STRING *name, TiXmlEncoding encoding);\r
364 \r
365     /*  Reads text. Returns a pointer past the given end tag.\r
366                 Wickedly complex options, but it keeps the (sensitive) code in one place.\r
367         */\r
368     static const char *ReadText(const char *in,          // where to start\r
369                                 TIXML_STRING *text,      // the string read\r
370                                 bool ignoreWhiteSpace,   // whether to keep the white space\r
371                                 const char *endTag,      // what ends this text\r
372                                 bool ignoreCase,         // whether to ignore case in the end tag\r
373                                 TiXmlEncoding encoding); // the current encoding\r
374 \r
375     // If an entity has been found, transform it into a character.\r
376     static const char *GetEntity(const char *in, char *value, int *length, TiXmlEncoding encoding);\r
377 \r
378     // Get a character, while interpreting entities.\r
379     // The length can be from 0 to 4 bytes.\r
380     inline static const char *GetChar(const char *p, char *_value, int *length, TiXmlEncoding encoding)\r
381     {\r
382         assert(p);\r
383         if (encoding == TIXML_ENCODING_UTF8)\r
384         {\r
385             *length = utf8ByteTable[*((const unsigned char *)p)];\r
386             assert(*length >= 0 && *length < 5);\r
387         }\r
388         else\r
389         {\r
390             *length = 1;\r
391         }\r
392 \r
393         if (*length == 1)\r
394         {\r
395             if (*p == '&')\r
396                 return GetEntity(p, _value, length, encoding);\r
397             *_value = *p;\r
398             return p + 1;\r
399         }\r
400         else if (*length)\r
401         {\r
402             //strncpy( _value, p, *length );    // lots of compilers don't like this function (unsafe),\r
403             // and the null terminator isn't needed\r
404             for (int i = 0; p[i] && i < *length; ++i)\r
405             {\r
406                 _value[i] = p[i];\r
407             }\r
408             return p + (*length);\r
409         }\r
410         else\r
411         {\r
412             // Not valid text.\r
413             return 0;\r
414         }\r
415     }\r
416 \r
417     // Return true if the next characters in the stream are any of the endTag sequences.\r
418     // Ignore case only works for english, and should only be relied on when comparing\r
419     // to English words: StringEqual( p, "version", true ) is fine.\r
420     static bool StringEqual(const char *p,\r
421                             const char *endTag,\r
422                             bool ignoreCase,\r
423                             TiXmlEncoding encoding);\r
424 \r
425     static const char *errorString[TIXML_ERROR_STRING_COUNT];\r
426 \r
427     TiXmlCursor location;\r
428 \r
429     /// Field containing a generic user pointer\r
430     void *userData;\r
431 \r
432     // None of these methods are reliable for any language except English.\r
433     // Good for approximation, not great for accuracy.\r
434     static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding);\r
435     static int IsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding);\r
436     inline static int ToLower(int v, TiXmlEncoding encoding)\r
437     {\r
438         if (encoding == TIXML_ENCODING_UTF8)\r
439         {\r
440             if (v < 128)\r
441                 return tolower(v);\r
442             return v;\r
443         }\r
444         else\r
445         {\r
446             return tolower(v);\r
447         }\r
448     }\r
449     static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length);\r
450 \r
451 private:\r
452     TiXmlBase(const TiXmlBase &);          // not implemented.\r
453     void operator=(const TiXmlBase &base); // not allowed.\r
454 \r
455     struct Entity\r
456     {\r
457         const char *str;\r
458         unsigned int strLength;\r
459         char chr;\r
460     };\r
461     enum\r
462     {\r
463         NUM_ENTITY = 5,\r
464         MAX_ENTITY_LENGTH = 6\r
465     };\r
466     static Entity entity[NUM_ENTITY];\r
467     static bool condenseWhiteSpace;\r
468 };\r
469 \r
470 /** The parent class for everything in the Document Object Model.\r
471         (Except for attributes).\r
472         Nodes have siblings, a parent, and children. A node can be\r
473         in a document, or stand on its own. The type of a TiXmlNode\r
474         can be queried, and it can be cast to its more defined type.\r
475 */\r
476 class TiXmlNode : public TiXmlBase\r
477 {\r
478     friend class TiXmlDocument;\r
479     friend class TiXmlElement;\r
480 \r
481 public:\r
482 #ifdef TIXML_USE_STL\r
483 \r
484     /** An input stream operator, for every class. Tolerant of newlines and\r
485             formatting, but doesn't expect them.\r
486         */\r
487     friend std::istream &operator>>(std::istream &in, TiXmlNode &base);\r
488 \r
489     /** An output stream operator, for every class. Note that this outputs\r
490             without any newlines or formatting, as opposed to Print(), which\r
491             includes tabs and new lines.\r
492 \r
493             The operator<< and operator>> are not completely symmetric. Writing\r
494             a node to a stream is very well defined. You'll get a nice stream\r
495             of output, without any extra whitespace or newlines.\r
496 \r
497             But reading is not as well defined. (As it always is.) If you create\r
498             a TiXmlElement (for example) and read that from an input stream,\r
499             the text needs to define an element or junk will result. This is\r
500             true of all input streams, but it's worth keeping in mind.\r
501 \r
502             A TiXmlDocument will read nodes until it reads a root element, and\r
503                 all the children of that root element.\r
504         */\r
505     friend std::ostream &operator<<(std::ostream &out, const TiXmlNode &base);\r
506 \r
507     /// Appends the XML node or attribute to a std::string.\r
508     friend std::string &operator<<(std::string &out, const TiXmlNode &base);\r
509 \r
510 #endif\r
511 \r
512     /** The types of XML nodes supported by TinyXml. (All the\r
513                         unsupported types are picked up by UNKNOWN.)\r
514         */\r
515     enum NodeType\r
516     {\r
517         TINYXML_DOCUMENT,\r
518         TINYXML_ELEMENT,\r
519         TINYXML_COMMENT,\r
520         TINYXML_UNKNOWN,\r
521         TINYXML_TEXT,\r
522         TINYXML_DECLARATION,\r
523         TINYXML_TYPECOUNT\r
524     };\r
525 \r
526     virtual ~TiXmlNode();\r
527 \r
528     /** The meaning of 'value' changes for the specific type of\r
529                 TiXmlNode.\r
530                 @verbatim\r
531                 Document:       filename of the xml file\r
532                 Element:        name of the element\r
533                 Comment:        the comment text\r
534                 Unknown:        the tag contents\r
535                 Text:           the text string\r
536                 @endverbatim\r
537 \r
538                 The subclasses will wrap this function.\r
539         */\r
540     const char *Value() const\r
541     {\r
542         return value.c_str();\r
543     }\r
544 \r
545 #ifdef TIXML_USE_STL\r
546     /** Return Value() as a std::string. If you only use STL,\r
547             this is more efficient than calling Value().\r
548                 Only available in STL mode.\r
549         */\r
550     const std::string &ValueStr() const\r
551     {\r
552         return value;\r
553     }\r
554 #endif\r
555 \r
556     const TIXML_STRING &ValueTStr() const\r
557     {\r
558         return value;\r
559     }\r
560 \r
561     /** Changes the value of the node. Defined as:\r
562                 @verbatim\r
563                 Document:       filename of the xml file\r
564                 Element:        name of the element\r
565                 Comment:        the comment text\r
566                 Unknown:        the tag contents\r
567                 Text:           the text string\r
568                 @endverbatim\r
569         */\r
570     void SetValue(const char *_value)\r
571     {\r
572         value = _value;\r
573     }\r
574 \r
575 #ifdef TIXML_USE_STL\r
576     /// STL std::string form.\r
577     void SetValue(const std::string &_value)\r
578     {\r
579         value = _value;\r
580     }\r
581 #endif\r
582 \r
583     /// Delete all the children of this node. Does not affect 'this'.\r
584     void Clear();\r
585 \r
586     /// One step up the DOM.\r
587     TiXmlNode *Parent()\r
588     {\r
589         return parent;\r
590     }\r
591     const TiXmlNode *Parent() const\r
592     {\r
593         return parent;\r
594     }\r
595 \r
596     const TiXmlNode *FirstChild() const\r
597     {\r
598         return firstChild; ///< The first child of this node. Will be null if there are no children.\r
599     }\r
600     TiXmlNode *FirstChild()\r
601     {\r
602         return firstChild;\r
603     }\r
604     const TiXmlNode *FirstChild(const char *value) const; ///< The first child of this node with the matching 'value'. Will be null if none found.\r
605     /// The first child of this node with the matching 'value'. Will be null if none found.\r
606     TiXmlNode *FirstChild(const char *_value)\r
607     {\r
608         // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe)\r
609         // call the method, cast the return back to non-const.\r
610         return const_cast<TiXmlNode *>((const_cast<const TiXmlNode *>(this))->FirstChild(_value));\r
611     }\r
612     const TiXmlNode *LastChild() const\r
613     {\r
614         return lastChild; /// The last child of this node. Will be null if there are no children.\r
615     }\r
616     TiXmlNode *LastChild()\r
617     {\r
618         return lastChild;\r
619     }\r
620 \r
621     const TiXmlNode *LastChild(const char *value) const; /// The last child of this node matching 'value'. Will be null if there are no children.\r
622     TiXmlNode *LastChild(const char *_value)\r
623     {\r
624         return const_cast<TiXmlNode *>((const_cast<const TiXmlNode *>(this))->LastChild(_value));\r
625     }\r
626 \r
627 #ifdef TIXML_USE_STL\r
628     const TiXmlNode *FirstChild(const std::string &_value) const\r
629     {\r
630         return FirstChild(_value.c_str()); ///< STL std::string form.\r
631     }\r
632     TiXmlNode *FirstChild(const std::string &_value)\r
633     {\r
634         return FirstChild(_value.c_str()); ///< STL std::string form.\r
635     }\r
636     const TiXmlNode *LastChild(const std::string &_value) const\r
637     {\r
638         return LastChild(_value.c_str()); ///< STL std::string form.\r
639     }\r
640     TiXmlNode *LastChild(const std::string &_value)\r
641     {\r
642         return LastChild(_value.c_str()); ///< STL std::string form.\r
643     }\r
644 #endif\r
645 \r
646     /** An alternate way to walk the children of a node.\r
647                 One way to iterate over nodes is:\r
648                 @verbatim\r
649                         for( child = parent->FirstChild(); child; child = child->NextSibling() )\r
650                 @endverbatim\r
651 \r
652                 IterateChildren does the same thing with the syntax:\r
653                 @verbatim\r
654                         child = 0;\r
655                         while( child = parent->IterateChildren( child ) )\r
656                 @endverbatim\r
657 \r
658                 IterateChildren takes the previous child as input and finds\r
659                 the next one. If the previous child is null, it returns the\r
660                 first. IterateChildren will return null when done.\r
661         */\r
662     const TiXmlNode *IterateChildren(const TiXmlNode *previous) const;\r
663     TiXmlNode *IterateChildren(const TiXmlNode *previous)\r
664     {\r
665         return const_cast<TiXmlNode *>((const_cast<const TiXmlNode *>(this))->IterateChildren(previous));\r
666     }\r
667 \r
668     /// This flavor of IterateChildren searches for children with a particular 'value'\r
669     const TiXmlNode *IterateChildren(const char *value, const TiXmlNode *previous) const;\r
670     TiXmlNode *IterateChildren(const char *_value, const TiXmlNode *previous)\r
671     {\r
672         return const_cast<TiXmlNode *>((const_cast<const TiXmlNode *>(this))->IterateChildren(_value, previous));\r
673     }\r
674 \r
675 #ifdef TIXML_USE_STL\r
676     const TiXmlNode *IterateChildren(const std::string &_value, const TiXmlNode *previous) const\r
677     {\r
678         return IterateChildren(_value.c_str(), previous); ///< STL std::string form.\r
679     }\r
680     TiXmlNode *IterateChildren(const std::string &_value, const TiXmlNode *previous)\r
681     {\r
682         return IterateChildren(_value.c_str(), previous); ///< STL std::string form.\r
683     }\r
684 #endif\r
685 \r
686     /** Add a new node related to this. Adds a child past the LastChild.\r
687                 Returns a pointer to the new object or NULL if an error occured.\r
688         */\r
689     TiXmlNode *InsertEndChild(const TiXmlNode &addThis);\r
690 \r
691     /** Add a new node related to this. Adds a child past the LastChild.\r
692 \r
693                 NOTE: the node to be added is passed by pointer, and will be\r
694                 henceforth owned (and deleted) by tinyXml. This method is efficient\r
695                 and avoids an extra copy, but should be used with care as it\r
696                 uses a different memory model than the other insert functions.\r
697 \r
698                 @sa InsertEndChild\r
699         */\r
700     TiXmlNode *LinkEndChild(TiXmlNode *addThis);\r
701 \r
702     /** Add a new node related to this. Adds a child before the specified child.\r
703                 Returns a pointer to the new object or NULL if an error occured.\r
704         */\r
705     TiXmlNode *InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis);\r
706 \r
707     /** Add a new node related to this. Adds a child after the specified child.\r
708                 Returns a pointer to the new object or NULL if an error occured.\r
709         */\r
710     TiXmlNode *InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis);\r
711 \r
712     /** Replace a child of this node.\r
713                 Returns a pointer to the new object or NULL if an error occured.\r
714         */\r
715     TiXmlNode *ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis);\r
716 \r
717     /// Delete a child of this node.\r
718     bool RemoveChild(TiXmlNode *removeThis);\r
719 \r
720     /// Navigate to a sibling node.\r
721     const TiXmlNode *PreviousSibling() const\r
722     {\r
723         return prev;\r
724     }\r
725     TiXmlNode *PreviousSibling()\r
726     {\r
727         return prev;\r
728     }\r
729 \r
730     /// Navigate to a sibling node.\r
731     const TiXmlNode *PreviousSibling(const char *) const;\r
732     TiXmlNode *PreviousSibling(const char *_prev)\r
733     {\r
734         return const_cast<TiXmlNode *>((const_cast<const TiXmlNode *>(this))->PreviousSibling(_prev));\r
735     }\r
736 \r
737 #ifdef TIXML_USE_STL\r
738     const TiXmlNode *PreviousSibling(const std::string &_value) const\r
739     {\r
740         return PreviousSibling(_value.c_str()); ///< STL std::string form.\r
741     }\r
742     TiXmlNode *PreviousSibling(const std::string &_value)\r
743     {\r
744         return PreviousSibling(_value.c_str()); ///< STL std::string form.\r
745     }\r
746     const TiXmlNode *NextSibling(const std::string &_value) const\r
747     {\r
748         return NextSibling(_value.c_str()); ///< STL std::string form.\r
749     }\r
750     TiXmlNode *NextSibling(const std::string &_value)\r
751     {\r
752         return NextSibling(_value.c_str()); ///< STL std::string form.\r
753     }\r
754 #endif\r
755 \r
756     /// Navigate to a sibling node.\r
757     const TiXmlNode *NextSibling() const\r
758     {\r
759         return next;\r
760     }\r
761     TiXmlNode *NextSibling()\r
762     {\r
763         return next;\r
764     }\r
765 \r
766     /// Navigate to a sibling node with the given 'value'.\r
767     const TiXmlNode *NextSibling(const char *) const;\r
768     TiXmlNode *NextSibling(const char *_next)\r
769     {\r
770         return const_cast<TiXmlNode *>((const_cast<const TiXmlNode *>(this))->NextSibling(_next));\r
771     }\r
772 \r
773     /** Convenience function to get through elements.\r
774                 Calls NextSibling and ToElement. Will skip all non-Element\r
775                 nodes. Returns 0 if there is not another element.\r
776         */\r
777     const TiXmlElement *NextSiblingElement() const;\r
778     TiXmlElement *NextSiblingElement()\r
779     {\r
780         return const_cast<TiXmlElement *>((const_cast<const TiXmlNode *>(this))->NextSiblingElement());\r
781     }\r
782 \r
783     /** Convenience function to get through elements.\r
784                 Calls NextSibling and ToElement. Will skip all non-Element\r
785                 nodes. Returns 0 if there is not another element.\r
786         */\r
787     const TiXmlElement *NextSiblingElement(const char *) const;\r
788     TiXmlElement *NextSiblingElement(const char *_next)\r
789     {\r
790         return const_cast<TiXmlElement *>((const_cast<const TiXmlNode *>(this))->NextSiblingElement(_next));\r
791     }\r
792 \r
793 #ifdef TIXML_USE_STL\r
794     const TiXmlElement *NextSiblingElement(const std::string &_value) const\r
795     {\r
796         return NextSiblingElement(_value.c_str()); ///< STL std::string form.\r
797     }\r
798     TiXmlElement *NextSiblingElement(const std::string &_value)\r
799     {\r
800         return NextSiblingElement(_value.c_str()); ///< STL std::string form.\r
801     }\r
802 #endif\r
803 \r
804     /// Convenience function to get through elements.\r
805     const TiXmlElement *FirstChildElement() const;\r
806     TiXmlElement *FirstChildElement()\r
807     {\r
808         return const_cast<TiXmlElement *>((const_cast<const TiXmlNode *>(this))->FirstChildElement());\r
809     }\r
810 \r
811     /// Convenience function to get through elements.\r
812     const TiXmlElement *FirstChildElement(const char *_value) const;\r
813     TiXmlElement *FirstChildElement(const char *_value)\r
814     {\r
815         return const_cast<TiXmlElement *>((const_cast<const TiXmlNode *>(this))->FirstChildElement(_value));\r
816     }\r
817 \r
818 #ifdef TIXML_USE_STL\r
819     const TiXmlElement *FirstChildElement(const std::string &_value) const\r
820     {\r
821         return FirstChildElement(_value.c_str()); ///< STL std::string form.\r
822     }\r
823     TiXmlElement *FirstChildElement(const std::string &_value)\r
824     {\r
825         return FirstChildElement(_value.c_str()); ///< STL std::string form.\r
826     }\r
827 #endif\r
828 \r
829     /** Query the type (as an enumerated value, above) of this node.\r
830                 The possible types are: TINYXML_DOCUMENT, TINYXML_ELEMENT, TINYXML_COMMENT,\r
831                                                                 TINYXML_UNKNOWN, TINYXML_TEXT, and TINYXML_DECLARATION.\r
832         */\r
833     int Type() const\r
834     {\r
835         return type;\r
836     }\r
837 \r
838     /** Return a pointer to the Document this node lives in.\r
839                 Returns null if not in a document.\r
840         */\r
841     const TiXmlDocument *GetDocument() const;\r
842     TiXmlDocument *GetDocument()\r
843     {\r
844         return const_cast<TiXmlDocument *>((const_cast<const TiXmlNode *>(this))->GetDocument());\r
845     }\r
846 \r
847     /// Returns true if this node has no children.\r
848     bool NoChildren() const\r
849     {\r
850         return !firstChild;\r
851     }\r
852 \r
853     virtual const TiXmlDocument *ToDocument() const\r
854     {\r
855         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
856     }\r
857     virtual const TiXmlElement *ToElement() const\r
858     {\r
859         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
860     }\r
861     virtual const TiXmlComment *ToComment() const\r
862     {\r
863         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
864     }\r
865     virtual const TiXmlUnknown *ToUnknown() const\r
866     {\r
867         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
868     }\r
869     virtual const TiXmlText *ToText() const\r
870     {\r
871         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
872     }\r
873     virtual const TiXmlDeclaration *ToDeclaration() const\r
874     {\r
875         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
876     }\r
877 \r
878     virtual TiXmlDocument *ToDocument()\r
879     {\r
880         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
881     }\r
882     virtual TiXmlElement *ToElement()\r
883     {\r
884         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
885     }\r
886     virtual TiXmlComment *ToComment()\r
887     {\r
888         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
889     }\r
890     virtual TiXmlUnknown *ToUnknown()\r
891     {\r
892         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
893     }\r
894     virtual TiXmlText *ToText()\r
895     {\r
896         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
897     }\r
898     virtual TiXmlDeclaration *ToDeclaration()\r
899     {\r
900         return 0; ///< Cast to a more defined type. Will return null if not of the requested type.\r
901     }\r
902 \r
903     /** Create an exact duplicate of this node and return it. The memory must be deleted\r
904                 by the caller.\r
905         */\r
906     virtual TiXmlNode *Clone() const = 0;\r
907 \r
908     /** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the\r
909                 XML tree will be conditionally visited and the host will be called back\r
910                 via the TiXmlVisitor interface.\r
911 \r
912                 This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse\r
913                 the XML for the callbacks, so the performance of TinyXML is unchanged by using this\r
914                 interface versus any other.)\r
915 \r
916                 The interface has been based on ideas from:\r
917 \r
918                 - http://www.saxproject.org/\r
919                 - http://c2.com/cgi/wiki?HierarchicalVisitorPattern\r
920 \r
921                 Which are both good references for "visiting".\r
922 \r
923                 An example of using Accept():\r
924                 @verbatim\r
925                 TiXmlPrinter printer;\r
926                 tinyxmlDoc.Accept( &printer );\r
927                 const char* xmlcstr = printer.CStr();\r
928                 @endverbatim\r
929         */\r
930     virtual bool Accept(TiXmlVisitor *visitor) const = 0;\r
931 \r
932 protected:\r
933     TiXmlNode(NodeType _type);\r
934 \r
935     // Copy to the allocated object. Shared functionality between Clone, Copy constructor,\r
936     // and the assignment operator.\r
937     void CopyTo(TiXmlNode *target) const;\r
938 \r
939 #ifdef TIXML_USE_STL\r
940     // The real work of the input operator.\r
941     virtual void StreamIn(std::istream *in, TIXML_STRING *tag) = 0;\r
942 #endif\r
943 \r
944     // Figure out what is at *p, and parse it. Returns null if it is not an xml node.\r
945     TiXmlNode *Identify(const char *start, TiXmlEncoding encoding);\r
946 \r
947     TiXmlNode *parent;\r
948     NodeType type;\r
949 \r
950     TiXmlNode *firstChild;\r
951     TiXmlNode *lastChild;\r
952 \r
953     TIXML_STRING value;\r
954 \r
955     TiXmlNode *prev;\r
956     TiXmlNode *next;\r
957 \r
958 private:\r
959     TiXmlNode(const TiXmlNode &);          // not implemented.\r
960     void operator=(const TiXmlNode &base); // not allowed.\r
961 };\r
962 \r
963 /** An attribute is a name-value pair. Elements have an arbitrary\r
964         number of attributes, each with a unique name.\r
965 \r
966         @note The attributes are not TiXmlNodes, since they are not\r
967                   part of the tinyXML document object model. There are other\r
968                   suggested ways to look at this problem.\r
969 */\r
970 class TiXmlAttribute : public TiXmlBase\r
971 {\r
972     friend class TiXmlAttributeSet;\r
973 \r
974 public:\r
975     /// Construct an empty attribute.\r
976     TiXmlAttribute()\r
977         : TiXmlBase()\r
978     {\r
979         document = 0;\r
980         prev = next = 0;\r
981     }\r
982 \r
983 #ifdef TIXML_USE_STL\r
984     /// std::string constructor.\r
985     TiXmlAttribute(const std::string &_name, const std::string &_value)\r
986     {\r
987         name = _name;\r
988         value = _value;\r
989         document = 0;\r
990         prev = next = 0;\r
991     }\r
992 #endif\r
993 \r
994     /// Construct an attribute with a name and value.\r
995     TiXmlAttribute(const char *_name, const char *_value)\r
996     {\r
997         name = _name;\r
998         value = _value;\r
999         document = 0;\r
1000         prev = next = 0;\r
1001     }\r
1002 \r
1003     const char *Name() const\r
1004     {\r
1005         return name.c_str(); ///< Return the name of this attribute.\r
1006     }\r
1007     const char *Value() const\r
1008     {\r
1009         return value.c_str(); ///< Return the value of this attribute.\r
1010     }\r
1011 #ifdef TIXML_USE_STL\r
1012     const std::string &ValueStr() const\r
1013     {\r
1014         return value; ///< Return the value of this attribute.\r
1015     }\r
1016 #endif\r
1017     int IntValue() const;       ///< Return the value of this attribute, converted to an integer.\r
1018     double DoubleValue() const; ///< Return the value of this attribute, converted to a double.\r
1019 \r
1020     // Get the tinyxml string representation\r
1021     const TIXML_STRING &NameTStr() const\r
1022     {\r
1023         return name;\r
1024     }\r
1025 \r
1026     /** QueryIntValue examines the value string. It is an alternative to the\r
1027                 IntValue() method with richer error checking.\r
1028                 If the value is an integer, it is stored in 'value' and\r
1029                 the call returns TIXML_SUCCESS. If it is not\r
1030                 an integer, it returns TIXML_WRONG_TYPE.\r
1031 \r
1032                 A specialized but useful call. Note that for success it returns 0,\r
1033                 which is the opposite of almost all other TinyXml calls.\r
1034         */\r
1035     int QueryIntValue(int *_value) const;\r
1036     /// QueryDoubleValue examines the value string. See QueryIntValue().\r
1037     int QueryDoubleValue(double *_value) const;\r
1038 \r
1039     void SetName(const char *_name)\r
1040     {\r
1041         name = _name; ///< Set the name of this attribute.\r
1042     }\r
1043     void SetValue(const char *_value)\r
1044     {\r
1045         value = _value; ///< Set the value.\r
1046     }\r
1047 \r
1048     void SetIntValue(int _value);       ///< Set the value from an integer.\r
1049     void SetDoubleValue(double _value); ///< Set the value from a double.\r
1050 \r
1051 #ifdef TIXML_USE_STL\r
1052     /// STL std::string form.\r
1053     void SetName(const std::string &_name)\r
1054     {\r
1055         name = _name;\r
1056     }\r
1057     /// STL std::string form.\r
1058     void SetValue(const std::string &_value)\r
1059     {\r
1060         value = _value;\r
1061     }\r
1062 #endif\r
1063 \r
1064     /// Get the next sibling attribute in the DOM. Returns null at end.\r
1065     const TiXmlAttribute *Next() const;\r
1066     TiXmlAttribute *Next()\r
1067     {\r
1068         return const_cast<TiXmlAttribute *>((const_cast<const TiXmlAttribute *>(this))->Next());\r
1069     }\r
1070 \r
1071     /// Get the previous sibling attribute in the DOM. Returns null at beginning.\r
1072     const TiXmlAttribute *Previous() const;\r
1073     TiXmlAttribute *Previous()\r
1074     {\r
1075         return const_cast<TiXmlAttribute *>((const_cast<const TiXmlAttribute *>(this))->Previous());\r
1076     }\r
1077 \r
1078     bool operator==(const TiXmlAttribute &rhs) const\r
1079     {\r
1080         return rhs.name == name;\r
1081     }\r
1082     bool operator<(const TiXmlAttribute &rhs) const\r
1083     {\r
1084         return name < rhs.name;\r
1085     }\r
1086     bool operator>(const TiXmlAttribute &rhs) const\r
1087     {\r
1088         return name > rhs.name;\r
1089     }\r
1090 \r
1091     /*  Attribute parsing starts: first letter of the name\r
1092                                                  returns: the next char after the value end quote\r
1093         */\r
1094     virtual const char *Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding);\r
1095 \r
1096     // Prints this Attribute to a FILE stream.\r
1097     virtual void Print(FILE *cfile, int depth) const\r
1098     {\r
1099         Print(cfile, depth, 0);\r
1100     }\r
1101     void Print(FILE *cfile, int depth, TIXML_STRING *str) const;\r
1102 \r
1103     // [internal use]\r
1104     // Set the document pointer so the attribute can report errors.\r
1105     void SetDocument(TiXmlDocument *doc)\r
1106     {\r
1107         document = doc;\r
1108     }\r
1109 \r
1110 private:\r
1111     TiXmlAttribute(const TiXmlAttribute &);     // not implemented.\r
1112     void operator=(const TiXmlAttribute &base); // not allowed.\r
1113 \r
1114     TiXmlDocument *document; // A pointer back to a document, for error reporting.\r
1115     TIXML_STRING name;\r
1116     TIXML_STRING value;\r
1117     TiXmlAttribute *prev;\r
1118     TiXmlAttribute *next;\r
1119 };\r
1120 \r
1121 /*      A class used to manage a group of attributes.\r
1122         It is only used internally, both by the ELEMENT and the DECLARATION.\r
1123 \r
1124         The set can be changed transparent to the Element and Declaration\r
1125         classes that use it, but NOT transparent to the Attribute\r
1126         which has to implement a next() and previous() method. Which makes\r
1127         it a bit problematic and prevents the use of STL.\r
1128 \r
1129         This version is implemented with circular lists because:\r
1130                 - I like circular lists\r
1131                 - it demonstrates some independence from the (typical) doubly linked list.\r
1132 */\r
1133 class TiXmlAttributeSet\r
1134 {\r
1135 public:\r
1136     TiXmlAttributeSet();\r
1137     ~TiXmlAttributeSet();\r
1138 \r
1139     void Add(TiXmlAttribute *attribute);\r
1140     void Remove(TiXmlAttribute *attribute);\r
1141 \r
1142     const TiXmlAttribute *First() const\r
1143     {\r
1144         return (sentinel.next == &sentinel) ? 0 : sentinel.next;\r
1145     }\r
1146     TiXmlAttribute *First()\r
1147     {\r
1148         return (sentinel.next == &sentinel) ? 0 : sentinel.next;\r
1149     }\r
1150     const TiXmlAttribute *Last() const\r
1151     {\r
1152         return (sentinel.prev == &sentinel) ? 0 : sentinel.prev;\r
1153     }\r
1154     TiXmlAttribute *Last()\r
1155     {\r
1156         return (sentinel.prev == &sentinel) ? 0 : sentinel.prev;\r
1157     }\r
1158 \r
1159     TiXmlAttribute *Find(const char *_name) const;\r
1160     TiXmlAttribute *FindOrCreate(const char *_name);\r
1161 \r
1162 #ifdef TIXML_USE_STL\r
1163     TiXmlAttribute *Find(const std::string &_name) const;\r
1164     TiXmlAttribute *FindOrCreate(const std::string &_name);\r
1165 #endif\r
1166 \r
1167 private:\r
1168     //*ME:      Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),\r
1169     //*ME:      this class must be also use a hidden/disabled copy-constructor !!!\r
1170     TiXmlAttributeSet(const TiXmlAttributeSet &); // not allowed\r
1171     void operator=(const TiXmlAttributeSet &);    // not allowed (as TiXmlAttribute)\r
1172 \r
1173     TiXmlAttribute sentinel;\r
1174 };\r
1175 \r
1176 /** The element is a container class. It has a value, the element name,\r
1177         and can contain other elements, text, comments, and unknowns.\r
1178         Elements also contain an arbitrary number of attributes.\r
1179 */\r
1180 class TiXmlElement : public TiXmlNode\r
1181 {\r
1182 public:\r
1183     /// Construct an element.\r
1184     TiXmlElement(const char *in_value);\r
1185 \r
1186 #ifdef TIXML_USE_STL\r
1187     /// std::string constructor.\r
1188     TiXmlElement(const std::string &_value);\r
1189 #endif\r
1190 \r
1191     TiXmlElement(const TiXmlElement &);\r
1192 \r
1193     TiXmlElement &operator=(const TiXmlElement &base);\r
1194 \r
1195     virtual ~TiXmlElement();\r
1196 \r
1197     /** Given an attribute name, Attribute() returns the value\r
1198                 for the attribute of that name, or null if none exists.\r
1199         */\r
1200     const char *Attribute(const char *name) const;\r
1201 \r
1202     /** Given an attribute name, Attribute() returns the value\r
1203                 for the attribute of that name, or null if none exists.\r
1204                 If the attribute exists and can be converted to an integer,\r
1205                 the integer value will be put in the return 'i', if 'i'\r
1206                 is non-null.\r
1207         */\r
1208     const char *Attribute(const char *name, int *i) const;\r
1209 \r
1210     /** Given an attribute name, Attribute() returns the value\r
1211                 for the attribute of that name, or null if none exists.\r
1212                 If the attribute exists and can be converted to an double,\r
1213                 the double value will be put in the return 'd', if 'd'\r
1214                 is non-null.\r
1215         */\r
1216     const char *Attribute(const char *name, double *d) const;\r
1217 \r
1218     /** QueryIntAttribute examines the attribute - it is an alternative to the\r
1219                 Attribute() method with richer error checking.\r
1220                 If the attribute is an integer, it is stored in 'value' and\r
1221                 the call returns TIXML_SUCCESS. If it is not\r
1222                 an integer, it returns TIXML_WRONG_TYPE. If the attribute\r
1223                 does not exist, then TIXML_NO_ATTRIBUTE is returned.\r
1224         */\r
1225     int QueryIntAttribute(const char *name, int *_value) const;\r
1226     /// QueryUnsignedAttribute examines the attribute - see QueryIntAttribute().\r
1227     int QueryUnsignedAttribute(const char *name, unsigned *_value) const;\r
1228     /** QueryBoolAttribute examines the attribute - see QueryIntAttribute().\r
1229                 Note that '1', 'true', or 'yes' are considered true, while '0', 'false'\r
1230                 and 'no' are considered false.\r
1231         */\r
1232     int QueryBoolAttribute(const char *name, bool *_value) const;\r
1233     /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().\r
1234     int QueryDoubleAttribute(const char *name, double *_value) const;\r
1235     /// QueryFloatAttribute examines the attribute - see QueryIntAttribute().\r
1236     int QueryFloatAttribute(const char *name, float *_value) const\r
1237     {\r
1238         double d;\r
1239         int result = QueryDoubleAttribute(name, &d);\r
1240         if (result == TIXML_SUCCESS)\r
1241         {\r
1242             *_value = (float)d;\r
1243         }\r
1244         return result;\r
1245     }\r
1246 \r
1247 #ifdef TIXML_USE_STL\r
1248     /// QueryStringAttribute examines the attribute - see QueryIntAttribute().\r
1249     int QueryStringAttribute(const char *name, std::string *_value) const\r
1250     {\r
1251         const char *cstr = Attribute(name);\r
1252         if (cstr)\r
1253         {\r
1254             *_value = std::string(cstr);\r
1255             return TIXML_SUCCESS;\r
1256         }\r
1257         return TIXML_NO_ATTRIBUTE;\r
1258     }\r
1259 \r
1260     /** Template form of the attribute query which will try to read the\r
1261                 attribute into the specified type. Very easy, very powerful, but\r
1262                 be careful to make sure to call this with the correct type.\r
1263 \r
1264                 NOTE: This method doesn't work correctly for 'string' types that contain spaces.\r
1265 \r
1266                 @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE\r
1267         */\r
1268     template <typename T>\r
1269     int QueryValueAttribute(const std::string &name, T *outValue) const\r
1270     {\r
1271         const TiXmlAttribute *node = attributeSet.Find(name);\r
1272         if (!node)\r
1273             return TIXML_NO_ATTRIBUTE;\r
1274 \r
1275         std::stringstream sstream(node->ValueStr());\r
1276         sstream >> *outValue;\r
1277         if (!sstream.fail())\r
1278             return TIXML_SUCCESS;\r
1279         return TIXML_WRONG_TYPE;\r
1280     }\r
1281 \r
1282     int QueryValueAttribute(const std::string &name, std::string *outValue) const\r
1283     {\r
1284         const TiXmlAttribute *node = attributeSet.Find(name);\r
1285         if (!node)\r
1286             return TIXML_NO_ATTRIBUTE;\r
1287         *outValue = node->ValueStr();\r
1288         return TIXML_SUCCESS;\r
1289     }\r
1290 #endif\r
1291 \r
1292     /** Sets an attribute of name to a given value. The attribute\r
1293                 will be created if it does not exist, or changed if it does.\r
1294         */\r
1295     void SetAttribute(const char *name, const char *_value);\r
1296 \r
1297 #ifdef TIXML_USE_STL\r
1298     const std::string *Attribute(const std::string &name) const;\r
1299     const std::string *Attribute(const std::string &name, int *i) const;\r
1300     const std::string *Attribute(const std::string &name, double *d) const;\r
1301     int QueryIntAttribute(const std::string &name, int *_value) const;\r
1302     int QueryDoubleAttribute(const std::string &name, double *_value) const;\r
1303 \r
1304     /// STL std::string form.\r
1305     void SetAttribute(const std::string &name, const std::string &_value);\r
1306     ///< STL std::string form.\r
1307     void SetAttribute(const std::string &name, int _value);\r
1308     ///< STL std::string form.\r
1309     void SetDoubleAttribute(const std::string &name, double value);\r
1310 #endif\r
1311 \r
1312     /** Sets an attribute of name to a given value. The attribute\r
1313                 will be created if it does not exist, or changed if it does.\r
1314         */\r
1315     void SetAttribute(const char *name, int value);\r
1316 \r
1317     /** Sets an attribute of name to a given value. The attribute\r
1318                 will be created if it does not exist, or changed if it does.\r
1319         */\r
1320     void SetDoubleAttribute(const char *name, double value);\r
1321 \r
1322     /** Deletes an attribute with the given name.\r
1323         */\r
1324     void RemoveAttribute(const char *name);\r
1325 #ifdef TIXML_USE_STL\r
1326     void RemoveAttribute(const std::string &name)\r
1327     {\r
1328         RemoveAttribute(name.c_str()); ///< STL std::string form.\r
1329     }\r
1330 #endif\r
1331 \r
1332     const TiXmlAttribute *FirstAttribute() const\r
1333     {\r
1334         return attributeSet.First(); ///< Access the first attribute in this element.\r
1335     }\r
1336     TiXmlAttribute *FirstAttribute()\r
1337     {\r
1338         return attributeSet.First();\r
1339     }\r
1340     const TiXmlAttribute *LastAttribute() const\r
1341     {\r
1342         return attributeSet.Last(); ///< Access the last attribute in this element.\r
1343     }\r
1344     TiXmlAttribute *LastAttribute()\r
1345     {\r
1346         return attributeSet.Last();\r
1347     }\r
1348 \r
1349     /** Convenience function for easy access to the text inside an element. Although easy\r
1350                 and concise, GetText() is limited compared to getting the TiXmlText child\r
1351                 and accessing it directly.\r
1352 \r
1353                 If the first child of 'this' is a TiXmlText, the GetText()\r
1354                 returns the character string of the Text node, else null is returned.\r
1355 \r
1356                 This is a convenient method for getting the text of simple contained text:\r
1357                 @verbatim\r
1358                 <foo>This is text</foo>\r
1359                 const char* str = fooElement->GetText();\r
1360                 @endverbatim\r
1361 \r
1362                 'str' will be a pointer to "This is text".\r
1363 \r
1364                 Note that this function can be misleading. If the element foo was created from\r
1365                 this XML:\r
1366                 @verbatim\r
1367                 <foo><b>This is text</b></foo>\r
1368                 @endverbatim\r
1369 \r
1370                 then the value of str would be null. The first child node isn't a text node, it is\r
1371                 another element. From this XML:\r
1372                 @verbatim\r
1373                 <foo>This is <b>text</b></foo>\r
1374                 @endverbatim\r
1375                 GetText() will return "This is ".\r
1376 \r
1377                 WARNING: GetText() accesses a child node - don't become confused with the\r
1378                                  similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are\r
1379                                  safe type casts on the referenced node.\r
1380         */\r
1381     const char *GetText() const;\r
1382 \r
1383     /// Creates a new Element and returns it - the returned element is a copy.\r
1384     virtual TiXmlNode *Clone() const;\r
1385     // Print the Element to a FILE stream.\r
1386     virtual void Print(FILE *cfile, int depth) const;\r
1387 \r
1388     /*  Attribtue parsing starts: next char past '<'\r
1389                                                  returns: next char past '>'\r
1390         */\r
1391     virtual const char *Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding);\r
1392 \r
1393     virtual const TiXmlElement *ToElement() const\r
1394     {\r
1395         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1396     }\r
1397     virtual TiXmlElement *ToElement()\r
1398     {\r
1399         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1400     }\r
1401 \r
1402     /** Walk the XML tree visiting this node and all of its children.\r
1403         */\r
1404     virtual bool Accept(TiXmlVisitor *visitor) const;\r
1405 \r
1406 protected:\r
1407     void CopyTo(TiXmlElement *target) const;\r
1408     void ClearThis(); // like clear, but initializes 'this' object as well\r
1409 \r
1410 // Used to be public [internal use]\r
1411 #ifdef TIXML_USE_STL\r
1412     virtual void StreamIn(std::istream *in, TIXML_STRING *tag);\r
1413 #endif\r
1414     /*  [internal use]\r
1415                 Reads the "value" of the element -- another element, or text.\r
1416                 This should terminate with the current end tag.\r
1417         */\r
1418     const char *ReadValue(const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding);\r
1419 \r
1420 private:\r
1421     TiXmlAttributeSet attributeSet;\r
1422 };\r
1423 \r
1424 /**     An XML comment.\r
1425 */\r
1426 class TiXmlComment : public TiXmlNode\r
1427 {\r
1428 public:\r
1429     /// Constructs an empty comment.\r
1430     TiXmlComment()\r
1431         : TiXmlNode(TiXmlNode::TINYXML_COMMENT)\r
1432     {\r
1433     }\r
1434     /// Construct a comment from text.\r
1435     TiXmlComment(const char *_value)\r
1436         : TiXmlNode(TiXmlNode::TINYXML_COMMENT)\r
1437     {\r
1438         SetValue(_value);\r
1439     }\r
1440     TiXmlComment(const TiXmlComment &);\r
1441     TiXmlComment &operator=(const TiXmlComment &base);\r
1442 \r
1443     virtual ~TiXmlComment()\r
1444     {\r
1445     }\r
1446 \r
1447     /// Returns a copy of this Comment.\r
1448     virtual TiXmlNode *Clone() const;\r
1449     // Write this Comment to a FILE stream.\r
1450     virtual void Print(FILE *cfile, int depth) const;\r
1451 \r
1452     /*  Attribtue parsing starts: at the ! of the !--\r
1453                                                  returns: next char past '>'\r
1454         */\r
1455     virtual const char *Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding);\r
1456 \r
1457     virtual const TiXmlComment *ToComment() const\r
1458     {\r
1459         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1460     }\r
1461     virtual TiXmlComment *ToComment()\r
1462     {\r
1463         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1464     }\r
1465 \r
1466     /** Walk the XML tree visiting this node and all of its children.\r
1467         */\r
1468     virtual bool Accept(TiXmlVisitor *visitor) const;\r
1469 \r
1470 protected:\r
1471     void CopyTo(TiXmlComment *target) const;\r
1472 \r
1473 // used to be public\r
1474 #ifdef TIXML_USE_STL\r
1475     virtual void StreamIn(std::istream *in, TIXML_STRING *tag);\r
1476 #endif\r
1477     //  virtual void StreamOut( TIXML_OSTREAM * out ) const;\r
1478 \r
1479 private:\r
1480 };\r
1481 \r
1482 /** XML text. A text node can have 2 ways to output the next. "normal" output\r
1483         and CDATA. It will default to the mode it was parsed from the XML file and\r
1484         you generally want to leave it alone, but you can change the output mode with\r
1485         SetCDATA() and query it with CDATA().\r
1486 */\r
1487 class TiXmlText : public TiXmlNode\r
1488 {\r
1489     friend class TiXmlElement;\r
1490 \r
1491 public:\r
1492     /** Constructor for text element. By default, it is treated as\r
1493                 normal, encoded text. If you want it be output as a CDATA text\r
1494                 element, set the parameter _cdata to 'true'\r
1495         */\r
1496     TiXmlText(const char *initValue)\r
1497         : TiXmlNode(TiXmlNode::TINYXML_TEXT)\r
1498     {\r
1499         SetValue(initValue);\r
1500         cdata = false;\r
1501     }\r
1502     virtual ~TiXmlText()\r
1503     {\r
1504     }\r
1505 \r
1506 #ifdef TIXML_USE_STL\r
1507     /// Constructor.\r
1508     TiXmlText(const std::string &initValue)\r
1509         : TiXmlNode(TiXmlNode::TINYXML_TEXT)\r
1510     {\r
1511         SetValue(initValue);\r
1512         cdata = false;\r
1513     }\r
1514 #endif\r
1515 \r
1516     TiXmlText(const TiXmlText &copy)\r
1517         : TiXmlNode(TiXmlNode::TINYXML_TEXT)\r
1518     {\r
1519         copy.CopyTo(this);\r
1520     }\r
1521     TiXmlText &operator=(const TiXmlText &base)\r
1522     {\r
1523         base.CopyTo(this);\r
1524         return *this;\r
1525     }\r
1526 \r
1527     // Write this text object to a FILE stream.\r
1528     virtual void Print(FILE *cfile, int depth) const;\r
1529 \r
1530     /// Queries whether this represents text using a CDATA section.\r
1531     bool CDATA() const\r
1532     {\r
1533         return cdata;\r
1534     }\r
1535     /// Turns on or off a CDATA representation of text.\r
1536     void SetCDATA(bool _cdata)\r
1537     {\r
1538         cdata = _cdata;\r
1539     }\r
1540 \r
1541     virtual const char *Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding);\r
1542 \r
1543     virtual const TiXmlText *ToText() const\r
1544     {\r
1545         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1546     }\r
1547     virtual TiXmlText *ToText()\r
1548     {\r
1549         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1550     }\r
1551 \r
1552     /** Walk the XML tree visiting this node and all of its children.\r
1553         */\r
1554     virtual bool Accept(TiXmlVisitor *content) const;\r
1555 \r
1556 protected:\r
1557     ///  [internal use] Creates a new Element and returns it.\r
1558     virtual TiXmlNode *Clone() const;\r
1559     void CopyTo(TiXmlText *target) const;\r
1560 \r
1561     bool Blank() const; // returns true if all white space and new lines\r
1562                         // [internal use]\r
1563 #ifdef TIXML_USE_STL\r
1564     virtual void StreamIn(std::istream *in, TIXML_STRING *tag);\r
1565 #endif\r
1566 \r
1567 private:\r
1568     bool cdata; // true if this should be input and output as a CDATA style text element\r
1569 };\r
1570 \r
1571 /** In correct XML the declaration is the first entry in the file.\r
1572         @verbatim\r
1573                 <?xml version="1.0" standalone="yes"?>\r
1574         @endverbatim\r
1575 \r
1576         TinyXml will happily read or write files without a declaration,\r
1577         however. There are 3 possible attributes to the declaration:\r
1578         version, encoding, and standalone.\r
1579 \r
1580         Note: In this version of the code, the attributes are\r
1581         handled as special cases, not generic attributes, simply\r
1582         because there can only be at most 3 and they are always the same.\r
1583 */\r
1584 class TiXmlDeclaration : public TiXmlNode\r
1585 {\r
1586 public:\r
1587     /// Construct an empty declaration.\r
1588     TiXmlDeclaration()\r
1589         : TiXmlNode(TiXmlNode::TINYXML_DECLARATION)\r
1590     {\r
1591     }\r
1592 \r
1593 #ifdef TIXML_USE_STL\r
1594     /// Constructor.\r
1595     TiXmlDeclaration(const std::string &_version,\r
1596                      const std::string &_encoding,\r
1597                      const std::string &_standalone);\r
1598 #endif\r
1599 \r
1600     /// Construct.\r
1601     TiXmlDeclaration(const char *_version,\r
1602                      const char *_encoding,\r
1603                      const char *_standalone);\r
1604 \r
1605     TiXmlDeclaration(const TiXmlDeclaration &copy);\r
1606     TiXmlDeclaration &operator=(const TiXmlDeclaration &copy);\r
1607 \r
1608     virtual ~TiXmlDeclaration()\r
1609     {\r
1610     }\r
1611 \r
1612     /// Version. Will return an empty string if none was found.\r
1613     const char *Version() const\r
1614     {\r
1615         return version.c_str();\r
1616     }\r
1617     /// Encoding. Will return an empty string if none was found.\r
1618     const char *Encoding() const\r
1619     {\r
1620         return encoding.c_str();\r
1621     }\r
1622     /// Is this a standalone document?\r
1623     const char *Standalone() const\r
1624     {\r
1625         return standalone.c_str();\r
1626     }\r
1627 \r
1628     /// Creates a copy of this Declaration and returns it.\r
1629     virtual TiXmlNode *Clone() const;\r
1630     // Print this declaration to a FILE stream.\r
1631     virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const;\r
1632     virtual void Print(FILE *cfile, int depth) const\r
1633     {\r
1634         Print(cfile, depth, 0);\r
1635     }\r
1636 \r
1637     virtual const char *Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding);\r
1638 \r
1639     virtual const TiXmlDeclaration *ToDeclaration() const\r
1640     {\r
1641         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1642     }\r
1643     virtual TiXmlDeclaration *ToDeclaration()\r
1644     {\r
1645         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1646     }\r
1647 \r
1648     /** Walk the XML tree visiting this node and all of its children.\r
1649         */\r
1650     virtual bool Accept(TiXmlVisitor *visitor) const;\r
1651 \r
1652 protected:\r
1653     void CopyTo(TiXmlDeclaration *target) const;\r
1654 // used to be public\r
1655 #ifdef TIXML_USE_STL\r
1656     virtual void StreamIn(std::istream *in, TIXML_STRING *tag);\r
1657 #endif\r
1658 \r
1659 private:\r
1660     TIXML_STRING version;\r
1661     TIXML_STRING encoding;\r
1662     TIXML_STRING standalone;\r
1663 };\r
1664 \r
1665 /** Any tag that tinyXml doesn't recognize is saved as an\r
1666         unknown. It is a tag of text, but should not be modified.\r
1667         It will be written back to the XML, unchanged, when the file\r
1668         is saved.\r
1669 \r
1670         DTD tags get thrown into TiXmlUnknowns.\r
1671 */\r
1672 class TiXmlUnknown : public TiXmlNode\r
1673 {\r
1674 public:\r
1675     TiXmlUnknown()\r
1676         : TiXmlNode(TiXmlNode::TINYXML_UNKNOWN)\r
1677     {\r
1678     }\r
1679     virtual ~TiXmlUnknown()\r
1680     {\r
1681     }\r
1682 \r
1683     TiXmlUnknown(const TiXmlUnknown &copy)\r
1684         : TiXmlNode(TiXmlNode::TINYXML_UNKNOWN)\r
1685     {\r
1686         copy.CopyTo(this);\r
1687     }\r
1688     TiXmlUnknown &operator=(const TiXmlUnknown &copy)\r
1689     {\r
1690         copy.CopyTo(this);\r
1691         return *this;\r
1692     }\r
1693 \r
1694     /// Creates a copy of this Unknown and returns it.\r
1695     virtual TiXmlNode *Clone() const;\r
1696     // Print this Unknown to a FILE stream.\r
1697     virtual void Print(FILE *cfile, int depth) const;\r
1698 \r
1699     virtual const char *Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding);\r
1700 \r
1701     virtual const TiXmlUnknown *ToUnknown() const\r
1702     {\r
1703         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1704     }\r
1705     virtual TiXmlUnknown *ToUnknown()\r
1706     {\r
1707         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1708     }\r
1709 \r
1710     /** Walk the XML tree visiting this node and all of its children.\r
1711         */\r
1712     virtual bool Accept(TiXmlVisitor *content) const;\r
1713 \r
1714 protected:\r
1715     void CopyTo(TiXmlUnknown *target) const;\r
1716 \r
1717 #ifdef TIXML_USE_STL\r
1718     virtual void StreamIn(std::istream *in, TIXML_STRING *tag);\r
1719 #endif\r
1720 \r
1721 private:\r
1722 };\r
1723 \r
1724 /** Always the top level node. A document binds together all the\r
1725         XML pieces. It can be saved, loaded, and printed to the screen.\r
1726         The 'value' of a document node is the xml file name.\r
1727 */\r
1728 class TiXmlDocument : public TiXmlNode\r
1729 {\r
1730 public:\r
1731     /// Create an empty document, that has no name.\r
1732     TiXmlDocument();\r
1733     /// Create a document with a name. The name of the document is also the filename of the xml.\r
1734     TiXmlDocument(const char *documentName);\r
1735 \r
1736 #ifdef TIXML_USE_STL\r
1737     /// Constructor.\r
1738     TiXmlDocument(const std::string &documentName);\r
1739 #endif\r
1740 \r
1741     TiXmlDocument(const TiXmlDocument &copy);\r
1742     TiXmlDocument &operator=(const TiXmlDocument &copy);\r
1743 \r
1744     virtual ~TiXmlDocument()\r
1745     {\r
1746     }\r
1747 \r
1748     /** Load a file using the current document value.\r
1749                 Returns true if successful. Will delete any existing\r
1750                 document data before loading.\r
1751         */\r
1752     bool LoadFile(TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);\r
1753     /// Save a file using the current document value. Returns true if successful.\r
1754     bool SaveFile() const;\r
1755     /// Load a file using the given filename. Returns true if successful.\r
1756     bool LoadFile(const char *filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);\r
1757     /// Save a file using the given filename. Returns true if successful.\r
1758     bool SaveFile(const char *filename) const;\r
1759     /** Load a file using the given FILE*. Returns true if successful. Note that this method\r
1760                 doesn't stream - the entire object pointed at by the FILE*\r
1761                 will be interpreted as an XML file. TinyXML doesn't stream in XML from the current\r
1762                 file location. Streaming may be added in the future.\r
1763         */\r
1764     bool LoadFile(FILE *, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);\r
1765     /// Save a file using the given FILE*. Returns true if successful.\r
1766     bool SaveFile(FILE *) const;\r
1767 \r
1768 #ifdef TIXML_USE_STL\r
1769     bool LoadFile(const std::string &filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING) ///< STL std::string version.\r
1770     {\r
1771         return LoadFile(filename.c_str(), encoding);\r
1772     }\r
1773     bool SaveFile(const std::string &filename) const ///< STL std::string version.\r
1774     {\r
1775         return SaveFile(filename.c_str());\r
1776     }\r
1777 #endif\r
1778 \r
1779     /** Parse the given null terminated block of xml data. Passing in an encoding to this\r
1780                 method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml\r
1781                 to use that encoding, regardless of what TinyXml might otherwise try to detect.\r
1782         */\r
1783     virtual const char *Parse(const char *p, TiXmlParsingData *data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);\r
1784 \r
1785     /** Get the root element -- the only top level element -- of the document.\r
1786                 In well formed XML, there should only be one. TinyXml is tolerant of\r
1787                 multiple elements at the document level.\r
1788         */\r
1789     const TiXmlElement *RootElement() const\r
1790     {\r
1791         return FirstChildElement();\r
1792     }\r
1793     TiXmlElement *RootElement()\r
1794     {\r
1795         return FirstChildElement();\r
1796     }\r
1797 \r
1798     /** If an error occurs, Error will be set to true. Also,\r
1799                 - The ErrorId() will contain the integer identifier of the error (not generally useful)\r
1800                 - The ErrorDesc() method will return the name of the error. (very useful)\r
1801                 - The ErrorRow() and ErrorCol() will return the location of the error (if known)\r
1802         */\r
1803     bool Error() const\r
1804     {\r
1805         return error;\r
1806     }\r
1807 \r
1808     /// Contains a textual (english) description of the error if one occurs.\r
1809     const char *ErrorDesc() const\r
1810     {\r
1811         return errorDesc.c_str();\r
1812     }\r
1813 \r
1814     /** Generally, you probably want the error string ( ErrorDesc() ). But if you\r
1815                 prefer the ErrorId, this function will fetch it.\r
1816         */\r
1817     int ErrorId() const\r
1818     {\r
1819         return errorId;\r
1820     }\r
1821 \r
1822     /** Returns the location (if known) of the error. The first column is column 1,\r
1823                 and the first row is row 1. A value of 0 means the row and column wasn't applicable\r
1824                 (memory errors, for example, have no row/column) or the parser lost the error. (An\r
1825                 error in the error reporting, in that case.)\r
1826 \r
1827                 @sa SetTabSize, Row, Column\r
1828         */\r
1829     int ErrorRow() const\r
1830     {\r
1831         return errorLocation.row + 1;\r
1832     }\r
1833     int ErrorCol() const\r
1834     {\r
1835         return errorLocation.col + 1; ///< The column where the error occured. See ErrorRow()\r
1836     }\r
1837 \r
1838     /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol())\r
1839                 to report the correct values for row and column. It does not change the output\r
1840                 or input in any way.\r
1841 \r
1842                 By calling this method, with a tab size\r
1843                 greater than 0, the row and column of each node and attribute is stored\r
1844                 when the file is loaded. Very useful for tracking the DOM back in to\r
1845                 the source file.\r
1846 \r
1847                 The tab size is required for calculating the location of nodes. If not\r
1848                 set, the default of 4 is used. The tabsize is set per document. Setting\r
1849                 the tabsize to 0 disables row/column tracking.\r
1850 \r
1851                 Note that row and column tracking is not supported when using operator>>.\r
1852 \r
1853                 The tab size needs to be enabled before the parse or load. Correct usage:\r
1854                 @verbatim\r
1855                 TiXmlDocument doc;\r
1856                 doc.SetTabSize( 8 );\r
1857                 doc.Load( "myfile.xml" );\r
1858                 @endverbatim\r
1859 \r
1860                 @sa Row, Column\r
1861         */\r
1862     void SetTabSize(int _tabsize)\r
1863     {\r
1864         tabsize = _tabsize;\r
1865     }\r
1866 \r
1867     int TabSize() const\r
1868     {\r
1869         return tabsize;\r
1870     }\r
1871 \r
1872     /** If you have handled the error, it can be reset with this call. The error\r
1873                 state is automatically cleared if you Parse a new XML block.\r
1874         */\r
1875     void ClearError()\r
1876     {\r
1877         error = false;\r
1878         errorId = 0;\r
1879         errorDesc = "";\r
1880         errorLocation.row = errorLocation.col = 0;\r
1881         //errorLocation.last = 0;\r
1882     }\r
1883 \r
1884     /** Write the document to standard out using formatted printing ("pretty print"). */\r
1885     void Print() const\r
1886     {\r
1887         Print(stdout, 0);\r
1888     }\r
1889 \r
1890     /* Write the document to a string using formatted printing ("pretty print"). This\r
1891                 will allocate a character array (new char[]) and return it as a pointer. The\r
1892                 calling code pust call delete[] on the return char* to avoid a memory leak.\r
1893         */\r
1894     //char* PrintToMemory() const;\r
1895 \r
1896     /// Print this Document to a FILE stream.\r
1897     virtual void Print(FILE *cfile, int depth = 0) const;\r
1898     // [internal use]\r
1899     void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding);\r
1900 \r
1901     virtual const TiXmlDocument *ToDocument() const\r
1902     {\r
1903         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1904     }\r
1905     virtual TiXmlDocument *ToDocument()\r
1906     {\r
1907         return this; ///< Cast to a more defined type. Will return null not of the requested type.\r
1908     }\r
1909 \r
1910     /** Walk the XML tree visiting this node and all of its children.\r
1911         */\r
1912     virtual bool Accept(TiXmlVisitor *content) const;\r
1913 \r
1914 protected:\r
1915     // [internal use]\r
1916     virtual TiXmlNode *Clone() const;\r
1917 #ifdef TIXML_USE_STL\r
1918     virtual void StreamIn(std::istream *in, TIXML_STRING *tag);\r
1919 #endif\r
1920 \r
1921 private:\r
1922     void CopyTo(TiXmlDocument *target) const;\r
1923 \r
1924     bool error;\r
1925     int errorId;\r
1926     TIXML_STRING errorDesc;\r
1927     int tabsize;\r
1928     TiXmlCursor errorLocation;\r
1929     bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write.\r
1930 };\r
1931 \r
1932 /**\r
1933         A TiXmlHandle is a class that wraps a node pointer with null checks; this is\r
1934         an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml\r
1935         DOM structure. It is a separate utility class.\r
1936 \r
1937         Take an example:\r
1938         @verbatim\r
1939         <Document>\r
1940                 <Element attributeA = "valueA">\r
1941                         <Child attributeB = "value1" />\r
1942                         <Child attributeB = "value2" />\r
1943                 </Element>\r
1944         <Document>\r
1945         @endverbatim\r
1946 \r
1947         Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very\r
1948         easy to write a *lot* of code that looks like:\r
1949 \r
1950         @verbatim\r
1951         TiXmlElement* root = document.FirstChildElement( "Document" );\r
1952         if ( root )\r
1953         {\r
1954                 TiXmlElement* element = root->FirstChildElement( "Element" );\r
1955                 if ( element )\r
1956                 {\r
1957                         TiXmlElement* child = element->FirstChildElement( "Child" );\r
1958                         if ( child )\r
1959                         {\r
1960                                 TiXmlElement* child2 = child->NextSiblingElement( "Child" );\r
1961                                 if ( child2 )\r
1962                                 {\r
1963                                         // Finally do something useful.\r
1964         @endverbatim\r
1965 \r
1966         And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity\r
1967         of such code. A TiXmlHandle checks for null     pointers so it is perfectly safe\r
1968         and correct to use:\r
1969 \r
1970         @verbatim\r
1971         TiXmlHandle docHandle( &document );\r
1972         TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement();\r
1973         if ( child2 )\r
1974         {\r
1975                 // do something useful\r
1976         @endverbatim\r
1977 \r
1978         Which is MUCH more concise and useful.\r
1979 \r
1980         It is also safe to copy handles - internally they are nothing more than node pointers.\r
1981         @verbatim\r
1982         TiXmlHandle handleCopy = handle;\r
1983         @endverbatim\r
1984 \r
1985         What they should not be used for is iteration:\r
1986 \r
1987         @verbatim\r
1988         int i=0;\r
1989         while ( true )\r
1990         {\r
1991                 TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement();\r
1992                 if ( !child )\r
1993                         break;\r
1994                 // do something\r
1995                 ++i;\r
1996         }\r
1997         @endverbatim\r
1998 \r
1999         It seems reasonable, but it is in fact two embedded while loops. The Child method is\r
2000         a linear walk to find the element, so this code would iterate much more than it needs\r
2001         to. Instead, prefer:\r
2002 \r
2003         @verbatim\r
2004         TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement();\r
2005 \r
2006         for( child; child; child=child->NextSiblingElement() )\r
2007         {\r
2008                 // do something\r
2009         }\r
2010         @endverbatim\r
2011 */\r
2012 class TiXmlHandle\r
2013 {\r
2014 public:\r
2015     /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.\r
2016     TiXmlHandle(TiXmlNode *_node)\r
2017     {\r
2018         this->node = _node;\r
2019     }\r
2020     /// Copy constructor\r
2021     TiXmlHandle(const TiXmlHandle &ref)\r
2022     {\r
2023         this->node = ref.node;\r
2024     }\r
2025     TiXmlHandle operator=(const TiXmlHandle &ref)\r
2026     {\r
2027         if (&ref != this)\r
2028             this->node = ref.node;\r
2029         return *this;\r
2030     }\r
2031 \r
2032     /// Return a handle to the first child node.\r
2033     TiXmlHandle FirstChild() const;\r
2034     /// Return a handle to the first child node with the given name.\r
2035     TiXmlHandle FirstChild(const char *value) const;\r
2036     /// Return a handle to the first child element.\r
2037     TiXmlHandle FirstChildElement() const;\r
2038     /// Return a handle to the first child element with the given name.\r
2039     TiXmlHandle FirstChildElement(const char *value) const;\r
2040 \r
2041     /** Return a handle to the "index" child with the given name.\r
2042                 The first child is 0, the second 1, etc.\r
2043         */\r
2044     TiXmlHandle Child(const char *value, int index) const;\r
2045     /** Return a handle to the "index" child.\r
2046                 The first child is 0, the second 1, etc.\r
2047         */\r
2048     TiXmlHandle Child(int index) const;\r
2049     /** Return a handle to the "index" child element with the given name.\r
2050                 The first child element is 0, the second 1, etc. Note that only TiXmlElements\r
2051                 are indexed: other types are not counted.\r
2052         */\r
2053     TiXmlHandle ChildElement(const char *value, int index) const;\r
2054     /** Return a handle to the "index" child element.\r
2055                 The first child element is 0, the second 1, etc. Note that only TiXmlElements\r
2056                 are indexed: other types are not counted.\r
2057         */\r
2058     TiXmlHandle ChildElement(int index) const;\r
2059 \r
2060 #ifdef TIXML_USE_STL\r
2061     TiXmlHandle FirstChild(const std::string &_value) const\r
2062     {\r
2063         return FirstChild(_value.c_str());\r
2064     }\r
2065     TiXmlHandle FirstChildElement(const std::string &_value) const\r
2066     {\r
2067         return FirstChildElement(_value.c_str());\r
2068     }\r
2069 \r
2070     TiXmlHandle Child(const std::string &_value, int index) const\r
2071     {\r
2072         return Child(_value.c_str(), index);\r
2073     }\r
2074     TiXmlHandle ChildElement(const std::string &_value, int index) const\r
2075     {\r
2076         return ChildElement(_value.c_str(), index);\r
2077     }\r
2078 #endif\r
2079 \r
2080     /** Return the handle as a TiXmlNode. This may return null.\r
2081         */\r
2082     TiXmlNode *ToNode() const\r
2083     {\r
2084         return node;\r
2085     }\r
2086     /** Return the handle as a TiXmlElement. This may return null.\r
2087         */\r
2088     TiXmlElement *ToElement() const\r
2089     {\r
2090         return ((node && node->ToElement()) ? node->ToElement() : 0);\r
2091     }\r
2092     /** Return the handle as a TiXmlText. This may return null.\r
2093         */\r
2094     TiXmlText *ToText() const\r
2095     {\r
2096         return ((node && node->ToText()) ? node->ToText() : 0);\r
2097     }\r
2098     /** Return the handle as a TiXmlUnknown. This may return null.\r
2099         */\r
2100     TiXmlUnknown *ToUnknown() const\r
2101     {\r
2102         return ((node && node->ToUnknown()) ? node->ToUnknown() : 0);\r
2103     }\r
2104 \r
2105     /** @deprecated use ToNode.\r
2106                 Return the handle as a TiXmlNode. This may return null.\r
2107         */\r
2108     TiXmlNode *Node() const\r
2109     {\r
2110         return ToNode();\r
2111     }\r
2112     /** @deprecated use ToElement.\r
2113                 Return the handle as a TiXmlElement. This may return null.\r
2114         */\r
2115     TiXmlElement *Element() const\r
2116     {\r
2117         return ToElement();\r
2118     }\r
2119     /** @deprecated use ToText()\r
2120                 Return the handle as a TiXmlText. This may return null.\r
2121         */\r
2122     TiXmlText *Text() const\r
2123     {\r
2124         return ToText();\r
2125     }\r
2126     /** @deprecated use ToUnknown()\r
2127                 Return the handle as a TiXmlUnknown. This may return null.\r
2128         */\r
2129     TiXmlUnknown *Unknown() const\r
2130     {\r
2131         return ToUnknown();\r
2132     }\r
2133 \r
2134 private:\r
2135     TiXmlNode *node;\r
2136 };\r
2137 \r
2138 /** Print to memory functionality. The TiXmlPrinter is useful when you need to:\r
2139 \r
2140         -# Print to memory (especially in non-STL mode)\r
2141         -# Control formatting (line endings, etc.)\r
2142 \r
2143         When constructed, the TiXmlPrinter is in its default "pretty printing" mode.\r
2144         Before calling Accept() you can call methods to control the printing\r
2145         of the XML document. After TiXmlNode::Accept() is called, the printed document can\r
2146         be accessed via the CStr(), Str(), and Size() methods.\r
2147 \r
2148         TiXmlPrinter uses the Visitor API.\r
2149         @verbatim\r
2150         TiXmlPrinter printer;\r
2151         printer.SetIndent( "\t" );\r
2152 \r
2153         doc.Accept( &printer );\r
2154         fprintf( stdout, "%s", printer.CStr() );\r
2155         @endverbatim\r
2156 */\r
2157 class TiXmlPrinter : public TiXmlVisitor\r
2158 {\r
2159 public:\r
2160     TiXmlPrinter()\r
2161         : depth(0), simpleTextPrint(false),\r
2162           buffer(), indent("    "), lineBreak("\n")\r
2163     {\r
2164     }\r
2165 \r
2166     virtual bool VisitEnter(const TiXmlDocument &doc);\r
2167     virtual bool VisitExit(const TiXmlDocument &doc);\r
2168 \r
2169     virtual bool VisitEnter(const TiXmlElement &element, const TiXmlAttribute *firstAttribute);\r
2170     virtual bool VisitExit(const TiXmlElement &element);\r
2171 \r
2172     virtual bool Visit(const TiXmlDeclaration &declaration);\r
2173     virtual bool Visit(const TiXmlText &text);\r
2174     virtual bool Visit(const TiXmlComment &comment);\r
2175     virtual bool Visit(const TiXmlUnknown &unknown);\r
2176 \r
2177     /** Set the indent characters for printing. By default 4 spaces\r
2178                 but tab (\t) is also useful, or null/empty string for no indentation.\r
2179         */\r
2180     void SetIndent(const char *_indent)\r
2181     {\r
2182         indent = _indent ? _indent : "";\r
2183     }\r
2184     /// Query the indention string.\r
2185     const char *Indent()\r
2186     {\r
2187         return indent.c_str();\r
2188     }\r
2189     /** Set the line breaking string. By default set to newline (\n).\r
2190                 Some operating systems prefer other characters, or can be\r
2191                 set to the null/empty string for no indenation.\r
2192         */\r
2193     void SetLineBreak(const char *_lineBreak)\r
2194     {\r
2195         lineBreak = _lineBreak ? _lineBreak : "";\r
2196     }\r
2197     /// Query the current line breaking string.\r
2198     const char *LineBreak()\r
2199     {\r
2200         return lineBreak.c_str();\r
2201     }\r
2202 \r
2203     /** Switch over to "stream printing" which is the most dense formatting without\r
2204                 linebreaks. Common when the XML is needed for network transmission.\r
2205         */\r
2206     void SetStreamPrinting()\r
2207     {\r
2208         indent = "";\r
2209         lineBreak = "";\r
2210     }\r
2211     /// Return the result.\r
2212     const char *CStr()\r
2213     {\r
2214         return buffer.c_str();\r
2215     }\r
2216     /// Return the length of the result string.\r
2217     size_t Size()\r
2218     {\r
2219         return buffer.size();\r
2220     }\r
2221 \r
2222 #ifdef TIXML_USE_STL\r
2223     /// Return the result.\r
2224     const std::string &Str()\r
2225     {\r
2226         return buffer;\r
2227     }\r
2228 #endif\r
2229 \r
2230 private:\r
2231     void DoIndent()\r
2232     {\r
2233         for (int i = 0; i < depth; ++i)\r
2234             buffer += indent;\r
2235     }\r
2236     void DoLineBreak()\r
2237     {\r
2238         buffer += lineBreak;\r
2239     }\r
2240 \r
2241     int depth;\r
2242     bool simpleTextPrint;\r
2243     TIXML_STRING buffer;\r
2244     TIXML_STRING indent;\r
2245     TIXML_STRING lineBreak;\r
2246 };\r
2247 \r
2248 #ifdef _MSC_VER\r
2249 #pragma warning(pop)\r
2250 #endif\r
2251 \r
2252 #endif\r