24 #ifndef TINYXML2_INCLUDED
25 #define TINYXML2_INCLUDED
27 #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
54 #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
61 # pragma warning(push)
62 # pragma warning(disable: 4251)
66 # ifdef TINYXML2_EXPORT
67 # define TINYXML2_LIB __declspec(dllexport)
68 # elif defined(TINYXML2_IMPORT)
69 # define TINYXML2_LIB __declspec(dllimport)
79 # if defined(_MSC_VER)
80 # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
81 # define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); } //if ( !(x)) WinDebugBreak()
82 # elif defined (ANDROID_NDK)
83 # include <android/log.h>
84 # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
87 # define TIXMLASSERT assert
90 # define TIXMLASSERT( x ) {}
97 static const int TIXML2_MAJOR_VERSION = 3;
98 static const int TIXML2_MINOR_VERSION = 0;
99 static const int TIXML2_PATCH_VERSION = 0;
108 class XMLDeclaration;
122 NEEDS_ENTITY_PROCESSING = 0x01,
123 NEEDS_NEWLINE_NORMALIZATION = 0x02,
124 NEEDS_WHITESPACE_COLLAPSING = 0x04,
126 TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
127 TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
129 ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
130 ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
131 COMMENT = NEEDS_NEWLINE_NORMALIZATION
134 StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
137 void Set(
char* start,
char* end,
int flags ) {
141 _flags = flags | NEEDS_FLUSH;
144 const char* GetStr();
147 return _start == _end;
150 void SetInternedStr(
const char* str ) {
152 _start =
const_cast<char*
>(str);
155 void SetStr(
const char* str,
int flags=0 );
157 char* ParseText(
char* in,
const char* endTag,
int strFlags );
158 char* ParseName(
char* in );
160 void TransferTo( StrPair* other );
164 void CollapseWhitespace();
176 StrPair(
const StrPair& other );
177 void operator=( StrPair& other );
186 template <
class T,
int INITIAL_SIZE>
192 _allocated = INITIAL_SIZE;
197 if ( _mem != _pool ) {
207 TIXMLASSERT( _size < INT_MAX );
208 EnsureCapacity( _size+1 );
212 T* PushArr(
int count ) {
213 TIXMLASSERT( count >= 0 );
214 TIXMLASSERT( _size <= INT_MAX - count );
215 EnsureCapacity( _size+count );
216 T* ret = &_mem[_size];
222 TIXMLASSERT( _size > 0 );
223 return _mem[--_size];
226 void PopArr(
int count ) {
227 TIXMLASSERT( _size >= count );
235 T& operator[](
int i) {
236 TIXMLASSERT( i>= 0 && i < _size );
240 const T& operator[](
int i)
const {
241 TIXMLASSERT( i>= 0 && i < _size );
245 const T& PeekTop()
const {
246 TIXMLASSERT( _size > 0 );
247 return _mem[ _size - 1];
251 TIXMLASSERT( _size >= 0 );
255 int Capacity()
const {
256 TIXMLASSERT( _allocated >= INITIAL_SIZE );
260 const T* Mem()
const {
271 DynArray(
const DynArray& );
272 void operator=(
const DynArray& );
274 void EnsureCapacity(
int cap ) {
275 TIXMLASSERT( cap > 0 );
276 if ( cap > _allocated ) {
277 TIXMLASSERT( cap <= INT_MAX / 2 );
278 int newAllocated = cap * 2;
279 T* newMem =
new T[newAllocated];
280 memcpy( newMem, _mem,
sizeof(T)*_size );
281 if ( _mem != _pool ) {
285 _allocated = newAllocated;
290 T _pool[INITIAL_SIZE];
304 virtual ~MemPool() {}
306 virtual int ItemSize()
const = 0;
307 virtual void* Alloc() = 0;
308 virtual void Free(
void* ) = 0;
309 virtual void SetTracked() = 0;
310 virtual void Clear() = 0;
318 class MemPoolT :
public MemPool
321 MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
328 while( !_blockPtrs.Empty()) {
329 Block* b = _blockPtrs.Pop();
339 virtual int ItemSize()
const {
342 int CurrentAllocs()
const {
343 return _currentAllocs;
346 virtual void* Alloc() {
349 Block* block =
new Block();
350 _blockPtrs.Push( block );
352 for(
int i=0; i<COUNT-1; ++i ) {
353 block->chunk[i].next = &block->chunk[i+1];
355 block->chunk[COUNT-1].next = 0;
356 _root = block->chunk;
358 void* result = _root;
362 if ( _currentAllocs > _maxAllocs ) {
363 _maxAllocs = _currentAllocs;
370 virtual void Free(
void* mem ) {
375 Chunk* chunk =
static_cast<Chunk*
>( mem );
377 memset( chunk, 0xfe,
sizeof(Chunk) );
382 void Trace(
const char* name ) {
383 printf(
"Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
384 name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() );
391 int Untracked()
const {
404 enum { COUNT = (4*1024)/SIZE };
407 MemPoolT(
const MemPoolT& );
408 void operator=(
const MemPoolT& );
417 DynArray< Block*, 10 > _blockPtrs;
447 class TINYXML2_LIB XMLVisitor
450 virtual ~XMLVisitor() {}
453 virtual bool VisitEnter(
const XMLDocument& ) {
457 virtual bool VisitExit(
const XMLDocument& ) {
462 virtual bool VisitEnter(
const XMLElement& ,
const XMLAttribute* ) {
466 virtual bool VisitExit(
const XMLElement& ) {
471 virtual bool Visit(
const XMLDeclaration& ) {
475 virtual bool Visit(
const XMLText& ) {
479 virtual bool Visit(
const XMLComment& ) {
483 virtual bool Visit(
const XMLUnknown& ) {
493 XML_WRONG_ATTRIBUTE_TYPE,
494 XML_ERROR_FILE_NOT_FOUND,
495 XML_ERROR_FILE_COULD_NOT_BE_OPENED,
496 XML_ERROR_FILE_READ_ERROR,
497 XML_ERROR_ELEMENT_MISMATCH,
498 XML_ERROR_PARSING_ELEMENT,
499 XML_ERROR_PARSING_ATTRIBUTE,
500 XML_ERROR_IDENTIFYING_TAG,
501 XML_ERROR_PARSING_TEXT,
502 XML_ERROR_PARSING_CDATA,
503 XML_ERROR_PARSING_COMMENT,
504 XML_ERROR_PARSING_DECLARATION,
505 XML_ERROR_PARSING_UNKNOWN,
506 XML_ERROR_EMPTY_DOCUMENT,
507 XML_ERROR_MISMATCHED_ELEMENT,
509 XML_CAN_NOT_CONVERT_TEXT,
522 static const char* SkipWhiteSpace(
const char* p ) {
524 while( IsWhiteSpace(*p) ) {
530 static char* SkipWhiteSpace(
char* p ) {
531 return const_cast<char*
>( SkipWhiteSpace( const_cast<const char*>(p) ) );
536 static bool IsWhiteSpace(
char p ) {
537 return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
540 inline static bool IsNameStartChar(
unsigned char ch ) {
545 if ( isalpha( ch ) ) {
548 return ch ==
':' || ch ==
'_';
551 inline static bool IsNameChar(
unsigned char ch ) {
552 return IsNameStartChar( ch )
558 inline static bool StringEqual(
const char* p,
const char* q,
int nChar=INT_MAX ) {
563 while( *p && *q && *p == *q && n<nChar ) {
568 if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
574 inline static bool IsUTF8Continuation(
char p ) {
575 return ( p & 0x80 ) != 0;
578 static const char* ReadBOM(
const char* p,
bool* hasBOM );
581 static const char* GetCharacterRef(
const char* p,
char* value,
int* length );
582 static void ConvertUTF32ToUTF8(
unsigned long input,
char* output,
int* length );
585 static void ToStr(
int v,
char* buffer,
int bufferSize );
586 static void ToStr(
unsigned v,
char* buffer,
int bufferSize );
587 static void ToStr(
bool v,
char* buffer,
int bufferSize );
588 static void ToStr(
float v,
char* buffer,
int bufferSize );
589 static void ToStr(
double v,
char* buffer,
int bufferSize );
592 static bool ToInt(
const char* str,
int* value );
593 static bool ToUnsigned(
const char* str,
unsigned* value );
594 static bool ToBool(
const char* str,
bool* value );
595 static bool ToFloat(
const char* str,
float* value );
596 static bool ToDouble(
const char* str,
double* value );
625 class TINYXML2_LIB XMLNode
627 friend class XMLDocument;
628 friend class XMLElement;
632 const XMLDocument* GetDocument()
const {
633 TIXMLASSERT( _document );
637 XMLDocument* GetDocument() {
638 TIXMLASSERT( _document );
643 virtual XMLElement* ToElement() {
647 virtual XMLText* ToText() {
651 virtual XMLComment* ToComment() {
655 virtual XMLDocument* ToDocument() {
659 virtual XMLDeclaration* ToDeclaration() {
663 virtual XMLUnknown* ToUnknown() {
667 virtual const XMLElement* ToElement()
const {
670 virtual const XMLText* ToText()
const {
673 virtual const XMLComment* ToComment()
const {
676 virtual const XMLDocument* ToDocument()
const {
679 virtual const XMLDeclaration* ToDeclaration()
const {
682 virtual const XMLUnknown* ToUnknown()
const {
695 const char* Value()
const;
700 void SetValue(
const char* val,
bool staticMem=
false );
703 const XMLNode* Parent()
const {
712 bool NoChildren()
const {
717 const XMLNode* FirstChild()
const {
721 XMLNode* FirstChild() {
728 const XMLElement* FirstChildElement(
const char* name = 0 )
const;
730 XMLElement* FirstChildElement(
const char* name = 0 ) {
731 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->FirstChildElement( name ));
735 const XMLNode* LastChild()
const {
739 XMLNode* LastChild() {
746 const XMLElement* LastChildElement(
const char* name = 0 )
const;
748 XMLElement* LastChildElement(
const char* name = 0 ) {
749 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->LastChildElement(name) );
753 const XMLNode* PreviousSibling()
const {
757 XMLNode* PreviousSibling() {
762 const XMLElement* PreviousSiblingElement(
const char* name = 0 )
const ;
764 XMLElement* PreviousSiblingElement(
const char* name = 0 ) {
765 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->PreviousSiblingElement( name ) );
769 const XMLNode* NextSibling()
const {
773 XMLNode* NextSibling() {
778 const XMLElement* NextSiblingElement(
const char* name = 0 )
const;
780 XMLElement* NextSiblingElement(
const char* name = 0 ) {
781 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->NextSiblingElement( name ) );
791 XMLNode* InsertEndChild( XMLNode* addThis );
793 XMLNode* LinkEndChild( XMLNode* addThis ) {
794 return InsertEndChild( addThis );
803 XMLNode* InsertFirstChild( XMLNode* addThis );
812 XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
817 void DeleteChildren();
822 void DeleteChild( XMLNode* node );
833 virtual XMLNode* ShallowClone( XMLDocument* document )
const = 0;
841 virtual bool ShallowEqual(
const XMLNode* compare )
const = 0;
865 virtual bool Accept( XMLVisitor* visitor )
const = 0;
868 XMLNode( XMLDocument* );
871 virtual char* ParseDeep(
char*, StrPair* );
873 XMLDocument* _document;
875 mutable StrPair _value;
877 XMLNode* _firstChild;
885 void Unlink( XMLNode* child );
886 static void DeleteNode( XMLNode* node );
887 void InsertChildPreamble( XMLNode* insertThis )
const;
889 XMLNode(
const XMLNode& );
890 XMLNode& operator=(
const XMLNode& );
906 class TINYXML2_LIB XMLText :
public XMLNode
908 friend class XMLBase;
909 friend class XMLDocument;
911 virtual bool Accept( XMLVisitor* visitor )
const;
913 virtual XMLText* ToText() {
916 virtual const XMLText* ToText()
const {
921 void SetCData(
bool isCData ) {
929 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
930 virtual bool ShallowEqual(
const XMLNode* compare )
const;
933 XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
934 virtual ~XMLText() {}
936 char* ParseDeep(
char*, StrPair* endTag );
941 XMLText(
const XMLText& );
942 XMLText& operator=(
const XMLText& );
947 class TINYXML2_LIB XMLComment :
public XMLNode
949 friend class XMLDocument;
951 virtual XMLComment* ToComment() {
954 virtual const XMLComment* ToComment()
const {
958 virtual bool Accept( XMLVisitor* visitor )
const;
960 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
961 virtual bool ShallowEqual(
const XMLNode* compare )
const;
964 XMLComment( XMLDocument* doc );
965 virtual ~XMLComment();
967 char* ParseDeep(
char*, StrPair* endTag );
970 XMLComment(
const XMLComment& );
971 XMLComment& operator=(
const XMLComment& );
986 class TINYXML2_LIB XMLDeclaration :
public XMLNode
988 friend class XMLDocument;
990 virtual XMLDeclaration* ToDeclaration() {
993 virtual const XMLDeclaration* ToDeclaration()
const {
997 virtual bool Accept( XMLVisitor* visitor )
const;
999 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
1000 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1003 XMLDeclaration( XMLDocument* doc );
1004 virtual ~XMLDeclaration();
1006 char* ParseDeep(
char*, StrPair* endTag );
1009 XMLDeclaration(
const XMLDeclaration& );
1010 XMLDeclaration& operator=(
const XMLDeclaration& );
1021 class TINYXML2_LIB XMLUnknown :
public XMLNode
1023 friend class XMLDocument;
1025 virtual XMLUnknown* ToUnknown() {
1028 virtual const XMLUnknown* ToUnknown()
const {
1032 virtual bool Accept( XMLVisitor* visitor )
const;
1034 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
1035 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1038 XMLUnknown( XMLDocument* doc );
1039 virtual ~XMLUnknown();
1041 char* ParseDeep(
char*, StrPair* endTag );
1044 XMLUnknown(
const XMLUnknown& );
1045 XMLUnknown& operator=(
const XMLUnknown& );
1056 class TINYXML2_LIB XMLAttribute
1058 friend class XMLElement;
1061 const char* Name()
const;
1064 const char* Value()
const;
1067 const XMLAttribute* Next()
const {
1075 int IntValue()
const {
1077 QueryIntValue( &i );
1081 unsigned UnsignedValue()
const {
1083 QueryUnsignedValue( &i );
1087 bool BoolValue()
const {
1089 QueryBoolValue( &b );
1093 double DoubleValue()
const {
1095 QueryDoubleValue( &d );
1099 float FloatValue()
const {
1101 QueryFloatValue( &f );
1109 XMLError QueryIntValue(
int* value )
const;
1111 XMLError QueryUnsignedValue(
unsigned int* value )
const;
1113 XMLError QueryBoolValue(
bool* value )
const;
1115 XMLError QueryDoubleValue(
double* value )
const;
1117 XMLError QueryFloatValue(
float* value )
const;
1120 void SetAttribute(
const char* value );
1122 void SetAttribute(
int value );
1124 void SetAttribute(
unsigned value );
1126 void SetAttribute(
bool value );
1128 void SetAttribute(
double value );
1130 void SetAttribute(
float value );
1133 enum { BUF_SIZE = 200 };
1135 XMLAttribute() : _next( 0 ), _memPool( 0 ) {}
1136 virtual ~XMLAttribute() {}
1138 XMLAttribute(
const XMLAttribute& );
1139 void operator=(
const XMLAttribute& );
1140 void SetName(
const char* name );
1142 char* ParseDeep(
char* p,
bool processEntities );
1144 mutable StrPair _name;
1145 mutable StrPair _value;
1146 XMLAttribute* _next;
1155 class TINYXML2_LIB XMLElement :
public XMLNode
1157 friend class XMLBase;
1158 friend class XMLDocument;
1161 const char* Name()
const {
1165 void SetName(
const char* str,
bool staticMem=
false ) {
1166 SetValue( str, staticMem );
1169 virtual XMLElement* ToElement() {
1172 virtual const XMLElement* ToElement()
const {
1175 virtual bool Accept( XMLVisitor* visitor )
const;
1200 const char* Attribute(
const char* name,
const char* value=0 )
const;
1207 int IntAttribute(
const char* name )
const {
1209 QueryIntAttribute( name, &i );
1213 unsigned UnsignedAttribute(
const char* name )
const {
1215 QueryUnsignedAttribute( name, &i );
1219 bool BoolAttribute(
const char* name )
const {
1221 QueryBoolAttribute( name, &b );
1225 double DoubleAttribute(
const char* name )
const {
1227 QueryDoubleAttribute( name, &d );
1231 float FloatAttribute(
const char* name )
const {
1233 QueryFloatAttribute( name, &f );
1250 XMLError QueryIntAttribute(
const char* name,
int* value )
const {
1251 const XMLAttribute* a = FindAttribute( name );
1253 return XML_NO_ATTRIBUTE;
1255 return a->QueryIntValue( value );
1258 XMLError QueryUnsignedAttribute(
const char* name,
unsigned int* value )
const {
1259 const XMLAttribute* a = FindAttribute( name );
1261 return XML_NO_ATTRIBUTE;
1263 return a->QueryUnsignedValue( value );
1266 XMLError QueryBoolAttribute(
const char* name,
bool* value )
const {
1267 const XMLAttribute* a = FindAttribute( name );
1269 return XML_NO_ATTRIBUTE;
1271 return a->QueryBoolValue( value );
1274 XMLError QueryDoubleAttribute(
const char* name,
double* value )
const {
1275 const XMLAttribute* a = FindAttribute( name );
1277 return XML_NO_ATTRIBUTE;
1279 return a->QueryDoubleValue( value );
1282 XMLError QueryFloatAttribute(
const char* name,
float* value )
const {
1283 const XMLAttribute* a = FindAttribute( name );
1285 return XML_NO_ATTRIBUTE;
1287 return a->QueryFloatValue( value );
1308 int QueryAttribute(
const char* name,
int* value )
const {
1309 return QueryIntAttribute( name, value );
1312 int QueryAttribute(
const char* name,
unsigned int* value )
const {
1313 return QueryUnsignedAttribute( name, value );
1316 int QueryAttribute(
const char* name,
bool* value )
const {
1317 return QueryBoolAttribute( name, value );
1320 int QueryAttribute(
const char* name,
double* value )
const {
1321 return QueryDoubleAttribute( name, value );
1324 int QueryAttribute(
const char* name,
float* value )
const {
1325 return QueryFloatAttribute( name, value );
1329 void SetAttribute(
const char* name,
const char* value ) {
1330 XMLAttribute* a = FindOrCreateAttribute( name );
1331 a->SetAttribute( value );
1334 void SetAttribute(
const char* name,
int value ) {
1335 XMLAttribute* a = FindOrCreateAttribute( name );
1336 a->SetAttribute( value );
1339 void SetAttribute(
const char* name,
unsigned value ) {
1340 XMLAttribute* a = FindOrCreateAttribute( name );
1341 a->SetAttribute( value );
1344 void SetAttribute(
const char* name,
bool value ) {
1345 XMLAttribute* a = FindOrCreateAttribute( name );
1346 a->SetAttribute( value );
1349 void SetAttribute(
const char* name,
double value ) {
1350 XMLAttribute* a = FindOrCreateAttribute( name );
1351 a->SetAttribute( value );
1354 void SetAttribute(
const char* name,
float value ) {
1355 XMLAttribute* a = FindOrCreateAttribute( name );
1356 a->SetAttribute( value );
1362 void DeleteAttribute(
const char* name );
1365 const XMLAttribute* FirstAttribute()
const {
1366 return _rootAttribute;
1369 const XMLAttribute* FindAttribute(
const char* name )
const;
1399 const char* GetText()
const;
1435 void SetText(
const char* inText );
1437 void SetText(
int value );
1439 void SetText(
unsigned value );
1441 void SetText(
bool value );
1443 void SetText(
double value );
1445 void SetText(
float value );
1473 XMLError QueryIntText(
int* ival )
const;
1475 XMLError QueryUnsignedText(
unsigned* uval )
const;
1477 XMLError QueryBoolText(
bool* bval )
const;
1479 XMLError QueryDoubleText(
double* dval )
const;
1481 XMLError QueryFloatText(
float* fval )
const;
1489 int ClosingType()
const {
1490 return _closingType;
1492 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
1493 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1496 char* ParseDeep(
char* p, StrPair* endTag );
1499 XMLElement( XMLDocument* doc );
1500 virtual ~XMLElement();
1501 XMLElement(
const XMLElement& );
1502 void operator=(
const XMLElement& );
1504 XMLAttribute* FindAttribute(
const char* name ) {
1505 return const_cast<XMLAttribute*
>(
const_cast<const XMLElement*
>(
this)->FindAttribute( name ));
1507 XMLAttribute* FindOrCreateAttribute(
const char* name );
1509 char* ParseAttributes(
char* p );
1510 static void DeleteAttribute( XMLAttribute* attribute );
1512 enum { BUF_SIZE = 200 };
1517 XMLAttribute* _rootAttribute;
1522 PRESERVE_WHITESPACE,
1532 class TINYXML2_LIB XMLDocument :
public XMLNode
1534 friend class XMLElement;
1537 XMLDocument(
bool processEntities =
true, Whitespace = PRESERVE_WHITESPACE );
1540 virtual XMLDocument* ToDocument() {
1541 TIXMLASSERT(
this == _document );
1544 virtual const XMLDocument* ToDocument()
const {
1545 TIXMLASSERT(
this == _document );
1559 XMLError Parse(
const char* xml,
size_t nBytes=(
size_t)(-1) );
1566 XMLError LoadFile(
const char* filename );
1579 XMLError LoadFile( FILE* );
1586 XMLError SaveFile(
const char* filename,
bool compact =
false );
1595 XMLError SaveFile( FILE* fp,
bool compact =
false );
1597 bool ProcessEntities()
const {
1598 return _processEntities;
1600 Whitespace WhitespaceMode()
const {
1607 bool HasBOM()
const {
1612 void SetBOM(
bool useBOM ) {
1619 XMLElement* RootElement() {
1620 return FirstChildElement();
1622 const XMLElement* RootElement()
const {
1623 return FirstChildElement();
1640 void Print( XMLPrinter* streamer=0 )
const;
1641 virtual bool Accept( XMLVisitor* visitor )
const;
1648 XMLElement* NewElement(
const char* name );
1654 XMLComment* NewComment(
const char* comment );
1660 XMLText* NewText(
const char* text );
1672 XMLDeclaration* NewDeclaration(
const char* text=0 );
1678 XMLUnknown* NewUnknown(
const char* text );
1684 void DeleteNode( XMLNode* node );
1686 void SetError( XMLError error,
const char* str1,
const char* str2 );
1689 bool Error()
const {
1690 return _errorID != XML_NO_ERROR;
1693 XMLError ErrorID()
const {
1696 const char* ErrorName()
const;
1699 const char* GetErrorStr1()
const {
1703 const char* GetErrorStr2()
const {
1707 void PrintError()
const;
1713 char* Identify(
char* p, XMLNode** node );
1715 virtual XMLNode* ShallowClone( XMLDocument* )
const {
1718 virtual bool ShallowEqual(
const XMLNode* )
const {
1723 XMLDocument(
const XMLDocument& );
1724 void operator=(
const XMLDocument& );
1727 bool _processEntities;
1729 Whitespace _whitespace;
1730 const char* _errorStr1;
1731 const char* _errorStr2;
1734 MemPoolT< sizeof(XMLElement) > _elementPool;
1735 MemPoolT< sizeof(XMLAttribute) > _attributePool;
1736 MemPoolT< sizeof(XMLText) > _textPool;
1737 MemPoolT< sizeof(XMLComment) > _commentPool;
1739 static const char* _errorNames[XML_ERROR_COUNT];
1800 class TINYXML2_LIB XMLHandle
1804 XMLHandle( XMLNode* node ) {
1808 XMLHandle( XMLNode& node ) {
1812 XMLHandle(
const XMLHandle& ref ) {
1816 XMLHandle& operator=(
const XMLHandle& ref ) {
1822 XMLHandle FirstChild() {
1823 return XMLHandle( _node ? _node->FirstChild() : 0 );
1826 XMLHandle FirstChildElement(
const char* name = 0 ) {
1827 return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
1830 XMLHandle LastChild() {
1831 return XMLHandle( _node ? _node->LastChild() : 0 );
1834 XMLHandle LastChildElement(
const char* name = 0 ) {
1835 return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
1838 XMLHandle PreviousSibling() {
1839 return XMLHandle( _node ? _node->PreviousSibling() : 0 );
1842 XMLHandle PreviousSiblingElement(
const char* name = 0 ) {
1843 return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
1846 XMLHandle NextSibling() {
1847 return XMLHandle( _node ? _node->NextSibling() : 0 );
1850 XMLHandle NextSiblingElement(
const char* name = 0 ) {
1851 return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
1859 XMLElement* ToElement() {
1860 return ( ( _node == 0 ) ? 0 : _node->ToElement() );
1864 return ( ( _node == 0 ) ? 0 : _node->ToText() );
1867 XMLUnknown* ToUnknown() {
1868 return ( ( _node == 0 ) ? 0 : _node->ToUnknown() );
1871 XMLDeclaration* ToDeclaration() {
1872 return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() );
1884 class TINYXML2_LIB XMLConstHandle
1887 XMLConstHandle(
const XMLNode* node ) {
1890 XMLConstHandle(
const XMLNode& node ) {
1893 XMLConstHandle(
const XMLConstHandle& ref ) {
1897 XMLConstHandle& operator=(
const XMLConstHandle& ref ) {
1902 const XMLConstHandle FirstChild()
const {
1903 return XMLConstHandle( _node ? _node->FirstChild() : 0 );
1905 const XMLConstHandle FirstChildElement(
const char* name = 0 )
const {
1906 return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
1908 const XMLConstHandle LastChild()
const {
1909 return XMLConstHandle( _node ? _node->LastChild() : 0 );
1911 const XMLConstHandle LastChildElement(
const char* name = 0 )
const {
1912 return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
1914 const XMLConstHandle PreviousSibling()
const {
1915 return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
1917 const XMLConstHandle PreviousSiblingElement(
const char* name = 0 )
const {
1918 return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
1920 const XMLConstHandle NextSibling()
const {
1921 return XMLConstHandle( _node ? _node->NextSibling() : 0 );
1923 const XMLConstHandle NextSiblingElement(
const char* name = 0 )
const {
1924 return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
1928 const XMLNode* ToNode()
const {
1931 const XMLElement* ToElement()
const {
1932 return ( ( _node == 0 ) ? 0 : _node->ToElement() );
1934 const XMLText* ToText()
const {
1935 return ( ( _node == 0 ) ? 0 : _node->ToText() );
1937 const XMLUnknown* ToUnknown()
const {
1938 return ( ( _node == 0 ) ? 0 : _node->ToUnknown() );
1940 const XMLDeclaration* ToDeclaration()
const {
1941 return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() );
1945 const XMLNode* _node;
1991 class TINYXML2_LIB XMLPrinter :
public XMLVisitor
2000 XMLPrinter( FILE* file=0,
bool compact =
false,
int depth = 0 );
2001 virtual ~XMLPrinter() {}
2004 void PushHeader(
bool writeBOM,
bool writeDeclaration );
2008 void OpenElement(
const char* name,
bool compactMode=
false );
2010 void PushAttribute(
const char* name,
const char* value );
2011 void PushAttribute(
const char* name,
int value );
2012 void PushAttribute(
const char* name,
unsigned value );
2013 void PushAttribute(
const char* name,
bool value );
2014 void PushAttribute(
const char* name,
double value );
2016 virtual void CloseElement(
bool compactMode=
false );
2019 void PushText(
const char* text,
bool cdata=
false );
2021 void PushText(
int value );
2023 void PushText(
unsigned value );
2025 void PushText(
bool value );
2027 void PushText(
float value );
2029 void PushText(
double value );
2032 void PushComment(
const char* comment );
2034 void PushDeclaration(
const char* value );
2035 void PushUnknown(
const char* value );
2037 virtual bool VisitEnter(
const XMLDocument& );
2038 virtual bool VisitExit(
const XMLDocument& ) {
2042 virtual bool VisitEnter(
const XMLElement& element,
const XMLAttribute* attribute );
2043 virtual bool VisitExit(
const XMLElement& element );
2045 virtual bool Visit(
const XMLText& text );
2046 virtual bool Visit(
const XMLComment& comment );
2047 virtual bool Visit(
const XMLDeclaration& declaration );
2048 virtual bool Visit(
const XMLUnknown& unknown );
2054 const char* CStr()
const {
2055 return _buffer.Mem();
2062 int CStrSize()
const {
2063 return _buffer.Size();
2069 void ClearBuffer() {
2075 virtual bool CompactMode(
const XMLElement& ) {
return _compactMode; }
2080 virtual void PrintSpace(
int depth );
2081 void Print(
const char* format, ... );
2083 void SealElementIfJustOpened();
2084 bool _elementJustOpened;
2085 DynArray< const char*, 10 > _stack;
2088 void PrintString(
const char*,
bool restrictedEntitySet );
2094 bool _processEntities;
2101 bool _entityFlag[ENTITY_RANGE];
2102 bool _restrictedEntityFlag[ENTITY_RANGE];
2104 DynArray< char, 20 > _buffer;
2110 #if defined(_MSC_VER)
2111 # pragma warning(pop)
2114 #endif // TINYXML2_INCLUDED
Definition: tinyxml2.h:101