Openholo  v5.0
Open Source Digital Holographic Library
tinyxml2.h
Go to the documentation of this file.
1 /*
2 Original code by Lee Thomason (www.grinninglizard.com)
3 
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any
6 damages arising from the use of this software.
7 
8 Permission is granted to anyone to use this software for any
9 purpose, including commercial applications, and to alter it and
10 redistribute it freely, subject to the following restrictions:
11 
12 1. The origin of this software must not be misrepresented; you must
13 not claim that you wrote the original software. If you use this
14 software in a product, an acknowledgment in the product documentation
15 would be appreciated but is not required.
16 
17 2. Altered source versions must be plainly marked as such, and
18 must not be misrepresented as being the original software.
19 
20 3. This notice may not be removed or altered from any source
21 distribution.
22 */
23 
24 #ifndef TINYXML2_INCLUDED
25 #define TINYXML2_INCLUDED
26 
27 #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
28 # include <ctype.h>
29 # include <limits.h>
30 # include <stdio.h>
31 # include <stdlib.h>
32 # include <string.h>
33 # if defined(__PS3__)
34 # include <stddef.h>
35 # endif
36 #else
37 # include <cctype>
38 # include <climits>
39 # include <cstdio>
40 # include <cstdlib>
41 # include <cstring>
42 #endif
43 #include <stdint.h>
44 
45 /*
46  TODO: intern strings instead of allocation.
47 */
48 /*
49  gcc:
50  g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
51 
52  Formatting, Artistic Style:
53  AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
54 */
55 
56 #if defined( _DEBUG ) || defined (__DEBUG__)
57 # ifndef TINYXML2_DEBUG
58 # define TINYXML2_DEBUG
59 # endif
60 #endif
61 
62 #ifdef _MSC_VER
63 # pragma warning(push)
64 # pragma warning(disable: 4251)
65 #endif
66 
67 #ifdef _WIN32
68 # ifdef TINYXML2_EXPORT
69 # define TINYXML2_LIB __declspec(dllexport)
70 # elif defined(TINYXML2_IMPORT)
71 # define TINYXML2_LIB __declspec(dllimport)
72 # else
73 # define TINYXML2_LIB
74 # endif
75 #elif __GNUC__ >= 4
76 # define TINYXML2_LIB __attribute__((visibility("default")))
77 #else
78 # define TINYXML2_LIB
79 #endif
80 
81 
82 #if defined(TINYXML2_DEBUG)
83 # if defined(_MSC_VER)
84 # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
85 # define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); }
86 # elif defined (ANDROID_NDK)
87 # include <android/log.h>
88 # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
89 # else
90 # include <assert.h>
91 # define TIXMLASSERT assert
92 # endif
93 #else
94 # define TIXMLASSERT( x ) {}
95 #endif
96 
97 
98 /* Versioning, past 1.0.14:
99  http://semver.org/
100 */
101 static const int TIXML2_MAJOR_VERSION = 6;
102 static const int TIXML2_MINOR_VERSION = 2;
103 static const int TIXML2_PATCH_VERSION = 0;
104 
105 #define TINYXML2_MAJOR_VERSION 6
106 #define TINYXML2_MINOR_VERSION 2
107 #define TINYXML2_PATCH_VERSION 0
108 
109 // A fixed element depth limit is problematic. There needs to be a
110 // limit to avoid a stack overflow. However, that limit varies per
111 // system, and the capacity of the stack. On the other hand, it's a trivial
112 // attack that can result from ill, malicious, or even correctly formed XML,
113 // so there needs to be a limit in place.
114 static const int TINYXML2_MAX_ELEMENT_DEPTH = 100;
115 
116 namespace tinyxml2
117 {
118 class XMLDocument;
119 class XMLElement;
120 class XMLAttribute;
121 class XMLComment;
122 class XMLText;
123 class XMLDeclaration;
124 class XMLUnknown;
125 class XMLPrinter;
126 
127 /*
128  A class that wraps strings. Normally stores the start and end
129  pointers into the XML file itself, and will apply normalization
130  and entity translation if actually read. Can also store (and memory
131  manage) a traditional char[]
132 */
133 class StrPair
134 {
135 public:
136  enum {
140 
147  };
148 
149  StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
150  ~StrPair();
151 
152  void Set( char* start, char* end, int flags ) {
153  TIXMLASSERT( start );
154  TIXMLASSERT( end );
155  Reset();
156  _start = start;
157  _end = end;
158  _flags = flags | NEEDS_FLUSH;
159  }
160 
161  const char* GetStr();
162 
163  bool Empty() const {
164  return _start == _end;
165  }
166 
167  void SetInternedStr( const char* str ) {
168  Reset();
169  _start = const_cast<char*>(str);
170  }
171 
172  void SetStr( const char* str, int flags=0 );
173 
174  char* ParseText( char* in, const char* endTag, int strFlags, int* curLineNumPtr );
175  char* ParseName( char* in );
176 
177  void TransferTo( StrPair* other );
178  void Reset();
179 
180 private:
181  void CollapseWhitespace();
182 
183  enum {
184  NEEDS_FLUSH = 0x100,
185  NEEDS_DELETE = 0x200
186  };
187 
188  int _flags;
189  char* _start;
190  char* _end;
191 
192  StrPair( const StrPair& other ); // not supported
193  void operator=( StrPair& other ); // not supported, use TransferTo()
194 };
195 
196 
197 /*
198  A dynamic array of Plain Old Data. Doesn't support constructors, etc.
199  Has a small initial memory pool, so that low or no usage will not
200  cause a call to new/delete
201 */
202 template <class T, int INITIAL_SIZE>
203 class DynArray
204 {
205 public:
207  _mem( _pool ),
208  _allocated( INITIAL_SIZE ),
209  _size( 0 )
210  {
211  }
212 
214  if ( _mem != _pool ) {
215  delete [] _mem;
216  }
217  }
218 
219  void Clear() {
220  _size = 0;
221  }
222 
223  void Push( T t ) {
224  TIXMLASSERT( _size < INT_MAX );
225  EnsureCapacity( _size+1 );
226  _mem[_size] = t;
227  ++_size;
228  }
229 
230  T* PushArr( int count ) {
231  TIXMLASSERT( count >= 0 );
232  TIXMLASSERT( _size <= INT_MAX - count );
233  EnsureCapacity( _size+count );
234  T* ret = &_mem[_size];
235  _size += count;
236  return ret;
237  }
238 
239  T Pop() {
240  TIXMLASSERT( _size > 0 );
241  --_size;
242  return _mem[_size];
243  }
244 
245  void PopArr( int count ) {
246  TIXMLASSERT( _size >= count );
247  _size -= count;
248  }
249 
250  bool Empty() const {
251  return _size == 0;
252  }
253 
254  T& operator[](int i) {
255  TIXMLASSERT( i>= 0 && i < _size );
256  return _mem[i];
257  }
258 
259  const T& operator[](int i) const {
260  TIXMLASSERT( i>= 0 && i < _size );
261  return _mem[i];
262  }
263 
264  const T& PeekTop() const {
265  TIXMLASSERT( _size > 0 );
266  return _mem[ _size - 1];
267  }
268 
269  int Size() const {
270  TIXMLASSERT( _size >= 0 );
271  return _size;
272  }
273 
274  int Capacity() const {
275  TIXMLASSERT( _allocated >= INITIAL_SIZE );
276  return _allocated;
277  }
278 
279  void SwapRemove(int i) {
280  TIXMLASSERT(i >= 0 && i < _size);
281  TIXMLASSERT(_size > 0);
282  _mem[i] = _mem[_size - 1];
283  --_size;
284  }
285 
286  const T* Mem() const {
287  TIXMLASSERT( _mem );
288  return _mem;
289  }
290 
291  T* Mem() {
292  TIXMLASSERT( _mem );
293  return _mem;
294  }
295 
296 private:
297  DynArray( const DynArray& ); // not supported
298  void operator=( const DynArray& ); // not supported
299 
300  void EnsureCapacity( int cap ) {
301  TIXMLASSERT( cap > 0 );
302  if ( cap > _allocated ) {
303  TIXMLASSERT( cap <= INT_MAX / 2 );
304  int newAllocated = cap * 2;
305  T* newMem = new T[newAllocated];
306  TIXMLASSERT( newAllocated >= _size );
307  memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
308  if ( _mem != _pool ) {
309  delete [] _mem;
310  }
311  _mem = newMem;
312  _allocated = newAllocated;
313  }
314  }
315 
316  T* _mem;
317  T _pool[INITIAL_SIZE];
318  int _allocated; // objects allocated
319  int _size; // number objects in use
320 };
321 
322 
323 /*
324  Parent virtual class of a pool for fast allocation
325  and deallocation of objects.
326 */
327 class MemPool
328 {
329 public:
330  MemPool() {}
331  virtual ~MemPool() {}
332 
333  virtual int ItemSize() const = 0;
334  virtual void* Alloc() = 0;
335  virtual void Free( void* ) = 0;
336  virtual void SetTracked() = 0;
337  virtual void Clear() = 0;
338 };
339 
340 
341 /*
342  Template child class to create pools of the correct type.
343 */
344 template< int ITEM_SIZE >
345 class MemPoolT : public MemPool
346 {
347 public:
348  MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
350  Clear();
351  }
352 
353  void Clear() {
354  // Delete the blocks.
355  while( !_blockPtrs.Empty()) {
356  Block* lastBlock = _blockPtrs.Pop();
357  delete lastBlock;
358  }
359  _root = 0;
360  _currentAllocs = 0;
361  _nAllocs = 0;
362  _maxAllocs = 0;
363  _nUntracked = 0;
364  }
365 
366  virtual int ItemSize() const {
367  return ITEM_SIZE;
368  }
369  int CurrentAllocs() const {
370  return _currentAllocs;
371  }
372 
373  virtual void* Alloc() {
374  if ( !_root ) {
375  // Need a new block.
376  Block* block = new Block();
377  _blockPtrs.Push( block );
378 
379  Item* blockItems = block->items;
380  for( int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
381  blockItems[i].next = &(blockItems[i + 1]);
382  }
383  blockItems[ITEMS_PER_BLOCK - 1].next = 0;
384  _root = blockItems;
385  }
386  Item* const result = _root;
387  TIXMLASSERT( result != 0 );
388  _root = _root->next;
389 
390  ++_currentAllocs;
391  if ( _currentAllocs > _maxAllocs ) {
392  _maxAllocs = _currentAllocs;
393  }
394  ++_nAllocs;
395  ++_nUntracked;
396  return result;
397  }
398 
399  virtual void Free( void* mem ) {
400  if ( !mem ) {
401  return;
402  }
403  --_currentAllocs;
404  Item* item = static_cast<Item*>( mem );
405 #ifdef TINYXML2_DEBUG
406  memset( item, 0xfe, sizeof( *item ) );
407 #endif
408  item->next = _root;
409  _root = item;
410  }
411  void Trace( const char* name ) {
412  printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
413  name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs,
414  ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
415  }
416 
417  void SetTracked() {
418  --_nUntracked;
419  }
420 
421  int Untracked() const {
422  return _nUntracked;
423  }
424 
425  // This number is perf sensitive. 4k seems like a good tradeoff on my machine.
426  // The test file is large, 170k.
427  // Release: VS2010 gcc(no opt)
428  // 1k: 4000
429  // 2k: 4000
430  // 4k: 3900 21000
431  // 16k: 5200
432  // 32k: 4300
433  // 64k: 4000 21000
434  // Declared public because some compilers do not accept to use ITEMS_PER_BLOCK
435  // in private part if ITEMS_PER_BLOCK is private
436  enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE };
437 
438 private:
439  MemPoolT( const MemPoolT& ); // not supported
440  void operator=( const MemPoolT& ); // not supported
441 
442  union Item {
443  Item* next;
444  char itemData[ITEM_SIZE];
445  };
446  struct Block {
447  Item items[ITEMS_PER_BLOCK];
448  };
449  DynArray< Block*, 10 > _blockPtrs;
450  Item* _root;
451 
452  int _currentAllocs;
453  int _nAllocs;
454  int _maxAllocs;
455  int _nUntracked;
456 };
457 
458 
459 
480 {
481 public:
482  virtual ~XMLVisitor() {}
483 
485  virtual bool VisitEnter( const XMLDocument& /*doc*/ ) {
486  return true;
487  }
489  virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
490  return true;
491  }
492 
494  virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) {
495  return true;
496  }
498  virtual bool VisitExit( const XMLElement& /*element*/ ) {
499  return true;
500  }
501 
503  virtual bool Visit( const XMLDeclaration& /*declaration*/ ) {
504  return true;
505  }
507  virtual bool Visit( const XMLText& /*text*/ ) {
508  return true;
509  }
511  virtual bool Visit( const XMLComment& /*comment*/ ) {
512  return true;
513  }
515  virtual bool Visit( const XMLUnknown& /*unknown*/ ) {
516  return true;
517  }
518 };
519 
520 // WARNING: must match XMLDocument::_errorNames[]
521 enum XMLError {
541 
543 };
544 
545 
546 /*
547  Utility functionality.
548 */
550 {
551 public:
552  static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) {
553  TIXMLASSERT( p );
554 
555  while( IsWhiteSpace(*p) ) {
556  if (curLineNumPtr && *p == '\n') {
557  ++(*curLineNumPtr);
558  }
559  ++p;
560  }
561  TIXMLASSERT( p );
562  return p;
563  }
564  static char* SkipWhiteSpace( char* p, int* curLineNumPtr ) {
565  return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p), curLineNumPtr ) );
566  }
567 
568  // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
569  // correct, but simple, and usually works.
570  static bool IsWhiteSpace( char p ) {
571  return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
572  }
573 
574  inline static bool IsNameStartChar( unsigned char ch ) {
575  if ( ch >= 128 ) {
576  // This is a heuristic guess in attempt to not implement Unicode-aware isalpha()
577  return true;
578  }
579  if ( isalpha( ch ) ) {
580  return true;
581  }
582  return ch == ':' || ch == '_';
583  }
584 
585  inline static bool IsNameChar( unsigned char ch ) {
586  return IsNameStartChar( ch )
587  || isdigit( ch )
588  || ch == '.'
589  || ch == '-';
590  }
591 
592  inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
593  if ( p == q ) {
594  return true;
595  }
596  TIXMLASSERT( p );
597  TIXMLASSERT( q );
598  TIXMLASSERT( nChar >= 0 );
599  return strncmp( p, q, nChar ) == 0;
600  }
601 
602  inline static bool IsUTF8Continuation( char p ) {
603  return ( p & 0x80 ) != 0;
604  }
605 
606  static const char* ReadBOM( const char* p, bool* hasBOM );
607  // p is the starting location,
608  // the UTF-8 value of the entity will be placed in value, and length filled in.
609  static const char* GetCharacterRef( const char* p, char* value, int* length );
610  static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
611 
612  // converts primitive types to strings
613  static void ToStr( int v, char* buffer, int bufferSize );
614  static void ToStr( unsigned v, char* buffer, int bufferSize );
615  static void ToStr( bool v, char* buffer, int bufferSize );
616  static void ToStr( float v, char* buffer, int bufferSize );
617  static void ToStr( double v, char* buffer, int bufferSize );
618  static void ToStr(int64_t v, char* buffer, int bufferSize);
619 
620  // converts strings to primitive types
621  static bool ToInt( const char* str, int* value );
622  static bool ToUnsigned( const char* str, unsigned* value );
623  static bool ToBool( const char* str, bool* value );
624  static bool ToFloat( const char* str, float* value );
625  static bool ToDouble( const char* str, double* value );
626  static bool ToInt64(const char* str, int64_t* value);
627 
628  // Changes what is serialized for a boolean value.
629  // Default to "true" and "false". Shouldn't be changed
630  // unless you have a special testing or compatibility need.
631  // Be careful: static, global, & not thread safe.
632  // Be sure to set static const memory as parameters.
633  static void SetBoolSerialization(const char* writeTrue, const char* writeFalse);
634 
635 private:
636  static const char* writeBoolTrue;
637  static const char* writeBoolFalse;
638 };
639 
640 
667 {
668  friend class XMLDocument;
669  friend class XMLElement;
670 public:
671 
673  const XMLDocument* GetDocument() const {
674  TIXMLASSERT( _document );
675  return _document;
676  }
679  TIXMLASSERT( _document );
680  return _document;
681  }
682 
684  virtual XMLElement* ToElement() {
685  return 0;
686  }
688  virtual XMLText* ToText() {
689  return 0;
690  }
692  virtual XMLComment* ToComment() {
693  return 0;
694  }
696  virtual XMLDocument* ToDocument() {
697  return 0;
698  }
701  return 0;
702  }
704  virtual XMLUnknown* ToUnknown() {
705  return 0;
706  }
707 
708  virtual const XMLElement* ToElement() const {
709  return 0;
710  }
711  virtual const XMLText* ToText() const {
712  return 0;
713  }
714  virtual const XMLComment* ToComment() const {
715  return 0;
716  }
717  virtual const XMLDocument* ToDocument() const {
718  return 0;
719  }
720  virtual const XMLDeclaration* ToDeclaration() const {
721  return 0;
722  }
723  virtual const XMLUnknown* ToUnknown() const {
724  return 0;
725  }
726 
736  const char* Value() const;
737 
741  void SetValue( const char* val, bool staticMem=false );
742 
744  int GetLineNum() const { return _parseLineNum; }
745 
747  const XMLNode* Parent() const {
748  return _parent;
749  }
750 
752  return _parent;
753  }
754 
756  bool NoChildren() const {
757  return !_firstChild;
758  }
759 
761  const XMLNode* FirstChild() const {
762  return _firstChild;
763  }
764 
766  return _firstChild;
767  }
768 
772  const XMLElement* FirstChildElement( const char* name = 0 ) const;
773 
774  XMLElement* FirstChildElement( const char* name = 0 ) {
775  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name ));
776  }
777 
779  const XMLNode* LastChild() const {
780  return _lastChild;
781  }
782 
784  return _lastChild;
785  }
786 
790  const XMLElement* LastChildElement( const char* name = 0 ) const;
791 
792  XMLElement* LastChildElement( const char* name = 0 ) {
793  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) );
794  }
795 
797  const XMLNode* PreviousSibling() const {
798  return _prev;
799  }
800 
802  return _prev;
803  }
804 
806  const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ;
807 
808  XMLElement* PreviousSiblingElement( const char* name = 0 ) {
809  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) );
810  }
811 
813  const XMLNode* NextSibling() const {
814  return _next;
815  }
816 
818  return _next;
819  }
820 
822  const XMLElement* NextSiblingElement( const char* name = 0 ) const;
823 
824  XMLElement* NextSiblingElement( const char* name = 0 ) {
825  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) );
826  }
827 
835  XMLNode* InsertEndChild( XMLNode* addThis );
836 
837  XMLNode* LinkEndChild( XMLNode* addThis ) {
838  return InsertEndChild( addThis );
839  }
847  XMLNode* InsertFirstChild( XMLNode* addThis );
856  XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
857 
861  void DeleteChildren();
862 
866  void DeleteChild( XMLNode* node );
867 
877  virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
878 
892  XMLNode* DeepClone( XMLDocument* target ) const;
893 
900  virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
901 
924  virtual bool Accept( XMLVisitor* visitor ) const = 0;
925 
931  void SetUserData(void* userData) { _userData = userData; }
932 
938  void* GetUserData() const { return _userData; }
939 
940 protected:
941  XMLNode( XMLDocument* );
942  virtual ~XMLNode();
943 
944  virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
945 
948  mutable StrPair _value;
950 
953 
956 
957  void* _userData;
958 
959 private:
960  MemPool* _memPool;
961  void Unlink( XMLNode* child );
962  static void DeleteNode( XMLNode* node );
963  void InsertChildPreamble( XMLNode* insertThis ) const;
964  const XMLElement* ToElementWithName( const char* name ) const;
965 
966  XMLNode( const XMLNode& ); // not supported
967  XMLNode& operator=( const XMLNode& ); // not supported
968 };
969 
970 
984 {
985  friend class XMLDocument;
986 public:
987  virtual bool Accept( XMLVisitor* visitor ) const;
988 
989  virtual XMLText* ToText() {
990  return this;
991  }
992  virtual const XMLText* ToText() const {
993  return this;
994  }
995 
997  void SetCData( bool isCData ) {
998  _isCData = isCData;
999  }
1001  bool CData() const {
1002  return _isCData;
1003  }
1004 
1005  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1006  virtual bool ShallowEqual( const XMLNode* compare ) const;
1007 
1008 protected:
1009  XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
1010  virtual ~XMLText() {}
1011 
1012  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1013 
1014 private:
1015  bool _isCData;
1016 
1017  XMLText( const XMLText& ); // not supported
1018  XMLText& operator=( const XMLText& ); // not supported
1019 };
1020 
1021 
1024 {
1025  friend class XMLDocument;
1026 public:
1027  virtual XMLComment* ToComment() {
1028  return this;
1029  }
1030  virtual const XMLComment* ToComment() const {
1031  return this;
1032  }
1033 
1034  virtual bool Accept( XMLVisitor* visitor ) const;
1035 
1036  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1037  virtual bool ShallowEqual( const XMLNode* compare ) const;
1038 
1039 protected:
1040  XMLComment( XMLDocument* doc );
1041  virtual ~XMLComment();
1042 
1043  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
1044 
1045 private:
1046  XMLComment( const XMLComment& ); // not supported
1047  XMLComment& operator=( const XMLComment& ); // not supported
1048 };
1049 
1050 
1063 {
1064  friend class XMLDocument;
1065 public:
1067  return this;
1068  }
1069  virtual const XMLDeclaration* ToDeclaration() const {
1070  return this;
1071  }
1072 
1073  virtual bool Accept( XMLVisitor* visitor ) const;
1074 
1075  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1076  virtual bool ShallowEqual( const XMLNode* compare ) const;
1077 
1078 protected:
1079  XMLDeclaration( XMLDocument* doc );
1080  virtual ~XMLDeclaration();
1081 
1082  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1083 
1084 private:
1085  XMLDeclaration( const XMLDeclaration& ); // not supported
1086  XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
1087 };
1088 
1089 
1098 {
1099  friend class XMLDocument;
1100 public:
1101  virtual XMLUnknown* ToUnknown() {
1102  return this;
1103  }
1104  virtual const XMLUnknown* ToUnknown() const {
1105  return this;
1106  }
1107 
1108  virtual bool Accept( XMLVisitor* visitor ) const;
1109 
1110  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1111  virtual bool ShallowEqual( const XMLNode* compare ) const;
1112 
1113 protected:
1114  XMLUnknown( XMLDocument* doc );
1115  virtual ~XMLUnknown();
1116 
1117  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1118 
1119 private:
1120  XMLUnknown( const XMLUnknown& ); // not supported
1121  XMLUnknown& operator=( const XMLUnknown& ); // not supported
1122 };
1123 
1124 
1125 
1133 {
1134  friend class XMLElement;
1135 public:
1137  const char* Name() const;
1138 
1140  const char* Value() const;
1141 
1143  int GetLineNum() const { return _parseLineNum; }
1144 
1146  const XMLAttribute* Next() const {
1147  return _next;
1148  }
1149 
1154  int IntValue() const {
1155  int i = 0;
1156  QueryIntValue(&i);
1157  return i;
1158  }
1159 
1160  int64_t Int64Value() const {
1161  int64_t i = 0;
1162  QueryInt64Value(&i);
1163  return i;
1164  }
1165 
1167  unsigned UnsignedValue() const {
1168  unsigned i=0;
1169  QueryUnsignedValue( &i );
1170  return i;
1171  }
1173  bool BoolValue() const {
1174  bool b=false;
1175  QueryBoolValue( &b );
1176  return b;
1177  }
1179  double DoubleValue() const {
1180  double d=0;
1181  QueryDoubleValue( &d );
1182  return d;
1183  }
1185  float FloatValue() const {
1186  float f=0;
1187  QueryFloatValue( &f );
1188  return f;
1189  }
1190 
1195  XMLError QueryIntValue( int* value ) const;
1197  XMLError QueryUnsignedValue( unsigned int* value ) const;
1199  XMLError QueryInt64Value(int64_t* value) const;
1201  XMLError QueryBoolValue( bool* value ) const;
1203  XMLError QueryDoubleValue( double* value ) const;
1205  XMLError QueryFloatValue( float* value ) const;
1206 
1208  void SetAttribute( const char* value );
1210  void SetAttribute( int value );
1212  void SetAttribute( unsigned value );
1214  void SetAttribute(int64_t value);
1216  void SetAttribute( bool value );
1218  void SetAttribute( double value );
1220  void SetAttribute( float value );
1221 
1222 private:
1223  enum { BUF_SIZE = 200 };
1224 
1225  XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
1226  virtual ~XMLAttribute() {}
1227 
1228  XMLAttribute( const XMLAttribute& ); // not supported
1229  void operator=( const XMLAttribute& ); // not supported
1230  void SetName( const char* name );
1231 
1232  char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr );
1233 
1234  mutable StrPair _name;
1235  mutable StrPair _value;
1236  int _parseLineNum;
1237  XMLAttribute* _next;
1238  MemPool* _memPool;
1239 };
1240 
1241 
1247 {
1248  friend class XMLDocument;
1249 public:
1251  const char* Name() const {
1252  return Value();
1253  }
1255  void SetName( const char* str, bool staticMem=false ) {
1256  SetValue( str, staticMem );
1257  }
1258 
1259  virtual XMLElement* ToElement() {
1260  return this;
1261  }
1262  virtual const XMLElement* ToElement() const {
1263  return this;
1264  }
1265  virtual bool Accept( XMLVisitor* visitor ) const;
1266 
1290  const char* Attribute( const char* name, const char* value=0 ) const;
1291 
1298  int IntAttribute(const char* name, int defaultValue = 0) const;
1300  unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const;
1302  int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const;
1304  bool BoolAttribute(const char* name, bool defaultValue = false) const;
1306  double DoubleAttribute(const char* name, double defaultValue = 0) const;
1308  float FloatAttribute(const char* name, float defaultValue = 0) const;
1309 
1323  XMLError QueryIntAttribute( const char* name, int* value ) const {
1324  const XMLAttribute* a = FindAttribute( name );
1325  if ( !a ) {
1326  return XML_NO_ATTRIBUTE;
1327  }
1328  return a->QueryIntValue( value );
1329  }
1330 
1332  XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
1333  const XMLAttribute* a = FindAttribute( name );
1334  if ( !a ) {
1335  return XML_NO_ATTRIBUTE;
1336  }
1337  return a->QueryUnsignedValue( value );
1338  }
1339 
1341  XMLError QueryInt64Attribute(const char* name, int64_t* value) const {
1342  const XMLAttribute* a = FindAttribute(name);
1343  if (!a) {
1344  return XML_NO_ATTRIBUTE;
1345  }
1346  return a->QueryInt64Value(value);
1347  }
1348 
1350  XMLError QueryBoolAttribute( const char* name, bool* value ) const {
1351  const XMLAttribute* a = FindAttribute( name );
1352  if ( !a ) {
1353  return XML_NO_ATTRIBUTE;
1354  }
1355  return a->QueryBoolValue( value );
1356  }
1358  XMLError QueryDoubleAttribute( const char* name, double* value ) const {
1359  const XMLAttribute* a = FindAttribute( name );
1360  if ( !a ) {
1361  return XML_NO_ATTRIBUTE;
1362  }
1363  return a->QueryDoubleValue( value );
1364  }
1366  XMLError QueryFloatAttribute( const char* name, float* value ) const {
1367  const XMLAttribute* a = FindAttribute( name );
1368  if ( !a ) {
1369  return XML_NO_ATTRIBUTE;
1370  }
1371  return a->QueryFloatValue( value );
1372  }
1373 
1375  XMLError QueryStringAttribute(const char* name, const char** value) const {
1376  const XMLAttribute* a = FindAttribute(name);
1377  if (!a) {
1378  return XML_NO_ATTRIBUTE;
1379  }
1380  *value = a->Value();
1381  return XML_SUCCESS;
1382  }
1383 
1384 
1385 
1403  XMLError QueryAttribute( const char* name, int* value ) const {
1404  return QueryIntAttribute( name, value );
1405  }
1406 
1407  XMLError QueryAttribute( const char* name, unsigned int* value ) const {
1408  return QueryUnsignedAttribute( name, value );
1409  }
1410 
1411  XMLError QueryAttribute(const char* name, int64_t* value) const {
1412  return QueryInt64Attribute(name, value);
1413  }
1414 
1415  XMLError QueryAttribute( const char* name, bool* value ) const {
1416  return QueryBoolAttribute( name, value );
1417  }
1418 
1419  XMLError QueryAttribute( const char* name, double* value ) const {
1420  return QueryDoubleAttribute( name, value );
1421  }
1422 
1423  XMLError QueryAttribute( const char* name, float* value ) const {
1424  return QueryFloatAttribute( name, value );
1425  }
1426 
1428  void SetAttribute( const char* name, const char* value ) {
1429  XMLAttribute* a = FindOrCreateAttribute( name );
1430  a->SetAttribute( value );
1431  }
1433  void SetAttribute( const char* name, int value ) {
1434  XMLAttribute* a = FindOrCreateAttribute( name );
1435  a->SetAttribute( value );
1436  }
1438  void SetAttribute( const char* name, unsigned value ) {
1439  XMLAttribute* a = FindOrCreateAttribute( name );
1440  a->SetAttribute( value );
1441  }
1442 
1444  void SetAttribute(const char* name, int64_t value) {
1445  XMLAttribute* a = FindOrCreateAttribute(name);
1446  a->SetAttribute(value);
1447  }
1448 
1450  void SetAttribute( const char* name, bool value ) {
1451  XMLAttribute* a = FindOrCreateAttribute( name );
1452  a->SetAttribute( value );
1453  }
1455  void SetAttribute( const char* name, double value ) {
1456  XMLAttribute* a = FindOrCreateAttribute( name );
1457  a->SetAttribute( value );
1458  }
1460  void SetAttribute( const char* name, float value ) {
1461  XMLAttribute* a = FindOrCreateAttribute( name );
1462  a->SetAttribute( value );
1463  }
1464 
1468  void DeleteAttribute( const char* name );
1469 
1471  const XMLAttribute* FirstAttribute() const {
1472  return _rootAttribute;
1473  }
1475  const XMLAttribute* FindAttribute( const char* name ) const;
1476 
1505  const char* GetText() const;
1506 
1541  void SetText( const char* inText );
1543  void SetText( int value );
1545  void SetText( unsigned value );
1547  void SetText(int64_t value);
1549  void SetText( bool value );
1551  void SetText( double value );
1553  void SetText( float value );
1554 
1581  XMLError QueryIntText( int* ival ) const;
1583  XMLError QueryUnsignedText( unsigned* uval ) const;
1585  XMLError QueryInt64Text(int64_t* uval) const;
1587  XMLError QueryBoolText( bool* bval ) const;
1589  XMLError QueryDoubleText( double* dval ) const;
1591  XMLError QueryFloatText( float* fval ) const;
1592 
1593  int IntText(int defaultValue = 0) const;
1594 
1596  unsigned UnsignedText(unsigned defaultValue = 0) const;
1598  int64_t Int64Text(int64_t defaultValue = 0) const;
1600  bool BoolText(bool defaultValue = false) const;
1602  double DoubleText(double defaultValue = 0) const;
1604  float FloatText(float defaultValue = 0) const;
1605 
1606  // internal:
1608  OPEN, // <foo>
1609  CLOSED, // <foo/>
1610  CLOSING // </foo>
1611  };
1613  return _closingType;
1614  }
1615  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1616  virtual bool ShallowEqual( const XMLNode* compare ) const;
1617 
1618 protected:
1619  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1620 
1621 private:
1622  XMLElement( XMLDocument* doc );
1623  virtual ~XMLElement();
1624  XMLElement( const XMLElement& ); // not supported
1625  void operator=( const XMLElement& ); // not supported
1626 
1627  XMLAttribute* FindOrCreateAttribute( const char* name );
1628  char* ParseAttributes( char* p, int* curLineNumPtr );
1629  static void DeleteAttribute( XMLAttribute* attribute );
1630  XMLAttribute* CreateAttribute();
1631 
1632  enum { BUF_SIZE = 200 };
1633  ElementClosingType _closingType;
1634  // The attribute list is ordered; there is no 'lastAttribute'
1635  // because the list needs to be scanned for dupes before adding
1636  // a new attribute.
1637  XMLAttribute* _rootAttribute;
1638 };
1639 
1640 
1644 };
1645 
1646 
1653 {
1654  friend class XMLElement;
1655  // Gives access to SetError and Push/PopDepth, but over-access for everything else.
1656  // Wishing C++ had "internal" scope.
1657  friend class XMLNode;
1658  friend class XMLText;
1659  friend class XMLComment;
1660  friend class XMLDeclaration;
1661  friend class XMLUnknown;
1662 public:
1664  XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
1665  ~XMLDocument();
1666 
1668  TIXMLASSERT( this == _document );
1669  return this;
1670  }
1671  virtual const XMLDocument* ToDocument() const {
1672  TIXMLASSERT( this == _document );
1673  return this;
1674  }
1675 
1686  XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) );
1687 
1693  XMLError LoadFile( const char* filename );
1694 
1706  XMLError LoadFile( FILE* );
1707 
1713  XMLError SaveFile( const char* filename, bool compact = false );
1714 
1722  XMLError SaveFile( FILE* fp, bool compact = false );
1723 
1724  bool ProcessEntities() const {
1725  return _processEntities;
1726  }
1728  return _whitespaceMode;
1729  }
1730 
1734  bool HasBOM() const {
1735  return _writeBOM;
1736  }
1739  void SetBOM( bool useBOM ) {
1740  _writeBOM = useBOM;
1741  }
1742 
1747  return FirstChildElement();
1748  }
1749  const XMLElement* RootElement() const {
1750  return FirstChildElement();
1751  }
1752 
1767  void Print( XMLPrinter* streamer=0 ) const;
1768  virtual bool Accept( XMLVisitor* visitor ) const;
1769 
1775  XMLElement* NewElement( const char* name );
1781  XMLComment* NewComment( const char* comment );
1787  XMLText* NewText( const char* text );
1799  XMLDeclaration* NewDeclaration( const char* text=0 );
1805  XMLUnknown* NewUnknown( const char* text );
1806 
1811  void DeleteNode( XMLNode* node );
1812 
1813  void ClearError() {
1814  SetError(XML_SUCCESS, 0, 0);
1815  }
1816 
1818  bool Error() const {
1819  return _errorID != XML_SUCCESS;
1820  }
1822  XMLError ErrorID() const {
1823  return _errorID;
1824  }
1825  const char* ErrorName() const;
1826  static const char* ErrorIDToName(XMLError errorID);
1827 
1831  const char* ErrorStr() const;
1832 
1834  void PrintError() const;
1835 
1837  int ErrorLineNum() const
1838  {
1839  return _errorLineNum;
1840  }
1841 
1843  void Clear();
1844 
1852  void DeepCopy(XMLDocument* target) const;
1853 
1854  // internal
1855  char* Identify( char* p, XMLNode** node );
1856 
1857  // internal
1858  void MarkInUse(XMLNode*);
1859 
1860  virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
1861  return 0;
1862  }
1863  virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
1864  return false;
1865  }
1866 
1867 private:
1868  XMLDocument( const XMLDocument& ); // not supported
1869  void operator=( const XMLDocument& ); // not supported
1870 
1871  bool _writeBOM;
1872  bool _processEntities;
1873  XMLError _errorID;
1874  Whitespace _whitespaceMode;
1875  mutable StrPair _errorStr;
1876  int _errorLineNum;
1877  char* _charBuffer;
1878  int _parseCurLineNum;
1879  int _parsingDepth;
1880  // Memory tracking does add some overhead.
1881  // However, the code assumes that you don't
1882  // have a bunch of unlinked nodes around.
1883  // Therefore it takes less memory to track
1884  // in the document vs. a linked list in the XMLNode,
1885  // and the performance is the same.
1886  DynArray<XMLNode*, 10> _unlinked;
1887 
1888  MemPoolT< sizeof(XMLElement) > _elementPool;
1889  MemPoolT< sizeof(XMLAttribute) > _attributePool;
1890  MemPoolT< sizeof(XMLText) > _textPool;
1891  MemPoolT< sizeof(XMLComment) > _commentPool;
1892 
1893  static const char* _errorNames[XML_ERROR_COUNT];
1894 
1895  void Parse();
1896 
1897  void SetError( XMLError error, int lineNum, const char* format, ... );
1898 
1899  // Something of an obvious security hole, once it was discovered.
1900  // Either an ill-formed XML or an excessively deep one can overflow
1901  // the stack. Track stack depth, and error out if needed.
1902  class DepthTracker {
1903  public:
1904  DepthTracker(XMLDocument * document) {
1905  this->_document = document;
1906  document->PushDepth();
1907  }
1908  ~DepthTracker() {
1909  _document->PopDepth();
1910  }
1911  private:
1912  XMLDocument * _document;
1913  };
1914  void PushDepth();
1915  void PopDepth();
1916 
1917  template<class NodeType, int PoolElementSize>
1918  NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
1919 };
1920 
1921 template<class NodeType, int PoolElementSize>
1922 inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool )
1923 {
1924  TIXMLASSERT( sizeof( NodeType ) == PoolElementSize );
1925  TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() );
1926  NodeType* returnNode = new (pool.Alloc()) NodeType( this );
1927  TIXMLASSERT( returnNode );
1928  returnNode->_memPool = &pool;
1929 
1930  _unlinked.Push(returnNode);
1931  return returnNode;
1932 }
1933 
1990 {
1991 public:
1993  XMLHandle( XMLNode* node ) : _node( node ) {
1994  }
1996  XMLHandle( XMLNode& node ) : _node( &node ) {
1997  }
1999  XMLHandle( const XMLHandle& ref ) : _node( ref._node ) {
2000  }
2002  XMLHandle& operator=( const XMLHandle& ref ) {
2003  _node = ref._node;
2004  return *this;
2005  }
2006 
2009  return XMLHandle( _node ? _node->FirstChild() : 0 );
2010  }
2012  XMLHandle FirstChildElement( const char* name = 0 ) {
2013  return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
2014  }
2017  return XMLHandle( _node ? _node->LastChild() : 0 );
2018  }
2020  XMLHandle LastChildElement( const char* name = 0 ) {
2021  return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
2022  }
2025  return XMLHandle( _node ? _node->PreviousSibling() : 0 );
2026  }
2028  XMLHandle PreviousSiblingElement( const char* name = 0 ) {
2029  return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2030  }
2033  return XMLHandle( _node ? _node->NextSibling() : 0 );
2034  }
2036  XMLHandle NextSiblingElement( const char* name = 0 ) {
2037  return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2038  }
2039 
2042  return _node;
2043  }
2046  return ( _node ? _node->ToElement() : 0 );
2047  }
2050  return ( _node ? _node->ToText() : 0 );
2051  }
2054  return ( _node ? _node->ToUnknown() : 0 );
2055  }
2058  return ( _node ? _node->ToDeclaration() : 0 );
2059  }
2060 
2061 private:
2062  XMLNode* _node;
2063 };
2064 
2065 
2071 {
2072 public:
2073  XMLConstHandle( const XMLNode* node ) : _node( node ) {
2074  }
2075  XMLConstHandle( const XMLNode& node ) : _node( &node ) {
2076  }
2077  XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) {
2078  }
2079 
2081  _node = ref._node;
2082  return *this;
2083  }
2084 
2085  const XMLConstHandle FirstChild() const {
2086  return XMLConstHandle( _node ? _node->FirstChild() : 0 );
2087  }
2088  const XMLConstHandle FirstChildElement( const char* name = 0 ) const {
2089  return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
2090  }
2091  const XMLConstHandle LastChild() const {
2092  return XMLConstHandle( _node ? _node->LastChild() : 0 );
2093  }
2094  const XMLConstHandle LastChildElement( const char* name = 0 ) const {
2095  return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
2096  }
2098  return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
2099  }
2100  const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const {
2101  return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2102  }
2103  const XMLConstHandle NextSibling() const {
2104  return XMLConstHandle( _node ? _node->NextSibling() : 0 );
2105  }
2106  const XMLConstHandle NextSiblingElement( const char* name = 0 ) const {
2107  return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2108  }
2109 
2110 
2111  const XMLNode* ToNode() const {
2112  return _node;
2113  }
2114  const XMLElement* ToElement() const {
2115  return ( _node ? _node->ToElement() : 0 );
2116  }
2117  const XMLText* ToText() const {
2118  return ( _node ? _node->ToText() : 0 );
2119  }
2120  const XMLUnknown* ToUnknown() const {
2121  return ( _node ? _node->ToUnknown() : 0 );
2122  }
2124  return ( _node ? _node->ToDeclaration() : 0 );
2125  }
2126 
2127 private:
2128  const XMLNode* _node;
2129 };
2130 
2131 
2175 {
2176 public:
2183  XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 );
2184  virtual ~XMLPrinter() {}
2185 
2187  void PushHeader( bool writeBOM, bool writeDeclaration );
2191  void OpenElement( const char* name, bool compactMode=false );
2193  void PushAttribute( const char* name, const char* value );
2194  void PushAttribute( const char* name, int value );
2195  void PushAttribute( const char* name, unsigned value );
2196  void PushAttribute(const char* name, int64_t value);
2197  void PushAttribute( const char* name, bool value );
2198  void PushAttribute( const char* name, double value );
2200  virtual void CloseElement( bool compactMode=false );
2201 
2203  void PushText( const char* text, bool cdata=false );
2205  void PushText( int value );
2207  void PushText( unsigned value );
2209  void PushText(int64_t value);
2211  void PushText( bool value );
2213  void PushText( float value );
2215  void PushText( double value );
2216 
2218  void PushComment( const char* comment );
2219 
2220  void PushDeclaration( const char* value );
2221  void PushUnknown( const char* value );
2222 
2223  virtual bool VisitEnter( const XMLDocument& /*doc*/ );
2224  virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
2225  return true;
2226  }
2227 
2228  virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
2229  virtual bool VisitExit( const XMLElement& element );
2230 
2231  virtual bool Visit( const XMLText& text );
2232  virtual bool Visit( const XMLComment& comment );
2233  virtual bool Visit( const XMLDeclaration& declaration );
2234  virtual bool Visit( const XMLUnknown& unknown );
2235 
2240  const char* CStr() const {
2241  return _buffer.Mem();
2242  }
2248  int CStrSize() const {
2249  return _buffer.Size();
2250  }
2255  void ClearBuffer() {
2256  _buffer.Clear();
2257  _buffer.Push(0);
2258  _firstElement = true;
2259  }
2260 
2261 protected:
2262  virtual bool CompactMode( const XMLElement& ) { return _compactMode; }
2263 
2267  virtual void PrintSpace( int depth );
2268  void Print( const char* format, ... );
2269  void Write( const char* data, size_t size );
2270  inline void Write( const char* data ) { Write( data, strlen( data ) ); }
2271  void Putc( char ch );
2272 
2273  void SealElementIfJustOpened();
2276 
2277 private:
2278  void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
2279 
2280  bool _firstElement;
2281  FILE* _fp;
2282  int _depth;
2283  int _textDepth;
2284  bool _processEntities;
2285  bool _compactMode;
2286 
2287  enum {
2288  ENTITY_RANGE = 64,
2289  BUF_SIZE = 200
2290  };
2291  bool _entityFlag[ENTITY_RANGE];
2292  bool _restrictedEntityFlag[ENTITY_RANGE];
2293 
2294  DynArray< char, 20 > _buffer;
2295 
2296  // Prohibit cloning, intentionally not implemented
2297  XMLPrinter( const XMLPrinter& );
2298  XMLPrinter& operator=( const XMLPrinter& );
2299 };
2300 
2301 
2302 } // tinyxml2
2303 
2304 #if defined(_MSC_VER)
2305 # pragma warning(pop)
2306 #endif
2307 
2308 #endif // TINYXML2_INCLUDED
XMLError QueryInt64Attribute(const char *name, int64_t *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1341
XMLError QueryIntValue(int *value) const
Definition: tinyxml2.cpp:1380
const XMLNode * ToNode() const
Definition: tinyxml2.h:2111
const T * Mem() const
Definition: tinyxml2.h:286
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1350
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:489
virtual XMLNode * ShallowClone(XMLDocument *) const
Definition: tinyxml2.h:1860
#define TIXMLASSERT(x)
Definition: tinyxml2.h:94
const XMLDeclaration * ToDeclaration() const
Definition: tinyxml2.h:2123
static bool IsUTF8Continuation(char p)
Definition: tinyxml2.h:602
void SetInternedStr(const char *str)
Definition: tinyxml2.h:167
virtual ~XMLVisitor()
Definition: tinyxml2.h:482
virtual bool ShallowEqual(const XMLNode *) const
Definition: tinyxml2.h:1863
XMLHandle FirstChildElement(const char *name=0)
Get the first child element of this handle.
Definition: tinyxml2.h:2012
virtual const XMLComment * ToComment() const
Definition: tinyxml2.h:714
const XMLConstHandle LastChild() const
Definition: tinyxml2.h:2091
XMLText * ToText()
Safe cast to XMLText. This can return null.
Definition: tinyxml2.h:2049
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1416
XMLText(XMLDocument *doc)
Definition: tinyxml2.h:1009
const char * CStr() const
Definition: tinyxml2.h:2240
const XMLElement * ToElement() const
Definition: tinyxml2.h:2114
XMLError ErrorID() const
Return the errorID.
Definition: tinyxml2.h:1822
virtual const XMLDeclaration * ToDeclaration() const
Definition: tinyxml2.h:1069
bool Empty() const
Definition: tinyxml2.h:163
XMLElement * PreviousSiblingElement(const char *name=0)
Definition: tinyxml2.h:808
virtual void Free(void *)=0
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition: tinyxml2.h:2045
virtual bool CompactMode(const XMLElement &)
Definition: tinyxml2.h:2262
void PopArr(int count)
Definition: tinyxml2.h:245
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:684
XMLError QueryStringAttribute(const char *name, const char **value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1375
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:688
bool Empty() const
Definition: tinyxml2.h:250
XMLDocument * _document
Definition: tinyxml2.h:946
virtual const XMLDocument * ToDocument() const
Definition: tinyxml2.h:1671
Whitespace WhitespaceMode() const
Definition: tinyxml2.h:1727
virtual const XMLElement * ToElement() const
Definition: tinyxml2.h:708
static const char * SkipWhiteSpace(const char *p, int *curLineNumPtr)
Definition: tinyxml2.h:552
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1332
XMLNode * LinkEndChild(XMLNode *addThis)
Definition: tinyxml2.h:837
virtual const XMLUnknown * ToUnknown() const
Definition: tinyxml2.h:1104
int CStrSize() const
Definition: tinyxml2.h:2248
float FloatValue() const
Query as a float. See IntValue()
Definition: tinyxml2.h:1185
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:1667
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
Definition: tinyxml2.h:2053
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition: tinyxml2.h:1251
ElementClosingType ClosingType() const
Definition: tinyxml2.h:1612
XMLHandle(const XMLHandle &ref)
Copy constructor.
Definition: tinyxml2.h:1999
XMLHandle FirstChild()
Get the first child of this handle.
Definition: tinyxml2.h:2008
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
Definition: tinyxml2.h:997
void SetUserData(void *userData)
Definition: tinyxml2.h:931
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition: tinyxml2.h:813
unsigned UnsignedValue() const
Query as an unsigned integer. See IntValue()
Definition: tinyxml2.h:1167
int Size() const
Definition: tinyxml2.h:269
XMLHandle LastChildElement(const char *name=0)
Get the last child element of this handle.
Definition: tinyxml2.h:2020
static char * SkipWhiteSpace(char *p, int *curLineNumPtr)
Definition: tinyxml2.h:564
const XMLConstHandle PreviousSibling() const
Definition: tinyxml2.h:2097
XMLHandle LastChild()
Get the last child of this handle.
Definition: tinyxml2.h:2016
XMLNode * _firstChild
Definition: tinyxml2.h:951
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
Definition: tinyxml2.h:592
XMLElement * RootElement()
Definition: tinyxml2.h:1746
virtual const XMLDeclaration * ToDeclaration() const
Definition: tinyxml2.h:720
virtual void SetTracked()=0
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:989
XMLHandle(XMLNode &node)
Create a handle from a node.
Definition: tinyxml2.h:1996
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
Definition: tinyxml2.h:1255
void SetBOM(bool useBOM)
Definition: tinyxml2.h:1739
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1993
void Trace(const char *name)
Definition: tinyxml2.h:411
void Write(const char *data)
Definition: tinyxml2.h:2270
const XMLConstHandle NextSiblingElement(const char *name=0) const
Definition: tinyxml2.h:2106
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:1027
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:1259
bool HasBOM() const
Definition: tinyxml2.h:1734
static bool IsNameChar(unsigned char ch)
Definition: tinyxml2.h:585
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1366
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1389
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
Definition: tinyxml2.h:2041
bool BoolValue() const
Query as a boolean. See IntValue()
Definition: tinyxml2.h:1173
virtual int ItemSize() const =0
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:761
const XMLConstHandle FirstChild() const
Definition: tinyxml2.h:2085
const XMLConstHandle PreviousSiblingElement(const char *name=0) const
Definition: tinyxml2.h:2100
const XMLConstHandle NextSibling() const
Definition: tinyxml2.h:2103
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:1066
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
Definition: tinyxml2.h:503
virtual void Clear()=0
XMLNode * FirstChild()
Definition: tinyxml2.h:765
void SwapRemove(int i)
Definition: tinyxml2.h:279
virtual void * Alloc()=0
void Push(T t)
Definition: tinyxml2.h:223
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
Definition: tinyxml2.h:515
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
Definition: tinyxml2.h:1438
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1358
const char * GetStr()
Definition: tinyxml2.cpp:267
XMLNode * _lastChild
Definition: tinyxml2.h:952
XMLError QueryInt64Value(int64_t *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1398
XMLHandle NextSibling()
Get the next sibling of this handle.
Definition: tinyxml2.h:2032
virtual int ItemSize() const
Definition: tinyxml2.h:366
int GetLineNum() const
Gets the line number the attribute is in, if the document was parsed from a file. ...
Definition: tinyxml2.h:1143
void Set(char *start, char *end, int flags)
Definition: tinyxml2.h:152
int IntValue() const
Definition: tinyxml2.h:1154
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:1101
bool CData() const
Returns true if this is a CDATA text element.
Definition: tinyxml2.h:1001
int64_t Int64Value() const
Definition: tinyxml2.h:1160
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
Definition: tinyxml2.h:2024
const T & operator[](int i) const
Definition: tinyxml2.h:259
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
Definition: tinyxml2.h:2002
virtual const XMLUnknown * ToUnknown() const
Definition: tinyxml2.h:723
XMLConstHandle(const XMLNode &node)
Definition: tinyxml2.h:2075
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:2224
char * ParseName(char *in)
Definition: tinyxml2.cpp:218
const T & PeekTop() const
Definition: tinyxml2.h:264
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
Definition: tinyxml2.h:494
bool Error() const
Return true if there was an error parsing the document.
Definition: tinyxml2.h:1818
const XMLConstHandle LastChildElement(const char *name=0) const
Definition: tinyxml2.h:2094
const XMLText * ToText() const
Definition: tinyxml2.h:2117
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:485
virtual const XMLComment * ToComment() const
Definition: tinyxml2.h:1030
XMLNode * _parent
Definition: tinyxml2.h:947
int Untracked() const
Definition: tinyxml2.h:421
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:696
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition: tinyxml2.h:779
XMLElement * LastChildElement(const char *name=0)
Definition: tinyxml2.h:792
T * PushArr(int count)
Definition: tinyxml2.h:230
T & operator[](int i)
Definition: tinyxml2.h:254
virtual ~XMLPrinter()
Definition: tinyxml2.h:2184
virtual void * Alloc()
Definition: tinyxml2.h:373
XMLError QueryAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1403
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
Definition: tinyxml2.h:1450
virtual const XMLElement * ToElement() const
Definition: tinyxml2.h:1262
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
Definition: tinyxml2.h:2057
const XMLElement * RootElement() const
Definition: tinyxml2.h:1749
void SetAttribute(const char *value)
Set the attribute to a string value.
Definition: tinyxml2.cpp:1434
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition: tinyxml2.h:1428
static bool IsWhiteSpace(char p)
Definition: tinyxml2.h:570
virtual bool VisitExit(const XMLElement &)
Visit an element.
Definition: tinyxml2.h:498
virtual const XMLText * ToText() const
Definition: tinyxml2.h:992
void * GetUserData() const
Definition: tinyxml2.h:938
virtual ~XMLText()
Definition: tinyxml2.h:1010
virtual void Free(void *mem)
Definition: tinyxml2.h:399
void SetAttribute(const char *name, int64_t value)
Sets the named attribute to value.
Definition: tinyxml2.h:1444
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
Definition: tinyxml2.h:1455
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1425
void TransferTo(StrPair *other)
Definition: tinyxml2.cpp:144
XMLNode * LastChild()
Definition: tinyxml2.h:783
virtual const XMLDocument * ToDocument() const
Definition: tinyxml2.h:717
const XMLNode * Parent() const
Get the parent of this node on the DOM.
Definition: tinyxml2.h:747
virtual bool Visit(const XMLComment &)
Visit a comment node.
Definition: tinyxml2.h:511
static bool IsNameStartChar(unsigned char ch)
Definition: tinyxml2.h:574
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1407
XMLNode * NextSibling()
Definition: tinyxml2.h:817
XMLNode * _next
Definition: tinyxml2.h:955
int Capacity() const
Definition: tinyxml2.h:274
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition: tinyxml2.h:797
XMLHandle NextSiblingElement(const char *name=0)
Get the next sibling element of this handle.
Definition: tinyxml2.h:2036
void * _userData
Definition: tinyxml2.h:957
XMLConstHandle(const XMLConstHandle &ref)
Definition: tinyxml2.h:2077
virtual ~MemPool()
Definition: tinyxml2.h:331
XMLElement * NextSiblingElement(const char *name=0)
Definition: tinyxml2.h:824
const char * Value() const
The value of the attribute.
Definition: tinyxml2.cpp:1341
XMLNode * _prev
Definition: tinyxml2.h:954
XMLElement * FirstChildElement(const char *name=0)
Definition: tinyxml2.h:774
XMLConstHandle(const XMLNode *node)
Definition: tinyxml2.h:2073
XMLError QueryIntAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1323
StrPair _value
Definition: tinyxml2.h:948
char * ParseText(char *in, const char *endTag, int strFlags, int *curLineNumPtr)
Definition: tinyxml2.cpp:193
const XMLUnknown * ToUnknown() const
Definition: tinyxml2.h:2120
int GetLineNum() const
Gets the line number the node is in, if the document was parsed from a file.
Definition: tinyxml2.h:744
XMLError QueryAttribute(const char *name, double *value) const
Definition: tinyxml2.h:1419
DynArray< const char *, 10 > _stack
Definition: tinyxml2.h:2275
#define TINYXML2_LIB
Definition: tinyxml2.h:78
virtual bool Visit(const XMLText &)
Visit a text node.
Definition: tinyxml2.h:507
XMLError QueryAttribute(const char *name, float *value) const
Definition: tinyxml2.h:1423
int ErrorLineNum() const
Return the line where the error occured, or zero if unknown.
Definition: tinyxml2.h:1837
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:678
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:704
XMLConstHandle & operator=(const XMLConstHandle &ref)
Definition: tinyxml2.h:2080
void SetAttribute(const char *name, float value)
Sets the named attribute to value.
Definition: tinyxml2.h:1460
const XMLAttribute * Next() const
The next attribute in the list.
Definition: tinyxml2.h:1146
XMLNode * Parent()
Definition: tinyxml2.h:751
const XMLConstHandle FirstChildElement(const char *name=0) const
Definition: tinyxml2.h:2088
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml2.h:756
int CurrentAllocs() const
Definition: tinyxml2.h:369
double DoubleValue() const
Query as a double. See IntValue()
Definition: tinyxml2.h:1179
XMLError QueryAttribute(const char *name, unsigned int *value) const
Definition: tinyxml2.h:1407
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:700
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:673
bool ProcessEntities() const
Definition: tinyxml2.h:1724
void SetStr(const char *str, int flags=0)
Definition: tinyxml2.cpp:180
XMLError QueryAttribute(const char *name, int64_t *value) const
Definition: tinyxml2.h:1411
XMLHandle PreviousSiblingElement(const char *name=0)
Get the previous sibling element of this handle.
Definition: tinyxml2.h:2028
XMLNode * PreviousSibling()
Definition: tinyxml2.h:801
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
Definition: tinyxml2.h:1433
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
Definition: tinyxml2.h:1471
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:692
XMLError QueryAttribute(const char *name, bool *value) const
Definition: tinyxml2.h:1415
virtual const XMLText * ToText() const
Definition: tinyxml2.h:711