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 // Do NOT export. This version is meant to be linked statically only.
68 #ifdef _WIN32
69 # define TINYXML2_LIB // TODO?
70 #else
71 # define TINYXML2_LIB __attribute__((visibility("hidden")))
72 #endif
73 
74 #if defined(TINYXML2_DEBUG)
75 # if defined(_MSC_VER)
76 # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
77 # define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); }
78 # elif defined (ANDROID_NDK)
79 # include <android/log.h>
80 # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
81 # else
82 # include <assert.h>
83 # define TIXMLASSERT assert
84 # endif
85 #else
86 # define TIXMLASSERT( x ) {}
87 #endif
88 
89 
90 /* Versioning, past 1.0.14:
91  http://semver.org/
92 */
93 static const int TIXML2_MAJOR_VERSION = 6;
94 static const int TIXML2_MINOR_VERSION = 2;
95 static const int TIXML2_PATCH_VERSION = 0;
96 
97 #define TINYXML2_MAJOR_VERSION 6
98 #define TINYXML2_MINOR_VERSION 2
99 #define TINYXML2_PATCH_VERSION 0
100 
101 // A fixed element depth limit is problematic. There needs to be a
102 // limit to avoid a stack overflow. However, that limit varies per
103 // system, and the capacity of the stack. On the other hand, it's a trivial
104 // attack that can result from ill, malicious, or even correctly formed XML,
105 // so there needs to be a limit in place.
106 static const int TINYXML2_MAX_ELEMENT_DEPTH = 100;
107 
108 namespace tinyxml2
109 {
110 class XMLDocument;
111 class XMLElement;
112 class XMLAttribute;
113 class XMLComment;
114 class XMLText;
115 class XMLDeclaration;
116 class XMLUnknown;
117 class XMLPrinter;
118 
119 /*
120  A class that wraps strings. Normally stores the start and end
121  pointers into the XML file itself, and will apply normalization
122  and entity translation if actually read. Can also store (and memory
123  manage) a traditional char[]
124 */
125 class StrPair
126 {
127 public:
128  enum {
132 
139  };
140 
141  StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
142  ~StrPair();
143 
144  void Set( char* start, char* end, int flags ) {
145  TIXMLASSERT( start );
146  TIXMLASSERT( end );
147  Reset();
148  _start = start;
149  _end = end;
150  _flags = flags | NEEDS_FLUSH;
151  }
152 
153  const char* GetStr();
154 
155  bool Empty() const {
156  return _start == _end;
157  }
158 
159  void SetInternedStr( const char* str ) {
160  Reset();
161  _start = const_cast<char*>(str);
162  }
163 
164  void SetStr( const char* str, int flags=0 );
165 
166  char* ParseText( char* in, const char* endTag, int strFlags, int* curLineNumPtr );
167  char* ParseName( char* in );
168 
169  void TransferTo( StrPair* other );
170  void Reset();
171 
172 private:
173  void CollapseWhitespace();
174 
175  enum {
176  NEEDS_FLUSH = 0x100,
177  NEEDS_DELETE = 0x200
178  };
179 
180  int _flags;
181  char* _start;
182  char* _end;
183 
184  StrPair( const StrPair& other ); // not supported
185  void operator=( StrPair& other ); // not supported, use TransferTo()
186 };
187 
188 
189 /*
190  A dynamic array of Plain Old Data. Doesn't support constructors, etc.
191  Has a small initial memory pool, so that low or no usage will not
192  cause a call to new/delete
193 */
194 template <class T, int INITIAL_SIZE>
195 class DynArray
196 {
197 public:
199  _mem( _pool ),
200  _allocated( INITIAL_SIZE ),
201  _size( 0 )
202  {
203  }
204 
206  if ( _mem != _pool ) {
207  delete [] _mem;
208  }
209  }
210 
211  void Clear() {
212  _size = 0;
213  }
214 
215  void Push( T t ) {
216  TIXMLASSERT( _size < INT_MAX );
217  EnsureCapacity( _size+1 );
218  _mem[_size] = t;
219  ++_size;
220  }
221 
222  T* PushArr( int count ) {
223  TIXMLASSERT( count >= 0 );
224  TIXMLASSERT( _size <= INT_MAX - count );
225  EnsureCapacity( _size+count );
226  T* ret = &_mem[_size];
227  _size += count;
228  return ret;
229  }
230 
231  T Pop() {
232  TIXMLASSERT( _size > 0 );
233  --_size;
234  return _mem[_size];
235  }
236 
237  void PopArr( int count ) {
238  TIXMLASSERT( _size >= count );
239  _size -= count;
240  }
241 
242  bool Empty() const {
243  return _size == 0;
244  }
245 
246  T& operator[](int i) {
247  TIXMLASSERT( i>= 0 && i < _size );
248  return _mem[i];
249  }
250 
251  const T& operator[](int i) const {
252  TIXMLASSERT( i>= 0 && i < _size );
253  return _mem[i];
254  }
255 
256  const T& PeekTop() const {
257  TIXMLASSERT( _size > 0 );
258  return _mem[ _size - 1];
259  }
260 
261  int Size() const {
262  TIXMLASSERT( _size >= 0 );
263  return _size;
264  }
265 
266  int Capacity() const {
267  TIXMLASSERT( _allocated >= INITIAL_SIZE );
268  return _allocated;
269  }
270 
271  void SwapRemove(int i) {
272  TIXMLASSERT(i >= 0 && i < _size);
273  TIXMLASSERT(_size > 0);
274  _mem[i] = _mem[_size - 1];
275  --_size;
276  }
277 
278  const T* Mem() const {
279  TIXMLASSERT( _mem );
280  return _mem;
281  }
282 
283  T* Mem() {
284  TIXMLASSERT( _mem );
285  return _mem;
286  }
287 
288 private:
289  DynArray( const DynArray& ); // not supported
290  void operator=( const DynArray& ); // not supported
291 
292  void EnsureCapacity( int cap ) {
293  TIXMLASSERT( cap > 0 );
294  if ( cap > _allocated ) {
295  TIXMLASSERT( cap <= INT_MAX / 2 );
296  int newAllocated = cap * 2;
297  T* newMem = new T[newAllocated];
298  TIXMLASSERT( newAllocated >= _size );
299  memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
300  if ( _mem != _pool ) {
301  delete [] _mem;
302  }
303  _mem = newMem;
304  _allocated = newAllocated;
305  }
306  }
307 
308  T* _mem;
309  T _pool[INITIAL_SIZE];
310  int _allocated; // objects allocated
311  int _size; // number objects in use
312 };
313 
314 
315 /*
316  Parent virtual class of a pool for fast allocation
317  and deallocation of objects.
318 */
319 class MemPool
320 {
321 public:
322  MemPool() {}
323  virtual ~MemPool() {}
324 
325  virtual int ItemSize() const = 0;
326  virtual void* Alloc() = 0;
327  virtual void Free( void* ) = 0;
328  virtual void SetTracked() = 0;
329  virtual void Clear() = 0;
330 };
331 
332 
333 /*
334  Template child class to create pools of the correct type.
335 */
336 template< int ITEM_SIZE >
337 class MemPoolT : public MemPool
338 {
339 public:
340  MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
342  Clear();
343  }
344 
345  void Clear() {
346  // Delete the blocks.
347  while( !_blockPtrs.Empty()) {
348  Block* lastBlock = _blockPtrs.Pop();
349  delete lastBlock;
350  }
351  _root = 0;
352  _currentAllocs = 0;
353  _nAllocs = 0;
354  _maxAllocs = 0;
355  _nUntracked = 0;
356  }
357 
358  virtual int ItemSize() const {
359  return ITEM_SIZE;
360  }
361  int CurrentAllocs() const {
362  return _currentAllocs;
363  }
364 
365  virtual void* Alloc() {
366  if ( !_root ) {
367  // Need a new block.
368  Block* block = new Block();
369  _blockPtrs.Push( block );
370 
371  Item* blockItems = block->items;
372  for( int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
373  blockItems[i].next = &(blockItems[i + 1]);
374  }
375  blockItems[ITEMS_PER_BLOCK - 1].next = 0;
376  _root = blockItems;
377  }
378  Item* const result = _root;
379  TIXMLASSERT( result != 0 );
380  _root = _root->next;
381 
382  ++_currentAllocs;
383  if ( _currentAllocs > _maxAllocs ) {
384  _maxAllocs = _currentAllocs;
385  }
386  ++_nAllocs;
387  ++_nUntracked;
388  return result;
389  }
390 
391  virtual void Free( void* mem ) {
392  if ( !mem ) {
393  return;
394  }
395  --_currentAllocs;
396  Item* item = static_cast<Item*>( mem );
397 #ifdef TINYXML2_DEBUG
398  memset( item, 0xfe, sizeof( *item ) );
399 #endif
400  item->next = _root;
401  _root = item;
402  }
403  void Trace( const char* name ) {
404  printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
405  name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs,
406  ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
407  }
408 
409  void SetTracked() {
410  --_nUntracked;
411  }
412 
413  int Untracked() const {
414  return _nUntracked;
415  }
416 
417  // This number is perf sensitive. 4k seems like a good tradeoff on my machine.
418  // The test file is large, 170k.
419  // Release: VS2010 gcc(no opt)
420  // 1k: 4000
421  // 2k: 4000
422  // 4k: 3900 21000
423  // 16k: 5200
424  // 32k: 4300
425  // 64k: 4000 21000
426  // Declared public because some compilers do not accept to use ITEMS_PER_BLOCK
427  // in private part if ITEMS_PER_BLOCK is private
428  enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE };
429 
430 private:
431  MemPoolT( const MemPoolT& ); // not supported
432  void operator=( const MemPoolT& ); // not supported
433 
434  union Item {
436  char itemData[ITEM_SIZE];
437  };
438  struct Block {
439  Item items[ITEMS_PER_BLOCK];
440  };
442  Item* _root;
443 
445  int _nAllocs;
448 };
449 
450 
451 
472 {
473 public:
474  virtual ~XMLVisitor() {}
475 
477  virtual bool VisitEnter( const XMLDocument& /*doc*/ ) {
478  return true;
479  }
481  virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
482  return true;
483  }
484 
486  virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) {
487  return true;
488  }
490  virtual bool VisitExit( const XMLElement& /*element*/ ) {
491  return true;
492  }
493 
495  virtual bool Visit( const XMLDeclaration& /*declaration*/ ) {
496  return true;
497  }
499  virtual bool Visit( const XMLText& /*text*/ ) {
500  return true;
501  }
503  virtual bool Visit( const XMLComment& /*comment*/ ) {
504  return true;
505  }
507  virtual bool Visit( const XMLUnknown& /*unknown*/ ) {
508  return true;
509  }
510 };
511 
512 // WARNING: must match XMLDocument::_errorNames[]
513 enum XMLError {
520  UNUSED_XML_ERROR_ELEMENT_MISMATCH, // remove at next major version
523  UNUSED_XML_ERROR_IDENTIFYING_TAG, // remove at next major version
535 
537 };
538 
539 
540 /*
541  Utility functionality.
542 */
544 {
545 public:
546  static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) {
547  TIXMLASSERT( p );
548 
549  while( IsWhiteSpace(*p) ) {
550  if (curLineNumPtr && *p == '\n') {
551  ++(*curLineNumPtr);
552  }
553  ++p;
554  }
555  TIXMLASSERT( p );
556  return p;
557  }
558  static char* SkipWhiteSpace( char* p, int* curLineNumPtr ) {
559  return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p), curLineNumPtr ) );
560  }
561 
562  // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
563  // correct, but simple, and usually works.
564  static bool IsWhiteSpace( char p ) {
565  return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
566  }
567 
568  inline static bool IsNameStartChar( unsigned char ch ) {
569  if ( ch >= 128 ) {
570  // This is a heuristic guess in attempt to not implement Unicode-aware isalpha()
571  return true;
572  }
573  if ( isalpha( ch ) ) {
574  return true;
575  }
576  return ch == ':' || ch == '_';
577  }
578 
579  inline static bool IsNameChar( unsigned char ch ) {
580  return IsNameStartChar( ch )
581  || isdigit( ch )
582  || ch == '.'
583  || ch == '-';
584  }
585 
586  inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
587  if ( p == q ) {
588  return true;
589  }
590  TIXMLASSERT( p );
591  TIXMLASSERT( q );
592  TIXMLASSERT( nChar >= 0 );
593  return strncmp( p, q, nChar ) == 0;
594  }
595 
596  inline static bool IsUTF8Continuation( char p ) {
597  return ( p & 0x80 ) != 0;
598  }
599 
600  static const char* ReadBOM( const char* p, bool* hasBOM );
601  // p is the starting location,
602  // the UTF-8 value of the entity will be placed in value, and length filled in.
603  static const char* GetCharacterRef( const char* p, char* value, int* length );
604  static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
605 
606  // converts primitive types to strings
607  static void ToStr( int v, char* buffer, int bufferSize );
608  static void ToStr( unsigned v, char* buffer, int bufferSize );
609  static void ToStr( bool v, char* buffer, int bufferSize );
610  static void ToStr( float v, char* buffer, int bufferSize );
611  static void ToStr( double v, char* buffer, int bufferSize );
612  static void ToStr(int64_t v, char* buffer, int bufferSize);
613 
614  // converts strings to primitive types
615  static bool ToInt( const char* str, int* value );
616  static bool ToUnsigned( const char* str, unsigned* value );
617  static bool ToBool( const char* str, bool* value );
618  static bool ToFloat( const char* str, float* value );
619  static bool ToDouble( const char* str, double* value );
620  static bool ToInt64(const char* str, int64_t* value);
621 
622  // Changes what is serialized for a boolean value.
623  // Default to "true" and "false". Shouldn't be changed
624  // unless you have a special testing or compatibility need.
625  // Be careful: static, global, & not thread safe.
626  // Be sure to set static const memory as parameters.
627  static void SetBoolSerialization(const char* writeTrue, const char* writeFalse);
628 
629 private:
630  static const char* writeBoolTrue;
631  static const char* writeBoolFalse;
632 };
633 
634 
661 {
662  friend class XMLDocument;
663  friend class XMLElement;
664 public:
665 
667  const XMLDocument* GetDocument() const {
668  TIXMLASSERT( _document );
669  return _document;
670  }
673  TIXMLASSERT( _document );
674  return _document;
675  }
676 
678  virtual XMLElement* ToElement() {
679  return 0;
680  }
682  virtual XMLText* ToText() {
683  return 0;
684  }
686  virtual XMLComment* ToComment() {
687  return 0;
688  }
690  virtual XMLDocument* ToDocument() {
691  return 0;
692  }
695  return 0;
696  }
698  virtual XMLUnknown* ToUnknown() {
699  return 0;
700  }
701 
702  virtual const XMLElement* ToElement() const {
703  return 0;
704  }
705  virtual const XMLText* ToText() const {
706  return 0;
707  }
708  virtual const XMLComment* ToComment() const {
709  return 0;
710  }
711  virtual const XMLDocument* ToDocument() const {
712  return 0;
713  }
714  virtual const XMLDeclaration* ToDeclaration() const {
715  return 0;
716  }
717  virtual const XMLUnknown* ToUnknown() const {
718  return 0;
719  }
720 
730  const char* Value() const;
731 
735  void SetValue( const char* val, bool staticMem=false );
736 
738  int GetLineNum() const { return _parseLineNum; }
739 
741  const XMLNode* Parent() const {
742  return _parent;
743  }
744 
746  return _parent;
747  }
748 
750  bool NoChildren() const {
751  return !_firstChild;
752  }
753 
755  const XMLNode* FirstChild() const {
756  return _firstChild;
757  }
758 
760  return _firstChild;
761  }
762 
766  const XMLElement* FirstChildElement( const char* name = 0 ) const;
767 
768  XMLElement* FirstChildElement( const char* name = 0 ) {
769  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name ));
770  }
771 
773  const XMLNode* LastChild() const {
774  return _lastChild;
775  }
776 
778  return _lastChild;
779  }
780 
784  const XMLElement* LastChildElement( const char* name = 0 ) const;
785 
786  XMLElement* LastChildElement( const char* name = 0 ) {
787  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) );
788  }
789 
791  const XMLNode* PreviousSibling() const {
792  return _prev;
793  }
794 
796  return _prev;
797  }
798 
800  const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ;
801 
802  XMLElement* PreviousSiblingElement( const char* name = 0 ) {
803  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) );
804  }
805 
807  const XMLNode* NextSibling() const {
808  return _next;
809  }
810 
812  return _next;
813  }
814 
816  const XMLElement* NextSiblingElement( const char* name = 0 ) const;
817 
818  XMLElement* NextSiblingElement( const char* name = 0 ) {
819  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) );
820  }
821 
829  XMLNode* InsertEndChild( XMLNode* addThis );
830 
831  XMLNode* LinkEndChild( XMLNode* addThis ) {
832  return InsertEndChild( addThis );
833  }
841  XMLNode* InsertFirstChild( XMLNode* addThis );
850  XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
851 
855  void DeleteChildren();
856 
860  void DeleteChild( XMLNode* node );
861 
871  virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
872 
886  XMLNode* DeepClone( XMLDocument* target ) const;
887 
894  virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
895 
918  virtual bool Accept( XMLVisitor* visitor ) const = 0;
919 
925  void SetUserData(void* userData) { _userData = userData; }
926 
932  void* GetUserData() const { return _userData; }
933 
934 protected:
935  XMLNode( XMLDocument* );
936  virtual ~XMLNode();
937 
938  virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
939 
942  mutable StrPair _value;
944 
947 
950 
951  void* _userData;
952 
953 private:
955  void Unlink( XMLNode* child );
956  static void DeleteNode( XMLNode* node );
957  void InsertChildPreamble( XMLNode* insertThis ) const;
958  const XMLElement* ToElementWithName( const char* name ) const;
959 
960  XMLNode( const XMLNode& ); // not supported
961  XMLNode& operator=( const XMLNode& ); // not supported
962 };
963 
964 
978 {
979  friend class XMLDocument;
980 public:
981  virtual bool Accept( XMLVisitor* visitor ) const;
982 
983  virtual XMLText* ToText() {
984  return this;
985  }
986  virtual const XMLText* ToText() const {
987  return this;
988  }
989 
991  void SetCData( bool isCData ) {
992  _isCData = isCData;
993  }
995  bool CData() const {
996  return _isCData;
997  }
998 
999  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1000  virtual bool ShallowEqual( const XMLNode* compare ) const;
1001 
1002 protected:
1003  XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
1004  virtual ~XMLText() {}
1005 
1006  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1007 
1008 private:
1009  bool _isCData;
1010 
1011  XMLText( const XMLText& ); // not supported
1012  XMLText& operator=( const XMLText& ); // not supported
1013 };
1014 
1015 
1018 {
1019  friend class XMLDocument;
1020 public:
1021  virtual XMLComment* ToComment() {
1022  return this;
1023  }
1024  virtual const XMLComment* ToComment() const {
1025  return this;
1026  }
1027 
1028  virtual bool Accept( XMLVisitor* visitor ) const;
1029 
1030  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1031  virtual bool ShallowEqual( const XMLNode* compare ) const;
1032 
1033 protected:
1034  XMLComment( XMLDocument* doc );
1035  virtual ~XMLComment();
1036 
1037  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
1038 
1039 private:
1040  XMLComment( const XMLComment& ); // not supported
1041  XMLComment& operator=( const XMLComment& ); // not supported
1042 };
1043 
1044 
1057 {
1058  friend class XMLDocument;
1059 public:
1061  return this;
1062  }
1063  virtual const XMLDeclaration* ToDeclaration() const {
1064  return this;
1065  }
1066 
1067  virtual bool Accept( XMLVisitor* visitor ) const;
1068 
1069  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1070  virtual bool ShallowEqual( const XMLNode* compare ) const;
1071 
1072 protected:
1073  XMLDeclaration( XMLDocument* doc );
1074  virtual ~XMLDeclaration();
1075 
1076  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1077 
1078 private:
1079  XMLDeclaration( const XMLDeclaration& ); // not supported
1080  XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
1081 };
1082 
1083 
1092 {
1093  friend class XMLDocument;
1094 public:
1095  virtual XMLUnknown* ToUnknown() {
1096  return this;
1097  }
1098  virtual const XMLUnknown* ToUnknown() const {
1099  return this;
1100  }
1101 
1102  virtual bool Accept( XMLVisitor* visitor ) const;
1103 
1104  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1105  virtual bool ShallowEqual( const XMLNode* compare ) const;
1106 
1107 protected:
1108  XMLUnknown( XMLDocument* doc );
1109  virtual ~XMLUnknown();
1110 
1111  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1112 
1113 private:
1114  XMLUnknown( const XMLUnknown& ); // not supported
1115  XMLUnknown& operator=( const XMLUnknown& ); // not supported
1116 };
1117 
1118 
1119 
1127 {
1128  friend class XMLElement;
1129 public:
1131  const char* Name() const;
1132 
1134  const char* Value() const;
1135 
1137  int GetLineNum() const { return _parseLineNum; }
1138 
1140  const XMLAttribute* Next() const {
1141  return _next;
1142  }
1143 
1148  int IntValue() const {
1149  int i = 0;
1150  QueryIntValue(&i);
1151  return i;
1152  }
1153 
1154  int64_t Int64Value() const {
1155  int64_t i = 0;
1156  QueryInt64Value(&i);
1157  return i;
1158  }
1159 
1161  unsigned UnsignedValue() const {
1162  unsigned i=0;
1163  QueryUnsignedValue( &i );
1164  return i;
1165  }
1167  bool BoolValue() const {
1168  bool b=false;
1169  QueryBoolValue( &b );
1170  return b;
1171  }
1173  double DoubleValue() const {
1174  double d=0;
1175  QueryDoubleValue( &d );
1176  return d;
1177  }
1179  float FloatValue() const {
1180  float f=0;
1181  QueryFloatValue( &f );
1182  return f;
1183  }
1184 
1189  XMLError QueryIntValue( int* value ) const;
1191  XMLError QueryUnsignedValue( unsigned int* value ) const;
1193  XMLError QueryInt64Value(int64_t* value) const;
1195  XMLError QueryBoolValue( bool* value ) const;
1197  XMLError QueryDoubleValue( double* value ) const;
1199  XMLError QueryFloatValue( float* value ) const;
1200 
1202  void SetAttribute( const char* value );
1204  void SetAttribute( int value );
1206  void SetAttribute( unsigned value );
1208  void SetAttribute(int64_t value);
1210  void SetAttribute( bool value );
1212  void SetAttribute( double value );
1214  void SetAttribute( float value );
1215 
1216 private:
1217  enum { BUF_SIZE = 200 };
1218 
1219  XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
1220  virtual ~XMLAttribute() {}
1221 
1222  XMLAttribute( const XMLAttribute& ); // not supported
1223  void operator=( const XMLAttribute& ); // not supported
1224  void SetName( const char* name );
1225 
1226  char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr );
1227 
1228  mutable StrPair _name;
1229  mutable StrPair _value;
1233 };
1234 
1235 
1241 {
1242  friend class XMLDocument;
1243 public:
1245  const char* Name() const {
1246  return Value();
1247  }
1249  void SetName( const char* str, bool staticMem=false ) {
1250  SetValue( str, staticMem );
1251  }
1252 
1253  virtual XMLElement* ToElement() {
1254  return this;
1255  }
1256  virtual const XMLElement* ToElement() const {
1257  return this;
1258  }
1259  virtual bool Accept( XMLVisitor* visitor ) const;
1260 
1284  const char* Attribute( const char* name, const char* value=0 ) const;
1285 
1292  int IntAttribute(const char* name, int defaultValue = 0) const;
1294  unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const;
1296  int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const;
1298  bool BoolAttribute(const char* name, bool defaultValue = false) const;
1300  double DoubleAttribute(const char* name, double defaultValue = 0) const;
1302  float FloatAttribute(const char* name, float defaultValue = 0) const;
1303 
1317  XMLError QueryIntAttribute( const char* name, int* value ) const {
1318  const XMLAttribute* a = FindAttribute( name );
1319  if ( !a ) {
1320  return XML_NO_ATTRIBUTE;
1321  }
1322  return a->QueryIntValue( value );
1323  }
1324 
1326  XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
1327  const XMLAttribute* a = FindAttribute( name );
1328  if ( !a ) {
1329  return XML_NO_ATTRIBUTE;
1330  }
1331  return a->QueryUnsignedValue( value );
1332  }
1333 
1335  XMLError QueryInt64Attribute(const char* name, int64_t* value) const {
1336  const XMLAttribute* a = FindAttribute(name);
1337  if (!a) {
1338  return XML_NO_ATTRIBUTE;
1339  }
1340  return a->QueryInt64Value(value);
1341  }
1342 
1344  XMLError QueryBoolAttribute( const char* name, bool* value ) const {
1345  const XMLAttribute* a = FindAttribute( name );
1346  if ( !a ) {
1347  return XML_NO_ATTRIBUTE;
1348  }
1349  return a->QueryBoolValue( value );
1350  }
1352  XMLError QueryDoubleAttribute( const char* name, double* value ) const {
1353  const XMLAttribute* a = FindAttribute( name );
1354  if ( !a ) {
1355  return XML_NO_ATTRIBUTE;
1356  }
1357  return a->QueryDoubleValue( value );
1358  }
1360  XMLError QueryFloatAttribute( const char* name, float* value ) const {
1361  const XMLAttribute* a = FindAttribute( name );
1362  if ( !a ) {
1363  return XML_NO_ATTRIBUTE;
1364  }
1365  return a->QueryFloatValue( value );
1366  }
1367 
1369  XMLError QueryStringAttribute(const char* name, const char** value) const {
1370  const XMLAttribute* a = FindAttribute(name);
1371  if (!a) {
1372  return XML_NO_ATTRIBUTE;
1373  }
1374  *value = a->Value();
1375  return XML_SUCCESS;
1376  }
1377 
1378 
1379 
1397  int QueryAttribute( const char* name, int* value ) const {
1398  return QueryIntAttribute( name, value );
1399  }
1400 
1401  int QueryAttribute( const char* name, unsigned int* value ) const {
1402  return QueryUnsignedAttribute( name, value );
1403  }
1404 
1405  int QueryAttribute(const char* name, int64_t* value) const {
1406  return QueryInt64Attribute(name, value);
1407  }
1408 
1409  int QueryAttribute( const char* name, bool* value ) const {
1410  return QueryBoolAttribute( name, value );
1411  }
1412 
1413  int QueryAttribute( const char* name, double* value ) const {
1414  return QueryDoubleAttribute( name, value );
1415  }
1416 
1417  int QueryAttribute( const char* name, float* value ) const {
1418  return QueryFloatAttribute( name, value );
1419  }
1420 
1422  void SetAttribute( const char* name, const char* value ) {
1423  XMLAttribute* a = FindOrCreateAttribute( name );
1424  a->SetAttribute( value );
1425  }
1427  void SetAttribute( const char* name, int value ) {
1428  XMLAttribute* a = FindOrCreateAttribute( name );
1429  a->SetAttribute( value );
1430  }
1432  void SetAttribute( const char* name, unsigned value ) {
1433  XMLAttribute* a = FindOrCreateAttribute( name );
1434  a->SetAttribute( value );
1435  }
1436 
1438  void SetAttribute(const char* name, int64_t value) {
1439  XMLAttribute* a = FindOrCreateAttribute(name);
1440  a->SetAttribute(value);
1441  }
1442 
1444  void SetAttribute( const char* name, bool value ) {
1445  XMLAttribute* a = FindOrCreateAttribute( name );
1446  a->SetAttribute( value );
1447  }
1449  void SetAttribute( const char* name, double value ) {
1450  XMLAttribute* a = FindOrCreateAttribute( name );
1451  a->SetAttribute( value );
1452  }
1454  void SetAttribute( const char* name, float value ) {
1455  XMLAttribute* a = FindOrCreateAttribute( name );
1456  a->SetAttribute( value );
1457  }
1458 
1462  void DeleteAttribute( const char* name );
1463 
1465  const XMLAttribute* FirstAttribute() const {
1466  return _rootAttribute;
1467  }
1469  const XMLAttribute* FindAttribute( const char* name ) const;
1470 
1499  const char* GetText() const;
1500 
1535  void SetText( const char* inText );
1537  void SetText( int value );
1539  void SetText( unsigned value );
1541  void SetText(int64_t value);
1543  void SetText( bool value );
1545  void SetText( double value );
1547  void SetText( float value );
1548 
1575  XMLError QueryIntText( int* ival ) const;
1577  XMLError QueryUnsignedText( unsigned* uval ) const;
1579  XMLError QueryInt64Text(int64_t* uval) const;
1581  XMLError QueryBoolText( bool* bval ) const;
1583  XMLError QueryDoubleText( double* dval ) const;
1585  XMLError QueryFloatText( float* fval ) const;
1586 
1587  int IntText(int defaultValue = 0) const;
1588 
1590  unsigned UnsignedText(unsigned defaultValue = 0) const;
1592  int64_t Int64Text(int64_t defaultValue = 0) const;
1594  bool BoolText(bool defaultValue = false) const;
1596  double DoubleText(double defaultValue = 0) const;
1598  float FloatText(float defaultValue = 0) const;
1599 
1600  // internal:
1602  OPEN, // <foo>
1603  CLOSED, // <foo/>
1604  CLOSING // </foo>
1605  };
1607  return _closingType;
1608  }
1609  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1610  virtual bool ShallowEqual( const XMLNode* compare ) const;
1611 
1612 protected:
1613  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1614 
1615 private:
1616  XMLElement( XMLDocument* doc );
1617  virtual ~XMLElement();
1618  XMLElement( const XMLElement& ); // not supported
1619  void operator=( const XMLElement& ); // not supported
1620 
1621  XMLAttribute* FindAttribute( const char* name ) {
1622  return const_cast<XMLAttribute*>(const_cast<const XMLElement*>(this)->FindAttribute( name ));
1623  }
1624  XMLAttribute* FindOrCreateAttribute( const char* name );
1625  //void LinkAttribute( XMLAttribute* attrib );
1626  char* ParseAttributes( char* p, int* curLineNumPtr );
1627  static void DeleteAttribute( XMLAttribute* attribute );
1628  XMLAttribute* CreateAttribute();
1629 
1630  enum { BUF_SIZE = 200 };
1632  // The attribute list is ordered; there is no 'lastAttribute'
1633  // because the list needs to be scanned for dupes before adding
1634  // a new attribute.
1636 };
1637 
1638 
1642 };
1643 
1644 
1651 {
1652  friend class XMLElement;
1653  // Gives access to SetError and Push/PopDepth, but over-access for everything else.
1654  // Wishing C++ had "internal" scope.
1655  friend class XMLNode;
1656  friend class XMLText;
1657  friend class XMLComment;
1658  friend class XMLDeclaration;
1659  friend class XMLUnknown;
1660 public:
1662  XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
1663  ~XMLDocument();
1664 
1666  TIXMLASSERT( this == _document );
1667  return this;
1668  }
1669  virtual const XMLDocument* ToDocument() const {
1670  TIXMLASSERT( this == _document );
1671  return this;
1672  }
1673 
1684  XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) );
1685 
1691  XMLError LoadFile( const char* filename );
1692 
1704  XMLError LoadFile( FILE* );
1705 
1711  XMLError SaveFile( const char* filename, bool compact = false );
1712 
1720  XMLError SaveFile( FILE* fp, bool compact = false );
1721 
1722  bool ProcessEntities() const {
1723  return _processEntities;
1724  }
1726  return _whitespaceMode;
1727  }
1728 
1732  bool HasBOM() const {
1733  return _writeBOM;
1734  }
1737  void SetBOM( bool useBOM ) {
1738  _writeBOM = useBOM;
1739  }
1740 
1745  return FirstChildElement();
1746  }
1747  const XMLElement* RootElement() const {
1748  return FirstChildElement();
1749  }
1750 
1765  void Print( XMLPrinter* streamer=0 ) const;
1766  virtual bool Accept( XMLVisitor* visitor ) const;
1767 
1773  XMLElement* NewElement( const char* name );
1779  XMLComment* NewComment( const char* comment );
1785  XMLText* NewText( const char* text );
1797  XMLDeclaration* NewDeclaration( const char* text=0 );
1803  XMLUnknown* NewUnknown( const char* text );
1804 
1809  void DeleteNode( XMLNode* node );
1810 
1811  void ClearError() {
1812  SetError(XML_SUCCESS, 0, 0);
1813  }
1814 
1816  bool Error() const {
1817  return _errorID != XML_SUCCESS;
1818  }
1820  XMLError ErrorID() const {
1821  return _errorID;
1822  }
1823  const char* ErrorName() const;
1824  static const char* ErrorIDToName(XMLError errorID);
1825 
1829  const char* ErrorStr() const;
1830 
1832  void PrintError() const;
1833 
1835  int ErrorLineNum() const
1836  {
1837  return _errorLineNum;
1838  }
1839 
1841  void Clear();
1842 
1850  void DeepCopy(XMLDocument* target) const;
1851 
1852  // internal
1853  char* Identify( char* p, XMLNode** node );
1854 
1855  // internal
1856  void MarkInUse(XMLNode*);
1857 
1858  virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
1859  return 0;
1860  }
1861  virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
1862  return false;
1863  }
1864 
1865 private:
1866  XMLDocument( const XMLDocument& ); // not supported
1867  void operator=( const XMLDocument& ); // not supported
1868 
1878  // Memory tracking does add some overhead.
1879  // However, the code assumes that you don't
1880  // have a bunch of unlinked nodes around.
1881  // Therefore it takes less memory to track
1882  // in the document vs. a linked list in the XMLNode,
1883  // and the performance is the same.
1885 
1890 
1891  static const char* _errorNames[XML_ERROR_COUNT];
1892 
1893  void Parse();
1894 
1895  void SetError( XMLError error, int lineNum, const char* format, ... );
1896 
1897  // Something of an obvious security hole, once it was discovered.
1898  // Either an ill-formed XML or an excessively deep one can overflow
1899  // the stack. Track stack depth, and error out if needed.
1901  public:
1902  DepthTracker(XMLDocument * document) {
1903  this->_document = document;
1904  document->PushDepth();
1905  }
1907  _document->PopDepth();
1908  }
1909  private:
1911  };
1912  void PushDepth();
1913  void PopDepth();
1914 
1915  template<class NodeType, int PoolElementSize>
1916  NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
1917 };
1918 
1919 template<class NodeType, int PoolElementSize>
1921 {
1922  TIXMLASSERT( sizeof( NodeType ) == PoolElementSize );
1923  TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() );
1924  NodeType* returnNode = new (pool.Alloc()) NodeType( this );
1925  TIXMLASSERT( returnNode );
1926  returnNode->_memPool = &pool;
1927 
1928  _unlinked.Push(returnNode);
1929  return returnNode;
1930 }
1931 
1988 {
1989 public:
1991  XMLHandle( XMLNode* node ) : _node( node ) {
1992  }
1994  XMLHandle( XMLNode& node ) : _node( &node ) {
1995  }
1997  XMLHandle( const XMLHandle& ref ) : _node( ref._node ) {
1998  }
2000  XMLHandle& operator=( const XMLHandle& ref ) {
2001  _node = ref._node;
2002  return *this;
2003  }
2004 
2007  return XMLHandle( _node ? _node->FirstChild() : 0 );
2008  }
2010  XMLHandle FirstChildElement( const char* name = 0 ) {
2011  return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
2012  }
2015  return XMLHandle( _node ? _node->LastChild() : 0 );
2016  }
2018  XMLHandle LastChildElement( const char* name = 0 ) {
2019  return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
2020  }
2023  return XMLHandle( _node ? _node->PreviousSibling() : 0 );
2024  }
2026  XMLHandle PreviousSiblingElement( const char* name = 0 ) {
2027  return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2028  }
2031  return XMLHandle( _node ? _node->NextSibling() : 0 );
2032  }
2034  XMLHandle NextSiblingElement( const char* name = 0 ) {
2035  return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2036  }
2037 
2040  return _node;
2041  }
2044  return ( _node ? _node->ToElement() : 0 );
2045  }
2048  return ( _node ? _node->ToText() : 0 );
2049  }
2052  return ( _node ? _node->ToUnknown() : 0 );
2053  }
2056  return ( _node ? _node->ToDeclaration() : 0 );
2057  }
2058 
2059 private:
2061 };
2062 
2063 
2069 {
2070 public:
2071  XMLConstHandle( const XMLNode* node ) : _node( node ) {
2072  }
2073  XMLConstHandle( const XMLNode& node ) : _node( &node ) {
2074  }
2075  XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) {
2076  }
2077 
2079  _node = ref._node;
2080  return *this;
2081  }
2082 
2083  const XMLConstHandle FirstChild() const {
2084  return XMLConstHandle( _node ? _node->FirstChild() : 0 );
2085  }
2086  const XMLConstHandle FirstChildElement( const char* name = 0 ) const {
2087  return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
2088  }
2089  const XMLConstHandle LastChild() const {
2090  return XMLConstHandle( _node ? _node->LastChild() : 0 );
2091  }
2092  const XMLConstHandle LastChildElement( const char* name = 0 ) const {
2093  return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
2094  }
2096  return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
2097  }
2098  const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const {
2099  return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2100  }
2101  const XMLConstHandle NextSibling() const {
2102  return XMLConstHandle( _node ? _node->NextSibling() : 0 );
2103  }
2104  const XMLConstHandle NextSiblingElement( const char* name = 0 ) const {
2105  return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2106  }
2107 
2108 
2109  const XMLNode* ToNode() const {
2110  return _node;
2111  }
2112  const XMLElement* ToElement() const {
2113  return ( _node ? _node->ToElement() : 0 );
2114  }
2115  const XMLText* ToText() const {
2116  return ( _node ? _node->ToText() : 0 );
2117  }
2118  const XMLUnknown* ToUnknown() const {
2119  return ( _node ? _node->ToUnknown() : 0 );
2120  }
2122  return ( _node ? _node->ToDeclaration() : 0 );
2123  }
2124 
2125 private:
2126  const XMLNode* _node;
2127 };
2128 
2129 
2173 {
2174 public:
2181  XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 );
2182  virtual ~XMLPrinter() {}
2183 
2185  void PushHeader( bool writeBOM, bool writeDeclaration );
2189  void OpenElement( const char* name, bool compactMode=false );
2191  void PushAttribute( const char* name, const char* value );
2192  void PushAttribute( const char* name, int value );
2193  void PushAttribute( const char* name, unsigned value );
2194  void PushAttribute(const char* name, int64_t value);
2195  void PushAttribute( const char* name, bool value );
2196  void PushAttribute( const char* name, double value );
2198  virtual void CloseElement( bool compactMode=false );
2199 
2201  void PushText( const char* text, bool cdata=false );
2203  void PushText( int value );
2205  void PushText( unsigned value );
2207  void PushText(int64_t value);
2209  void PushText( bool value );
2211  void PushText( float value );
2213  void PushText( double value );
2214 
2216  void PushComment( const char* comment );
2217 
2218  void PushDeclaration( const char* value );
2219  void PushUnknown( const char* value );
2220 
2221  virtual bool VisitEnter( const XMLDocument& /*doc*/ );
2222  virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
2223  return true;
2224  }
2225 
2226  virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
2227  virtual bool VisitExit( const XMLElement& element );
2228 
2229  virtual bool Visit( const XMLText& text );
2230  virtual bool Visit( const XMLComment& comment );
2231  virtual bool Visit( const XMLDeclaration& declaration );
2232  virtual bool Visit( const XMLUnknown& unknown );
2233 
2238  const char* CStr() const {
2239  return _buffer.Mem();
2240  }
2246  int CStrSize() const {
2247  return _buffer.Size();
2248  }
2253  void ClearBuffer() {
2254  _buffer.Clear();
2255  _buffer.Push(0);
2256  _firstElement = true;
2257  }
2258 
2259 protected:
2260  virtual bool CompactMode( const XMLElement& ) { return _compactMode; }
2261 
2265  virtual void PrintSpace( int depth );
2266  void Print( const char* format, ... );
2267  void Write( const char* data, size_t size );
2268  inline void Write( const char* data ) { Write( data, strlen( data ) ); }
2269  void Putc( char ch );
2270 
2271  void SealElementIfJustOpened();
2274 
2275 private:
2276  void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
2277 
2279  FILE* _fp;
2280  int _depth;
2284 
2285  enum {
2286  ENTITY_RANGE = 64,
2287  BUF_SIZE = 200
2288  };
2289  bool _entityFlag[ENTITY_RANGE];
2290  bool _restrictedEntityFlag[ENTITY_RANGE];
2291 
2293 
2294  // Prohibit cloning, intentionally not implemented
2295  XMLPrinter( const XMLPrinter& );
2296  XMLPrinter& operator=( const XMLPrinter& );
2297 };
2298 
2299 
2300 } // tinyxml2
2301 
2302 #if defined(_MSC_VER)
2303 # pragma warning(pop)
2304 #endif
2305 
2306 #endif // TINYXML2_INCLUDED
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:1253
int QueryAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1397
int QueryAttribute(const char *name, bool *value) const
Definition: tinyxml2.h:1409
const XMLDeclaration * ToDeclaration() const
Definition: tinyxml2.h:2121
void CollapseWhitespace()
Definition: tinyxml2.cpp:238
const T * data(const std::vector< T, Alloc > &v)
Definition: flatbuffers.h:709
bool BoolValue() const
Query as a boolean. See IntValue()
Definition: tinyxml2.h:1167
void SetAttribute(const char *name, int64_t value)
Sets the named attribute to value.
Definition: tinyxml2.h:1438
bool Error() const
Return true if there was an error parsing the document.
Definition: tinyxml2.h:1816
virtual ~XMLText()
Definition: tinyxml2.h:1004
const XMLConstHandle FirstChild() const
Definition: tinyxml2.h:2083
void Push(T t)
Definition: tinyxml2.h:215
const XMLConstHandle LastChild() const
Definition: tinyxml2.h:2089
XMLError QueryIntValue(int *value) const
Definition: tinyxml2.cpp:1380
const XMLText * ToText() const
Definition: tinyxml2.h:2115
static const int TIXML2_PATCH_VERSION
Definition: tinyxml2.h:95
NodeType * CreateUnlinkedNode(MemPoolT< PoolElementSize > &pool)
Definition: tinyxml2.h:1920
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1326
virtual const XMLDeclaration * ToDeclaration() const
Definition: tinyxml2.h:714
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:690
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1991
virtual const XMLComment * ToComment() const
Definition: tinyxml2.h:708
const XMLNode * _node
Definition: tinyxml2.h:2126
virtual ~MemPool()
Definition: tinyxml2.h:323
XMLElement * PreviousSiblingElement(const char *name=0)
Definition: tinyxml2.h:802
int CurrentAllocs() const
Definition: tinyxml2.h:361
T * PushArr(int count)
Definition: tinyxml2.h:222
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1416
const T & operator[](int i) const
Definition: tinyxml2.h:251
static raw_event_t * buffer
Definition: minitrace.cpp:54
XMLElement * LastChildElement(const char *name=0)
Definition: tinyxml2.h:786
XMLAttribute * _rootAttribute
Definition: tinyxml2.h:1635
MemPoolT< sizeof(XMLAttribute) > _attributePool
Definition: tinyxml2.h:1887
ElementClosingType ClosingType() const
Definition: tinyxml2.h:1606
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
Definition: tinyxml2.h:1432
virtual ~XMLAttribute()
Definition: tinyxml2.h:1220
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:686
int GetLineNum() const
Gets the line number the node is in, if the document was parsed from a file.
Definition: tinyxml2.h:738
XMLNode * FirstChild()
Definition: tinyxml2.h:759
XMLConstHandle & operator=(const XMLConstHandle &ref)
Definition: tinyxml2.h:2078
static FILE * file
Definition: minitrace.cpp:59
const T * Mem() const
Definition: tinyxml2.h:278
virtual const XMLText * ToText() const
Definition: tinyxml2.h:705
XMLError QueryInt64Value(int64_t *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1398
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
Definition: tinyxml2.h:486
XMLNode * _lastChild
Definition: tinyxml2.h:946
virtual ~XMLVisitor()
Definition: tinyxml2.h:474
static const char * SkipWhiteSpace(const char *p, int *curLineNumPtr)
Definition: tinyxml2.h:546
bool CData() const
Returns true if this is a CDATA text element.
Definition: tinyxml2.h:995
void Set(char *start, char *end, int flags)
Definition: tinyxml2.h:144
static bool IsNameChar(unsigned char ch)
Definition: tinyxml2.h:579
static bool IsWhiteSpace(char p)
Definition: tinyxml2.h:564
void TransferTo(StrPair *other)
Definition: tinyxml2.cpp:144
bool LoadFile(const char *name, bool binary, std::string *buf)
XMLNode * _next
Definition: tinyxml2.h:949
const XMLElement * RootElement() const
Definition: tinyxml2.h:1747
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:1095
virtual bool Visit(const XMLText &)
Visit a text node.
Definition: tinyxml2.h:499
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:755
DepthTracker(XMLDocument *document)
Definition: tinyxml2.h:1902
XMLNode * _firstChild
Definition: tinyxml2.h:945
virtual bool ShallowEqual(const XMLNode *) const
Definition: tinyxml2.h:1861
static char * SkipWhiteSpace(char *p, int *curLineNumPtr)
Definition: tinyxml2.h:558
double DoubleValue() const
Query as a double. See IntValue()
Definition: tinyxml2.h:1173
XMLConstHandle(const XMLNode *node)
Definition: tinyxml2.h:2071
XMLNode * PreviousSibling()
Definition: tinyxml2.h:795
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:481
char * ParseName(char *in)
Definition: tinyxml2.cpp:218
const T & PeekTop() const
Definition: tinyxml2.h:256
const char * Value() const
The value of the attribute.
Definition: tinyxml2.cpp:1341
XMLConstHandle(const XMLNode &node)
Definition: tinyxml2.h:2073
int QueryAttribute(const char *name, double *value) const
Definition: tinyxml2.h:1413
void SetAttribute(const char *value)
Set the attribute to a string value.
Definition: tinyxml2.cpp:1434
virtual const XMLText * ToText() const
Definition: tinyxml2.h:986
void * _userData
Definition: tinyxml2.h:951
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1360
virtual const XMLUnknown * ToUnknown() const
Definition: tinyxml2.h:717
XMLNode * _parent
Definition: tinyxml2.h:941
const XMLNode * ToNode() const
Definition: tinyxml2.h:2109
const XMLConstHandle PreviousSibling() const
Definition: tinyxml2.h:2095
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:983
MemPool * _memPool
Definition: tinyxml2.h:954
virtual bool Visit(const XMLComment &)
Visit a comment node.
Definition: tinyxml2.h:503
XMLHandle LastChild()
Get the last child of this handle.
Definition: tinyxml2.h:2014
void Write(const char *data)
Definition: tinyxml2.h:2268
static const char * writeBoolTrue
Definition: tinyxml2.h:630
XMLNode * Parent()
Definition: tinyxml2.h:745
virtual XMLNode * ShallowClone(XMLDocument *) const
Definition: tinyxml2.h:1858
int Capacity() const
Definition: tinyxml2.h:266
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition: tinyxml2.h:1422
int Untracked() const
Definition: tinyxml2.h:413
XMLHandle FirstChildElement(const char *name=0)
Get the first child element of this handle.
Definition: tinyxml2.h:2010
static const int TIXML2_MINOR_VERSION
Definition: tinyxml2.h:94
const XMLUnknown * ToUnknown() const
Definition: tinyxml2.h:2118
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
Definition: tinyxml2.h:2000
bool Empty() const
Definition: tinyxml2.h:242
const XMLConstHandle NextSibling() const
Definition: tinyxml2.h:2101
void SetBOM(bool useBOM)
Definition: tinyxml2.h:1737
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1425
XMLError QueryInt64Attribute(const char *name, int64_t *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1335
bool ProcessEntities() const
Definition: tinyxml2.h:1722
DynArray< char, 20 > _buffer
Definition: tinyxml2.h:2292
XMLError ErrorID() const
Return the errorID.
Definition: tinyxml2.h:1820
XMLElement * RootElement()
Definition: tinyxml2.h:1744
XMLHandle NextSiblingElement(const char *name=0)
Get the next sibling element of this handle.
Definition: tinyxml2.h:2034
static bool IsUTF8Continuation(char p)
Definition: tinyxml2.h:596
const XMLNode * Parent() const
Get the parent of this node on the DOM.
Definition: tinyxml2.h:741
virtual ~XMLPrinter()
Definition: tinyxml2.h:2182
XMLAttribute * _next
Definition: tinyxml2.h:1231
const XMLAttribute * Next() const
The next attribute in the list.
Definition: tinyxml2.h:1140
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1352
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
Definition: tinyxml2.h:1249
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
Definition: tinyxml2.h:1449
int IntValue() const
Definition: tinyxml2.h:1148
int QueryAttribute(const char *name, float *value) const
Definition: tinyxml2.h:1417
const XMLConstHandle PreviousSiblingElement(const char *name=0) const
Definition: tinyxml2.h:2098
static const int TIXML2_MAJOR_VERSION
Definition: tinyxml2.h:93
StrPair _value
Definition: tinyxml2.h:942
MemPoolT< sizeof(XMLComment) > _commentPool
Definition: tinyxml2.h:1889
void * GetUserData() const
Definition: tinyxml2.h:932
#define TINYXML2_LIB
Definition: tinyxml2.h:71
XMLHandle LastChildElement(const char *name=0)
Get the last child element of this handle.
Definition: tinyxml2.h:2018
void EnsureCapacity(int cap)
Definition: tinyxml2.h:292
const char * GetStr()
Definition: tinyxml2.cpp:267
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:2222
void SetStr(const char *str, int flags=0)
Definition: tinyxml2.cpp:180
int Size() const
Definition: tinyxml2.h:261
XMLHandle(XMLNode &node)
Create a handle from a node.
Definition: tinyxml2.h:1994
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
Definition: tinyxml2.h:991
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:672
char * ParseText(char *in, const char *endTag, int strFlags, int *curLineNumPtr)
Definition: tinyxml2.cpp:193
void SwapRemove(int i)
Definition: tinyxml2.h:271
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:667
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:1060
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:698
ElementClosingType _closingType
Definition: tinyxml2.h:1631
int ErrorLineNum() const
Return the line where the error occured, or zero if unknown.
Definition: tinyxml2.h:1835
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
Definition: tinyxml2.h:586
int64_t Int64Value() const
Definition: tinyxml2.h:1154
virtual void * Alloc()
Definition: tinyxml2.h:365
virtual bool VisitExit(const XMLElement &)
Visit an element.
Definition: tinyxml2.h:490
int QueryAttribute(const char *name, int64_t *value) const
Definition: tinyxml2.h:1405
virtual const XMLElement * ToElement() const
Definition: tinyxml2.h:1256
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
Definition: tinyxml2.h:507
XMLConstHandle(const XMLConstHandle &ref)
Definition: tinyxml2.h:2075
XMLElement * NextSiblingElement(const char *name=0)
Definition: tinyxml2.h:818
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition: tinyxml2.h:791
virtual const XMLDeclaration * ToDeclaration() const
Definition: tinyxml2.h:1063
XMLNode * LinkEndChild(XMLNode *addThis)
Definition: tinyxml2.h:831
XMLAttribute * FindAttribute(const char *name)
Definition: tinyxml2.h:1621
XMLElement * FirstChildElement(const char *name=0)
Definition: tinyxml2.h:768
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
Definition: tinyxml2.h:1444
void SetAttribute(const char *name, float value)
Sets the named attribute to value.
Definition: tinyxml2.h:1454
static volatile int count
Definition: minitrace.cpp:55
XMLError QueryStringAttribute(const char *name, const char **value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1369
const XMLConstHandle FirstChildElement(const char *name=0) const
Definition: tinyxml2.h:2086
#define TIXMLASSERT(x)
Definition: tinyxml2.h:86
DynArray< const char *, 10 > _stack
Definition: tinyxml2.h:2273
XMLNode * NextSibling()
Definition: tinyxml2.h:811
XMLError QueryIntAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1317
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
Definition: tinyxml2.h:2039
void SetUserData(void *userData)
Definition: tinyxml2.h:925
XMLHandle NextSibling()
Get the next sibling of this handle.
Definition: tinyxml2.h:2030
unsigned UnsignedValue() const
Query as an unsigned integer. See IntValue()
Definition: tinyxml2.h:1161
void PopArr(int count)
Definition: tinyxml2.h:237
DynArray< XMLNode *, 10 > _unlinked
Definition: tinyxml2.h:1884
DynArray< Block *, 10 > _blockPtrs
Definition: tinyxml2.h:441
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1389
XMLText(XMLDocument *doc)
Definition: tinyxml2.h:1003
static bool IsNameStartChar(unsigned char ch)
Definition: tinyxml2.h:568
const XMLElement * ToElement() const
Definition: tinyxml2.h:2112
XMLDocument * _document
Definition: tinyxml2.h:940
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:682
int GetLineNum() const
Gets the line number the attribute is in, if the document was parsed from a file. ...
Definition: tinyxml2.h:1137
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
Definition: tinyxml2.h:1427
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1344
bool HasBOM() const
Definition: tinyxml2.h:1732
virtual void Free(void *mem)
Definition: tinyxml2.h:391
XMLText * ToText()
Safe cast to XMLText. This can return null.
Definition: tinyxml2.h:2047
void operator=(StrPair &other)
int QueryAttribute(const char *name, unsigned int *value) const
Definition: tinyxml2.h:1401
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition: tinyxml2.h:773
T & operator[](int i)
Definition: tinyxml2.h:246
const XMLConstHandle LastChildElement(const char *name=0) const
Definition: tinyxml2.h:2092
XMLNode * LastChild()
Definition: tinyxml2.h:777
const XMLConstHandle NextSiblingElement(const char *name=0) const
Definition: tinyxml2.h:2104
virtual bool CompactMode(const XMLElement &)
Definition: tinyxml2.h:2260
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
Definition: tinyxml2.h:2022
MemPoolT< sizeof(XMLText) > _textPool
Definition: tinyxml2.h:1888
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
Definition: tinyxml2.h:2055
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml2.h:750
virtual const XMLDocument * ToDocument() const
Definition: tinyxml2.h:711
int CStrSize() const
Definition: tinyxml2.h:2246
MemPoolT< sizeof(XMLElement) > _elementPool
Definition: tinyxml2.h:1886
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
Definition: tinyxml2.h:1465
virtual int ItemSize() const
Definition: tinyxml2.h:358
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
Definition: tinyxml2.h:2051
static const char * writeBoolFalse
Definition: tinyxml2.h:631
XMLHandle FirstChild()
Get the first child of this handle.
Definition: tinyxml2.h:2006
virtual const XMLUnknown * ToUnknown() const
Definition: tinyxml2.h:1098
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition: tinyxml2.h:2043
XMLHandle PreviousSiblingElement(const char *name=0)
Get the previous sibling element of this handle.
Definition: tinyxml2.h:2026
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
Definition: tinyxml2.h:495
Whitespace _whitespaceMode
Definition: tinyxml2.h:1872
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:477
XMLNode * _prev
Definition: tinyxml2.h:948
virtual const XMLElement * ToElement() const
Definition: tinyxml2.h:702
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1407
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:1665
NodeType
Definition: basic_types.h:16
Whitespace WhitespaceMode() const
Definition: tinyxml2.h:1725
float FloatValue() const
Query as a float. See IntValue()
Definition: tinyxml2.h:1179
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:694
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:678
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:1021
void Trace(const char *name)
Definition: tinyxml2.h:403
virtual const XMLComment * ToComment() const
Definition: tinyxml2.h:1024
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition: tinyxml2.h:807
static const int TINYXML2_MAX_ELEMENT_DEPTH
Definition: tinyxml2.h:106
XMLHandle(const XMLHandle &ref)
Copy constructor.
Definition: tinyxml2.h:1997
virtual const XMLDocument * ToDocument() const
Definition: tinyxml2.h:1669
bool SaveFile(const char *name, const char *buf, size_t len, bool binary)
Definition: util.h:223
bool Empty() const
Definition: tinyxml2.h:155
const char * CStr() const
Definition: tinyxml2.h:2238
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition: tinyxml2.h:1245
void SetInternedStr(const char *str)
Definition: tinyxml2.h:159


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sun Feb 3 2019 03:14:32