24 #ifndef TINYXML2_INCLUDED
25 #define TINYXML2_INCLUDED
27 #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
56 #if defined( _DEBUG ) || defined (__DEBUG__)
57 # ifndef TINYXML2_DEBUG
58 # define TINYXML2_DEBUG
63 # pragma warning(push)
64 # pragma warning(disable: 4251)
68 # ifdef TINYXML2_EXPORT
69 # define TINYXML2_LIB __declspec(dllexport)
70 # elif defined(TINYXML2_IMPORT)
71 # define TINYXML2_LIB __declspec(dllimport)
76 # define TINYXML2_LIB __attribute__((visibility("default")))
82 #if !defined(TIXMLASSERT)
83 #if defined(TINYXML2_DEBUG)
84 # if defined(_MSC_VER)
85 # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
86 # define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); }
87 # elif defined (ANDROID_NDK)
88 # include <android/log.h>
89 # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
92 # define TIXMLASSERT assert
95 # define TIXMLASSERT( x ) {}
102 static const int TIXML2_MAJOR_VERSION = 8;
103 static const int TIXML2_MINOR_VERSION = 1;
104 static const int TIXML2_PATCH_VERSION = 0;
106 #define TINYXML2_MAJOR_VERSION 8
107 #define TINYXML2_MINOR_VERSION 1
108 #define TINYXML2_PATCH_VERSION 0
115 static const int TINYXML2_MAX_ELEMENT_DEPTH = 100;
124 class XMLDeclaration;
136 class TINYXML2_LIB StrPair
140 NEEDS_ENTITY_PROCESSING = 0x01,
141 NEEDS_NEWLINE_NORMALIZATION = 0x02,
142 NEEDS_WHITESPACE_COLLAPSING = 0x04,
144 TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
145 TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
147 ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
148 ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
149 COMMENT = NEEDS_NEWLINE_NORMALIZATION
152 StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
155 void Set(
char* start,
char* end,
int flags ) {
156 TIXMLASSERT( start );
161 _flags = flags | NEEDS_FLUSH;
164 const char* GetStr();
167 return _start == _end;
170 void SetInternedStr(
const char* str ) {
172 _start =
const_cast<char*
>(str);
175 void SetStr(
const char* str,
int flags=0 );
177 char* ParseText(
char* in,
const char* endTag,
int strFlags,
int* curLineNumPtr );
178 char* ParseName(
char* in );
180 void TransferTo( StrPair* other );
184 void CollapseWhitespace();
195 StrPair(
const StrPair& other );
196 void operator=(
const StrPair& other );
205 template <
class T,
int INITIAL_SIZE>
211 _allocated( INITIAL_SIZE ),
217 if ( _mem != _pool ) {
227 TIXMLASSERT( _size < INT_MAX );
228 EnsureCapacity( _size+1 );
233 T* PushArr(
int count ) {
234 TIXMLASSERT( count >= 0 );
235 TIXMLASSERT( _size <= INT_MAX - count );
236 EnsureCapacity( _size+count );
237 T* ret = &_mem[_size];
243 TIXMLASSERT( _size > 0 );
248 void PopArr(
int count ) {
249 TIXMLASSERT( _size >= count );
257 T& operator[](
int i) {
258 TIXMLASSERT( i>= 0 && i < _size );
262 const T& operator[](
int i)
const {
263 TIXMLASSERT( i>= 0 && i < _size );
267 const T& PeekTop()
const {
268 TIXMLASSERT( _size > 0 );
269 return _mem[ _size - 1];
273 TIXMLASSERT( _size >= 0 );
277 int Capacity()
const {
278 TIXMLASSERT( _allocated >= INITIAL_SIZE );
282 void SwapRemove(
int i) {
283 TIXMLASSERT(i >= 0 && i < _size);
284 TIXMLASSERT(_size > 0);
285 _mem[i] = _mem[_size - 1];
289 const T* Mem()
const {
300 DynArray(
const DynArray& );
301 void operator=(
const DynArray& );
303 void EnsureCapacity(
int cap ) {
304 TIXMLASSERT( cap > 0 );
305 if ( cap > _allocated ) {
306 TIXMLASSERT( cap <= INT_MAX / 2 );
307 const int newAllocated = cap * 2;
308 T* newMem =
new T[newAllocated];
309 TIXMLASSERT( newAllocated >= _size );
310 memcpy( newMem, _mem,
sizeof(T)*_size );
311 if ( _mem != _pool ) {
315 _allocated = newAllocated;
320 T _pool[INITIAL_SIZE];
334 virtual ~MemPool() {}
336 virtual int ItemSize()
const = 0;
337 virtual void* Alloc() = 0;
338 virtual void Free(
void* ) = 0;
339 virtual void SetTracked() = 0;
346 template<
int ITEM_SIZE >
347 class MemPoolT :
public MemPool
350 MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
352 MemPoolT< ITEM_SIZE >::Clear();
357 while( !_blockPtrs.Empty()) {
358 Block* lastBlock = _blockPtrs.Pop();
368 virtual int ItemSize()
const {
371 int CurrentAllocs()
const {
372 return _currentAllocs;
375 virtual void* Alloc() {
378 Block* block =
new Block();
379 _blockPtrs.Push( block );
381 Item* blockItems = block->items;
382 for(
int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
383 blockItems[i].next = &(blockItems[i + 1]);
385 blockItems[ITEMS_PER_BLOCK - 1].next = 0;
388 Item*
const result = _root;
389 TIXMLASSERT( result != 0 );
393 if ( _currentAllocs > _maxAllocs ) {
394 _maxAllocs = _currentAllocs;
401 virtual void Free(
void* mem ) {
406 Item* item =
static_cast<Item*
>( mem );
407 #ifdef TINYXML2_DEBUG
408 memset( item, 0xfe,
sizeof( *item ) );
413 void Trace(
const char* name ) {
414 printf(
"Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
415 name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs,
416 ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
423 int Untracked()
const {
438 enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE };
441 MemPoolT(
const MemPoolT& );
442 void operator=(
const MemPoolT& );
446 char itemData[ITEM_SIZE];
449 Item items[ITEMS_PER_BLOCK];
451 DynArray< Block*, 10 > _blockPtrs;
526 XML_WRONG_ATTRIBUTE_TYPE,
527 XML_ERROR_FILE_NOT_FOUND,
528 XML_ERROR_FILE_COULD_NOT_BE_OPENED,
529 XML_ERROR_FILE_READ_ERROR,
530 XML_ERROR_PARSING_ELEMENT,
531 XML_ERROR_PARSING_ATTRIBUTE,
532 XML_ERROR_PARSING_TEXT,
533 XML_ERROR_PARSING_CDATA,
534 XML_ERROR_PARSING_COMMENT,
535 XML_ERROR_PARSING_DECLARATION,
536 XML_ERROR_PARSING_UNKNOWN,
537 XML_ERROR_EMPTY_DOCUMENT,
538 XML_ERROR_MISMATCHED_ELEMENT,
540 XML_CAN_NOT_CONVERT_TEXT,
542 XML_ELEMENT_DEPTH_EXCEEDED,
551 class TINYXML2_LIB XMLUtil
554 static const char* SkipWhiteSpace(
const char* p,
int* curLineNumPtr ) {
557 while( IsWhiteSpace(*p) ) {
558 if (curLineNumPtr && *p ==
'\n') {
566 static char* SkipWhiteSpace(
char*
const p,
int* curLineNumPtr ) {
567 return const_cast<char*
>( SkipWhiteSpace(
const_cast<const char*
>(p), curLineNumPtr ) );
572 static bool IsWhiteSpace(
char p ) {
573 return !IsUTF8Continuation(p) && isspace(
static_cast<unsigned char>(p) );
576 inline static bool IsNameStartChar(
unsigned char ch ) {
581 if ( isalpha( ch ) ) {
584 return ch ==
':' || ch ==
'_';
587 inline static bool IsNameChar(
unsigned char ch ) {
588 return IsNameStartChar( ch )
594 inline static bool IsPrefixHex(
const char* p) {
595 p = SkipWhiteSpace(p, 0);
596 return p && *p ==
'0' && ( *(p + 1) ==
'x' || *(p + 1) ==
'X');
599 inline static bool StringEqual(
const char* p,
const char* q,
int nChar=INT_MAX ) {
605 TIXMLASSERT( nChar >= 0 );
606 return strncmp( p, q, nChar ) == 0;
609 inline static bool IsUTF8Continuation(
const char p ) {
610 return ( p & 0x80 ) != 0;
613 static const char* ReadBOM(
const char* p,
bool* hasBOM );
616 static const char* GetCharacterRef(
const char* p,
char* value,
int* length );
617 static void ConvertUTF32ToUTF8(
unsigned long input,
char* output,
int* length );
620 static void ToStr(
int v,
char* buffer,
int bufferSize );
621 static void ToStr(
unsigned v,
char* buffer,
int bufferSize );
622 static void ToStr(
bool v,
char* buffer,
int bufferSize );
623 static void ToStr(
float v,
char* buffer,
int bufferSize );
624 static void ToStr(
double v,
char* buffer,
int bufferSize );
625 static void ToStr(int64_t v,
char* buffer,
int bufferSize);
626 static void ToStr(uint64_t v,
char* buffer,
int bufferSize);
629 static bool ToInt(
const char* str,
int* value );
630 static bool ToUnsigned(
const char* str,
unsigned* value );
631 static bool ToBool(
const char* str,
bool* value );
632 static bool ToFloat(
const char* str,
float* value );
633 static bool ToDouble(
const char* str,
double* value );
634 static bool ToInt64(
const char* str, int64_t* value);
635 static bool ToUnsigned64(
const char* str, uint64_t* value);
641 static void SetBoolSerialization(
const char* writeTrue,
const char* writeFalse);
644 static const char* writeBoolTrue;
645 static const char* writeBoolFalse;
682 TIXMLASSERT( _document );
687 TIXMLASSERT( _document );
719 virtual const XMLText* ToText()
const {
722 virtual const XMLComment* ToComment()
const {
725 virtual const XMLDocument* ToDocument()
const {
728 virtual const XMLDeclaration* ToDeclaration()
const {
731 virtual const XMLUnknown* ToUnknown()
const {
744 const char* Value()
const;
749 void SetValue(
const char* val,
bool staticMem=
false );
780 const XMLElement* FirstChildElement(
const char* name = 0 )
const;
782 XMLElement* FirstChildElement(
const char* name = 0 ) {
783 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->FirstChildElement( name ));
798 const XMLElement* LastChildElement(
const char* name = 0 )
const;
800 XMLElement* LastChildElement(
const char* name = 0 ) {
801 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->LastChildElement(name) );
814 const XMLElement* PreviousSiblingElement(
const char* name = 0 )
const ;
816 XMLElement* PreviousSiblingElement(
const char* name = 0 ) {
817 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->PreviousSiblingElement( name ) );
830 const XMLElement* NextSiblingElement(
const char* name = 0 )
const;
832 XMLElement* NextSiblingElement(
const char* name = 0 ) {
833 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->NextSiblingElement( name ) );
843 XMLNode* InsertEndChild( XMLNode* addThis );
845 XMLNode* LinkEndChild( XMLNode* addThis ) {
846 return InsertEndChild( addThis );
855 XMLNode* InsertFirstChild( XMLNode* addThis );
864 XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
869 void DeleteChildren();
874 void DeleteChild( XMLNode* node );
885 virtual XMLNode* ShallowClone( XMLDocument* document )
const = 0;
900 XMLNode* DeepClone( XMLDocument* target )
const;
908 virtual bool ShallowEqual(
const XMLNode* compare )
const = 0;
932 virtual bool Accept( XMLVisitor* visitor )
const = 0;
952 virtual char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr);
956 mutable StrPair _value;
970 static void DeleteNode(
XMLNode* node );
971 void InsertChildPreamble(
XMLNode* insertThis )
const;
972 const XMLElement* ToElementWithName(
const char* name )
const;
995 virtual bool Accept(
XMLVisitor* visitor )
const;
1000 virtual const XMLText* ToText()
const {
1014 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1018 virtual ~XMLText() {}
1020 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1025 XMLText(
const XMLText& );
1026 XMLText& operator=(
const XMLText& );
1038 virtual const XMLComment* ToComment()
const {
1042 virtual bool Accept( XMLVisitor* visitor )
const;
1044 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
1045 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1048 explicit XMLComment( XMLDocument* doc );
1049 virtual ~XMLComment();
1051 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr);
1054 XMLComment(
const XMLComment& );
1055 XMLComment& operator=(
const XMLComment& );
1081 virtual bool Accept( XMLVisitor* visitor )
const;
1083 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
1084 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1087 explicit XMLDeclaration( XMLDocument* doc );
1088 virtual ~XMLDeclaration();
1090 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1093 XMLDeclaration(
const XMLDeclaration& );
1094 XMLDeclaration& operator=(
const XMLDeclaration& );
1112 virtual const XMLUnknown* ToUnknown()
const {
1116 virtual bool Accept( XMLVisitor* visitor )
const;
1118 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
1119 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1122 explicit XMLUnknown( XMLDocument* doc );
1123 virtual ~XMLUnknown();
1125 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1128 XMLUnknown(
const XMLUnknown& );
1129 XMLUnknown& operator=(
const XMLUnknown& );
1145 const char* Name()
const;
1148 const char* Value()
const;
1168 int64_t Int64Value()
const {
1170 QueryInt64Value(&i);
1174 uint64_t Unsigned64Value()
const {
1176 QueryUnsigned64Value(&i);
1183 QueryUnsignedValue( &i );
1189 QueryBoolValue( &b );
1195 QueryDoubleValue( &d );
1201 QueryFloatValue( &f );
1209 XMLError QueryIntValue(
int* value )
const;
1211 XMLError QueryUnsignedValue(
unsigned int* value )
const;
1213 XMLError QueryInt64Value(int64_t* value)
const;
1215 XMLError QueryUnsigned64Value(uint64_t* value)
const;
1217 XMLError QueryBoolValue(
bool* value )
const;
1219 XMLError QueryDoubleValue(
double* value )
const;
1221 XMLError QueryFloatValue(
float* value )
const;
1224 void SetAttribute(
const char* value );
1226 void SetAttribute(
int value );
1228 void SetAttribute(
unsigned value );
1230 void SetAttribute(int64_t value);
1232 void SetAttribute(uint64_t value);
1234 void SetAttribute(
bool value );
1236 void SetAttribute(
double value );
1238 void SetAttribute(
float value );
1241 enum { BUF_SIZE = 200 };
1243 XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
1244 virtual ~XMLAttribute() {}
1246 XMLAttribute(
const XMLAttribute& );
1247 void operator=(
const XMLAttribute& );
1248 void SetName(
const char* name );
1250 char* ParseDeep(
char* p,
bool processEntities,
int* curLineNumPtr );
1252 mutable StrPair _name;
1253 mutable StrPair _value;
1255 XMLAttribute* _next;
1273 void SetName(
const char* str,
bool staticMem=
false ) {
1274 SetValue( str, staticMem );
1280 virtual const XMLElement* ToElement()
const {
1283 virtual bool Accept( XMLVisitor* visitor )
const;
1308 const char* Attribute(
const char* name,
const char* value=0 )
const;
1316 int IntAttribute(
const char* name,
int defaultValue = 0)
const;
1318 unsigned UnsignedAttribute(
const char* name,
unsigned defaultValue = 0)
const;
1320 int64_t Int64Attribute(
const char* name, int64_t defaultValue = 0)
const;
1322 uint64_t Unsigned64Attribute(
const char* name, uint64_t defaultValue = 0)
const;
1324 bool BoolAttribute(
const char* name,
bool defaultValue =
false)
const;
1326 double DoubleAttribute(
const char* name,
double defaultValue = 0)
const;
1328 float FloatAttribute(
const char* name,
float defaultValue = 0)
const;
1346 return XML_NO_ATTRIBUTE;
1355 return XML_NO_ATTRIBUTE;
1364 return XML_NO_ATTRIBUTE;
1373 return XML_NO_ATTRIBUTE;
1382 return XML_NO_ATTRIBUTE;
1390 return XML_NO_ATTRIBUTE;
1398 return XML_NO_ATTRIBUTE;
1407 return XML_NO_ATTRIBUTE;
1409 *value = a->
Value();
1433 return QueryIntAttribute( name, value );
1436 XMLError QueryAttribute(
const char* name,
unsigned int* value )
const {
1437 return QueryUnsignedAttribute( name, value );
1440 XMLError QueryAttribute(
const char* name, int64_t* value)
const {
1441 return QueryInt64Attribute(name, value);
1444 XMLError QueryAttribute(
const char* name, uint64_t* value)
const {
1445 return QueryUnsigned64Attribute(name, value);
1448 XMLError QueryAttribute(
const char* name,
bool* value )
const {
1449 return QueryBoolAttribute( name, value );
1452 XMLError QueryAttribute(
const char* name,
double* value )
const {
1453 return QueryDoubleAttribute( name, value );
1456 XMLError QueryAttribute(
const char* name,
float* value )
const {
1457 return QueryFloatAttribute( name, value );
1460 XMLError QueryAttribute(
const char* name,
const char** value)
const {
1461 return QueryStringAttribute(name, value);
1511 void DeleteAttribute(
const char* name );
1515 return _rootAttribute;
1518 const XMLAttribute* FindAttribute(
const char* name )
const;
1548 const char* GetText()
const;
1584 void SetText(
const char* inText );
1586 void SetText(
int value );
1588 void SetText(
unsigned value );
1590 void SetText(int64_t value);
1592 void SetText(uint64_t value);
1594 void SetText(
bool value );
1596 void SetText(
double value );
1598 void SetText(
float value );
1626 XMLError QueryIntText(
int* ival )
const;
1628 XMLError QueryUnsignedText(
unsigned* uval )
const;
1630 XMLError QueryInt64Text(int64_t* uval)
const;
1632 XMLError QueryUnsigned64Text(uint64_t* uval)
const;
1634 XMLError QueryBoolText(
bool* bval )
const;
1636 XMLError QueryDoubleText(
double* dval )
const;
1638 XMLError QueryFloatText(
float* fval )
const;
1640 int IntText(
int defaultValue = 0)
const;
1643 unsigned UnsignedText(
unsigned defaultValue = 0)
const;
1645 int64_t Int64Text(int64_t defaultValue = 0)
const;
1647 uint64_t Unsigned64Text(uint64_t defaultValue = 0)
const;
1649 bool BoolText(
bool defaultValue =
false)
const;
1651 double DoubleText(
double defaultValue = 0)
const;
1653 float FloatText(
float defaultValue = 0)
const;
1659 XMLElement* InsertNewChildElement(
const char* name);
1661 XMLComment* InsertNewComment(
const char* comment);
1663 XMLText* InsertNewText(
const char* text);
1667 XMLUnknown* InsertNewUnknown(
const char* text);
1671 enum ElementClosingType {
1676 ElementClosingType ClosingType()
const {
1677 return _closingType;
1679 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
1680 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1683 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1686 XMLElement( XMLDocument* doc );
1687 virtual ~XMLElement();
1688 XMLElement(
const XMLElement& );
1689 void operator=(
const XMLElement& );
1691 XMLAttribute* FindOrCreateAttribute(
const char* name );
1692 char* ParseAttributes(
char* p,
int* curLineNumPtr );
1693 static void DeleteAttribute( XMLAttribute* attribute );
1694 XMLAttribute* CreateAttribute();
1696 enum { BUF_SIZE = 200 };
1697 ElementClosingType _closingType;
1701 XMLAttribute* _rootAttribute;
1706 PRESERVE_WHITESPACE,
1728 XMLDocument(
bool processEntities =
true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
1732 TIXMLASSERT(
this == _document );
1736 TIXMLASSERT(
this == _document );
1750 XMLError Parse(
const char* xml,
size_t nBytes=
static_cast<size_t>(-1) );
1757 XMLError LoadFile(
const char* filename );
1770 XMLError LoadFile( FILE* );
1777 XMLError SaveFile(
const char* filename,
bool compact =
false );
1786 XMLError SaveFile( FILE* fp,
bool compact =
false );
1788 bool ProcessEntities()
const {
1789 return _processEntities;
1791 Whitespace WhitespaceMode()
const {
1792 return _whitespaceMode;
1811 return FirstChildElement();
1814 return FirstChildElement();
1831 void Print( XMLPrinter* streamer=0 )
const;
1832 virtual bool Accept( XMLVisitor* visitor )
const;
1839 XMLElement* NewElement(
const char* name );
1845 XMLComment* NewComment(
const char* comment );
1851 XMLText* NewText(
const char* text );
1863 XMLDeclaration* NewDeclaration(
const char* text=0 );
1869 XMLUnknown* NewUnknown(
const char* text );
1875 void DeleteNode( XMLNode* node );
1882 return _errorID != XML_SUCCESS;
1888 const char* ErrorName()
const;
1889 static const char* ErrorIDToName(XMLError errorID);
1894 const char* ErrorStr()
const;
1897 void PrintError()
const;
1902 return _errorLineNum;
1918 char* Identify(
char* p,
XMLNode** node );
1921 void MarkInUse(
const XMLNode*
const);
1935 bool _processEntities;
1937 Whitespace _whitespaceMode;
1938 mutable StrPair _errorStr;
1941 int _parseCurLineNum;
1949 DynArray<XMLNode*, 10> _unlinked;
1953 MemPoolT<
sizeof(
XMLText) > _textPool;
1956 static const char* _errorNames[XML_ERROR_COUNT];
1960 void SetError( XMLError error,
int lineNum,
const char* format, ... );
1965 class DepthTracker {
1968 this->_document = document;
1969 document->PushDepth();
1972 _document->PopDepth();
1975 XMLDocument * _document;
1980 template<
class NodeType,
int PoolElementSize>
1981 NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
1984 template<
class NodeType,
int PoolElementSize>
1985 inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool )
1987 TIXMLASSERT(
sizeof( NodeType ) == PoolElementSize );
1988 TIXMLASSERT(
sizeof( NodeType ) == pool.ItemSize() );
1989 NodeType* returnNode =
new (pool.Alloc()) NodeType(
this );
1990 TIXMLASSERT( returnNode );
1991 returnNode->_memPool = &pool;
1993 _unlinked.Push(returnNode);
2072 return XMLHandle( _node ? _node->FirstChild() : 0 );
2076 return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
2080 return XMLHandle( _node ? _node->LastChild() : 0 );
2084 return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
2088 return XMLHandle( _node ? _node->PreviousSibling() : 0 );
2092 return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2096 return XMLHandle( _node ? _node->NextSibling() : 0 );
2100 return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2109 return ( _node ? _node->ToElement() : 0 );
2113 return ( _node ? _node->ToText() : 0 );
2117 return ( _node ? _node->ToUnknown() : 0 );
2121 return ( _node ? _node->ToDeclaration() : 0 );
2151 const XMLConstHandle FirstChildElement(
const char* name = 0 )
const {
2152 return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
2157 const XMLConstHandle LastChildElement(
const char* name = 0 )
const {
2158 return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
2163 const XMLConstHandle PreviousSiblingElement(
const char* name = 0 )
const {
2164 return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2169 const XMLConstHandle NextSiblingElement(
const char* name = 0 )
const {
2170 return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2174 const XMLNode* ToNode()
const {
2178 return ( _node ? _node->ToElement() : 0 );
2180 const XMLText* ToText()
const {
2181 return ( _node ? _node->ToText() : 0 );
2184 return ( _node ? _node->ToUnknown() : 0 );
2187 return ( _node ? _node->ToDeclaration() : 0 );
2246 XMLPrinter( FILE* file=0,
bool compact =
false,
int depth = 0 );
2250 void PushHeader(
bool writeBOM,
bool writeDeclaration );
2254 void OpenElement(
const char* name,
bool compactMode=
false );
2256 void PushAttribute(
const char* name,
const char* value );
2257 void PushAttribute(
const char* name,
int value );
2258 void PushAttribute(
const char* name,
unsigned value );
2259 void PushAttribute(
const char* name, int64_t value );
2260 void PushAttribute(
const char* name, uint64_t value );
2261 void PushAttribute(
const char* name,
bool value );
2262 void PushAttribute(
const char* name,
double value );
2264 virtual void CloseElement(
bool compactMode=
false );
2267 void PushText(
const char* text,
bool cdata=
false );
2269 void PushText(
int value );
2271 void PushText(
unsigned value );
2273 void PushText( int64_t value );
2275 void PushText( uint64_t value );
2277 void PushText(
bool value );
2279 void PushText(
float value );
2281 void PushText(
double value );
2284 void PushComment(
const char* comment );
2286 void PushDeclaration(
const char* value );
2287 void PushUnknown(
const char* value );
2295 virtual bool VisitExit(
const XMLElement& element );
2297 virtual bool Visit(
const XMLText& text );
2298 virtual bool Visit(
const XMLComment& comment );
2300 virtual bool Visit(
const XMLUnknown& unknown );
2307 return _buffer.Mem();
2315 return _buffer.Size();
2324 _firstElement = resetToFirstElement;
2328 virtual bool CompactMode(
const XMLElement& ) {
return _compactMode; }
2333 virtual void PrintSpace(
int depth );
2334 virtual void Print(
const char* format, ... );
2335 virtual void Write(
const char* data,
size_t size );
2336 virtual void Putc(
char ch );
2338 inline void Write(
const char* data) { Write(data, strlen(data)); }
2340 void SealElementIfJustOpened();
2341 bool _elementJustOpened;
2342 DynArray< const char*, 10 > _stack;
2349 void PrepareForNewNode(
bool compactMode );
2350 void PrintString(
const char*,
bool restrictedEntitySet );
2356 bool _processEntities;
2363 bool _entityFlag[ENTITY_RANGE];
2364 bool _restrictedEntityFlag[ENTITY_RANGE];
2366 DynArray< char, 20 > _buffer;
2369 XMLPrinter(
const XMLPrinter& );
2370 XMLPrinter& operator=(
const XMLPrinter& );
2376 #if defined(_MSC_VER)
2377 # pragma warning(pop)
2380 #endif // TINYXML2_INCLUDED