Crazy Eddies GUI System  0.6.2
tinyxml.h
1 /*
2 www.sourceforge.net/projects/tinyxml
3 Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
4 
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any
7 damages arising from the use of this software.
8 
9 Permission is granted to anyone to use this software for any
10 purpose, including commercial applications, and to alter it and
11 redistribute it freely, subject to the following restrictions:
12 
13 1. The origin of this software must not be misrepresented; you must
14 not claim that you wrote the original software. If you use this
15 software in a product, an acknowledgment in the product documentation
16 would be appreciated but is not required.
17 
18 2. Altered source versions must be plainly marked as such, and
19 must not be misrepresented as being the original software.
20 
21 3. This notice may not be removed or altered from any source
22 distribution.
23 */
24 
25 
26 #ifndef TINYXML_INCLUDED
27 #define TINYXML_INCLUDED
28 
29 #ifdef _MSC_VER
30 #pragma warning( push )
31 #pragma warning( disable : 4530 )
32 #pragma warning( disable : 4786 )
33 #endif
34 
35 #include <ctype.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <assert.h>
40 
41 // Help out windows:
42 #if defined( _DEBUG ) && !defined( DEBUG )
43 #define DEBUG
44 #endif
45 
46 #ifdef TIXML_USE_STL
47  #include <string>
48  #include <iostream>
49  #define TIXML_STRING std::string
50  #define TIXML_ISTREAM std::istream
51  #define TIXML_OSTREAM std::ostream
52 #else
53  #include "tinystr.h"
54  #define TIXML_STRING TiXmlString
55  #define TIXML_OSTREAM TiXmlOutStream
56 #endif
57 
58 // Deprecated library function hell. Compilers want to use the
59 // new safe versions. This probably doesn't fully address the problem,
60 // but it gets closer. There are too many compilers for me to fully
61 // test. If you get compilation troubles, undefine TIXML_SAFE
62 
63 #define TIXML_SAFE // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress.
64 #ifdef TIXML_SAFE
65  #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
66  // Microsoft visual studio, version 2005 and higher.
67  #define TIXML_SNPRINTF _snprintf_s
68  #define TIXML_SNSCANF _snscanf_s
69  #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
70  // Microsoft visual studio, version 6 and higher.
71  //#pragma message( "Using _sn* functions." )
72  #define TIXML_SNPRINTF _snprintf
73  #define TIXML_SNSCANF _snscanf
74  #elif defined(__GNUC__) && (__GNUC__ >= 3 )
75  // GCC version 3 and higher.s
76  //#warning( "Using sn* functions." )
77  #define TIXML_SNPRINTF snprintf
78  #define TIXML_SNSCANF snscanf
79  #endif
80 #endif
81 
82 namespace CEGUITinyXML
83 {
84 
85 class TiXmlDocument;
86 class TiXmlElement;
87 class TiXmlComment;
88 class TiXmlUnknown;
89 class TiXmlAttribute;
90 class TiXmlText;
91 class TiXmlDeclaration;
92 class TiXmlParsingData;
93 
94 const int TIXML_MAJOR_VERSION = 2;
95 const int TIXML_MINOR_VERSION = 4;
96 const int TIXML_PATCH_VERSION = 3;
97 
98 /* Internal structure for tracking location of items
99  in the XML file.
100 */
102 {
103  TiXmlCursor() { Clear(); }
104  void Clear() { row = col = -1; }
105 
106  int row; // 0 based.
107  int col; // 0 based.
108 };
109 
110 
111 // Only used by Attribute::Query functions
112 enum
113 {
114  TIXML_SUCCESS,
115  TIXML_NO_ATTRIBUTE,
116  TIXML_WRONG_TYPE
117 };
118 
119 
120 // Used by the parsing routines.
121 enum TiXmlEncoding
122 {
123  TIXML_ENCODING_UNKNOWN,
124  TIXML_ENCODING_UTF8,
125  TIXML_ENCODING_LEGACY
126 };
127 
128 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
129 
153 {
154  friend class TiXmlNode;
155  friend class TiXmlElement;
156  friend class TiXmlDocument;
157 
158 public:
159  TiXmlBase() : userData(0) {}
160  virtual ~TiXmlBase() {}
161 
167  virtual void Print( FILE* cfile, int depth ) const = 0;
168 
175  static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
176 
178  static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
179 
198  int Row() const { return location.row + 1; }
199  int Column() const { return location.col + 1; }
200 
201  void SetUserData( void* user ) { userData = user; }
202  void* GetUserData() { return userData; }
203 
204  // Table that returs, for a given lead byte, the total number of bytes
205  // in the UTF-8 sequence.
206  static const int utf8ByteTable[256];
207 
208  virtual const char* Parse( const char* p,
209  TiXmlParsingData* data,
210  TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
211 
212  enum
213  {
214  TIXML_NO_ERROR = 0,
215  TIXML_ERROR,
216  TIXML_ERROR_OPENING_FILE,
217  TIXML_ERROR_OUT_OF_MEMORY,
218  TIXML_ERROR_PARSING_ELEMENT,
219  TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
220  TIXML_ERROR_READING_ELEMENT_VALUE,
221  TIXML_ERROR_READING_ATTRIBUTES,
222  TIXML_ERROR_PARSING_EMPTY,
223  TIXML_ERROR_READING_END_TAG,
224  TIXML_ERROR_PARSING_UNKNOWN,
225  TIXML_ERROR_PARSING_COMMENT,
226  TIXML_ERROR_PARSING_DECLARATION,
227  TIXML_ERROR_DOCUMENT_EMPTY,
228  TIXML_ERROR_EMBEDDED_NULL,
229  TIXML_ERROR_PARSING_CDATA,
230 
231  TIXML_ERROR_STRING_COUNT
232  };
233 
234 protected:
235 
236  // See STL_STRING_BUG
237  // Utility class to overcome a bug.
239  {
240  public:
241  StringToBuffer( const TIXML_STRING& str );
242  ~StringToBuffer();
243  char* buffer;
244  };
245 
246  static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
247  inline static bool IsWhiteSpace( char c )
248  {
249  return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
250  }
251  inline static bool IsWhiteSpace( int c )
252  {
253  if ( c < 256 )
254  return IsWhiteSpace( (char) c );
255  return false; // Again, only truly correct for English/Latin...but usually works.
256  }
257 
258  virtual void StreamOut (TIXML_OSTREAM *) const = 0;
259 
260  #ifdef TIXML_USE_STL
261  static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
262  static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
263  #endif
264 
265  /* Reads an XML name into the string provided. Returns
266  a pointer just past the last character of the name,
267  or 0 if the function has an error.
268  */
269  static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
270 
271  /* Reads text. Returns a pointer past the given end tag.
272  Wickedly complex options, but it keeps the (sensitive) code in one place.
273  */
274  static const char* ReadText( const char* in, // where to start
275  TIXML_STRING* text, // the string read
276  bool ignoreWhiteSpace, // whether to keep the white space
277  const char* endTag, // what ends this text
278  bool ignoreCase, // whether to ignore case in the end tag
279  TiXmlEncoding encoding ); // the current encoding
280 
281  // If an entity has been found, transform it into a character.
282  static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
283 
284  // Get a character, while interpreting entities.
285  // The length can be from 0 to 4 bytes.
286  inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
287  {
288  assert( p );
289  if ( encoding == TIXML_ENCODING_UTF8 )
290  {
291  *length = utf8ByteTable[ *((unsigned char*)p) ];
292  assert( *length >= 0 && *length < 5 );
293  }
294  else
295  {
296  *length = 1;
297  }
298 
299  if ( *length == 1 )
300  {
301  if ( *p == '&' )
302  return GetEntity( p, _value, length, encoding );
303  *_value = *p;
304  return p+1;
305  }
306  else if ( *length )
307  {
308  //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe),
309  // and the null terminator isn't needed
310  for( int i=0; p[i] && i<*length; ++i ) {
311  _value[i] = p[i];
312  }
313  return p + (*length);
314  }
315  else
316  {
317  // Not valid text.
318  return 0;
319  }
320  }
321 
322  // Puts a string to a stream, expanding entities as it goes.
323  // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
324  static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
325 
326  static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
327 
328  // Return true if the next characters in the stream are any of the endTag sequences.
329  // Ignore case only works for english, and should only be relied on when comparing
330  // to English words: StringEqual( p, "version", true ) is fine.
331  static bool StringEqual( const char* p,
332  const char* endTag,
333  bool ignoreCase,
334  TiXmlEncoding encoding );
335 
336  static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
337 
338  TiXmlCursor location;
339 
341  void* userData;
342 
343  // None of these methods are reliable for any language except English.
344  // Good for approximation, not great for accuracy.
345  static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
346  static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
347  inline static int ToLower( int v, TiXmlEncoding encoding )
348  {
349  if ( encoding == TIXML_ENCODING_UTF8 )
350  {
351  if ( v < 128 ) return tolower( v );
352  return v;
353  }
354  else
355  {
356  return tolower( v );
357  }
358  }
359  static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
360 
361 private:
362  TiXmlBase( const TiXmlBase& ); // not implemented.
363  void operator=( const TiXmlBase& base ); // not allowed.
364 
365  struct Entity
366  {
367  const char* str;
368  unsigned int strLength;
369  char chr;
370  };
371  enum
372  {
373  NUM_ENTITY = 5,
374  MAX_ENTITY_LENGTH = 6
375 
376  };
377  static Entity entity[ NUM_ENTITY ];
378  static bool condenseWhiteSpace;
379 };
380 
381 
388 class TiXmlNode : public TiXmlBase
389 {
390  friend class TiXmlDocument;
391  friend class TiXmlElement;
392 
393 public:
394  #ifdef TIXML_USE_STL
395 
399  friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
400 
417  friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
418 
420  friend std::string& operator<< (std::string& out, const TiXmlNode& base );
421 
422  #else
423  // Used internally, not part of the public API.
424  friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
425  #endif
426 
430  enum NodeType
431  {
432  DOCUMENT,
433  ELEMENT,
434  COMMENT,
435  UNKNOWN,
436  TEXT,
437  DECLARATION,
438  TYPECOUNT
439  };
440 
441  virtual ~TiXmlNode();
442 
455  const char *Value() const { return value.c_str (); }
456 
457  #ifdef TIXML_USE_STL
458 
462  const std::string& ValueStr() const { return value; }
463  #endif
464 
474  void SetValue(const char * _value) { value = _value;}
475 
476  #ifdef TIXML_USE_STL
477 
478  void SetValue( const std::string& _value ) { value = _value; }
479  #endif
480 
482  void Clear();
483 
485  TiXmlNode* Parent() { return parent; }
486  const TiXmlNode* Parent() const { return parent; }
487 
488  const TiXmlNode* FirstChild() const { return firstChild; }
489  TiXmlNode* FirstChild() { return firstChild; }
490  const TiXmlNode* FirstChild( const char * value ) const;
491  TiXmlNode* FirstChild( const char * value );
492 
493  const TiXmlNode* LastChild() const { return lastChild; }
494  TiXmlNode* LastChild() { return lastChild; }
495  const TiXmlNode* LastChild( const char * value ) const;
496  TiXmlNode* LastChild( const char * value );
497 
498  #ifdef TIXML_USE_STL
499  const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
500  TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
501  const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
502  TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
503  #endif
504 
521  const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
522  TiXmlNode* IterateChildren( TiXmlNode* previous );
523 
525  const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
526  TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous );
527 
528  #ifdef TIXML_USE_STL
529  const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
530  TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
531  #endif
532 
536  TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
537 
538 
548  TiXmlNode* LinkEndChild( TiXmlNode* addThis );
549 
553  TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
554 
558  TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
559 
563  TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
564 
566  bool RemoveChild( TiXmlNode* removeThis );
567 
569  const TiXmlNode* PreviousSibling() const { return prev; }
570  TiXmlNode* PreviousSibling() { return prev; }
571 
573  const TiXmlNode* PreviousSibling( const char * ) const;
574  TiXmlNode* PreviousSibling( const char * );
575 
576  #ifdef TIXML_USE_STL
577  const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
578  TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
579  const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
580  TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
581  #endif
582 
584  const TiXmlNode* NextSibling() const { return next; }
585  TiXmlNode* NextSibling() { return next; }
586 
588  const TiXmlNode* NextSibling( const char * ) const;
589  TiXmlNode* NextSibling( const char * );
590 
595  const TiXmlElement* NextSiblingElement() const;
596  TiXmlElement* NextSiblingElement();
597 
602  const TiXmlElement* NextSiblingElement( const char * ) const;
603  TiXmlElement* NextSiblingElement( const char * );
604 
605  #ifdef TIXML_USE_STL
606  const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
607  TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
608  #endif
609 
611  const TiXmlElement* FirstChildElement() const;
612  TiXmlElement* FirstChildElement();
613 
615  const TiXmlElement* FirstChildElement( const char * value ) const;
616  TiXmlElement* FirstChildElement( const char * value );
617 
618  #ifdef TIXML_USE_STL
619  const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
620  TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
621  #endif
622 
627  int Type() const { return type; }
628 
632  const TiXmlDocument* GetDocument() const;
634 
636  bool NoChildren() const { return !firstChild; }
637 
638  virtual const TiXmlDocument* ToDocument() const { return 0; }
639  virtual const TiXmlElement* ToElement() const { return 0; }
640  virtual const TiXmlComment* ToComment() const { return 0; }
641  virtual const TiXmlUnknown* ToUnknown() const { return 0; }
642  virtual const TiXmlText* ToText() const { return 0; }
643  virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
644 
645  virtual TiXmlDocument* ToDocument() { return 0; }
646  virtual TiXmlElement* ToElement() { return 0; }
647  virtual TiXmlComment* ToComment() { return 0; }
648  virtual TiXmlUnknown* ToUnknown() { return 0; }
649  virtual TiXmlText* ToText() { return 0; }
650  virtual TiXmlDeclaration* ToDeclaration() { return 0; }
651 
655  virtual TiXmlNode* Clone() const = 0;
656 
657 protected:
658  TiXmlNode( NodeType _type );
659 
660  // Copy to the allocated object. Shared functionality between Clone, Copy constructor,
661  // and the assignment operator.
662  void CopyTo( TiXmlNode* target ) const;
663 
664  #ifdef TIXML_USE_STL
665  // The real work of the input operator.
666  virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
667  #endif
668 
669  // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
670  TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
671 
672  TiXmlNode* parent;
673  NodeType type;
674 
675  TiXmlNode* firstChild;
676  TiXmlNode* lastChild;
677 
678  TIXML_STRING value;
679 
680  TiXmlNode* prev;
681  TiXmlNode* next;
682 
683 private:
684  TiXmlNode( const TiXmlNode& ); // not implemented.
685  void operator=( const TiXmlNode& base ); // not allowed.
686 };
687 
688 
696 class TiXmlAttribute : public TiXmlBase
697 {
698  friend class TiXmlAttributeSet;
699 
700 public:
703  {
704  document = 0;
705  prev = next = 0;
706  }
707 
708  #ifdef TIXML_USE_STL
709 
710  TiXmlAttribute( const std::string& _name, const std::string& _value )
711  {
712  name = _name;
713  value = _value;
714  document = 0;
715  prev = next = 0;
716  }
717  #endif
718 
720  TiXmlAttribute( const char * _name, const char * _value )
721  {
722  name = _name;
723  value = _value;
724  document = 0;
725  prev = next = 0;
726  }
727 
728  const char* Name() const { return name.c_str (); }
729  const char* Value() const { return value.c_str (); }
730  int IntValue() const;
731  double DoubleValue() const;
732 
733  // Get the tinyxml string representation
734  const TIXML_STRING& NameTStr() const { return name; }
735 
745  int QueryIntValue( int* _value ) const;
747  int QueryDoubleValue( double* _value ) const;
748 
749  void SetName( const char* _name ) { name = _name; }
750  void SetValue( const char* _value ) { value = _value; }
751 
752  void SetIntValue( int _value );
753  void SetDoubleValue( double _value );
754 
755  #ifdef TIXML_USE_STL
756 
757  void SetName( const std::string& _name ) { name = _name; }
759  void SetValue( const std::string& _value ) { value = _value; }
760  #endif
761 
763  const TiXmlAttribute* Next() const;
764  TiXmlAttribute* Next();
766  const TiXmlAttribute* Previous() const;
768 
769  bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
770  bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
771  bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
772 
773  /* Attribute parsing starts: first letter of the name
774  returns: the next char after the value end quote
775  */
776  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
777 
778  // Prints this Attribute to a FILE stream.
779  virtual void Print( FILE* cfile, int depth ) const;
780 
781  virtual void StreamOut( TIXML_OSTREAM * out ) const;
782  // [internal use]
783  // Set the document pointer so the attribute can report errors.
784  void SetDocument( TiXmlDocument* doc ) { document = doc; }
785 
786 private:
787  TiXmlAttribute( const TiXmlAttribute& ); // not implemented.
788  void operator=( const TiXmlAttribute& base ); // not allowed.
789 
790  TiXmlDocument* document; // A pointer back to a document, for error reporting.
791  TIXML_STRING name;
792  TIXML_STRING value;
793  TiXmlAttribute* prev;
794  TiXmlAttribute* next;
795 };
796 
797 
798 /* A class used to manage a group of attributes.
799  It is only used internally, both by the ELEMENT and the DECLARATION.
800 
801  The set can be changed transparent to the Element and Declaration
802  classes that use it, but NOT transparent to the Attribute
803  which has to implement a next() and previous() method. Which makes
804  it a bit problematic and prevents the use of STL.
805 
806  This version is implemented with circular lists because:
807  - I like circular lists
808  - it demonstrates some independence from the (typical) doubly linked list.
809 */
811 {
812 public:
815 
816  void Add( TiXmlAttribute* attribute );
817  void Remove( TiXmlAttribute* attribute );
818 
819  const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
820  TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
821  const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
822  TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
823 
824  const TiXmlAttribute* Find( const TIXML_STRING& name ) const;
825  TiXmlAttribute* Find( const TIXML_STRING& name );
826 
827 private:
828  //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),
829  //*ME: this class must be also use a hidden/disabled copy-constructor !!!
830  TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed
831  void operator=( const TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute)
832 
833  TiXmlAttribute sentinel;
834 };
835 
836 
841 class TiXmlElement : public TiXmlNode
842 {
843 public:
845  TiXmlElement (const char * in_value);
846 
847  #ifdef TIXML_USE_STL
848 
849  TiXmlElement( const std::string& _value );
850  #endif
851 
852  TiXmlElement( const TiXmlElement& );
853 
854  void operator=( const TiXmlElement& base );
855 
856  virtual ~TiXmlElement();
857 
861  const char* Attribute( const char* name ) const;
862 
869  const char* Attribute( const char* name, int* i ) const;
870 
877  const char* Attribute( const char* name, double* d ) const;
878 
886  int QueryIntAttribute( const char* name, int* _value ) const;
888  int QueryDoubleAttribute( const char* name, double* _value ) const;
890  int QueryFloatAttribute( const char* name, float* _value ) const {
891  double d;
892  int result = QueryDoubleAttribute( name, &d );
893  if ( result == TIXML_SUCCESS ) {
894  *_value = (float)d;
895  }
896  return result;
897  }
898 
902  void SetAttribute( const char* name, const char * _value );
903 
904  #ifdef TIXML_USE_STL
905  const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
906  const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
907  const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); }
908  int QueryIntAttribute( const std::string& name, int* _value ) const { return QueryIntAttribute( name.c_str(), _value ); }
909  int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); }
910 
912  void SetAttribute( const std::string& name, const std::string& _value );
914  void SetAttribute( const std::string& name, int _value );
915  #endif
916 
920  void SetAttribute( const char * name, int value );
921 
925  void SetDoubleAttribute( const char * name, double value );
926 
929  void RemoveAttribute( const char * name );
930  #ifdef TIXML_USE_STL
931  void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
932  #endif
933 
934  const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
935  TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
936  const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
937  TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
938 
971  const char* GetText() const;
972 
974  virtual TiXmlNode* Clone() const;
975  // Print the Element to a FILE stream.
976  virtual void Print( FILE* cfile, int depth ) const;
977 
978  /* Attribtue parsing starts: next char past '<'
979  returns: next char past '>'
980  */
981  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
982 
983  virtual const TiXmlElement* ToElement() const { return this; }
984  virtual TiXmlElement* ToElement() { return this; }
985 
986 protected:
987 
988  void CopyTo( TiXmlElement* target ) const;
989  void ClearThis(); // like clear, but initializes 'this' object as well
990 
991  // Used to be public [internal use]
992  #ifdef TIXML_USE_STL
993  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
994  #endif
995  virtual void StreamOut( TIXML_OSTREAM * out ) const;
996 
997  /* [internal use]
998  Reads the "value" of the element -- another element, or text.
999  This should terminate with the current end tag.
1000  */
1001  const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1002 
1003 private:
1004 
1005  TiXmlAttributeSet attributeSet;
1006 };
1007 
1008 
1011 class TiXmlComment : public TiXmlNode
1012 {
1013 public:
1015  TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
1016  TiXmlComment( const TiXmlComment& );
1017  void operator=( const TiXmlComment& base );
1018 
1019  virtual ~TiXmlComment() {}
1020 
1022  virtual TiXmlNode* Clone() const;
1024  virtual void Print( FILE* cfile, int depth ) const;
1025 
1026  /* Attribtue parsing starts: at the ! of the !--
1027  returns: next char past '>'
1028  */
1029  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1030 
1031  virtual const TiXmlComment* ToComment() const { return this; }
1032  virtual TiXmlComment* ToComment() { return this; }
1033 
1034 protected:
1035  void CopyTo( TiXmlComment* target ) const;
1036 
1037  // used to be public
1038  #ifdef TIXML_USE_STL
1039  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1040  #endif
1041  virtual void StreamOut( TIXML_OSTREAM * out ) const;
1042 
1043 private:
1044 
1045 };
1046 
1047 
1053 class TiXmlText : public TiXmlNode
1054 {
1055  friend class TiXmlElement;
1056 public:
1061  TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
1062  {
1063  SetValue( initValue );
1064  cdata = false;
1065  }
1066  virtual ~TiXmlText() {}
1067 
1068  #ifdef TIXML_USE_STL
1069 
1070  TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
1071  {
1072  SetValue( initValue );
1073  cdata = false;
1074  }
1075  #endif
1076 
1077  TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
1078  void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
1079 
1081  virtual void Print( FILE* cfile, int depth ) const;
1082 
1084  bool CDATA() { return cdata; }
1086  void SetCDATA( bool _cdata ) { cdata = _cdata; }
1087 
1088  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1089 
1090  virtual const TiXmlText* ToText() const { return this; }
1091  virtual TiXmlText* ToText() { return this; }
1092 
1093 protected :
1095  virtual TiXmlNode* Clone() const;
1096  void CopyTo( TiXmlText* target ) const;
1097 
1098  virtual void StreamOut ( TIXML_OSTREAM * out ) const;
1099  bool Blank() const; // returns true if all white space and new lines
1100  // [internal use]
1101  #ifdef TIXML_USE_STL
1102  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1103  #endif
1104 
1105 private:
1106  bool cdata; // true if this should be input and output as a CDATA style text element
1107 };
1108 
1109 
1124 {
1125 public:
1127  TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
1128 
1129 #ifdef TIXML_USE_STL
1130 
1131  TiXmlDeclaration( const std::string& _version,
1132  const std::string& _encoding,
1133  const std::string& _standalone );
1134 #endif
1135 
1137  TiXmlDeclaration( const char* _version,
1138  const char* _encoding,
1139  const char* _standalone );
1140 
1141  TiXmlDeclaration( const TiXmlDeclaration& copy );
1142  void operator=( const TiXmlDeclaration& copy );
1143 
1144  virtual ~TiXmlDeclaration() {}
1145 
1147  const char *Version() const { return version.c_str (); }
1149  const char *Encoding() const { return encoding.c_str (); }
1151  const char *Standalone() const { return standalone.c_str (); }
1152 
1154  virtual TiXmlNode* Clone() const;
1156  virtual void Print( FILE* cfile, int depth ) const;
1157 
1158  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1159 
1160  virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
1161  virtual TiXmlDeclaration* ToDeclaration() { return this; }
1162 
1163 protected:
1164  void CopyTo( TiXmlDeclaration* target ) const;
1165  // used to be public
1166  #ifdef TIXML_USE_STL
1167  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1168  #endif
1169  virtual void StreamOut ( TIXML_OSTREAM * out) const;
1170 
1171 private:
1172 
1173  TIXML_STRING version;
1174  TIXML_STRING encoding;
1175  TIXML_STRING standalone;
1176 };
1177 
1178 
1186 class TiXmlUnknown : public TiXmlNode
1187 {
1188 public:
1189  TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
1190  virtual ~TiXmlUnknown() {}
1191 
1192  TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
1193  void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
1194 
1196  virtual TiXmlNode* Clone() const;
1198  virtual void Print( FILE* cfile, int depth ) const;
1199 
1200  virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1201 
1202  virtual const TiXmlUnknown* ToUnknown() const { return this; }
1203  virtual TiXmlUnknown* ToUnknown() { return this; }
1204 
1205 protected:
1206  void CopyTo( TiXmlUnknown* target ) const;
1207 
1208  #ifdef TIXML_USE_STL
1209  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1210  #endif
1211  virtual void StreamOut ( TIXML_OSTREAM * out ) const;
1212 
1213 private:
1214 
1215 };
1216 
1217 
1222 class TiXmlDocument : public TiXmlNode
1223 {
1224 public:
1226  TiXmlDocument();
1228  TiXmlDocument( const char * documentName );
1229 
1230  #ifdef TIXML_USE_STL
1231 
1232  TiXmlDocument( const std::string& documentName );
1233  #endif
1234 
1235  TiXmlDocument( const TiXmlDocument& copy );
1236  void operator=( const TiXmlDocument& copy );
1237 
1238  virtual ~TiXmlDocument() {}
1239 
1244  bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1246  bool SaveFile() const;
1248  bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1250  bool SaveFile( const char * filename ) const;
1256  bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1258  bool SaveFile( FILE* ) const;
1259 
1260  #ifdef TIXML_USE_STL
1261  bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
1262  {
1263  StringToBuffer f( filename );
1264  return ( f.buffer && LoadFile( f.buffer, encoding ));
1265  }
1266  bool SaveFile( const std::string& filename ) const
1267  {
1268  StringToBuffer f( filename );
1269  return ( f.buffer && SaveFile( f.buffer ));
1270  }
1271  #endif
1272 
1277  virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1278 
1283  const TiXmlElement* RootElement() const { return FirstChildElement(); }
1284  TiXmlElement* RootElement() { return FirstChildElement(); }
1285 
1291  bool Error() const { return error; }
1292 
1294  const char * ErrorDesc() const { return errorDesc.c_str (); }
1295 
1299  int ErrorId() const { return errorId; }
1300 
1308  int ErrorRow() { return errorLocation.row+1; }
1309  int ErrorCol() { return errorLocation.col+1; }
1310 
1335  void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
1336 
1337  int TabSize() const { return tabsize; }
1338 
1342  void ClearError() { error = false;
1343  errorId = 0;
1344  errorDesc = "";
1345  errorLocation.row = errorLocation.col = 0;
1346  //errorLocation.last = 0;
1347  }
1348 
1350  void Print() const { Print( stdout, 0 ); }
1351 
1353  virtual void Print( FILE* cfile, int depth = 0 ) const;
1354  // [internal use]
1355  void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1356 
1357  virtual const TiXmlDocument* ToDocument() const { return this; }
1358  virtual TiXmlDocument* ToDocument() { return this; }
1359 
1360 protected :
1361  virtual void StreamOut ( TIXML_OSTREAM * out) const;
1362  // [internal use]
1363  virtual TiXmlNode* Clone() const;
1364  #ifdef TIXML_USE_STL
1365  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1366  #endif
1367 
1368 private:
1369  void CopyTo( TiXmlDocument* target ) const;
1370 
1371  bool error;
1372  int errorId;
1373  TIXML_STRING errorDesc;
1374  int tabsize;
1375  TiXmlCursor errorLocation;
1376  bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write.
1377 };
1378 
1379 
1461 {
1462 public:
1464  TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
1466  TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
1467  TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
1468 
1470  TiXmlHandle FirstChild() const;
1472  TiXmlHandle FirstChild( const char * value ) const;
1476  TiXmlHandle FirstChildElement( const char * value ) const;
1477 
1481  TiXmlHandle Child( const char* value, int index ) const;
1485  TiXmlHandle Child( int index ) const;
1490  TiXmlHandle ChildElement( const char* value, int index ) const;
1495  TiXmlHandle ChildElement( int index ) const;
1496 
1497  #ifdef TIXML_USE_STL
1498  TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
1499  TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
1500 
1501  TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
1502  TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
1503  #endif
1504 
1506  TiXmlNode* Node() const { return node; }
1508  TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
1510  TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
1512  TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
1513 
1514 private:
1515  TiXmlNode* node;
1516 };
1517 
1518 }
1519 #ifdef _MSC_VER
1520 #pragma warning( pop )
1521 #endif
1522 
1523 #endif
1524