1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-06-08 09:31:58 +00:00

Bump TinyXML2 to 4.0.1

This commit is contained in:
James Le Cuirot 2017-02-08 10:21:25 +00:00 committed by James Le Cuirot
parent 55ad1e8faa
commit 5a16a290fc
No known key found for this signature in database
GPG key ID: 21C632129C6D7DE4
3 changed files with 937 additions and 507 deletions

View file

@ -9511,7 +9511,7 @@ luaFunc(loadXMLTable)
tinyxml2::XMLDocument xml; tinyxml2::XMLDocument xml;
tinyxml2::XMLError err = readXML(fn, xml); tinyxml2::XMLError err = readXML(fn, xml);
if(err != tinyxml2::XML_NO_ERROR) if(err != tinyxml2::XML_SUCCESS)
{ {
lua_pushboolean(L, false); lua_pushboolean(L, false);
lua_pushinteger(L, err); lua_pushinteger(L, err);

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,6 @@ not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation software in a product, an acknowledgment in the product documentation
would be appreciated but is not required. would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and 2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software. must not be misrepresented as being the original software.
@ -25,21 +24,23 @@ distribution.
#ifndef TINYXML2_INCLUDED #ifndef TINYXML2_INCLUDED
#define TINYXML2_INCLUDED #define TINYXML2_INCLUDED
#if defined(ANDROID_NDK) || defined(__BORLANDC__) #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
# include <ctype.h> # include <ctype.h>
# include <limits.h> # include <limits.h>
# include <stdio.h> # include <stdio.h>
# include <stdlib.h> # include <stdlib.h>
# include <string.h> # include <string.h>
# include <stdarg.h> # if defined(__PS3__)
# include <stddef.h>
# endif
#else #else
# include <cctype> # include <cctype>
# include <climits> # include <climits>
# include <cstdio> # include <cstdio>
# include <cstdlib> # include <cstdlib>
# include <cstring> # include <cstring>
# include <cstdarg>
#endif #endif
#include <stdint.h>
/* /*
TODO: intern strings instead of allocation. TODO: intern strings instead of allocation.
@ -78,7 +79,8 @@ distribution.
#if defined(DEBUG) #if defined(DEBUG)
# if defined(_MSC_VER) # if defined(_MSC_VER)
# define TIXMLASSERT( x ) if ( !(x)) { __debugbreak(); } //if ( !(x)) WinDebugBreak() # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
# define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); }
# elif defined (ANDROID_NDK) # elif defined (ANDROID_NDK)
# include <android/log.h> # include <android/log.h>
# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
@ -91,37 +93,12 @@ distribution.
#endif #endif
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
// Microsoft visual studio, version 2005 and higher.
/*int _snprintf_s(
char *buffer,
size_t sizeOfBuffer,
size_t count,
const char *format [,
argument] ...
);*/
inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
{
va_list va;
va_start( va, format );
int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
va_end( va );
return result;
}
#define TIXML_SSCANF sscanf_s
#else
// GCC version 3 and higher
//#warning( "Using sn* functions." )
#define TIXML_SNPRINTF snprintf
#define TIXML_SSCANF sscanf
#endif
/* Versioning, past 1.0.14: /* Versioning, past 1.0.14:
http://semver.org/ http://semver.org/
*/ */
static const int TIXML2_MAJOR_VERSION = 2; static const int TIXML2_MAJOR_VERSION = 4;
static const int TIXML2_MINOR_VERSION = 1; static const int TIXML2_MINOR_VERSION = 0;
static const int TIXML2_PATCH_VERSION = 0; static const int TIXML2_PATCH_VERSION = 1;
namespace tinyxml2 namespace tinyxml2
{ {
@ -146,7 +123,7 @@ public:
enum { enum {
NEEDS_ENTITY_PROCESSING = 0x01, NEEDS_ENTITY_PROCESSING = 0x01,
NEEDS_NEWLINE_NORMALIZATION = 0x02, NEEDS_NEWLINE_NORMALIZATION = 0x02,
COLLAPSE_WHITESPACE = 0x04, NEEDS_WHITESPACE_COLLAPSING = 0x04,
TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
@ -182,6 +159,8 @@ public:
char* ParseText( char* in, const char* endTag, int strFlags ); char* ParseText( char* in, const char* endTag, int strFlags );
char* ParseName( char* in ); char* ParseName( char* in );
void TransferTo( StrPair* other );
private: private:
void Reset(); void Reset();
void CollapseWhitespace(); void CollapseWhitespace();
@ -191,10 +170,12 @@ private:
NEEDS_DELETE = 0x200 NEEDS_DELETE = 0x200
}; };
// After parsing, if *_end != 0, it can be set to zero.
int _flags; int _flags;
char* _start; char* _start;
char* _end; char* _end;
StrPair( const StrPair& other ); // not supported
void operator=( StrPair& other ); // not supported, use TransferTo()
}; };
@ -203,13 +184,13 @@ private:
Has a small initial memory pool, so that low or no usage will not Has a small initial memory pool, so that low or no usage will not
cause a call to new/delete cause a call to new/delete
*/ */
template <class T, int INIT> template <class T, int INITIAL_SIZE>
class DynArray class DynArray
{ {
public: public:
DynArray< T, INIT >() { DynArray() {
_mem = _pool; _mem = _pool;
_allocated = INIT; _allocated = INITIAL_SIZE;
_size = 0; _size = 0;
} }
@ -224,11 +205,14 @@ public:
} }
void Push( T t ) { void Push( T t ) {
TIXMLASSERT( _size < INT_MAX );
EnsureCapacity( _size+1 ); EnsureCapacity( _size+1 );
_mem[_size++] = t; _mem[_size++] = t;
} }
T* PushArr( int count ) { T* PushArr( int count ) {
TIXMLASSERT( count >= 0 );
TIXMLASSERT( _size <= INT_MAX - count );
EnsureCapacity( _size+count ); EnsureCapacity( _size+count );
T* ret = &_mem[_size]; T* ret = &_mem[_size];
_size += count; _size += count;
@ -236,6 +220,7 @@ public:
} }
T Pop() { T Pop() {
TIXMLASSERT( _size > 0 );
return _mem[--_size]; return _mem[--_size];
} }
@ -264,24 +249,33 @@ public:
} }
int Size() const { int Size() const {
TIXMLASSERT( _size >= 0 );
return _size; return _size;
} }
int Capacity() const { int Capacity() const {
TIXMLASSERT( _allocated >= INITIAL_SIZE );
return _allocated; return _allocated;
} }
const T* Mem() const { const T* Mem() const {
TIXMLASSERT( _mem );
return _mem; return _mem;
} }
T* Mem() { T* Mem() {
TIXMLASSERT( _mem );
return _mem; return _mem;
} }
private: private:
DynArray( const DynArray& ); // not supported
void operator=( const DynArray& ); // not supported
void EnsureCapacity( int cap ) { void EnsureCapacity( int cap ) {
TIXMLASSERT( cap > 0 );
if ( cap > _allocated ) { if ( cap > _allocated ) {
TIXMLASSERT( cap <= INT_MAX / 2 );
int newAllocated = cap * 2; int newAllocated = cap * 2;
T* newMem = new T[newAllocated]; T* newMem = new T[newAllocated];
memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
@ -294,7 +288,7 @@ private:
} }
T* _mem; T* _mem;
T _pool[INIT]; T _pool[INITIAL_SIZE];
int _allocated; // objects allocated int _allocated; // objects allocated
int _size; // number objects in use int _size; // number objects in use
}; };
@ -314,6 +308,7 @@ public:
virtual void* Alloc() = 0; virtual void* Alloc() = 0;
virtual void Free( void* ) = 0; virtual void Free( void* ) = 0;
virtual void SetTracked() = 0; virtual void SetTracked() = 0;
virtual void Clear() = 0;
}; };
@ -326,10 +321,20 @@ class MemPoolT : public MemPool
public: public:
MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
~MemPoolT() { ~MemPoolT() {
// Delete the blocks. Clear();
for( int i=0; i<_blockPtrs.Size(); ++i ) {
delete _blockPtrs[i];
} }
void Clear() {
// Delete the blocks.
while( !_blockPtrs.Empty()) {
Block* b = _blockPtrs.Pop();
delete b;
}
_root = 0;
_currentAllocs = 0;
_nAllocs = 0;
_maxAllocs = 0;
_nUntracked = 0;
} }
virtual int ItemSize() const { virtual int ItemSize() const {
@ -362,12 +367,13 @@ public:
_nUntracked++; _nUntracked++;
return result; return result;
} }
virtual void Free( void* mem ) { virtual void Free( void* mem ) {
if ( !mem ) { if ( !mem ) {
return; return;
} }
--_currentAllocs; --_currentAllocs;
Chunk* chunk = (Chunk*)mem; Chunk* chunk = static_cast<Chunk*>( mem );
#ifdef DEBUG #ifdef DEBUG
memset( chunk, 0xfe, sizeof(Chunk) ); memset( chunk, 0xfe, sizeof(Chunk) );
#endif #endif
@ -399,6 +405,9 @@ public:
enum { COUNT = (4*1024)/SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private enum { COUNT = (4*1024)/SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private
private: private:
MemPoolT( const MemPoolT& ); // not supported
void operator=( const MemPoolT& ); // not supported
union Chunk { union Chunk {
Chunk* next; Chunk* next;
char mem[SIZE]; char mem[SIZE];
@ -477,6 +486,32 @@ public:
} }
}; };
// WARNING: must match XMLDocument::_errorNames[]
enum XMLError {
XML_SUCCESS = 0,
XML_NO_ATTRIBUTE,
XML_WRONG_ATTRIBUTE_TYPE,
XML_ERROR_FILE_NOT_FOUND,
XML_ERROR_FILE_COULD_NOT_BE_OPENED,
XML_ERROR_FILE_READ_ERROR,
XML_ERROR_ELEMENT_MISMATCH,
XML_ERROR_PARSING_ELEMENT,
XML_ERROR_PARSING_ATTRIBUTE,
XML_ERROR_IDENTIFYING_TAG,
XML_ERROR_PARSING_TEXT,
XML_ERROR_PARSING_CDATA,
XML_ERROR_PARSING_COMMENT,
XML_ERROR_PARSING_DECLARATION,
XML_ERROR_PARSING_UNKNOWN,
XML_ERROR_EMPTY_DOCUMENT,
XML_ERROR_MISMATCHED_ELEMENT,
XML_ERROR_PARSING,
XML_CAN_NOT_CONVERT_TEXT,
XML_NO_TEXT_NODE,
XML_ERROR_COUNT
};
/* /*
Utility functionality. Utility functionality.
@ -484,28 +519,33 @@ public:
class XMLUtil class XMLUtil
{ {
public: public:
// Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
// correct, but simple, and usually works.
static const char* SkipWhiteSpace( const char* p ) { static const char* SkipWhiteSpace( const char* p ) {
while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<const unsigned char*>(p) ) ) { TIXMLASSERT( p );
while( IsWhiteSpace(*p) ) {
++p; ++p;
} }
TIXMLASSERT( p );
return p; return p;
} }
static char* SkipWhiteSpace( char* p ) { static char* SkipWhiteSpace( char* p ) {
while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<unsigned char*>(p) ) ) { return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p) ) );
++p;
}
return p;
} }
// Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
// correct, but simple, and usually works.
static bool IsWhiteSpace( char p ) { static bool IsWhiteSpace( char p ) {
return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) ); return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
} }
inline static bool IsNameStartChar( unsigned char ch ) { inline static bool IsNameStartChar( unsigned char ch ) {
return ( ( ch < 128 ) ? isalpha( ch ) : 1 ) if ( ch >= 128 ) {
|| ch == ':' // This is a heuristic guess in attempt to not implement Unicode-aware isalpha()
|| ch == '_'; return true;
}
if ( isalpha( ch ) ) {
return true;
}
return ch == ':' || ch == '_';
} }
inline static bool IsNameChar( unsigned char ch ) { inline static bool IsNameChar( unsigned char ch ) {
@ -516,23 +556,14 @@ public:
} }
inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) { inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
int n = 0;
if ( p == q ) { if ( p == q ) {
return true; return true;
} }
while( *p && *q && *p == *q && n<nChar ) { return strncmp( p, q, nChar ) == 0;
++p;
++q;
++n;
}
if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
return true;
}
return false;
} }
inline static int IsUTF8Continuation( const char p ) { inline static bool IsUTF8Continuation( char p ) {
return p & 0x80; return ( p & 0x80 ) != 0;
} }
static const char* ReadBOM( const char* p, bool* hasBOM ); static const char* ReadBOM( const char* p, bool* hasBOM );
@ -547,6 +578,7 @@ public:
static void ToStr( bool v, char* buffer, int bufferSize ); static void ToStr( bool v, char* buffer, int bufferSize );
static void ToStr( float v, char* buffer, int bufferSize ); static void ToStr( float v, char* buffer, int bufferSize );
static void ToStr( double v, char* buffer, int bufferSize ); static void ToStr( double v, char* buffer, int bufferSize );
static void ToStr(int64_t v, char* buffer, int bufferSize);
// converts strings to primitive types // converts strings to primitive types
static bool ToInt( const char* str, int* value ); static bool ToInt( const char* str, int* value );
@ -554,6 +586,7 @@ public:
static bool ToBool( const char* str, bool* value ); static bool ToBool( const char* str, bool* value );
static bool ToFloat( const char* str, float* value ); static bool ToFloat( const char* str, float* value );
static bool ToDouble( const char* str, double* value ); static bool ToDouble( const char* str, double* value );
static bool ToInt64(const char* str, int64_t* value);
}; };
@ -590,10 +623,12 @@ public:
/// Get the XMLDocument that owns this XMLNode. /// Get the XMLDocument that owns this XMLNode.
const XMLDocument* GetDocument() const { const XMLDocument* GetDocument() const {
TIXMLASSERT( _document );
return _document; return _document;
} }
/// Get the XMLDocument that owns this XMLNode. /// Get the XMLDocument that owns this XMLNode.
XMLDocument* GetDocument() { XMLDocument* GetDocument() {
TIXMLASSERT( _document );
return _document; return _document;
} }
@ -643,7 +678,7 @@ public:
/** The meaning of 'value' changes for the specific type. /** The meaning of 'value' changes for the specific type.
@verbatim @verbatim
Document: empty Document: empty (NULL is returned, not an empty string)
Element: name of the element Element: name of the element
Comment: the comment text Comment: the comment text
Unknown: the tag contents Unknown: the tag contents
@ -683,10 +718,10 @@ public:
/** Get the first child element, or optionally the first child /** Get the first child element, or optionally the first child
element with the specified name. element with the specified name.
*/ */
const XMLElement* FirstChildElement( const char* value=0 ) const; const XMLElement* FirstChildElement( const char* name = 0 ) const;
XMLElement* FirstChildElement( const char* value=0 ) { XMLElement* FirstChildElement( const char* name = 0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( value )); return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name ));
} }
/// Get the last child node, or null if none exists. /// Get the last child node, or null if none exists.
@ -695,16 +730,16 @@ public:
} }
XMLNode* LastChild() { XMLNode* LastChild() {
return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->LastChild() ); return _lastChild;
} }
/** Get the last child element or optionally the last child /** Get the last child element or optionally the last child
element with the specified name. element with the specified name.
*/ */
const XMLElement* LastChildElement( const char* value=0 ) const; const XMLElement* LastChildElement( const char* name = 0 ) const;
XMLElement* LastChildElement( const char* value=0 ) { XMLElement* LastChildElement( const char* name = 0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(value) ); return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) );
} }
/// Get the previous (left) sibling node of this node. /// Get the previous (left) sibling node of this node.
@ -717,10 +752,10 @@ public:
} }
/// Get the previous (left) sibling element of this node, with an optionally supplied name. /// Get the previous (left) sibling element of this node, with an optionally supplied name.
const XMLElement* PreviousSiblingElement( const char* value=0 ) const ; const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ;
XMLElement* PreviousSiblingElement( const char* value=0 ) { XMLElement* PreviousSiblingElement( const char* name = 0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( value ) ); return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) );
} }
/// Get the next (right) sibling node of this node. /// Get the next (right) sibling node of this node.
@ -733,10 +768,10 @@ public:
} }
/// Get the next (right) sibling element of this node, with an optionally supplied name. /// Get the next (right) sibling element of this node, with an optionally supplied name.
const XMLElement* NextSiblingElement( const char* value=0 ) const; const XMLElement* NextSiblingElement( const char* name = 0 ) const;
XMLElement* NextSiblingElement( const char* value=0 ) { XMLElement* NextSiblingElement( const char* name = 0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( value ) ); return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) );
} }
/** /**
@ -822,14 +857,25 @@ public:
*/ */
virtual bool Accept( XMLVisitor* visitor ) const = 0; virtual bool Accept( XMLVisitor* visitor ) const = 0;
// internal /**
virtual char* ParseDeep( char*, StrPair* ); Set user data into the XMLNode. TinyXML-2 in
no way processes or interprets user data.
It is initially 0.
*/
void SetUserData(void* userData) { _userData = userData; }
/**
Get user data set into the XMLNode. TinyXML-2 in
no way processes or interprets user data.
It is initially 0.
*/
void* GetUserData() const { return _userData; }
protected: protected:
XMLNode( XMLDocument* ); XMLNode( XMLDocument* );
virtual ~XMLNode(); virtual ~XMLNode();
XMLNode( const XMLNode& ); // not supported
XMLNode& operator=( const XMLNode& ); // not supported virtual char* ParseDeep( char*, StrPair* );
XMLDocument* _document; XMLDocument* _document;
XMLNode* _parent; XMLNode* _parent;
@ -841,9 +887,16 @@ protected:
XMLNode* _prev; XMLNode* _prev;
XMLNode* _next; XMLNode* _next;
void* _userData;
private: private:
MemPool* _memPool; MemPool* _memPool;
void Unlink( XMLNode* child ); void Unlink( XMLNode* child );
static void DeleteNode( XMLNode* node );
void InsertChildPreamble( XMLNode* insertThis ) const;
XMLNode( const XMLNode& ); // not supported
XMLNode& operator=( const XMLNode& ); // not supported
}; };
@ -861,7 +914,6 @@ private:
*/ */
class TINYXML2_LIB XMLText : public XMLNode class TINYXML2_LIB XMLText : public XMLNode
{ {
friend class XMLBase;
friend class XMLDocument; friend class XMLDocument;
public: public:
virtual bool Accept( XMLVisitor* visitor ) const; virtual bool Accept( XMLVisitor* visitor ) const;
@ -882,18 +934,20 @@ public:
return _isCData; return _isCData;
} }
char* ParseDeep( char*, StrPair* endTag );
virtual XMLNode* ShallowClone( XMLDocument* document ) const; virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const; virtual bool ShallowEqual( const XMLNode* compare ) const;
protected: protected:
XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {} XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
virtual ~XMLText() {} virtual ~XMLText() {}
XMLText( const XMLText& ); // not supported
XMLText& operator=( const XMLText& ); // not supported char* ParseDeep( char*, StrPair* endTag );
private: private:
bool _isCData; bool _isCData;
XMLText( const XMLText& ); // not supported
XMLText& operator=( const XMLText& ); // not supported
}; };
@ -911,17 +965,18 @@ public:
virtual bool Accept( XMLVisitor* visitor ) const; virtual bool Accept( XMLVisitor* visitor ) const;
char* ParseDeep( char*, StrPair* endTag );
virtual XMLNode* ShallowClone( XMLDocument* document ) const; virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const; virtual bool ShallowEqual( const XMLNode* compare ) const;
protected: protected:
XMLComment( XMLDocument* doc ); XMLComment( XMLDocument* doc );
virtual ~XMLComment(); virtual ~XMLComment();
XMLComment( const XMLComment& ); // not supported
XMLComment& operator=( const XMLComment& ); // not supported char* ParseDeep( char*, StrPair* endTag );
private: private:
XMLComment( const XMLComment& ); // not supported
XMLComment& operator=( const XMLComment& ); // not supported
}; };
@ -949,13 +1004,16 @@ public:
virtual bool Accept( XMLVisitor* visitor ) const; virtual bool Accept( XMLVisitor* visitor ) const;
char* ParseDeep( char*, StrPair* endTag );
virtual XMLNode* ShallowClone( XMLDocument* document ) const; virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const; virtual bool ShallowEqual( const XMLNode* compare ) const;
protected: protected:
XMLDeclaration( XMLDocument* doc ); XMLDeclaration( XMLDocument* doc );
virtual ~XMLDeclaration(); virtual ~XMLDeclaration();
char* ParseDeep( char*, StrPair* endTag );
private:
XMLDeclaration( const XMLDeclaration& ); // not supported XMLDeclaration( const XMLDeclaration& ); // not supported
XMLDeclaration& operator=( const XMLDeclaration& ); // not supported XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
}; };
@ -981,45 +1039,21 @@ public:
virtual bool Accept( XMLVisitor* visitor ) const; virtual bool Accept( XMLVisitor* visitor ) const;
char* ParseDeep( char*, StrPair* endTag );
virtual XMLNode* ShallowClone( XMLDocument* document ) const; virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const; virtual bool ShallowEqual( const XMLNode* compare ) const;
protected: protected:
XMLUnknown( XMLDocument* doc ); XMLUnknown( XMLDocument* doc );
virtual ~XMLUnknown(); virtual ~XMLUnknown();
char* ParseDeep( char*, StrPair* endTag );
private:
XMLUnknown( const XMLUnknown& ); // not supported XMLUnknown( const XMLUnknown& ); // not supported
XMLUnknown& operator=( const XMLUnknown& ); // not supported XMLUnknown& operator=( const XMLUnknown& ); // not supported
}; };
enum XMLError {
XML_NO_ERROR = 0,
XML_SUCCESS = 0,
XML_NO_ATTRIBUTE,
XML_WRONG_ATTRIBUTE_TYPE,
XML_ERROR_FILE_NOT_FOUND,
XML_ERROR_FILE_COULD_NOT_BE_OPENED,
XML_ERROR_FILE_READ_ERROR,
XML_ERROR_ELEMENT_MISMATCH,
XML_ERROR_PARSING_ELEMENT,
XML_ERROR_PARSING_ATTRIBUTE,
XML_ERROR_IDENTIFYING_TAG,
XML_ERROR_PARSING_TEXT,
XML_ERROR_PARSING_CDATA,
XML_ERROR_PARSING_COMMENT,
XML_ERROR_PARSING_DECLARATION,
XML_ERROR_PARSING_UNKNOWN,
XML_ERROR_EMPTY_DOCUMENT,
XML_ERROR_MISMATCHED_ELEMENT,
XML_ERROR_PARSING,
XML_CAN_NOT_CONVERT_TEXT,
XML_NO_TEXT_NODE
};
/** An attribute is a name-value pair. Elements have an arbitrary /** An attribute is a name-value pair. Elements have an arbitrary
number of attributes, each with a unique name. number of attributes, each with a unique name.
@ -1051,6 +1085,13 @@ public:
QueryIntValue(&i); QueryIntValue(&i);
return i; return i;
} }
int64_t Int64Value() const {
int64_t i = 0;
QueryInt64Value(&i);
return i;
}
/// Query as an unsigned integer. See IntValue() /// Query as an unsigned integer. See IntValue()
unsigned UnsignedValue() const { unsigned UnsignedValue() const {
unsigned i=0; unsigned i=0;
@ -1084,6 +1125,8 @@ public:
/// See QueryIntValue /// See QueryIntValue
XMLError QueryUnsignedValue( unsigned int* value ) const; XMLError QueryUnsignedValue( unsigned int* value ) const;
/// See QueryIntValue /// See QueryIntValue
XMLError QueryInt64Value(int64_t* value) const;
/// See QueryIntValue
XMLError QueryBoolValue( bool* value ) const; XMLError QueryBoolValue( bool* value ) const;
/// See QueryIntValue /// See QueryIntValue
XMLError QueryDoubleValue( double* value ) const; XMLError QueryDoubleValue( double* value ) const;
@ -1097,6 +1140,8 @@ public:
/// Set the attribute to value. /// Set the attribute to value.
void SetAttribute( unsigned value ); void SetAttribute( unsigned value );
/// Set the attribute to value. /// Set the attribute to value.
void SetAttribute(int64_t value);
/// Set the attribute to value.
void SetAttribute( bool value ); void SetAttribute( bool value );
/// Set the attribute to value. /// Set the attribute to value.
void SetAttribute( double value ); void SetAttribute( double value );
@ -1128,7 +1173,6 @@ private:
*/ */
class TINYXML2_LIB XMLElement : public XMLNode class TINYXML2_LIB XMLElement : public XMLNode
{ {
friend class XMLBase;
friend class XMLDocument; friend class XMLDocument;
public: public:
/// Get the name of an element (which is the Value() of the node.) /// Get the name of an element (which is the Value() of the node.)
@ -1183,12 +1227,21 @@ public:
QueryIntAttribute( name, &i ); QueryIntAttribute( name, &i );
return i; return i;
} }
/// See IntAttribute() /// See IntAttribute()
unsigned UnsignedAttribute( const char* name ) const { unsigned UnsignedAttribute( const char* name ) const {
unsigned i=0; unsigned i=0;
QueryUnsignedAttribute( name, &i ); QueryUnsignedAttribute( name, &i );
return i; return i;
} }
/// See IntAttribute()
int64_t Int64Attribute(const char* name) const {
int64_t i = 0;
QueryInt64Attribute(name, &i);
return i;
}
/// See IntAttribute() /// See IntAttribute()
bool BoolAttribute( const char* name ) const { bool BoolAttribute( const char* name ) const {
bool b=false; bool b=false;
@ -1228,6 +1281,7 @@ public:
} }
return a->QueryIntValue( value ); return a->QueryIntValue( value );
} }
/// See QueryIntAttribute() /// See QueryIntAttribute()
XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const { XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
const XMLAttribute* a = FindAttribute( name ); const XMLAttribute* a = FindAttribute( name );
@ -1236,6 +1290,16 @@ public:
} }
return a->QueryUnsignedValue( value ); return a->QueryUnsignedValue( value );
} }
/// See QueryIntAttribute()
XMLError QueryInt64Attribute(const char* name, int64_t* value) const {
const XMLAttribute* a = FindAttribute(name);
if (!a) {
return XML_NO_ATTRIBUTE;
}
return a->QueryInt64Value(value);
}
/// See QueryIntAttribute() /// See QueryIntAttribute()
XMLError QueryBoolAttribute( const char* name, bool* value ) const { XMLError QueryBoolAttribute( const char* name, bool* value ) const {
const XMLAttribute* a = FindAttribute( name ); const XMLAttribute* a = FindAttribute( name );
@ -1287,6 +1351,10 @@ public:
return QueryUnsignedAttribute( name, value ); return QueryUnsignedAttribute( name, value );
} }
int QueryAttribute(const char* name, int64_t* value) const {
return QueryInt64Attribute(name, value);
}
int QueryAttribute( const char* name, bool* value ) const { int QueryAttribute( const char* name, bool* value ) const {
return QueryBoolAttribute( name, value ); return QueryBoolAttribute( name, value );
} }
@ -1314,6 +1382,13 @@ public:
XMLAttribute* a = FindOrCreateAttribute( name ); XMLAttribute* a = FindOrCreateAttribute( name );
a->SetAttribute( value ); a->SetAttribute( value );
} }
/// Sets the named attribute to value.
void SetAttribute(const char* name, int64_t value) {
XMLAttribute* a = FindOrCreateAttribute(name);
a->SetAttribute(value);
}
/// Sets the named attribute to value. /// Sets the named attribute to value.
void SetAttribute( const char* name, bool value ) { void SetAttribute( const char* name, bool value ) {
XMLAttribute* a = FindOrCreateAttribute( name ); XMLAttribute* a = FindOrCreateAttribute( name );
@ -1407,15 +1482,17 @@ public:
@endverbatim @endverbatim
*/ */
void SetText( const char* inText ); void SetText( const char* inText );
/// Convenience method for setting text inside and element. See SetText() for important limitations. /// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText( int value ); void SetText( int value );
/// Convenience method for setting text inside and element. See SetText() for important limitations. /// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText( unsigned value ); void SetText( unsigned value );
/// Convenience method for setting text inside and element. See SetText() for important limitations. /// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText(int64_t value);
/// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText( bool value ); void SetText( bool value );
/// Convenience method for setting text inside and element. See SetText() for important limitations. /// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText( double value ); void SetText( double value );
/// Convenience method for setting text inside and element. See SetText() for important limitations. /// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText( float value ); void SetText( float value );
/** /**
@ -1448,6 +1525,8 @@ public:
/// See QueryIntText() /// See QueryIntText()
XMLError QueryUnsignedText( unsigned* uval ) const; XMLError QueryUnsignedText( unsigned* uval ) const;
/// See QueryIntText() /// See QueryIntText()
XMLError QueryInt64Text(int64_t* uval) const;
/// See QueryIntText()
XMLError QueryBoolText( bool* bval ) const; XMLError QueryBoolText( bool* bval ) const;
/// See QueryIntText() /// See QueryIntText()
XMLError QueryDoubleText( double* dval ) const; XMLError QueryDoubleText( double* dval ) const;
@ -1463,20 +1542,25 @@ public:
int ClosingType() const { int ClosingType() const {
return _closingType; return _closingType;
} }
char* ParseDeep( char* p, StrPair* endTag );
virtual XMLNode* ShallowClone( XMLDocument* document ) const; virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const; virtual bool ShallowEqual( const XMLNode* compare ) const;
protected:
char* ParseDeep( char* p, StrPair* endTag );
private: private:
XMLElement( XMLDocument* doc ); XMLElement( XMLDocument* doc );
virtual ~XMLElement(); virtual ~XMLElement();
XMLElement( const XMLElement& ); // not supported XMLElement( const XMLElement& ); // not supported
void operator=( const XMLElement& ); // not supported void operator=( const XMLElement& ); // not supported
XMLAttribute* FindAttribute( const char* name ); XMLAttribute* FindAttribute( const char* name ) {
return const_cast<XMLAttribute*>(const_cast<const XMLElement*>(this)->FindAttribute( name ));
}
XMLAttribute* FindOrCreateAttribute( const char* name ); XMLAttribute* FindOrCreateAttribute( const char* name );
//void LinkAttribute( XMLAttribute* attrib ); //void LinkAttribute( XMLAttribute* attrib );
char* ParseAttributes( char* p ); char* ParseAttributes( char* p );
static void DeleteAttribute( XMLAttribute* attribute );
enum { BUF_SIZE = 200 }; enum { BUF_SIZE = 200 };
int _closingType; int _closingType;
@ -1507,9 +1591,11 @@ public:
~XMLDocument(); ~XMLDocument();
virtual XMLDocument* ToDocument() { virtual XMLDocument* ToDocument() {
TIXMLASSERT( this == _document );
return this; return this;
} }
virtual const XMLDocument* ToDocument() const { virtual const XMLDocument* ToDocument() const {
TIXMLASSERT( this == _document );
return this; return this;
} }
@ -1530,16 +1616,20 @@ public:
Returns XML_NO_ERROR (0) on success, or Returns XML_NO_ERROR (0) on success, or
an errorID. an errorID.
*/ */
//XMLError LoadFile( const char* filename ); XMLError LoadFile( const char* filename );
/** /**
Load an XML file from disk. You are responsible Load an XML file from disk. You are responsible
for providing and closing the FILE*. for providing and closing the FILE*.
NOTE: The file should be opened as binary ("rb")
not text in order for TinyXML-2 to correctly
do newline normalization.
Returns XML_NO_ERROR (0) on success, or Returns XML_NO_ERROR (0) on success, or
an errorID. an errorID.
*/ */
//XMLError LoadFile( FILE* ); XMLError LoadFile( FILE* );
/** /**
Save the XML file to disk. Save the XML file to disk.
@ -1644,20 +1734,20 @@ public:
Delete a node associated with this document. Delete a node associated with this document.
It will be unlinked from the DOM. It will be unlinked from the DOM.
*/ */
void DeleteNode( XMLNode* node ) { void DeleteNode( XMLNode* node );
node->_parent->DeleteChild( node );
}
void SetError( XMLError error, const char* str1, const char* str2 ); void SetError( XMLError error, const char* str1, const char* str2 );
/// Return true if there was an error parsing the document. /// Return true if there was an error parsing the document.
bool Error() const { bool Error() const {
return _errorID != XML_NO_ERROR; return _errorID != XML_SUCCESS;
} }
/// Return the errorID. /// Return the errorID.
XMLError ErrorID() const { XMLError ErrorID() const {
return _errorID; return _errorID;
} }
const char* ErrorName() const;
/// Return a possibly helpful diagnostic location or string. /// Return a possibly helpful diagnostic location or string.
const char* GetErrorStr1() const { const char* GetErrorStr1() const {
return _errorStr1; return _errorStr1;
@ -1698,6 +1788,10 @@ private:
MemPoolT< sizeof(XMLAttribute) > _attributePool; MemPoolT< sizeof(XMLAttribute) > _attributePool;
MemPoolT< sizeof(XMLText) > _textPool; MemPoolT< sizeof(XMLText) > _textPool;
MemPoolT< sizeof(XMLComment) > _commentPool; MemPoolT< sizeof(XMLComment) > _commentPool;
static const char* _errorNames[XML_ERROR_COUNT];
void Parse();
}; };
@ -1741,7 +1835,7 @@ private:
@verbatim @verbatim
XMLHandle docHandle( &document ); XMLHandle docHandle( &document );
XMLElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild().NextSibling().ToElement(); XMLElement* child2 = docHandle.FirstChildElement( "Document" ).FirstChildElement( "Element" ).FirstChildElement().NextSiblingElement();
if ( child2 ) if ( child2 )
{ {
// do something useful // do something useful
@ -1782,32 +1876,32 @@ public:
return XMLHandle( _node ? _node->FirstChild() : 0 ); return XMLHandle( _node ? _node->FirstChild() : 0 );
} }
/// Get the first child element of this handle. /// Get the first child element of this handle.
XMLHandle FirstChildElement( const char* value=0 ) { XMLHandle FirstChildElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->FirstChildElement( value ) : 0 ); return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
} }
/// Get the last child of this handle. /// Get the last child of this handle.
XMLHandle LastChild() { XMLHandle LastChild() {
return XMLHandle( _node ? _node->LastChild() : 0 ); return XMLHandle( _node ? _node->LastChild() : 0 );
} }
/// Get the last child element of this handle. /// Get the last child element of this handle.
XMLHandle LastChildElement( const char* _value=0 ) { XMLHandle LastChildElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->LastChildElement( _value ) : 0 ); return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
} }
/// Get the previous sibling of this handle. /// Get the previous sibling of this handle.
XMLHandle PreviousSibling() { XMLHandle PreviousSibling() {
return XMLHandle( _node ? _node->PreviousSibling() : 0 ); return XMLHandle( _node ? _node->PreviousSibling() : 0 );
} }
/// Get the previous sibling element of this handle. /// Get the previous sibling element of this handle.
XMLHandle PreviousSiblingElement( const char* _value=0 ) { XMLHandle PreviousSiblingElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 ); return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
} }
/// Get the next sibling of this handle. /// Get the next sibling of this handle.
XMLHandle NextSibling() { XMLHandle NextSibling() {
return XMLHandle( _node ? _node->NextSibling() : 0 ); return XMLHandle( _node ? _node->NextSibling() : 0 );
} }
/// Get the next sibling element of this handle. /// Get the next sibling element of this handle.
XMLHandle NextSiblingElement( const char* _value=0 ) { XMLHandle NextSiblingElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->NextSiblingElement( _value ) : 0 ); return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
} }
/// Safe cast to XMLNode. This can return null. /// Safe cast to XMLNode. This can return null.
@ -1816,19 +1910,19 @@ public:
} }
/// Safe cast to XMLElement. This can return null. /// Safe cast to XMLElement. This can return null.
XMLElement* ToElement() { XMLElement* ToElement() {
return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 ); return ( ( _node == 0 ) ? 0 : _node->ToElement() );
} }
/// Safe cast to XMLText. This can return null. /// Safe cast to XMLText. This can return null.
XMLText* ToText() { XMLText* ToText() {
return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 ); return ( ( _node == 0 ) ? 0 : _node->ToText() );
} }
/// Safe cast to XMLUnknown. This can return null. /// Safe cast to XMLUnknown. This can return null.
XMLUnknown* ToUnknown() { XMLUnknown* ToUnknown() {
return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 ); return ( ( _node == 0 ) ? 0 : _node->ToUnknown() );
} }
/// Safe cast to XMLDeclaration. This can return null. /// Safe cast to XMLDeclaration. This can return null.
XMLDeclaration* ToDeclaration() { XMLDeclaration* ToDeclaration() {
return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 ); return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() );
} }
private: private:
@ -1861,26 +1955,26 @@ public:
const XMLConstHandle FirstChild() const { const XMLConstHandle FirstChild() const {
return XMLConstHandle( _node ? _node->FirstChild() : 0 ); return XMLConstHandle( _node ? _node->FirstChild() : 0 );
} }
const XMLConstHandle FirstChildElement( const char* value=0 ) const { const XMLConstHandle FirstChildElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->FirstChildElement( value ) : 0 ); return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
} }
const XMLConstHandle LastChild() const { const XMLConstHandle LastChild() const {
return XMLConstHandle( _node ? _node->LastChild() : 0 ); return XMLConstHandle( _node ? _node->LastChild() : 0 );
} }
const XMLConstHandle LastChildElement( const char* _value=0 ) const { const XMLConstHandle LastChildElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->LastChildElement( _value ) : 0 ); return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
} }
const XMLConstHandle PreviousSibling() const { const XMLConstHandle PreviousSibling() const {
return XMLConstHandle( _node ? _node->PreviousSibling() : 0 ); return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
} }
const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const { const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 ); return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
} }
const XMLConstHandle NextSibling() const { const XMLConstHandle NextSibling() const {
return XMLConstHandle( _node ? _node->NextSibling() : 0 ); return XMLConstHandle( _node ? _node->NextSibling() : 0 );
} }
const XMLConstHandle NextSiblingElement( const char* _value=0 ) const { const XMLConstHandle NextSiblingElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->NextSiblingElement( _value ) : 0 ); return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
} }
@ -1888,16 +1982,16 @@ public:
return _node; return _node;
} }
const XMLElement* ToElement() const { const XMLElement* ToElement() const {
return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 ); return ( ( _node == 0 ) ? 0 : _node->ToElement() );
} }
const XMLText* ToText() const { const XMLText* ToText() const {
return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 ); return ( ( _node == 0 ) ? 0 : _node->ToText() );
} }
const XMLUnknown* ToUnknown() const { const XMLUnknown* ToUnknown() const {
return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 ); return ( ( _node == 0 ) ? 0 : _node->ToUnknown() );
} }
const XMLDeclaration* ToDeclaration() const { const XMLDeclaration* ToDeclaration() const {
return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 ); return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() );
} }
private: private:
@ -1969,6 +2063,7 @@ public:
void PushAttribute( const char* name, const char* value ); void PushAttribute( const char* name, const char* value );
void PushAttribute( const char* name, int value ); void PushAttribute( const char* name, int value );
void PushAttribute( const char* name, unsigned value ); void PushAttribute( const char* name, unsigned value );
void PushAttribute(const char* name, int64_t value);
void PushAttribute( const char* name, bool value ); void PushAttribute( const char* name, bool value );
void PushAttribute( const char* name, double value ); void PushAttribute( const char* name, double value );
/// If streaming, close the Element. /// If streaming, close the Element.
@ -1980,6 +2075,8 @@ public:
void PushText( int value ); void PushText( int value );
/// Add a text node from an unsigned. /// Add a text node from an unsigned.
void PushText( unsigned value ); void PushText( unsigned value );
/// Add a text node from an unsigned.
void PushText(int64_t value);
/// Add a text node from a bool. /// Add a text node from a bool.
void PushText( bool value ); void PushText( bool value );
/// Add a text node from a float. /// Add a text node from a float.
@ -2039,7 +2136,7 @@ protected:
virtual void PrintSpace( int depth ); virtual void PrintSpace( int depth );
void Print( const char* format, ... ); void Print( const char* format, ... );
void SealElement(); void SealElementIfJustOpened();
bool _elementJustOpened; bool _elementJustOpened;
DynArray< const char*, 10 > _stack; DynArray< const char*, 10 > _stack;
@ -2061,9 +2158,6 @@ private:
bool _restrictedEntityFlag[ENTITY_RANGE]; bool _restrictedEntityFlag[ENTITY_RANGE];
DynArray< char, 20 > _buffer; DynArray< char, 20 > _buffer;
#ifdef _MSC_VER
DynArray< char, 20 > _accumulator;
#endif
}; };