Project

General

Profile

SO3Engine
tinyxml2.h
Go to the documentation of this file.
1/*
2Original code by Lee Thomason (www.grinninglizard.com)
3
4This software is provided 'as-is', without any express or implied
5warranty. In no event will the authors be held liable for any
6damages arising from the use of this software.
7
8Permission is granted to anyone to use this software for any
9purpose, including commercial applications, and to alter it and
10redistribute it freely, subject to the following restrictions:
11
121. The origin of this software must not be misrepresented; you must
13not claim that you wrote the original software. If you use this
14software in a product, an acknowledgment in the product documentation
15would be appreciated but is not required.
16
17
182. Altered source versions must be plainly marked as such, and
19must not be misrepresented as being the original software.
20
213. This notice may not be removed or altered from any source
22distribution.
23*/
24
25#ifndef TINYXML2_INCLUDED
26#define TINYXML2_INCLUDED
27
28#if defined(ANDROID_NDK) || defined(__BORLANDC__)
29# include <ctype.h>
30# include <limits.h>
31# include <stdio.h>
32# include <stdlib.h>
33# include <string.h>
34# include <stdarg.h>
35#else
36# include <cctype>
37# include <climits>
38# include <cstdio>
39# include <cstdlib>
40# include <cstring>
41# include <cstdarg>
42#endif
43
44/*
45 TODO: intern strings instead of allocation.
46*/
47/*
48 gcc:
49 g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
50
51 Formatting, Artistic Style:
52 AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
53*/
54
55#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
56# ifndef DEBUG
57# define DEBUG
58# endif
59#endif
60
61#ifdef _MSC_VER
62# pragma warning(push)
63# pragma warning(disable: 4251)
64#endif
65
66#ifdef _WIN32
67# ifdef TINYXML2_EXPORT
68# define TINYXML2_LIB __declspec(dllexport)
69# elif defined(TINYXML2_IMPORT)
70# define TINYXML2_LIB __declspec(dllimport)
71# else
72# define TINYXML2_LIB
73# endif
74#else
75# define TINYXML2_LIB
76#endif
77
78
79#if defined(DEBUG)
80# if defined(_MSC_VER)
81# define TIXMLASSERT( x ) if ( !(x)) { __debugbreak(); } //if ( !(x)) WinDebugBreak()
82# elif defined (ANDROID_NDK)
83# include <android/log.h>
84# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
85# else
86# include <assert.h>
87# define TIXMLASSERT assert
88# endif
89# else
90# define TIXMLASSERT( x ) {}
91#endif
92
93
94#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
95// Microsoft visual studio, version 2005 and higher.
96/*int _snprintf_s(
97 char *buffer,
98 size_t sizeOfBuffer,
99 size_t count,
100 const char *format [,
101 argument] ...
102);*/
103inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
104{
105 va_list va;
106 va_start( va, format );
107 int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
108 va_end( va );
109 return result;
110}
111#define TIXML_SSCANF sscanf_s
112#else
113// GCC version 3 and higher
114//#warning( "Using sn* functions." )
115#define TIXML_SNPRINTF snprintf
116#define TIXML_SSCANF sscanf
117#endif
118
119/* Versioning, past 1.0.14:
120 http://semver.org/
121*/
122static const int TIXML2_MAJOR_VERSION = 2;
123static const int TIXML2_MINOR_VERSION = 1;
124static const int TIXML2_PATCH_VERSION = 0;
125
126namespace tinyxml2
127{
128class XMLDocument;
129class XMLElement;
130class XMLAttribute;
131class XMLComment;
132class XMLText;
133class XMLDeclaration;
134class XMLUnknown;
135class XMLPrinter;
136
137/*
138 A class that wraps strings. Normally stores the start and end
139 pointers into the XML file itself, and will apply normalization
140 and entity translation if actually read. Can also store (and memory
141 manage) a traditional char[]
142*/
144{
145public:
146 enum {
150
157 };
158
159 StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
161
162 void Set( char* start, char* end, int flags ) {
163 Reset();
164 _start = start;
165 _end = end;
166 _flags = flags | NEEDS_FLUSH;
167 }
168
169 const char* GetStr();
170
171 bool Empty() const {
172 return _start == _end;
173 }
174
175 void SetInternedStr( const char* str ) {
176 Reset();
177 _start = const_cast<char*>(str);
178 }
179
180 void SetStr( const char* str, int flags=0 );
181
182 char* ParseText( char* in, const char* endTag, int strFlags );
183 char* ParseName( char* in );
184
185private:
186 void Reset();
187 void CollapseWhitespace();
188
189 enum {
190 NEEDS_FLUSH = 0x100,
191 NEEDS_DELETE = 0x200
192 };
193
194 // After parsing, if *_end != 0, it can be set to zero.
195 int _flags;
196 char* _start;
197 char* _end;
198};
199
200
201/*
202 A dynamic array of Plain Old Data. Doesn't support constructors, etc.
203 Has a small initial memory pool, so that low or no usage will not
204 cause a call to new/delete
205*/
206template <class T, int INIT>
208{
209public:
211 _mem = _pool;
212 _allocated = INIT;
213 _size = 0;
214 }
215
217 if ( _mem != _pool ) {
218 delete [] _mem;
219 }
220 }
221
222 void Clear() {
223 _size = 0;
224 }
225
226 void Push( T t ) {
227 EnsureCapacity( _size+1 );
228 _mem[_size++] = t;
229 }
230
231 T* PushArr( int count ) {
232 EnsureCapacity( _size+count );
233 T* ret = &_mem[_size];
234 _size += count;
235 return ret;
236 }
237
238 T Pop() {
239 return _mem[--_size];
240 }
241
242 void PopArr( int count ) {
243 TIXMLASSERT( _size >= count );
244 _size -= count;
245 }
246
247 bool Empty() const {
248 return _size == 0;
249 }
250
251 T& operator[](int i) {
252 TIXMLASSERT( i>= 0 && i < _size );
253 return _mem[i];
254 }
255
256 const T& operator[](int i) const {
257 TIXMLASSERT( i>= 0 && i < _size );
258 return _mem[i];
259 }
260
261 const T& PeekTop() const {
262 TIXMLASSERT( _size > 0 );
263 return _mem[ _size - 1];
264 }
265
266 int Size() const {
267 return _size;
268 }
269
270 int Capacity() const {
271 return _allocated;
272 }
273
274 const T* Mem() const {
275 return _mem;
276 }
277
278 T* Mem() {
279 return _mem;
280 }
281
282private:
283 void EnsureCapacity( int cap ) {
284 if ( cap > _allocated ) {
285 int newAllocated = cap * 2;
286 T* newMem = new T[newAllocated];
287 memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
288 if ( _mem != _pool ) {
289 delete [] _mem;
290 }
291 _mem = newMem;
292 _allocated = newAllocated;
293 }
294 }
295
296 T* _mem;
297 T _pool[INIT];
298 int _allocated; // objects allocated
299 int _size; // number objects in use
300};
301
302
303/*
304 Parent virtual class of a pool for fast allocation
305 and deallocation of objects.
306*/
308{
309public:
311 virtual ~MemPool() {}
312
313 virtual int ItemSize() const = 0;
314 virtual void* Alloc() = 0;
315 virtual void Free( void* ) = 0;
316 virtual void SetTracked() = 0;
317};
318
319
320/*
321 Template child class to create pools of the correct type.
322*/
323template< int SIZE >
324class MemPoolT : public MemPool
325{
326public:
327 MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
329 // Delete the blocks.
330 for( int i=0; i<_blockPtrs.Size(); ++i ) {
331 delete _blockPtrs[i];
332 }
333 }
334
335 virtual int ItemSize() const {
336 return SIZE;
337 }
338 int CurrentAllocs() const {
339 return _currentAllocs;
340 }
341
342 virtual void* Alloc() {
343 if ( !_root ) {
344 // Need a new block.
345 Block* block = new Block();
346 _blockPtrs.Push( block );
347
348 for( int i=0; i<COUNT-1; ++i ) {
349 block->chunk[i].next = &block->chunk[i+1];
350 }
351 block->chunk[COUNT-1].next = 0;
352 _root = block->chunk;
353 }
354 void* result = _root;
355 _root = _root->next;
356
357 ++_currentAllocs;
358 if ( _currentAllocs > _maxAllocs ) {
359 _maxAllocs = _currentAllocs;
360 }
361 _nAllocs++;
362 _nUntracked++;
363 return result;
364 }
365 virtual void Free( void* mem ) {
366 if ( !mem ) {
367 return;
368 }
369 --_currentAllocs;
370 Chunk* chunk = (Chunk*)mem;
371#ifdef DEBUG
372 memset( chunk, 0xfe, sizeof(Chunk) );
373#endif
374 chunk->next = _root;
375 _root = chunk;
376 }
377 void Trace( const char* name ) {
378 printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
379 name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() );
380 }
381
382 void SetTracked() {
383 _nUntracked--;
384 }
385
386 int Untracked() const {
387 return _nUntracked;
388 }
389
390 // This number is perf sensitive. 4k seems like a good tradeoff on my machine.
391 // The test file is large, 170k.
392 // Release: VS2010 gcc(no opt)
393 // 1k: 4000
394 // 2k: 4000
395 // 4k: 3900 21000
396 // 16k: 5200
397 // 32k: 4300
398 // 64k: 4000 21000
399 enum { COUNT = (4*1024)/SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private
400
401private:
402 union Chunk {
403 Chunk* next;
404 char mem[SIZE];
405 };
406 struct Block {
407 Chunk chunk[COUNT];
408 };
409 DynArray< Block*, 10 > _blockPtrs;
410 Chunk* _root;
411
412 int _currentAllocs;
413 int _nAllocs;
414 int _maxAllocs;
415 int _nUntracked;
416};
417
418
419
439class TINYXML2_LIB XMLVisitor
440{
441public:
442 virtual ~XMLVisitor() {}
443
445 virtual bool VisitEnter( const XMLDocument& /*doc*/ ) {
446 return true;
447 }
449 virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
450 return true;
451 }
452
454 virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) {
455 return true;
456 }
458 virtual bool VisitExit( const XMLElement& /*element*/ ) {
459 return true;
460 }
461
463 virtual bool Visit( const XMLDeclaration& /*declaration*/ ) {
464 return true;
465 }
467 virtual bool Visit( const XMLText& /*text*/ ) {
468 return true;
469 }
471 virtual bool Visit( const XMLComment& /*comment*/ ) {
472 return true;
473 }
475 virtual bool Visit( const XMLUnknown& /*unknown*/ ) {
476 return true;
477 }
478};
479
480
481/*
482 Utility functionality.
483*/
485{
486public:
487 // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
488 // correct, but simple, and usually works.
489 static const char* SkipWhiteSpace( const char* p ) {
490 while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<const unsigned char*>(p) ) ) {
491 ++p;
492 }
493 return p;
494 }
495 static char* SkipWhiteSpace( char* p ) {
496 while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<unsigned char*>(p) ) ) {
497 ++p;
498 }
499 return p;
500 }
501 static bool IsWhiteSpace( char p ) {
502 return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
503 }
504
505 inline static bool IsNameStartChar( unsigned char ch ) {
506 return ( ( ch < 128 ) ? isalpha( ch ) : 1 )
507 || ch == ':'
508 || ch == '_';
509 }
510
511 inline static bool IsNameChar( unsigned char ch ) {
512 return IsNameStartChar( ch )
513 || isdigit( ch )
514 || ch == '.'
515 || ch == '-';
516 }
517
518 inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
519 int n = 0;
520 if ( p == q ) {
521 return true;
522 }
523 while( *p && *q && *p == *q && n<nChar ) {
524 ++p;
525 ++q;
526 ++n;
527 }
528 if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
529 return true;
530 }
531 return false;
532 }
533
534 inline static int IsUTF8Continuation( const char p ) {
535 return p & 0x80;
536 }
537
538 static const char* ReadBOM( const char* p, bool* hasBOM );
539 // p is the starting location,
540 // the UTF-8 value of the entity will be placed in value, and length filled in.
541 static const char* GetCharacterRef( const char* p, char* value, int* length );
542 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
543
544 // converts primitive types to strings
545 static void ToStr( int v, char* buffer, int bufferSize );
546 static void ToStr( unsigned v, char* buffer, int bufferSize );
547 static void ToStr( bool v, char* buffer, int bufferSize );
548 static void ToStr( float v, char* buffer, int bufferSize );
549 static void ToStr( double v, char* buffer, int bufferSize );
550
551 // converts strings to primitive types
552 static bool ToInt( const char* str, int* value );
553 static bool ToUnsigned( const char* str, unsigned* value );
554 static bool ToBool( const char* str, bool* value );
555 static bool ToFloat( const char* str, float* value );
556 static bool ToDouble( const char* str, double* value );
557};
558
559
585class TINYXML2_LIB XMLNode
586{
587 friend class XMLDocument;
588 friend class XMLElement;
589public:
590
592 const XMLDocument* GetDocument() const {
593 return _document;
594 }
597 return _document;
598 }
599
602 return 0;
603 }
605 virtual XMLText* ToText() {
606 return 0;
607 }
610 return 0;
611 }
614 return 0;
615 }
618 return 0;
619 }
622 return 0;
623 }
624
625 virtual const XMLElement* ToElement() const {
626 return 0;
627 }
628 virtual const XMLText* ToText() const {
629 return 0;
630 }
631 virtual const XMLComment* ToComment() const {
632 return 0;
633 }
634 virtual const XMLDocument* ToDocument() const {
635 return 0;
636 }
637 virtual const XMLDeclaration* ToDeclaration() const {
638 return 0;
639 }
640 virtual const XMLUnknown* ToUnknown() const {
641 return 0;
642 }
643
653 const char* Value() const;
654
658 void SetValue( const char* val, bool staticMem=false );
659
661 const XMLNode* Parent() const {
662 return _parent;
663 }
664
666 return _parent;
667 }
668
670 bool NoChildren() const {
671 return !_firstChild;
672 }
673
675 const XMLNode* FirstChild() const {
676 return _firstChild;
677 }
678
680 return _firstChild;
681 }
682
686 const XMLElement* FirstChildElement( const char* value=0 ) const;
687
688 XMLElement* FirstChildElement( const char* value=0 ) {
689 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( value ));
690 }
691
693 const XMLNode* LastChild() const {
694 return _lastChild;
695 }
696
698 return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->LastChild() );
699 }
700
704 const XMLElement* LastChildElement( const char* value=0 ) const;
705
706 XMLElement* LastChildElement( const char* value=0 ) {
707 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(value) );
708 }
709
711 const XMLNode* PreviousSibling() const {
712 return _prev;
713 }
714
716 return _prev;
717 }
718
720 const XMLElement* PreviousSiblingElement( const char* value=0 ) const ;
721
722 XMLElement* PreviousSiblingElement( const char* value=0 ) {
723 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( value ) );
724 }
725
727 const XMLNode* NextSibling() const {
728 return _next;
729 }
730
732 return _next;
733 }
734
736 const XMLElement* NextSiblingElement( const char* value=0 ) const;
737
738 XMLElement* NextSiblingElement( const char* value=0 ) {
739 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( value ) );
740 }
741
750
752 return InsertEndChild( addThis );
753 }
770 XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
771
776
780 void DeleteChild( XMLNode* node );
781
791 virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
792
799 virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
800
823 virtual bool Accept( XMLVisitor* visitor ) const = 0;
824
825 // internal
826 virtual char* ParseDeep( char*, StrPair* );
827
828protected:
830 virtual ~XMLNode();
831 XMLNode( const XMLNode& ); // not supported
832 XMLNode& operator=( const XMLNode& ); // not supported
833
837
840
843
844private:
845 MemPool* _memPool;
846 void Unlink( XMLNode* child );
847};
848
849
862class TINYXML2_LIB XMLText : public XMLNode
863{
864 friend class XMLBase;
865 friend class XMLDocument;
866public:
867 virtual bool Accept( XMLVisitor* visitor ) const;
868
869 virtual XMLText* ToText() {
870 return this;
871 }
872 virtual const XMLText* ToText() const {
873 return this;
874 }
875
877 void SetCData( bool isCData ) {
878 _isCData = isCData;
879 }
881 bool CData() const {
882 return _isCData;
883 }
884
885 char* ParseDeep( char*, StrPair* endTag );
886 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
887 virtual bool ShallowEqual( const XMLNode* compare ) const;
888
889protected:
890 XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
891 virtual ~XMLText() {}
892 XMLText( const XMLText& ); // not supported
893 XMLText& operator=( const XMLText& ); // not supported
894
895private:
896 bool _isCData;
897};
898
899
901class TINYXML2_LIB XMLComment : public XMLNode
902{
903 friend class XMLDocument;
904public:
906 return this;
907 }
908 virtual const XMLComment* ToComment() const {
909 return this;
910 }
911
912 virtual bool Accept( XMLVisitor* visitor ) const;
913
914 char* ParseDeep( char*, StrPair* endTag );
915 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
916 virtual bool ShallowEqual( const XMLNode* compare ) const;
917
918protected:
920 virtual ~XMLComment();
921 XMLComment( const XMLComment& ); // not supported
922 XMLComment& operator=( const XMLComment& ); // not supported
923
924private:
925};
926
927
939class TINYXML2_LIB XMLDeclaration : public XMLNode
940{
941 friend class XMLDocument;
942public:
944 return this;
945 }
946 virtual const XMLDeclaration* ToDeclaration() const {
947 return this;
948 }
949
950 virtual bool Accept( XMLVisitor* visitor ) const;
951
952 char* ParseDeep( char*, StrPair* endTag );
953 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
954 virtual bool ShallowEqual( const XMLNode* compare ) const;
955
956protected:
959 XMLDeclaration( const XMLDeclaration& ); // not supported
960 XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
961};
962
963
971class TINYXML2_LIB XMLUnknown : public XMLNode
972{
973 friend class XMLDocument;
974public:
976 return this;
977 }
978 virtual const XMLUnknown* ToUnknown() const {
979 return this;
980 }
981
982 virtual bool Accept( XMLVisitor* visitor ) const;
983
984 char* ParseDeep( char*, StrPair* endTag );
985 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
986 virtual bool ShallowEqual( const XMLNode* compare ) const;
987
988protected:
990 virtual ~XMLUnknown();
991 XMLUnknown( const XMLUnknown& ); // not supported
992 XMLUnknown& operator=( const XMLUnknown& ); // not supported
993};
994
995
1022
1023
1030class TINYXML2_LIB XMLAttribute
1031{
1032 friend class XMLElement;
1033public:
1035 const char* Name() const;
1036
1038 const char* Value() const;
1039
1041 const XMLAttribute* Next() const {
1042 return _next;
1043 }
1044
1049 int IntValue() const {
1050 int i=0;
1051 QueryIntValue( &i );
1052 return i;
1053 }
1055 unsigned UnsignedValue() const {
1056 unsigned i=0;
1057 QueryUnsignedValue( &i );
1058 return i;
1059 }
1061 bool BoolValue() const {
1062 bool b=false;
1063 QueryBoolValue( &b );
1064 return b;
1065 }
1067 double DoubleValue() const {
1068 double d=0;
1069 QueryDoubleValue( &d );
1070 return d;
1071 }
1073 float FloatValue() const {
1074 float f=0;
1075 QueryFloatValue( &f );
1076 return f;
1077 }
1078
1083 XMLError QueryIntValue( int* value ) const;
1085 XMLError QueryUnsignedValue( unsigned int* value ) const;
1087 XMLError QueryBoolValue( bool* value ) const;
1089 XMLError QueryDoubleValue( double* value ) const;
1091 XMLError QueryFloatValue( float* value ) const;
1092
1094 void SetAttribute( const char* value );
1096 void SetAttribute( int value );
1098 void SetAttribute( unsigned value );
1100 void SetAttribute( bool value );
1102 void SetAttribute( double value );
1104 void SetAttribute( float value );
1105
1106private:
1107 enum { BUF_SIZE = 200 };
1108
1109 XMLAttribute() : _next( 0 ), _memPool( 0 ) {}
1110 virtual ~XMLAttribute() {}
1111
1112 XMLAttribute( const XMLAttribute& ); // not supported
1113 void operator=( const XMLAttribute& ); // not supported
1114 void SetName( const char* name );
1115
1116 char* ParseDeep( char* p, bool processEntities );
1117
1118 mutable StrPair _name;
1119 mutable StrPair _value;
1120 XMLAttribute* _next;
1121 MemPool* _memPool;
1122};
1123
1124
1129class TINYXML2_LIB XMLElement : public XMLNode
1130{
1131 friend class XMLBase;
1132 friend class XMLDocument;
1133public:
1135 const char* Name() const {
1136 return Value();
1137 }
1139 void SetName( const char* str, bool staticMem=false ) {
1140 SetValue( str, staticMem );
1141 }
1142
1144 return this;
1145 }
1146 virtual const XMLElement* ToElement() const {
1147 return this;
1148 }
1149 virtual bool Accept( XMLVisitor* visitor ) const;
1150
1174 const char* Attribute( const char* name, const char* value=0 ) const;
1175
1181 int IntAttribute( const char* name ) const {
1182 int i=0;
1183 QueryIntAttribute( name, &i );
1184 return i;
1185 }
1187 unsigned UnsignedAttribute( const char* name ) const {
1188 unsigned i=0;
1189 QueryUnsignedAttribute( name, &i );
1190 return i;
1191 }
1193 bool BoolAttribute( const char* name ) const {
1194 bool b=false;
1195 QueryBoolAttribute( name, &b );
1196 return b;
1197 }
1199 double DoubleAttribute( const char* name ) const {
1200 double d=0;
1201 QueryDoubleAttribute( name, &d );
1202 return d;
1203 }
1205 float FloatAttribute( const char* name ) const {
1206 float f=0;
1207 QueryFloatAttribute( name, &f );
1208 return f;
1209 }
1210
1224 XMLError QueryIntAttribute( const char* name, int* value ) const {
1225 const XMLAttribute* a = FindAttribute( name );
1226 if ( !a ) {
1227 return XML_NO_ATTRIBUTE;
1228 }
1229 return a->QueryIntValue( value );
1230 }
1232 XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
1233 const XMLAttribute* a = FindAttribute( name );
1234 if ( !a ) {
1235 return XML_NO_ATTRIBUTE;
1236 }
1237 return a->QueryUnsignedValue( value );
1238 }
1240 XMLError QueryBoolAttribute( const char* name, bool* value ) const {
1241 const XMLAttribute* a = FindAttribute( name );
1242 if ( !a ) {
1243 return XML_NO_ATTRIBUTE;
1244 }
1245 return a->QueryBoolValue( value );
1246 }
1248 XMLError QueryDoubleAttribute( const char* name, double* value ) const {
1249 const XMLAttribute* a = FindAttribute( name );
1250 if ( !a ) {
1251 return XML_NO_ATTRIBUTE;
1252 }
1253 return a->QueryDoubleValue( value );
1254 }
1256 XMLError QueryFloatAttribute( const char* name, float* value ) const {
1257 const XMLAttribute* a = FindAttribute( name );
1258 if ( !a ) {
1259 return XML_NO_ATTRIBUTE;
1260 }
1261 return a->QueryFloatValue( value );
1262 }
1263
1264
1282 int QueryAttribute( const char* name, int* value ) const {
1283 return QueryIntAttribute( name, value );
1284 }
1285
1286 int QueryAttribute( const char* name, unsigned int* value ) const {
1287 return QueryUnsignedAttribute( name, value );
1288 }
1289
1290 int QueryAttribute( const char* name, bool* value ) const {
1291 return QueryBoolAttribute( name, value );
1292 }
1293
1294 int QueryAttribute( const char* name, double* value ) const {
1295 return QueryDoubleAttribute( name, value );
1296 }
1297
1298 int QueryAttribute( const char* name, float* value ) const {
1299 return QueryFloatAttribute( name, value );
1300 }
1301
1303 void SetAttribute( const char* name, const char* value ) {
1304 XMLAttribute* a = FindOrCreateAttribute( name );
1305 a->SetAttribute( value );
1306 }
1308 void SetAttribute( const char* name, int value ) {
1309 XMLAttribute* a = FindOrCreateAttribute( name );
1310 a->SetAttribute( value );
1311 }
1313 void SetAttribute( const char* name, unsigned value ) {
1314 XMLAttribute* a = FindOrCreateAttribute( name );
1315 a->SetAttribute( value );
1316 }
1318 void SetAttribute( const char* name, bool value ) {
1319 XMLAttribute* a = FindOrCreateAttribute( name );
1320 a->SetAttribute( value );
1321 }
1323 void SetAttribute( const char* name, double value ) {
1324 XMLAttribute* a = FindOrCreateAttribute( name );
1325 a->SetAttribute( value );
1326 }
1328 void SetAttribute( const char* name, float value ) {
1329 XMLAttribute* a = FindOrCreateAttribute( name );
1330 a->SetAttribute( value );
1331 }
1332
1336 void DeleteAttribute( const char* name );
1337
1340 return _rootAttribute;
1341 }
1343 const XMLAttribute* FindAttribute( const char* name ) const;
1344
1373 const char* GetText() const;
1374
1409 void SetText( const char* inText );
1411 void SetText( int value );
1413 void SetText( unsigned value );
1415 void SetText( bool value );
1417 void SetText( double value );
1419 void SetText( float value );
1420
1447 XMLError QueryIntText( int* ival ) const;
1449 XMLError QueryUnsignedText( unsigned* uval ) const;
1451 XMLError QueryBoolText( bool* bval ) const;
1453 XMLError QueryDoubleText( double* dval ) const;
1455 XMLError QueryFloatText( float* fval ) const;
1456
1457 // internal:
1458 enum {
1459 OPEN, // <foo>
1460 CLOSED, // <foo/>
1461 CLOSING // </foo>
1463 int ClosingType() const {
1464 return _closingType;
1465 }
1466 char* ParseDeep( char* p, StrPair* endTag );
1467 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1468 virtual bool ShallowEqual( const XMLNode* compare ) const;
1469
1470private:
1471 XMLElement( XMLDocument* doc );
1472 virtual ~XMLElement();
1473 XMLElement( const XMLElement& ); // not supported
1474 void operator=( const XMLElement& ); // not supported
1475
1476 XMLAttribute* FindAttribute( const char* name );
1477 XMLAttribute* FindOrCreateAttribute( const char* name );
1478 //void LinkAttribute( XMLAttribute* attrib );
1479 char* ParseAttributes( char* p );
1480
1481 enum { BUF_SIZE = 200 };
1482 int _closingType;
1483 // The attribute list is ordered; there is no 'lastAttribute'
1484 // because the list needs to be scanned for dupes before adding
1485 // a new attribute.
1486 XMLAttribute* _rootAttribute;
1487};
1488
1489
1494
1495
1501class TINYXML2_LIB XMLDocument : public XMLNode
1502{
1503 friend class XMLElement;
1504public:
1506 XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE );
1508
1510 return this;
1511 }
1512 virtual const XMLDocument* ToDocument() const {
1513 return this;
1514 }
1515
1526 XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) );
1527
1533 XMLError LoadFile( const char* filename );
1534
1543
1549 XMLError SaveFile( const char* filename, bool compact = false );
1550
1558 XMLError SaveFile( FILE* fp, bool compact = false );
1559
1560 bool ProcessEntities() const {
1561 return _processEntities;
1562 }
1564 return _whitespace;
1565 }
1566
1570 bool HasBOM() const {
1571 return _writeBOM;
1572 }
1575 void SetBOM( bool useBOM ) {
1576 _writeBOM = useBOM;
1577 }
1578
1583 return FirstChildElement();
1584 }
1585 const XMLElement* RootElement() const {
1586 return FirstChildElement();
1587 }
1588
1603 void Print( XMLPrinter* streamer=0 ) const;
1604 virtual bool Accept( XMLVisitor* visitor ) const;
1605
1611 XMLElement* NewElement( const char* name );
1617 XMLComment* NewComment( const char* comment );
1623 XMLText* NewText( const char* text );
1635 XMLDeclaration* NewDeclaration( const char* text=0 );
1641 XMLUnknown* NewUnknown( const char* text );
1642
1647 void DeleteNode( XMLNode* node ) {
1648 node->_parent->DeleteChild( node );
1649 }
1650
1651 void SetError( XMLError error, const char* str1, const char* str2 );
1652
1654 bool Error() const {
1655 return _errorID != XML_NO_ERROR;
1656 }
1659 return _errorID;
1660 }
1662 const char* GetErrorStr1() const {
1663 return _errorStr1;
1664 }
1666 const char* GetErrorStr2() const {
1667 return _errorStr2;
1668 }
1670 void PrintError() const;
1671
1673 void Clear();
1674
1675 // internal
1676 char* Identify( char* p, XMLNode** node );
1677
1678 virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
1679 return 0;
1680 }
1681 virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
1682 return false;
1683 }
1684
1685private:
1686 XMLDocument( const XMLDocument& ); // not supported
1687 void operator=( const XMLDocument& ); // not supported
1688
1689 bool _writeBOM;
1690 bool _processEntities;
1691 XMLError _errorID;
1692 Whitespace _whitespace;
1693 const char* _errorStr1;
1694 const char* _errorStr2;
1695 char* _charBuffer;
1696
1697 MemPoolT< sizeof(XMLElement) > _elementPool;
1698 MemPoolT< sizeof(XMLAttribute) > _attributePool;
1699 MemPoolT< sizeof(XMLText) > _textPool;
1700 MemPoolT< sizeof(XMLComment) > _commentPool;
1701};
1702
1703
1759class TINYXML2_LIB XMLHandle
1760{
1761public:
1764 _node = node;
1765 }
1768 _node = &node;
1769 }
1771 XMLHandle( const XMLHandle& ref ) {
1772 _node = ref._node;
1773 }
1776 _node = ref._node;
1777 return *this;
1778 }
1779
1782 return XMLHandle( _node ? _node->FirstChild() : 0 );
1783 }
1785 XMLHandle FirstChildElement( const char* value=0 ) {
1786 return XMLHandle( _node ? _node->FirstChildElement( value ) : 0 );
1787 }
1790 return XMLHandle( _node ? _node->LastChild() : 0 );
1791 }
1793 XMLHandle LastChildElement( const char* _value=0 ) {
1794 return XMLHandle( _node ? _node->LastChildElement( _value ) : 0 );
1795 }
1798 return XMLHandle( _node ? _node->PreviousSibling() : 0 );
1799 }
1801 XMLHandle PreviousSiblingElement( const char* _value=0 ) {
1802 return XMLHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
1803 }
1806 return XMLHandle( _node ? _node->NextSibling() : 0 );
1807 }
1809 XMLHandle NextSiblingElement( const char* _value=0 ) {
1810 return XMLHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
1811 }
1812
1815 return _node;
1816 }
1819 return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
1820 }
1823 return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
1824 }
1827 return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
1828 }
1831 return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
1832 }
1833
1834private:
1835 XMLNode* _node;
1836};
1837
1838
1843class TINYXML2_LIB XMLConstHandle
1844{
1845public:
1846 XMLConstHandle( const XMLNode* node ) {
1847 _node = node;
1848 }
1849 XMLConstHandle( const XMLNode& node ) {
1850 _node = &node;
1851 }
1853 _node = ref._node;
1854 }
1855
1857 _node = ref._node;
1858 return *this;
1859 }
1860
1862 return XMLConstHandle( _node ? _node->FirstChild() : 0 );
1863 }
1864 const XMLConstHandle FirstChildElement( const char* value=0 ) const {
1865 return XMLConstHandle( _node ? _node->FirstChildElement( value ) : 0 );
1866 }
1868 return XMLConstHandle( _node ? _node->LastChild() : 0 );
1869 }
1870 const XMLConstHandle LastChildElement( const char* _value=0 ) const {
1871 return XMLConstHandle( _node ? _node->LastChildElement( _value ) : 0 );
1872 }
1874 return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
1875 }
1876 const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const {
1877 return XMLConstHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
1878 }
1880 return XMLConstHandle( _node ? _node->NextSibling() : 0 );
1881 }
1882 const XMLConstHandle NextSiblingElement( const char* _value=0 ) const {
1883 return XMLConstHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
1884 }
1885
1886
1887 const XMLNode* ToNode() const {
1888 return _node;
1889 }
1890 const XMLElement* ToElement() const {
1891 return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
1892 }
1893 const XMLText* ToText() const {
1894 return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
1895 }
1896 const XMLUnknown* ToUnknown() const {
1897 return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
1898 }
1900 return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
1901 }
1902
1903private:
1904 const XMLNode* _node;
1905};
1906
1907
1950class TINYXML2_LIB XMLPrinter : public XMLVisitor
1951{
1952public:
1959 XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 );
1960 virtual ~XMLPrinter() {}
1961
1963 void PushHeader( bool writeBOM, bool writeDeclaration );
1967 void OpenElement( const char* name, bool compactMode=false );
1969 void PushAttribute( const char* name, const char* value );
1970 void PushAttribute( const char* name, int value );
1971 void PushAttribute( const char* name, unsigned value );
1972 void PushAttribute( const char* name, bool value );
1973 void PushAttribute( const char* name, double value );
1975 virtual void CloseElement( bool compactMode=false );
1976
1978 void PushText( const char* text, bool cdata=false );
1980 void PushText( int value );
1982 void PushText( unsigned value );
1984 void PushText( bool value );
1986 void PushText( float value );
1988 void PushText( double value );
1989
1991 void PushComment( const char* comment );
1992
1993 void PushDeclaration( const char* value );
1994 void PushUnknown( const char* value );
1995
1996 virtual bool VisitEnter( const XMLDocument& /*doc*/ );
1997 virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
1998 return true;
1999 }
2000
2001 virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
2002 virtual bool VisitExit( const XMLElement& element );
2003
2004 virtual bool Visit( const XMLText& text );
2005 virtual bool Visit( const XMLComment& comment );
2006 virtual bool Visit( const XMLDeclaration& declaration );
2007 virtual bool Visit( const XMLUnknown& unknown );
2008
2013 const char* CStr() const {
2014 return _buffer.Mem();
2015 }
2021 int CStrSize() const {
2022 return _buffer.Size();
2023 }
2029 _buffer.Clear();
2030 _buffer.Push(0);
2031 }
2032
2033protected:
2034 virtual bool CompactMode( const XMLElement& ) { return _compactMode; }
2035
2039 virtual void PrintSpace( int depth );
2040 void Print( const char* format, ... );
2041
2045
2046private:
2047 void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
2048
2049 bool _firstElement;
2050 FILE* _fp;
2051 int _depth;
2052 int _textDepth;
2053 bool _processEntities;
2054 bool _compactMode;
2055
2056 enum {
2057 ENTITY_RANGE = 64,
2058 BUF_SIZE = 200
2059 };
2060 bool _entityFlag[ENTITY_RANGE];
2061 bool _restrictedEntityFlag[ENTITY_RANGE];
2062
2063 DynArray< char, 20 > _buffer;
2064#ifdef _MSC_VER
2065 DynArray< char, 20 > _accumulator;
2066#endif
2067};
2068
2069
2070} // tinyxml2
2071
2072#if defined(_MSC_VER)
2073# pragma warning(pop)
2074#endif
2075
2076#endif // TINYXML2_INCLUDED
T & operator[](int i)
Definition tinyxml2.h:251
T * PushArr(int count)
Definition tinyxml2.h:231
int Size() const
Definition tinyxml2.h:266
int Capacity() const
Definition tinyxml2.h:270
const T * Mem() const
Definition tinyxml2.h:274
const T & operator[](int i) const
Definition tinyxml2.h:256
const T & PeekTop() const
Definition tinyxml2.h:261
void PopArr(int count)
Definition tinyxml2.h:242
bool Empty() const
Definition tinyxml2.h:247
virtual int ItemSize() const =0
virtual void * Alloc()=0
virtual void Free(void *)=0
virtual void SetTracked()=0
virtual ~MemPool()
Definition tinyxml2.h:311
void Trace(const char *name)
Definition tinyxml2.h:377
virtual int ItemSize() const
Definition tinyxml2.h:335
int Untracked() const
Definition tinyxml2.h:386
virtual void Free(void *mem)
Definition tinyxml2.h:365
int CurrentAllocs() const
Definition tinyxml2.h:338
virtual void * Alloc()
Definition tinyxml2.h:342
void SetStr(const char *str, int flags=0)
void SetInternedStr(const char *str)
Definition tinyxml2.h:175
void Set(char *start, char *end, int flags)
Definition tinyxml2.h:162
char * ParseName(char *in)
@ ATTRIBUTE_VALUE_LEAVE_ENTITIES
Definition tinyxml2.h:155
@ NEEDS_NEWLINE_NORMALIZATION
Definition tinyxml2.h:148
@ TEXT_ELEMENT_LEAVE_ENTITIES
Definition tinyxml2.h:152
bool Empty() const
Definition tinyxml2.h:171
const char * GetStr()
char * ParseText(char *in, const char *endTag, int strFlags)
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
unsigned UnsignedValue() const
Query as an unsigned integer. See IntValue()
Definition tinyxml2.h:1055
float FloatValue() const
Query as a float. See IntValue()
Definition tinyxml2.h:1073
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
void SetAttribute(const char *value)
Set the attribute to a string value.
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
double DoubleValue() const
Query as a double. See IntValue()
Definition tinyxml2.h:1067
const char * Name() const
The name of the attribute.
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
XMLError QueryIntValue(int *value) const
bool BoolValue() const
Query as a boolean. See IntValue()
Definition tinyxml2.h:1061
void SetAttribute(double value)
Set the attribute to value.
const XMLAttribute * Next() const
The next attribute in the list.
Definition tinyxml2.h:1041
const char * Value() const
The value of the attribute.
void SetAttribute(bool value)
Set the attribute to value.
void SetAttribute(int value)
Set the attribute to value.
void SetAttribute(unsigned value)
Set the attribute to value.
void SetAttribute(float value)
Set the attribute to value.
virtual bool Accept(XMLVisitor *visitor) const
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition tinyxml2.h:905
virtual bool ShallowEqual(const XMLNode *compare) const
XMLComment & operator=(const XMLComment &)
virtual XMLNode * ShallowClone(XMLDocument *document) const
XMLComment(const XMLComment &)
char * ParseDeep(char *, StrPair *endTag)
XMLComment(XMLDocument *doc)
virtual const XMLComment * ToComment() const
Definition tinyxml2.h:908
XMLConstHandle(const XMLNode *node)
Definition tinyxml2.h:1846
const XMLText * ToText() const
Definition tinyxml2.h:1893
XMLConstHandle & operator=(const XMLConstHandle &ref)
Definition tinyxml2.h:1856
const XMLElement * ToElement() const
Definition tinyxml2.h:1890
XMLConstHandle(const XMLConstHandle &ref)
Definition tinyxml2.h:1852
const XMLUnknown * ToUnknown() const
Definition tinyxml2.h:1896
const XMLDeclaration * ToDeclaration() const
Definition tinyxml2.h:1899
const XMLConstHandle NextSiblingElement(const char *_value=0) const
Definition tinyxml2.h:1882
XMLConstHandle(const XMLNode &node)
Definition tinyxml2.h:1849
const XMLConstHandle FirstChildElement(const char *value=0) const
Definition tinyxml2.h:1864
const XMLConstHandle LastChild() const
Definition tinyxml2.h:1867
const XMLNode * ToNode() const
Definition tinyxml2.h:1887
const XMLConstHandle PreviousSibling() const
Definition tinyxml2.h:1873
const XMLConstHandle PreviousSiblingElement(const char *_value=0) const
Definition tinyxml2.h:1876
const XMLConstHandle LastChildElement(const char *_value=0) const
Definition tinyxml2.h:1870
const XMLConstHandle NextSibling() const
Definition tinyxml2.h:1879
const XMLConstHandle FirstChild() const
Definition tinyxml2.h:1861
XMLDeclaration & operator=(const XMLDeclaration &)
char * ParseDeep(char *, StrPair *endTag)
XMLDeclaration(const XMLDeclaration &)
virtual bool Accept(XMLVisitor *visitor) const
virtual const XMLDeclaration * ToDeclaration() const
Definition tinyxml2.h:946
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition tinyxml2.h:943
virtual bool ShallowEqual(const XMLNode *compare) const
virtual XMLNode * ShallowClone(XMLDocument *document) const
XMLDeclaration(XMLDocument *doc)
XMLElement * RootElement()
Definition tinyxml2.h:1582
void SetBOM(bool useBOM)
Definition tinyxml2.h:1575
XMLError Parse(const char *xml, size_t nBytes=(size_t)(-1))
void PrintError() const
If there is an error, print it to stdout.
char * Identify(char *p, XMLNode **node)
XMLError LoadFile(const char *filename)
bool HasBOM() const
Definition tinyxml2.h:1570
bool Error() const
Return true if there was an error parsing the document.
Definition tinyxml2.h:1654
XMLComment * NewComment(const char *comment)
XMLElement * NewElement(const char *name)
XMLUnknown * NewUnknown(const char *text)
const XMLElement * RootElement() const
Definition tinyxml2.h:1585
bool ProcessEntities() const
Definition tinyxml2.h:1560
XMLError LoadFile(FILE *)
void Clear()
Clear the document, resetting it to the initial state.
virtual bool ShallowEqual(const XMLNode *) const
Definition tinyxml2.h:1681
XMLError SaveFile(const char *filename, bool compact=false)
Whitespace WhitespaceMode() const
Definition tinyxml2.h:1563
void Print(XMLPrinter *streamer=0) const
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition tinyxml2.h:1509
const char * GetErrorStr1() const
Return a possibly helpful diagnostic location or string.
Definition tinyxml2.h:1662
XMLError SaveFile(FILE *fp, bool compact=false)
virtual bool Accept(XMLVisitor *visitor) const
void DeleteNode(XMLNode *node)
Definition tinyxml2.h:1647
virtual const XMLDocument * ToDocument() const
Definition tinyxml2.h:1512
const char * GetErrorStr2() const
Return a possibly helpful secondary diagnostic location or string.
Definition tinyxml2.h:1666
XMLText * NewText(const char *text)
void SetError(XMLError error, const char *str1, const char *str2)
XMLDeclaration * NewDeclaration(const char *text=0)
XMLDocument(bool processEntities=true, Whitespace=PRESERVE_WHITESPACE)
constructor
virtual XMLNode * ShallowClone(XMLDocument *) const
Definition tinyxml2.h:1678
XMLError ErrorID() const
Return the errorID.
Definition tinyxml2.h:1658
int QueryAttribute(const char *name, int *value) const
Definition tinyxml2.h:1282
bool BoolAttribute(const char *name) const
See IntAttribute()
Definition tinyxml2.h:1193
const char * GetText() const
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition tinyxml2.h:1303
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1240
XMLError QueryUnsignedText(unsigned *uval) const
See QueryIntText()
const XMLAttribute * FindAttribute(const char *name) const
Query a specific attribute in the list.
int QueryAttribute(const char *name, unsigned int *value) const
Definition tinyxml2.h:1286
virtual XMLNode * ShallowClone(XMLDocument *document) const
void SetText(const char *inText)
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
Definition tinyxml2.h:1323
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1232
unsigned UnsignedAttribute(const char *name) const
See IntAttribute()
Definition tinyxml2.h:1187
virtual bool Accept(XMLVisitor *visitor) const
XMLError QueryBoolText(bool *bval) const
See QueryIntText()
const char * Attribute(const char *name, const char *value=0) const
int QueryAttribute(const char *name, float *value) const
Definition tinyxml2.h:1298
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
Definition tinyxml2.h:1339
void SetText(float value)
Convenience method for setting text inside and element. See SetText() for important limitations.
void SetAttribute(const char *name, float value)
Sets the named attribute to value.
Definition tinyxml2.h:1328
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1248
void SetText(double value)
Convenience method for setting text inside and element. See SetText() for important limitations.
XMLError QueryDoubleText(double *dval) const
See QueryIntText()
float FloatAttribute(const char *name) const
See IntAttribute()
Definition tinyxml2.h:1205
void SetText(unsigned value)
Convenience method for setting text inside and element. See SetText() for important limitations.
int QueryAttribute(const char *name, double *value) const
Definition tinyxml2.h:1294
double DoubleAttribute(const char *name) const
See IntAttribute()
Definition tinyxml2.h:1199
XMLError QueryIntAttribute(const char *name, int *value) const
Definition tinyxml2.h:1224
XMLError QueryIntText(int *ival) const
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
Definition tinyxml2.h:1139
virtual const XMLElement * ToElement() const
Definition tinyxml2.h:1146
int QueryAttribute(const char *name, bool *value) const
Definition tinyxml2.h:1290
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
Definition tinyxml2.h:1318
char * ParseDeep(char *p, StrPair *endTag)
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
Definition tinyxml2.h:1308
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition tinyxml2.h:1143
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition tinyxml2.h:1135
int ClosingType() const
Definition tinyxml2.h:1463
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1256
int IntAttribute(const char *name) const
Definition tinyxml2.h:1181
virtual bool ShallowEqual(const XMLNode *compare) const
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
Definition tinyxml2.h:1313
void SetText(bool value)
Convenience method for setting text inside and element. See SetText() for important limitations.
void SetText(int value)
Convenience method for setting text inside and element. See SetText() for important limitations.
void DeleteAttribute(const char *name)
XMLError QueryFloatText(float *fval) const
See QueryIntText()
XMLHandle PreviousSiblingElement(const char *_value=0)
Get the previous sibling element of this handle.
Definition tinyxml2.h:1801
XMLHandle LastChildElement(const char *_value=0)
Get the last child element of this handle.
Definition tinyxml2.h:1793
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
Definition tinyxml2.h:1797
XMLHandle NextSiblingElement(const char *_value=0)
Get the next sibling element of this handle.
Definition tinyxml2.h:1809
XMLHandle FirstChild()
Get the first child of this handle.
Definition tinyxml2.h:1781
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
Definition tinyxml2.h:1814
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
Definition tinyxml2.h:1830
XMLHandle FirstChildElement(const char *value=0)
Get the first child element of this handle.
Definition tinyxml2.h:1785
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition tinyxml2.h:1763
XMLHandle LastChild()
Get the last child of this handle.
Definition tinyxml2.h:1789
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
Definition tinyxml2.h:1775
XMLHandle(XMLNode &node)
Create a handle from a node.
Definition tinyxml2.h:1767
XMLHandle NextSibling()
Get the next sibling of this handle.
Definition tinyxml2.h:1805
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition tinyxml2.h:1818
XMLText * ToText()
Safe cast to XMLText. This can return null.
Definition tinyxml2.h:1822
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
Definition tinyxml2.h:1826
XMLHandle(const XMLHandle &ref)
Copy constructor.
Definition tinyxml2.h:1771
const char * Value() const
virtual const XMLText * ToText() const
Definition tinyxml2.h:628
XMLNode * NextSibling()
Definition tinyxml2.h:731
XMLNode * _lastChild
Definition tinyxml2.h:839
void SetValue(const char *val, bool staticMem=false)
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition tinyxml2.h:605
const XMLElement * LastChildElement(const char *value=0) const
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition tinyxml2.h:617
XMLNode * _parent
Definition tinyxml2.h:835
XMLElement * NextSiblingElement(const char *value=0)
Definition tinyxml2.h:738
XMLNode * _next
Definition tinyxml2.h:842
XMLNode(XMLDocument *)
void DeleteChild(XMLNode *node)
XMLNode * FirstChild()
Definition tinyxml2.h:679
const XMLElement * NextSiblingElement(const char *value=0) const
Get the next (right) sibling element of this node, with an optionally supplied name.
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
Definition tinyxml2.h:596
const XMLNode * Parent() const
Get the parent of this node on the DOM.
Definition tinyxml2.h:661
const XMLElement * FirstChildElement(const char *value=0) const
XMLNode * LastChild()
Definition tinyxml2.h:697
XMLNode & operator=(const XMLNode &)
XMLNode * PreviousSibling()
Definition tinyxml2.h:715
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition tinyxml2.h:609
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition tinyxml2.h:613
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition tinyxml2.h:693
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition tinyxml2.h:592
virtual const XMLElement * ToElement() const
Definition tinyxml2.h:625
XMLNode(const XMLNode &)
virtual bool ShallowEqual(const XMLNode *compare) const =0
virtual char * ParseDeep(char *, StrPair *)
virtual bool Accept(XMLVisitor *visitor) const =0
virtual ~XMLNode()
XMLDocument * _document
Definition tinyxml2.h:834
virtual XMLNode * ShallowClone(XMLDocument *document) const =0
XMLNode * InsertAfterChild(XMLNode *afterThis, XMLNode *addThis)
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition tinyxml2.h:711
virtual const XMLDeclaration * ToDeclaration() const
Definition tinyxml2.h:637
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition tinyxml2.h:601
XMLNode * _prev
Definition tinyxml2.h:841
XMLNode * _firstChild
Definition tinyxml2.h:838
XMLElement * PreviousSiblingElement(const char *value=0)
Definition tinyxml2.h:722
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition tinyxml2.h:621
const XMLElement * PreviousSiblingElement(const char *value=0) const
Get the previous (left) sibling element of this node, with an optionally supplied name.
virtual const XMLUnknown * ToUnknown() const
Definition tinyxml2.h:640
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition tinyxml2.h:675
bool NoChildren() const
Returns true if this node has no children.
Definition tinyxml2.h:670
XMLNode * InsertFirstChild(XMLNode *addThis)
virtual const XMLDocument * ToDocument() const
Definition tinyxml2.h:634
XMLNode * Parent()
Definition tinyxml2.h:665
XMLNode * InsertEndChild(XMLNode *addThis)
XMLNode * LinkEndChild(XMLNode *addThis)
Definition tinyxml2.h:751
virtual const XMLComment * ToComment() const
Definition tinyxml2.h:631
XMLElement * LastChildElement(const char *value=0)
Definition tinyxml2.h:706
XMLElement * FirstChildElement(const char *value=0)
Definition tinyxml2.h:688
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition tinyxml2.h:727
virtual void PrintSpace(int depth)
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition tinyxml2.h:1997
void PushAttribute(const char *name, double value)
void PushHeader(bool writeBOM, bool writeDeclaration)
void PushText(const char *text, bool cdata=false)
Add a text node.
void PushText(float value)
Add a text node from a float.
void OpenElement(const char *name, bool compactMode=false)
virtual bool Visit(const XMLText &text)
Visit a text node.
virtual bool VisitEnter(const XMLElement &element, const XMLAttribute *attribute)
Visit an element.
void PushDeclaration(const char *value)
int CStrSize() const
Definition tinyxml2.h:2021
virtual bool CompactMode(const XMLElement &)
Definition tinyxml2.h:2034
void PushText(int value)
Add a text node from an integer.
virtual bool Visit(const XMLComment &comment)
Visit a comment node.
void PushText(bool value)
Add a text node from a bool.
void PushAttribute(const char *name, bool value)
void PushText(unsigned value)
Add a text node from an unsigned.
void PushAttribute(const char *name, int value)
DynArray< const char *, 10 > _stack
Definition tinyxml2.h:2044
void PushAttribute(const char *name, const char *value)
If streaming, add an attribute to an open element.
virtual bool Visit(const XMLDeclaration &declaration)
Visit a declaration.
virtual bool Visit(const XMLUnknown &unknown)
Visit an unknown node.
void PushAttribute(const char *name, unsigned value)
XMLPrinter(FILE *file=0, bool compact=false, int depth=0)
void PushText(double value)
Add a text node from a double.
void PushUnknown(const char *value)
void Print(const char *format,...)
const char * CStr() const
Definition tinyxml2.h:2013
virtual void CloseElement(bool compactMode=false)
If streaming, close the Element.
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
virtual bool VisitExit(const XMLElement &element)
Visit an element.
virtual ~XMLPrinter()
Definition tinyxml2.h:1960
void PushComment(const char *comment)
Add a comment.
XMLText(const XMLText &)
virtual bool Accept(XMLVisitor *visitor) const
virtual const XMLText * ToText() const
Definition tinyxml2.h:872
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition tinyxml2.h:869
XMLText & operator=(const XMLText &)
char * ParseDeep(char *, StrPair *endTag)
bool CData() const
Returns true if this is a CDATA text element.
Definition tinyxml2.h:881
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
Definition tinyxml2.h:877
XMLText(XMLDocument *doc)
Definition tinyxml2.h:890
virtual bool ShallowEqual(const XMLNode *compare) const
virtual ~XMLText()
Definition tinyxml2.h:891
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual bool ShallowEqual(const XMLNode *compare) const
char * ParseDeep(char *, StrPair *endTag)
virtual bool Accept(XMLVisitor *visitor) const
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition tinyxml2.h:975
virtual XMLNode * ShallowClone(XMLDocument *document) const
XMLUnknown(XMLDocument *doc)
XMLUnknown(const XMLUnknown &)
virtual const XMLUnknown * ToUnknown() const
Definition tinyxml2.h:978
XMLUnknown & operator=(const XMLUnknown &)
static bool IsNameChar(unsigned char ch)
Definition tinyxml2.h:511
static const char * GetCharacterRef(const char *p, char *value, int *length)
static void ToStr(unsigned v, char *buffer, int bufferSize)
static const char * SkipWhiteSpace(const char *p)
Definition tinyxml2.h:489
static int IsUTF8Continuation(const char p)
Definition tinyxml2.h:534
static bool IsWhiteSpace(char p)
Definition tinyxml2.h:501
static bool ToUnsigned(const char *str, unsigned *value)
static void ToStr(int v, char *buffer, int bufferSize)
static void ToStr(double v, char *buffer, int bufferSize)
static void ToStr(float v, char *buffer, int bufferSize)
static char * SkipWhiteSpace(char *p)
Definition tinyxml2.h:495
static bool ToDouble(const char *str, double *value)
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
static bool IsNameStartChar(unsigned char ch)
Definition tinyxml2.h:505
static bool ToFloat(const char *str, float *value)
static bool ToInt(const char *str, int *value)
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
Definition tinyxml2.h:518
static const char * ReadBOM(const char *p, bool *hasBOM)
static void ToStr(bool v, char *buffer, int bufferSize)
static bool ToBool(const char *str, bool *value)
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
Definition tinyxml2.h:475
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition tinyxml2.h:449
virtual ~XMLVisitor()
Definition tinyxml2.h:442
virtual bool VisitExit(const XMLElement &)
Visit an element.
Definition tinyxml2.h:458
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
Definition tinyxml2.h:445
virtual bool Visit(const XMLComment &)
Visit a comment node.
Definition tinyxml2.h:471
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
Definition tinyxml2.h:463
virtual bool Visit(const XMLText &)
Visit a text node.
Definition tinyxml2.h:467
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
Definition tinyxml2.h:454
@ XML_ERROR_MISMATCHED_ELEMENT
Definition tinyxml2.h:1016
@ XML_ERROR_EMPTY_DOCUMENT
Definition tinyxml2.h:1015
@ XML_SUCCESS
Definition tinyxml2.h:998
@ XML_ERROR_ELEMENT_MISMATCH
Definition tinyxml2.h:1006
@ XML_ERROR_PARSING_ATTRIBUTE
Definition tinyxml2.h:1008
@ XML_ERROR_FILE_NOT_FOUND
Definition tinyxml2.h:1003
@ XML_ERROR_IDENTIFYING_TAG
Definition tinyxml2.h:1009
@ XML_ERROR_PARSING_TEXT
Definition tinyxml2.h:1010
@ XML_ERROR_PARSING_COMMENT
Definition tinyxml2.h:1012
@ XML_NO_TEXT_NODE
Definition tinyxml2.h:1020
@ XML_ERROR_FILE_READ_ERROR
Definition tinyxml2.h:1005
@ XML_ERROR_PARSING_UNKNOWN
Definition tinyxml2.h:1014
@ XML_ERROR_PARSING_CDATA
Definition tinyxml2.h:1011
@ XML_NO_ATTRIBUTE
Definition tinyxml2.h:1000
@ XML_NO_ERROR
Definition tinyxml2.h:997
@ XML_ERROR_PARSING_DECLARATION
Definition tinyxml2.h:1013
@ XML_WRONG_ATTRIBUTE_TYPE
Definition tinyxml2.h:1001
@ XML_ERROR_PARSING
Definition tinyxml2.h:1017
@ XML_ERROR_PARSING_ELEMENT
Definition tinyxml2.h:1007
@ XML_ERROR_FILE_COULD_NOT_BE_OPENED
Definition tinyxml2.h:1004
@ XML_CAN_NOT_CONVERT_TEXT
Definition tinyxml2.h:1019
@ PRESERVE_WHITESPACE
Definition tinyxml2.h:1491
@ COLLAPSE_WHITESPACE
Definition tinyxml2.h:1492
STBI_EXTERN unsigned long const char * str
Definition stb_image.h:1182
STBI_EXTERN unsigned long flags
Definition stb_image.h:1182
int TIXML_SNPRINTF(char *buffer, size_t size, const char *format,...)
Definition tinyxml2.h:103