mirror of https://github.com/AxioDL/tinyxml2.git
Support for 'long long' number values.
This commit is contained in:
parent
4cd1f269c2
commit
664d05662e
48
tinyxml2.cpp
48
tinyxml2.cpp
|
@ -411,6 +411,12 @@ void XMLUtil::ToStr( int v, char* buffer, int bufferSize )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void XMLUtil::ToStr( long long v, char* buffer, int bufferSize )
|
||||||
|
{
|
||||||
|
TIXML_SNPRINTF( buffer, bufferSize, "%lld", v );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize )
|
void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize )
|
||||||
{
|
{
|
||||||
TIXML_SNPRINTF( buffer, bufferSize, "%u", v );
|
TIXML_SNPRINTF( buffer, bufferSize, "%u", v );
|
||||||
|
@ -446,6 +452,14 @@ bool XMLUtil::ToInt( const char* str, int* value )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool XMLUtil::ToLongLong( const char* str, long long* value )
|
||||||
|
{
|
||||||
|
if ( TIXML_SSCANF( str, "%lld", value ) == 1 ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool XMLUtil::ToUnsigned( const char* str, unsigned *value )
|
bool XMLUtil::ToUnsigned( const char* str, unsigned *value )
|
||||||
{
|
{
|
||||||
if ( TIXML_SSCANF( str, "%u", value ) == 1 ) {
|
if ( TIXML_SSCANF( str, "%u", value ) == 1 ) {
|
||||||
|
@ -1166,6 +1180,14 @@ void XMLAttribute::SetAttribute( int v )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void XMLAttribute::SetAttribute( long long v )
|
||||||
|
{
|
||||||
|
char buf[BUF_SIZE];
|
||||||
|
XMLUtil::ToStr( v, buf, BUF_SIZE );
|
||||||
|
_value.SetStr( buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void XMLAttribute::SetAttribute( unsigned v )
|
void XMLAttribute::SetAttribute( unsigned v )
|
||||||
{
|
{
|
||||||
char buf[BUF_SIZE];
|
char buf[BUF_SIZE];
|
||||||
|
@ -1322,6 +1344,19 @@ void XMLElement::SetText( float inNum )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XMLElement::SetText( long long inNum )
|
||||||
|
{
|
||||||
|
char buf[BUF_SIZE];
|
||||||
|
XMLUtil::ToStr( inNum, buf, BUF_SIZE );
|
||||||
|
if ( FirstChild() && FirstChild()->ToText() )
|
||||||
|
FirstChild()->SetValue( buf );
|
||||||
|
else {
|
||||||
|
XMLText* theText = GetDocument()->NewText( buf );
|
||||||
|
InsertFirstChild( theText );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void XMLElement::SetBoolFirstChild( bool inBool )
|
void XMLElement::SetBoolFirstChild( bool inBool )
|
||||||
{
|
{
|
||||||
|
@ -1371,6 +1406,19 @@ XMLError XMLElement::QueryIntText( int* ival ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
XMLError XMLElement::QueryLongLongText( long long* ival ) const
|
||||||
|
{
|
||||||
|
if ( FirstChild() && FirstChild()->ToText() ) {
|
||||||
|
const char* t = FirstChild()->ToText()->Value();
|
||||||
|
if ( XMLUtil::ToLongLong( t, ival ) ) {
|
||||||
|
return XML_SUCCESS;
|
||||||
|
}
|
||||||
|
return XML_CAN_NOT_CONVERT_TEXT;
|
||||||
|
}
|
||||||
|
return XML_NO_TEXT_NODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const
|
XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const
|
||||||
{
|
{
|
||||||
if ( FirstChild() && FirstChild()->ToText() ) {
|
if ( FirstChild() && FirstChild()->ToText() ) {
|
||||||
|
|
21
tinyxml2.h
21
tinyxml2.h
|
@ -540,6 +540,7 @@ public:
|
||||||
|
|
||||||
// converts primitive types to strings
|
// converts primitive types to strings
|
||||||
static void ToStr( int v, char* buffer, int bufferSize );
|
static void ToStr( int v, char* buffer, int bufferSize );
|
||||||
|
static void ToStr( long long v, char* buffer, int bufferSize );
|
||||||
static void ToStr( unsigned v, char* buffer, int bufferSize );
|
static void ToStr( unsigned v, char* buffer, int bufferSize );
|
||||||
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 );
|
||||||
|
@ -547,6 +548,7 @@ public:
|
||||||
|
|
||||||
// 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 );
|
||||||
|
static bool ToLongLong( const char* str, long long* value );
|
||||||
static bool ToUnsigned( const char* str, unsigned* value );
|
static bool ToUnsigned( const char* str, unsigned* value );
|
||||||
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 );
|
||||||
|
@ -1093,6 +1095,8 @@ public:
|
||||||
/// Set the attribute to value.
|
/// Set the attribute to value.
|
||||||
void SetAttribute( int value );
|
void SetAttribute( int value );
|
||||||
/// Set the attribute to value.
|
/// Set the attribute to value.
|
||||||
|
void SetAttribute( long long 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( bool value );
|
void SetAttribute( bool value );
|
||||||
|
@ -1308,6 +1312,11 @@ public:
|
||||||
a->SetAttribute( value );
|
a->SetAttribute( value );
|
||||||
}
|
}
|
||||||
/// Sets the named attribute to value.
|
/// Sets the named attribute to value.
|
||||||
|
void SetAttribute( const char* name, long long value ) {
|
||||||
|
XMLAttribute* a = FindOrCreateAttribute( name );
|
||||||
|
a->SetAttribute( value );
|
||||||
|
}
|
||||||
|
/// Sets the named attribute to value.
|
||||||
void SetAttribute( const char* name, unsigned value ) {
|
void SetAttribute( const char* name, unsigned value ) {
|
||||||
XMLAttribute* a = FindOrCreateAttribute( name );
|
XMLAttribute* a = FindOrCreateAttribute( name );
|
||||||
a->SetAttribute( value );
|
a->SetAttribute( value );
|
||||||
|
@ -1418,6 +1427,8 @@ public:
|
||||||
/// Sets the text to the given float.
|
/// Sets the text to the given float.
|
||||||
void SetText( float inNum );
|
void SetText( float inNum );
|
||||||
|
|
||||||
|
/// Sets the text to the given long long.
|
||||||
|
void SetText( long long inNum );
|
||||||
|
|
||||||
/// Convenience for QueryIntText when you don't care if the text won't convert.
|
/// Convenience for QueryIntText when you don't care if the text won't convert.
|
||||||
int IntText()
|
int IntText()
|
||||||
|
@ -1427,6 +1438,14 @@ public:
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convenience for QueryLongLongText when you don't care if the text won't convert.
|
||||||
|
long long LongLongText()
|
||||||
|
{
|
||||||
|
long long i = 0;
|
||||||
|
QueryLongLongText( &i );
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
/// Convenience for QueryUnsignedText when you don't care if the text won't convert.
|
/// Convenience for QueryUnsignedText when you don't care if the text won't convert.
|
||||||
unsigned UnsignedText()
|
unsigned UnsignedText()
|
||||||
{
|
{
|
||||||
|
@ -1492,6 +1511,8 @@ public:
|
||||||
*/
|
*/
|
||||||
XMLError QueryIntText( int* ival ) const;
|
XMLError QueryIntText( int* ival ) const;
|
||||||
/// See QueryIntText()
|
/// See QueryIntText()
|
||||||
|
XMLError QueryLongLongText( long long* ival ) const;
|
||||||
|
/// See QueryIntText()
|
||||||
XMLError QueryUnsignedText( unsigned* uval ) const;
|
XMLError QueryUnsignedText( unsigned* uval ) const;
|
||||||
/// See QueryIntText()
|
/// See QueryIntText()
|
||||||
XMLError QueryBoolText( bool* bval ) const;
|
XMLError QueryBoolText( bool* bval ) const;
|
||||||
|
|
Loading…
Reference in New Issue