Project

General

Profile

BitmapToolkit Scol plugin
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
172. Altered source versions must be plainly marked as such, and
18must not be misrepresented as being the original software.
19
203. This notice may not be removed or altered from any source
21distribution.
22*/
23
24#ifndef TINYXML2_INCLUDED
25#define TINYXML2_INCLUDED
26
27#include <scolPlugin.h>
28
29#include <cctype>
30#include <climits>
31#include <cstdio>
32#include <cstdlib>
33#include <cstring>
34#include <cstdarg>
35
36
37/*
38 TODO: intern strings instead of allocation.
39*/
40/*
41 gcc:
42 g++ -Wall tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
43
44 Formatting, Artistic Style:
45 AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
46*/
47
48#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
49# ifndef DEBUG
50# define DEBUG
51# endif
52#endif
53
54
55#if defined(DEBUG)
56# if defined(_MSC_VER)
57# define TIXMLASSERT( x ) if ( !(x)) { __debugbreak(); } //if ( !(x)) WinDebugBreak()
58# elif defined (ANDROID_NDK)
59# include <android/log.h>
60# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
61# else
62# include <assert.h>
63# define TIXMLASSERT assert
64# endif
65# else
66# define TIXMLASSERT( x ) {}
67#endif
68
69
70#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
71// Microsoft visual studio, version 2005 and higher.
72/*int _snprintf_s(
73 char *buffer,
74 size_t sizeOfBuffer,
75 size_t count,
76 const char *format [,
77 argument] ...
78);*/
79inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
80{
81 va_list va;
82 va_start( va, format );
83 int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
84 va_end( va );
85 return result;
86}
87#define TIXML_SSCANF sscanf_s
88#else
89// GCC version 3 and higher
90//#warning( "Using sn* functions." )
91#define TIXML_SNPRINTF snprintf
92#define TIXML_SSCANF sscanf
93#endif
94
95static const int TIXML2_MAJOR_VERSION = 1;
96static const int TIXML2_MINOR_VERSION = 0;
97static const int TIXML2_PATCH_VERSION = 9;
98
99namespace tinyxml2
100{
101class XMLDocument;
102class XMLElement;
103class XMLAttribute;
104class XMLComment;
105class XMLNode;
106class XMLText;
107class XMLDeclaration;
108class XMLUnknown;
109
110class XMLPrinter;
111
112/*
113 A class that wraps strings. Normally stores the start and end
114 pointers into the XML file itself, and will apply normalization
115 and entity translation if actually read. Can also store (and memory
116 manage) a traditional char[]
117*/
119{
120public:
121 enum {
125
132 };
133
134 StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
135 ~StrPair();
136
137 void Set( char* start, char* end, int flags ) {
138 Reset();
139 _start = start;
140 _end = end;
141 _flags = flags | NEEDS_FLUSH;
142 }
143
144 const char* GetStr();
145
146 bool Empty() const {
147 return _start == _end;
148 }
149
150 void SetInternedStr( const char* str ) {
151 Reset();
152 _start = const_cast<char*>(str);
153 }
154
155 void SetStr( const char* str, int flags=0 );
156
157 char* ParseText( char* in, const char* endTag, int strFlags );
158 char* ParseName( char* in );
159
160private:
161 void Reset();
162 void CollapseWhitespace();
163
164 enum {
165 NEEDS_FLUSH = 0x100,
166 NEEDS_DELETE = 0x200
167 };
168
169 // After parsing, if *end != 0, it can be set to zero.
170 int _flags;
171 char* _start;
172 char* _end;
173};
174
175
176/*
177 A dynamic array of Plain Old Data. Doesn't support constructors, etc.
178 Has a small initial memory pool, so that low or no usage will not
179 cause a call to new/delete
180*/
181template <class T, int INIT>
183{
184public:
186 _mem = _pool;
187 _allocated = INIT;
188 _size = 0;
189 }
190
192 if ( _mem != _pool ) {
193 delete [] _mem;
194 }
195 }
196
197 void Push( T t ) {
198 EnsureCapacity( _size+1 );
199 _mem[_size++] = t;
200 }
201
202 T* PushArr( int count ) {
203 EnsureCapacity( _size+count );
204 T* ret = &_mem[_size];
205 _size += count;
206 return ret;
207 }
208
209 T Pop() {
210 return _mem[--_size];
211 }
212
213 void PopArr( int count ) {
214 TIXMLASSERT( _size >= count );
215 _size -= count;
216 }
217
218 bool Empty() const {
219 return _size == 0;
220 }
221
222 T& operator[](int i) {
223 TIXMLASSERT( i>= 0 && i < _size );
224 return _mem[i];
225 }
226
227 const T& operator[](int i) const {
228 TIXMLASSERT( i>= 0 && i < _size );
229 return _mem[i];
230 }
231
232 int Size() const {
233 return _size;
234 }
235
236 int Capacity() const {
237 return _allocated;
238 }
239
240 const T* Mem() const {
241 return _mem;
242 }
243
244 T* Mem() {
245 return _mem;
246 }
247
248private:
249 void EnsureCapacity( int cap ) {
250 if ( cap > _allocated ) {
251 int newAllocated = cap * 2;
252 T* newMem = new T[newAllocated];
253 memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
254 if ( _mem != _pool ) {
255 delete [] _mem;
256 }
257 _mem = newMem;
258 _allocated = newAllocated;
259 }
260 }
261
262 T* _mem;
263 T _pool[INIT];
264 int _allocated; // objects allocated
265 int _size; // number objects in use
266};
267
268
269/*
270 Parent virtual class of a pool for fast allocation
271 and deallocation of objects.
272*/
274{
275public:
277 virtual ~MemPool() {}
278
279 virtual int ItemSize() const = 0;
280 virtual void* Alloc() = 0;
281 virtual void Free( void* ) = 0;
282};
283
284
285/*
286 Template child class to create pools of the correct type.
287*/
288template< int SIZE >
289class MemPoolT : public MemPool
290{
291public:
292 MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0) {}
294 // Delete the blocks.
295 for( int i=0; i<_blockPtrs.Size(); ++i ) {
296 delete _blockPtrs[i];
297 }
298 }
299
300 virtual int ItemSize() const {
301 return SIZE;
302 }
303 int CurrentAllocs() const {
304 return _currentAllocs;
305 }
306
307 virtual void* Alloc() {
308 if ( !_root ) {
309 // Need a new block.
310 Block* block = new Block();
311 _blockPtrs.Push( block );
312
313 for( int i=0; i<COUNT-1; ++i ) {
314 block->chunk[i].next = &block->chunk[i+1];
315 }
316 block->chunk[COUNT-1].next = 0;
317 _root = block->chunk;
318 }
319 void* result = _root;
320 _root = _root->next;
321
322 ++_currentAllocs;
323 if ( _currentAllocs > _maxAllocs ) {
324 _maxAllocs = _currentAllocs;
325 }
326 _nAllocs++;
327 return result;
328 }
329 virtual void Free( void* mem ) {
330 if ( !mem ) {
331 return;
332 }
333 --_currentAllocs;
334 Chunk* chunk = (Chunk*)mem;
335#ifdef DEBUG
336 memset( chunk, 0xfe, sizeof(Chunk) );
337#endif
338 chunk->next = _root;
339 _root = chunk;
340 }
341 void Trace( const char* name ) {
342 printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
343 name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() );
344 }
345
346 enum { COUNT = 1024/SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private
347
348private:
349 union Chunk {
350 Chunk* next;
351 char mem[SIZE];
352 };
353 struct Block {
354 Chunk chunk[COUNT];
355 };
356 DynArray< Block*, 10 > _blockPtrs;
357 Chunk* _root;
358
359 int _currentAllocs;
360 int _nAllocs;
361 int _maxAllocs;
362};
363
364
365
386{
387public:
388 virtual ~XMLVisitor() {}
389
391 virtual bool VisitEnter( const XMLDocument& /*doc*/ ) {
392 return true;
393 }
395 virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
396 return true;
397 }
398
400 virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) {
401 return true;
402 }
404 virtual bool VisitExit( const XMLElement& /*element*/ ) {
405 return true;
406 }
407
409 virtual bool Visit( const XMLDeclaration& /*declaration*/ ) {
410 return true;
411 }
413 virtual bool Visit( const XMLText& /*text*/ ) {
414 return true;
415 }
417 virtual bool Visit( const XMLComment& /*comment*/ ) {
418 return true;
419 }
421 virtual bool Visit( const XMLUnknown& /*unknown*/ ) {
422 return true;
423 }
424};
425
426
427/*
428 Utility functionality.
429*/
431{
432public:
433 // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
434 // correct, but simple, and usually works.
435 static const char* SkipWhiteSpace( const char* p ) {
436 while( !IsUTF8Continuation(*p) && std::isspace( *reinterpret_cast<const unsigned char*>(p) ) ) {
437 ++p;
438 }
439 return p;
440 }
441 static char* SkipWhiteSpace( char* p ) {
442 while( !IsUTF8Continuation(*p) && std::isspace( *reinterpret_cast<unsigned char*>(p) ) ) {
443 ++p;
444 }
445 return p;
446 }
447 static bool IsWhiteSpace( char p ) {
448 return !IsUTF8Continuation(p) && std::isspace( static_cast<unsigned char>(p) );
449 }
450
451 inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
452 int n = 0;
453 if ( p == q ) {
454 return true;
455 }
456 while( *p && *q && *p == *q && n<nChar ) {
457 ++p;
458 ++q;
459 ++n;
460 }
461 if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
462 return true;
463 }
464 return false;
465 }
466 inline static int IsUTF8Continuation( const char p ) {
467 return p & 0x80;
468 }
469 inline static int IsAlphaNum( unsigned char anyByte ) {
470 return ( anyByte < 128 ) ? std::isalnum( anyByte ) : 1;
471 }
472 inline static int IsAlpha( unsigned char anyByte ) {
473 return ( anyByte < 128 ) ? std::isalpha( anyByte ) : 1;
474 }
475
476 static const char* ReadBOM( const char* p, bool* hasBOM );
477 // p is the starting location,
478 // the UTF-8 value of the entity will be placed in value, and length filled in.
479 static const char* GetCharacterRef( const char* p, char* value, int* length );
480 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
481
482 // converts primitive types to strings
483 static void ToStr( int v, char* buffer, int bufferSize );
484 static void ToStr( unsigned v, char* buffer, int bufferSize );
485 static void ToStr( bool v, char* buffer, int bufferSize );
486 static void ToStr( float v, char* buffer, int bufferSize );
487 static void ToStr( double v, char* buffer, int bufferSize );
488
489 // converts strings to primitive types
490 static bool ToInt( const char* str, int* value );
491 static bool ToUnsigned( const char* str, unsigned* value );
492 static bool ToBool( const char* str, bool* value );
493 static bool ToFloat( const char* str, float* value );
494 static bool ToDouble( const char* str, double* value );
495};
496
497
524{
525 friend class XMLDocument;
526 friend class XMLElement;
527public:
528
530 const XMLDocument* GetDocument() const {
531 return _document;
532 }
535 return _document;
536 }
537
540 return 0;
541 }
543 virtual XMLText* ToText() {
544 return 0;
545 }
548 return 0;
549 }
552 return 0;
553 }
556 return 0;
557 }
560 return 0;
561 }
562
563 virtual const XMLElement* ToElement() const {
564 return 0;
565 }
566 virtual const XMLText* ToText() const {
567 return 0;
568 }
569 virtual const XMLComment* ToComment() const {
570 return 0;
571 }
572 virtual const XMLDocument* ToDocument() const {
573 return 0;
574 }
575 virtual const XMLDeclaration* ToDeclaration() const {
576 return 0;
577 }
578 virtual const XMLUnknown* ToUnknown() const {
579 return 0;
580 }
581
591 const char* Value() const {
592 return _value.GetStr();
593 }
594
598 void SetValue( const char* val, bool staticMem=false );
599
601 const XMLNode* Parent() const {
602 return _parent;
603 }
604
606 return _parent;
607 }
608
610 bool NoChildren() const {
611 return !_firstChild;
612 }
613
615 const XMLNode* FirstChild() const {
616 return _firstChild;
617 }
618
620 return _firstChild;
621 }
622
626 const XMLElement* FirstChildElement( const char* value=0 ) const;
627
628 XMLElement* FirstChildElement( const char* value=0 ) {
629 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( value ));
630 }
631
633 const XMLNode* LastChild() const {
634 return _lastChild;
635 }
636
638 return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->LastChild() );
639 }
640
644 const XMLElement* LastChildElement( const char* value=0 ) const;
645
646 XMLElement* LastChildElement( const char* value=0 ) {
647 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(value) );
648 }
649
651 const XMLNode* PreviousSibling() const {
652 return _prev;
653 }
654
656 return _prev;
657 }
658
660 const XMLElement* PreviousSiblingElement( const char* value=0 ) const ;
661
662 XMLElement* PreviousSiblingElement( const char* value=0 ) {
663 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( value ) );
664 }
665
667 const XMLNode* NextSibling() const {
668 return _next;
669 }
670
672 return _next;
673 }
674
676 const XMLElement* NextSiblingElement( const char* value=0 ) const;
677
678 XMLElement* NextSiblingElement( const char* value=0 ) {
679 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( value ) );
680 }
681
685 XMLNode* InsertEndChild( XMLNode* addThis );
686
688 return InsertEndChild( addThis );
689 }
693 XMLNode* InsertFirstChild( XMLNode* addThis );
697 XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
698
702 void DeleteChildren();
703
707 void DeleteChild( XMLNode* node );
708
718 virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
719
726 virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
727
750 virtual bool Accept( XMLVisitor* visitor ) const = 0;
751
752 // internal
753 virtual char* ParseDeep( char*, StrPair* );
754
755protected:
757 virtual ~XMLNode();
758 XMLNode( const XMLNode& ); // not supported
759 XMLNode& operator=( const XMLNode& ); // not supported
760
764
767
770
771private:
772 MemPool* _memPool;
773 void Unlink( XMLNode* child );
774};
775
776
789class XMLText : public XMLNode
790{
791 friend class XMLBase;
792 friend class XMLDocument;
793public:
794 virtual bool Accept( XMLVisitor* visitor ) const;
795
796 virtual XMLText* ToText() {
797 return this;
798 }
799 virtual const XMLText* ToText() const {
800 return this;
801 }
802
804 void SetCData( bool isCData ) {
805 _isCData = isCData;
806 }
808 bool CData() const {
809 return _isCData;
810 }
811
812 char* ParseDeep( char*, StrPair* endTag );
813 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
814 virtual bool ShallowEqual( const XMLNode* compare ) const;
815
816protected:
817 XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
818 virtual ~XMLText() {}
819 XMLText( const XMLText& ); // not supported
820 XMLText& operator=( const XMLText& ); // not supported
821
822private:
823 bool _isCData;
824};
825
826
828class XMLComment : public XMLNode
829{
830 friend class XMLDocument;
831public:
833 return this;
834 }
835 virtual const XMLComment* ToComment() const {
836 return this;
837 }
838
839 virtual bool Accept( XMLVisitor* visitor ) const;
840
841 char* ParseDeep( char*, StrPair* endTag );
842 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
843 virtual bool ShallowEqual( const XMLNode* compare ) const;
844
845protected:
846 XMLComment( XMLDocument* doc );
847 virtual ~XMLComment();
848 XMLComment( const XMLComment& ); // not supported
849 XMLComment& operator=( const XMLComment& ); // not supported
850
851private:
852};
853
854
867{
868 friend class XMLDocument;
869public:
871 return this;
872 }
873 virtual const XMLDeclaration* ToDeclaration() const {
874 return this;
875 }
876
877 virtual bool Accept( XMLVisitor* visitor ) const;
878
879 char* ParseDeep( char*, StrPair* endTag );
880 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
881 virtual bool ShallowEqual( const XMLNode* compare ) const;
882
883protected:
885 virtual ~XMLDeclaration();
886 XMLDeclaration( const XMLDeclaration& ); // not supported
887 XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
888};
889
890
898class XMLUnknown : public XMLNode
899{
900 friend class XMLDocument;
901public:
903 return this;
904 }
905 virtual const XMLUnknown* ToUnknown() const {
906 return this;
907 }
908
909 virtual bool Accept( XMLVisitor* visitor ) const;
910
911 char* ParseDeep( char*, StrPair* endTag );
912 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
913 virtual bool ShallowEqual( const XMLNode* compare ) const;
914
915protected:
916 XMLUnknown( XMLDocument* doc );
917 virtual ~XMLUnknown();
918 XMLUnknown( const XMLUnknown& ); // not supported
919 XMLUnknown& operator=( const XMLUnknown& ); // not supported
920};
921
922
949
950
958{
959 friend class XMLElement;
960public:
962 const char* Name() const {
963 return _name.GetStr();
964 }
966 const char* Value() const {
967 return _value.GetStr();
968 }
970 const XMLAttribute* Next() const {
971 return _next;
972 }
973
978 int IntValue() const {
979 int i=0;
980 QueryIntValue( &i );
981 return i;
982 }
984 unsigned UnsignedValue() const {
985 unsigned i=0;
986 QueryUnsignedValue( &i );
987 return i;
988 }
990 bool BoolValue() const {
991 bool b=false;
992 QueryBoolValue( &b );
993 return b;
994 }
996 double DoubleValue() const {
997 double d=0;
998 QueryDoubleValue( &d );
999 return d;
1000 }
1002 float FloatValue() const {
1003 float f=0;
1004 QueryFloatValue( &f );
1005 return f;
1006 }
1007
1012 XMLError QueryIntValue( int* value ) const;
1014 XMLError QueryUnsignedValue( unsigned int* value ) const;
1016 XMLError QueryBoolValue( bool* value ) const;
1018 XMLError QueryDoubleValue( double* value ) const;
1020 XMLError QueryFloatValue( float* value ) const;
1021
1023 void SetAttribute( const char* value );
1025 void SetAttribute( int value );
1027 void SetAttribute( unsigned value );
1029 void SetAttribute( bool value );
1031 void SetAttribute( double value );
1033 void SetAttribute( float value );
1034
1035private:
1036 enum { BUF_SIZE = 200 };
1037
1038 XMLAttribute() : _next( 0 ) {}
1039 virtual ~XMLAttribute() {}
1040
1041 XMLAttribute( const XMLAttribute& ); // not supported
1042 void operator=( const XMLAttribute& ); // not supported
1043 void SetName( const char* name );
1044
1045 char* ParseDeep( char* p, bool processEntities );
1046
1047 mutable StrPair _name;
1048 mutable StrPair _value;
1049 XMLAttribute* _next;
1050 MemPool* _memPool;
1051};
1052
1053
1058class XMLElement : public XMLNode
1059{
1060 friend class XMLBase;
1061 friend class XMLDocument;
1062public:
1064 const char* Name() const {
1065 return Value();
1066 }
1068 void SetName( const char* str, bool staticMem=false ) {
1069 SetValue( str, staticMem );
1070 }
1071
1073 return this;
1074 }
1075 virtual const XMLElement* ToElement() const {
1076 return this;
1077 }
1078 virtual bool Accept( XMLVisitor* visitor ) const;
1079
1103 const char* Attribute( const char* name, const char* value=0 ) const;
1104
1110 int IntAttribute( const char* name ) const {
1111 int i=0;
1112 QueryIntAttribute( name, &i );
1113 return i;
1114 }
1116 unsigned UnsignedAttribute( const char* name ) const {
1117 unsigned i=0;
1118 QueryUnsignedAttribute( name, &i );
1119 return i;
1120 }
1122 bool BoolAttribute( const char* name ) const {
1123 bool b=false;
1124 QueryBoolAttribute( name, &b );
1125 return b;
1126 }
1128 double DoubleAttribute( const char* name ) const {
1129 double d=0;
1130 QueryDoubleAttribute( name, &d );
1131 return d;
1132 }
1134 float FloatAttribute( const char* name ) const {
1135 float f=0;
1136 QueryFloatAttribute( name, &f );
1137 return f;
1138 }
1139
1153 XMLError QueryIntAttribute( const char* name, int* value ) const {
1154 const XMLAttribute* a = FindAttribute( name );
1155 if ( !a ) {
1156 return XML_NO_ATTRIBUTE;
1157 }
1158 return a->QueryIntValue( value );
1159 }
1161 XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
1162 const XMLAttribute* a = FindAttribute( name );
1163 if ( !a ) {
1164 return XML_NO_ATTRIBUTE;
1165 }
1166 return a->QueryUnsignedValue( value );
1167 }
1169 XMLError QueryBoolAttribute( const char* name, bool* value ) const {
1170 const XMLAttribute* a = FindAttribute( name );
1171 if ( !a ) {
1172 return XML_NO_ATTRIBUTE;
1173 }
1174 return a->QueryBoolValue( value );
1175 }
1177 XMLError QueryDoubleAttribute( const char* name, double* value ) const {
1178 const XMLAttribute* a = FindAttribute( name );
1179 if ( !a ) {
1180 return XML_NO_ATTRIBUTE;
1181 }
1182 return a->QueryDoubleValue( value );
1183 }
1185 XMLError QueryFloatAttribute( const char* name, float* value ) const {
1186 const XMLAttribute* a = FindAttribute( name );
1187 if ( !a ) {
1188 return XML_NO_ATTRIBUTE;
1189 }
1190 return a->QueryFloatValue( value );
1191 }
1192
1194 void SetAttribute( const char* name, const char* value ) {
1195 XMLAttribute* a = FindOrCreateAttribute( name );
1196 a->SetAttribute( value );
1197 }
1199 void SetAttribute( const char* name, int value ) {
1200 XMLAttribute* a = FindOrCreateAttribute( name );
1201 a->SetAttribute( value );
1202 }
1204 void SetAttribute( const char* name, unsigned value ) {
1205 XMLAttribute* a = FindOrCreateAttribute( name );
1206 a->SetAttribute( value );
1207 }
1209 void SetAttribute( const char* name, bool value ) {
1210 XMLAttribute* a = FindOrCreateAttribute( name );
1211 a->SetAttribute( value );
1212 }
1214 void SetAttribute( const char* name, double value ) {
1215 XMLAttribute* a = FindOrCreateAttribute( name );
1216 a->SetAttribute( value );
1217 }
1218
1222 void DeleteAttribute( const char* name );
1223
1226 return _rootAttribute;
1227 }
1229 const XMLAttribute* FindAttribute( const char* name ) const;
1230
1259 const char* GetText() const;
1260
1287 XMLError QueryIntText( int* _value ) const;
1289 XMLError QueryUnsignedText( unsigned* _value ) const;
1291 XMLError QueryBoolText( bool* _value ) const;
1293 XMLError QueryDoubleText( double* _value ) const;
1295 XMLError QueryFloatText( float* _value ) const;
1296
1297 // internal:
1298 enum {
1299 OPEN, // <foo>
1300 CLOSED, // <foo/>
1301 CLOSING // </foo>
1303 int ClosingType() const {
1304 return _closingType;
1305 }
1306 char* ParseDeep( char* p, StrPair* endTag );
1307 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1308 virtual bool ShallowEqual( const XMLNode* compare ) const;
1309
1310private:
1311 XMLElement( XMLDocument* doc );
1312 virtual ~XMLElement();
1313 XMLElement( const XMLElement& ); // not supported
1314 void operator=( const XMLElement& ); // not supported
1315
1316 XMLAttribute* FindAttribute( const char* name );
1317 XMLAttribute* FindOrCreateAttribute( const char* name );
1318 //void LinkAttribute( XMLAttribute* attrib );
1319 char* ParseAttributes( char* p );
1320
1321 int _closingType;
1322 // The attribute list is ordered; there is no 'lastAttribute'
1323 // because the list needs to be scanned for dupes before adding
1324 // a new attribute.
1325 XMLAttribute* _rootAttribute;
1326};
1327
1328
1333
1334
1340class XMLDocument : public XMLNode
1341{
1342 friend class XMLElement;
1343public:
1345 XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE );
1346 ~XMLDocument();
1347
1349 return this;
1350 }
1351 virtual const XMLDocument* ToDocument() const {
1352 return this;
1353 }
1354
1365 XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) );
1366
1372 XMLError LoadFile( const char* filename );
1373
1381 XMLError LoadFile( std::FILE* );
1382
1388 XMLError SaveFile( const char* filename, bool compact = false );
1389
1397 XMLError SaveFile( std::FILE* fp, bool compact = false );
1398
1399 bool ProcessEntities() const {
1400 return _processEntities;
1401 }
1403 return _whitespace;
1404 }
1405
1409 bool HasBOM() const {
1410 return _writeBOM;
1411 }
1414 void SetBOM( bool useBOM ) {
1415 _writeBOM = useBOM;
1416 }
1417
1422 return FirstChildElement();
1423 }
1424 const XMLElement* RootElement() const {
1425 return FirstChildElement();
1426 }
1427
1442 void Print( XMLPrinter* streamer=0 );
1443 virtual bool Accept( XMLVisitor* visitor ) const;
1444
1450 XMLElement* NewElement( const char* name );
1456 XMLComment* NewComment( const char* comment );
1462 XMLText* NewText( const char* text );
1474 XMLDeclaration* NewDeclaration( const char* text=0 );
1480 XMLUnknown* NewUnknown( const char* text );
1481
1486 void DeleteNode( XMLNode* node ) {
1487 node->_parent->DeleteChild( node );
1488 }
1489
1490 void SetError( XMLError error, const char* str1, const char* str2 );
1491
1493 bool Error() const {
1494 return _errorID != XML_NO_ERROR;
1495 }
1498 return _errorID;
1499 }
1501 const char* GetErrorStr1() const {
1502 return _errorStr1;
1503 }
1505 const char* GetErrorStr2() const {
1506 return _errorStr2;
1507 }
1509 void PrintError() const;
1510
1511 // internal
1512 char* Identify( char* p, XMLNode** node );
1513
1514 virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
1515 return 0;
1516 }
1517 virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
1518 return false;
1519 }
1520
1521private:
1522 XMLDocument( const XMLDocument& ); // not supported
1523 void operator=( const XMLDocument& ); // not supported
1524 void InitDocument();
1525
1526 bool _writeBOM;
1527 bool _processEntities;
1528 XMLError _errorID;
1529 Whitespace _whitespace;
1530 const char* _errorStr1;
1531 const char* _errorStr2;
1532 char* _charBuffer;
1533
1534 MemPoolT< sizeof(XMLElement) > _elementPool;
1535 MemPoolT< sizeof(XMLAttribute) > _attributePool;
1536 MemPoolT< sizeof(XMLText) > _textPool;
1537 MemPoolT< sizeof(XMLComment) > _commentPool;
1538};
1539
1540
1597{
1598public:
1601 _node = node;
1602 }
1605 _node = &node;
1606 }
1608 XMLHandle( const XMLHandle& ref ) {
1609 _node = ref._node;
1610 }
1613 _node = ref._node;
1614 return *this;
1615 }
1616
1619 return XMLHandle( _node ? _node->FirstChild() : 0 );
1620 }
1622 XMLHandle FirstChildElement( const char* value=0 ) {
1623 return XMLHandle( _node ? _node->FirstChildElement( value ) : 0 );
1624 }
1627 return XMLHandle( _node ? _node->LastChild() : 0 );
1628 }
1630 XMLHandle LastChildElement( const char* _value=0 ) {
1631 return XMLHandle( _node ? _node->LastChildElement( _value ) : 0 );
1632 }
1635 return XMLHandle( _node ? _node->PreviousSibling() : 0 );
1636 }
1638 XMLHandle PreviousSiblingElement( const char* _value=0 ) {
1639 return XMLHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
1640 }
1643 return XMLHandle( _node ? _node->NextSibling() : 0 );
1644 }
1646 XMLHandle NextSiblingElement( const char* _value=0 ) {
1647 return XMLHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
1648 }
1649
1652 return _node;
1653 }
1656 return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
1657 }
1660 return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
1661 }
1664 return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
1665 }
1668 return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
1669 }
1670
1671private:
1672 XMLNode* _node;
1673};
1674
1675
1681{
1682public:
1683 XMLConstHandle( const XMLNode* node ) {
1684 _node = node;
1685 }
1686 XMLConstHandle( const XMLNode& node ) {
1687 _node = &node;
1688 }
1690 _node = ref._node;
1691 }
1692
1694 _node = ref._node;
1695 return *this;
1696 }
1697
1699 return XMLConstHandle( _node ? _node->FirstChild() : 0 );
1700 }
1701 const XMLConstHandle FirstChildElement( const char* value=0 ) const {
1702 return XMLConstHandle( _node ? _node->FirstChildElement( value ) : 0 );
1703 }
1705 return XMLConstHandle( _node ? _node->LastChild() : 0 );
1706 }
1707 const XMLConstHandle LastChildElement( const char* _value=0 ) const {
1708 return XMLConstHandle( _node ? _node->LastChildElement( _value ) : 0 );
1709 }
1711 return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
1712 }
1713 const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const {
1714 return XMLConstHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
1715 }
1717 return XMLConstHandle( _node ? _node->NextSibling() : 0 );
1718 }
1719 const XMLConstHandle NextSiblingElement( const char* _value=0 ) const {
1720 return XMLConstHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
1721 }
1722
1723
1724 const XMLNode* ToNode() const {
1725 return _node;
1726 }
1727 const XMLElement* ToElement() const {
1728 return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
1729 }
1730 const XMLText* ToText() const {
1731 return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
1732 }
1733 const XMLUnknown* ToUnknown() const {
1734 return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
1735 }
1737 return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
1738 }
1739
1740private:
1741 const XMLNode* _node;
1742};
1743
1744
1788{
1789public:
1796 XMLPrinter( std::FILE* file=0, bool compact = false );
1798
1800 void PushHeader( bool writeBOM, bool writeDeclaration );
1804 void OpenElement( const char* name );
1806 void PushAttribute( const char* name, const char* value );
1807 void PushAttribute( const char* name, int value );
1808 void PushAttribute( const char* name, unsigned value );
1809 void PushAttribute( const char* name, bool value );
1810 void PushAttribute( const char* name, double value );
1812 void CloseElement();
1813
1815 void PushText( const char* text, bool cdata=false );
1817 void PushText( int value );
1819 void PushText( unsigned value );
1821 void PushText( bool value );
1823 void PushText( float value );
1825 void PushText( double value );
1826
1828 void PushComment( const char* comment );
1829
1830 void PushDeclaration( const char* value );
1831 void PushUnknown( const char* value );
1832
1833 virtual bool VisitEnter( const XMLDocument& /*doc*/ );
1834 virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
1835 return true;
1836 }
1837
1838 virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
1839 virtual bool VisitExit( const XMLElement& element );
1840
1841 virtual bool Visit( const XMLText& text );
1842 virtual bool Visit( const XMLComment& comment );
1843 virtual bool Visit( const XMLDeclaration& declaration );
1844 virtual bool Visit( const XMLUnknown& unknown );
1845
1850 const char* CStr() const {
1851 return _buffer.Mem();
1852 }
1858 int CStrSize() const {
1859 return _buffer.Size();
1860 }
1861
1862private:
1863 void SealElement();
1864 void PrintSpace( int depth );
1865 void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
1866 void Print( const char* format, ... );
1867
1868 bool _elementJustOpened;
1869 bool _firstElement;
1870 std::FILE* _fp;
1871 int _depth;
1872 int _textDepth;
1873 bool _processEntities;
1874 bool _compactMode;
1875
1876 enum {
1877 ENTITY_RANGE = 64,
1878 BUF_SIZE = 200
1879 };
1880 bool _entityFlag[ENTITY_RANGE];
1881 bool _restrictedEntityFlag[ENTITY_RANGE];
1882
1883 DynArray< const char*, 10 > _stack;
1884 DynArray< char, 20 > _buffer;
1885#ifdef _MSC_VER
1886 DynArray< char, 20 > _accumulator;
1887#endif
1888};
1889
1890
1891} // tinyxml2
1892
1893
1894#endif // TINYXML2_INCLUDED
T & operator[](int i)
Definition tinyxml2.h:222
T * PushArr(int count)
Definition tinyxml2.h:202
int Size() const
Definition tinyxml2.h:232
int Capacity() const
Definition tinyxml2.h:236
const T * Mem() const
Definition tinyxml2.h:240
const T & operator[](int i) const
Definition tinyxml2.h:227
void PopArr(int count)
Definition tinyxml2.h:213
bool Empty() const
Definition tinyxml2.h:218
virtual int ItemSize() const =0
virtual void * Alloc()=0
virtual void Free(void *)=0
virtual ~MemPool()
Definition tinyxml2.h:277
void Trace(const char *name)
Definition tinyxml2.h:341
virtual int ItemSize() const
Definition tinyxml2.h:300
virtual void Free(void *mem)
Definition tinyxml2.h:329
int CurrentAllocs() const
Definition tinyxml2.h:303
virtual void * Alloc()
Definition tinyxml2.h:307
@ ATTRIBUTE_VALUE_LEAVE_ENTITIES
Definition tinyxml2.h:130
@ NEEDS_NEWLINE_NORMALIZATION
Definition tinyxml2.h:123
@ TEXT_ELEMENT_LEAVE_ENTITIES
Definition tinyxml2.h:127
void SetStr(const char *str, int flags=0)
Definition tinyxml2.cpp:102
void SetInternedStr(const char *str)
Definition tinyxml2.h:150
void Set(char *start, char *end, int flags)
Definition tinyxml2.h:137
char * ParseName(char *in)
Definition tinyxml2.cpp:133
bool Empty() const
Definition tinyxml2.h:146
const char * GetStr()
Definition tinyxml2.cpp:185
char * ParseText(char *in, const char *endTag, int strFlags)
Definition tinyxml2.cpp:113
XMLError QueryFloatValue(float *value) const
See QueryIntAttribute.
unsigned UnsignedValue() const
Query as an unsigned integer. See IntAttribute()
Definition tinyxml2.h:984
float FloatValue() const
Query as a float. See IntAttribute()
Definition tinyxml2.h:1002
XMLError QueryDoubleValue(double *value) const
See QueryIntAttribute.
void SetAttribute(const char *value)
Set the attribute to a string value.
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntAttribute.
double DoubleValue() const
Query as a double. See IntAttribute()
Definition tinyxml2.h:996
const char * Name() const
The name of the attribute.
Definition tinyxml2.h:962
XMLError QueryBoolValue(bool *value) const
See QueryIntAttribute.
XMLError QueryIntValue(int *value) const
bool BoolValue() const
Query as a boolean. See IntAttribute()
Definition tinyxml2.h:990
const XMLAttribute * Next() const
The next attribute in the list.
Definition tinyxml2.h:970
const char * Value() const
The value of the attribute.
Definition tinyxml2.h:966
int IntValue() const
Definition tinyxml2.h:978
virtual bool Accept(XMLVisitor *visitor) const
Definition tinyxml2.cpp:943
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition tinyxml2.h:832
XMLComment & operator=(const XMLComment &)
virtual bool ShallowEqual(const XMLNode *compare) const
Definition tinyxml2.cpp:937
XMLComment(const XMLComment &)
char * ParseDeep(char *, StrPair *endTag)
Definition tinyxml2.cpp:915
virtual XMLNode * ShallowClone(XMLDocument *document) const
Definition tinyxml2.cpp:927
virtual const XMLComment * ToComment() const
Definition tinyxml2.h:835
XMLConstHandle(const XMLNode *node)
Definition tinyxml2.h:1683
const XMLText * ToText() const
Definition tinyxml2.h:1730
XMLConstHandle & operator=(const XMLConstHandle &ref)
Definition tinyxml2.h:1693
const XMLElement * ToElement() const
Definition tinyxml2.h:1727
XMLConstHandle(const XMLConstHandle &ref)
Definition tinyxml2.h:1689
const XMLUnknown * ToUnknown() const
Definition tinyxml2.h:1733
const XMLDeclaration * ToDeclaration() const
Definition tinyxml2.h:1736
const XMLConstHandle NextSiblingElement(const char *_value=0) const
Definition tinyxml2.h:1719
XMLConstHandle(const XMLNode &node)
Definition tinyxml2.h:1686
const XMLConstHandle FirstChildElement(const char *value=0) const
Definition tinyxml2.h:1701
const XMLConstHandle LastChild() const
Definition tinyxml2.h:1704
const XMLNode * ToNode() const
Definition tinyxml2.h:1724
const XMLConstHandle PreviousSibling() const
Definition tinyxml2.h:1710
const XMLConstHandle PreviousSiblingElement(const char *_value=0) const
Definition tinyxml2.h:1713
const XMLConstHandle LastChildElement(const char *_value=0) const
Definition tinyxml2.h:1707
const XMLConstHandle NextSibling() const
Definition tinyxml2.h:1716
const XMLConstHandle FirstChild() const
Definition tinyxml2.h:1698
XMLDeclaration & operator=(const XMLDeclaration &)
char * ParseDeep(char *, StrPair *endTag)
Definition tinyxml2.cpp:962
XMLDeclaration(const XMLDeclaration &)
virtual const XMLDeclaration * ToDeclaration() const
Definition tinyxml2.h:873
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition tinyxml2.h:870
virtual bool Accept(XMLVisitor *visitor) const
Definition tinyxml2.cpp:991
virtual XMLNode * ShallowClone(XMLDocument *document) const
Definition tinyxml2.cpp:974
virtual bool ShallowEqual(const XMLNode *compare) const
Definition tinyxml2.cpp:984
XMLElement * RootElement()
Definition tinyxml2.h:1421
void SetBOM(bool useBOM)
Definition tinyxml2.h:1414
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)
Definition tinyxml2.cpp:495
XMLError LoadFile(std::FILE *)
void Print(XMLPrinter *streamer=0)
XMLError LoadFile(const char *filename)
bool HasBOM() const
Definition tinyxml2.h:1409
bool Error() const
Return true if there was an error parsing the document.
Definition tinyxml2.h:1493
XMLComment * NewComment(const char *comment)
XMLElement * NewElement(const char *name)
XMLUnknown * NewUnknown(const char *text)
XMLError SaveFile(std::FILE *fp, bool compact=false)
const XMLElement * RootElement() const
Definition tinyxml2.h:1424
bool ProcessEntities() const
Definition tinyxml2.h:1399
virtual bool ShallowEqual(const XMLNode *) const
Definition tinyxml2.h:1517
XMLError SaveFile(const char *filename, bool compact=false)
Whitespace WhitespaceMode() const
Definition tinyxml2.h:1402
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition tinyxml2.h:1348
const char * GetErrorStr1() const
Return a possibly helpful diagnostic location or string.
Definition tinyxml2.h:1501
virtual bool Accept(XMLVisitor *visitor) const
Definition tinyxml2.cpp:570
void DeleteNode(XMLNode *node)
Definition tinyxml2.h:1486
friend class XMLElement
Definition tinyxml2.h:1342
virtual const XMLDocument * ToDocument() const
Definition tinyxml2.h:1351
const char * GetErrorStr2() const
Return a possibly helpful secondary diagnostic location or string.
Definition tinyxml2.h:1505
XMLText * NewText(const char *text)
void SetError(XMLError error, const char *str1, const char *str2)
XMLDeclaration * NewDeclaration(const char *text=0)
virtual XMLNode * ShallowClone(XMLDocument *) const
Definition tinyxml2.h:1514
XMLError ErrorID() const
Return the errorID.
Definition tinyxml2.h:1497
bool BoolAttribute(const char *name) const
See IntAttribute()
Definition tinyxml2.h:1122
XMLError QueryDoubleText(double *_value) const
See QueryIntText()
const char * GetText() const
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition tinyxml2.h:1194
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1169
const XMLAttribute * FindAttribute(const char *name) const
Query a specific attribute in the list.
XMLError QueryUnsignedText(unsigned *_value) const
See QueryIntText()
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
Definition tinyxml2.h:1214
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1161
unsigned UnsignedAttribute(const char *name) const
See IntAttribute()
Definition tinyxml2.h:1116
XMLError QueryFloatText(float *_value) const
See QueryIntText()
friend class XMLBase
Definition tinyxml2.h:1060
const char * Attribute(const char *name, const char *value=0) const
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
Definition tinyxml2.h:1225
XMLError QueryIntText(int *_value) const
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1177
virtual bool ShallowEqual(const XMLNode *compare) const
float FloatAttribute(const char *name) const
See IntAttribute()
Definition tinyxml2.h:1134
double DoubleAttribute(const char *name) const
See IntAttribute()
Definition tinyxml2.h:1128
XMLError QueryIntAttribute(const char *name, int *value) const
Definition tinyxml2.h:1153
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
Definition tinyxml2.h:1068
virtual const XMLElement * ToElement() const
Definition tinyxml2.h:1075
virtual bool Accept(XMLVisitor *visitor) const
XMLError QueryBoolText(bool *_value) const
See QueryIntText()
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
Definition tinyxml2.h:1209
char * ParseDeep(char *p, StrPair *endTag)
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
Definition tinyxml2.h:1199
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition tinyxml2.h:1072
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition tinyxml2.h:1064
int ClosingType() const
Definition tinyxml2.h:1303
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1185
int IntAttribute(const char *name) const
Definition tinyxml2.h:1110
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
Definition tinyxml2.h:1204
void DeleteAttribute(const char *name)
XMLHandle PreviousSiblingElement(const char *_value=0)
Get the previous sibling element of this handle.
Definition tinyxml2.h:1638
XMLHandle LastChildElement(const char *_value=0)
Get the last child element of this handle.
Definition tinyxml2.h:1630
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
Definition tinyxml2.h:1634
XMLHandle NextSiblingElement(const char *_value=0)
Get the next sibling element of this handle.
Definition tinyxml2.h:1646
XMLHandle FirstChild()
Get the first child of this handle.
Definition tinyxml2.h:1618
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
Definition tinyxml2.h:1651
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
Definition tinyxml2.h:1667
XMLHandle FirstChildElement(const char *value=0)
Get the first child element of this handle.
Definition tinyxml2.h:1622
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition tinyxml2.h:1600
XMLHandle LastChild()
Get the last child of this handle.
Definition tinyxml2.h:1626
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
Definition tinyxml2.h:1612
XMLHandle(XMLNode &node)
Create a handle from a node.
Definition tinyxml2.h:1604
XMLHandle NextSibling()
Get the next sibling of this handle.
Definition tinyxml2.h:1642
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition tinyxml2.h:1655
XMLText * ToText()
Safe cast to XMLText. This can return null.
Definition tinyxml2.h:1659
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
Definition tinyxml2.h:1663
XMLHandle(const XMLHandle &ref)
Copy constructor.
Definition tinyxml2.h:1608
const char * Value() const
Definition tinyxml2.h:591
virtual const XMLText * ToText() const
Definition tinyxml2.h:566
XMLNode * NextSibling()
Definition tinyxml2.h:671
XMLNode * _lastChild
Definition tinyxml2.h:766
void SetValue(const char *val, bool staticMem=false)
Definition tinyxml2.cpp:603
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition tinyxml2.h:543
const XMLElement * LastChildElement(const char *value=0) const
Definition tinyxml2.cpp:736
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition tinyxml2.h:555
XMLNode * _parent
Definition tinyxml2.h:762
XMLElement * NextSiblingElement(const char *value=0)
Definition tinyxml2.h:678
XMLNode * _next
Definition tinyxml2.h:769
void DeleteChild(XMLNode *node)
Definition tinyxml2.cpp:646
XMLNode * FirstChild()
Definition tinyxml2.h:619
const XMLElement * NextSiblingElement(const char *value=0) const
Get the next (right) sibling element of this node, with an opitionally supplied name.
Definition tinyxml2.cpp:750
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
Definition tinyxml2.h:534
const XMLNode * Parent() const
Get the parent of this node on the DOM.
Definition tinyxml2.h:601
friend class XMLDocument
Definition tinyxml2.h:525
const XMLElement * FirstChildElement(const char *value=0) const
Definition tinyxml2.cpp:722
XMLNode * LastChild()
Definition tinyxml2.h:637
XMLNode & operator=(const XMLNode &)
XMLNode * PreviousSibling()
Definition tinyxml2.h:655
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition tinyxml2.h:547
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition tinyxml2.h:551
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition tinyxml2.h:633
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition tinyxml2.h:530
virtual const XMLElement * ToElement() const
Definition tinyxml2.h:563
virtual char * ParseDeep(char *, StrPair *)
Definition tinyxml2.cpp:774
XMLNode(const XMLNode &)
virtual bool ShallowEqual(const XMLNode *compare) const =0
virtual bool Accept(XMLVisitor *visitor) const =0
XMLDocument * _document
Definition tinyxml2.h:761
virtual ~XMLNode()
Definition tinyxml2.cpp:594
virtual XMLNode * ShallowClone(XMLDocument *document) const =0
XMLNode * InsertAfterChild(XMLNode *afterThis, XMLNode *addThis)
Definition tinyxml2.cpp:700
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition tinyxml2.h:651
virtual const XMLDeclaration * ToDeclaration() const
Definition tinyxml2.h:575
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition tinyxml2.h:539
XMLNode * _prev
Definition tinyxml2.h:768
XMLNode * _firstChild
Definition tinyxml2.h:765
XMLElement * PreviousSiblingElement(const char *value=0)
Definition tinyxml2.h:662
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition tinyxml2.h:559
const XMLElement * PreviousSiblingElement(const char *value=0) const
Get the previous (left) sibling element of this node, with an opitionally supplied name.
Definition tinyxml2.cpp:762
virtual const XMLUnknown * ToUnknown() const
Definition tinyxml2.h:578
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition tinyxml2.h:615
friend class XMLElement
Definition tinyxml2.h:526
bool NoChildren() const
Returns true if this node has no children.
Definition tinyxml2.h:610
XMLNode * InsertFirstChild(XMLNode *addThis)
Definition tinyxml2.cpp:676
virtual const XMLDocument * ToDocument() const
Definition tinyxml2.h:572
XMLNode * Parent()
Definition tinyxml2.h:605
XMLNode * InsertEndChild(XMLNode *addThis)
Definition tinyxml2.cpp:653
XMLNode * LinkEndChild(XMLNode *addThis)
Definition tinyxml2.h:687
virtual const XMLComment * ToComment() const
Definition tinyxml2.h:569
XMLElement * LastChildElement(const char *value=0)
Definition tinyxml2.h:646
XMLElement * FirstChildElement(const char *value=0)
Definition tinyxml2.h:628
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition tinyxml2.h:667
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition tinyxml2.h:1834
void PushHeader(bool writeBOM, bool writeDeclaration)
void PushText(const char *text, bool cdata=false)
Add a text node.
void PushDeclaration(const char *value)
int CStrSize() const
Definition tinyxml2.h:1858
void PushAttribute(const char *name, const char *value)
If streaming, add an attribute to an open element.
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
void OpenElement(const char *name)
void PushUnknown(const char *value)
const char * CStr() const
Definition tinyxml2.h:1850
virtual bool Visit(const XMLText &text)
Visit a text node.
void CloseElement()
If streaming, close the Element.
void PushComment(const char *comment)
Add a comment.
XMLText(const XMLText &)
friend class XMLBase
Definition tinyxml2.h:791
virtual const XMLText * ToText() const
Definition tinyxml2.h:799
virtual bool Accept(XMLVisitor *visitor) const
Definition tinyxml2.cpp:897
virtual XMLNode * ShallowClone(XMLDocument *document) const
Definition tinyxml2.cpp:880
virtual bool ShallowEqual(const XMLNode *compare) const
Definition tinyxml2.cpp:891
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition tinyxml2.h:796
XMLText & operator=(const XMLText &)
char * ParseDeep(char *, StrPair *endTag)
Definition tinyxml2.cpp:852
bool CData() const
Returns true if this is a CDATA text element.
Definition tinyxml2.h:808
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
Definition tinyxml2.h:804
XMLText(XMLDocument *doc)
Definition tinyxml2.h:817
virtual ~XMLText()
Definition tinyxml2.h:818
char * ParseDeep(char *, StrPair *endTag)
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition tinyxml2.h:902
virtual bool Accept(XMLVisitor *visitor) const
XMLUnknown(const XMLUnknown &)
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual const XMLUnknown * ToUnknown() const
Definition tinyxml2.h:905
XMLUnknown & operator=(const XMLUnknown &)
virtual bool ShallowEqual(const XMLNode *compare) const
static int IsAlpha(unsigned char anyByte)
Definition tinyxml2.h:472
static const char * SkipWhiteSpace(const char *p)
Definition tinyxml2.h:435
static bool ToUnsigned(const char *str, unsigned *value)
Definition tinyxml2.cpp:451
static int IsUTF8Continuation(const char p)
Definition tinyxml2.h:466
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
Definition tinyxml2.cpp:289
static bool IsWhiteSpace(char p)
Definition tinyxml2.h:447
static bool ToFloat(const char *str, float *value)
Definition tinyxml2.cpp:478
static void ToStr(int v, char *buffer, int bufferSize)
Definition tinyxml2.cpp:413
static const char * GetCharacterRef(const char *p, char *value, int *length)
Definition tinyxml2.cpp:335
static char * SkipWhiteSpace(char *p)
Definition tinyxml2.h:441
static int IsAlphaNum(unsigned char anyByte)
Definition tinyxml2.h:469
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
Definition tinyxml2.h:451
static bool ToInt(const char *str, int *value)
Definition tinyxml2.cpp:443
static bool ToDouble(const char *str, double *value)
Definition tinyxml2.cpp:486
static bool ToBool(const char *str, bool *value)
Definition tinyxml2.cpp:459
static const char * ReadBOM(const char *p, bool *hasBOM)
Definition tinyxml2.cpp:274
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
Definition tinyxml2.h:421
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition tinyxml2.h:395
virtual ~XMLVisitor()
Definition tinyxml2.h:388
virtual bool VisitExit(const XMLElement &)
Visit an element.
Definition tinyxml2.h:404
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
Definition tinyxml2.h:391
virtual bool Visit(const XMLComment &)
Visit a comment node.
Definition tinyxml2.h:417
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
Definition tinyxml2.h:409
virtual bool Visit(const XMLText &)
Visit a text node.
Definition tinyxml2.h:413
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
Definition tinyxml2.h:400
@ XML_ERROR_MISMATCHED_ELEMENT
Definition tinyxml2.h:943
@ XML_ERROR_EMPTY_DOCUMENT
Definition tinyxml2.h:942
@ XML_SUCCESS
Definition tinyxml2.h:925
@ XML_ERROR_ELEMENT_MISMATCH
Definition tinyxml2.h:933
@ XML_ERROR_PARSING_ATTRIBUTE
Definition tinyxml2.h:935
@ XML_ERROR_FILE_NOT_FOUND
Definition tinyxml2.h:930
@ XML_ERROR_IDENTIFYING_TAG
Definition tinyxml2.h:936
@ XML_ERROR_PARSING_TEXT
Definition tinyxml2.h:937
@ XML_ERROR_PARSING_COMMENT
Definition tinyxml2.h:939
@ XML_NO_TEXT_NODE
Definition tinyxml2.h:947
@ XML_ERROR_FILE_READ_ERROR
Definition tinyxml2.h:932
@ XML_ERROR_PARSING_UNKNOWN
Definition tinyxml2.h:941
@ XML_ERROR_PARSING_CDATA
Definition tinyxml2.h:938
@ XML_NO_ATTRIBUTE
Definition tinyxml2.h:927
@ XML_NO_ERROR
Definition tinyxml2.h:924
@ XML_ERROR_PARSING_DECLARATION
Definition tinyxml2.h:940
@ XML_WRONG_ATTRIBUTE_TYPE
Definition tinyxml2.h:928
@ XML_ERROR_PARSING
Definition tinyxml2.h:944
@ XML_ERROR_PARSING_ELEMENT
Definition tinyxml2.h:934
@ XML_ERROR_FILE_COULD_NOT_BE_OPENED
Definition tinyxml2.h:931
@ XML_CAN_NOT_CONVERT_TEXT
Definition tinyxml2.h:946
@ PRESERVE_WHITESPACE
Definition tinyxml2.h:1330
@ COLLAPSE_WHITESPACE
Definition tinyxml2.h:1331
#define TIXMLASSERT(x)
Definition tinyxml2.h:66
#define TIXML_SNPRINTF
Definition tinyxml2.h:91