nuclear@19: /* nuclear@19: Original code by Lee Thomason (www.grinninglizard.com) nuclear@19: nuclear@19: This software is provided 'as-is', without any express or implied nuclear@19: warranty. In no event will the authors be held liable for any nuclear@19: damages arising from the use of this software. nuclear@19: nuclear@19: Permission is granted to anyone to use this software for any nuclear@19: purpose, including commercial applications, and to alter it and nuclear@19: redistribute it freely, subject to the following restrictions: nuclear@19: nuclear@19: 1. The origin of this software must not be misrepresented; you must nuclear@19: not claim that you wrote the original software. If you use this nuclear@19: software in a product, an acknowledgment in the product documentation nuclear@19: would be appreciated but is not required. nuclear@19: nuclear@19: nuclear@19: 2. Altered source versions must be plainly marked as such, and nuclear@19: must not be misrepresented as being the original software. nuclear@19: nuclear@19: 3. This notice may not be removed or altered from any source nuclear@19: distribution. nuclear@19: */ nuclear@19: nuclear@19: #ifndef TINYXML2_INCLUDED nuclear@19: #define TINYXML2_INCLUDED nuclear@19: nuclear@19: #if defined(ANDROID_NDK) || defined(__BORLANDC__) nuclear@19: # include nuclear@19: # include nuclear@19: # include nuclear@19: # include nuclear@19: # include nuclear@19: # include nuclear@19: #else nuclear@19: # include nuclear@19: # include nuclear@19: # include nuclear@19: # include nuclear@19: # include nuclear@19: # include nuclear@19: #endif nuclear@19: nuclear@19: /* nuclear@19: TODO: intern strings instead of allocation. nuclear@19: */ nuclear@19: /* nuclear@19: gcc: nuclear@19: g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe nuclear@19: nuclear@19: Formatting, Artistic Style: nuclear@19: AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h nuclear@19: */ nuclear@19: nuclear@19: #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__) nuclear@19: # ifndef DEBUG nuclear@19: # define DEBUG nuclear@19: # endif nuclear@19: #endif nuclear@19: nuclear@19: #ifdef _MSC_VER nuclear@19: # pragma warning(push) nuclear@19: # pragma warning(disable: 4251) nuclear@19: #endif nuclear@19: nuclear@19: #ifdef _WIN32 nuclear@19: # ifdef TINYXML2_EXPORT nuclear@19: # define TINYXML2_LIB __declspec(dllexport) nuclear@19: # elif defined(TINYXML2_IMPORT) nuclear@19: # define TINYXML2_LIB __declspec(dllimport) nuclear@19: # else nuclear@19: # define TINYXML2_LIB nuclear@19: # endif nuclear@19: #else nuclear@19: # define TINYXML2_LIB nuclear@19: #endif nuclear@19: nuclear@19: nuclear@19: #if defined(DEBUG) nuclear@19: # if defined(_MSC_VER) nuclear@19: # define TIXMLASSERT( x ) if ( !(x)) { __debugbreak(); } //if ( !(x)) WinDebugBreak() nuclear@19: # elif defined (ANDROID_NDK) nuclear@19: # include nuclear@19: # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } nuclear@19: # else nuclear@19: # include nuclear@19: # define TIXMLASSERT assert nuclear@19: # endif nuclear@19: # else nuclear@19: # define TIXMLASSERT( x ) {} nuclear@19: #endif nuclear@19: nuclear@19: nuclear@19: #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) nuclear@19: // Microsoft visual studio, version 2005 and higher. nuclear@19: /*int _snprintf_s( nuclear@19: char *buffer, nuclear@19: size_t sizeOfBuffer, nuclear@19: size_t count, nuclear@19: const char *format [, nuclear@19: argument] ... nuclear@19: );*/ nuclear@19: inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... ) nuclear@19: { nuclear@19: va_list va; nuclear@19: va_start( va, format ); nuclear@19: int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va ); nuclear@19: va_end( va ); nuclear@19: return result; nuclear@19: } nuclear@19: #define TIXML_SSCANF sscanf_s nuclear@19: #else nuclear@19: // GCC version 3 and higher nuclear@19: //#warning( "Using sn* functions." ) nuclear@19: #define TIXML_SNPRINTF snprintf nuclear@19: #define TIXML_SSCANF sscanf nuclear@19: #endif nuclear@19: nuclear@19: static const int TIXML2_MAJOR_VERSION = 1; nuclear@19: static const int TIXML2_MINOR_VERSION = 0; nuclear@19: static const int TIXML2_PATCH_VERSION = 11; nuclear@19: nuclear@19: namespace tinyxml2 nuclear@19: { nuclear@19: class XMLDocument; nuclear@19: class XMLElement; nuclear@19: class XMLAttribute; nuclear@19: class XMLComment; nuclear@19: class XMLText; nuclear@19: class XMLDeclaration; nuclear@19: class XMLUnknown; nuclear@19: class XMLPrinter; nuclear@19: nuclear@19: /* nuclear@19: A class that wraps strings. Normally stores the start and end nuclear@19: pointers into the XML file itself, and will apply normalization nuclear@19: and entity translation if actually read. Can also store (and memory nuclear@19: manage) a traditional char[] nuclear@19: */ nuclear@19: class StrPair nuclear@19: { nuclear@19: public: nuclear@19: enum { nuclear@19: NEEDS_ENTITY_PROCESSING = 0x01, nuclear@19: NEEDS_NEWLINE_NORMALIZATION = 0x02, nuclear@19: COLLAPSE_WHITESPACE = 0x04, nuclear@19: nuclear@19: TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, nuclear@19: TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, nuclear@19: ATTRIBUTE_NAME = 0, nuclear@19: ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, nuclear@19: ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, nuclear@19: COMMENT = NEEDS_NEWLINE_NORMALIZATION nuclear@19: }; nuclear@19: nuclear@19: StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {} nuclear@19: ~StrPair(); nuclear@19: nuclear@19: void Set( char* start, char* end, int flags ) { nuclear@19: Reset(); nuclear@19: _start = start; nuclear@19: _end = end; nuclear@19: _flags = flags | NEEDS_FLUSH; nuclear@19: } nuclear@19: nuclear@19: const char* GetStr(); nuclear@19: nuclear@19: bool Empty() const { nuclear@19: return _start == _end; nuclear@19: } nuclear@19: nuclear@19: void SetInternedStr( const char* str ) { nuclear@19: Reset(); nuclear@19: _start = const_cast(str); nuclear@19: } nuclear@19: nuclear@19: void SetStr( const char* str, int flags=0 ); nuclear@19: nuclear@19: char* ParseText( char* in, const char* endTag, int strFlags ); nuclear@19: char* ParseName( char* in ); nuclear@19: nuclear@19: private: nuclear@19: void Reset(); nuclear@19: void CollapseWhitespace(); nuclear@19: nuclear@19: enum { nuclear@19: NEEDS_FLUSH = 0x100, nuclear@19: NEEDS_DELETE = 0x200 nuclear@19: }; nuclear@19: nuclear@19: // After parsing, if *_end != 0, it can be set to zero. nuclear@19: int _flags; nuclear@19: char* _start; nuclear@19: char* _end; nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /* nuclear@19: A dynamic array of Plain Old Data. Doesn't support constructors, etc. nuclear@19: Has a small initial memory pool, so that low or no usage will not nuclear@19: cause a call to new/delete nuclear@19: */ nuclear@19: template nuclear@19: class DynArray nuclear@19: { nuclear@19: public: nuclear@19: DynArray< T, INIT >() { nuclear@19: _mem = _pool; nuclear@19: _allocated = INIT; nuclear@19: _size = 0; nuclear@19: } nuclear@19: nuclear@19: ~DynArray() { nuclear@19: if ( _mem != _pool ) { nuclear@19: delete [] _mem; nuclear@19: } nuclear@19: } nuclear@19: nuclear@19: void Push( T t ) { nuclear@19: EnsureCapacity( _size+1 ); nuclear@19: _mem[_size++] = t; nuclear@19: } nuclear@19: nuclear@19: T* PushArr( int count ) { nuclear@19: EnsureCapacity( _size+count ); nuclear@19: T* ret = &_mem[_size]; nuclear@19: _size += count; nuclear@19: return ret; nuclear@19: } nuclear@19: nuclear@19: T Pop() { nuclear@19: return _mem[--_size]; nuclear@19: } nuclear@19: nuclear@19: void PopArr( int count ) { nuclear@19: TIXMLASSERT( _size >= count ); nuclear@19: _size -= count; nuclear@19: } nuclear@19: nuclear@19: bool Empty() const { nuclear@19: return _size == 0; nuclear@19: } nuclear@19: nuclear@19: T& operator[](int i) { nuclear@19: TIXMLASSERT( i>= 0 && i < _size ); nuclear@19: return _mem[i]; nuclear@19: } nuclear@19: nuclear@19: const T& operator[](int i) const { nuclear@19: TIXMLASSERT( i>= 0 && i < _size ); nuclear@19: return _mem[i]; nuclear@19: } nuclear@19: nuclear@19: int Size() const { nuclear@19: return _size; nuclear@19: } nuclear@19: nuclear@19: int Capacity() const { nuclear@19: return _allocated; nuclear@19: } nuclear@19: nuclear@19: const T* Mem() const { nuclear@19: return _mem; nuclear@19: } nuclear@19: nuclear@19: T* Mem() { nuclear@19: return _mem; nuclear@19: } nuclear@19: nuclear@19: private: nuclear@19: void EnsureCapacity( int cap ) { nuclear@19: if ( cap > _allocated ) { nuclear@19: int newAllocated = cap * 2; nuclear@19: T* newMem = new T[newAllocated]; nuclear@19: memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs nuclear@19: if ( _mem != _pool ) { nuclear@19: delete [] _mem; nuclear@19: } nuclear@19: _mem = newMem; nuclear@19: _allocated = newAllocated; nuclear@19: } nuclear@19: } nuclear@19: nuclear@19: T* _mem; nuclear@19: T _pool[INIT]; nuclear@19: int _allocated; // objects allocated nuclear@19: int _size; // number objects in use nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /* nuclear@19: Parent virtual class of a pool for fast allocation nuclear@19: and deallocation of objects. nuclear@19: */ nuclear@19: class MemPool nuclear@19: { nuclear@19: public: nuclear@19: MemPool() {} nuclear@19: virtual ~MemPool() {} nuclear@19: nuclear@19: virtual int ItemSize() const = 0; nuclear@19: virtual void* Alloc() = 0; nuclear@19: virtual void Free( void* ) = 0; nuclear@19: virtual void SetTracked() = 0; nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /* nuclear@19: Template child class to create pools of the correct type. nuclear@19: */ nuclear@19: template< int SIZE > nuclear@19: class MemPoolT : public MemPool nuclear@19: { nuclear@19: public: nuclear@19: MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} nuclear@19: ~MemPoolT() { nuclear@19: // Delete the blocks. nuclear@19: for( int i=0; i<_blockPtrs.Size(); ++i ) { nuclear@19: delete _blockPtrs[i]; nuclear@19: } nuclear@19: } nuclear@19: nuclear@19: virtual int ItemSize() const { nuclear@19: return SIZE; nuclear@19: } nuclear@19: int CurrentAllocs() const { nuclear@19: return _currentAllocs; nuclear@19: } nuclear@19: nuclear@19: virtual void* Alloc() { nuclear@19: if ( !_root ) { nuclear@19: // Need a new block. nuclear@19: Block* block = new Block(); nuclear@19: _blockPtrs.Push( block ); nuclear@19: nuclear@19: for( int i=0; ichunk[i].next = &block->chunk[i+1]; nuclear@19: } nuclear@19: block->chunk[COUNT-1].next = 0; nuclear@19: _root = block->chunk; nuclear@19: } nuclear@19: void* result = _root; nuclear@19: _root = _root->next; nuclear@19: nuclear@19: ++_currentAllocs; nuclear@19: if ( _currentAllocs > _maxAllocs ) { nuclear@19: _maxAllocs = _currentAllocs; nuclear@19: } nuclear@19: _nAllocs++; nuclear@19: _nUntracked++; nuclear@19: return result; nuclear@19: } nuclear@19: virtual void Free( void* mem ) { nuclear@19: if ( !mem ) { nuclear@19: return; nuclear@19: } nuclear@19: --_currentAllocs; nuclear@19: Chunk* chunk = (Chunk*)mem; nuclear@19: #ifdef DEBUG nuclear@19: memset( chunk, 0xfe, sizeof(Chunk) ); nuclear@19: #endif nuclear@19: chunk->next = _root; nuclear@19: _root = chunk; nuclear@19: } nuclear@19: void Trace( const char* name ) { nuclear@19: printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n", nuclear@19: name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() ); nuclear@19: } nuclear@19: nuclear@19: void SetTracked() { nuclear@19: _nUntracked--; nuclear@19: } nuclear@19: nuclear@19: int Untracked() const { nuclear@19: return _nUntracked; nuclear@19: } nuclear@19: nuclear@19: // This number is perf sensitive. 4k seems like a good tradeoff on my machine. nuclear@19: // The test file is large, 170k. nuclear@19: // Release: VS2010 gcc(no opt) nuclear@19: // 1k: 4000 nuclear@19: // 2k: 4000 nuclear@19: // 4k: 3900 21000 nuclear@19: // 16k: 5200 nuclear@19: // 32k: 4300 nuclear@19: // 64k: 4000 21000 nuclear@19: enum { COUNT = (4*1024)/SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private nuclear@19: nuclear@19: private: nuclear@19: union Chunk { nuclear@19: Chunk* next; nuclear@19: char mem[SIZE]; nuclear@19: }; nuclear@19: struct Block { nuclear@19: Chunk chunk[COUNT]; nuclear@19: }; nuclear@19: DynArray< Block*, 10 > _blockPtrs; nuclear@19: Chunk* _root; nuclear@19: nuclear@19: int _currentAllocs; nuclear@19: int _nAllocs; nuclear@19: int _maxAllocs; nuclear@19: int _nUntracked; nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: nuclear@19: /** nuclear@19: Implements the interface to the "Visitor pattern" (see the Accept() method.) nuclear@19: If you call the Accept() method, it requires being passed a XMLVisitor nuclear@19: class to handle callbacks. For nodes that contain other nodes (Document, Element) nuclear@19: you will get called with a VisitEnter/VisitExit pair. Nodes that are always leafs nuclear@19: are simply called with Visit(). nuclear@19: nuclear@19: If you return 'true' from a Visit method, recursive parsing will continue. If you return nuclear@19: false, no children of this node or its siblings will be visited. nuclear@19: nuclear@19: All flavors of Visit methods have a default implementation that returns 'true' (continue nuclear@19: visiting). You need to only override methods that are interesting to you. nuclear@19: nuclear@19: Generally Accept() is called on the XMLDocument, although all nodes support visiting. nuclear@19: nuclear@19: You should never change the document from a callback. nuclear@19: nuclear@19: @sa XMLNode::Accept() nuclear@19: */ nuclear@19: class TINYXML2_LIB XMLVisitor nuclear@19: { nuclear@19: public: nuclear@19: virtual ~XMLVisitor() {} nuclear@19: nuclear@19: /// Visit a document. nuclear@19: virtual bool VisitEnter( const XMLDocument& /*doc*/ ) { nuclear@19: return true; nuclear@19: } nuclear@19: /// Visit a document. nuclear@19: virtual bool VisitExit( const XMLDocument& /*doc*/ ) { nuclear@19: return true; nuclear@19: } nuclear@19: nuclear@19: /// Visit an element. nuclear@19: virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) { nuclear@19: return true; nuclear@19: } nuclear@19: /// Visit an element. nuclear@19: virtual bool VisitExit( const XMLElement& /*element*/ ) { nuclear@19: return true; nuclear@19: } nuclear@19: nuclear@19: /// Visit a declaration. nuclear@19: virtual bool Visit( const XMLDeclaration& /*declaration*/ ) { nuclear@19: return true; nuclear@19: } nuclear@19: /// Visit a text node. nuclear@19: virtual bool Visit( const XMLText& /*text*/ ) { nuclear@19: return true; nuclear@19: } nuclear@19: /// Visit a comment node. nuclear@19: virtual bool Visit( const XMLComment& /*comment*/ ) { nuclear@19: return true; nuclear@19: } nuclear@19: /// Visit an unknown node. nuclear@19: virtual bool Visit( const XMLUnknown& /*unknown*/ ) { nuclear@19: return true; nuclear@19: } nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /* nuclear@19: Utility functionality. nuclear@19: */ nuclear@19: class XMLUtil nuclear@19: { nuclear@19: public: nuclear@19: // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't nuclear@19: // correct, but simple, and usually works. nuclear@19: static const char* SkipWhiteSpace( const char* p ) { nuclear@19: while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast(p) ) ) { nuclear@19: ++p; nuclear@19: } nuclear@19: return p; nuclear@19: } nuclear@19: static char* SkipWhiteSpace( char* p ) { nuclear@19: while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast(p) ) ) { nuclear@19: ++p; nuclear@19: } nuclear@19: return p; nuclear@19: } nuclear@19: static bool IsWhiteSpace( char p ) { nuclear@19: return !IsUTF8Continuation(p) && isspace( static_cast(p) ); nuclear@19: } nuclear@19: nuclear@19: inline static bool IsNameStartChar( unsigned char ch ) { nuclear@19: return ( ( ch < 128 ) ? isalpha( ch ) : 1 ) nuclear@19: || ch == ':' nuclear@19: || ch == '_'; nuclear@19: } nuclear@19: nuclear@19: inline static bool IsNameChar( unsigned char ch ) { nuclear@19: return IsNameStartChar( ch ) nuclear@19: || isdigit( ch ) nuclear@19: || ch == '.' nuclear@19: || ch == '-'; nuclear@19: } nuclear@19: nuclear@19: inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) { nuclear@19: int n = 0; nuclear@19: if ( p == q ) { nuclear@19: return true; nuclear@19: } nuclear@19: while( *p && *q && *p == *q && n(const_cast(this)->FirstChildElement( value )); nuclear@19: } nuclear@19: nuclear@19: /// Get the last child node, or null if none exists. nuclear@19: const XMLNode* LastChild() const { nuclear@19: return _lastChild; nuclear@19: } nuclear@19: nuclear@19: XMLNode* LastChild() { nuclear@19: return const_cast(const_cast(this)->LastChild() ); nuclear@19: } nuclear@19: nuclear@19: /** Get the last child element or optionally the last child nuclear@19: element with the specified name. nuclear@19: */ nuclear@19: const XMLElement* LastChildElement( const char* value=0 ) const; nuclear@19: nuclear@19: XMLElement* LastChildElement( const char* value=0 ) { nuclear@19: return const_cast(const_cast(this)->LastChildElement(value) ); nuclear@19: } nuclear@19: nuclear@19: /// Get the previous (left) sibling node of this node. nuclear@19: const XMLNode* PreviousSibling() const { nuclear@19: return _prev; nuclear@19: } nuclear@19: nuclear@19: XMLNode* PreviousSibling() { nuclear@19: return _prev; nuclear@19: } nuclear@19: nuclear@19: /// Get the previous (left) sibling element of this node, with an optionally supplied name. nuclear@19: const XMLElement* PreviousSiblingElement( const char* value=0 ) const ; nuclear@19: nuclear@19: XMLElement* PreviousSiblingElement( const char* value=0 ) { nuclear@19: return const_cast(const_cast(this)->PreviousSiblingElement( value ) ); nuclear@19: } nuclear@19: nuclear@19: /// Get the next (right) sibling node of this node. nuclear@19: const XMLNode* NextSibling() const { nuclear@19: return _next; nuclear@19: } nuclear@19: nuclear@19: XMLNode* NextSibling() { nuclear@19: return _next; nuclear@19: } nuclear@19: nuclear@19: /// Get the next (right) sibling element of this node, with an optionally supplied name. nuclear@19: const XMLElement* NextSiblingElement( const char* value=0 ) const; nuclear@19: nuclear@19: XMLElement* NextSiblingElement( const char* value=0 ) { nuclear@19: return const_cast(const_cast(this)->NextSiblingElement( value ) ); nuclear@19: } nuclear@19: nuclear@19: /** nuclear@19: Add a child node as the last (right) child. nuclear@19: */ nuclear@19: XMLNode* InsertEndChild( XMLNode* addThis ); nuclear@19: nuclear@19: XMLNode* LinkEndChild( XMLNode* addThis ) { nuclear@19: return InsertEndChild( addThis ); nuclear@19: } nuclear@19: /** nuclear@19: Add a child node as the first (left) child. nuclear@19: */ nuclear@19: XMLNode* InsertFirstChild( XMLNode* addThis ); nuclear@19: /** nuclear@19: Add a node after the specified child node. nuclear@19: */ nuclear@19: XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ); nuclear@19: nuclear@19: /** nuclear@19: Delete all the children of this node. nuclear@19: */ nuclear@19: void DeleteChildren(); nuclear@19: nuclear@19: /** nuclear@19: Delete a child of this node. nuclear@19: */ nuclear@19: void DeleteChild( XMLNode* node ); nuclear@19: nuclear@19: /** nuclear@19: Make a copy of this node, but not its children. nuclear@19: You may pass in a Document pointer that will be nuclear@19: the owner of the new Node. If the 'document' is nuclear@19: null, then the node returned will be allocated nuclear@19: from the current Document. (this->GetDocument()) nuclear@19: nuclear@19: Note: if called on a XMLDocument, this will return null. nuclear@19: */ nuclear@19: virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0; nuclear@19: nuclear@19: /** nuclear@19: Test if 2 nodes are the same, but don't test children. nuclear@19: The 2 nodes do not need to be in the same Document. nuclear@19: nuclear@19: Note: if called on a XMLDocument, this will return false. nuclear@19: */ nuclear@19: virtual bool ShallowEqual( const XMLNode* compare ) const = 0; nuclear@19: nuclear@19: /** Accept a hierarchical visit of the nodes in the TinyXML-2 DOM. Every node in the nuclear@19: XML tree will be conditionally visited and the host will be called back nuclear@19: via the XMLVisitor interface. nuclear@19: nuclear@19: This is essentially a SAX interface for TinyXML-2. (Note however it doesn't re-parse nuclear@19: the XML for the callbacks, so the performance of TinyXML-2 is unchanged by using this nuclear@19: interface versus any other.) nuclear@19: nuclear@19: The interface has been based on ideas from: nuclear@19: nuclear@19: - http://www.saxproject.org/ nuclear@19: - http://c2.com/cgi/wiki?HierarchicalVisitorPattern nuclear@19: nuclear@19: Which are both good references for "visiting". nuclear@19: nuclear@19: An example of using Accept(): nuclear@19: @verbatim nuclear@19: XMLPrinter printer; nuclear@19: tinyxmlDoc.Accept( &printer ); nuclear@19: const char* xmlcstr = printer.CStr(); nuclear@19: @endverbatim nuclear@19: */ nuclear@19: virtual bool Accept( XMLVisitor* visitor ) const = 0; nuclear@19: nuclear@19: // internal nuclear@19: virtual char* ParseDeep( char*, StrPair* ); nuclear@19: nuclear@19: protected: nuclear@19: XMLNode( XMLDocument* ); nuclear@19: virtual ~XMLNode(); nuclear@19: XMLNode( const XMLNode& ); // not supported nuclear@19: XMLNode& operator=( const XMLNode& ); // not supported nuclear@19: nuclear@19: XMLDocument* _document; nuclear@19: XMLNode* _parent; nuclear@19: mutable StrPair _value; nuclear@19: nuclear@19: XMLNode* _firstChild; nuclear@19: XMLNode* _lastChild; nuclear@19: nuclear@19: XMLNode* _prev; nuclear@19: XMLNode* _next; nuclear@19: nuclear@19: private: nuclear@19: MemPool* _memPool; nuclear@19: void Unlink( XMLNode* child ); nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /** XML text. nuclear@19: nuclear@19: Note that a text node can have child element nodes, for example: nuclear@19: @verbatim nuclear@19: This is bold nuclear@19: @endverbatim nuclear@19: nuclear@19: A text node can have 2 ways to output the next. "normal" output nuclear@19: and CDATA. It will default to the mode it was parsed from the XML file and nuclear@19: you generally want to leave it alone, but you can change the output mode with nuclear@19: SetCData() and query it with CData(). nuclear@19: */ nuclear@19: class TINYXML2_LIB XMLText : public XMLNode nuclear@19: { nuclear@19: friend class XMLBase; nuclear@19: friend class XMLDocument; nuclear@19: public: nuclear@19: virtual bool Accept( XMLVisitor* visitor ) const; nuclear@19: nuclear@19: virtual XMLText* ToText() { nuclear@19: return this; nuclear@19: } nuclear@19: virtual const XMLText* ToText() const { nuclear@19: return this; nuclear@19: } nuclear@19: nuclear@19: /// Declare whether this should be CDATA or standard text. nuclear@19: void SetCData( bool isCData ) { nuclear@19: _isCData = isCData; nuclear@19: } nuclear@19: /// Returns true if this is a CDATA text element. nuclear@19: bool CData() const { nuclear@19: return _isCData; nuclear@19: } nuclear@19: nuclear@19: char* ParseDeep( char*, StrPair* endTag ); nuclear@19: virtual XMLNode* ShallowClone( XMLDocument* document ) const; nuclear@19: virtual bool ShallowEqual( const XMLNode* compare ) const; nuclear@19: nuclear@19: protected: nuclear@19: XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {} nuclear@19: virtual ~XMLText() {} nuclear@19: XMLText( const XMLText& ); // not supported nuclear@19: XMLText& operator=( const XMLText& ); // not supported nuclear@19: nuclear@19: private: nuclear@19: bool _isCData; nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /** An XML Comment. */ nuclear@19: class TINYXML2_LIB XMLComment : public XMLNode nuclear@19: { nuclear@19: friend class XMLDocument; nuclear@19: public: nuclear@19: virtual XMLComment* ToComment() { nuclear@19: return this; nuclear@19: } nuclear@19: virtual const XMLComment* ToComment() const { nuclear@19: return this; nuclear@19: } nuclear@19: nuclear@19: virtual bool Accept( XMLVisitor* visitor ) const; nuclear@19: nuclear@19: char* ParseDeep( char*, StrPair* endTag ); nuclear@19: virtual XMLNode* ShallowClone( XMLDocument* document ) const; nuclear@19: virtual bool ShallowEqual( const XMLNode* compare ) const; nuclear@19: nuclear@19: protected: nuclear@19: XMLComment( XMLDocument* doc ); nuclear@19: virtual ~XMLComment(); nuclear@19: XMLComment( const XMLComment& ); // not supported nuclear@19: XMLComment& operator=( const XMLComment& ); // not supported nuclear@19: nuclear@19: private: nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /** In correct XML the declaration is the first entry in the file. nuclear@19: @verbatim nuclear@19: nuclear@19: @endverbatim nuclear@19: nuclear@19: TinyXML-2 will happily read or write files without a declaration, nuclear@19: however. nuclear@19: nuclear@19: The text of the declaration isn't interpreted. It is parsed nuclear@19: and written as a string. nuclear@19: */ nuclear@19: class TINYXML2_LIB XMLDeclaration : public XMLNode nuclear@19: { nuclear@19: friend class XMLDocument; nuclear@19: public: nuclear@19: virtual XMLDeclaration* ToDeclaration() { nuclear@19: return this; nuclear@19: } nuclear@19: virtual const XMLDeclaration* ToDeclaration() const { nuclear@19: return this; nuclear@19: } nuclear@19: nuclear@19: virtual bool Accept( XMLVisitor* visitor ) const; nuclear@19: nuclear@19: char* ParseDeep( char*, StrPair* endTag ); nuclear@19: virtual XMLNode* ShallowClone( XMLDocument* document ) const; nuclear@19: virtual bool ShallowEqual( const XMLNode* compare ) const; nuclear@19: nuclear@19: protected: nuclear@19: XMLDeclaration( XMLDocument* doc ); nuclear@19: virtual ~XMLDeclaration(); nuclear@19: XMLDeclaration( const XMLDeclaration& ); // not supported nuclear@19: XMLDeclaration& operator=( const XMLDeclaration& ); // not supported nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /** Any tag that TinyXML-2 doesn't recognize is saved as an nuclear@19: unknown. It is a tag of text, but should not be modified. nuclear@19: It will be written back to the XML, unchanged, when the file nuclear@19: is saved. nuclear@19: nuclear@19: DTD tags get thrown into XMLUnknowns. nuclear@19: */ nuclear@19: class TINYXML2_LIB XMLUnknown : public XMLNode nuclear@19: { nuclear@19: friend class XMLDocument; nuclear@19: public: nuclear@19: virtual XMLUnknown* ToUnknown() { nuclear@19: return this; nuclear@19: } nuclear@19: virtual const XMLUnknown* ToUnknown() const { nuclear@19: return this; nuclear@19: } nuclear@19: nuclear@19: virtual bool Accept( XMLVisitor* visitor ) const; nuclear@19: nuclear@19: char* ParseDeep( char*, StrPair* endTag ); nuclear@19: virtual XMLNode* ShallowClone( XMLDocument* document ) const; nuclear@19: virtual bool ShallowEqual( const XMLNode* compare ) const; nuclear@19: nuclear@19: protected: nuclear@19: XMLUnknown( XMLDocument* doc ); nuclear@19: virtual ~XMLUnknown(); nuclear@19: XMLUnknown( const XMLUnknown& ); // not supported nuclear@19: XMLUnknown& operator=( const XMLUnknown& ); // not supported nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: enum XMLError { nuclear@19: XML_NO_ERROR = 0, nuclear@19: XML_SUCCESS = 0, nuclear@19: nuclear@19: XML_NO_ATTRIBUTE, nuclear@19: XML_WRONG_ATTRIBUTE_TYPE, nuclear@19: nuclear@19: XML_ERROR_FILE_NOT_FOUND, nuclear@19: XML_ERROR_FILE_COULD_NOT_BE_OPENED, nuclear@19: XML_ERROR_FILE_READ_ERROR, nuclear@19: XML_ERROR_ELEMENT_MISMATCH, nuclear@19: XML_ERROR_PARSING_ELEMENT, nuclear@19: XML_ERROR_PARSING_ATTRIBUTE, nuclear@19: XML_ERROR_IDENTIFYING_TAG, nuclear@19: XML_ERROR_PARSING_TEXT, nuclear@19: XML_ERROR_PARSING_CDATA, nuclear@19: XML_ERROR_PARSING_COMMENT, nuclear@19: XML_ERROR_PARSING_DECLARATION, nuclear@19: XML_ERROR_PARSING_UNKNOWN, nuclear@19: XML_ERROR_EMPTY_DOCUMENT, nuclear@19: XML_ERROR_MISMATCHED_ELEMENT, nuclear@19: XML_ERROR_PARSING, nuclear@19: nuclear@19: XML_CAN_NOT_CONVERT_TEXT, nuclear@19: XML_NO_TEXT_NODE nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /** An attribute is a name-value pair. Elements have an arbitrary nuclear@19: number of attributes, each with a unique name. nuclear@19: nuclear@19: @note The attributes are not XMLNodes. You may only query the nuclear@19: Next() attribute in a list. nuclear@19: */ nuclear@19: class TINYXML2_LIB XMLAttribute nuclear@19: { nuclear@19: friend class XMLElement; nuclear@19: public: nuclear@19: /// The name of the attribute. nuclear@19: const char* Name() const { nuclear@19: return _name.GetStr(); nuclear@19: } nuclear@19: /// The value of the attribute. nuclear@19: const char* Value() const { nuclear@19: return _value.GetStr(); nuclear@19: } nuclear@19: /// The next attribute in the list. nuclear@19: const XMLAttribute* Next() const { nuclear@19: return _next; nuclear@19: } nuclear@19: nuclear@19: /** IntValue interprets the attribute as an integer, and returns the value. nuclear@19: If the value isn't an integer, 0 will be returned. There is no error checking; nuclear@19: use QueryIntValue() if you need error checking. nuclear@19: */ nuclear@19: int IntValue() const { nuclear@19: int i=0; nuclear@19: QueryIntValue( &i ); nuclear@19: return i; nuclear@19: } nuclear@19: /// Query as an unsigned integer. See IntValue() nuclear@19: unsigned UnsignedValue() const { nuclear@19: unsigned i=0; nuclear@19: QueryUnsignedValue( &i ); nuclear@19: return i; nuclear@19: } nuclear@19: /// Query as a boolean. See IntValue() nuclear@19: bool BoolValue() const { nuclear@19: bool b=false; nuclear@19: QueryBoolValue( &b ); nuclear@19: return b; nuclear@19: } nuclear@19: /// Query as a double. See IntValue() nuclear@19: double DoubleValue() const { nuclear@19: double d=0; nuclear@19: QueryDoubleValue( &d ); nuclear@19: return d; nuclear@19: } nuclear@19: /// Query as a float. See IntValue() nuclear@19: float FloatValue() const { nuclear@19: float f=0; nuclear@19: QueryFloatValue( &f ); nuclear@19: return f; nuclear@19: } nuclear@19: nuclear@19: /** QueryIntValue interprets the attribute as an integer, and returns the value nuclear@19: in the provided parameter. The function will return XML_NO_ERROR on success, nuclear@19: and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful. nuclear@19: */ nuclear@19: XMLError QueryIntValue( int* value ) const; nuclear@19: /// See QueryIntValue nuclear@19: XMLError QueryUnsignedValue( unsigned int* value ) const; nuclear@19: /// See QueryIntValue nuclear@19: XMLError QueryBoolValue( bool* value ) const; nuclear@19: /// See QueryIntValue nuclear@19: XMLError QueryDoubleValue( double* value ) const; nuclear@19: /// See QueryIntValue nuclear@19: XMLError QueryFloatValue( float* value ) const; nuclear@19: nuclear@19: /// Set the attribute to a string value. nuclear@19: void SetAttribute( const char* value ); nuclear@19: /// Set the attribute to value. nuclear@19: void SetAttribute( int value ); nuclear@19: /// Set the attribute to value. nuclear@19: void SetAttribute( unsigned value ); nuclear@19: /// Set the attribute to value. nuclear@19: void SetAttribute( bool value ); nuclear@19: /// Set the attribute to value. nuclear@19: void SetAttribute( double value ); nuclear@19: /// Set the attribute to value. nuclear@19: void SetAttribute( float value ); nuclear@19: nuclear@19: private: nuclear@19: enum { BUF_SIZE = 200 }; nuclear@19: nuclear@19: XMLAttribute() : _next( 0 ), _memPool( 0 ) {} nuclear@19: virtual ~XMLAttribute() {} nuclear@19: nuclear@19: XMLAttribute( const XMLAttribute& ); // not supported nuclear@19: void operator=( const XMLAttribute& ); // not supported nuclear@19: void SetName( const char* name ); nuclear@19: nuclear@19: char* ParseDeep( char* p, bool processEntities ); nuclear@19: nuclear@19: mutable StrPair _name; nuclear@19: mutable StrPair _value; nuclear@19: XMLAttribute* _next; nuclear@19: MemPool* _memPool; nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /** The element is a container class. It has a value, the element name, nuclear@19: and can contain other elements, text, comments, and unknowns. nuclear@19: Elements also contain an arbitrary number of attributes. nuclear@19: */ nuclear@19: class TINYXML2_LIB XMLElement : public XMLNode nuclear@19: { nuclear@19: friend class XMLBase; nuclear@19: friend class XMLDocument; nuclear@19: public: nuclear@19: /// Get the name of an element (which is the Value() of the node.) nuclear@19: const char* Name() const { nuclear@19: return Value(); nuclear@19: } nuclear@19: /// Set the name of the element. nuclear@19: void SetName( const char* str, bool staticMem=false ) { nuclear@19: SetValue( str, staticMem ); nuclear@19: } nuclear@19: nuclear@19: virtual XMLElement* ToElement() { nuclear@19: return this; nuclear@19: } nuclear@19: virtual const XMLElement* ToElement() const { nuclear@19: return this; nuclear@19: } nuclear@19: virtual bool Accept( XMLVisitor* visitor ) const; nuclear@19: nuclear@19: /** Given an attribute name, Attribute() returns the value nuclear@19: for the attribute of that name, or null if none nuclear@19: exists. For example: nuclear@19: nuclear@19: @verbatim nuclear@19: const char* value = ele->Attribute( "foo" ); nuclear@19: @endverbatim nuclear@19: nuclear@19: The 'value' parameter is normally null. However, if specified, nuclear@19: the attribute will only be returned if the 'name' and 'value' nuclear@19: match. This allow you to write code: nuclear@19: nuclear@19: @verbatim nuclear@19: if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar(); nuclear@19: @endverbatim nuclear@19: nuclear@19: rather than: nuclear@19: @verbatim nuclear@19: if ( ele->Attribute( "foo" ) ) { nuclear@19: if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar(); nuclear@19: } nuclear@19: @endverbatim nuclear@19: */ nuclear@19: const char* Attribute( const char* name, const char* value=0 ) const; nuclear@19: nuclear@19: /** Given an attribute name, IntAttribute() returns the value nuclear@19: of the attribute interpreted as an integer. 0 will be nuclear@19: returned if there is an error. For a method with error nuclear@19: checking, see QueryIntAttribute() nuclear@19: */ nuclear@19: int IntAttribute( const char* name ) const { nuclear@19: int i=0; nuclear@19: QueryIntAttribute( name, &i ); nuclear@19: return i; nuclear@19: } nuclear@19: /// See IntAttribute() nuclear@19: unsigned UnsignedAttribute( const char* name ) const { nuclear@19: unsigned i=0; nuclear@19: QueryUnsignedAttribute( name, &i ); nuclear@19: return i; nuclear@19: } nuclear@19: /// See IntAttribute() nuclear@19: bool BoolAttribute( const char* name ) const { nuclear@19: bool b=false; nuclear@19: QueryBoolAttribute( name, &b ); nuclear@19: return b; nuclear@19: } nuclear@19: /// See IntAttribute() nuclear@19: double DoubleAttribute( const char* name ) const { nuclear@19: double d=0; nuclear@19: QueryDoubleAttribute( name, &d ); nuclear@19: return d; nuclear@19: } nuclear@19: /// See IntAttribute() nuclear@19: float FloatAttribute( const char* name ) const { nuclear@19: float f=0; nuclear@19: QueryFloatAttribute( name, &f ); nuclear@19: return f; nuclear@19: } nuclear@19: nuclear@19: /** Given an attribute name, QueryIntAttribute() returns nuclear@19: XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion nuclear@19: can't be performed, or XML_NO_ATTRIBUTE if the attribute nuclear@19: doesn't exist. If successful, the result of the conversion nuclear@19: will be written to 'value'. If not successful, nothing will nuclear@19: be written to 'value'. This allows you to provide default nuclear@19: value: nuclear@19: nuclear@19: @verbatim nuclear@19: int value = 10; nuclear@19: QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 nuclear@19: @endverbatim nuclear@19: */ nuclear@19: XMLError QueryIntAttribute( const char* name, int* value ) const { nuclear@19: const XMLAttribute* a = FindAttribute( name ); nuclear@19: if ( !a ) { nuclear@19: return XML_NO_ATTRIBUTE; nuclear@19: } nuclear@19: return a->QueryIntValue( value ); nuclear@19: } nuclear@19: /// See QueryIntAttribute() nuclear@19: XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const { nuclear@19: const XMLAttribute* a = FindAttribute( name ); nuclear@19: if ( !a ) { nuclear@19: return XML_NO_ATTRIBUTE; nuclear@19: } nuclear@19: return a->QueryUnsignedValue( value ); nuclear@19: } nuclear@19: /// See QueryIntAttribute() nuclear@19: XMLError QueryBoolAttribute( const char* name, bool* value ) const { nuclear@19: const XMLAttribute* a = FindAttribute( name ); nuclear@19: if ( !a ) { nuclear@19: return XML_NO_ATTRIBUTE; nuclear@19: } nuclear@19: return a->QueryBoolValue( value ); nuclear@19: } nuclear@19: /// See QueryIntAttribute() nuclear@19: XMLError QueryDoubleAttribute( const char* name, double* value ) const { nuclear@19: const XMLAttribute* a = FindAttribute( name ); nuclear@19: if ( !a ) { nuclear@19: return XML_NO_ATTRIBUTE; nuclear@19: } nuclear@19: return a->QueryDoubleValue( value ); nuclear@19: } nuclear@19: /// See QueryIntAttribute() nuclear@19: XMLError QueryFloatAttribute( const char* name, float* value ) const { nuclear@19: const XMLAttribute* a = FindAttribute( name ); nuclear@19: if ( !a ) { nuclear@19: return XML_NO_ATTRIBUTE; nuclear@19: } nuclear@19: return a->QueryFloatValue( value ); nuclear@19: } nuclear@19: nuclear@19: nuclear@19: /** Given an attribute name, QueryAttribute() returns nuclear@19: XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion nuclear@19: can't be performed, or XML_NO_ATTRIBUTE if the attribute nuclear@19: doesn't exist. It is overloaded for the primitive types, nuclear@19: and is a generally more convenient replacement of nuclear@19: QueryIntAttribute() and related functions. nuclear@19: nuclear@19: If successful, the result of the conversion nuclear@19: will be written to 'value'. If not successful, nothing will nuclear@19: be written to 'value'. This allows you to provide default nuclear@19: value: nuclear@19: nuclear@19: @verbatim nuclear@19: int value = 10; nuclear@19: QueryAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 nuclear@19: @endverbatim nuclear@19: */ nuclear@19: int QueryAttribute( const char* name, int* value ) const { nuclear@19: return QueryIntAttribute( name, value ); nuclear@19: } nuclear@19: nuclear@19: int QueryAttribute( const char* name, unsigned int* value ) const { nuclear@19: return QueryUnsignedAttribute( name, value ); nuclear@19: } nuclear@19: nuclear@19: int QueryAttribute( const char* name, bool* value ) const { nuclear@19: return QueryBoolAttribute( name, value ); nuclear@19: } nuclear@19: nuclear@19: int QueryAttribute( const char* name, double* value ) const { nuclear@19: return QueryDoubleAttribute( name, value ); nuclear@19: } nuclear@19: nuclear@19: int QueryAttribute( const char* name, float* value ) const { nuclear@19: return QueryFloatAttribute( name, value ); nuclear@19: } nuclear@19: nuclear@19: /// Sets the named attribute to value. nuclear@19: void SetAttribute( const char* name, const char* value ) { nuclear@19: XMLAttribute* a = FindOrCreateAttribute( name ); nuclear@19: a->SetAttribute( value ); nuclear@19: } nuclear@19: /// Sets the named attribute to value. nuclear@19: void SetAttribute( const char* name, int value ) { nuclear@19: XMLAttribute* a = FindOrCreateAttribute( name ); nuclear@19: a->SetAttribute( value ); nuclear@19: } nuclear@19: /// Sets the named attribute to value. nuclear@19: void SetAttribute( const char* name, unsigned value ) { nuclear@19: XMLAttribute* a = FindOrCreateAttribute( name ); nuclear@19: a->SetAttribute( value ); nuclear@19: } nuclear@19: /// Sets the named attribute to value. nuclear@19: void SetAttribute( const char* name, bool value ) { nuclear@19: XMLAttribute* a = FindOrCreateAttribute( name ); nuclear@19: a->SetAttribute( value ); nuclear@19: } nuclear@19: /// Sets the named attribute to value. nuclear@19: void SetAttribute( const char* name, double value ) { nuclear@19: XMLAttribute* a = FindOrCreateAttribute( name ); nuclear@19: a->SetAttribute( value ); nuclear@19: } nuclear@19: nuclear@19: /** nuclear@19: Delete an attribute. nuclear@19: */ nuclear@19: void DeleteAttribute( const char* name ); nuclear@19: nuclear@19: /// Return the first attribute in the list. nuclear@19: const XMLAttribute* FirstAttribute() const { nuclear@19: return _rootAttribute; nuclear@19: } nuclear@19: /// Query a specific attribute in the list. nuclear@19: const XMLAttribute* FindAttribute( const char* name ) const; nuclear@19: nuclear@19: /** Convenience function for easy access to the text inside an element. Although easy nuclear@19: and concise, GetText() is limited compared to getting the XMLText child nuclear@19: and accessing it directly. nuclear@19: nuclear@19: If the first child of 'this' is a XMLText, the GetText() nuclear@19: returns the character string of the Text node, else null is returned. nuclear@19: nuclear@19: This is a convenient method for getting the text of simple contained text: nuclear@19: @verbatim nuclear@19: This is text nuclear@19: const char* str = fooElement->GetText(); nuclear@19: @endverbatim nuclear@19: nuclear@19: 'str' will be a pointer to "This is text". nuclear@19: nuclear@19: Note that this function can be misleading. If the element foo was created from nuclear@19: this XML: nuclear@19: @verbatim nuclear@19: This is text nuclear@19: @endverbatim nuclear@19: nuclear@19: then the value of str would be null. The first child node isn't a text node, it is nuclear@19: another element. From this XML: nuclear@19: @verbatim nuclear@19: This is text nuclear@19: @endverbatim nuclear@19: GetText() will return "This is ". nuclear@19: */ nuclear@19: const char* GetText() const; nuclear@19: nuclear@19: /** nuclear@19: Convenience method to query the value of a child text node. This is probably best nuclear@19: shown by example. Given you have a document is this form: nuclear@19: @verbatim nuclear@19: nuclear@19: 1 nuclear@19: 1.4 nuclear@19: nuclear@19: @endverbatim nuclear@19: nuclear@19: The QueryIntText() and similar functions provide a safe and easier way to get to the nuclear@19: "value" of x and y. nuclear@19: nuclear@19: @verbatim nuclear@19: int x = 0; nuclear@19: float y = 0; // types of x and y are contrived for example nuclear@19: const XMLElement* xElement = pointElement->FirstChildElement( "x" ); nuclear@19: const XMLElement* yElement = pointElement->FirstChildElement( "y" ); nuclear@19: xElement->QueryIntText( &x ); nuclear@19: yElement->QueryFloatText( &y ); nuclear@19: @endverbatim nuclear@19: nuclear@19: @returns XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted nuclear@19: to the requested type, and XML_NO_TEXT_NODE if there is no child text to query. nuclear@19: nuclear@19: */ nuclear@19: XMLError QueryIntText( int* ival ) const; nuclear@19: /// See QueryIntText() nuclear@19: XMLError QueryUnsignedText( unsigned* uval ) const; nuclear@19: /// See QueryIntText() nuclear@19: XMLError QueryBoolText( bool* bval ) const; nuclear@19: /// See QueryIntText() nuclear@19: XMLError QueryDoubleText( double* dval ) const; nuclear@19: /// See QueryIntText() nuclear@19: XMLError QueryFloatText( float* fval ) const; nuclear@19: nuclear@19: // internal: nuclear@19: enum { nuclear@19: OPEN, // nuclear@19: CLOSED, // nuclear@19: CLOSING // nuclear@19: }; nuclear@19: int ClosingType() const { nuclear@19: return _closingType; nuclear@19: } nuclear@19: char* ParseDeep( char* p, StrPair* endTag ); nuclear@19: virtual XMLNode* ShallowClone( XMLDocument* document ) const; nuclear@19: virtual bool ShallowEqual( const XMLNode* compare ) const; nuclear@19: nuclear@19: private: nuclear@19: XMLElement( XMLDocument* doc ); nuclear@19: virtual ~XMLElement(); nuclear@19: XMLElement( const XMLElement& ); // not supported nuclear@19: void operator=( const XMLElement& ); // not supported nuclear@19: nuclear@19: XMLAttribute* FindAttribute( const char* name ); nuclear@19: XMLAttribute* FindOrCreateAttribute( const char* name ); nuclear@19: //void LinkAttribute( XMLAttribute* attrib ); nuclear@19: char* ParseAttributes( char* p ); nuclear@19: nuclear@19: int _closingType; nuclear@19: // The attribute list is ordered; there is no 'lastAttribute' nuclear@19: // because the list needs to be scanned for dupes before adding nuclear@19: // a new attribute. nuclear@19: XMLAttribute* _rootAttribute; nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: enum Whitespace { nuclear@19: PRESERVE_WHITESPACE, nuclear@19: COLLAPSE_WHITESPACE nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /** A Document binds together all the functionality. nuclear@19: It can be saved, loaded, and printed to the screen. nuclear@19: All Nodes are connected and allocated to a Document. nuclear@19: If the Document is deleted, all its Nodes are also deleted. nuclear@19: */ nuclear@19: class TINYXML2_LIB XMLDocument : public XMLNode nuclear@19: { nuclear@19: friend class XMLElement; nuclear@19: public: nuclear@19: /// constructor nuclear@19: XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE ); nuclear@19: ~XMLDocument(); nuclear@19: nuclear@19: virtual XMLDocument* ToDocument() { nuclear@19: return this; nuclear@19: } nuclear@19: virtual const XMLDocument* ToDocument() const { nuclear@19: return this; nuclear@19: } nuclear@19: nuclear@19: /** nuclear@19: Parse an XML file from a character string. nuclear@19: Returns XML_NO_ERROR (0) on success, or nuclear@19: an errorID. nuclear@19: nuclear@19: You may optionally pass in the 'nBytes', which is nuclear@19: the number of bytes which will be parsed. If not nuclear@19: specified, TinyXML-2 will assume 'xml' points to a nuclear@19: null terminated string. nuclear@19: */ nuclear@19: XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) ); nuclear@19: nuclear@19: /** nuclear@19: Load an XML file from disk. nuclear@19: Returns XML_NO_ERROR (0) on success, or nuclear@19: an errorID. nuclear@19: */ nuclear@19: XMLError LoadFile( const char* filename ); nuclear@19: nuclear@19: /** nuclear@19: Load an XML file from disk. You are responsible nuclear@19: for providing and closing the FILE*. nuclear@19: nuclear@19: Returns XML_NO_ERROR (0) on success, or nuclear@19: an errorID. nuclear@19: */ nuclear@19: XMLError LoadFile( FILE* ); nuclear@19: nuclear@19: /** nuclear@19: Save the XML file to disk. nuclear@19: Returns XML_NO_ERROR (0) on success, or nuclear@19: an errorID. nuclear@19: */ nuclear@19: XMLError SaveFile( const char* filename, bool compact = false ); nuclear@19: nuclear@19: /** nuclear@19: Save the XML file to disk. You are responsible nuclear@19: for providing and closing the FILE*. nuclear@19: nuclear@19: Returns XML_NO_ERROR (0) on success, or nuclear@19: an errorID. nuclear@19: */ nuclear@19: XMLError SaveFile( FILE* fp, bool compact = false ); nuclear@19: nuclear@19: bool ProcessEntities() const { nuclear@19: return _processEntities; nuclear@19: } nuclear@19: Whitespace WhitespaceMode() const { nuclear@19: return _whitespace; nuclear@19: } nuclear@19: nuclear@19: /** nuclear@19: Returns true if this document has a leading Byte Order Mark of UTF8. nuclear@19: */ nuclear@19: bool HasBOM() const { nuclear@19: return _writeBOM; nuclear@19: } nuclear@19: /** Sets whether to write the BOM when writing the file. nuclear@19: */ nuclear@19: void SetBOM( bool useBOM ) { nuclear@19: _writeBOM = useBOM; nuclear@19: } nuclear@19: nuclear@19: /** Return the root element of DOM. Equivalent to FirstChildElement(). nuclear@19: To get the first node, use FirstChild(). nuclear@19: */ nuclear@19: XMLElement* RootElement() { nuclear@19: return FirstChildElement(); nuclear@19: } nuclear@19: const XMLElement* RootElement() const { nuclear@19: return FirstChildElement(); nuclear@19: } nuclear@19: nuclear@19: /** Print the Document. If the Printer is not provided, it will nuclear@19: print to stdout. If you provide Printer, this can print to a file: nuclear@19: @verbatim nuclear@19: XMLPrinter printer( fp ); nuclear@19: doc.Print( &printer ); nuclear@19: @endverbatim nuclear@19: nuclear@19: Or you can use a printer to print to memory: nuclear@19: @verbatim nuclear@19: XMLPrinter printer; nuclear@19: doc.Print( &printer ); nuclear@19: // printer.CStr() has a const char* to the XML nuclear@19: @endverbatim nuclear@19: */ nuclear@19: void Print( XMLPrinter* streamer=0 ) const; nuclear@19: virtual bool Accept( XMLVisitor* visitor ) const; nuclear@19: nuclear@19: /** nuclear@19: Create a new Element associated with nuclear@19: this Document. The memory for the Element nuclear@19: is managed by the Document. nuclear@19: */ nuclear@19: XMLElement* NewElement( const char* name ); nuclear@19: /** nuclear@19: Create a new Comment associated with nuclear@19: this Document. The memory for the Comment nuclear@19: is managed by the Document. nuclear@19: */ nuclear@19: XMLComment* NewComment( const char* comment ); nuclear@19: /** nuclear@19: Create a new Text associated with nuclear@19: this Document. The memory for the Text nuclear@19: is managed by the Document. nuclear@19: */ nuclear@19: XMLText* NewText( const char* text ); nuclear@19: /** nuclear@19: Create a new Declaration associated with nuclear@19: this Document. The memory for the object nuclear@19: is managed by the Document. nuclear@19: nuclear@19: If the 'text' param is null, the standard nuclear@19: declaration is used.: nuclear@19: @verbatim nuclear@19: nuclear@19: @endverbatim nuclear@19: */ nuclear@19: XMLDeclaration* NewDeclaration( const char* text=0 ); nuclear@19: /** nuclear@19: Create a new Unknown associated with nuclear@19: this Document. The memory for the object nuclear@19: is managed by the Document. nuclear@19: */ nuclear@19: XMLUnknown* NewUnknown( const char* text ); nuclear@19: nuclear@19: /** nuclear@19: Delete a node associated with this document. nuclear@19: It will be unlinked from the DOM. nuclear@19: */ nuclear@19: void DeleteNode( XMLNode* node ) { nuclear@19: node->_parent->DeleteChild( node ); nuclear@19: } nuclear@19: nuclear@19: void SetError( XMLError error, const char* str1, const char* str2 ); nuclear@19: nuclear@19: /// Return true if there was an error parsing the document. nuclear@19: bool Error() const { nuclear@19: return _errorID != XML_NO_ERROR; nuclear@19: } nuclear@19: /// Return the errorID. nuclear@19: XMLError ErrorID() const { nuclear@19: return _errorID; nuclear@19: } nuclear@19: /// Return a possibly helpful diagnostic location or string. nuclear@19: const char* GetErrorStr1() const { nuclear@19: return _errorStr1; nuclear@19: } nuclear@19: /// Return a possibly helpful secondary diagnostic location or string. nuclear@19: const char* GetErrorStr2() const { nuclear@19: return _errorStr2; nuclear@19: } nuclear@19: /// If there is an error, print it to stdout. nuclear@19: void PrintError() const; nuclear@19: nuclear@19: /// Clear the document, resetting it to the initial state. nuclear@19: void Clear(); nuclear@19: nuclear@19: // internal nuclear@19: char* Identify( char* p, XMLNode** node ); nuclear@19: nuclear@19: virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const { nuclear@19: return 0; nuclear@19: } nuclear@19: virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const { nuclear@19: return false; nuclear@19: } nuclear@19: nuclear@19: private: nuclear@19: XMLDocument( const XMLDocument& ); // not supported nuclear@19: void operator=( const XMLDocument& ); // not supported nuclear@19: nuclear@19: bool _writeBOM; nuclear@19: bool _processEntities; nuclear@19: XMLError _errorID; nuclear@19: Whitespace _whitespace; nuclear@19: const char* _errorStr1; nuclear@19: const char* _errorStr2; nuclear@19: char* _charBuffer; nuclear@19: nuclear@19: MemPoolT< sizeof(XMLElement) > _elementPool; nuclear@19: MemPoolT< sizeof(XMLAttribute) > _attributePool; nuclear@19: MemPoolT< sizeof(XMLText) > _textPool; nuclear@19: MemPoolT< sizeof(XMLComment) > _commentPool; nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /** nuclear@19: A XMLHandle is a class that wraps a node pointer with null checks; this is nuclear@19: an incredibly useful thing. Note that XMLHandle is not part of the TinyXML-2 nuclear@19: DOM structure. It is a separate utility class. nuclear@19: nuclear@19: Take an example: nuclear@19: @verbatim nuclear@19: nuclear@19: nuclear@19: nuclear@19: nuclear@19: nuclear@19: nuclear@19: @endverbatim nuclear@19: nuclear@19: Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very nuclear@19: easy to write a *lot* of code that looks like: nuclear@19: nuclear@19: @verbatim nuclear@19: XMLElement* root = document.FirstChildElement( "Document" ); nuclear@19: if ( root ) nuclear@19: { nuclear@19: XMLElement* element = root->FirstChildElement( "Element" ); nuclear@19: if ( element ) nuclear@19: { nuclear@19: XMLElement* child = element->FirstChildElement( "Child" ); nuclear@19: if ( child ) nuclear@19: { nuclear@19: XMLElement* child2 = child->NextSiblingElement( "Child" ); nuclear@19: if ( child2 ) nuclear@19: { nuclear@19: // Finally do something useful. nuclear@19: @endverbatim nuclear@19: nuclear@19: And that doesn't even cover "else" cases. XMLHandle addresses the verbosity nuclear@19: of such code. A XMLHandle checks for null pointers so it is perfectly safe nuclear@19: and correct to use: nuclear@19: nuclear@19: @verbatim nuclear@19: XMLHandle docHandle( &document ); nuclear@19: XMLElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild().NextSibling().ToElement(); nuclear@19: if ( child2 ) nuclear@19: { nuclear@19: // do something useful nuclear@19: @endverbatim nuclear@19: nuclear@19: Which is MUCH more concise and useful. nuclear@19: nuclear@19: It is also safe to copy handles - internally they are nothing more than node pointers. nuclear@19: @verbatim nuclear@19: XMLHandle handleCopy = handle; nuclear@19: @endverbatim nuclear@19: nuclear@19: See also XMLConstHandle, which is the same as XMLHandle, but operates on const objects. nuclear@19: */ nuclear@19: class TINYXML2_LIB XMLHandle nuclear@19: { nuclear@19: public: nuclear@19: /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. nuclear@19: XMLHandle( XMLNode* node ) { nuclear@19: _node = node; nuclear@19: } nuclear@19: /// Create a handle from a node. nuclear@19: XMLHandle( XMLNode& node ) { nuclear@19: _node = &node; nuclear@19: } nuclear@19: /// Copy constructor nuclear@19: XMLHandle( const XMLHandle& ref ) { nuclear@19: _node = ref._node; nuclear@19: } nuclear@19: /// Assignment nuclear@19: XMLHandle& operator=( const XMLHandle& ref ) { nuclear@19: _node = ref._node; nuclear@19: return *this; nuclear@19: } nuclear@19: nuclear@19: /// Get the first child of this handle. nuclear@19: XMLHandle FirstChild() { nuclear@19: return XMLHandle( _node ? _node->FirstChild() : 0 ); nuclear@19: } nuclear@19: /// Get the first child element of this handle. nuclear@19: XMLHandle FirstChildElement( const char* value=0 ) { nuclear@19: return XMLHandle( _node ? _node->FirstChildElement( value ) : 0 ); nuclear@19: } nuclear@19: /// Get the last child of this handle. nuclear@19: XMLHandle LastChild() { nuclear@19: return XMLHandle( _node ? _node->LastChild() : 0 ); nuclear@19: } nuclear@19: /// Get the last child element of this handle. nuclear@19: XMLHandle LastChildElement( const char* _value=0 ) { nuclear@19: return XMLHandle( _node ? _node->LastChildElement( _value ) : 0 ); nuclear@19: } nuclear@19: /// Get the previous sibling of this handle. nuclear@19: XMLHandle PreviousSibling() { nuclear@19: return XMLHandle( _node ? _node->PreviousSibling() : 0 ); nuclear@19: } nuclear@19: /// Get the previous sibling element of this handle. nuclear@19: XMLHandle PreviousSiblingElement( const char* _value=0 ) { nuclear@19: return XMLHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 ); nuclear@19: } nuclear@19: /// Get the next sibling of this handle. nuclear@19: XMLHandle NextSibling() { nuclear@19: return XMLHandle( _node ? _node->NextSibling() : 0 ); nuclear@19: } nuclear@19: /// Get the next sibling element of this handle. nuclear@19: XMLHandle NextSiblingElement( const char* _value=0 ) { nuclear@19: return XMLHandle( _node ? _node->NextSiblingElement( _value ) : 0 ); nuclear@19: } nuclear@19: nuclear@19: /// Safe cast to XMLNode. This can return null. nuclear@19: XMLNode* ToNode() { nuclear@19: return _node; nuclear@19: } nuclear@19: /// Safe cast to XMLElement. This can return null. nuclear@19: XMLElement* ToElement() { nuclear@19: return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 ); nuclear@19: } nuclear@19: /// Safe cast to XMLText. This can return null. nuclear@19: XMLText* ToText() { nuclear@19: return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 ); nuclear@19: } nuclear@19: /// Safe cast to XMLUnknown. This can return null. nuclear@19: XMLUnknown* ToUnknown() { nuclear@19: return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 ); nuclear@19: } nuclear@19: /// Safe cast to XMLDeclaration. This can return null. nuclear@19: XMLDeclaration* ToDeclaration() { nuclear@19: return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 ); nuclear@19: } nuclear@19: nuclear@19: private: nuclear@19: XMLNode* _node; nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /** nuclear@19: A variant of the XMLHandle class for working with const XMLNodes and Documents. It is the nuclear@19: same in all regards, except for the 'const' qualifiers. See XMLHandle for API. nuclear@19: */ nuclear@19: class TINYXML2_LIB XMLConstHandle nuclear@19: { nuclear@19: public: nuclear@19: XMLConstHandle( const XMLNode* node ) { nuclear@19: _node = node; nuclear@19: } nuclear@19: XMLConstHandle( const XMLNode& node ) { nuclear@19: _node = &node; nuclear@19: } nuclear@19: XMLConstHandle( const XMLConstHandle& ref ) { nuclear@19: _node = ref._node; nuclear@19: } nuclear@19: nuclear@19: XMLConstHandle& operator=( const XMLConstHandle& ref ) { nuclear@19: _node = ref._node; nuclear@19: return *this; nuclear@19: } nuclear@19: nuclear@19: const XMLConstHandle FirstChild() const { nuclear@19: return XMLConstHandle( _node ? _node->FirstChild() : 0 ); nuclear@19: } nuclear@19: const XMLConstHandle FirstChildElement( const char* value=0 ) const { nuclear@19: return XMLConstHandle( _node ? _node->FirstChildElement( value ) : 0 ); nuclear@19: } nuclear@19: const XMLConstHandle LastChild() const { nuclear@19: return XMLConstHandle( _node ? _node->LastChild() : 0 ); nuclear@19: } nuclear@19: const XMLConstHandle LastChildElement( const char* _value=0 ) const { nuclear@19: return XMLConstHandle( _node ? _node->LastChildElement( _value ) : 0 ); nuclear@19: } nuclear@19: const XMLConstHandle PreviousSibling() const { nuclear@19: return XMLConstHandle( _node ? _node->PreviousSibling() : 0 ); nuclear@19: } nuclear@19: const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const { nuclear@19: return XMLConstHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 ); nuclear@19: } nuclear@19: const XMLConstHandle NextSibling() const { nuclear@19: return XMLConstHandle( _node ? _node->NextSibling() : 0 ); nuclear@19: } nuclear@19: const XMLConstHandle NextSiblingElement( const char* _value=0 ) const { nuclear@19: return XMLConstHandle( _node ? _node->NextSiblingElement( _value ) : 0 ); nuclear@19: } nuclear@19: nuclear@19: nuclear@19: const XMLNode* ToNode() const { nuclear@19: return _node; nuclear@19: } nuclear@19: const XMLElement* ToElement() const { nuclear@19: return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 ); nuclear@19: } nuclear@19: const XMLText* ToText() const { nuclear@19: return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 ); nuclear@19: } nuclear@19: const XMLUnknown* ToUnknown() const { nuclear@19: return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 ); nuclear@19: } nuclear@19: const XMLDeclaration* ToDeclaration() const { nuclear@19: return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 ); nuclear@19: } nuclear@19: nuclear@19: private: nuclear@19: const XMLNode* _node; nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: /** nuclear@19: Printing functionality. The XMLPrinter gives you more nuclear@19: options than the XMLDocument::Print() method. nuclear@19: nuclear@19: It can: nuclear@19: -# Print to memory. nuclear@19: -# Print to a file you provide. nuclear@19: -# Print XML without a XMLDocument. nuclear@19: nuclear@19: Print to Memory nuclear@19: nuclear@19: @verbatim nuclear@19: XMLPrinter printer; nuclear@19: doc.Print( &printer ); nuclear@19: SomeFunction( printer.CStr() ); nuclear@19: @endverbatim nuclear@19: nuclear@19: Print to a File nuclear@19: nuclear@19: You provide the file pointer. nuclear@19: @verbatim nuclear@19: XMLPrinter printer( fp ); nuclear@19: doc.Print( &printer ); nuclear@19: @endverbatim nuclear@19: nuclear@19: Print without a XMLDocument nuclear@19: nuclear@19: When loading, an XML parser is very useful. However, sometimes nuclear@19: when saving, it just gets in the way. The code is often set up nuclear@19: for streaming, and constructing the DOM is just overhead. nuclear@19: nuclear@19: The Printer supports the streaming case. The following code nuclear@19: prints out a trivially simple XML file without ever creating nuclear@19: an XML document. nuclear@19: nuclear@19: @verbatim nuclear@19: XMLPrinter printer( fp ); nuclear@19: printer.OpenElement( "foo" ); nuclear@19: printer.PushAttribute( "foo", "bar" ); nuclear@19: printer.CloseElement(); nuclear@19: @endverbatim nuclear@19: */ nuclear@19: class TINYXML2_LIB XMLPrinter : public XMLVisitor nuclear@19: { nuclear@19: public: nuclear@19: /** Construct the printer. If the FILE* is specified, nuclear@19: this will print to the FILE. Else it will print nuclear@19: to memory, and the result is available in CStr(). nuclear@19: If 'compact' is set to true, then output is created nuclear@19: with only required whitespace and newlines. nuclear@19: */ nuclear@19: XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 ); nuclear@19: ~XMLPrinter() {} nuclear@19: nuclear@19: /** If streaming, write the BOM and declaration. */ nuclear@19: void PushHeader( bool writeBOM, bool writeDeclaration ); nuclear@19: /** If streaming, start writing an element. nuclear@19: The element must be closed with CloseElement() nuclear@19: */ nuclear@19: void OpenElement( const char* name ); nuclear@19: /// If streaming, add an attribute to an open element. nuclear@19: void PushAttribute( const char* name, const char* value ); nuclear@19: void PushAttribute( const char* name, int value ); nuclear@19: void PushAttribute( const char* name, unsigned value ); nuclear@19: void PushAttribute( const char* name, bool value ); nuclear@19: void PushAttribute( const char* name, double value ); nuclear@19: /// If streaming, close the Element. nuclear@19: void CloseElement(); nuclear@19: nuclear@19: /// Add a text node. nuclear@19: void PushText( const char* text, bool cdata=false ); nuclear@19: /// Add a text node from an integer. nuclear@19: void PushText( int value ); nuclear@19: /// Add a text node from an unsigned. nuclear@19: void PushText( unsigned value ); nuclear@19: /// Add a text node from a bool. nuclear@19: void PushText( bool value ); nuclear@19: /// Add a text node from a float. nuclear@19: void PushText( float value ); nuclear@19: /// Add a text node from a double. nuclear@19: void PushText( double value ); nuclear@19: nuclear@19: /// Add a comment nuclear@19: void PushComment( const char* comment ); nuclear@19: nuclear@19: void PushDeclaration( const char* value ); nuclear@19: void PushUnknown( const char* value ); nuclear@19: nuclear@19: virtual bool VisitEnter( const XMLDocument& /*doc*/ ); nuclear@19: virtual bool VisitExit( const XMLDocument& /*doc*/ ) { nuclear@19: return true; nuclear@19: } nuclear@19: nuclear@19: virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute ); nuclear@19: virtual bool VisitExit( const XMLElement& element ); nuclear@19: nuclear@19: virtual bool Visit( const XMLText& text ); nuclear@19: virtual bool Visit( const XMLComment& comment ); nuclear@19: virtual bool Visit( const XMLDeclaration& declaration ); nuclear@19: virtual bool Visit( const XMLUnknown& unknown ); nuclear@19: nuclear@19: /** nuclear@19: If in print to memory mode, return a pointer to nuclear@19: the XML file in memory. nuclear@19: */ nuclear@19: const char* CStr() const { nuclear@19: return _buffer.Mem(); nuclear@19: } nuclear@19: /** nuclear@19: If in print to memory mode, return the size nuclear@19: of the XML file in memory. (Note the size returned nuclear@19: includes the terminating null.) nuclear@19: */ nuclear@19: int CStrSize() const { nuclear@19: return _buffer.Size(); nuclear@19: } nuclear@19: nuclear@19: private: nuclear@19: void SealElement(); nuclear@19: void PrintSpace( int depth ); nuclear@19: void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities. nuclear@19: void Print( const char* format, ... ); nuclear@19: nuclear@19: bool _elementJustOpened; nuclear@19: bool _firstElement; nuclear@19: FILE* _fp; nuclear@19: int _depth; nuclear@19: int _textDepth; nuclear@19: bool _processEntities; nuclear@19: bool _compactMode; nuclear@19: nuclear@19: enum { nuclear@19: ENTITY_RANGE = 64, nuclear@19: BUF_SIZE = 200 nuclear@19: }; nuclear@19: bool _entityFlag[ENTITY_RANGE]; nuclear@19: bool _restrictedEntityFlag[ENTITY_RANGE]; nuclear@19: nuclear@19: DynArray< const char*, 10 > _stack; nuclear@19: DynArray< char, 20 > _buffer; nuclear@19: #ifdef _MSC_VER nuclear@19: DynArray< char, 20 > _accumulator; nuclear@19: #endif nuclear@19: }; nuclear@19: nuclear@19: nuclear@19: } // tinyxml2 nuclear@19: nuclear@19: #if defined(_MSC_VER) nuclear@19: # pragma warning(pop) nuclear@19: #endif nuclear@19: nuclear@19: #endif // TINYXML2_INCLUDED