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 BT_TINYXML2_INCLUDED
25 #define BT_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("hidden")))
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 = 7;
102 static const int TIXML2_MINOR_VERSION = 0;
103 static const int TIXML2_PATCH_VERSION = 1;
104 
105 #define TINYXML2_MAJOR_VERSION 7
106 #define TINYXML2_MINOR_VERSION 0
107 #define TINYXML2_PATCH_VERSION 1
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 BT_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  Isn't clear why TINYXML2_LIB is needed; but seems to fix #719
134 */
136 {
137 public:
138  enum {
139  NEEDS_ENTITY_PROCESSING = 0x01,
140  NEEDS_NEWLINE_NORMALIZATION = 0x02,
141  NEEDS_WHITESPACE_COLLAPSING = 0x04,
142 
143  TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
144  TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
145  ATTRIBUTE_NAME = 0,
146  ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
147  ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
148  COMMENT = NEEDS_NEWLINE_NORMALIZATION
149  };
150 
151  StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
152  ~StrPair();
153 
154  void Set( char* start, char* end, int flags ) {
155  TIXMLASSERT( start );
156  TIXMLASSERT( end );
157  Reset();
158  _start = start;
159  _end = end;
160  _flags = flags | NEEDS_FLUSH;
161  }
162 
163  const char* GetStr();
164 
165  bool Empty() const {
166  return _start == _end;
167  }
168 
169  void SetInternedStr( const char* str ) {
170  Reset();
171  _start = const_cast<char*>(str);
172  }
173 
174  void SetStr( const char* str, int flags=0 );
175 
176  char* ParseText( char* in, const char* endTag, int strFlags, int* curLineNumPtr );
177  char* ParseName( char* in );
178 
179  void TransferTo( StrPair* other );
180  void Reset();
181 
182 private:
183  void CollapseWhitespace();
184 
185  enum {
186  NEEDS_FLUSH = 0x100,
187  NEEDS_DELETE = 0x200
188  };
189 
190  int _flags;
191  char* _start;
192  char* _end;
193 
194  StrPair( const StrPair& other ); // not supported
195  void operator=( const StrPair& other ); // not supported, use TransferTo()
196 };
197 
198 
199 /*
200  A dynamic array of Plain Old Data. Doesn't support constructors, etc.
201  Has a small initial memory pool, so that low or no usage will not
202  cause a call to new/delete
203 */
204 template <class T, int INITIAL_SIZE>
205 class DynArray
206 {
207 public:
209  _mem( _pool ),
210  _allocated( INITIAL_SIZE ),
211  _size( 0 )
212  {
213  }
214 
216  if ( _mem != _pool ) {
217  delete [] _mem;
218  }
219  }
220 
221  void Clear() {
222  _size = 0;
223  }
224 
225  void Push( T t ) {
226  TIXMLASSERT( _size < INT_MAX );
227  EnsureCapacity( _size+1 );
228  _mem[_size] = t;
229  ++_size;
230  }
231 
232  T* PushArr( int count ) {
233  TIXMLASSERT( count >= 0 );
234  TIXMLASSERT( _size <= INT_MAX - count );
235  EnsureCapacity( _size+count );
236  T* ret = &_mem[_size];
237  _size += count;
238  return ret;
239  }
240 
241  T Pop() {
242  TIXMLASSERT( _size > 0 );
243  --_size;
244  return _mem[_size];
245  }
246 
247  void PopArr( int count ) {
248  TIXMLASSERT( _size >= count );
249  _size -= count;
250  }
251 
252  bool Empty() const {
253  return _size == 0;
254  }
255 
256  T& operator[](int i) {
257  TIXMLASSERT( i>= 0 && i < _size );
258  return _mem[i];
259  }
260 
261  const T& operator[](int i) const {
262  TIXMLASSERT( i>= 0 && i < _size );
263  return _mem[i];
264  }
265 
266  const T& PeekTop() const {
267  TIXMLASSERT( _size > 0 );
268  return _mem[ _size - 1];
269  }
270 
271  int Size() const {
272  TIXMLASSERT( _size >= 0 );
273  return _size;
274  }
275 
276  int Capacity() const {
277  TIXMLASSERT( _allocated >= INITIAL_SIZE );
278  return _allocated;
279  }
280 
281  void SwapRemove(int i) {
282  TIXMLASSERT(i >= 0 && i < _size);
283  TIXMLASSERT(_size > 0);
284  _mem[i] = _mem[_size - 1];
285  --_size;
286  }
287 
288  const T* Mem() const {
289  TIXMLASSERT( _mem );
290  return _mem;
291  }
292 
293  T* Mem() {
294  TIXMLASSERT( _mem );
295  return _mem;
296  }
297 
298 private:
299  DynArray( const DynArray& ); // not supported
300  void operator=( const DynArray& ); // not supported
301 
302  void EnsureCapacity( int cap ) {
303  TIXMLASSERT( cap > 0 );
304  if ( cap > _allocated ) {
305  TIXMLASSERT( cap <= INT_MAX / 2 );
306  int newAllocated = cap * 2;
307  T* newMem = new T[newAllocated];
308  TIXMLASSERT( newAllocated >= _size );
309  memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
310  if ( _mem != _pool ) {
311  delete [] _mem;
312  }
313  _mem = newMem;
314  _allocated = newAllocated;
315  }
316  }
317 
318  T* _mem;
319  T _pool[INITIAL_SIZE];
320  int _allocated; // objects allocated
321  int _size; // number objects in use
322 };
323 
324 
325 /*
326  Parent virtual class of a pool for fast allocation
327  and deallocation of objects.
328 */
329 class MemPool
330 {
331 public:
332  MemPool() {}
333  virtual ~MemPool() {}
334 
335  virtual int ItemSize() const = 0;
336  virtual void* Alloc() = 0;
337  virtual void Free( void* ) = 0;
338  virtual void SetTracked() = 0;
339 };
340 
341 
342 /*
343  Template child class to create pools of the correct type.
344 */
345 template< int ITEM_SIZE >
346 class MemPoolT : public MemPool
347 {
348 public:
349  MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
352  }
353 
354  void Clear() {
355  // Delete the blocks.
356  while( !_blockPtrs.Empty()) {
357  Block* lastBlock = _blockPtrs.Pop();
358  delete lastBlock;
359  }
360  _root = 0;
361  _currentAllocs = 0;
362  _nAllocs = 0;
363  _maxAllocs = 0;
364  _nUntracked = 0;
365  }
366 
367  virtual int ItemSize() const {
368  return ITEM_SIZE;
369  }
370  int CurrentAllocs() const {
371  return _currentAllocs;
372  }
373 
374  virtual void* Alloc() {
375  if ( !_root ) {
376  // Need a new block.
377  Block* block = new Block();
378  _blockPtrs.Push( block );
379 
380  Item* blockItems = block->items;
381  for( int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
382  blockItems[i].next = &(blockItems[i + 1]);
383  }
384  blockItems[ITEMS_PER_BLOCK - 1].next = 0;
385  _root = blockItems;
386  }
387  Item* const result = _root;
388  TIXMLASSERT( result != 0 );
389  _root = _root->next;
390 
391  ++_currentAllocs;
392  if ( _currentAllocs > _maxAllocs ) {
393  _maxAllocs = _currentAllocs;
394  }
395  ++_nAllocs;
396  ++_nUntracked;
397  return result;
398  }
399 
400  virtual void Free( void* mem ) {
401  if ( !mem ) {
402  return;
403  }
404  --_currentAllocs;
405  Item* item = static_cast<Item*>( mem );
406 #ifdef TINYXML2_DEBUG
407  memset( item, 0xfe, sizeof( *item ) );
408 #endif
409  item->next = _root;
410  _root = item;
411  }
412  void Trace( const char* name ) {
413  printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
414  name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs,
415  ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
416  }
417 
418  void SetTracked() {
419  --_nUntracked;
420  }
421 
422  int Untracked() const {
423  return _nUntracked;
424  }
425 
426  // This number is perf sensitive. 4k seems like a good tradeoff on my machine.
427  // The test file is large, 170k.
428  // Release: VS2010 gcc(no opt)
429  // 1k: 4000
430  // 2k: 4000
431  // 4k: 3900 21000
432  // 16k: 5200
433  // 32k: 4300
434  // 64k: 4000 21000
435  // Declared public because some compilers do not accept to use ITEMS_PER_BLOCK
436  // in private part if ITEMS_PER_BLOCK is private
437  enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE };
438 
439 private:
440  MemPoolT( const MemPoolT& ); // not supported
441  void operator=( const MemPoolT& ); // not supported
442 
443  union Item {
445  char itemData[ITEM_SIZE];
446  };
447  struct Block {
448  Item items[ITEMS_PER_BLOCK];
449  };
451  Item* _root;
452 
454  int _nAllocs;
457 };
458 
459 
460 
481 {
482 public:
483  virtual ~XMLVisitor() {}
484 
486  virtual bool VisitEnter( const XMLDocument& /*doc*/ ) {
487  return true;
488  }
490  virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
491  return true;
492  }
493 
495  virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) {
496  return true;
497  }
499  virtual bool VisitExit( const XMLElement& /*element*/ ) {
500  return true;
501  }
502 
504  virtual bool Visit( const XMLDeclaration& /*declaration*/ ) {
505  return true;
506  }
508  virtual bool Visit( const XMLText& /*text*/ ) {
509  return true;
510  }
512  virtual bool Visit( const XMLComment& /*comment*/ ) {
513  return true;
514  }
516  virtual bool Visit( const XMLUnknown& /*unknown*/ ) {
517  return true;
518  }
519 };
520 
521 // WARNING: must match XMLDocument::_errorNames[]
522 enum XMLError {
542 
544 };
545 
546 
547 /*
548  Utility functionality.
549 */
551 {
552 public:
553  static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) {
554  TIXMLASSERT( p );
555 
556  while( IsWhiteSpace(*p) ) {
557  if (curLineNumPtr && *p == '\n') {
558  ++(*curLineNumPtr);
559  }
560  ++p;
561  }
562  TIXMLASSERT( p );
563  return p;
564  }
565  static char* SkipWhiteSpace( char* p, int* curLineNumPtr ) {
566  return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p), curLineNumPtr ) );
567  }
568 
569  // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
570  // correct, but simple, and usually works.
571  static bool IsWhiteSpace( char p ) {
572  return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
573  }
574 
575  inline static bool IsNameStartChar( unsigned char ch ) {
576  if ( ch >= 128 ) {
577  // This is a heuristic guess in attempt to not implement Unicode-aware isalpha()
578  return true;
579  }
580  if ( isalpha( ch ) ) {
581  return true;
582  }
583  return ch == ':' || ch == '_';
584  }
585 
586  inline static bool IsNameChar( unsigned char ch ) {
587  return IsNameStartChar( ch )
588  || isdigit( ch )
589  || ch == '.'
590  || ch == '-';
591  }
592 
593  inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
594  if ( p == q ) {
595  return true;
596  }
597  TIXMLASSERT( p );
598  TIXMLASSERT( q );
599  TIXMLASSERT( nChar >= 0 );
600  return strncmp( p, q, nChar ) == 0;
601  }
602 
603  inline static bool IsUTF8Continuation( char p ) {
604  return ( p & 0x80 ) != 0;
605  }
606 
607  static const char* ReadBOM( const char* p, bool* hasBOM );
608  // p is the starting location,
609  // the UTF-8 value of the entity will be placed in value, and length filled in.
610  static const char* GetCharacterRef( const char* p, char* value, int* length );
611  static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
612 
613  // converts primitive types to strings
614  static void ToStr( int v, char* buffer, int bufferSize );
615  static void ToStr( unsigned v, char* buffer, int bufferSize );
616  static void ToStr( bool v, char* buffer, int bufferSize );
617  static void ToStr( float v, char* buffer, int bufferSize );
618  static void ToStr( double v, char* buffer, int bufferSize );
619  static void ToStr(int64_t v, char* buffer, int bufferSize);
620 
621  // converts strings to primitive types
622  static bool ToInt( const char* str, int* value );
623  static bool ToUnsigned( const char* str, unsigned* value );
624  static bool ToBool( const char* str, bool* value );
625  static bool ToFloat( const char* str, float* value );
626  static bool ToDouble( const char* str, double* value );
627  static bool ToInt64(const char* str, int64_t* value);
628 
629  // Changes what is serialized for a boolean value.
630  // Default to "true" and "false". Shouldn't be changed
631  // unless you have a special testing or compatibility need.
632  // Be careful: static, global, & not thread safe.
633  // Be sure to set static const memory as parameters.
634  static void SetBoolSerialization(const char* writeTrue, const char* writeFalse);
635 
636 private:
637  static const char* writeBoolTrue;
638  static const char* writeBoolFalse;
639 };
640 
641 
668 {
669  friend class XMLDocument;
670  friend class XMLElement;
671 public:
672 
674  const XMLDocument* GetDocument() const {
675  TIXMLASSERT( _document );
676  return _document;
677  }
680  TIXMLASSERT( _document );
681  return _document;
682  }
683 
685  virtual XMLElement* ToElement() {
686  return 0;
687  }
689  virtual XMLText* ToText() {
690  return 0;
691  }
693  virtual XMLComment* ToComment() {
694  return 0;
695  }
697  virtual XMLDocument* ToDocument() {
698  return 0;
699  }
702  return 0;
703  }
705  virtual XMLUnknown* ToUnknown() {
706  return 0;
707  }
708 
709  virtual const XMLElement* ToElement() const {
710  return 0;
711  }
712  virtual const XMLText* ToText() const {
713  return 0;
714  }
715  virtual const XMLComment* ToComment() const {
716  return 0;
717  }
718  virtual const XMLDocument* ToDocument() const {
719  return 0;
720  }
721  virtual const XMLDeclaration* ToDeclaration() const {
722  return 0;
723  }
724  virtual const XMLUnknown* ToUnknown() const {
725  return 0;
726  }
727 
737  const char* Value() const;
738 
742  void SetValue( const char* val, bool staticMem=false );
743 
745  int GetLineNum() const { return _parseLineNum; }
746 
748  const XMLNode* Parent() const {
749  return _parent;
750  }
751 
753  return _parent;
754  }
755 
757  bool NoChildren() const {
758  return !_firstChild;
759  }
760 
762  const XMLNode* FirstChild() const {
763  return _firstChild;
764  }
765 
767  return _firstChild;
768  }
769 
773  const XMLElement* FirstChildElement( const char* name = 0 ) const;
774 
775  XMLElement* FirstChildElement( const char* name = 0 ) {
776  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name ));
777  }
778 
780  const XMLNode* LastChild() const {
781  return _lastChild;
782  }
783 
785  return _lastChild;
786  }
787 
791  const XMLElement* LastChildElement( const char* name = 0 ) const;
792 
793  XMLElement* LastChildElement( const char* name = 0 ) {
794  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) );
795  }
796 
798  const XMLNode* PreviousSibling() const {
799  return _prev;
800  }
801 
803  return _prev;
804  }
805 
807  const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ;
808 
809  XMLElement* PreviousSiblingElement( const char* name = 0 ) {
810  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) );
811  }
812 
814  const XMLNode* NextSibling() const {
815  return _next;
816  }
817 
819  return _next;
820  }
821 
823  const XMLElement* NextSiblingElement( const char* name = 0 ) const;
824 
825  XMLElement* NextSiblingElement( const char* name = 0 ) {
826  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) );
827  }
828 
836  XMLNode* InsertEndChild( XMLNode* addThis );
837 
838  XMLNode* LinkEndChild( XMLNode* addThis ) {
839  return InsertEndChild( addThis );
840  }
848  XMLNode* InsertFirstChild( XMLNode* addThis );
857  XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
858 
862  void DeleteChildren();
863 
867  void DeleteChild( XMLNode* node );
868 
878  virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
879 
893  XMLNode* DeepClone( XMLDocument* target ) const;
894 
901  virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
902 
925  virtual bool Accept( XMLVisitor* visitor ) const = 0;
926 
932  void SetUserData(void* userData) { _userData = userData; }
933 
939  void* GetUserData() const { return _userData; }
940 
941 protected:
942  explicit XMLNode( XMLDocument* );
943  virtual ~XMLNode();
944 
945  virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
946 
949  mutable StrPair _value;
951 
954 
957 
958  void* _userData;
959 
960 private:
962  void Unlink( XMLNode* child );
963  static void DeleteNode( XMLNode* node );
964  void InsertChildPreamble( XMLNode* insertThis ) const;
965  const XMLElement* ToElementWithName( const char* name ) const;
966 
967  XMLNode( const XMLNode& ); // not supported
968  XMLNode& operator=( const XMLNode& ); // not supported
969 };
970 
971 
985 {
986  friend class XMLDocument;
987 public:
988  virtual bool Accept( XMLVisitor* visitor ) const;
989 
990  virtual XMLText* ToText() {
991  return this;
992  }
993  virtual const XMLText* ToText() const {
994  return this;
995  }
996 
998  void SetCData( bool isCData ) {
999  _isCData = isCData;
1000  }
1002  bool CData() const {
1003  return _isCData;
1004  }
1005 
1006  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1007  virtual bool ShallowEqual( const XMLNode* compare ) const;
1008 
1009 protected:
1010  explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
1011  virtual ~XMLText() {}
1012 
1013  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1014 
1015 private:
1016  bool _isCData;
1017 
1018  XMLText( const XMLText& ); // not supported
1019  XMLText& operator=( const XMLText& ); // not supported
1020 };
1021 
1022 
1025 {
1026  friend class XMLDocument;
1027 public:
1028  virtual XMLComment* ToComment() {
1029  return this;
1030  }
1031  virtual const XMLComment* ToComment() const {
1032  return this;
1033  }
1034 
1035  virtual bool Accept( XMLVisitor* visitor ) const;
1036 
1037  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1038  virtual bool ShallowEqual( const XMLNode* compare ) const;
1039 
1040 protected:
1041  explicit XMLComment( XMLDocument* doc );
1042  virtual ~XMLComment();
1043 
1044  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
1045 
1046 private:
1047  XMLComment( const XMLComment& ); // not supported
1048  XMLComment& operator=( const XMLComment& ); // not supported
1049 };
1050 
1051 
1064 {
1065  friend class XMLDocument;
1066 public:
1068  return this;
1069  }
1070  virtual const XMLDeclaration* ToDeclaration() const {
1071  return this;
1072  }
1073 
1074  virtual bool Accept( XMLVisitor* visitor ) const;
1075 
1076  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1077  virtual bool ShallowEqual( const XMLNode* compare ) const;
1078 
1079 protected:
1080  explicit XMLDeclaration( XMLDocument* doc );
1081  virtual ~XMLDeclaration();
1082 
1083  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1084 
1085 private:
1086  XMLDeclaration( const XMLDeclaration& ); // not supported
1087  XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
1088 };
1089 
1090 
1099 {
1100  friend class XMLDocument;
1101 public:
1102  virtual XMLUnknown* ToUnknown() {
1103  return this;
1104  }
1105  virtual const XMLUnknown* ToUnknown() const {
1106  return this;
1107  }
1108 
1109  virtual bool Accept( XMLVisitor* visitor ) const;
1110 
1111  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1112  virtual bool ShallowEqual( const XMLNode* compare ) const;
1113 
1114 protected:
1115  explicit XMLUnknown( XMLDocument* doc );
1116  virtual ~XMLUnknown();
1117 
1118  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1119 
1120 private:
1121  XMLUnknown( const XMLUnknown& ); // not supported
1122  XMLUnknown& operator=( const XMLUnknown& ); // not supported
1123 };
1124 
1125 
1126 
1134 {
1135  friend class XMLElement;
1136 public:
1138  const char* Name() const;
1139 
1141  const char* Value() const;
1142 
1144  int GetLineNum() const { return _parseLineNum; }
1145 
1147  const XMLAttribute* Next() const {
1148  return _next;
1149  }
1150 
1155  int IntValue() const {
1156  int i = 0;
1157  QueryIntValue(&i);
1158  return i;
1159  }
1160 
1161  int64_t Int64Value() const {
1162  int64_t i = 0;
1163  QueryInt64Value(&i);
1164  return i;
1165  }
1166 
1168  unsigned UnsignedValue() const {
1169  unsigned i=0;
1170  QueryUnsignedValue( &i );
1171  return i;
1172  }
1174  bool BoolValue() const {
1175  bool b=false;
1176  QueryBoolValue( &b );
1177  return b;
1178  }
1180  double DoubleValue() const {
1181  double d=0;
1182  QueryDoubleValue( &d );
1183  return d;
1184  }
1186  float FloatValue() const {
1187  float f=0;
1188  QueryFloatValue( &f );
1189  return f;
1190  }
1191 
1196  XMLError QueryIntValue( int* value ) const;
1198  XMLError QueryUnsignedValue( unsigned int* value ) const;
1200  XMLError QueryInt64Value(int64_t* value) const;
1202  XMLError QueryBoolValue( bool* value ) const;
1204  XMLError QueryDoubleValue( double* value ) const;
1206  XMLError QueryFloatValue( float* value ) const;
1207 
1209  void SetAttribute( const char* value );
1211  void SetAttribute( int value );
1213  void SetAttribute( unsigned value );
1215  void SetAttribute(int64_t value);
1217  void SetAttribute( bool value );
1219  void SetAttribute( double value );
1221  void SetAttribute( float value );
1222 
1223 private:
1224  enum { BUF_SIZE = 200 };
1225 
1226  XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
1227  virtual ~XMLAttribute() {}
1228 
1229  XMLAttribute( const XMLAttribute& ); // not supported
1230  void operator=( const XMLAttribute& ); // not supported
1231  void SetName( const char* name );
1232 
1233  char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr );
1234 
1235  mutable StrPair _name;
1236  mutable StrPair _value;
1240 };
1241 
1242 
1248 {
1249  friend class XMLDocument;
1250 public:
1252  const char* Name() const {
1253  return Value();
1254  }
1256  void SetName( const char* str, bool staticMem=false ) {
1257  SetValue( str, staticMem );
1258  }
1259 
1260  virtual XMLElement* ToElement() {
1261  return this;
1262  }
1263  virtual const XMLElement* ToElement() const {
1264  return this;
1265  }
1266  virtual bool Accept( XMLVisitor* visitor ) const;
1267 
1291  const char* Attribute( const char* name, const char* value=0 ) const;
1292 
1299  int IntAttribute(const char* name, int defaultValue = 0) const;
1301  unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const;
1303  int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const;
1305  bool BoolAttribute(const char* name, bool defaultValue = false) const;
1307  double DoubleAttribute(const char* name, double defaultValue = 0) const;
1309  float FloatAttribute(const char* name, float defaultValue = 0) const;
1310 
1324  XMLError QueryIntAttribute( const char* name, int* value ) const {
1325  const XMLAttribute* a = FindAttribute( name );
1326  if ( !a ) {
1327  return XML_NO_ATTRIBUTE;
1328  }
1329  return a->QueryIntValue( value );
1330  }
1331 
1333  XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
1334  const XMLAttribute* a = FindAttribute( name );
1335  if ( !a ) {
1336  return XML_NO_ATTRIBUTE;
1337  }
1338  return a->QueryUnsignedValue( value );
1339  }
1340 
1342  XMLError QueryInt64Attribute(const char* name, int64_t* value) const {
1343  const XMLAttribute* a = FindAttribute(name);
1344  if (!a) {
1345  return XML_NO_ATTRIBUTE;
1346  }
1347  return a->QueryInt64Value(value);
1348  }
1349 
1351  XMLError QueryBoolAttribute( const char* name, bool* value ) const {
1352  const XMLAttribute* a = FindAttribute( name );
1353  if ( !a ) {
1354  return XML_NO_ATTRIBUTE;
1355  }
1356  return a->QueryBoolValue( value );
1357  }
1359  XMLError QueryDoubleAttribute( const char* name, double* value ) const {
1360  const XMLAttribute* a = FindAttribute( name );
1361  if ( !a ) {
1362  return XML_NO_ATTRIBUTE;
1363  }
1364  return a->QueryDoubleValue( value );
1365  }
1367  XMLError QueryFloatAttribute( const char* name, float* value ) const {
1368  const XMLAttribute* a = FindAttribute( name );
1369  if ( !a ) {
1370  return XML_NO_ATTRIBUTE;
1371  }
1372  return a->QueryFloatValue( value );
1373  }
1374 
1376  XMLError QueryStringAttribute(const char* name, const char** value) const {
1377  const XMLAttribute* a = FindAttribute(name);
1378  if (!a) {
1379  return XML_NO_ATTRIBUTE;
1380  }
1381  *value = a->Value();
1382  return XML_SUCCESS;
1383  }
1384 
1385 
1386 
1404  XMLError QueryAttribute( const char* name, int* value ) const {
1405  return QueryIntAttribute( name, value );
1406  }
1407 
1408  XMLError QueryAttribute( const char* name, unsigned int* value ) const {
1409  return QueryUnsignedAttribute( name, value );
1410  }
1411 
1412  XMLError QueryAttribute(const char* name, int64_t* value) const {
1413  return QueryInt64Attribute(name, value);
1414  }
1415 
1416  XMLError QueryAttribute( const char* name, bool* value ) const {
1417  return QueryBoolAttribute( name, value );
1418  }
1419 
1420  XMLError QueryAttribute( const char* name, double* value ) const {
1421  return QueryDoubleAttribute( name, value );
1422  }
1423 
1424  XMLError QueryAttribute( const char* name, float* value ) const {
1425  return QueryFloatAttribute( name, value );
1426  }
1427 
1429  void SetAttribute( const char* name, const char* value ) {
1430  XMLAttribute* a = FindOrCreateAttribute( name );
1431  a->SetAttribute( value );
1432  }
1434  void SetAttribute( const char* name, int value ) {
1435  XMLAttribute* a = FindOrCreateAttribute( name );
1436  a->SetAttribute( value );
1437  }
1439  void SetAttribute( const char* name, unsigned value ) {
1440  XMLAttribute* a = FindOrCreateAttribute( name );
1441  a->SetAttribute( value );
1442  }
1443 
1445  void SetAttribute(const char* name, int64_t value) {
1446  XMLAttribute* a = FindOrCreateAttribute(name);
1447  a->SetAttribute(value);
1448  }
1449 
1451  void SetAttribute( const char* name, bool value ) {
1452  XMLAttribute* a = FindOrCreateAttribute( name );
1453  a->SetAttribute( value );
1454  }
1456  void SetAttribute( const char* name, double value ) {
1457  XMLAttribute* a = FindOrCreateAttribute( name );
1458  a->SetAttribute( value );
1459  }
1461  void SetAttribute( const char* name, float value ) {
1462  XMLAttribute* a = FindOrCreateAttribute( name );
1463  a->SetAttribute( value );
1464  }
1465 
1469  void DeleteAttribute( const char* name );
1470 
1472  const XMLAttribute* FirstAttribute() const {
1473  return _rootAttribute;
1474  }
1476  const XMLAttribute* FindAttribute( const char* name ) const;
1477 
1506  const char* GetText() const;
1507 
1542  void SetText( const char* inText );
1544  void SetText( int value );
1546  void SetText( unsigned value );
1548  void SetText(int64_t value);
1550  void SetText( bool value );
1552  void SetText( double value );
1554  void SetText( float value );
1555 
1582  XMLError QueryIntText( int* ival ) const;
1584  XMLError QueryUnsignedText( unsigned* uval ) const;
1586  XMLError QueryInt64Text(int64_t* uval) const;
1588  XMLError QueryBoolText( bool* bval ) const;
1590  XMLError QueryDoubleText( double* dval ) const;
1592  XMLError QueryFloatText( float* fval ) const;
1593 
1594  int IntText(int defaultValue = 0) const;
1595 
1597  unsigned UnsignedText(unsigned defaultValue = 0) const;
1599  int64_t Int64Text(int64_t defaultValue = 0) const;
1601  bool BoolText(bool defaultValue = false) const;
1603  double DoubleText(double defaultValue = 0) const;
1605  float FloatText(float defaultValue = 0) const;
1606 
1607  // internal:
1609  OPEN, // <foo>
1610  CLOSED, // <foo/>
1611  CLOSING // </foo>
1612  };
1614  return _closingType;
1615  }
1616  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1617  virtual bool ShallowEqual( const XMLNode* compare ) const;
1618 
1619 protected:
1620  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1621 
1622 private:
1623  XMLElement( XMLDocument* doc );
1624  virtual ~XMLElement();
1625  XMLElement( const XMLElement& ); // not supported
1626  void operator=( const XMLElement& ); // not supported
1627 
1628  XMLAttribute* FindOrCreateAttribute( const char* name );
1629  char* ParseAttributes( char* p, int* curLineNumPtr );
1630  static void DeleteAttribute( XMLAttribute* attribute );
1631  XMLAttribute* CreateAttribute();
1632 
1633  enum { BUF_SIZE = 200 };
1635  // The attribute list is ordered; there is no 'lastAttribute'
1636  // because the list needs to be scanned for dupes before adding
1637  // a new attribute.
1639 };
1640 
1641 
1645 };
1646 
1647 
1654 {
1655  friend class XMLElement;
1656  // Gives access to SetError and Push/PopDepth, but over-access for everything else.
1657  // Wishing C++ had "internal" scope.
1658  friend class XMLNode;
1659  friend class XMLText;
1660  friend class XMLComment;
1661  friend class XMLDeclaration;
1662  friend class XMLUnknown;
1663 public:
1665  XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
1666  ~XMLDocument();
1667 
1669  TIXMLASSERT( this == _document );
1670  return this;
1671  }
1672  virtual const XMLDocument* ToDocument() const {
1673  TIXMLASSERT( this == _document );
1674  return this;
1675  }
1676 
1687  XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) );
1688 
1694  XMLError LoadFile( const char* filename );
1695 
1707  XMLError LoadFile( FILE* );
1708 
1714  XMLError SaveFile( const char* filename, bool compact = false );
1715 
1723  XMLError SaveFile( FILE* fp, bool compact = false );
1724 
1725  bool ProcessEntities() const {
1726  return _processEntities;
1727  }
1729  return _whitespaceMode;
1730  }
1731 
1735  bool HasBOM() const {
1736  return _writeBOM;
1737  }
1740  void SetBOM( bool useBOM ) {
1741  _writeBOM = useBOM;
1742  }
1743 
1748  return FirstChildElement();
1749  }
1750  const XMLElement* RootElement() const {
1751  return FirstChildElement();
1752  }
1753 
1768  void Print( XMLPrinter* streamer=0 ) const;
1769  virtual bool Accept( XMLVisitor* visitor ) const;
1770 
1776  XMLElement* NewElement( const char* name );
1782  XMLComment* NewComment( const char* comment );
1788  XMLText* NewText( const char* text );
1800  XMLDeclaration* NewDeclaration( const char* text=0 );
1806  XMLUnknown* NewUnknown( const char* text );
1807 
1812  void DeleteNode( XMLNode* node );
1813 
1814  void ClearError() {
1815  SetError(XML_SUCCESS, 0, 0);
1816  }
1817 
1819  bool Error() const {
1820  return _errorID != XML_SUCCESS;
1821  }
1823  XMLError ErrorID() const {
1824  return _errorID;
1825  }
1826  const char* ErrorName() const;
1827  static const char* ErrorIDToName(XMLError errorID);
1828 
1832  const char* ErrorStr() const;
1833 
1835  void PrintError() const;
1836 
1838  int ErrorLineNum() const
1839  {
1840  return _errorLineNum;
1841  }
1842 
1844  void Clear();
1845 
1853  void DeepCopy(XMLDocument* target) const;
1854 
1855  // internal
1856  char* Identify( char* p, XMLNode** node );
1857 
1858  // internal
1859  void MarkInUse(XMLNode*);
1860 
1861  virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
1862  return 0;
1863  }
1864  virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
1865  return false;
1866  }
1867 
1868 private:
1869  XMLDocument( const XMLDocument& ); // not supported
1870  void operator=( const XMLDocument& ); // not supported
1871 
1881  // Memory tracking does add some overhead.
1882  // However, the code assumes that you don't
1883  // have a bunch of unlinked nodes around.
1884  // Therefore it takes less memory to track
1885  // in the document vs. a linked list in the XMLNode,
1886  // and the performance is the same.
1888 
1893 
1894  static const char* _errorNames[XML_ERROR_COUNT];
1895 
1896  void Parse();
1897 
1898  void SetError( XMLError error, int lineNum, const char* format, ... );
1899 
1900  // Something of an obvious security hole, once it was discovered.
1901  // Either an ill-formed XML or an excessively deep one can overflow
1902  // the stack. Track stack depth, and error out if needed.
1904  public:
1905  explicit DepthTracker(XMLDocument * document) {
1906  this->_document = document;
1907  document->PushDepth();
1908  }
1910  _document->PopDepth();
1911  }
1912  private:
1914  };
1915  void PushDepth();
1916  void PopDepth();
1917 
1918  template<class NodeType, int PoolElementSize>
1919  NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
1920 };
1921 
1922 template<class NodeType, int PoolElementSize>
1924 {
1925  TIXMLASSERT( sizeof( NodeType ) == PoolElementSize );
1926  TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() );
1927  NodeType* returnNode = new (pool.Alloc()) NodeType( this );
1928  TIXMLASSERT( returnNode );
1929  returnNode->_memPool = &pool;
1930 
1931  _unlinked.Push(returnNode);
1932  return returnNode;
1933 }
1934 
1991 {
1992 public:
1994  explicit XMLHandle( XMLNode* node ) : _node( node ) {
1995  }
1997  explicit XMLHandle( XMLNode& node ) : _node( &node ) {
1998  }
2000  XMLHandle( const XMLHandle& ref ) : _node( ref._node ) {
2001  }
2003  XMLHandle& operator=( const XMLHandle& ref ) {
2004  _node = ref._node;
2005  return *this;
2006  }
2007 
2010  return XMLHandle( _node ? _node->FirstChild() : 0 );
2011  }
2013  XMLHandle FirstChildElement( const char* name = 0 ) {
2014  return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
2015  }
2018  return XMLHandle( _node ? _node->LastChild() : 0 );
2019  }
2021  XMLHandle LastChildElement( const char* name = 0 ) {
2022  return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
2023  }
2026  return XMLHandle( _node ? _node->PreviousSibling() : 0 );
2027  }
2029  XMLHandle PreviousSiblingElement( const char* name = 0 ) {
2030  return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2031  }
2034  return XMLHandle( _node ? _node->NextSibling() : 0 );
2035  }
2037  XMLHandle NextSiblingElement( const char* name = 0 ) {
2038  return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2039  }
2040 
2043  return _node;
2044  }
2047  return ( _node ? _node->ToElement() : 0 );
2048  }
2051  return ( _node ? _node->ToText() : 0 );
2052  }
2055  return ( _node ? _node->ToUnknown() : 0 );
2056  }
2059  return ( _node ? _node->ToDeclaration() : 0 );
2060  }
2061 
2062 private:
2064 };
2065 
2066 
2072 {
2073 public:
2074  explicit XMLConstHandle( const XMLNode* node ) : _node( node ) {
2075  }
2076  explicit XMLConstHandle( const XMLNode& node ) : _node( &node ) {
2077  }
2078  XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) {
2079  }
2080 
2082  _node = ref._node;
2083  return *this;
2084  }
2085 
2086  const XMLConstHandle FirstChild() const {
2087  return XMLConstHandle( _node ? _node->FirstChild() : 0 );
2088  }
2089  const XMLConstHandle FirstChildElement( const char* name = 0 ) const {
2090  return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
2091  }
2092  const XMLConstHandle LastChild() const {
2093  return XMLConstHandle( _node ? _node->LastChild() : 0 );
2094  }
2095  const XMLConstHandle LastChildElement( const char* name = 0 ) const {
2096  return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
2097  }
2099  return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
2100  }
2101  const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const {
2102  return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2103  }
2104  const XMLConstHandle NextSibling() const {
2105  return XMLConstHandle( _node ? _node->NextSibling() : 0 );
2106  }
2107  const XMLConstHandle NextSiblingElement( const char* name = 0 ) const {
2108  return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2109  }
2110 
2111 
2112  const XMLNode* ToNode() const {
2113  return _node;
2114  }
2115  const XMLElement* ToElement() const {
2116  return ( _node ? _node->ToElement() : 0 );
2117  }
2118  const XMLText* ToText() const {
2119  return ( _node ? _node->ToText() : 0 );
2120  }
2121  const XMLUnknown* ToUnknown() const {
2122  return ( _node ? _node->ToUnknown() : 0 );
2123  }
2125  return ( _node ? _node->ToDeclaration() : 0 );
2126  }
2127 
2128 private:
2129  const XMLNode* _node;
2130 };
2131 
2132 
2176 {
2177 public:
2184  XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 );
2185  virtual ~XMLPrinter() {}
2186 
2188  void PushHeader( bool writeBOM, bool writeDeclaration );
2192  void OpenElement( const char* name, bool compactMode=false );
2194  void PushAttribute( const char* name, const char* value );
2195  void PushAttribute( const char* name, int value );
2196  void PushAttribute( const char* name, unsigned value );
2197  void PushAttribute(const char* name, int64_t value);
2198  void PushAttribute( const char* name, bool value );
2199  void PushAttribute( const char* name, double value );
2201  virtual void CloseElement( bool compactMode=false );
2202 
2204  void PushText( const char* text, bool cdata=false );
2206  void PushText( int value );
2208  void PushText( unsigned value );
2210  void PushText(int64_t value);
2212  void PushText( bool value );
2214  void PushText( float value );
2216  void PushText( double value );
2217 
2219  void PushComment( const char* comment );
2220 
2221  void PushDeclaration( const char* value );
2222  void PushUnknown( const char* value );
2223 
2224  virtual bool VisitEnter( const XMLDocument& /*doc*/ );
2225  virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
2226  return true;
2227  }
2228 
2229  virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
2230  virtual bool VisitExit( const XMLElement& element );
2231 
2232  virtual bool Visit( const XMLText& text );
2233  virtual bool Visit( const XMLComment& comment );
2234  virtual bool Visit( const XMLDeclaration& declaration );
2235  virtual bool Visit( const XMLUnknown& unknown );
2236 
2241  const char* CStr() const {
2242  return _buffer.Mem();
2243  }
2249  int CStrSize() const {
2250  return _buffer.Size();
2251  }
2256  void ClearBuffer() {
2257  _buffer.Clear();
2258  _buffer.Push(0);
2259  _firstElement = true;
2260  }
2261 
2262 protected:
2263  virtual bool CompactMode( const XMLElement& ) { return _compactMode; }
2264 
2268  virtual void PrintSpace( int depth );
2269  void Print( const char* format, ... );
2270  void Write( const char* data, size_t size );
2271  inline void Write( const char* data ) { Write( data, strlen( data ) ); }
2272  void Putc( char ch );
2273 
2274  void SealElementIfJustOpened();
2277 
2278 private:
2279  void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
2280 
2282  FILE* _fp;
2283  int _depth;
2287 
2288  enum {
2289  ENTITY_RANGE = 64,
2290  BUF_SIZE = 200
2291  };
2292  bool _entityFlag[ENTITY_RANGE];
2293  bool _restrictedEntityFlag[ENTITY_RANGE];
2294 
2296 
2297  // Prohibit cloning, intentionally not implemented
2298  XMLPrinter( const XMLPrinter& );
2299  XMLPrinter& operator=( const XMLPrinter& );
2300 };
2301 
2302 
2303 } // tinyxml2
2304 
2305 #if defined(_MSC_VER)
2306 # pragma warning(pop)
2307 #endif
2308 
2309 #endif // BT_TINYXML2_INCLUDED
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1333
const T & PeekTop() const
Definition: tinyxml2.h:266
static bool IsNameStartChar(unsigned char ch)
Definition: tinyxml2.h:575
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:693
XMLHandle LastChildElement(const char *name=0)
Get the last child element of this handle.
Definition: tinyxml2.h:2021
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:1260
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition: tinyxml2.h:814
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition: tinyxml2.h:1429
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1367
int64_t Int64Value() const
Definition: tinyxml2.h:1161
XMLNode * _firstChild
Definition: tinyxml2.h:952
Whitespace WhitespaceMode() const
Definition: tinyxml2.h:1728
MemPool * _memPool
Definition: tinyxml2.h:961
static const int TIXML2_PATCH_VERSION
Definition: tinyxml2.h:103
const XMLDeclaration * ToDeclaration() const
Definition: tinyxml2.h:2124
XMLError QueryIntAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1324
XMLError QueryAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1404
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1435
XMLAttribute * _next
Definition: tinyxml2.h:1238
static bool IsNameChar(unsigned char ch)
Definition: tinyxml2.h:586
DynArray< char, 20 > _buffer
Definition: tinyxml2.h:2295
void SetAttribute(const char *value)
Set the attribute to a string value.
Definition: tinyxml2.cpp:1444
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition: tinyxml2.h:780
int ErrorLineNum() const
Return the line where the error occurred, or zero if unknown.
Definition: tinyxml2.h:1838
virtual bool Visit(const XMLText &)
Visit a text node.
Definition: tinyxml2.h:508
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
Definition: tinyxml2.h:504
static raw_event_t * buffer
Definition: minitrace.cpp:54
XMLElement * NextSiblingElement(const char *name=0)
Definition: tinyxml2.h:825
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
Definition: tinyxml2.h:516
const XMLConstHandle NextSibling() const
Definition: tinyxml2.h:2104
XMLHandle NextSibling()
Get the next sibling of this handle.
Definition: tinyxml2.h:2033
XMLHandle FirstChild()
Get the first child of this handle.
Definition: tinyxml2.h:2009
XMLError QueryAttribute(const char *name, int64_t *value) const
Definition: tinyxml2.h:1412
XMLError QueryAttribute(const char *name, float *value) const
Definition: tinyxml2.h:1424
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition: tinyxml2.h:798
static FILE * file
Definition: minitrace.cpp:59
XMLDocument * _document
Definition: tinyxml2.h:947
XMLElement * FirstChildElement(const char *name=0)
Definition: tinyxml2.h:775
const char * Value() const
The value of the attribute.
Definition: tinyxml2.cpp:1351
XMLNode * FirstChild()
Definition: tinyxml2.h:766
const XMLAttribute * Next() const
The next attribute in the list.
Definition: tinyxml2.h:1147
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:2225
virtual const XMLDocument * ToDocument() const
Definition: tinyxml2.h:718
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:1067
const XMLNode * Parent() const
Get the parent of this node on the DOM.
Definition: tinyxml2.h:748
virtual bool ShallowEqual(const XMLNode *) const
Definition: tinyxml2.h:1864
virtual const XMLComment * ToComment() const
Definition: tinyxml2.h:715
const XMLConstHandle LastChildElement(const char *name=0) const
Definition: tinyxml2.h:2095
bool LoadFile(const char *name, bool binary, std::string *buf)
int Capacity() const
Definition: tinyxml2.h:276
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:679
virtual const XMLDocument * ToDocument() const
Definition: tinyxml2.h:1672
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:990
XMLConstHandle(const XMLConstHandle &ref)
Definition: tinyxml2.h:2078
void Trace(const char *name)
Definition: tinyxml2.h:412
Whitespace _whitespaceMode
Definition: tinyxml2.h:1875
XMLConstHandle(const XMLNode *node)
Definition: tinyxml2.h:2074
XMLNode * PreviousSibling()
Definition: tinyxml2.h:802
virtual bool CompactMode(const XMLElement &)
Definition: tinyxml2.h:2263
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
Definition: tinyxml2.h:1456
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:490
DynArray< Block *, 10 > _blockPtrs
Definition: tinyxml2.h:450
bool ProcessEntities() const
Definition: tinyxml2.h:1725
const XMLNode * ToNode() const
Definition: tinyxml2.h:2112
virtual XMLNode * ShallowClone(XMLDocument *) const
Definition: tinyxml2.h:1861
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1417
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:486
XMLElement * LastChildElement(const char *name=0)
Definition: tinyxml2.h:793
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:762
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:705
XMLError QueryAttribute(const char *name, bool *value) const
Definition: tinyxml2.h:1416
virtual const XMLComment * ToComment() const
Definition: tinyxml2.h:1031
void PopArr(int count)
Definition: tinyxml2.h:247
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1359
static const char * writeBoolFalse
Definition: tinyxml2.h:638
virtual const XMLText * ToText() const
Definition: tinyxml2.h:993
const XMLText * ToText() const
Definition: tinyxml2.h:2118
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
Definition: tinyxml2.h:593
int CurrentAllocs() const
Definition: tinyxml2.h:370
static const int TIXML2_MINOR_VERSION
Definition: tinyxml2.h:102
XMLNode * LinkEndChild(XMLNode *addThis)
Definition: tinyxml2.h:838
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
Definition: tinyxml2.h:1256
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:701
ElementClosingType _closingType
Definition: tinyxml2.h:1634
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
Definition: tinyxml2.h:2054
const XMLElement * RootElement() const
Definition: tinyxml2.h:1750
int GetLineNum() const
Gets the line number the node is in, if the document was parsed from a file.
Definition: tinyxml2.h:745
static char * SkipWhiteSpace(char *p, int *curLineNumPtr)
Definition: tinyxml2.h:565
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
Definition: tinyxml2.h:998
MemPoolT< sizeof(XMLText) > _textPool
Definition: tinyxml2.h:1891
XMLHandle(const XMLHandle &ref)
Copy constructor.
Definition: tinyxml2.h:2000
const XMLConstHandle FirstChildElement(const char *name=0) const
Definition: tinyxml2.h:2089
void SetAttribute(const char *name, int64_t value)
Sets the named attribute to value.
Definition: tinyxml2.h:1445
void Set(char *start, char *end, int flags)
Definition: tinyxml2.h:154
XMLHandle NextSiblingElement(const char *name=0)
Get the next sibling element of this handle.
Definition: tinyxml2.h:2037
virtual const XMLElement * ToElement() const
Definition: tinyxml2.h:1263
virtual const XMLDeclaration * ToDeclaration() const
Definition: tinyxml2.h:721
XMLText * ToText()
Safe cast to XMLText. This can return null.
Definition: tinyxml2.h:2050
XMLError QueryInt64Value(int64_t *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1408
XMLError QueryStringAttribute(const char *name, const char **value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1376
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:689
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1994
static const char * writeBoolTrue
Definition: tinyxml2.h:637
bool Empty() const
Definition: tinyxml2.h:165
const T * Mem() const
Definition: tinyxml2.h:288
XMLElement * RootElement()
Definition: tinyxml2.h:1747
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
Definition: tinyxml2.h:1434
void SetAttribute(const char *name, float value)
Sets the named attribute to value.
Definition: tinyxml2.h:1461
bool HasBOM() const
Definition: tinyxml2.h:1735
bool Error() const
Return true if there was an error parsing the document.
Definition: tinyxml2.h:1819
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
Definition: tinyxml2.h:495
T * PushArr(int count)
Definition: tinyxml2.h:232
XMLHandle PreviousSiblingElement(const char *name=0)
Get the previous sibling element of this handle.
Definition: tinyxml2.h:2029
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
Definition: tinyxml2.h:2025
static const int TIXML2_MAJOR_VERSION
Definition: tinyxml2.h:101
bool BoolValue() const
Query as a boolean. See IntValue()
Definition: tinyxml2.h:1174
const char * CStr() const
Definition: tinyxml2.h:2241
void SwapRemove(int i)
Definition: tinyxml2.h:281
static const char * SkipWhiteSpace(const char *p, int *curLineNumPtr)
Definition: tinyxml2.h:553
XMLError ErrorID() const
Return the errorID.
Definition: tinyxml2.h:1823
#define TINYXML2_LIB
Definition: tinyxml2.h:78
int Size() const
Definition: tinyxml2.h:271
virtual const XMLUnknown * ToUnknown() const
Definition: tinyxml2.h:1105
XMLNode * _lastChild
Definition: tinyxml2.h:953
T & operator[](int i)
Definition: tinyxml2.h:256
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
Definition: tinyxml2.h:1472
const T * data(const std::vector< T, Alloc > &v)
virtual bool Visit(const XMLComment &)
Visit a comment node.
Definition: tinyxml2.h:512
unsigned UnsignedValue() const
Query as an unsigned integer. See IntValue()
Definition: tinyxml2.h:1168
const XMLElement * ToElement() const
Definition: tinyxml2.h:2115
XMLError QueryInt64Attribute(const char *name, int64_t *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1342
const char * str
Definition: util.h:257
virtual ~XMLText()
Definition: tinyxml2.h:1011
DynArray< XMLNode *, 10 > _unlinked
Definition: tinyxml2.h:1887
const XMLConstHandle PreviousSibling() const
Definition: tinyxml2.h:2098
void EnsureCapacity(int cap)
Definition: tinyxml2.h:302
void SetUserData(void *userData)
Definition: tinyxml2.h:932
const XMLNode * _node
Definition: tinyxml2.h:2129
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
Definition: tinyxml2.h:2042
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:674
XMLAttribute * _rootAttribute
Definition: tinyxml2.h:1638
XMLNode * Parent()
Definition: tinyxml2.h:752
XMLNode * LastChild()
Definition: tinyxml2.h:784
bool Empty() const
Definition: tinyxml2.h:252
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition: tinyxml2.h:2046
ElementClosingType ClosingType() const
Definition: tinyxml2.h:1613
void * GetUserData() const
Definition: tinyxml2.h:939
static volatile int count
Definition: minitrace.cpp:55
const T & operator[](int i) const
Definition: tinyxml2.h:261
const XMLConstHandle LastChild() const
Definition: tinyxml2.h:2092
MemPoolT< sizeof(XMLAttribute) > _attributePool
Definition: tinyxml2.h:1890
float FloatValue() const
Query as a float. See IntValue()
Definition: tinyxml2.h:1186
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:685
#define TIXMLASSERT(x)
Definition: tinyxml2.h:94
XMLError QueryAttribute(const char *name, unsigned int *value) const
Definition: tinyxml2.h:1408
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:697
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
Definition: tinyxml2.h:1439
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1426
XMLHandle LastChild()
Get the last child of this handle.
Definition: tinyxml2.h:2017
XMLError QueryIntValue(int *value) const
Definition: tinyxml2.cpp:1390
XMLHandle FirstChildElement(const char *name=0)
Get the first child element of this handle.
Definition: tinyxml2.h:2013
bool CData() const
Returns true if this is a CDATA text element.
Definition: tinyxml2.h:1002
DepthTracker(XMLDocument *document)
Definition: tinyxml2.h:1905
double DoubleValue() const
Query as a double. See IntValue()
Definition: tinyxml2.h:1180
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:1102
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1351
NodeType * CreateUnlinkedNode(MemPoolT< PoolElementSize > &pool)
Definition: tinyxml2.h:1923
XMLConstHandle & operator=(const XMLConstHandle &ref)
Definition: tinyxml2.h:2081
int CStrSize() const
Definition: tinyxml2.h:2249
virtual const XMLText * ToText() const
Definition: tinyxml2.h:712
DynArray< const char *, 10 > _stack
Definition: tinyxml2.h:2276
virtual bool VisitExit(const XMLElement &)
Visit an element.
Definition: tinyxml2.h:499
XMLNode * NextSibling()
Definition: tinyxml2.h:818
XMLError QueryAttribute(const char *name, double *value) const
Definition: tinyxml2.h:1420
static bool IsWhiteSpace(char p)
Definition: tinyxml2.h:571
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1399
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
Definition: tinyxml2.h:2058
void Write(const char *data)
Definition: tinyxml2.h:2271
void SetInternedStr(const char *str)
Definition: tinyxml2.h:169
XMLConstHandle(const XMLNode &node)
Definition: tinyxml2.h:2076
virtual const XMLUnknown * ToUnknown() const
Definition: tinyxml2.h:724
int Untracked() const
Definition: tinyxml2.h:422
virtual const XMLDeclaration * ToDeclaration() const
Definition: tinyxml2.h:1070
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition: tinyxml2.h:1252
XMLNode * _parent
Definition: tinyxml2.h:948
virtual void * Alloc()
Definition: tinyxml2.h:374
virtual ~MemPool()
Definition: tinyxml2.h:333
const XMLUnknown * ToUnknown() const
Definition: tinyxml2.h:2121
virtual void Free(void *mem)
Definition: tinyxml2.h:400
virtual int ItemSize() const
Definition: tinyxml2.h:367
static bool IsUTF8Continuation(char p)
Definition: tinyxml2.h:603
const XMLConstHandle FirstChild() const
Definition: tinyxml2.h:2086
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
Definition: tinyxml2.h:2003
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml2.h:757
NodeType
Enumerates the possible types of nodes.
Definition: basic_types.h:22
int GetLineNum() const
Gets the line number the attribute is in, if the document was parsed from a file. ...
Definition: tinyxml2.h:1144
XMLText(XMLDocument *doc)
Definition: tinyxml2.h:1010
XMLElement * PreviousSiblingElement(const char *name=0)
Definition: tinyxml2.h:809
static const int TINYXML2_MAX_ELEMENT_DEPTH
Definition: tinyxml2.h:114
bool SaveFile(const char *name, const char *buf, size_t len, bool binary)
const XMLConstHandle PreviousSiblingElement(const char *name=0) const
Definition: tinyxml2.h:2101
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
Definition: tinyxml2.h:1451
XMLHandle(XMLNode &node)
Create a handle from a node.
Definition: tinyxml2.h:1997
MemPoolT< sizeof(XMLElement) > _elementPool
Definition: tinyxml2.h:1889
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:1668
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:1028
MemPoolT< sizeof(XMLComment) > _commentPool
Definition: tinyxml2.h:1892
const XMLConstHandle NextSiblingElement(const char *name=0) const
Definition: tinyxml2.h:2107
void SetBOM(bool useBOM)
Definition: tinyxml2.h:1740
virtual const XMLElement * ToElement() const
Definition: tinyxml2.h:709


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 18:04:05