ovr_sdk

diff 3rdParty/TinyXml/tinyxml2.h @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/3rdParty/TinyXml/tinyxml2.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,1911 @@
     1.4 +/*
     1.5 +Original code by Lee Thomason (www.grinninglizard.com)
     1.6 +
     1.7 +This software is provided 'as-is', without any express or implied
     1.8 +warranty. In no event will the authors be held liable for any
     1.9 +damages arising from the use of this software.
    1.10 +
    1.11 +Permission is granted to anyone to use this software for any
    1.12 +purpose, including commercial applications, and to alter it and
    1.13 +redistribute it freely, subject to the following restrictions:
    1.14 +
    1.15 +1. The origin of this software must not be misrepresented; you must
    1.16 +not claim that you wrote the original software. If you use this
    1.17 +software in a product, an acknowledgment in the product documentation
    1.18 +would be appreciated but is not required.
    1.19 +
    1.20 +2. Altered source versions must be plainly marked as such, and
    1.21 +must not be misrepresented as being the original software.
    1.22 +
    1.23 +3. This notice may not be removed or altered from any source
    1.24 +distribution.
    1.25 +*/
    1.26 +
    1.27 +#ifndef TINYXML2_INCLUDED
    1.28 +#define TINYXML2_INCLUDED
    1.29 +
    1.30 +#if defined(ANDROID_NDK) || defined(__BORLANDC__)
    1.31 +#   include <ctype.h>
    1.32 +#   include <limits.h>
    1.33 +#   include <stdio.h>
    1.34 +#   include <stdlib.h>
    1.35 +#   include <string.h>
    1.36 +#   include <stdarg.h>
    1.37 +#else
    1.38 +#   include <cctype>
    1.39 +#   include <climits>
    1.40 +#   include <cstdio>
    1.41 +#   include <cstdlib>
    1.42 +#   include <cstring>
    1.43 +#   include <cstdarg>
    1.44 +#endif
    1.45 +
    1.46 +/*
    1.47 +   TODO: intern strings instead of allocation.
    1.48 +*/
    1.49 +/*
    1.50 +	gcc:
    1.51 +        g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
    1.52 +
    1.53 +    Formatting, Artistic Style:
    1.54 +        AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
    1.55 +*/
    1.56 +
    1.57 +#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
    1.58 +#   ifndef DEBUG
    1.59 +#       define DEBUG
    1.60 +#   endif
    1.61 +#endif
    1.62 +
    1.63 +
    1.64 +#if defined(DEBUG)
    1.65 +#   if defined(_MSC_VER)
    1.66 +#       define TIXMLASSERT( x )           if ( !(x)) { __debugbreak(); } //if ( !(x)) WinDebugBreak()
    1.67 +#   elif defined (ANDROID_NDK)
    1.68 +#       include <android/log.h>
    1.69 +#       define TIXMLASSERT( x )           if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
    1.70 +#   else
    1.71 +#       include <assert.h>
    1.72 +#       define TIXMLASSERT                assert
    1.73 +#   endif
    1.74 +#   else
    1.75 +#       define TIXMLASSERT( x )           {}
    1.76 +#endif
    1.77 +
    1.78 +
    1.79 +#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
    1.80 +// Microsoft visual studio, version 2005 and higher.
    1.81 +/*int _snprintf_s(
    1.82 +   char *buffer,
    1.83 +   size_t sizeOfBuffer,
    1.84 +   size_t count,
    1.85 +   const char *format [,
    1.86 +	  argument] ...
    1.87 +);*/
    1.88 +inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
    1.89 +{
    1.90 +    va_list va;
    1.91 +    va_start( va, format );
    1.92 +    int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
    1.93 +    va_end( va );
    1.94 +    return result;
    1.95 +}
    1.96 +#define TIXML_SSCANF   sscanf_s
    1.97 +#else
    1.98 +// GCC version 3 and higher
    1.99 +//#warning( "Using sn* functions." )
   1.100 +#define TIXML_SNPRINTF snprintf
   1.101 +#define TIXML_SSCANF   sscanf
   1.102 +#endif
   1.103 +
   1.104 +static const int TIXML2_MAJOR_VERSION = 1;
   1.105 +static const int TIXML2_MINOR_VERSION = 0;
   1.106 +static const int TIXML2_PATCH_VERSION = 9;
   1.107 +
   1.108 +namespace tinyxml2
   1.109 +{
   1.110 +class XMLDocument;
   1.111 +class XMLElement;
   1.112 +class XMLAttribute;
   1.113 +class XMLComment;
   1.114 +class XMLNode;
   1.115 +class XMLText;
   1.116 +class XMLDeclaration;
   1.117 +class XMLUnknown;
   1.118 +
   1.119 +class XMLPrinter;
   1.120 +
   1.121 +/*
   1.122 +	A class that wraps strings. Normally stores the start and end
   1.123 +	pointers into the XML file itself, and will apply normalization
   1.124 +	and entity translation if actually read. Can also store (and memory
   1.125 +	manage) a traditional char[]
   1.126 +*/
   1.127 +class StrPair
   1.128 +{
   1.129 +public:
   1.130 +    enum {
   1.131 +        NEEDS_ENTITY_PROCESSING			= 0x01,
   1.132 +        NEEDS_NEWLINE_NORMALIZATION		= 0x02,
   1.133 +        COLLAPSE_WHITESPACE				= 0x04,
   1.134 +
   1.135 +        TEXT_ELEMENT		            = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
   1.136 +        TEXT_ELEMENT_LEAVE_ENTITIES		= NEEDS_NEWLINE_NORMALIZATION,
   1.137 +        ATTRIBUTE_NAME		            = 0,
   1.138 +        ATTRIBUTE_VALUE		            = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
   1.139 +        ATTRIBUTE_VALUE_LEAVE_ENTITIES  = NEEDS_NEWLINE_NORMALIZATION,
   1.140 +        COMMENT				            = NEEDS_NEWLINE_NORMALIZATION
   1.141 +    };
   1.142 +
   1.143 +    StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
   1.144 +    ~StrPair();
   1.145 +
   1.146 +    void Set( char* start, char* end, int flags ) {
   1.147 +        Reset();
   1.148 +        _start  = start;
   1.149 +        _end    = end;
   1.150 +        _flags  = flags | NEEDS_FLUSH;
   1.151 +    }
   1.152 +
   1.153 +    const char* GetStr();
   1.154 +
   1.155 +    bool Empty() const {
   1.156 +        return _start == _end;
   1.157 +    }
   1.158 +
   1.159 +    void SetInternedStr( const char* str ) {
   1.160 +        Reset();
   1.161 +        _start = const_cast<char*>(str);
   1.162 +    }
   1.163 +
   1.164 +    void SetStr( const char* str, int flags=0 );
   1.165 +
   1.166 +    char* ParseText( char* in, const char* endTag, int strFlags );
   1.167 +    char* ParseName( char* in );
   1.168 +
   1.169 +private:
   1.170 +    void Reset();
   1.171 +    void CollapseWhitespace();
   1.172 +
   1.173 +    enum {
   1.174 +        NEEDS_FLUSH = 0x100,
   1.175 +        NEEDS_DELETE = 0x200
   1.176 +    };
   1.177 +
   1.178 +    // After parsing, if *end != 0, it can be set to zero.
   1.179 +    int     _flags;
   1.180 +    char*   _start;
   1.181 +    char*   _end;
   1.182 +};
   1.183 +
   1.184 +
   1.185 +/*
   1.186 +	A dynamic array of Plain Old Data. Doesn't support constructors, etc.
   1.187 +	Has a small initial memory pool, so that low or no usage will not
   1.188 +	cause a call to new/delete
   1.189 +*/
   1.190 +template <class T, int INIT>
   1.191 +class DynArray
   1.192 +{
   1.193 +public:
   1.194 +    DynArray< T, INIT >() {
   1.195 +        _mem = _pool;
   1.196 +        _allocated = INIT;
   1.197 +        _size = 0;
   1.198 +    }
   1.199 +
   1.200 +    ~DynArray() {
   1.201 +        if ( _mem != _pool ) {
   1.202 +            delete [] _mem;
   1.203 +        }
   1.204 +    }
   1.205 +
   1.206 +    void Push( T t ) {
   1.207 +        EnsureCapacity( _size+1 );
   1.208 +        _mem[_size++] = t;
   1.209 +    }
   1.210 +
   1.211 +    T* PushArr( int count ) {
   1.212 +        EnsureCapacity( _size+count );
   1.213 +        T* ret = &_mem[_size];
   1.214 +        _size += count;
   1.215 +        return ret;
   1.216 +    }
   1.217 +
   1.218 +    T Pop() {
   1.219 +        return _mem[--_size];
   1.220 +    }
   1.221 +
   1.222 +    void PopArr( int count ) {
   1.223 +        TIXMLASSERT( _size >= count );
   1.224 +        _size -= count;
   1.225 +    }
   1.226 +
   1.227 +    bool Empty() const					{
   1.228 +        return _size == 0;
   1.229 +    }
   1.230 +
   1.231 +    T& operator[](int i)				{
   1.232 +        TIXMLASSERT( i>= 0 && i < _size );
   1.233 +        return _mem[i];
   1.234 +    }
   1.235 +
   1.236 +    const T& operator[](int i) const	{
   1.237 +        TIXMLASSERT( i>= 0 && i < _size );
   1.238 +        return _mem[i];
   1.239 +    }
   1.240 +
   1.241 +    int Size() const					{
   1.242 +        return _size;
   1.243 +    }
   1.244 +
   1.245 +    int Capacity() const				{
   1.246 +        return _allocated;
   1.247 +    }
   1.248 +
   1.249 +    const T* Mem() const				{
   1.250 +        return _mem;
   1.251 +    }
   1.252 +
   1.253 +    T* Mem()							{
   1.254 +        return _mem;
   1.255 +    }
   1.256 +
   1.257 +private:
   1.258 +    void EnsureCapacity( int cap ) {
   1.259 +        if ( cap > _allocated ) {
   1.260 +            int newAllocated = cap * 2;
   1.261 +            T* newMem = new T[newAllocated];
   1.262 +            memcpy( newMem, _mem, sizeof(T)*_size );	// warning: not using constructors, only works for PODs
   1.263 +            if ( _mem != _pool ) {
   1.264 +                delete [] _mem;
   1.265 +            }
   1.266 +            _mem = newMem;
   1.267 +            _allocated = newAllocated;
   1.268 +        }
   1.269 +    }
   1.270 +
   1.271 +    T*  _mem;
   1.272 +    T   _pool[INIT];
   1.273 +    int _allocated;		// objects allocated
   1.274 +    int _size;			// number objects in use
   1.275 +};
   1.276 +
   1.277 +
   1.278 +/*
   1.279 +	Parent virtual class of a pool for fast allocation
   1.280 +	and deallocation of objects.
   1.281 +*/
   1.282 +class MemPool
   1.283 +{
   1.284 +public:
   1.285 +    MemPool() {}
   1.286 +    virtual ~MemPool() {}
   1.287 +
   1.288 +    virtual int ItemSize() const = 0;
   1.289 +    virtual void* Alloc() = 0;
   1.290 +    virtual void Free( void* ) = 0;
   1.291 +    virtual void SetTracked() = 0;
   1.292 +};
   1.293 +
   1.294 +
   1.295 +/*
   1.296 +	Template child class to create pools of the correct type.
   1.297 +*/
   1.298 +template< int SIZE >
   1.299 +class MemPoolT : public MemPool
   1.300 +{
   1.301 +public:
   1.302 +    MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0)	{}
   1.303 +    ~MemPoolT() {
   1.304 +        // Delete the blocks.
   1.305 +        for( int i=0; i<_blockPtrs.Size(); ++i ) {
   1.306 +            delete _blockPtrs[i];
   1.307 +        }
   1.308 +    }
   1.309 +
   1.310 +    virtual int ItemSize() const	{
   1.311 +        return SIZE;
   1.312 +    }
   1.313 +    int CurrentAllocs() const		{
   1.314 +        return _currentAllocs;
   1.315 +    }
   1.316 +
   1.317 +    virtual void* Alloc() {
   1.318 +        if ( !_root ) {
   1.319 +            // Need a new block.
   1.320 +            Block* block = new Block();
   1.321 +            _blockPtrs.Push( block );
   1.322 +
   1.323 +            for( int i=0; i<COUNT-1; ++i ) {
   1.324 +                block->chunk[i].next = &block->chunk[i+1];
   1.325 +            }
   1.326 +            block->chunk[COUNT-1].next = 0;
   1.327 +            _root = block->chunk;
   1.328 +        }
   1.329 +        void* result = _root;
   1.330 +        _root = _root->next;
   1.331 +
   1.332 +        ++_currentAllocs;
   1.333 +        if ( _currentAllocs > _maxAllocs ) {
   1.334 +            _maxAllocs = _currentAllocs;
   1.335 +        }
   1.336 +        _nAllocs++;
   1.337 +        _nUntracked++;
   1.338 +        return result;
   1.339 +    }
   1.340 +    virtual void Free( void* mem ) {
   1.341 +        if ( !mem ) {
   1.342 +            return;
   1.343 +        }
   1.344 +        --_currentAllocs;
   1.345 +        Chunk* chunk = (Chunk*)mem;
   1.346 +#ifdef DEBUG
   1.347 +        memset( chunk, 0xfe, sizeof(Chunk) );
   1.348 +#endif
   1.349 +        chunk->next = _root;
   1.350 +        _root = chunk;
   1.351 +    }
   1.352 +    void Trace( const char* name ) {
   1.353 +        printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
   1.354 +                name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() );
   1.355 +    }
   1.356 +
   1.357 +    void SetTracked() {
   1.358 +        _nUntracked--;
   1.359 +    }
   1.360 +
   1.361 +    int Untracked() const {
   1.362 +        return _nUntracked;
   1.363 +    }
   1.364 +
   1.365 +    enum { COUNT = 1024/SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private
   1.366 +
   1.367 +private:
   1.368 +    union Chunk {
   1.369 +        Chunk*  next;
   1.370 +        char    mem[SIZE];
   1.371 +    };
   1.372 +    struct Block {
   1.373 +        Chunk chunk[COUNT];
   1.374 +    };
   1.375 +    DynArray< Block*, 10 > _blockPtrs;
   1.376 +    Chunk* _root;
   1.377 +
   1.378 +    int _currentAllocs;
   1.379 +    int _nAllocs;
   1.380 +    int _maxAllocs;
   1.381 +    int _nUntracked;
   1.382 +};
   1.383 +
   1.384 +
   1.385 +
   1.386 +/**
   1.387 +	Implements the interface to the "Visitor pattern" (see the Accept() method.)
   1.388 +	If you call the Accept() method, it requires being passed a XMLVisitor
   1.389 +	class to handle callbacks. For nodes that contain other nodes (Document, Element)
   1.390 +	you will get called with a VisitEnter/VisitExit pair. Nodes that are always leafs
   1.391 +	are simply called with Visit().
   1.392 +
   1.393 +	If you return 'true' from a Visit method, recursive parsing will continue. If you return
   1.394 +	false, <b>no children of this node or its sibilings</b> will be visited.
   1.395 +
   1.396 +	All flavors of Visit methods have a default implementation that returns 'true' (continue
   1.397 +	visiting). You need to only override methods that are interesting to you.
   1.398 +
   1.399 +	Generally Accept() is called on the TiXmlDocument, although all nodes support visiting.
   1.400 +
   1.401 +	You should never change the document from a callback.
   1.402 +
   1.403 +	@sa XMLNode::Accept()
   1.404 +*/
   1.405 +class XMLVisitor
   1.406 +{
   1.407 +public:
   1.408 +    virtual ~XMLVisitor() {}
   1.409 +
   1.410 +    /// Visit a document.
   1.411 +    virtual bool VisitEnter( const XMLDocument& /*doc*/ )			{
   1.412 +        return true;
   1.413 +    }
   1.414 +    /// Visit a document.
   1.415 +    virtual bool VisitExit( const XMLDocument& /*doc*/ )			{
   1.416 +        return true;
   1.417 +    }
   1.418 +
   1.419 +    /// Visit an element.
   1.420 +    virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ )	{
   1.421 +        return true;
   1.422 +    }
   1.423 +    /// Visit an element.
   1.424 +    virtual bool VisitExit( const XMLElement& /*element*/ )			{
   1.425 +        return true;
   1.426 +    }
   1.427 +
   1.428 +    /// Visit a declaration.
   1.429 +    virtual bool Visit( const XMLDeclaration& /*declaration*/ )		{
   1.430 +        return true;
   1.431 +    }
   1.432 +    /// Visit a text node.
   1.433 +    virtual bool Visit( const XMLText& /*text*/ )					{
   1.434 +        return true;
   1.435 +    }
   1.436 +    /// Visit a comment node.
   1.437 +    virtual bool Visit( const XMLComment& /*comment*/ )				{
   1.438 +        return true;
   1.439 +    }
   1.440 +    /// Visit an unknown node.
   1.441 +    virtual bool Visit( const XMLUnknown& /*unknown*/ )				{
   1.442 +        return true;
   1.443 +    }
   1.444 +};
   1.445 +
   1.446 +
   1.447 +/*
   1.448 +	Utility functionality.
   1.449 +*/
   1.450 +class XMLUtil
   1.451 +{
   1.452 +public:
   1.453 +    // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
   1.454 +    // correct, but simple, and usually works.
   1.455 +    static const char* SkipWhiteSpace( const char* p )	{
   1.456 +        while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<const unsigned char*>(p) ) ) {
   1.457 +            ++p;
   1.458 +        }
   1.459 +        return p;
   1.460 +    }
   1.461 +    static char* SkipWhiteSpace( char* p )				{
   1.462 +        while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<unsigned char*>(p) ) )		{
   1.463 +            ++p;
   1.464 +        }
   1.465 +        return p;
   1.466 +    }
   1.467 +    static bool IsWhiteSpace( char p )					{
   1.468 +        return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
   1.469 +    }
   1.470 +
   1.471 +    inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX )  {
   1.472 +        int n = 0;
   1.473 +        if ( p == q ) {
   1.474 +            return true;
   1.475 +        }
   1.476 +        while( *p && *q && *p == *q && n<nChar ) {
   1.477 +            ++p;
   1.478 +            ++q;
   1.479 +            ++n;
   1.480 +        }
   1.481 +        if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
   1.482 +            return true;
   1.483 +        }
   1.484 +        return false;
   1.485 +    }
   1.486 +    inline static int IsUTF8Continuation( const char p ) {
   1.487 +        return p & 0x80;
   1.488 +    }
   1.489 +    inline static int IsAlphaNum( unsigned char anyByte )	{
   1.490 +        return ( anyByte < 128 ) ? isalnum( anyByte ) : 1;
   1.491 +    }
   1.492 +    inline static int IsAlpha( unsigned char anyByte )		{
   1.493 +        return ( anyByte < 128 ) ? isalpha( anyByte ) : 1;
   1.494 +    }
   1.495 +
   1.496 +    static const char* ReadBOM( const char* p, bool* hasBOM );
   1.497 +    // p is the starting location,
   1.498 +    // the UTF-8 value of the entity will be placed in value, and length filled in.
   1.499 +    static const char* GetCharacterRef( const char* p, char* value, int* length );
   1.500 +    static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
   1.501 +
   1.502 +    // converts primitive types to strings
   1.503 +    static void ToStr( int v, char* buffer, int bufferSize );
   1.504 +    static void ToStr( unsigned v, char* buffer, int bufferSize );
   1.505 +    static void ToStr( bool v, char* buffer, int bufferSize );
   1.506 +    static void ToStr( float v, char* buffer, int bufferSize );
   1.507 +    static void ToStr( double v, char* buffer, int bufferSize );
   1.508 +
   1.509 +    // converts strings to primitive types
   1.510 +    static bool	ToInt( const char* str, int* value );
   1.511 +    static bool ToUnsigned( const char* str, unsigned* value );
   1.512 +    static bool	ToBool( const char* str, bool* value );
   1.513 +    static bool	ToFloat( const char* str, float* value );
   1.514 +    static bool ToDouble( const char* str, double* value );
   1.515 +};
   1.516 +
   1.517 +
   1.518 +/** XMLNode is a base class for every object that is in the
   1.519 +	XML Document Object Model (DOM), except XMLAttributes.
   1.520 +	Nodes have siblings, a parent, and children which can
   1.521 +	be navigated. A node is always in a XMLDocument.
   1.522 +	The type of a XMLNode can be queried, and it can
   1.523 +	be cast to its more defined type.
   1.524 +
   1.525 +	A XMLDocument allocates memory for all its Nodes.
   1.526 +	When the XMLDocument gets deleted, all its Nodes
   1.527 +	will also be deleted.
   1.528 +
   1.529 +	@verbatim
   1.530 +	A Document can contain:	Element	(container or leaf)
   1.531 +							Comment (leaf)
   1.532 +							Unknown (leaf)
   1.533 +							Declaration( leaf )
   1.534 +
   1.535 +	An Element can contain:	Element (container or leaf)
   1.536 +							Text	(leaf)
   1.537 +							Attributes (not on tree)
   1.538 +							Comment (leaf)
   1.539 +							Unknown (leaf)
   1.540 +
   1.541 +	@endverbatim
   1.542 +*/
   1.543 +class XMLNode
   1.544 +{
   1.545 +    friend class XMLDocument;
   1.546 +    friend class XMLElement;
   1.547 +public:
   1.548 +
   1.549 +    /// Get the XMLDocument that owns this XMLNode.
   1.550 +    const XMLDocument* GetDocument() const	{
   1.551 +        return _document;
   1.552 +    }
   1.553 +    /// Get the XMLDocument that owns this XMLNode.
   1.554 +    XMLDocument* GetDocument()				{
   1.555 +        return _document;
   1.556 +    }
   1.557 +
   1.558 +    /// Safely cast to an Element, or null.
   1.559 +    virtual XMLElement*		ToElement()		{
   1.560 +        return 0;
   1.561 +    }
   1.562 +    /// Safely cast to Text, or null.
   1.563 +    virtual XMLText*		ToText()		{
   1.564 +        return 0;
   1.565 +    }
   1.566 +    /// Safely cast to a Comment, or null.
   1.567 +    virtual XMLComment*		ToComment()		{
   1.568 +        return 0;
   1.569 +    }
   1.570 +    /// Safely cast to a Document, or null.
   1.571 +    virtual XMLDocument*	ToDocument()	{
   1.572 +        return 0;
   1.573 +    }
   1.574 +    /// Safely cast to a Declaration, or null.
   1.575 +    virtual XMLDeclaration*	ToDeclaration()	{
   1.576 +        return 0;
   1.577 +    }
   1.578 +    /// Safely cast to an Unknown, or null.
   1.579 +    virtual XMLUnknown*		ToUnknown()		{
   1.580 +        return 0;
   1.581 +    }
   1.582 +
   1.583 +    virtual const XMLElement*		ToElement() const		{
   1.584 +        return 0;
   1.585 +    }
   1.586 +    virtual const XMLText*			ToText() const			{
   1.587 +        return 0;
   1.588 +    }
   1.589 +    virtual const XMLComment*		ToComment() const		{
   1.590 +        return 0;
   1.591 +    }
   1.592 +    virtual const XMLDocument*		ToDocument() const		{
   1.593 +        return 0;
   1.594 +    }
   1.595 +    virtual const XMLDeclaration*	ToDeclaration() const	{
   1.596 +        return 0;
   1.597 +    }
   1.598 +    virtual const XMLUnknown*		ToUnknown() const		{
   1.599 +        return 0;
   1.600 +    }
   1.601 +
   1.602 +    /** The meaning of 'value' changes for the specific type.
   1.603 +    	@verbatim
   1.604 +    	Document:	empty
   1.605 +    	Element:	name of the element
   1.606 +    	Comment:	the comment text
   1.607 +    	Unknown:	the tag contents
   1.608 +    	Text:		the text string
   1.609 +    	@endverbatim
   1.610 +    */
   1.611 +    const char* Value() const			{
   1.612 +        return _value.GetStr();
   1.613 +    }
   1.614 +
   1.615 +    /** Set the Value of an XML node.
   1.616 +    	@sa Value()
   1.617 +    */
   1.618 +    void SetValue( const char* val, bool staticMem=false );
   1.619 +
   1.620 +    /// Get the parent of this node on the DOM.
   1.621 +    const XMLNode*	Parent() const			{
   1.622 +        return _parent;
   1.623 +    }
   1.624 +
   1.625 +    XMLNode* Parent()						{
   1.626 +        return _parent;
   1.627 +    }
   1.628 +
   1.629 +    /// Returns true if this node has no children.
   1.630 +    bool NoChildren() const					{
   1.631 +        return !_firstChild;
   1.632 +    }
   1.633 +
   1.634 +    /// Get the first child node, or null if none exists.
   1.635 +    const XMLNode*  FirstChild() const		{
   1.636 +        return _firstChild;
   1.637 +    }
   1.638 +
   1.639 +    XMLNode*		FirstChild()			{
   1.640 +        return _firstChild;
   1.641 +    }
   1.642 +
   1.643 +    /** Get the first child element, or optionally the first child
   1.644 +        element with the specified name.
   1.645 +    */
   1.646 +    const XMLElement* FirstChildElement( const char* value=0 ) const;
   1.647 +
   1.648 +    XMLElement* FirstChildElement( const char* value=0 )	{
   1.649 +        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( value ));
   1.650 +    }
   1.651 +
   1.652 +    /// Get the last child node, or null if none exists.
   1.653 +    const XMLNode*	LastChild() const						{
   1.654 +        return _lastChild;
   1.655 +    }
   1.656 +
   1.657 +    XMLNode*		LastChild()								{
   1.658 +        return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->LastChild() );
   1.659 +    }
   1.660 +
   1.661 +    /** Get the last child element or optionally the last child
   1.662 +        element with the specified name.
   1.663 +    */
   1.664 +    const XMLElement* LastChildElement( const char* value=0 ) const;
   1.665 +
   1.666 +    XMLElement* LastChildElement( const char* value=0 )	{
   1.667 +        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(value) );
   1.668 +    }
   1.669 +
   1.670 +    /// Get the previous (left) sibling node of this node.
   1.671 +    const XMLNode*	PreviousSibling() const					{
   1.672 +        return _prev;
   1.673 +    }
   1.674 +
   1.675 +    XMLNode*	PreviousSibling()							{
   1.676 +        return _prev;
   1.677 +    }
   1.678 +
   1.679 +    /// Get the previous (left) sibling element of this node, with an opitionally supplied name.
   1.680 +    const XMLElement*	PreviousSiblingElement( const char* value=0 ) const ;
   1.681 +
   1.682 +    XMLElement*	PreviousSiblingElement( const char* value=0 ) {
   1.683 +        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( value ) );
   1.684 +    }
   1.685 +
   1.686 +    /// Get the next (right) sibling node of this node.
   1.687 +    const XMLNode*	NextSibling() const						{
   1.688 +        return _next;
   1.689 +    }
   1.690 +
   1.691 +    XMLNode*	NextSibling()								{
   1.692 +        return _next;
   1.693 +    }
   1.694 +
   1.695 +    /// Get the next (right) sibling element of this node, with an opitionally supplied name.
   1.696 +    const XMLElement*	NextSiblingElement( const char* value=0 ) const;
   1.697 +
   1.698 +    XMLElement*	NextSiblingElement( const char* value=0 )	{
   1.699 +        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( value ) );
   1.700 +    }
   1.701 +
   1.702 +    /**
   1.703 +    	Add a child node as the last (right) child.
   1.704 +    */
   1.705 +    XMLNode* InsertEndChild( XMLNode* addThis );
   1.706 +
   1.707 +    XMLNode* LinkEndChild( XMLNode* addThis )	{
   1.708 +        return InsertEndChild( addThis );
   1.709 +    }
   1.710 +    /**
   1.711 +    	Add a child node as the first (left) child.
   1.712 +    */
   1.713 +    XMLNode* InsertFirstChild( XMLNode* addThis );
   1.714 +    /**
   1.715 +    	Add a node after the specified child node.
   1.716 +    */
   1.717 +    XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
   1.718 +
   1.719 +    /**
   1.720 +    	Delete all the children of this node.
   1.721 +    */
   1.722 +    void DeleteChildren();
   1.723 +
   1.724 +    /**
   1.725 +    	Delete a child of this node.
   1.726 +    */
   1.727 +    void DeleteChild( XMLNode* node );
   1.728 +
   1.729 +    /**
   1.730 +    	Make a copy of this node, but not its children.
   1.731 +    	You may pass in a Document pointer that will be
   1.732 +    	the owner of the new Node. If the 'document' is
   1.733 +    	null, then the node returned will be allocated
   1.734 +    	from the current Document. (this->GetDocument())
   1.735 +
   1.736 +    	Note: if called on a XMLDocument, this will return null.
   1.737 +    */
   1.738 +    virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
   1.739 +
   1.740 +    /**
   1.741 +    	Test if 2 nodes are the same, but don't test children.
   1.742 +    	The 2 nodes do not need to be in the same Document.
   1.743 +
   1.744 +    	Note: if called on a XMLDocument, this will return false.
   1.745 +    */
   1.746 +    virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
   1.747 +
   1.748 +    /** Accept a hierarchical visit of the nodes in the TinyXML DOM. Every node in the
   1.749 +    	XML tree will be conditionally visited and the host will be called back
   1.750 +    	via the TiXmlVisitor interface.
   1.751 +
   1.752 +    	This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse
   1.753 +    	the XML for the callbacks, so the performance of TinyXML is unchanged by using this
   1.754 +    	interface versus any other.)
   1.755 +
   1.756 +    	The interface has been based on ideas from:
   1.757 +
   1.758 +    	- http://www.saxproject.org/
   1.759 +    	- http://c2.com/cgi/wiki?HierarchicalVisitorPattern
   1.760 +
   1.761 +    	Which are both good references for "visiting".
   1.762 +
   1.763 +    	An example of using Accept():
   1.764 +    	@verbatim
   1.765 +    	TiXmlPrinter printer;
   1.766 +    	tinyxmlDoc.Accept( &printer );
   1.767 +    	const char* xmlcstr = printer.CStr();
   1.768 +    	@endverbatim
   1.769 +    */
   1.770 +    virtual bool Accept( XMLVisitor* visitor ) const = 0;
   1.771 +
   1.772 +    // internal
   1.773 +    virtual char* ParseDeep( char*, StrPair* );
   1.774 +
   1.775 +protected:
   1.776 +    XMLNode( XMLDocument* );
   1.777 +    virtual ~XMLNode();
   1.778 +    XMLNode( const XMLNode& );	// not supported
   1.779 +    XMLNode& operator=( const XMLNode& );	// not supported
   1.780 +
   1.781 +    XMLDocument*	_document;
   1.782 +    XMLNode*		_parent;
   1.783 +    mutable StrPair	_value;
   1.784 +
   1.785 +    XMLNode*		_firstChild;
   1.786 +    XMLNode*		_lastChild;
   1.787 +
   1.788 +    XMLNode*		_prev;
   1.789 +    XMLNode*		_next;
   1.790 +
   1.791 +private:
   1.792 +    MemPool*		_memPool;
   1.793 +    void Unlink( XMLNode* child );
   1.794 +};
   1.795 +
   1.796 +
   1.797 +/** XML text.
   1.798 +
   1.799 +	Note that a text node can have child element nodes, for example:
   1.800 +	@verbatim
   1.801 +	<root>This is <b>bold</b></root>
   1.802 +	@endverbatim
   1.803 +
   1.804 +	A text node can have 2 ways to output the next. "normal" output
   1.805 +	and CDATA. It will default to the mode it was parsed from the XML file and
   1.806 +	you generally want to leave it alone, but you can change the output mode with
   1.807 +	SetCDATA() and query it with CDATA().
   1.808 +*/
   1.809 +class XMLText : public XMLNode
   1.810 +{
   1.811 +    friend class XMLBase;
   1.812 +    friend class XMLDocument;
   1.813 +public:
   1.814 +    virtual bool Accept( XMLVisitor* visitor ) const;
   1.815 +
   1.816 +    virtual XMLText* ToText()			{
   1.817 +        return this;
   1.818 +    }
   1.819 +    virtual const XMLText* ToText() const	{
   1.820 +        return this;
   1.821 +    }
   1.822 +
   1.823 +    /// Declare whether this should be CDATA or standard text.
   1.824 +    void SetCData( bool isCData )			{
   1.825 +        _isCData = isCData;
   1.826 +    }
   1.827 +    /// Returns true if this is a CDATA text element.
   1.828 +    bool CData() const						{
   1.829 +        return _isCData;
   1.830 +    }
   1.831 +
   1.832 +    char* ParseDeep( char*, StrPair* endTag );
   1.833 +    virtual XMLNode* ShallowClone( XMLDocument* document ) const;
   1.834 +    virtual bool ShallowEqual( const XMLNode* compare ) const;
   1.835 +
   1.836 +protected:
   1.837 +    XMLText( XMLDocument* doc )	: XMLNode( doc ), _isCData( false )	{}
   1.838 +    virtual ~XMLText()												{}
   1.839 +    XMLText( const XMLText& );	// not supported
   1.840 +    XMLText& operator=( const XMLText& );	// not supported
   1.841 +
   1.842 +private:
   1.843 +    bool _isCData;
   1.844 +};
   1.845 +
   1.846 +
   1.847 +/** An XML Comment. */
   1.848 +class XMLComment : public XMLNode
   1.849 +{
   1.850 +    friend class XMLDocument;
   1.851 +public:
   1.852 +    virtual XMLComment*	ToComment()					{
   1.853 +        return this;
   1.854 +    }
   1.855 +    virtual const XMLComment* ToComment() const		{
   1.856 +        return this;
   1.857 +    }
   1.858 +
   1.859 +    virtual bool Accept( XMLVisitor* visitor ) const;
   1.860 +
   1.861 +    char* ParseDeep( char*, StrPair* endTag );
   1.862 +    virtual XMLNode* ShallowClone( XMLDocument* document ) const;
   1.863 +    virtual bool ShallowEqual( const XMLNode* compare ) const;
   1.864 +
   1.865 +protected:
   1.866 +    XMLComment( XMLDocument* doc );
   1.867 +    virtual ~XMLComment();
   1.868 +    XMLComment( const XMLComment& );	// not supported
   1.869 +    XMLComment& operator=( const XMLComment& );	// not supported
   1.870 +
   1.871 +private:
   1.872 +};
   1.873 +
   1.874 +
   1.875 +/** In correct XML the declaration is the first entry in the file.
   1.876 +	@verbatim
   1.877 +		<?xml version="1.0" standalone="yes"?>
   1.878 +	@endverbatim
   1.879 +
   1.880 +	TinyXML2 will happily read or write files without a declaration,
   1.881 +	however.
   1.882 +
   1.883 +	The text of the declaration isn't interpreted. It is parsed
   1.884 +	and written as a string.
   1.885 +*/
   1.886 +class XMLDeclaration : public XMLNode
   1.887 +{
   1.888 +    friend class XMLDocument;
   1.889 +public:
   1.890 +    virtual XMLDeclaration*	ToDeclaration()					{
   1.891 +        return this;
   1.892 +    }
   1.893 +    virtual const XMLDeclaration* ToDeclaration() const		{
   1.894 +        return this;
   1.895 +    }
   1.896 +
   1.897 +    virtual bool Accept( XMLVisitor* visitor ) const;
   1.898 +
   1.899 +    char* ParseDeep( char*, StrPair* endTag );
   1.900 +    virtual XMLNode* ShallowClone( XMLDocument* document ) const;
   1.901 +    virtual bool ShallowEqual( const XMLNode* compare ) const;
   1.902 +
   1.903 +protected:
   1.904 +    XMLDeclaration( XMLDocument* doc );
   1.905 +    virtual ~XMLDeclaration();
   1.906 +    XMLDeclaration( const XMLDeclaration& );	// not supported
   1.907 +    XMLDeclaration& operator=( const XMLDeclaration& );	// not supported
   1.908 +};
   1.909 +
   1.910 +
   1.911 +/** Any tag that tinyXml doesn't recognize is saved as an
   1.912 +	unknown. It is a tag of text, but should not be modified.
   1.913 +	It will be written back to the XML, unchanged, when the file
   1.914 +	is saved.
   1.915 +
   1.916 +	DTD tags get thrown into TiXmlUnknowns.
   1.917 +*/
   1.918 +class XMLUnknown : public XMLNode
   1.919 +{
   1.920 +    friend class XMLDocument;
   1.921 +public:
   1.922 +    virtual XMLUnknown*	ToUnknown()					{
   1.923 +        return this;
   1.924 +    }
   1.925 +    virtual const XMLUnknown* ToUnknown() const		{
   1.926 +        return this;
   1.927 +    }
   1.928 +
   1.929 +    virtual bool Accept( XMLVisitor* visitor ) const;
   1.930 +
   1.931 +    char* ParseDeep( char*, StrPair* endTag );
   1.932 +    virtual XMLNode* ShallowClone( XMLDocument* document ) const;
   1.933 +    virtual bool ShallowEqual( const XMLNode* compare ) const;
   1.934 +
   1.935 +protected:
   1.936 +    XMLUnknown( XMLDocument* doc );
   1.937 +    virtual ~XMLUnknown();
   1.938 +    XMLUnknown( const XMLUnknown& );	// not supported
   1.939 +    XMLUnknown& operator=( const XMLUnknown& );	// not supported
   1.940 +};
   1.941 +
   1.942 +
   1.943 +enum XMLError {
   1.944 +    XML_NO_ERROR = 0,
   1.945 +    XML_SUCCESS = 0,
   1.946 +
   1.947 +    XML_NO_ATTRIBUTE,
   1.948 +    XML_WRONG_ATTRIBUTE_TYPE,
   1.949 +
   1.950 +    XML_ERROR_FILE_NOT_FOUND,
   1.951 +    XML_ERROR_FILE_COULD_NOT_BE_OPENED,
   1.952 +    XML_ERROR_FILE_READ_ERROR,
   1.953 +    XML_ERROR_ELEMENT_MISMATCH,
   1.954 +    XML_ERROR_PARSING_ELEMENT,
   1.955 +    XML_ERROR_PARSING_ATTRIBUTE,
   1.956 +    XML_ERROR_IDENTIFYING_TAG,
   1.957 +    XML_ERROR_PARSING_TEXT,
   1.958 +    XML_ERROR_PARSING_CDATA,
   1.959 +    XML_ERROR_PARSING_COMMENT,
   1.960 +    XML_ERROR_PARSING_DECLARATION,
   1.961 +    XML_ERROR_PARSING_UNKNOWN,
   1.962 +    XML_ERROR_EMPTY_DOCUMENT,
   1.963 +    XML_ERROR_MISMATCHED_ELEMENT,
   1.964 +    XML_ERROR_PARSING,
   1.965 +
   1.966 +    XML_CAN_NOT_CONVERT_TEXT,
   1.967 +    XML_NO_TEXT_NODE
   1.968 +};
   1.969 +
   1.970 +
   1.971 +/** An attribute is a name-value pair. Elements have an arbitrary
   1.972 +	number of attributes, each with a unique name.
   1.973 +
   1.974 +	@note The attributes are not XMLNodes. You may only query the
   1.975 +	Next() attribute in a list.
   1.976 +*/
   1.977 +class XMLAttribute
   1.978 +{
   1.979 +    friend class XMLElement;
   1.980 +public:
   1.981 +    /// The name of the attribute.
   1.982 +    const char* Name() const {
   1.983 +        return _name.GetStr();
   1.984 +    }
   1.985 +    /// The value of the attribute.
   1.986 +    const char* Value() const {
   1.987 +        return _value.GetStr();
   1.988 +    }
   1.989 +    /// The next attribute in the list.
   1.990 +    const XMLAttribute* Next() const {
   1.991 +        return _next;
   1.992 +    }
   1.993 +
   1.994 +    /** IntAttribute interprets the attribute as an integer, and returns the value.
   1.995 +        If the value isn't an integer, 0 will be returned. There is no error checking;
   1.996 +    	use QueryIntAttribute() if you need error checking.
   1.997 +    */
   1.998 +    int		 IntValue() const				{
   1.999 +        int i=0;
  1.1000 +        QueryIntValue( &i );
  1.1001 +        return i;
  1.1002 +    }
  1.1003 +    /// Query as an unsigned integer. See IntAttribute()
  1.1004 +    unsigned UnsignedValue() const			{
  1.1005 +        unsigned i=0;
  1.1006 +        QueryUnsignedValue( &i );
  1.1007 +        return i;
  1.1008 +    }
  1.1009 +    /// Query as a boolean. See IntAttribute()
  1.1010 +    bool	 BoolValue() const				{
  1.1011 +        bool b=false;
  1.1012 +        QueryBoolValue( &b );
  1.1013 +        return b;
  1.1014 +    }
  1.1015 +    /// Query as a double. See IntAttribute()
  1.1016 +    double 	 DoubleValue() const			{
  1.1017 +        double d=0;
  1.1018 +        QueryDoubleValue( &d );
  1.1019 +        return d;
  1.1020 +    }
  1.1021 +    /// Query as a float. See IntAttribute()
  1.1022 +    float	 FloatValue() const				{
  1.1023 +        float f=0;
  1.1024 +        QueryFloatValue( &f );
  1.1025 +        return f;
  1.1026 +    }
  1.1027 +
  1.1028 +    /** QueryIntAttribute interprets the attribute as an integer, and returns the value
  1.1029 +    	in the provided paremeter. The function will return XML_NO_ERROR on success,
  1.1030 +    	and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful.
  1.1031 +    */
  1.1032 +    XMLError QueryIntValue( int* value ) const;
  1.1033 +    /// See QueryIntAttribute
  1.1034 +    XMLError QueryUnsignedValue( unsigned int* value ) const;
  1.1035 +    /// See QueryIntAttribute
  1.1036 +    XMLError QueryBoolValue( bool* value ) const;
  1.1037 +    /// See QueryIntAttribute
  1.1038 +    XMLError QueryDoubleValue( double* value ) const;
  1.1039 +    /// See QueryIntAttribute
  1.1040 +    XMLError QueryFloatValue( float* value ) const;
  1.1041 +
  1.1042 +    /// Set the attribute to a string value.
  1.1043 +    void SetAttribute( const char* value );
  1.1044 +    /// Set the attribute to value.
  1.1045 +    void SetAttribute( int value );
  1.1046 +    /// Set the attribute to value.
  1.1047 +    void SetAttribute( unsigned value );
  1.1048 +    /// Set the attribute to value.
  1.1049 +    void SetAttribute( bool value );
  1.1050 +    /// Set the attribute to value.
  1.1051 +    void SetAttribute( double value );
  1.1052 +    /// Set the attribute to value.
  1.1053 +    void SetAttribute( float value );
  1.1054 +
  1.1055 +private:
  1.1056 +    enum { BUF_SIZE = 200 };
  1.1057 +
  1.1058 +    XMLAttribute() : _next( 0 ) {}
  1.1059 +    virtual ~XMLAttribute()	{}
  1.1060 +
  1.1061 +    XMLAttribute( const XMLAttribute& );	// not supported
  1.1062 +    void operator=( const XMLAttribute& );	// not supported
  1.1063 +    void SetName( const char* name );
  1.1064 +
  1.1065 +    char* ParseDeep( char* p, bool processEntities );
  1.1066 +
  1.1067 +    mutable StrPair _name;
  1.1068 +    mutable StrPair _value;
  1.1069 +    XMLAttribute*   _next;
  1.1070 +    MemPool*        _memPool;
  1.1071 +};
  1.1072 +
  1.1073 +
  1.1074 +/** The element is a container class. It has a value, the element name,
  1.1075 +	and can contain other elements, text, comments, and unknowns.
  1.1076 +	Elements also contain an arbitrary number of attributes.
  1.1077 +*/
  1.1078 +class XMLElement : public XMLNode
  1.1079 +{
  1.1080 +    friend class XMLBase;
  1.1081 +    friend class XMLDocument;
  1.1082 +public:
  1.1083 +    /// Get the name of an element (which is the Value() of the node.)
  1.1084 +    const char* Name() const		{
  1.1085 +        return Value();
  1.1086 +    }
  1.1087 +    /// Set the name of the element.
  1.1088 +    void SetName( const char* str, bool staticMem=false )	{
  1.1089 +        SetValue( str, staticMem );
  1.1090 +    }
  1.1091 +
  1.1092 +    virtual XMLElement* ToElement()				{
  1.1093 +        return this;
  1.1094 +    }
  1.1095 +    virtual const XMLElement* ToElement() const {
  1.1096 +        return this;
  1.1097 +    }
  1.1098 +    virtual bool Accept( XMLVisitor* visitor ) const;
  1.1099 +
  1.1100 +    /** Given an attribute name, Attribute() returns the value
  1.1101 +    	for the attribute of that name, or null if none
  1.1102 +    	exists. For example:
  1.1103 +
  1.1104 +    	@verbatim
  1.1105 +    	const char* value = ele->Attribute( "foo" );
  1.1106 +    	@endverbatim
  1.1107 +
  1.1108 +    	The 'value' parameter is normally null. However, if specified,
  1.1109 +    	the attribute will only be returned if the 'name' and 'value'
  1.1110 +    	match. This allow you to write code:
  1.1111 +
  1.1112 +    	@verbatim
  1.1113 +    	if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar();
  1.1114 +    	@endverbatim
  1.1115 +
  1.1116 +    	rather than:
  1.1117 +    	@verbatim
  1.1118 +    	if ( ele->Attribute( "foo" ) ) {
  1.1119 +    		if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar();
  1.1120 +    	}
  1.1121 +    	@endverbatim
  1.1122 +    */
  1.1123 +    const char* Attribute( const char* name, const char* value=0 ) const;
  1.1124 +
  1.1125 +    /** Given an attribute name, IntAttribute() returns the value
  1.1126 +    	of the attribute interpreted as an integer. 0 will be
  1.1127 +    	returned if there is an error. For a method with error
  1.1128 +    	checking, see QueryIntAttribute()
  1.1129 +    */
  1.1130 +    int		 IntAttribute( const char* name ) const		{
  1.1131 +        int i=0;
  1.1132 +        QueryIntAttribute( name, &i );
  1.1133 +        return i;
  1.1134 +    }
  1.1135 +    /// See IntAttribute()
  1.1136 +    unsigned UnsignedAttribute( const char* name ) const {
  1.1137 +        unsigned i=0;
  1.1138 +        QueryUnsignedAttribute( name, &i );
  1.1139 +        return i;
  1.1140 +    }
  1.1141 +    /// See IntAttribute()
  1.1142 +    bool	 BoolAttribute( const char* name ) const	{
  1.1143 +        bool b=false;
  1.1144 +        QueryBoolAttribute( name, &b );
  1.1145 +        return b;
  1.1146 +    }
  1.1147 +    /// See IntAttribute()
  1.1148 +    double 	 DoubleAttribute( const char* name ) const	{
  1.1149 +        double d=0;
  1.1150 +        QueryDoubleAttribute( name, &d );
  1.1151 +        return d;
  1.1152 +    }
  1.1153 +    /// See IntAttribute()
  1.1154 +    float	 FloatAttribute( const char* name ) const	{
  1.1155 +        float f=0;
  1.1156 +        QueryFloatAttribute( name, &f );
  1.1157 +        return f;
  1.1158 +    }
  1.1159 +
  1.1160 +    /** Given an attribute name, QueryIntAttribute() returns
  1.1161 +    	XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion
  1.1162 +    	can't be performed, or XML_NO_ATTRIBUTE if the attribute
  1.1163 +    	doesn't exist. If successful, the result of the conversion
  1.1164 +    	will be written to 'value'. If not successful, nothing will
  1.1165 +    	be written to 'value'. This allows you to provide default
  1.1166 +    	value:
  1.1167 +
  1.1168 +    	@verbatim
  1.1169 +    	int value = 10;
  1.1170 +    	QueryIntAttribute( "foo", &value );		// if "foo" isn't found, value will still be 10
  1.1171 +    	@endverbatim
  1.1172 +    */
  1.1173 +    XMLError QueryIntAttribute( const char* name, int* value ) const				{
  1.1174 +        const XMLAttribute* a = FindAttribute( name );
  1.1175 +        if ( !a ) {
  1.1176 +            return XML_NO_ATTRIBUTE;
  1.1177 +        }
  1.1178 +        return a->QueryIntValue( value );
  1.1179 +    }
  1.1180 +    /// See QueryIntAttribute()
  1.1181 +    XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const	{
  1.1182 +        const XMLAttribute* a = FindAttribute( name );
  1.1183 +        if ( !a ) {
  1.1184 +            return XML_NO_ATTRIBUTE;
  1.1185 +        }
  1.1186 +        return a->QueryUnsignedValue( value );
  1.1187 +    }
  1.1188 +    /// See QueryIntAttribute()
  1.1189 +    XMLError QueryBoolAttribute( const char* name, bool* value ) const				{
  1.1190 +        const XMLAttribute* a = FindAttribute( name );
  1.1191 +        if ( !a ) {
  1.1192 +            return XML_NO_ATTRIBUTE;
  1.1193 +        }
  1.1194 +        return a->QueryBoolValue( value );
  1.1195 +    }
  1.1196 +    /// See QueryIntAttribute()
  1.1197 +    XMLError QueryDoubleAttribute( const char* name, double* value ) const			{
  1.1198 +        const XMLAttribute* a = FindAttribute( name );
  1.1199 +        if ( !a ) {
  1.1200 +            return XML_NO_ATTRIBUTE;
  1.1201 +        }
  1.1202 +        return a->QueryDoubleValue( value );
  1.1203 +    }
  1.1204 +    /// See QueryIntAttribute()
  1.1205 +    XMLError QueryFloatAttribute( const char* name, float* value ) const			{
  1.1206 +        const XMLAttribute* a = FindAttribute( name );
  1.1207 +        if ( !a ) {
  1.1208 +            return XML_NO_ATTRIBUTE;
  1.1209 +        }
  1.1210 +        return a->QueryFloatValue( value );
  1.1211 +    }
  1.1212 +
  1.1213 +    /// Sets the named attribute to value.
  1.1214 +    void SetAttribute( const char* name, const char* value )	{
  1.1215 +        XMLAttribute* a = FindOrCreateAttribute( name );
  1.1216 +        a->SetAttribute( value );
  1.1217 +    }
  1.1218 +    /// Sets the named attribute to value.
  1.1219 +    void SetAttribute( const char* name, int value )			{
  1.1220 +        XMLAttribute* a = FindOrCreateAttribute( name );
  1.1221 +        a->SetAttribute( value );
  1.1222 +    }
  1.1223 +    /// Sets the named attribute to value.
  1.1224 +    void SetAttribute( const char* name, unsigned value )		{
  1.1225 +        XMLAttribute* a = FindOrCreateAttribute( name );
  1.1226 +        a->SetAttribute( value );
  1.1227 +    }
  1.1228 +    /// Sets the named attribute to value.
  1.1229 +    void SetAttribute( const char* name, bool value )			{
  1.1230 +        XMLAttribute* a = FindOrCreateAttribute( name );
  1.1231 +        a->SetAttribute( value );
  1.1232 +    }
  1.1233 +    /// Sets the named attribute to value.
  1.1234 +    void SetAttribute( const char* name, double value )		{
  1.1235 +        XMLAttribute* a = FindOrCreateAttribute( name );
  1.1236 +        a->SetAttribute( value );
  1.1237 +    }
  1.1238 +
  1.1239 +    /**
  1.1240 +    	Delete an attribute.
  1.1241 +    */
  1.1242 +    void DeleteAttribute( const char* name );
  1.1243 +
  1.1244 +    /// Return the first attribute in the list.
  1.1245 +    const XMLAttribute* FirstAttribute() const {
  1.1246 +        return _rootAttribute;
  1.1247 +    }
  1.1248 +    /// Query a specific attribute in the list.
  1.1249 +    const XMLAttribute* FindAttribute( const char* name ) const;
  1.1250 +
  1.1251 +    /** Convenience function for easy access to the text inside an element. Although easy
  1.1252 +    	and concise, GetText() is limited compared to getting the TiXmlText child
  1.1253 +    	and accessing it directly.
  1.1254 +
  1.1255 +    	If the first child of 'this' is a TiXmlText, the GetText()
  1.1256 +    	returns the character string of the Text node, else null is returned.
  1.1257 +
  1.1258 +    	This is a convenient method for getting the text of simple contained text:
  1.1259 +    	@verbatim
  1.1260 +    	<foo>This is text</foo>
  1.1261 +    		const char* str = fooElement->GetText();
  1.1262 +    	@endverbatim
  1.1263 +
  1.1264 +    	'str' will be a pointer to "This is text".
  1.1265 +
  1.1266 +    	Note that this function can be misleading. If the element foo was created from
  1.1267 +    	this XML:
  1.1268 +    	@verbatim
  1.1269 +    		<foo><b>This is text</b></foo>
  1.1270 +    	@endverbatim
  1.1271 +
  1.1272 +    	then the value of str would be null. The first child node isn't a text node, it is
  1.1273 +    	another element. From this XML:
  1.1274 +    	@verbatim
  1.1275 +    		<foo>This is <b>text</b></foo>
  1.1276 +    	@endverbatim
  1.1277 +    	GetText() will return "This is ".
  1.1278 +    */
  1.1279 +    const char* GetText() const;
  1.1280 +
  1.1281 +    /**
  1.1282 +    	Convenience method to query the value of a child text node. This is probably best
  1.1283 +    	shown by example. Given you have a document is this form:
  1.1284 +    	@verbatim
  1.1285 +    		<point>
  1.1286 +    			<x>1</x>
  1.1287 +    			<y>1.4</y>
  1.1288 +    		</point>
  1.1289 +    	@endverbatim
  1.1290 +
  1.1291 +    	The QueryIntText() and similar functions provide a safe and easier way to get to the
  1.1292 +    	"value" of x and y.
  1.1293 +
  1.1294 +    	@verbatim
  1.1295 +    		int x = 0;
  1.1296 +    		float y = 0;	// types of x and y are contrived for example
  1.1297 +    		const XMLElement* xElement = pointElement->FirstChildElement( "x" );
  1.1298 +    		const XMLElement* yElement = pointElement->FirstChildElement( "y" );
  1.1299 +    		xElement->QueryIntText( &x );
  1.1300 +    		yElement->QueryFloatText( &y );
  1.1301 +    	@endverbatim
  1.1302 +
  1.1303 +    	@returns XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted
  1.1304 +    			 to the requested type, and XML_NO_TEXT_NODE if there is no child text to query.
  1.1305 +
  1.1306 +    */
  1.1307 +    XMLError QueryIntText( int* ival ) const;
  1.1308 +    /// See QueryIntText()
  1.1309 +    XMLError QueryUnsignedText( unsigned* uval ) const;
  1.1310 +    /// See QueryIntText()
  1.1311 +    XMLError QueryBoolText( bool* bval ) const;
  1.1312 +    /// See QueryIntText()
  1.1313 +    XMLError QueryDoubleText( double* dval ) const;
  1.1314 +    /// See QueryIntText()
  1.1315 +    XMLError QueryFloatText( float* fval ) const;
  1.1316 +
  1.1317 +    // internal:
  1.1318 +    enum {
  1.1319 +        OPEN,		// <foo>
  1.1320 +        CLOSED,		// <foo/>
  1.1321 +        CLOSING		// </foo>
  1.1322 +    };
  1.1323 +    int ClosingType() const {
  1.1324 +        return _closingType;
  1.1325 +    }
  1.1326 +    char* ParseDeep( char* p, StrPair* endTag );
  1.1327 +    virtual XMLNode* ShallowClone( XMLDocument* document ) const;
  1.1328 +    virtual bool ShallowEqual( const XMLNode* compare ) const;
  1.1329 +
  1.1330 +private:
  1.1331 +    XMLElement( XMLDocument* doc );
  1.1332 +    virtual ~XMLElement();
  1.1333 +    XMLElement( const XMLElement& );	// not supported
  1.1334 +    void operator=( const XMLElement& );	// not supported
  1.1335 +
  1.1336 +    XMLAttribute* FindAttribute( const char* name );
  1.1337 +    XMLAttribute* FindOrCreateAttribute( const char* name );
  1.1338 +    //void LinkAttribute( XMLAttribute* attrib );
  1.1339 +    char* ParseAttributes( char* p );
  1.1340 +
  1.1341 +    int _closingType;
  1.1342 +    // The attribute list is ordered; there is no 'lastAttribute'
  1.1343 +    // because the list needs to be scanned for dupes before adding
  1.1344 +    // a new attribute.
  1.1345 +    XMLAttribute* _rootAttribute;
  1.1346 +};
  1.1347 +
  1.1348 +
  1.1349 +enum Whitespace {
  1.1350 +    PRESERVE_WHITESPACE,
  1.1351 +    COLLAPSE_WHITESPACE
  1.1352 +};
  1.1353 +
  1.1354 +
  1.1355 +/** A Document binds together all the functionality.
  1.1356 +	It can be saved, loaded, and printed to the screen.
  1.1357 +	All Nodes are connected and allocated to a Document.
  1.1358 +	If the Document is deleted, all its Nodes are also deleted.
  1.1359 +*/
  1.1360 +class XMLDocument : public XMLNode
  1.1361 +{
  1.1362 +    friend class XMLElement;
  1.1363 +public:
  1.1364 +    /// constructor
  1.1365 +    XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE );
  1.1366 +    ~XMLDocument();
  1.1367 +
  1.1368 +    virtual XMLDocument* ToDocument()				{
  1.1369 +        return this;
  1.1370 +    }
  1.1371 +    virtual const XMLDocument* ToDocument() const	{
  1.1372 +        return this;
  1.1373 +    }
  1.1374 +
  1.1375 +    /**
  1.1376 +    	Parse an XML file from a character string.
  1.1377 +    	Returns XML_NO_ERROR (0) on success, or
  1.1378 +    	an errorID.
  1.1379 +
  1.1380 +    	You may optionally pass in the 'nBytes', which is
  1.1381 +    	the number of bytes which will be parsed. If not
  1.1382 +    	specified, TinyXML will assume 'xml' points to a
  1.1383 +    	null terminated string.
  1.1384 +    */
  1.1385 +    XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) );
  1.1386 +
  1.1387 +    /**
  1.1388 +    	Load an XML file from disk.
  1.1389 +    	Returns XML_NO_ERROR (0) on success, or
  1.1390 +    	an errorID.
  1.1391 +    */
  1.1392 +    XMLError LoadFile( const char* filename );
  1.1393 +
  1.1394 +    /**
  1.1395 +    	Load an XML file from disk. You are responsible
  1.1396 +    	for providing and closing the FILE*.
  1.1397 +
  1.1398 +    	Returns XML_NO_ERROR (0) on success, or
  1.1399 +    	an errorID.
  1.1400 +    */
  1.1401 +    XMLError LoadFile( FILE* );
  1.1402 +
  1.1403 +    /**
  1.1404 +    	Save the XML file to disk.
  1.1405 +    	Returns XML_NO_ERROR (0) on success, or
  1.1406 +    	an errorID.
  1.1407 +    */
  1.1408 +    XMLError SaveFile( const char* filename, bool compact = false );
  1.1409 +
  1.1410 +    /**
  1.1411 +    	Save the XML file to disk. You are responsible
  1.1412 +    	for providing and closing the FILE*.
  1.1413 +
  1.1414 +    	Returns XML_NO_ERROR (0) on success, or
  1.1415 +    	an errorID.
  1.1416 +    */
  1.1417 +    XMLError SaveFile( FILE* fp, bool compact = false );
  1.1418 +
  1.1419 +    bool ProcessEntities() const		{
  1.1420 +        return _processEntities;
  1.1421 +    }
  1.1422 +    Whitespace WhitespaceMode() const	{
  1.1423 +        return _whitespace;
  1.1424 +    }
  1.1425 +
  1.1426 +    /**
  1.1427 +    	Returns true if this document has a leading Byte Order Mark of UTF8.
  1.1428 +    */
  1.1429 +    bool HasBOM() const {
  1.1430 +        return _writeBOM;
  1.1431 +    }
  1.1432 +    /** Sets whether to write the BOM when writing the file.
  1.1433 +    */
  1.1434 +    void SetBOM( bool useBOM ) {
  1.1435 +        _writeBOM = useBOM;
  1.1436 +    }
  1.1437 +
  1.1438 +    /** Return the root element of DOM. Equivalent to FirstChildElement().
  1.1439 +        To get the first node, use FirstChild().
  1.1440 +    */
  1.1441 +    XMLElement* RootElement()				{
  1.1442 +        return FirstChildElement();
  1.1443 +    }
  1.1444 +    const XMLElement* RootElement() const	{
  1.1445 +        return FirstChildElement();
  1.1446 +    }
  1.1447 +
  1.1448 +    /** Print the Document. If the Printer is not provided, it will
  1.1449 +        print to stdout. If you provide Printer, this can print to a file:
  1.1450 +    	@verbatim
  1.1451 +    	XMLPrinter printer( fp );
  1.1452 +    	doc.Print( &printer );
  1.1453 +    	@endverbatim
  1.1454 +
  1.1455 +    	Or you can use a printer to print to memory:
  1.1456 +    	@verbatim
  1.1457 +    	XMLPrinter printer;
  1.1458 +    	doc->Print( &printer );
  1.1459 +    	// printer.CStr() has a const char* to the XML
  1.1460 +    	@endverbatim
  1.1461 +    */
  1.1462 +    void Print( XMLPrinter* streamer=0 );
  1.1463 +    virtual bool Accept( XMLVisitor* visitor ) const;
  1.1464 +
  1.1465 +    /**
  1.1466 +    	Create a new Element associated with
  1.1467 +    	this Document. The memory for the Element
  1.1468 +    	is managed by the Document.
  1.1469 +    */
  1.1470 +    XMLElement* NewElement( const char* name );
  1.1471 +    /**
  1.1472 +    	Create a new Comment associated with
  1.1473 +    	this Document. The memory for the Comment
  1.1474 +    	is managed by the Document.
  1.1475 +    */
  1.1476 +    XMLComment* NewComment( const char* comment );
  1.1477 +    /**
  1.1478 +    	Create a new Text associated with
  1.1479 +    	this Document. The memory for the Text
  1.1480 +    	is managed by the Document.
  1.1481 +    */
  1.1482 +    XMLText* NewText( const char* text );
  1.1483 +    /**
  1.1484 +    	Create a new Declaration associated with
  1.1485 +    	this Document. The memory for the object
  1.1486 +    	is managed by the Document.
  1.1487 +
  1.1488 +    	If the 'text' param is null, the standard
  1.1489 +    	declaration is used.:
  1.1490 +    	@verbatim
  1.1491 +    		<?xml version="1.0" encoding="UTF-8"?>
  1.1492 +    	@endverbatim
  1.1493 +    */
  1.1494 +    XMLDeclaration* NewDeclaration( const char* text=0 );
  1.1495 +    /**
  1.1496 +    	Create a new Unknown associated with
  1.1497 +    	this Document. The memory forthe object
  1.1498 +    	is managed by the Document.
  1.1499 +    */
  1.1500 +    XMLUnknown* NewUnknown( const char* text );
  1.1501 +
  1.1502 +    /**
  1.1503 +    	Delete a node associated with this document.
  1.1504 +    	It will be unlinked from the DOM.
  1.1505 +    */
  1.1506 +    void DeleteNode( XMLNode* node )	{
  1.1507 +        node->_parent->DeleteChild( node );
  1.1508 +    }
  1.1509 +
  1.1510 +    void SetError( XMLError error, const char* str1, const char* str2 );
  1.1511 +
  1.1512 +    /// Return true if there was an error parsing the document.
  1.1513 +    bool Error() const {
  1.1514 +        return _errorID != XML_NO_ERROR;
  1.1515 +    }
  1.1516 +    /// Return the errorID.
  1.1517 +    XMLError  ErrorID() const {
  1.1518 +        return _errorID;
  1.1519 +    }
  1.1520 +    /// Return a possibly helpful diagnostic location or string.
  1.1521 +    const char* GetErrorStr1() const {
  1.1522 +        return _errorStr1;
  1.1523 +    }
  1.1524 +    /// Return a possibly helpful secondary diagnostic location or string.
  1.1525 +    const char* GetErrorStr2() const {
  1.1526 +        return _errorStr2;
  1.1527 +    }
  1.1528 +    /// If there is an error, print it to stdout.
  1.1529 +    void PrintError() const;
  1.1530 +
  1.1531 +    // internal
  1.1532 +    char* Identify( char* p, XMLNode** node );
  1.1533 +
  1.1534 +    virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const	{
  1.1535 +        return 0;
  1.1536 +    }
  1.1537 +    virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const	{
  1.1538 +        return false;
  1.1539 +    }
  1.1540 +
  1.1541 +private:
  1.1542 +    XMLDocument( const XMLDocument& );	// not supported
  1.1543 +    void operator=( const XMLDocument& );	// not supported
  1.1544 +    void InitDocument();
  1.1545 +
  1.1546 +    bool        _writeBOM;
  1.1547 +    bool        _processEntities;
  1.1548 +    XMLError    _errorID;
  1.1549 +    Whitespace  _whitespace;
  1.1550 +    const char* _errorStr1;
  1.1551 +    const char* _errorStr2;
  1.1552 +    char*       _charBuffer;
  1.1553 +
  1.1554 +    MemPoolT< sizeof(XMLElement) >	 _elementPool;
  1.1555 +    MemPoolT< sizeof(XMLAttribute) > _attributePool;
  1.1556 +    MemPoolT< sizeof(XMLText) >		 _textPool;
  1.1557 +    MemPoolT< sizeof(XMLComment) >	 _commentPool;
  1.1558 +};
  1.1559 +
  1.1560 +
  1.1561 +/**
  1.1562 +	A XMLHandle is a class that wraps a node pointer with null checks; this is
  1.1563 +	an incredibly useful thing. Note that XMLHandle is not part of the TinyXML
  1.1564 +	DOM structure. It is a separate utility class.
  1.1565 +
  1.1566 +	Take an example:
  1.1567 +	@verbatim
  1.1568 +	<Document>
  1.1569 +		<Element attributeA = "valueA">
  1.1570 +			<Child attributeB = "value1" />
  1.1571 +			<Child attributeB = "value2" />
  1.1572 +		</Element>
  1.1573 +	</Document>
  1.1574 +	@endverbatim
  1.1575 +
  1.1576 +	Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very
  1.1577 +	easy to write a *lot* of code that looks like:
  1.1578 +
  1.1579 +	@verbatim
  1.1580 +	XMLElement* root = document.FirstChildElement( "Document" );
  1.1581 +	if ( root )
  1.1582 +	{
  1.1583 +		XMLElement* element = root->FirstChildElement( "Element" );
  1.1584 +		if ( element )
  1.1585 +		{
  1.1586 +			XMLElement* child = element->FirstChildElement( "Child" );
  1.1587 +			if ( child )
  1.1588 +			{
  1.1589 +				XMLElement* child2 = child->NextSiblingElement( "Child" );
  1.1590 +				if ( child2 )
  1.1591 +				{
  1.1592 +					// Finally do something useful.
  1.1593 +	@endverbatim
  1.1594 +
  1.1595 +	And that doesn't even cover "else" cases. XMLHandle addresses the verbosity
  1.1596 +	of such code. A XMLHandle checks for null pointers so it is perfectly safe
  1.1597 +	and correct to use:
  1.1598 +
  1.1599 +	@verbatim
  1.1600 +	XMLHandle docHandle( &document );
  1.1601 +	XMLElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild().NextSibling().ToElement();
  1.1602 +	if ( child2 )
  1.1603 +	{
  1.1604 +		// do something useful
  1.1605 +	@endverbatim
  1.1606 +
  1.1607 +	Which is MUCH more concise and useful.
  1.1608 +
  1.1609 +	It is also safe to copy handles - internally they are nothing more than node pointers.
  1.1610 +	@verbatim
  1.1611 +	XMLHandle handleCopy = handle;
  1.1612 +	@endverbatim
  1.1613 +
  1.1614 +	See also XMLConstHandle, which is the same as XMLHandle, but operates on const objects.
  1.1615 +*/
  1.1616 +class XMLHandle
  1.1617 +{
  1.1618 +public:
  1.1619 +    /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
  1.1620 +    XMLHandle( XMLNode* node )												{
  1.1621 +        _node = node;
  1.1622 +    }
  1.1623 +    /// Create a handle from a node.
  1.1624 +    XMLHandle( XMLNode& node )												{
  1.1625 +        _node = &node;
  1.1626 +    }
  1.1627 +    /// Copy constructor
  1.1628 +    XMLHandle( const XMLHandle& ref )										{
  1.1629 +        _node = ref._node;
  1.1630 +    }
  1.1631 +    /// Assignment
  1.1632 +    XMLHandle& operator=( const XMLHandle& ref )							{
  1.1633 +        _node = ref._node;
  1.1634 +        return *this;
  1.1635 +    }
  1.1636 +
  1.1637 +    /// Get the first child of this handle.
  1.1638 +    XMLHandle FirstChild() 													{
  1.1639 +        return XMLHandle( _node ? _node->FirstChild() : 0 );
  1.1640 +    }
  1.1641 +    /// Get the first child element of this handle.
  1.1642 +    XMLHandle FirstChildElement( const char* value=0 )						{
  1.1643 +        return XMLHandle( _node ? _node->FirstChildElement( value ) : 0 );
  1.1644 +    }
  1.1645 +    /// Get the last child of this handle.
  1.1646 +    XMLHandle LastChild()													{
  1.1647 +        return XMLHandle( _node ? _node->LastChild() : 0 );
  1.1648 +    }
  1.1649 +    /// Get the last child element of this handle.
  1.1650 +    XMLHandle LastChildElement( const char* _value=0 )						{
  1.1651 +        return XMLHandle( _node ? _node->LastChildElement( _value ) : 0 );
  1.1652 +    }
  1.1653 +    /// Get the previous sibling of this handle.
  1.1654 +    XMLHandle PreviousSibling()												{
  1.1655 +        return XMLHandle( _node ? _node->PreviousSibling() : 0 );
  1.1656 +    }
  1.1657 +    /// Get the previous sibling element of this handle.
  1.1658 +    XMLHandle PreviousSiblingElement( const char* _value=0 )				{
  1.1659 +        return XMLHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
  1.1660 +    }
  1.1661 +    /// Get the next sibling of this handle.
  1.1662 +    XMLHandle NextSibling()													{
  1.1663 +        return XMLHandle( _node ? _node->NextSibling() : 0 );
  1.1664 +    }
  1.1665 +    /// Get the next sibling element of this handle.
  1.1666 +    XMLHandle NextSiblingElement( const char* _value=0 )					{
  1.1667 +        return XMLHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
  1.1668 +    }
  1.1669 +
  1.1670 +    /// Safe cast to XMLNode. This can return null.
  1.1671 +    XMLNode* ToNode()							{
  1.1672 +        return _node;
  1.1673 +    }
  1.1674 +    /// Safe cast to XMLElement. This can return null.
  1.1675 +    XMLElement* ToElement() 					{
  1.1676 +        return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
  1.1677 +    }
  1.1678 +    /// Safe cast to XMLText. This can return null.
  1.1679 +    XMLText* ToText() 							{
  1.1680 +        return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
  1.1681 +    }
  1.1682 +    /// Safe cast to XMLUnknown. This can return null.
  1.1683 +    XMLUnknown* ToUnknown() 					{
  1.1684 +        return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
  1.1685 +    }
  1.1686 +    /// Safe cast to XMLDeclaration. This can return null.
  1.1687 +    XMLDeclaration* ToDeclaration() 			{
  1.1688 +        return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
  1.1689 +    }
  1.1690 +
  1.1691 +private:
  1.1692 +    XMLNode* _node;
  1.1693 +};
  1.1694 +
  1.1695 +
  1.1696 +/**
  1.1697 +	A variant of the XMLHandle class for working with const XMLNodes and Documents. It is the
  1.1698 +	same in all regards, except for the 'const' qualifiers. See XMLHandle for API.
  1.1699 +*/
  1.1700 +class XMLConstHandle
  1.1701 +{
  1.1702 +public:
  1.1703 +    XMLConstHandle( const XMLNode* node )											{
  1.1704 +        _node = node;
  1.1705 +    }
  1.1706 +    XMLConstHandle( const XMLNode& node )											{
  1.1707 +        _node = &node;
  1.1708 +    }
  1.1709 +    XMLConstHandle( const XMLConstHandle& ref )										{
  1.1710 +        _node = ref._node;
  1.1711 +    }
  1.1712 +
  1.1713 +    XMLConstHandle& operator=( const XMLConstHandle& ref )							{
  1.1714 +        _node = ref._node;
  1.1715 +        return *this;
  1.1716 +    }
  1.1717 +
  1.1718 +    const XMLConstHandle FirstChild() const											{
  1.1719 +        return XMLConstHandle( _node ? _node->FirstChild() : 0 );
  1.1720 +    }
  1.1721 +    const XMLConstHandle FirstChildElement( const char* value=0 ) const				{
  1.1722 +        return XMLConstHandle( _node ? _node->FirstChildElement( value ) : 0 );
  1.1723 +    }
  1.1724 +    const XMLConstHandle LastChild()	const										{
  1.1725 +        return XMLConstHandle( _node ? _node->LastChild() : 0 );
  1.1726 +    }
  1.1727 +    const XMLConstHandle LastChildElement( const char* _value=0 ) const				{
  1.1728 +        return XMLConstHandle( _node ? _node->LastChildElement( _value ) : 0 );
  1.1729 +    }
  1.1730 +    const XMLConstHandle PreviousSibling() const									{
  1.1731 +        return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
  1.1732 +    }
  1.1733 +    const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const		{
  1.1734 +        return XMLConstHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
  1.1735 +    }
  1.1736 +    const XMLConstHandle NextSibling() const										{
  1.1737 +        return XMLConstHandle( _node ? _node->NextSibling() : 0 );
  1.1738 +    }
  1.1739 +    const XMLConstHandle NextSiblingElement( const char* _value=0 ) const			{
  1.1740 +        return XMLConstHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
  1.1741 +    }
  1.1742 +
  1.1743 +
  1.1744 +    const XMLNode* ToNode() const				{
  1.1745 +        return _node;
  1.1746 +    }
  1.1747 +    const XMLElement* ToElement() const			{
  1.1748 +        return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
  1.1749 +    }
  1.1750 +    const XMLText* ToText() const				{
  1.1751 +        return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
  1.1752 +    }
  1.1753 +    const XMLUnknown* ToUnknown() const			{
  1.1754 +        return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
  1.1755 +    }
  1.1756 +    const XMLDeclaration* ToDeclaration() const	{
  1.1757 +        return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
  1.1758 +    }
  1.1759 +
  1.1760 +private:
  1.1761 +    const XMLNode* _node;
  1.1762 +};
  1.1763 +
  1.1764 +
  1.1765 +/**
  1.1766 +	Printing functionality. The XMLPrinter gives you more
  1.1767 +	options than the XMLDocument::Print() method.
  1.1768 +
  1.1769 +	It can:
  1.1770 +	-# Print to memory.
  1.1771 +	-# Print to a file you provide.
  1.1772 +	-# Print XML without a XMLDocument.
  1.1773 +
  1.1774 +	Print to Memory
  1.1775 +
  1.1776 +	@verbatim
  1.1777 +	XMLPrinter printer;
  1.1778 +	doc->Print( &printer );
  1.1779 +	SomeFunction( printer.CStr() );
  1.1780 +	@endverbatim
  1.1781 +
  1.1782 +	Print to a File
  1.1783 +
  1.1784 +	You provide the file pointer.
  1.1785 +	@verbatim
  1.1786 +	XMLPrinter printer( fp );
  1.1787 +	doc.Print( &printer );
  1.1788 +	@endverbatim
  1.1789 +
  1.1790 +	Print without a XMLDocument
  1.1791 +
  1.1792 +	When loading, an XML parser is very useful. However, sometimes
  1.1793 +	when saving, it just gets in the way. The code is often set up
  1.1794 +	for streaming, and constructing the DOM is just overhead.
  1.1795 +
  1.1796 +	The Printer supports the streaming case. The following code
  1.1797 +	prints out a trivially simple XML file without ever creating
  1.1798 +	an XML document.
  1.1799 +
  1.1800 +	@verbatim
  1.1801 +	XMLPrinter printer( fp );
  1.1802 +	printer.OpenElement( "foo" );
  1.1803 +	printer.PushAttribute( "foo", "bar" );
  1.1804 +	printer.CloseElement();
  1.1805 +	@endverbatim
  1.1806 +*/
  1.1807 +class XMLPrinter : public XMLVisitor
  1.1808 +{
  1.1809 +public:
  1.1810 +    /** Construct the printer. If the FILE* is specified,
  1.1811 +    	this will print to the FILE. Else it will print
  1.1812 +    	to memory, and the result is available in CStr().
  1.1813 +    	If 'compact' is set to true, then output is created
  1.1814 +    	with only required whitespace and newlines.
  1.1815 +    */
  1.1816 +    XMLPrinter( FILE* file=0, bool compact = false );
  1.1817 +    ~XMLPrinter()	{}
  1.1818 +
  1.1819 +    /** If streaming, write the BOM and declaration. */
  1.1820 +    void PushHeader( bool writeBOM, bool writeDeclaration );
  1.1821 +    /** If streaming, start writing an element.
  1.1822 +        The element must be closed with CloseElement()
  1.1823 +    */
  1.1824 +    void OpenElement( const char* name );
  1.1825 +    /// If streaming, add an attribute to an open element.
  1.1826 +    void PushAttribute( const char* name, const char* value );
  1.1827 +    void PushAttribute( const char* name, int value );
  1.1828 +    void PushAttribute( const char* name, unsigned value );
  1.1829 +    void PushAttribute( const char* name, bool value );
  1.1830 +    void PushAttribute( const char* name, double value );
  1.1831 +    /// If streaming, close the Element.
  1.1832 +    void CloseElement();
  1.1833 +
  1.1834 +    /// Add a text node.
  1.1835 +    void PushText( const char* text, bool cdata=false );
  1.1836 +    /// Add a text node from an integer.
  1.1837 +    void PushText( int value );
  1.1838 +    /// Add a text node from an unsigned.
  1.1839 +    void PushText( unsigned value );
  1.1840 +    /// Add a text node from a bool.
  1.1841 +    void PushText( bool value );
  1.1842 +    /// Add a text node from a float.
  1.1843 +    void PushText( float value );
  1.1844 +    /// Add a text node from a double.
  1.1845 +    void PushText( double value );
  1.1846 +
  1.1847 +    /// Add a comment
  1.1848 +    void PushComment( const char* comment );
  1.1849 +
  1.1850 +    void PushDeclaration( const char* value );
  1.1851 +    void PushUnknown( const char* value );
  1.1852 +
  1.1853 +    virtual bool VisitEnter( const XMLDocument& /*doc*/ );
  1.1854 +    virtual bool VisitExit( const XMLDocument& /*doc*/ )			{
  1.1855 +        return true;
  1.1856 +    }
  1.1857 +
  1.1858 +    virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
  1.1859 +    virtual bool VisitExit( const XMLElement& element );
  1.1860 +
  1.1861 +    virtual bool Visit( const XMLText& text );
  1.1862 +    virtual bool Visit( const XMLComment& comment );
  1.1863 +    virtual bool Visit( const XMLDeclaration& declaration );
  1.1864 +    virtual bool Visit( const XMLUnknown& unknown );
  1.1865 +
  1.1866 +    /**
  1.1867 +    	If in print to memory mode, return a pointer to
  1.1868 +    	the XML file in memory.
  1.1869 +    */
  1.1870 +    const char* CStr() const {
  1.1871 +        return _buffer.Mem();
  1.1872 +    }
  1.1873 +    /**
  1.1874 +    	If in print to memory mode, return the size
  1.1875 +    	of the XML file in memory. (Note the size returned
  1.1876 +    	includes the terminating null.)
  1.1877 +    */
  1.1878 +    int CStrSize() const {
  1.1879 +        return _buffer.Size();
  1.1880 +    }
  1.1881 +
  1.1882 +private:
  1.1883 +    void SealElement();
  1.1884 +    void PrintSpace( int depth );
  1.1885 +    void PrintString( const char*, bool restrictedEntitySet );	// prints out, after detecting entities.
  1.1886 +    void Print( const char* format, ... );
  1.1887 +
  1.1888 +    bool _elementJustOpened;
  1.1889 +    bool _firstElement;
  1.1890 +    FILE* _fp;
  1.1891 +    int _depth;
  1.1892 +    int _textDepth;
  1.1893 +    bool _processEntities;
  1.1894 +    bool _compactMode;
  1.1895 +
  1.1896 +    enum {
  1.1897 +        ENTITY_RANGE = 64,
  1.1898 +        BUF_SIZE = 200
  1.1899 +    };
  1.1900 +    bool _entityFlag[ENTITY_RANGE];
  1.1901 +    bool _restrictedEntityFlag[ENTITY_RANGE];
  1.1902 +
  1.1903 +    DynArray< const char*, 10 > _stack;
  1.1904 +    DynArray< char, 20 > _buffer;
  1.1905 +#ifdef _MSC_VER
  1.1906 +    DynArray< char, 20 > _accumulator;
  1.1907 +#endif
  1.1908 +};
  1.1909 +
  1.1910 +
  1.1911 +}	// tinyxml2
  1.1912 +
  1.1913 +
  1.1914 +#endif // TINYXML2_INCLUDED