Merge branch 'master' of git://github.com/cugone/tinyxml2 into cugone-master
This commit is contained in:
75
tinyxml2.cpp
75
tinyxml2.cpp
@@ -588,6 +588,11 @@ void XMLUtil::ToStr(int64_t v, char* buffer, int bufferSize)
|
|||||||
TIXML_SNPRINTF(buffer, bufferSize, "%lld", (long long)v);
|
TIXML_SNPRINTF(buffer, bufferSize, "%lld", (long long)v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize )
|
||||||
|
{
|
||||||
|
// horrible syntax trick to make the compiler happy about %llu
|
||||||
|
TIXML_SNPRINTF(buffer, bufferSize, "%llu", (long long)v);
|
||||||
|
}
|
||||||
|
|
||||||
bool XMLUtil::ToInt( const char* str, int* value )
|
bool XMLUtil::ToInt( const char* str, int* value )
|
||||||
{
|
{
|
||||||
@@ -653,6 +658,16 @@ bool XMLUtil::ToInt64(const char* str, int64_t* value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) {
|
||||||
|
unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llu
|
||||||
|
if(TIXML_SSCANF(str, "%llu", &v) == 1) {
|
||||||
|
*value = (uint64_t)v;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char* XMLDocument::Identify( char* p, XMLNode** node )
|
char* XMLDocument::Identify( char* p, XMLNode** node )
|
||||||
{
|
{
|
||||||
TIXMLASSERT( node );
|
TIXMLASSERT( node );
|
||||||
@@ -1414,6 +1429,15 @@ XMLError XMLAttribute::QueryInt64Value(int64_t* value) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
XMLError XMLAttribute::QueryUnsigned64Value(uint64_t* value) const
|
||||||
|
{
|
||||||
|
if(XMLUtil::ToUnsigned64(Value(), value)) {
|
||||||
|
return XML_SUCCESS;
|
||||||
|
}
|
||||||
|
return XML_WRONG_ATTRIBUTE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
XMLError XMLAttribute::QueryBoolValue( bool* value ) const
|
XMLError XMLAttribute::QueryBoolValue( bool* value ) const
|
||||||
{
|
{
|
||||||
if ( XMLUtil::ToBool( Value(), value )) {
|
if ( XMLUtil::ToBool( Value(), value )) {
|
||||||
@@ -1556,6 +1580,13 @@ int64_t XMLElement::Int64Attribute(const char* name, int64_t defaultValue) const
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t XMLElement::Unsigned64Attribute(const char* name, uint64_t defaultValue) const
|
||||||
|
{
|
||||||
|
uint64_t i = defaultValue;
|
||||||
|
QueryUnsigned64Attribute(name, &i);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
bool XMLElement::BoolAttribute(const char* name, bool defaultValue) const
|
bool XMLElement::BoolAttribute(const char* name, bool defaultValue) const
|
||||||
{
|
{
|
||||||
bool b = defaultValue;
|
bool b = defaultValue;
|
||||||
@@ -1620,6 +1651,12 @@ void XMLElement::SetText(int64_t v)
|
|||||||
SetText(buf);
|
SetText(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XMLElement::SetText(uint64_t v) {
|
||||||
|
char buf[BUF_SIZE];
|
||||||
|
XMLUtil::ToStr(v, buf, BUF_SIZE);
|
||||||
|
SetText(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void XMLElement::SetText( bool v )
|
void XMLElement::SetText( bool v )
|
||||||
{
|
{
|
||||||
@@ -1684,6 +1721,19 @@ XMLError XMLElement::QueryInt64Text(int64_t* ival) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
XMLError XMLElement::QueryUnsigned64Text(uint64_t* ival) const
|
||||||
|
{
|
||||||
|
if(FirstChild() && FirstChild()->ToText()) {
|
||||||
|
const char* t = FirstChild()->Value();
|
||||||
|
if(XMLUtil::ToUnsigned64(t, ival)) {
|
||||||
|
return XML_SUCCESS;
|
||||||
|
}
|
||||||
|
return XML_CAN_NOT_CONVERT_TEXT;
|
||||||
|
}
|
||||||
|
return XML_NO_TEXT_NODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
XMLError XMLElement::QueryBoolText( bool* bval ) const
|
XMLError XMLElement::QueryBoolText( bool* bval ) const
|
||||||
{
|
{
|
||||||
if ( FirstChild() && FirstChild()->ToText() ) {
|
if ( FirstChild() && FirstChild()->ToText() ) {
|
||||||
@@ -1743,6 +1793,13 @@ int64_t XMLElement::Int64Text(int64_t defaultValue) const
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t XMLElement::Unsigned64Text(uint64_t defaultValue) const
|
||||||
|
{
|
||||||
|
uint64_t i = defaultValue;
|
||||||
|
QueryUnsigned64Text(&i);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
bool XMLElement::BoolText(bool defaultValue) const
|
bool XMLElement::BoolText(bool defaultValue) const
|
||||||
{
|
{
|
||||||
bool b = defaultValue;
|
bool b = defaultValue;
|
||||||
@@ -2614,6 +2671,14 @@ void XMLPrinter::PushAttribute(const char* name, int64_t v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void XMLPrinter::PushAttribute(const char* name, uint64_t v)
|
||||||
|
{
|
||||||
|
char buf[BUF_SIZE];
|
||||||
|
XMLUtil::ToStr(v, buf, BUF_SIZE);
|
||||||
|
PushAttribute(name, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void XMLPrinter::PushAttribute( const char* name, bool v )
|
void XMLPrinter::PushAttribute( const char* name, bool v )
|
||||||
{
|
{
|
||||||
char buf[BUF_SIZE];
|
char buf[BUF_SIZE];
|
||||||
@@ -2683,6 +2748,7 @@ void XMLPrinter::PushText( const char* text, bool cdata )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void XMLPrinter::PushText( int64_t value )
|
void XMLPrinter::PushText( int64_t value )
|
||||||
{
|
{
|
||||||
char buf[BUF_SIZE];
|
char buf[BUF_SIZE];
|
||||||
@@ -2690,6 +2756,15 @@ void XMLPrinter::PushText( int64_t value )
|
|||||||
PushText( buf, false );
|
PushText( buf, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void XMLPrinter::PushText( uint64_t value )
|
||||||
|
{
|
||||||
|
char buf[BUF_SIZE];
|
||||||
|
XMLUtil::ToStr(value, buf, BUF_SIZE);
|
||||||
|
PushText(buf, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void XMLPrinter::PushText( int value )
|
void XMLPrinter::PushText( int value )
|
||||||
{
|
{
|
||||||
char buf[BUF_SIZE];
|
char buf[BUF_SIZE];
|
||||||
|
|||||||
33
tinyxml2.h
33
tinyxml2.h
@@ -617,6 +617,7 @@ public:
|
|||||||
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);
|
static void ToStr(int64_t v, char* buffer, int bufferSize);
|
||||||
|
static void ToStr(uint64_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 );
|
||||||
@@ -625,7 +626,7 @@ public:
|
|||||||
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);
|
static bool ToInt64(const char* str, int64_t* value);
|
||||||
|
static bool ToUnsigned64(const char* str, uint64_t* value);
|
||||||
// Changes what is serialized for a boolean value.
|
// Changes what is serialized for a boolean value.
|
||||||
// Default to "true" and "false". Shouldn't be changed
|
// Default to "true" and "false". Shouldn't be changed
|
||||||
// unless you have a special testing or compatibility need.
|
// unless you have a special testing or compatibility need.
|
||||||
@@ -1164,6 +1165,12 @@ public:
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t Unsigned64Value() const {
|
||||||
|
uint64_t i = 0;
|
||||||
|
QueryUnsigned64Value(&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;
|
||||||
@@ -1199,6 +1206,8 @@ public:
|
|||||||
/// See QueryIntValue
|
/// See QueryIntValue
|
||||||
XMLError QueryInt64Value(int64_t* value) const;
|
XMLError QueryInt64Value(int64_t* value) const;
|
||||||
/// See QueryIntValue
|
/// See QueryIntValue
|
||||||
|
XMLError QueryUnsigned64Value(uint64_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;
|
||||||
@@ -1302,6 +1311,8 @@ public:
|
|||||||
/// See IntAttribute()
|
/// See IntAttribute()
|
||||||
int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const;
|
int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const;
|
||||||
/// See IntAttribute()
|
/// See IntAttribute()
|
||||||
|
uint64_t Unsigned64Attribute(const char* name, uint64_t defaultValue = 0) const;
|
||||||
|
/// See IntAttribute()
|
||||||
bool BoolAttribute(const char* name, bool defaultValue = false) const;
|
bool BoolAttribute(const char* name, bool defaultValue = false) const;
|
||||||
/// See IntAttribute()
|
/// See IntAttribute()
|
||||||
double DoubleAttribute(const char* name, double defaultValue = 0) const;
|
double DoubleAttribute(const char* name, double defaultValue = 0) const;
|
||||||
@@ -1348,6 +1359,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// See QueryIntAttribute()
|
/// See QueryIntAttribute()
|
||||||
|
XMLError QueryUnsigned64Attribute(const char* name, uint64_t* value) const {
|
||||||
|
const XMLAttribute* a = FindAttribute(name);
|
||||||
|
if(!a) {
|
||||||
|
return XML_NO_ATTRIBUTE;
|
||||||
|
}
|
||||||
|
return a->QueryUnsigned64Value(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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 );
|
||||||
if ( !a ) {
|
if ( !a ) {
|
||||||
@@ -1547,6 +1567,8 @@ public:
|
|||||||
/// 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);
|
void SetText(int64_t 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(uint64_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 an 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 );
|
||||||
@@ -1585,6 +1607,8 @@ public:
|
|||||||
/// See QueryIntText()
|
/// See QueryIntText()
|
||||||
XMLError QueryInt64Text(int64_t* uval) const;
|
XMLError QueryInt64Text(int64_t* uval) const;
|
||||||
/// See QueryIntText()
|
/// See QueryIntText()
|
||||||
|
XMLError QueryUnsigned64Text(uint64_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;
|
||||||
@@ -1598,6 +1622,8 @@ public:
|
|||||||
/// See QueryIntText()
|
/// See QueryIntText()
|
||||||
int64_t Int64Text(int64_t defaultValue = 0) const;
|
int64_t Int64Text(int64_t defaultValue = 0) const;
|
||||||
/// See QueryIntText()
|
/// See QueryIntText()
|
||||||
|
uint64_t Unsigned64Text(uint64_t defaultValue = 0) const;
|
||||||
|
/// See QueryIntText()
|
||||||
bool BoolText(bool defaultValue = false) const;
|
bool BoolText(bool defaultValue = false) const;
|
||||||
/// See QueryIntText()
|
/// See QueryIntText()
|
||||||
double DoubleText(double defaultValue = 0) const;
|
double DoubleText(double defaultValue = 0) const;
|
||||||
@@ -2195,6 +2221,7 @@ public:
|
|||||||
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, int64_t value );
|
||||||
|
void PushAttribute( const char* name, uint64_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.
|
||||||
@@ -2206,8 +2233,10 @@ 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.
|
/// Add a text node from a signed 64bit integer.
|
||||||
void PushText( int64_t value );
|
void PushText( int64_t value );
|
||||||
|
/// Add a text node from an unsigned 64bit integer.
|
||||||
|
void PushText( uint64_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.
|
||||||
|
|||||||
Reference in New Issue
Block a user