fixed some potential issues with MAC addresses
added corresponding test-cases switched to newer version of tinyxml due to some issues adjusted affected code-parts accordingly for better re-use, moved ceiling-calculation to a new class some minor fixes new helper methods worked on wifi-opt
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,9 @@ distribution.
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# if defined(__PS3__)
|
||||
# include <stddef.h>
|
||||
# endif
|
||||
#else
|
||||
# include <cctype>
|
||||
# include <climits>
|
||||
@@ -37,6 +40,7 @@ distribution.
|
||||
# include <cstdlib>
|
||||
# include <cstring>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
TODO: intern strings instead of allocation.
|
||||
@@ -68,6 +72,8 @@ distribution.
|
||||
# else
|
||||
# define TINYXML2_LIB
|
||||
# endif
|
||||
#elif __GNUC__ >= 4
|
||||
# define TINYXML2_LIB __attribute__((visibility("default")))
|
||||
#else
|
||||
# define TINYXML2_LIB
|
||||
#endif
|
||||
@@ -92,9 +98,9 @@ distribution.
|
||||
/* Versioning, past 1.0.14:
|
||||
http://semver.org/
|
||||
*/
|
||||
static const int TIXML2_MAJOR_VERSION = 3;
|
||||
static const int TIXML2_MAJOR_VERSION = 4;
|
||||
static const int TIXML2_MINOR_VERSION = 0;
|
||||
static const int TIXML2_PATCH_VERSION = 0;
|
||||
static const int TIXML2_PATCH_VERSION = 1;
|
||||
|
||||
namespace tinyxml2
|
||||
{
|
||||
@@ -121,18 +127,20 @@ public:
|
||||
NEEDS_NEWLINE_NORMALIZATION = 0x02,
|
||||
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,
|
||||
ATTRIBUTE_NAME = 0,
|
||||
ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
|
||||
ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
|
||||
COMMENT = NEEDS_NEWLINE_NORMALIZATION
|
||||
ATTRIBUTE_NAME = 0,
|
||||
ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
|
||||
ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
|
||||
COMMENT = NEEDS_NEWLINE_NORMALIZATION
|
||||
};
|
||||
|
||||
StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
|
||||
~StrPair();
|
||||
|
||||
void Set( char* start, char* end, int flags ) {
|
||||
TIXMLASSERT( start );
|
||||
TIXMLASSERT( end );
|
||||
Reset();
|
||||
_start = start;
|
||||
_end = end;
|
||||
@@ -152,13 +160,13 @@ public:
|
||||
|
||||
void SetStr( const char* str, int flags=0 );
|
||||
|
||||
char* ParseText( char* in, const char* endTag, int strFlags );
|
||||
char* ParseText( char* in, const char* endTag, int strFlags, int* curLineNumPtr );
|
||||
char* ParseName( char* in );
|
||||
|
||||
void TransferTo( StrPair* other );
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
void Reset();
|
||||
void CollapseWhitespace();
|
||||
|
||||
enum {
|
||||
@@ -203,7 +211,8 @@ public:
|
||||
void Push( T t ) {
|
||||
TIXMLASSERT( _size < INT_MAX );
|
||||
EnsureCapacity( _size+1 );
|
||||
_mem[_size++] = t;
|
||||
_mem[_size] = t;
|
||||
++_size;
|
||||
}
|
||||
|
||||
T* PushArr( int count ) {
|
||||
@@ -217,7 +226,8 @@ public:
|
||||
|
||||
T Pop() {
|
||||
TIXMLASSERT( _size > 0 );
|
||||
return _mem[--_size];
|
||||
--_size;
|
||||
return _mem[_size];
|
||||
}
|
||||
|
||||
void PopArr( int count ) {
|
||||
@@ -311,7 +321,7 @@ public:
|
||||
/*
|
||||
Template child class to create pools of the correct type.
|
||||
*/
|
||||
template< int SIZE >
|
||||
template< int ITEM_SIZE >
|
||||
class MemPoolT : public MemPool
|
||||
{
|
||||
public:
|
||||
@@ -334,7 +344,7 @@ public:
|
||||
}
|
||||
|
||||
virtual int ItemSize() const {
|
||||
return SIZE;
|
||||
return ITEM_SIZE;
|
||||
}
|
||||
int CurrentAllocs() const {
|
||||
return _currentAllocs;
|
||||
@@ -346,21 +356,23 @@ public:
|
||||
Block* block = new Block();
|
||||
_blockPtrs.Push( block );
|
||||
|
||||
for( int i=0; i<COUNT-1; ++i ) {
|
||||
block->chunk[i].next = &block->chunk[i+1];
|
||||
Item* blockItems = block->items;
|
||||
for( int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
|
||||
blockItems[i].next = &(blockItems[i + 1]);
|
||||
}
|
||||
block->chunk[COUNT-1].next = 0;
|
||||
_root = block->chunk;
|
||||
blockItems[ITEMS_PER_BLOCK - 1].next = 0;
|
||||
_root = blockItems;
|
||||
}
|
||||
void* result = _root;
|
||||
Item* const result = _root;
|
||||
TIXMLASSERT( result != 0 );
|
||||
_root = _root->next;
|
||||
|
||||
++_currentAllocs;
|
||||
if ( _currentAllocs > _maxAllocs ) {
|
||||
_maxAllocs = _currentAllocs;
|
||||
}
|
||||
_nAllocs++;
|
||||
_nUntracked++;
|
||||
++_nAllocs;
|
||||
++_nUntracked;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -369,20 +381,21 @@ public:
|
||||
return;
|
||||
}
|
||||
--_currentAllocs;
|
||||
Chunk* chunk = static_cast<Chunk*>( mem );
|
||||
Item* item = static_cast<Item*>( mem );
|
||||
#ifdef DEBUG
|
||||
memset( chunk, 0xfe, sizeof(Chunk) );
|
||||
memset( item, 0xfe, sizeof( *item ) );
|
||||
#endif
|
||||
chunk->next = _root;
|
||||
_root = chunk;
|
||||
item->next = _root;
|
||||
_root = item;
|
||||
}
|
||||
void Trace( const char* name ) {
|
||||
printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
|
||||
name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() );
|
||||
name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs,
|
||||
ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
|
||||
}
|
||||
|
||||
void SetTracked() {
|
||||
_nUntracked--;
|
||||
--_nUntracked;
|
||||
}
|
||||
|
||||
int Untracked() const {
|
||||
@@ -398,21 +411,23 @@ public:
|
||||
// 16k: 5200
|
||||
// 32k: 4300
|
||||
// 64k: 4000 21000
|
||||
enum { COUNT = (4*1024)/SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private
|
||||
// Declared public because some compilers do not accept to use ITEMS_PER_BLOCK
|
||||
// in private part if ITEMS_PER_BLOCK is private
|
||||
enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE };
|
||||
|
||||
private:
|
||||
MemPoolT( const MemPoolT& ); // not supported
|
||||
void operator=( const MemPoolT& ); // not supported
|
||||
|
||||
union Chunk {
|
||||
Chunk* next;
|
||||
char mem[SIZE];
|
||||
union Item {
|
||||
Item* next;
|
||||
char itemData[ITEM_SIZE];
|
||||
};
|
||||
struct Block {
|
||||
Chunk chunk[COUNT];
|
||||
Item items[ITEMS_PER_BLOCK];
|
||||
};
|
||||
DynArray< Block*, 10 > _blockPtrs;
|
||||
Chunk* _root;
|
||||
Item* _root;
|
||||
|
||||
int _currentAllocs;
|
||||
int _nAllocs;
|
||||
@@ -485,7 +500,6 @@ public:
|
||||
// WARNING: must match XMLDocument::_errorNames[]
|
||||
enum XMLError {
|
||||
XML_SUCCESS = 0,
|
||||
XML_NO_ERROR = 0,
|
||||
XML_NO_ATTRIBUTE,
|
||||
XML_WRONG_ATTRIBUTE_TYPE,
|
||||
XML_ERROR_FILE_NOT_FOUND,
|
||||
@@ -513,19 +527,23 @@ enum XMLError {
|
||||
/*
|
||||
Utility functionality.
|
||||
*/
|
||||
class XMLUtil
|
||||
class TINYXML2_LIB XMLUtil
|
||||
{
|
||||
public:
|
||||
static const char* SkipWhiteSpace( const char* p ) {
|
||||
static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) {
|
||||
TIXMLASSERT( p );
|
||||
|
||||
while( IsWhiteSpace(*p) ) {
|
||||
if (curLineNumPtr && *p == '\n') {
|
||||
++(*curLineNumPtr);
|
||||
}
|
||||
++p;
|
||||
}
|
||||
TIXMLASSERT( p );
|
||||
return p;
|
||||
}
|
||||
static char* SkipWhiteSpace( char* p ) {
|
||||
return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p) ) );
|
||||
static char* SkipWhiteSpace( char* p, int* curLineNumPtr ) {
|
||||
return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p), curLineNumPtr ) );
|
||||
}
|
||||
|
||||
// Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
|
||||
@@ -556,6 +574,9 @@ public:
|
||||
if ( p == q ) {
|
||||
return true;
|
||||
}
|
||||
TIXMLASSERT( p );
|
||||
TIXMLASSERT( q );
|
||||
TIXMLASSERT( nChar >= 0 );
|
||||
return strncmp( p, q, nChar ) == 0;
|
||||
}
|
||||
|
||||
@@ -575,6 +596,7 @@ public:
|
||||
static void ToStr( bool 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(int64_t v, char* buffer, int bufferSize);
|
||||
|
||||
// converts strings to primitive types
|
||||
static bool ToInt( const char* str, int* value );
|
||||
@@ -582,6 +604,18 @@ public:
|
||||
static bool ToBool( const char* str, bool* value );
|
||||
static bool ToFloat( const char* str, float* value );
|
||||
static bool ToDouble( const char* str, double* value );
|
||||
static bool ToInt64(const char* str, int64_t* value);
|
||||
|
||||
// Changes what is serialized for a boolean value.
|
||||
// Default to "true" and "false". Shouldn't be changed
|
||||
// unless you have a special testing or compatibility need.
|
||||
// Be careful: static, global, & not thread safe.
|
||||
// Be sure to set static const memory as parameters.
|
||||
static void SetBoolSerialization(const char* writeTrue, const char* writeFalse);
|
||||
|
||||
private:
|
||||
static const char* writeBoolTrue;
|
||||
static const char* writeBoolFalse;
|
||||
};
|
||||
|
||||
|
||||
@@ -687,6 +721,9 @@ public:
|
||||
*/
|
||||
void SetValue( const char* val, bool staticMem=false );
|
||||
|
||||
/// Gets the line number the node is in, if the document was parsed from a file.
|
||||
int GetLineNum() const { return _parseLineNum; }
|
||||
|
||||
/// Get the parent of this node on the DOM.
|
||||
const XMLNode* Parent() const {
|
||||
return _parent;
|
||||
@@ -852,15 +889,30 @@ public:
|
||||
*/
|
||||
virtual bool Accept( XMLVisitor* visitor ) const = 0;
|
||||
|
||||
/**
|
||||
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:
|
||||
XMLNode( XMLDocument* );
|
||||
virtual ~XMLNode();
|
||||
|
||||
virtual char* ParseDeep( char*, StrPair* );
|
||||
virtual char* ParseDeep( char*, StrPair*, int* );
|
||||
|
||||
XMLDocument* _document;
|
||||
XMLNode* _parent;
|
||||
mutable StrPair _value;
|
||||
int _parseLineNum;
|
||||
|
||||
XMLNode* _firstChild;
|
||||
XMLNode* _lastChild;
|
||||
@@ -868,11 +920,14 @@ protected:
|
||||
XMLNode* _prev;
|
||||
XMLNode* _next;
|
||||
|
||||
void* _userData;
|
||||
|
||||
private:
|
||||
MemPool* _memPool;
|
||||
void Unlink( XMLNode* child );
|
||||
static void DeleteNode( XMLNode* node );
|
||||
void InsertChildPreamble( XMLNode* insertThis ) const;
|
||||
const XMLElement* ToElementWithName( const char* name ) const;
|
||||
|
||||
XMLNode( const XMLNode& ); // not supported
|
||||
XMLNode& operator=( const XMLNode& ); // not supported
|
||||
@@ -893,7 +948,6 @@ private:
|
||||
*/
|
||||
class TINYXML2_LIB XMLText : public XMLNode
|
||||
{
|
||||
friend class XMLBase;
|
||||
friend class XMLDocument;
|
||||
public:
|
||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
||||
@@ -921,7 +975,7 @@ protected:
|
||||
XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
|
||||
virtual ~XMLText() {}
|
||||
|
||||
char* ParseDeep( char*, StrPair* endTag );
|
||||
char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr );
|
||||
|
||||
private:
|
||||
bool _isCData;
|
||||
@@ -952,7 +1006,7 @@ protected:
|
||||
XMLComment( XMLDocument* doc );
|
||||
virtual ~XMLComment();
|
||||
|
||||
char* ParseDeep( char*, StrPair* endTag );
|
||||
char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr);
|
||||
|
||||
private:
|
||||
XMLComment( const XMLComment& ); // not supported
|
||||
@@ -991,7 +1045,7 @@ protected:
|
||||
XMLDeclaration( XMLDocument* doc );
|
||||
virtual ~XMLDeclaration();
|
||||
|
||||
char* ParseDeep( char*, StrPair* endTag );
|
||||
char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr );
|
||||
|
||||
private:
|
||||
XMLDeclaration( const XMLDeclaration& ); // not supported
|
||||
@@ -1026,7 +1080,7 @@ protected:
|
||||
XMLUnknown( XMLDocument* doc );
|
||||
virtual ~XMLUnknown();
|
||||
|
||||
char* ParseDeep( char*, StrPair* endTag );
|
||||
char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr );
|
||||
|
||||
private:
|
||||
XMLUnknown( const XMLUnknown& ); // not supported
|
||||
@@ -1051,6 +1105,9 @@ public:
|
||||
/// The value of the attribute.
|
||||
const char* Value() const;
|
||||
|
||||
/// Gets the line number the attribute is in, if the document was parsed from a file.
|
||||
int GetLineNum() const { return _parseLineNum; }
|
||||
|
||||
/// The next attribute in the list.
|
||||
const XMLAttribute* Next() const {
|
||||
return _next;
|
||||
@@ -1060,11 +1117,18 @@ public:
|
||||
If the value isn't an integer, 0 will be returned. There is no error checking;
|
||||
use QueryIntValue() if you need error checking.
|
||||
*/
|
||||
int IntValue() const {
|
||||
int i=0;
|
||||
QueryIntValue( &i );
|
||||
return i;
|
||||
}
|
||||
int IntValue() const {
|
||||
int i = 0;
|
||||
QueryIntValue(&i);
|
||||
return i;
|
||||
}
|
||||
|
||||
int64_t Int64Value() const {
|
||||
int64_t i = 0;
|
||||
QueryInt64Value(&i);
|
||||
return i;
|
||||
}
|
||||
|
||||
/// Query as an unsigned integer. See IntValue()
|
||||
unsigned UnsignedValue() const {
|
||||
unsigned i=0;
|
||||
@@ -1091,13 +1155,15 @@ public:
|
||||
}
|
||||
|
||||
/** QueryIntValue interprets the attribute as an integer, and returns the value
|
||||
in the provided parameter. The function will return XML_NO_ERROR on success,
|
||||
in the provided parameter. The function will return XML_SUCCESS on success,
|
||||
and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful.
|
||||
*/
|
||||
XMLError QueryIntValue( int* value ) const;
|
||||
/// See QueryIntValue
|
||||
XMLError QueryUnsignedValue( unsigned int* value ) const;
|
||||
/// See QueryIntValue
|
||||
/// See QueryIntValue
|
||||
XMLError QueryInt64Value(int64_t* value) const;
|
||||
/// See QueryIntValue
|
||||
XMLError QueryBoolValue( bool* value ) const;
|
||||
/// See QueryIntValue
|
||||
XMLError QueryDoubleValue( double* value ) const;
|
||||
@@ -1110,7 +1176,9 @@ public:
|
||||
void SetAttribute( int value );
|
||||
/// Set the attribute to 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 );
|
||||
/// Set the attribute to value.
|
||||
void SetAttribute( double value );
|
||||
@@ -1120,17 +1188,18 @@ public:
|
||||
private:
|
||||
enum { BUF_SIZE = 200 };
|
||||
|
||||
XMLAttribute() : _next( 0 ), _memPool( 0 ) {}
|
||||
XMLAttribute() : _parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
|
||||
virtual ~XMLAttribute() {}
|
||||
|
||||
XMLAttribute( const XMLAttribute& ); // not supported
|
||||
void operator=( const XMLAttribute& ); // not supported
|
||||
void SetName( const char* name );
|
||||
|
||||
char* ParseDeep( char* p, bool processEntities );
|
||||
char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr );
|
||||
|
||||
mutable StrPair _name;
|
||||
mutable StrPair _value;
|
||||
int _parseLineNum;
|
||||
XMLAttribute* _next;
|
||||
MemPool* _memPool;
|
||||
};
|
||||
@@ -1142,7 +1211,6 @@ private:
|
||||
*/
|
||||
class TINYXML2_LIB XMLElement : public XMLNode
|
||||
{
|
||||
friend class XMLBase;
|
||||
friend class XMLDocument;
|
||||
public:
|
||||
/// Get the name of an element (which is the Value() of the node.)
|
||||
@@ -1188,42 +1256,25 @@ public:
|
||||
const char* Attribute( const char* name, const char* value=0 ) const;
|
||||
|
||||
/** Given an attribute name, IntAttribute() returns the value
|
||||
of the attribute interpreted as an integer. 0 will be
|
||||
returned if there is an error. For a method with error
|
||||
checking, see QueryIntAttribute()
|
||||
of the attribute interpreted as an integer. The default
|
||||
value will be returned if the attribute isn't present,
|
||||
or if there is an error. (For a method with error
|
||||
checking, see QueryIntAttribute()).
|
||||
*/
|
||||
int IntAttribute( const char* name ) const {
|
||||
int i=0;
|
||||
QueryIntAttribute( name, &i );
|
||||
return i;
|
||||
}
|
||||
int IntAttribute(const char* name, int defaultValue = 0) const;
|
||||
/// See IntAttribute()
|
||||
unsigned UnsignedAttribute( const char* name ) const {
|
||||
unsigned i=0;
|
||||
QueryUnsignedAttribute( name, &i );
|
||||
return i;
|
||||
}
|
||||
unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const;
|
||||
/// See IntAttribute()
|
||||
int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const;
|
||||
/// See IntAttribute()
|
||||
bool BoolAttribute(const char* name, bool defaultValue = false) const;
|
||||
/// See IntAttribute()
|
||||
bool BoolAttribute( const char* name ) const {
|
||||
bool b=false;
|
||||
QueryBoolAttribute( name, &b );
|
||||
return b;
|
||||
}
|
||||
double DoubleAttribute(const char* name, double defaultValue = 0) const;
|
||||
/// See IntAttribute()
|
||||
double DoubleAttribute( const char* name ) const {
|
||||
double d=0;
|
||||
QueryDoubleAttribute( name, &d );
|
||||
return d;
|
||||
}
|
||||
/// See IntAttribute()
|
||||
float FloatAttribute( const char* name ) const {
|
||||
float f=0;
|
||||
QueryFloatAttribute( name, &f );
|
||||
return f;
|
||||
}
|
||||
float FloatAttribute(const char* name, float defaultValue = 0) const;
|
||||
|
||||
/** Given an attribute name, QueryIntAttribute() returns
|
||||
XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion
|
||||
XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion
|
||||
can't be performed, or XML_NO_ATTRIBUTE if the attribute
|
||||
doesn't exist. If successful, the result of the conversion
|
||||
will be written to 'value'. If not successful, nothing will
|
||||
@@ -1242,7 +1293,8 @@ public:
|
||||
}
|
||||
return a->QueryIntValue( value );
|
||||
}
|
||||
/// See QueryIntAttribute()
|
||||
|
||||
/// See QueryIntAttribute()
|
||||
XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
|
||||
const XMLAttribute* a = FindAttribute( name );
|
||||
if ( !a ) {
|
||||
@@ -1250,7 +1302,17 @@ public:
|
||||
}
|
||||
return a->QueryUnsignedValue( value );
|
||||
}
|
||||
/// See QueryIntAttribute()
|
||||
|
||||
/// 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()
|
||||
XMLError QueryBoolAttribute( const char* name, bool* value ) const {
|
||||
const XMLAttribute* a = FindAttribute( name );
|
||||
if ( !a ) {
|
||||
@@ -1277,7 +1339,7 @@ public:
|
||||
|
||||
|
||||
/** Given an attribute name, QueryAttribute() returns
|
||||
XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion
|
||||
XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion
|
||||
can't be performed, or XML_NO_ATTRIBUTE if the attribute
|
||||
doesn't exist. It is overloaded for the primitive types,
|
||||
and is a generally more convenient replacement of
|
||||
@@ -1301,6 +1363,10 @@ public:
|
||||
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 {
|
||||
return QueryBoolAttribute( name, value );
|
||||
}
|
||||
@@ -1328,7 +1394,14 @@ public:
|
||||
XMLAttribute* a = FindOrCreateAttribute( name );
|
||||
a->SetAttribute( value );
|
||||
}
|
||||
/// Sets the named attribute to 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.
|
||||
void SetAttribute( const char* name, bool value ) {
|
||||
XMLAttribute* a = FindOrCreateAttribute( name );
|
||||
a->SetAttribute( value );
|
||||
@@ -1425,7 +1498,9 @@ public:
|
||||
void SetText( int value );
|
||||
/// Convenience method for setting text inside an element. See SetText() for important limitations.
|
||||
void SetText( unsigned value );
|
||||
/// Convenience method for setting text inside an 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 );
|
||||
/// Convenience method for setting text inside an element. See SetText() for important limitations.
|
||||
void SetText( double value );
|
||||
@@ -1461,13 +1536,28 @@ public:
|
||||
XMLError QueryIntText( int* ival ) const;
|
||||
/// See QueryIntText()
|
||||
XMLError QueryUnsignedText( unsigned* uval ) const;
|
||||
/// See QueryIntText()
|
||||
/// See QueryIntText()
|
||||
XMLError QueryInt64Text(int64_t* uval) const;
|
||||
/// See QueryIntText()
|
||||
XMLError QueryBoolText( bool* bval ) const;
|
||||
/// See QueryIntText()
|
||||
XMLError QueryDoubleText( double* dval ) const;
|
||||
/// See QueryIntText()
|
||||
XMLError QueryFloatText( float* fval ) const;
|
||||
|
||||
int IntText(int defaultValue = 0) const;
|
||||
|
||||
/// See QueryIntText()
|
||||
unsigned UnsignedText(unsigned defaultValue = 0) const;
|
||||
/// See QueryIntText()
|
||||
int64_t Int64Text(int64_t defaultValue = 0) const;
|
||||
/// See QueryIntText()
|
||||
bool BoolText(bool defaultValue = false) const;
|
||||
/// See QueryIntText()
|
||||
double DoubleText(double defaultValue = 0) const;
|
||||
/// See QueryIntText()
|
||||
float FloatText(float defaultValue = 0) const;
|
||||
|
||||
// internal:
|
||||
enum {
|
||||
OPEN, // <foo>
|
||||
@@ -1481,7 +1571,7 @@ public:
|
||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
||||
|
||||
protected:
|
||||
char* ParseDeep( char* p, StrPair* endTag );
|
||||
char* ParseDeep( char* p, StrPair* endTag, int* curLineNumPtr );
|
||||
|
||||
private:
|
||||
XMLElement( XMLDocument* doc );
|
||||
@@ -1494,8 +1584,9 @@ private:
|
||||
}
|
||||
XMLAttribute* FindOrCreateAttribute( const char* name );
|
||||
//void LinkAttribute( XMLAttribute* attrib );
|
||||
char* ParseAttributes( char* p );
|
||||
char* ParseAttributes( char* p, int* curLineNumPtr );
|
||||
static void DeleteAttribute( XMLAttribute* attribute );
|
||||
XMLAttribute* CreateAttribute();
|
||||
|
||||
enum { BUF_SIZE = 200 };
|
||||
int _closingType;
|
||||
@@ -1522,7 +1613,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode
|
||||
friend class XMLElement;
|
||||
public:
|
||||
/// constructor
|
||||
XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE );
|
||||
XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
|
||||
~XMLDocument();
|
||||
|
||||
virtual XMLDocument* ToDocument() {
|
||||
@@ -1536,7 +1627,7 @@ public:
|
||||
|
||||
/**
|
||||
Parse an XML file from a character string.
|
||||
Returns XML_NO_ERROR (0) on success, or
|
||||
Returns XML_SUCCESS (0) on success, or
|
||||
an errorID.
|
||||
|
||||
You may optionally pass in the 'nBytes', which is
|
||||
@@ -1548,7 +1639,7 @@ public:
|
||||
|
||||
/**
|
||||
Load an XML file from disk.
|
||||
Returns XML_NO_ERROR (0) on success, or
|
||||
Returns XML_SUCCESS (0) on success, or
|
||||
an errorID.
|
||||
*/
|
||||
XMLError LoadFile( const char* filename );
|
||||
@@ -1561,14 +1652,14 @@ public:
|
||||
not text in order for TinyXML-2 to correctly
|
||||
do newline normalization.
|
||||
|
||||
Returns XML_NO_ERROR (0) on success, or
|
||||
Returns XML_SUCCESS (0) on success, or
|
||||
an errorID.
|
||||
*/
|
||||
XMLError LoadFile( FILE* );
|
||||
|
||||
/**
|
||||
Save the XML file to disk.
|
||||
Returns XML_NO_ERROR (0) on success, or
|
||||
Returns XML_SUCCESS (0) on success, or
|
||||
an errorID.
|
||||
*/
|
||||
XMLError SaveFile( const char* filename, bool compact = false );
|
||||
@@ -1577,7 +1668,7 @@ public:
|
||||
Save the XML file to disk. You are responsible
|
||||
for providing and closing the FILE*.
|
||||
|
||||
Returns XML_NO_ERROR (0) on success, or
|
||||
Returns XML_SUCCESS (0) on success, or
|
||||
an errorID.
|
||||
*/
|
||||
XMLError SaveFile( FILE* fp, bool compact = false );
|
||||
@@ -1586,7 +1677,7 @@ public:
|
||||
return _processEntities;
|
||||
}
|
||||
Whitespace WhitespaceMode() const {
|
||||
return _whitespace;
|
||||
return _whitespaceMode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1671,25 +1762,35 @@ public:
|
||||
*/
|
||||
void DeleteNode( XMLNode* node );
|
||||
|
||||
void SetError( XMLError error, const char* str1, const char* str2 );
|
||||
void SetError( XMLError error, const char* str1, const char* str2, int lineNum );
|
||||
|
||||
void ClearError() {
|
||||
SetError(XML_SUCCESS, 0, 0, 0);
|
||||
}
|
||||
|
||||
/// Return true if there was an error parsing the document.
|
||||
bool Error() const {
|
||||
return _errorID != XML_NO_ERROR;
|
||||
return _errorID != XML_SUCCESS;
|
||||
}
|
||||
/// Return the errorID.
|
||||
XMLError ErrorID() const {
|
||||
return _errorID;
|
||||
}
|
||||
const char* ErrorName() const;
|
||||
static const char* ErrorIDToName(XMLError errorID);
|
||||
|
||||
/// Return a possibly helpful diagnostic location or string.
|
||||
const char* GetErrorStr1() const {
|
||||
return _errorStr1;
|
||||
return _errorStr1.GetStr();
|
||||
}
|
||||
/// Return a possibly helpful secondary diagnostic location or string.
|
||||
const char* GetErrorStr2() const {
|
||||
return _errorStr2;
|
||||
return _errorStr2.GetStr();
|
||||
}
|
||||
/// Return the line where the error occured, or zero if unknown.
|
||||
int GetErrorLineNum() const
|
||||
{
|
||||
return _errorLineNum;
|
||||
}
|
||||
/// If there is an error, print it to stdout.
|
||||
void PrintError() const;
|
||||
@@ -1711,13 +1812,15 @@ private:
|
||||
XMLDocument( const XMLDocument& ); // not supported
|
||||
void operator=( const XMLDocument& ); // not supported
|
||||
|
||||
bool _writeBOM;
|
||||
bool _processEntities;
|
||||
XMLError _errorID;
|
||||
Whitespace _whitespace;
|
||||
const char* _errorStr1;
|
||||
const char* _errorStr2;
|
||||
char* _charBuffer;
|
||||
bool _writeBOM;
|
||||
bool _processEntities;
|
||||
XMLError _errorID;
|
||||
Whitespace _whitespaceMode;
|
||||
mutable StrPair _errorStr1;
|
||||
mutable StrPair _errorStr2;
|
||||
int _errorLineNum;
|
||||
char* _charBuffer;
|
||||
int _parseCurLineNum;
|
||||
|
||||
MemPoolT< sizeof(XMLElement) > _elementPool;
|
||||
MemPoolT< sizeof(XMLAttribute) > _attributePool;
|
||||
@@ -1727,8 +1830,21 @@ private:
|
||||
static const char* _errorNames[XML_ERROR_COUNT];
|
||||
|
||||
void Parse();
|
||||
|
||||
template<class NodeType, int PoolElementSize>
|
||||
NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
|
||||
};
|
||||
|
||||
template<class NodeType, int PoolElementSize>
|
||||
inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool )
|
||||
{
|
||||
TIXMLASSERT( sizeof( NodeType ) == PoolElementSize );
|
||||
TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() );
|
||||
NodeType* returnNode = new (pool.Alloc()) NodeType( this );
|
||||
TIXMLASSERT( returnNode );
|
||||
returnNode->_memPool = &pool;
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
/**
|
||||
A XMLHandle is a class that wraps a node pointer with null checks; this is
|
||||
@@ -1845,19 +1961,19 @@ public:
|
||||
}
|
||||
/// Safe cast to XMLElement. This can return null.
|
||||
XMLElement* ToElement() {
|
||||
return ( ( _node == 0 ) ? 0 : _node->ToElement() );
|
||||
return ( _node ? _node->ToElement() : 0 );
|
||||
}
|
||||
/// Safe cast to XMLText. This can return null.
|
||||
XMLText* ToText() {
|
||||
return ( ( _node == 0 ) ? 0 : _node->ToText() );
|
||||
return ( _node ? _node->ToText() : 0 );
|
||||
}
|
||||
/// Safe cast to XMLUnknown. This can return null.
|
||||
XMLUnknown* ToUnknown() {
|
||||
return ( ( _node == 0 ) ? 0 : _node->ToUnknown() );
|
||||
return ( _node ? _node->ToUnknown() : 0 );
|
||||
}
|
||||
/// Safe cast to XMLDeclaration. This can return null.
|
||||
XMLDeclaration* ToDeclaration() {
|
||||
return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() );
|
||||
return ( _node ? _node->ToDeclaration() : 0 );
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -1917,16 +2033,16 @@ public:
|
||||
return _node;
|
||||
}
|
||||
const XMLElement* ToElement() const {
|
||||
return ( ( _node == 0 ) ? 0 : _node->ToElement() );
|
||||
return ( _node ? _node->ToElement() : 0 );
|
||||
}
|
||||
const XMLText* ToText() const {
|
||||
return ( ( _node == 0 ) ? 0 : _node->ToText() );
|
||||
return ( _node ? _node->ToText() : 0 );
|
||||
}
|
||||
const XMLUnknown* ToUnknown() const {
|
||||
return ( ( _node == 0 ) ? 0 : _node->ToUnknown() );
|
||||
return ( _node ? _node->ToUnknown() : 0 );
|
||||
}
|
||||
const XMLDeclaration* ToDeclaration() const {
|
||||
return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() );
|
||||
return ( _node ? _node->ToDeclaration() : 0 );
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -1998,7 +2114,8 @@ public:
|
||||
void PushAttribute( const char* name, const char* value );
|
||||
void PushAttribute( const char* name, int value );
|
||||
void PushAttribute( const char* name, unsigned value );
|
||||
void PushAttribute( const char* name, bool value );
|
||||
void PushAttribute(const char* name, int64_t value);
|
||||
void PushAttribute( const char* name, bool value );
|
||||
void PushAttribute( const char* name, double value );
|
||||
/// If streaming, close the Element.
|
||||
virtual void CloseElement( bool compactMode=false );
|
||||
@@ -2009,7 +2126,9 @@ public:
|
||||
void PushText( int value );
|
||||
/// Add a text node from an unsigned.
|
||||
void PushText( unsigned value );
|
||||
/// Add a text node from a bool.
|
||||
/// Add a text node from an unsigned.
|
||||
void PushText(int64_t value);
|
||||
/// Add a text node from a bool.
|
||||
void PushText( bool value );
|
||||
/// Add a text node from a float.
|
||||
void PushText( float value );
|
||||
|
||||
Reference in New Issue
Block a user