Support for 'long long' number values.

This commit is contained in:
Uli Kusterer
2014-01-21 12:24:47 +01:00
parent 4cd1f269c2
commit 664d05662e
2 changed files with 69 additions and 0 deletions

View File

@@ -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 )
{
TIXML_SNPRINTF( buffer, bufferSize, "%u", v );
@@ -446,6 +452,14 @@ bool XMLUtil::ToInt( const char* str, int* value )
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 )
{
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 )
{
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 )
{
@@ -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
{
if ( FirstChild() && FirstChild()->ToText() ) {