TinyXML-2: tinyxml2.h Source File

TinyXML-2 5.0.1

tinyxml2.h
1 /*
2 Original code by Lee Thomason (www.grinninglizard.com)
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any
6 damages arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any
9 purpose, including commercial applications, and to alter it and
10 redistribute it freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must
13 not claim that you wrote the original software. If you use this
14 software in a product, an acknowledgment in the product documentation
15 would be appreciated but is not required.
16
17 2. Altered source versions must be plainly marked as such, and
18 must not be misrepresented as being the original software.
19
20 3. This notice may not be removed or altered from any source
21 distribution.
22 */
23
24 #ifndef TINYXML2_INCLUDED
25 #define TINYXML2_INCLUDED
26
27 #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
28 # include <ctype.h>
29 # include <limits.h>
30 # include <stdio.h>
31 # include <stdlib.h>
32 # include <string.h>
33 # if defined(__PS3__)
34 # include <stddef.h>
35 # endif
36 #else
37 # include <cctype>
38 # include <climits>
39 # include <cstdio>
40 # include <cstdlib>
41 # include <cstring>
42 #endif
43 #include <stdint.h>
44
45 /*
46 TODO: intern strings instead of allocation.
47 */
48 /*
49 gcc:
50 g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
51
52 Formatting, Artistic Style:
53 AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
54 */
55
56 #if defined( _DEBUG ) || defined (__DEBUG__)
57 # ifndef DEBUG
58 # define DEBUG
59 # endif
60 #endif
61
62 #ifdef _MSC_VER
63 # pragma warning(push)
64 # pragma warning(disable: 4251)
65 #endif
66
67 #ifdef _WIN32
68 # ifdef TINYXML2_EXPORT
69 # define TINYXML2_LIB __declspec(dllexport)
70 # elif defined(TINYXML2_IMPORT)
71 # define TINYXML2_LIB __declspec(dllimport)
72 # else
73 # define TINYXML2_LIB
74 # endif
75 #elif __GNUC__ >= 4
76 # define TINYXML2_LIB __attribute__((visibility("default")))
77 #else
78 # define TINYXML2_LIB
79 #endif
80
81
82 #if defined(DEBUG)
83 # if defined(_MSC_VER)
84 # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
85 # define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); }
86 # elif defined (ANDROID_NDK)
87 # include <android/log.h>
88 # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
89 # else
90 # include <assert.h>
91 # define TIXMLASSERT assert
92 # endif
93 #else
94 # define TIXMLASSERT( x ) {}
95 #endif
96
97
98 /* Versioning, past 1.0.14:
99 http://semver.org/
100 */
101 static const int TIXML2_MAJOR_VERSION = 5;
102 static const int TIXML2_MINOR_VERSION = 0;
103 static const int TIXML2_PATCH_VERSION = 1;
104
105 namespace tinyxml2
106 {
107 class XMLDocument;
108 class XMLElement;
109 class XMLAttribute;
110 class XMLComment;
111 class XMLText;
112 class XMLDeclaration;
113 class XMLUnknown;
114 class XMLPrinter;
115
116 /*
117 A class that wraps strings. Normally stores the start and end
118 pointers into the XML file itself, and will apply normalization
119 and entity translation if actually read. Can also store (and memory
120 manage) a traditional char[]
121 */
122 class StrPair
123 {
124 public:
125 enum {
126 NEEDS_ENTITY_PROCESSING = 0x01,
127 NEEDS_NEWLINE_NORMALIZATION = 0x02,
128 NEEDS_WHITESPACE_COLLAPSING = 0x04,
129
130 TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
131 TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
132 ATTRIBUTE_NAME = 0,
133 ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
134 ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
135 COMMENT = NEEDS_NEWLINE_NORMALIZATION
136 };
137
138 StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
139 ~StrPair();
140
141 void Set( char* start, char* end, int flags ) {
142 TIXMLASSERT( start );
143 TIXMLASSERT( end );
144 Reset();
145 _start = start;
146 _end = end;
147 _flags = flags | NEEDS_FLUSH;
148 }
149
150 const char* GetStr();
151
152 bool Empty() const {
153 return _start == _end;
154 }
155
156 void SetInternedStr( const char* str ) {
157 Reset();
158 _start = const_cast<char*>(str);
159 }
160
161 void SetStr( const char* str, int flags=0 );
162
163 char* ParseText( char* in, const char* endTag, int strFlags, int* curLineNumPtr );
164 char* ParseName( char* in );
165
166 void TransferTo( StrPair* other );
167 void Reset();
168
169 private:
170 void CollapseWhitespace();
171
172 enum {
173 NEEDS_FLUSH = 0x100,
174 NEEDS_DELETE = 0x200
175 };
176
177 int _flags;
178 char* _start;
179 char* _end;
180
181 StrPair( const StrPair& other ); // not supported
182 void operator=( StrPair& other ); // not supported, use TransferTo()
183 };
184
185
186 /*
187 A dynamic array of Plain Old Data. Doesn't support constructors, etc.
188 Has a small initial memory pool, so that low or no usage will not
189 cause a call to new/delete
190 */
191 template <class T, int INITIAL_SIZE>
192 class DynArray
193 {
194 public:
195 DynArray() {
196 _mem = _pool;
197 _allocated = INITIAL_SIZE;
198 _size = 0;
199 }
200
201 ~DynArray() {
202 if ( _mem != _pool ) {
203 delete [] _mem;
204 }
205 }
206
207 void Clear() {
208 _size = 0;
209 }
210
211 void Push( T t ) {
212 TIXMLASSERT( _size < INT_MAX );
213 EnsureCapacity( _size+1 );
214 _mem[_size] = t;
215 ++_size;
216 }
217
218 T* PushArr( int count ) {
219 TIXMLASSERT( count >= 0 );
220 TIXMLASSERT( _size <= INT_MAX - count );
221 EnsureCapacity( _size+count );
222 T* ret = &_mem[_size];
223 _size += count;
224 return ret;
225 }
226
227 T Pop() {
228 TIXMLASSERT( _size > 0 );
229 --_size;
230 return _mem[_size];
231 }
232
233 void PopArr( int count ) {
234 TIXMLASSERT( _size >= count );
235 _size -= count;
236 }
237
238 bool Empty() const {
239 return _size == 0;
240 }
241
242 T& operator[](int i) {
243 TIXMLASSERT( i>= 0 && i < _size );
244 return _mem[i];
245 }
246
247 const T& operator[](int i) const {
248 TIXMLASSERT( i>= 0 && i < _size );
249 return _mem[i];
250 }
251
252 const T& PeekTop() const {
253 TIXMLASSERT( _size > 0 );
254 return _mem[ _size - 1];
255 }
256
257 int Size() const {
258 TIXMLASSERT( _size >= 0 );
259 return _size;
260 }
261
262 int Capacity() const {
263 TIXMLASSERT( _allocated >= INITIAL_SIZE );
264 return _allocated;
265 }
266
267 void SwapRemove(int i) {
268 TIXMLASSERT(i >= 0 && i < _size);
269 TIXMLASSERT(_size > 0);
270 _mem[i] = _mem[_size - 1];
271 --_size;
272 }
273
274 const T* Mem() const {
275 TIXMLASSERT( _mem );
276 return _mem;
277 }
278
279 T* Mem() {
280 TIXMLASSERT( _mem );
281 return _mem;
282 }
283
284 private:
285 DynArray( const DynArray& ); // not supported
286 void operator=( const DynArray& ); // not supported
287
288 void EnsureCapacity( int cap ) {
289 TIXMLASSERT( cap > 0 );
290 if ( cap > _allocated ) {
291 TIXMLASSERT( cap <= INT_MAX / 2 );
292 int newAllocated = cap * 2;
293 T* newMem = new T[newAllocated];
294 TIXMLASSERT( newAllocated >= _size );
295 memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
296 if ( _mem != _pool ) {
297 delete [] _mem;
298 }
299 _mem = newMem;
300 _allocated = newAllocated;
301 }
302 }
303
304 T* _mem;
305 T _pool[INITIAL_SIZE];
306 int _allocated; // objects allocated
307 int _size; // number objects in use
308 };
309
310
311 /*
312 Parent virtual class of a pool for fast allocation
313 and deallocation of objects.
314 */
315 class MemPool
316 {
317 public:
318 MemPool() {}
319 virtual ~MemPool() {}
320
321 virtual int ItemSize() const = 0;
322 virtual void* Alloc() = 0;
323 virtual void Free( void* ) = 0;
324 virtual void SetTracked() = 0;
325 virtual void Clear() = 0;
326 };
327
328
329 /*
330 Template child class to create pools of the correct type.
331 */
332 template< int ITEM_SIZE >
333 class MemPoolT : public MemPool
334 {
335 public:
336 MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
337 ~MemPoolT() {
338 Clear();
339 }
340
341 void Clear() {
342 // Delete the blocks.
343 while( !_blockPtrs.Empty()) {
344 Block* b = _blockPtrs.Pop();
345 delete b;
346 }
347 _root = 0;
348 _currentAllocs = 0;
349 _nAllocs = 0;
350 _maxAllocs = 0;
351 _nUntracked = 0;
352 }
353
354 virtual int ItemSize() const {
355 return ITEM_SIZE;
356 }
357 int CurrentAllocs() const {
358 return _currentAllocs;
359 }
360
361 virtual void* Alloc() {
362 if ( !_root ) {
363 // Need a new block.
364 Block* block = new Block();
365 _blockPtrs.Push( block );
366
367 Item* blockItems = block->items;
368 for( int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
369 blockItems[i].next = &(blockItems[i + 1]);
370 }
371 blockItems[ITEMS_PER_BLOCK - 1].next = 0;
372 _root = blockItems;
373 }
374 Item* const result = _root;
375 TIXMLASSERT( result != 0 );
376 _root = _root->next;
377
378 ++_currentAllocs;
379 if ( _currentAllocs > _maxAllocs ) {
380 _maxAllocs = _currentAllocs;
381 }
382 ++_nAllocs;
383 ++_nUntracked;
384 return result;
385 }
386
387 virtual void Free( void* mem ) {
388 if ( !mem ) {
389 return;
390 }
391 --_currentAllocs;
392 Item* item = static_cast<Item*>( mem );
393 #ifdef DEBUG
394 memset( item, 0xfe, sizeof( *item ) );
395 #endif
396 item->next = _root;
397 _root = item;
398 }
399 void Trace( const char* name ) {
400 printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
401 name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs,
402 ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
403 }
404
405 void SetTracked() {
406 --_nUntracked;
407 }
408
409 int Untracked() const {
410 return _nUntracked;
411 }
412
413 // This number is perf sensitive. 4k seems like a good tradeoff on my machine.
414 // The test file is large, 170k.
415 // Release: VS2010 gcc(no opt)
416 // 1k: 4000
417 // 2k: 4000
418 // 4k: 3900 21000
419 // 16k: 5200
420 // 32k: 4300
421 // 64k: 4000 21000
422 // Declared public because some compilers do not accept to use ITEMS_PER_BLOCK
423 // in private part if ITEMS_PER_BLOCK is private
424 enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE };
425
426 private:
427 MemPoolT( const MemPoolT& ); // not supported
428 void operator=( const MemPoolT& ); // not supported
429
430 union Item {
431 Item* next;
432 char itemData[ITEM_SIZE];
433 };
434 struct Block {
435 Item items[ITEMS_PER_BLOCK];
436 };
437 DynArray< Block*, 10 > _blockPtrs;
438 Item* _root;
439
440 int _currentAllocs;
441 int _nAllocs;
442 int _maxAllocs;
443 int _nUntracked;
444 };
445
446
447
467 class TINYXML2_LIB XMLVisitor
468 {
469 public:
470 virtual ~XMLVisitor() {}
471
473 virtual bool VisitEnter( const XMLDocument& /*doc*/ ) {
474 return true;
475 }
477 virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
478 return true;
479 }
480
482 virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) {
483 return true;
484 }
486 virtual bool VisitExit( const XMLElement& /*element*/ ) {
487 return true;
488 }
489
491 virtual bool Visit( const XMLDeclaration& /*declaration*/ ) {
492 return true;
493 }
495 virtual bool Visit( const XMLText& /*text*/ ) {
496 return true;
497 }
499 virtual bool Visit( const XMLComment& /*comment*/ ) {
500 return true;
501 }
503 virtual bool Visit( const XMLUnknown& /*unknown*/ ) {
504 return true;
505 }
506 };
507
508 // WARNING: must match XMLDocument::_errorNames[]
509 enum XMLError {
510 XML_SUCCESS = 0,
511 XML_NO_ATTRIBUTE,
512 XML_WRONG_ATTRIBUTE_TYPE,
513 XML_ERROR_FILE_NOT_FOUND,
514 XML_ERROR_FILE_COULD_NOT_BE_OPENED,
515 XML_ERROR_FILE_READ_ERROR,
516 UNUSED_XML_ERROR_ELEMENT_MISMATCH, // remove at next major version
517 XML_ERROR_PARSING_ELEMENT,
518 XML_ERROR_PARSING_ATTRIBUTE,
519 UNUSED_XML_ERROR_IDENTIFYING_TAG, // remove at next major version
520 XML_ERROR_PARSING_TEXT,
521 XML_ERROR_PARSING_CDATA,
522 XML_ERROR_PARSING_COMMENT,
523 XML_ERROR_PARSING_DECLARATION,
524 XML_ERROR_PARSING_UNKNOWN,
525 XML_ERROR_EMPTY_DOCUMENT,
526 XML_ERROR_MISMATCHED_ELEMENT,
527 XML_ERROR_PARSING,
528 XML_CAN_NOT_CONVERT_TEXT,
529 XML_NO_TEXT_NODE,
530
531 XML_ERROR_COUNT
532 };
533
534
535 /*
536 Utility functionality.
537 */
538 class TINYXML2_LIB XMLUtil
539 {
540 public:
541 static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) {
542 TIXMLASSERT( p );
543
544 while( IsWhiteSpace(*p) ) {
545 if (curLineNumPtr && *p == '\n') {
546 ++(*curLineNumPtr);
547 }
548 ++p;
549 }
550 TIXMLASSERT( p );
551 return p;
552 }
553 static char* SkipWhiteSpace( char* p, int* curLineNumPtr ) {
554 return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p), curLineNumPtr ) );
555 }
556
557 // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
558 // correct, but simple, and usually works.
559 static bool IsWhiteSpace( char p ) {
560 return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
561 }
562
563 inline static bool IsNameStartChar( unsigned char ch ) {
564 if ( ch >= 128 ) {
565 // This is a heuristic guess in attempt to not implement Unicode-aware isalpha()
566 return true;
567 }
568 if ( isalpha( ch ) ) {
569 return true;
570 }
571 return ch == ':' || ch == '_';
572 }
573
574 inline static bool IsNameChar( unsigned char ch ) {
575 return IsNameStartChar( ch )
576 || isdigit( ch )
577 || ch == '.'
578 || ch == '-';
579 }
580
581 inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
582 if ( p == q ) {
583 return true;
584 }
585 TIXMLASSERT( p );
586 TIXMLASSERT( q );
587 TIXMLASSERT( nChar >= 0 );
588 return strncmp( p, q, nChar ) == 0;
589 }
590
591 inline static bool IsUTF8Continuation( char p ) {
592 return ( p & 0x80 ) != 0;
593 }
594
595 static const char* ReadBOM( const char* p, bool* hasBOM );
596 // p is the starting location,
597 // the UTF-8 value of the entity will be placed in value, and length filled in.
598 static const char* GetCharacterRef( const char* p, char* value, int* length );
599 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
600
601 // converts primitive types to strings
602 static void ToStr( int v, char* buffer, int bufferSize );
603 static void ToStr( unsigned v, char* buffer, int bufferSize );
604 static void ToStr( bool v, char* buffer, int bufferSize );
605 static void ToStr( float v, char* buffer, int bufferSize );
606 static void ToStr( double v, char* buffer, int bufferSize );
607 static void ToStr(int64_t v, char* buffer, int bufferSize);
608
609 // converts strings to primitive types
610 static bool ToInt( const char* str, int* value );
611 static bool ToUnsigned( const char* str, unsigned* value );
612 static bool ToBool( const char* str, bool* value );
613 static bool ToFloat( const char* str, float* value );
614 static bool ToDouble( const char* str, double* value );
615 static bool ToInt64(const char* str, int64_t* value);
616
617 // Changes what is serialized for a boolean value.
618 // Default to "true" and "false". Shouldn't be changed
619 // unless you have a special testing or compatibility need.
620 // Be careful: static, global, & not thread safe.
621 // Be sure to set static const memory as parameters.
622 static void SetBoolSerialization(const char* writeTrue, const char* writeFalse);
623
624 private:
625 static const char* writeBoolTrue;
626 static const char* writeBoolFalse;
627 };
628
629
655 class TINYXML2_LIB XMLNode
656 {
657 friend class XMLDocument;
658 friend class XMLElement;
659 public:
660
662 const XMLDocument* GetDocument() const {
663 TIXMLASSERT( _document );
664 return _document;
665 }
667 XMLDocument* GetDocument() {
668 TIXMLASSERT( _document );
669 return _document;
670 }
671
673 virtual XMLElement* ToElement() {
674 return 0;
675 }
677 virtual XMLText* ToText() {
678 return 0;
679 }
681 virtual XMLComment* ToComment() {
682 return 0;
683 }
685 virtual XMLDocument* ToDocument() {
686 return 0;
687 }
689 virtual XMLDeclaration* ToDeclaration() {
690 return 0;
691 }
693 virtual XMLUnknown* ToUnknown() {
694 return 0;
695 }
696
697 virtual const XMLElement* ToElement() const {
698 return 0;
699 }
700 virtual const XMLText* ToText() const {
701 return 0;
702 }
703 virtual const XMLComment* ToComment() const {
704 return 0;
705 }
706 virtual const XMLDocument* ToDocument() const {
707 return 0;
708 }
709 virtual const XMLDeclaration* ToDeclaration() const {
710 return 0;
711 }
712 virtual const XMLUnknown* ToUnknown() const {
713 return 0;
714 }
715
725 const char* Value() const;
726
730 void SetValue( const char* val, bool staticMem=false );
731
733 int GetLineNum() const { return _parseLineNum; }
734
736 const XMLNode* Parent() const {
737 return _parent;
738 }
739
740 XMLNode* Parent() {
741 return _parent;
742 }
743
745 bool NoChildren() const {
746 return !_firstChild;
747 }
748
750 const XMLNode* FirstChild() const {
751 return _firstChild;
752 }
753
754 XMLNode* FirstChild() {
755 return _firstChild;
756 }
757
761 const XMLElement* FirstChildElement( const char* name = 0 ) const;
762
763 XMLElement* FirstChildElement( const char* name = 0 ) {
764 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name ));
765 }
766
768 const XMLNode* LastChild() const {
769 return _lastChild;
770 }
771
772 XMLNode* LastChild() {
773 return _lastChild;
774 }
775
779 const XMLElement* LastChildElement( const char* name = 0 ) const;
780
781 XMLElement* LastChildElement( const char* name = 0 ) {
782 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) );
783 }
784
786 const XMLNode* PreviousSibling() const {
787 return _prev;
788 }
789
790 XMLNode* PreviousSibling() {
791 return _prev;
792 }
793
795 const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ;
796
797 XMLElement* PreviousSiblingElement( const char* name = 0 ) {
798 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) );
799 }
800
802 const XMLNode* NextSibling() const {
803 return _next;
804 }
805
806 XMLNode* NextSibling() {
807 return _next;
808 }
809
811 const XMLElement* NextSiblingElement( const char* name = 0 ) const;
812
813 XMLElement* NextSiblingElement( const char* name = 0 ) {
814 return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) );
815 }
816
824 XMLNode* InsertEndChild( XMLNode* addThis );
825
826 XMLNode* LinkEndChild( XMLNode* addThis ) {
827 return InsertEndChild( addThis );
828 }
836 XMLNode* InsertFirstChild( XMLNode* addThis );
845 XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
846
850 void DeleteChildren();
851
855 void DeleteChild( XMLNode* node );
856
866 virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
867
881 XMLNode* DeepClone( XMLDocument* target ) const;
882
889 virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
890
913 virtual bool Accept( XMLVisitor* visitor ) const = 0;
914
920 void SetUserData(void* userData) { _userData = userData; }
921
927 void* GetUserData() const { return _userData; }
928
929 protected:
930 XMLNode( XMLDocument* );
931 virtual ~XMLNode();
932
933 virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
934
935 XMLDocument* _document;
936 XMLNode* _parent;
937 mutable StrPair _value;
938 int _parseLineNum;
939
940 XMLNode* _firstChild;
941 XMLNode* _lastChild;
942
943 XMLNode* _prev;
944 XMLNode* _next;
945
946 void* _userData;
947
948 private:
949 MemPool* _memPool;
950 void Unlink( XMLNode* child );
951 static void DeleteNode( XMLNode* node );
952 void InsertChildPreamble( XMLNode* insertThis ) const;
953 const XMLElement* ToElementWithName( const char* name ) const;
954
955 XMLNode( const XMLNode& ); // not supported
956 XMLNode& operator=( const XMLNode& ); // not supported
957 };
958
959
972 class TINYXML2_LIB XMLText : public XMLNode
973 {
974 friend class XMLDocument;
975 public:
976 virtual bool Accept( XMLVisitor* visitor ) const;
977
978 virtual XMLText* ToText() {
979 return this;
980 }
981 virtual const XMLText* ToText() const {
982 return this;
983 }
984
986 void SetCData( bool isCData ) {
987 _isCData = isCData;
988 }
990 bool CData() const {
991 return _isCData;
992 }
993
994 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
995 virtual bool ShallowEqual( const XMLNode* compare ) const;
996
997 protected:
998 XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
999 virtual ~XMLText() {}
1000
1001 char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1002
1003 private:
1004 bool _isCData;
1005
1006 XMLText( const XMLText& ); // not supported
1007 XMLText& operator=( const XMLText& ); // not supported
1008 };
1009
1010
1012 class TINYXML2_LIB XMLComment : public XMLNode
1013 {
1014 friend class XMLDocument;
1015 public:
1016 virtual XMLComment* ToComment() {
1017 return this;
1018 }
1019 virtual const XMLComment* ToComment() const {
1020 return this;
1021 }
1022
1023 virtual bool Accept( XMLVisitor* visitor ) const;
1024
1025 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1026 virtual bool ShallowEqual( const XMLNode* compare ) const;
1027
1028 protected:
1029 XMLComment( XMLDocument* doc );
1030 virtual ~XMLComment();
1031
1032 char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
1033
1034 private:
1035 XMLComment( const XMLComment& ); // not supported
1036 XMLComment& operator=( const XMLComment& ); // not supported
1037 };
1038
1039
1051 class TINYXML2_LIB XMLDeclaration : public XMLNode
1052 {
1053 friend class XMLDocument;
1054 public:
1055 virtual XMLDeclaration* ToDeclaration() {
1056 return this;
1057 }
1058 virtual const XMLDeclaration* ToDeclaration() const {
1059 return this;
1060 }
1061
1062 virtual bool Accept( XMLVisitor* visitor ) const;
1063
1064 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1065 virtual bool ShallowEqual( const XMLNode* compare ) const;
1066
1067 protected:
1068 XMLDeclaration( XMLDocument* doc );
1069 virtual ~XMLDeclaration();
1070
1071 char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1072
1073 private:
1074 XMLDeclaration( const XMLDeclaration& ); // not supported
1075 XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
1076 };
1077
1078
1086 class TINYXML2_LIB XMLUnknown : public XMLNode
1087 {
1088 friend class XMLDocument;
1089 public:
1090 virtual XMLUnknown* ToUnknown() {
1091 return this;
1092 }
1093 virtual const XMLUnknown* ToUnknown() const {
1094 return this;
1095 }
1096
1097 virtual bool Accept( XMLVisitor* visitor ) const;
1098
1099 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1100 virtual bool ShallowEqual( const XMLNode* compare ) const;
1101
1102 protected:
1103 XMLUnknown( XMLDocument* doc );
1104 virtual ~XMLUnknown();
1105
1106 char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1107
1108 private:
1109 XMLUnknown( const XMLUnknown& ); // not supported
1110 XMLUnknown& operator=( const XMLUnknown& ); // not supported
1111 };
1112
1113
1114
1121 class TINYXML2_LIB XMLAttribute
1122 {
1123 friend class XMLElement;
1124 public:
1126 const char* Name() const;
1127
1129 const char* Value() const;
1130
1132 int GetLineNum() const { return _parseLineNum; }
1133
1135 const XMLAttribute* Next() const {
1136 return _next;
1137 }
1138
1143 int IntValue() const {
1144 int i = 0;
1145 QueryIntValue(&i);
1146 return i;
1147 }
1148
1149 int64_t Int64Value() const {
1150 int64_t i = 0;
1151 QueryInt64Value(&i);
1152 return i;
1153 }
1154
1156 unsigned UnsignedValue() const {
1157 unsigned i=0;
1158 QueryUnsignedValue( &i );
1159 return i;
1160 }
1162 bool BoolValue() const {
1163 bool b=false;
1164 QueryBoolValue( &b );
1165 return b;
1166 }
1168 double DoubleValue() const {
1169 double d=0;
1170 QueryDoubleValue( &d );
1171 return d;
1172 }
1174 float FloatValue() const {
1175 float f=0;
1176 QueryFloatValue( &f );
1177 return f;
1178 }
1179
1184 XMLError QueryIntValue( int* value ) const;
1186 XMLError QueryUnsignedValue( unsigned int* value ) const;
1188 XMLError QueryInt64Value(int64_t* value) const;
1190 XMLError QueryBoolValue( bool* value ) const;
1192 XMLError QueryDoubleValue( double* value ) const;
1194 XMLError QueryFloatValue( float* value ) const;
1195
1197 void SetAttribute( const char* value );
1199 void SetAttribute( int value );
1201 void SetAttribute( unsigned value );
1203 void SetAttribute(int64_t value);
1205 void SetAttribute( bool value );
1207 void SetAttribute( double value );
1209 void SetAttribute( float value );
1210
1211 private:
1212 enum { BUF_SIZE = 200 };
1213
1214 XMLAttribute() : _parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
1215 virtual ~XMLAttribute() {}
1216
1217 XMLAttribute( const XMLAttribute& ); // not supported
1218 void operator=( const XMLAttribute& ); // not supported
1219 void SetName( const char* name );
1220
1221 char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr );
1222
1223 mutable StrPair _name;
1224 mutable StrPair _value;
1225 int _parseLineNum;
1226 XMLAttribute* _next;
1227 MemPool* _memPool;
1228 };
1229
1230
1235 class TINYXML2_LIB XMLElement : public XMLNode
1236 {
1237 friend class XMLDocument;
1238 public:
1240 const char* Name() const {
1241 return Value();
1242 }
1244 void SetName( const char* str, bool staticMem=false ) {
1245 SetValue( str, staticMem );
1246 }
1247
1248 virtual XMLElement* ToElement() {
1249 return this;
1250 }
1251 virtual const XMLElement* ToElement() const {
1252 return this;
1253 }
1254 virtual bool Accept( XMLVisitor* visitor ) const;
1255
1279 const char* Attribute( const char* name, const char* value=0 ) const;
1280
1287 int IntAttribute(const char* name, int defaultValue = 0) const;
1289 unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const;
1291 int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const;
1293 bool BoolAttribute(const char* name, bool defaultValue = false) const;
1295 double DoubleAttribute(const char* name, double defaultValue = 0) const;
1297 float FloatAttribute(const char* name, float defaultValue = 0) const;
1298
1312 XMLError QueryIntAttribute( const char* name, int* value ) const {
1313 const XMLAttribute* a = FindAttribute( name );
1314 if ( !a ) {
1315 return XML_NO_ATTRIBUTE;
1316 }
1317 return a->QueryIntValue( value );
1318 }
1319
1321 XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
1322 const XMLAttribute* a = FindAttribute( name );
1323 if ( !a ) {
1324 return XML_NO_ATTRIBUTE;
1325 }
1326 return a->QueryUnsignedValue( value );
1327 }
1328
1330 XMLError QueryInt64Attribute(const char* name, int64_t* value) const {
1331 const XMLAttribute* a = FindAttribute(name);
1332 if (!a) {
1333 return XML_NO_ATTRIBUTE;
1334 }
1335 return a->QueryInt64Value(value);
1336 }
1337
1339 XMLError QueryBoolAttribute( const char* name, bool* value ) const {
1340 const XMLAttribute* a = FindAttribute( name );
1341 if ( !a ) {
1342 return XML_NO_ATTRIBUTE;
1343 }
1344 return a->QueryBoolValue( value );
1345 }
1347 XMLError QueryDoubleAttribute( const char* name, double* value ) const {
1348 const XMLAttribute* a = FindAttribute( name );
1349 if ( !a ) {
1350 return XML_NO_ATTRIBUTE;
1351 }
1352 return a->QueryDoubleValue( value );
1353 }
1355 XMLError QueryFloatAttribute( const char* name, float* value ) const {
1356 const XMLAttribute* a = FindAttribute( name );
1357 if ( !a ) {
1358 return XML_NO_ATTRIBUTE;
1359 }
1360 return a->QueryFloatValue( value );
1361 }
1362
1363
1381 int QueryAttribute( const char* name, int* value ) const {
1382 return QueryIntAttribute( name, value );
1383 }
1384
1385 int QueryAttribute( const char* name, unsigned int* value ) const {
1386 return QueryUnsignedAttribute( name, value );
1387 }
1388
1389 int QueryAttribute(const char* name, int64_t* value) const {
1390 return QueryInt64Attribute(name, value);
1391 }
1392
1393 int QueryAttribute( const char* name, bool* value ) const {
1394 return QueryBoolAttribute( name, value );
1395 }
1396
1397 int QueryAttribute( const char* name, double* value ) const {
1398 return QueryDoubleAttribute( name, value );
1399 }
1400
1401 int QueryAttribute( const char* name, float* value ) const {
1402 return QueryFloatAttribute( name, value );
1403 }
1404
1406 void SetAttribute( const char* name, const char* value ) {
1407 XMLAttribute* a = FindOrCreateAttribute( name );
1408 a->SetAttribute( value );
1409 }
1411 void SetAttribute( const char* name, int value ) {
1412 XMLAttribute* a = FindOrCreateAttribute( name );
1413 a->SetAttribute( value );
1414 }
1416 void SetAttribute( const char* name, unsigned value ) {
1417 XMLAttribute* a = FindOrCreateAttribute( name );
1418 a->SetAttribute( value );
1419 }
1420
1422 void SetAttribute(const char* name, int64_t value) {
1423 XMLAttribute* a = FindOrCreateAttribute(name);
1424 a->SetAttribute(value);
1425 }
1426
1428 void SetAttribute( const char* name, bool value ) {
1429 XMLAttribute* a = FindOrCreateAttribute( name );
1430 a->SetAttribute( value );
1431 }
1433 void SetAttribute( const char* name, double value ) {
1434 XMLAttribute* a = FindOrCreateAttribute( name );
1435 a->SetAttribute( value );
1436 }
1438 void SetAttribute( const char* name, float value ) {
1439 XMLAttribute* a = FindOrCreateAttribute( name );
1440 a->SetAttribute( value );
1441 }
1442
1446 void DeleteAttribute( const char* name );
1447
1449 const XMLAttribute* FirstAttribute() const {
1450 return _rootAttribute;
1451 }
1453 const XMLAttribute* FindAttribute( const char* name ) const;
1454
1483 const char* GetText() const;
1484
1519 void SetText( const char* inText );
1521 void SetText( int value );
1523 void SetText( unsigned value );
1525 void SetText(int64_t value);
1527 void SetText( bool value );
1529 void SetText( double value );
1531 void SetText( float value );
1532
1559 XMLError QueryIntText( int* ival ) const;
1561 XMLError QueryUnsignedText( unsigned* uval ) const;
1563 XMLError QueryInt64Text(int64_t* uval) const;
1565 XMLError QueryBoolText( bool* bval ) const;
1567 XMLError QueryDoubleText( double* dval ) const;
1569 XMLError QueryFloatText( float* fval ) const;
1570
1571 int IntText(int defaultValue = 0) const;
1572
1574 unsigned UnsignedText(unsigned defaultValue = 0) const;
1576 int64_t Int64Text(int64_t defaultValue = 0) const;
1578 bool BoolText(bool defaultValue = false) const;
1580 double DoubleText(double defaultValue = 0) const;
1582 float FloatText(float defaultValue = 0) const;
1583
1584 // internal:
1585 enum ElementClosingType {
1586 OPEN, // <foo>
1587 CLOSED, // <foo/>
1588 CLOSING // </foo>
1589 };
1590 ElementClosingType ClosingType() const {
1591 return _closingType;
1592 }
1593 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1594 virtual bool ShallowEqual( const XMLNode* compare ) const;
1595
1596 protected:
1597 char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1598
1599 private:
1600 XMLElement( XMLDocument* doc );
1601 virtual ~XMLElement();
1602 XMLElement( const XMLElement& ); // not supported
1603 void operator=( const XMLElement& ); // not supported
1604
1605 XMLAttribute* FindAttribute( const char* name ) {
1606 return const_cast<XMLAttribute*>(const_cast<const XMLElement*>(this)->FindAttribute( name ));
1607 }
1608 XMLAttribute* FindOrCreateAttribute( const char* name );
1609 //void LinkAttribute( XMLAttribute* attrib );
1610 char* ParseAttributes( char* p, int* curLineNumPtr );
1611 static void DeleteAttribute( XMLAttribute* attribute );
1612 XMLAttribute* CreateAttribute();
1613
1614 enum { BUF_SIZE = 200 };
1615 ElementClosingType _closingType;
1616 // The attribute list is ordered; there is no 'lastAttribute'
1617 // because the list needs to be scanned for dupes before adding
1618 // a new attribute.
1619 XMLAttribute* _rootAttribute;
1620 };
1621
1622
1623 enum Whitespace {
1624 PRESERVE_WHITESPACE,
1625 COLLAPSE_WHITESPACE
1626 };
1627
1628
1634 class TINYXML2_LIB XMLDocument : public XMLNode
1635 {
1636 friend class XMLElement;
1637 public:
1639 XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
1640 ~XMLDocument();
1641
1642 virtual XMLDocument* ToDocument() {
1643 TIXMLASSERT( this == _document );
1644 return this;
1645 }
1646 virtual const XMLDocument* ToDocument() const {
1647 TIXMLASSERT( this == _document );
1648 return this;
1649 }
1650
1661 XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) );
1662
1668 XMLError LoadFile( const char* filename );
1669
1681 XMLError LoadFile( FILE* );
1682
1688 XMLError SaveFile( const char* filename, bool compact = false );
1689
1697 XMLError SaveFile( FILE* fp, bool compact = false );
1698
1699 bool ProcessEntities() const {
1700 return _processEntities;
1701 }
1702 Whitespace WhitespaceMode() const {
1703 return _whitespaceMode;
1704 }
1705
1709 bool HasBOM() const {
1710 return _writeBOM;
1711 }
1714 void SetBOM( bool useBOM ) {
1715 _writeBOM = useBOM;
1716 }
1717
1721 XMLElement* RootElement() {
1722 return FirstChildElement();
1723 }
1724 const XMLElement* RootElement() const {
1725 return FirstChildElement();
1726 }
1727
1742 void Print( XMLPrinter* streamer=0 ) const;
1743 virtual bool Accept( XMLVisitor* visitor ) const;
1744
1750 XMLElement* NewElement( const char* name );
1756 XMLComment* NewComment( const char* comment );
1762 XMLText* NewText( const char* text );
1774 XMLDeclaration* NewDeclaration( const char* text=0 );
1780 XMLUnknown* NewUnknown( const char* text );
1781
1786 void DeleteNode( XMLNode* node );
1787
1788 void SetError( XMLError error, const char* str1, const char* str2, int lineNum );
1789
1790 void ClearError() {
1791 SetError(XML_SUCCESS, 0, 0, 0);
1792 }
1793
1795 bool Error() const {
1796 return _errorID != XML_SUCCESS;
1797 }
1799 XMLError ErrorID() const {
1800 return _errorID;
1801 }
1802 const char* ErrorName() const;
1803 static const char* ErrorIDToName(XMLError errorID);
1804
1806 const char* GetErrorStr1() const;
1807
1809 const char* GetErrorStr2() const;
1810
1812 int GetErrorLineNum() const
1813 {
1814 return _errorLineNum;
1815 }
1817 void PrintError() const;
1818
1820 void Clear();
1821
1829 void DeepCopy(XMLDocument* target);
1830
1831 // internal
1832 char* Identify( char* p, XMLNode** node );
1833
1834 // internal
1835 void MarkInUse(XMLNode*);
1836
1837 virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
1838 return 0;
1839 }
1840 virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
1841 return false;
1842 }
1843
1844 private:
1845 XMLDocument( const XMLDocument& ); // not supported
1846 void operator=( const XMLDocument& ); // not supported
1847
1848 bool _writeBOM;
1849 bool _processEntities;
1850 XMLError _errorID;
1851 Whitespace _whitespaceMode;
1852 mutable StrPair _errorStr1;
1853 mutable StrPair _errorStr2;
1854 int _errorLineNum;
1855 char* _charBuffer;
1856 int _parseCurLineNum;
1857 // Memory tracking does add some overhead.
1858 // However, the code assumes that you don't
1859 // have a bunch of unlinked nodes around.
1860 // Therefore it takes less memory to track
1861 // in the document vs. a linked list in the XMLNode,
1862 // and the performance is the same.
1863 DynArray<XMLNode*, 10> _unlinked;
1864
1865 MemPoolT< sizeof(XMLElement) > _elementPool;
1866 MemPoolT< sizeof(XMLAttribute) > _attributePool;
1867 MemPoolT< sizeof(XMLText) > _textPool;
1868 MemPoolT< sizeof(XMLComment) > _commentPool;
1869
1870 static const char* _errorNames[XML_ERROR_COUNT];
1871
1872 void Parse();
1873
1874 template<class NodeType, int PoolElementSize>
1875 NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
1876 };
1877
1878 template<class NodeType, int PoolElementSize>
1879 inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool )
1880 {
1881 TIXMLASSERT( sizeof( NodeType ) == PoolElementSize );
1882 TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() );
1883 NodeType* returnNode = new (pool.Alloc()) NodeType( this );
1884 TIXMLASSERT( returnNode );
1885 returnNode->_memPool = &pool;
1886
1887 _unlinked.Push(returnNode);
1888 return returnNode;
1889 }
1890
1946 class TINYXML2_LIB XMLHandle
1947 {
1948 public:
1950 XMLHandle( XMLNode* node ) {
1951 _node = node;
1952 }
1954 XMLHandle( XMLNode& node ) {
1955 _node = &node;
1956 }
1958 XMLHandle( const XMLHandle& ref ) {
1959 _node = ref._node;
1960 }
1962 XMLHandle& operator=( const XMLHandle& ref ) {
1963 _node = ref._node;
1964 return *this;
1965 }
1966
1968 XMLHandle FirstChild() {
1969 return XMLHandle( _node ? _node->FirstChild() : 0 );
1970 }
1972 XMLHandle FirstChildElement( const char* name = 0 ) {
1973 return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
1974 }
1976 XMLHandle LastChild() {
1977 return XMLHandle( _node ? _node->LastChild() : 0 );
1978 }
1980 XMLHandle LastChildElement( const char* name = 0 ) {
1981 return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
1982 }
1984 XMLHandle PreviousSibling() {
1985 return XMLHandle( _node ? _node->PreviousSibling() : 0 );
1986 }
1988 XMLHandle PreviousSiblingElement( const char* name = 0 ) {
1989 return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
1990 }
1992 XMLHandle NextSibling() {
1993 return XMLHandle( _node ? _node->NextSibling() : 0 );
1994 }
1996 XMLHandle NextSiblingElement( const char* name = 0 ) {
1997 return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
1998 }
1999
2001 XMLNode* ToNode() {
2002 return _node;
2003 }
2005 XMLElement* ToElement() {
2006 return ( _node ? _node->ToElement() : 0 );
2007 }
2009 XMLText* ToText() {
2010 return ( _node ? _node->ToText() : 0 );
2011 }
2013 XMLUnknown* ToUnknown() {
2014 return ( _node ? _node->ToUnknown() : 0 );
2015 }
2017 XMLDeclaration* ToDeclaration() {
2018 return ( _node ? _node->ToDeclaration() : 0 );
2019 }
2020
2021 private:
2022 XMLNode* _node;
2023 };
2024
2025
2030 class TINYXML2_LIB XMLConstHandle
2031 {
2032 public:
2033 XMLConstHandle( const XMLNode* node ) {
2034 _node = node;
2035 }
2036 XMLConstHandle( const XMLNode& node ) {
2037 _node = &node;
2038 }
2039 XMLConstHandle( const XMLConstHandle& ref ) {
2040 _node = ref._node;
2041 }
2042
2043 XMLConstHandle& operator=( const XMLConstHandle& ref ) {
2044 _node = ref._node;
2045 return *this;
2046 }
2047
2048 const XMLConstHandle FirstChild() const {
2049 return XMLConstHandle( _node ? _node->FirstChild() : 0 );
2050 }
2051 const XMLConstHandle FirstChildElement( const char* name = 0 ) const {
2052 return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
2053 }
2054 const XMLConstHandle LastChild() const {
2055 return XMLConstHandle( _node ? _node->LastChild() : 0 );
2056 }
2057 const XMLConstHandle LastChildElement( const char* name = 0 ) const {
2058 return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
2059 }
2060 const XMLConstHandle PreviousSibling() const {
2061 return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
2062 }
2063 const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const {
2064 return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2065 }
2066 const XMLConstHandle NextSibling() const {
2067 return XMLConstHandle( _node ? _node->NextSibling() : 0 );
2068 }
2069 const XMLConstHandle NextSiblingElement( const char* name = 0 ) const {
2070 return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2071 }
2072
2073
2074 const XMLNode* ToNode() const {
2075 return _node;
2076 }
2077 const XMLElement* ToElement() const {
2078 return ( _node ? _node->ToElement() : 0 );
2079 }
2080 const XMLText* ToText() const {
2081 return ( _node ? _node->ToText() : 0 );
2082 }
2083 const XMLUnknown* ToUnknown() const {
2084 return ( _node ? _node->ToUnknown() : 0 );
2085 }
2086 const XMLDeclaration* ToDeclaration() const {
2087 return ( _node ? _node->ToDeclaration() : 0 );
2088 }
2089
2090 private:
2091 const XMLNode* _node;
2092 };
2093
2094
2137 class TINYXML2_LIB XMLPrinter : public XMLVisitor
2138 {
2139 public:
2146 XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 );
2147 virtual ~XMLPrinter() {}
2148
2150 void PushHeader( bool writeBOM, bool writeDeclaration );
2154 void OpenElement( const char* name, bool compactMode=false );
2156 void PushAttribute( const char* name, const char* value );
2157 void PushAttribute( const char* name, int value );
2158 void PushAttribute( const char* name, unsigned value );
2159 void PushAttribute(const char* name, int64_t value);
2160 void PushAttribute( const char* name, bool value );
2161 void PushAttribute( const char* name, double value );
2163 virtual void CloseElement( bool compactMode=false );
2164
2166 void PushText( const char* text, bool cdata=false );
2168 void PushText( int value );
2170 void PushText( unsigned value );
2172 void PushText(int64_t value);
2174 void PushText( bool value );
2176 void PushText( float value );
2178 void PushText( double value );
2179
2181 void PushComment( const char* comment );
2182
2183 void PushDeclaration( const char* value );
2184 void PushUnknown( const char* value );
2185
2186 virtual bool VisitEnter( const XMLDocument& /*doc*/ );
2187 virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
2188 return true;
2189 }
2190
2191 virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
2192 virtual bool VisitExit( const XMLElement& element );
2193
2194 virtual bool Visit( const XMLText& text );
2195 virtual bool Visit( const XMLComment& comment );
2196 virtual bool Visit( const XMLDeclaration& declaration );
2197 virtual bool Visit( const XMLUnknown& unknown );
2198
2203 const char* CStr() const {
2204 return _buffer.Mem();
2205 }
2211 int CStrSize() const {
2212 return _buffer.Size();
2213 }
2218 void ClearBuffer() {
2219 _buffer.Clear();
2220 _buffer.Push(0);
2221 _firstElement = true;
2222 }
2223
2224 protected:
2225 virtual bool CompactMode( const XMLElement& ) { return _compactMode; }
2226
2230 virtual void PrintSpace( int depth );
2231 void Print( const char* format, ... );
2232
2233 void SealElementIfJustOpened();
2234 bool _elementJustOpened;
2235 DynArray< const char*, 10 > _stack;
2236
2237 private:
2238 void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
2239
2240 bool _firstElement;
2241 FILE* _fp;
2242 int _depth;
2243 int _textDepth;
2244 bool _processEntities;
2245 bool _compactMode;
2246
2247 enum {
2248 ENTITY_RANGE = 64,
2249 BUF_SIZE = 200
2250 };
2251 bool _entityFlag[ENTITY_RANGE];
2252 bool _restrictedEntityFlag[ENTITY_RANGE];
2253
2254 DynArray< char, 20 > _buffer;
2255 };
2256
2257
2258 } // tinyxml2
2259
2260 #if defined(_MSC_VER)
2261 # pragma warning(pop)
2262 #endif
2263
2264 #endif // TINYXML2_INCLUDED
tinyxml2::XMLElement::QueryInt64Attribute
XMLError QueryInt64Attribute(const char *name, int64_t *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1330
tinyxml2::XMLAttribute::QueryIntValue
XMLError QueryIntValue(int *value) const
tinyxml2::XMLElement::QueryBoolAttribute
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1339
tinyxml2::XMLVisitor::VisitExit
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:477
tinyxml2::XMLDocument::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *) const
Definition: tinyxml2.h:1837
tinyxml2::XMLDocument::ShallowEqual
virtual bool ShallowEqual(const XMLNode *) const
Definition: tinyxml2.h:1840
tinyxml2::XMLHandle::FirstChildElement
XMLHandle FirstChildElement(const char *name=0)
Get the first child element of this handle.
Definition: tinyxml2.h:1972
tinyxml2::XMLHandle::ToText
XMLText * ToText()
Safe cast to XMLText. This can return null.
Definition: tinyxml2.h:2009
tinyxml2::XMLAttribute::QueryFloatValue
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
tinyxml2::XMLPrinter::CStr
const char * CStr() const
Definition: tinyxml2.h:2203
tinyxml2::XMLDocument::ErrorID
XMLError ErrorID() const
Return the errorID.
Definition: tinyxml2.h:1799
tinyxml2::XMLHandle::ToElement
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition: tinyxml2.h:2005
tinyxml2::XMLNode::ToElement
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:673
tinyxml2::XMLNode::ToText
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:677
tinyxml2::XMLElement::QueryUnsignedAttribute
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1321
tinyxml2::XMLPrinter::CStrSize
int CStrSize() const
Definition: tinyxml2.h:2211
tinyxml2::XMLAttribute::FloatValue
float FloatValue() const
Query as a float. See IntValue()
Definition: tinyxml2.h:1174
tinyxml2::XMLDocument::ToDocument
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:1642
tinyxml2::XMLHandle::ToUnknown
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
Definition: tinyxml2.h:2013
tinyxml2::XMLElement::Name
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition: tinyxml2.h:1240
tinyxml2::XMLHandle::XMLHandle
XMLHandle(const XMLHandle &ref)
Copy constructor.
Definition: tinyxml2.h:1958
tinyxml2::XMLHandle::FirstChild
XMLHandle FirstChild()
Get the first child of this handle.
Definition: tinyxml2.h:1968
tinyxml2::XMLText::SetCData
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
Definition: tinyxml2.h:986
tinyxml2::XMLNode::SetUserData
void SetUserData(void *userData)
Definition: tinyxml2.h:920
tinyxml2::XMLNode::NextSibling
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition: tinyxml2.h:802
tinyxml2::XMLAttribute::UnsignedValue
unsigned UnsignedValue() const
Query as an unsigned integer. See IntValue()
Definition: tinyxml2.h:1156
tinyxml2::XMLHandle::LastChildElement
XMLHandle LastChildElement(const char *name=0)
Get the last child element of this handle.
Definition: tinyxml2.h:1980
tinyxml2::XMLHandle::LastChild
XMLHandle LastChild()
Get the last child of this handle.
Definition: tinyxml2.h:1976
tinyxml2::XMLHandle
Definition: tinyxml2.h:1946
tinyxml2::XMLDeclaration
Definition: tinyxml2.h:1051
tinyxml2::XMLDocument::RootElement
XMLElement * RootElement()
Definition: tinyxml2.h:1721
tinyxml2::XMLElement::QueryAttribute
int QueryAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1381
tinyxml2::XMLText::ToText
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:978
tinyxml2::XMLHandle::XMLHandle
XMLHandle(XMLNode &node)
Create a handle from a node.
Definition: tinyxml2.h:1954
tinyxml2::XMLElement::SetName
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
Definition: tinyxml2.h:1244
tinyxml2::XMLDocument::SetBOM
void SetBOM(bool useBOM)
Definition: tinyxml2.h:1714
tinyxml2::XMLHandle::XMLHandle
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1950
tinyxml2::XMLPrinter::ClearBuffer
void ClearBuffer()
Definition: tinyxml2.h:2218
tinyxml2::XMLComment::ToComment
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:1016
tinyxml2::XMLElement::ToElement
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:1248
tinyxml2::XMLDocument::HasBOM
bool HasBOM() const
Definition: tinyxml2.h:1709
tinyxml2
Definition: tinyxml2.h:105
tinyxml2::XMLElement::QueryFloatAttribute
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1355
tinyxml2::XMLAttribute::QueryUnsignedValue
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
tinyxml2::XMLHandle::ToNode
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
Definition: tinyxml2.h:2001
tinyxml2::XMLAttribute::BoolValue
bool BoolValue() const
Query as a boolean. See IntValue()
Definition: tinyxml2.h:1162
tinyxml2::XMLNode::FirstChild
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:750
tinyxml2::XMLComment
Definition: tinyxml2.h:1012
tinyxml2::XMLDeclaration::ToDeclaration
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:1055
tinyxml2::XMLVisitor::Visit
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
Definition: tinyxml2.h:491
tinyxml2::XMLVisitor::Visit
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
Definition: tinyxml2.h:503
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
Definition: tinyxml2.h:1416
tinyxml2::XMLElement::QueryDoubleAttribute
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1347
tinyxml2::XMLElement
Definition: tinyxml2.h:1235
tinyxml2::XMLAttribute::QueryInt64Value
XMLError QueryInt64Value(int64_t *value) const
See QueryIntValue.
tinyxml2::XMLHandle::NextSibling
XMLHandle NextSibling()
Get the next sibling of this handle.
Definition: tinyxml2.h:1992
tinyxml2::XMLAttribute::GetLineNum
int GetLineNum() const
Gets the line number the attribute is in, if the document was parsed from a file. ...
Definition: tinyxml2.h:1132
tinyxml2::XMLAttribute::IntValue
int IntValue() const
Definition: tinyxml2.h:1143
tinyxml2::XMLUnknown::ToUnknown
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:1090
tinyxml2::XMLText::CData
bool CData() const
Returns true if this is a CDATA text element.
Definition: tinyxml2.h:990
tinyxml2::XMLHandle::PreviousSibling
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
Definition: tinyxml2.h:1984
tinyxml2::XMLConstHandle
Definition: tinyxml2.h:2030
tinyxml2::XMLHandle::operator=
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
Definition: tinyxml2.h:1962
tinyxml2::XMLPrinter::VisitExit
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:2187
tinyxml2::XMLVisitor::VisitEnter
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
Definition: tinyxml2.h:482
tinyxml2::XMLDocument::Error
bool Error() const
Return true if there was an error parsing the document.
Definition: tinyxml2.h:1795
tinyxml2::XMLVisitor::VisitEnter
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:473
tinyxml2::XMLUnknown
Definition: tinyxml2.h:1086
tinyxml2::XMLNode::ToDocument
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:685
tinyxml2::XMLNode::LastChild
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition: tinyxml2.h:768
tinyxml2::XMLAttribute
Definition: tinyxml2.h:1121
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
Definition: tinyxml2.h:1428
tinyxml2::XMLHandle::ToDeclaration
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
Definition: tinyxml2.h:2017
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(const char *value)
Set the attribute to a string value.
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition: tinyxml2.h:1406
tinyxml2::XMLVisitor::VisitExit
virtual bool VisitExit(const XMLElement &)
Visit an element.
Definition: tinyxml2.h:486
tinyxml2::XMLPrinter
Definition: tinyxml2.h:2137
tinyxml2::XMLDocument
Definition: tinyxml2.h:1634
tinyxml2::XMLNode::GetUserData
void * GetUserData() const
Definition: tinyxml2.h:927
tinyxml2::XMLDocument::GetErrorLineNum
int GetErrorLineNum() const
Return the line where the error occured, or zero if unknown.
Definition: tinyxml2.h:1812
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, int64_t value)
Sets the named attribute to value.
Definition: tinyxml2.h:1422
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
Definition: tinyxml2.h:1433
tinyxml2::XMLAttribute::QueryDoubleValue
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
tinyxml2::XMLNode::Parent
const XMLNode * Parent() const
Get the parent of this node on the DOM.
Definition: tinyxml2.h:736
tinyxml2::XMLVisitor::Visit
virtual bool Visit(const XMLComment &)
Visit a comment node.
Definition: tinyxml2.h:499
tinyxml2::XMLAttribute::QueryBoolValue
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
tinyxml2::XMLNode::PreviousSibling
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition: tinyxml2.h:786
tinyxml2::XMLHandle::NextSiblingElement
XMLHandle NextSiblingElement(const char *name=0)
Get the next sibling element of this handle.
Definition: tinyxml2.h:1996
tinyxml2::XMLNode
Definition: tinyxml2.h:655
tinyxml2::XMLElement::QueryIntAttribute
XMLError QueryIntAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1312
tinyxml2::XMLNode::GetLineNum
int GetLineNum() const
Gets the line number the node is in, if the document was parsed from a file.
Definition: tinyxml2.h:733
tinyxml2::XMLVisitor::Visit
virtual bool Visit(const XMLText &)
Visit a text node.
Definition: tinyxml2.h:495
tinyxml2::XMLText
Definition: tinyxml2.h:972
tinyxml2::XMLVisitor
Definition: tinyxml2.h:467
tinyxml2::XMLNode::GetDocument
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:667
tinyxml2::XMLNode::ToUnknown
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:693
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, float value)
Sets the named attribute to value.
Definition: tinyxml2.h:1438
tinyxml2::XMLAttribute::Next
const XMLAttribute * Next() const
The next attribute in the list.
Definition: tinyxml2.h:1135
tinyxml2::XMLNode::NoChildren
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml2.h:745
tinyxml2::XMLAttribute::DoubleValue
double DoubleValue() const
Query as a double. See IntValue()
Definition: tinyxml2.h:1168
tinyxml2::XMLNode::ToDeclaration
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:689
tinyxml2::XMLNode::GetDocument
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:662
tinyxml2::XMLHandle::PreviousSiblingElement
XMLHandle PreviousSiblingElement(const char *name=0)
Get the previous sibling element of this handle.
Definition: tinyxml2.h:1988
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
Definition: tinyxml2.h:1411
tinyxml2::XMLElement::FirstAttribute
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
Definition: tinyxml2.h:1449
tinyxml2::XMLNode::ToComment
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:681