To bring BoolFirstChild() more in line with the other methods, reimplemented it in terms of a new QueryBoolFirstChild().

This commit is contained in:
Uli Kusterer 2014-01-21 02:53:47 +01:00
parent 4af5573f42
commit ff8e2041dd
2 changed files with 29 additions and 8 deletions

View File

@ -1336,13 +1336,25 @@ void XMLElement::SetBoolFirstChild( bool inBool )
} }
bool XMLElement::BoolFirstChild() XMLError XMLElement::QueryBoolFirstChild( bool *outBool )
{ {
if ( FirstChild() && FirstChild()->ToElement() ) { if ( FirstChild() )
return strcmp( FirstChild()->Value(), "true" ) == 0; {
if ( FirstChild()->ToElement() )
{
bool isTrue = strcmp( FirstChild()->Value(), "true" ) == 0;
bool isFalse = strcmp( FirstChild()->Value(), "false" ) == 0;
if( !isTrue && !isFalse )
return XML_CAN_NOT_CONVERT_TEXT;
*outBool = isTrue;
return XML_SUCCESS;
}
else
return XML_NO_ELEMENT_NODE;
} }
else
return false; return XML_NO_ELEMENT_NODE;
} }

View File

@ -1014,7 +1014,8 @@ enum XMLError {
XML_ERROR_PARSING, XML_ERROR_PARSING,
XML_CAN_NOT_CONVERT_TEXT, XML_CAN_NOT_CONVERT_TEXT,
XML_NO_TEXT_NODE XML_NO_TEXT_NODE,
XML_NO_ELEMENT_NODE
}; };
@ -1419,9 +1420,17 @@ public:
/// Adds a sub-element equivalent to the given boolean. /// Adds a sub-element equivalent to the given boolean.
void SetBoolFirstChild( bool inBool ); void SetBoolFirstChild( bool inBool );
bool BoolFirstChild(); /// Looks for a <true /> or <false /> as the first child and returns the corresponding bool.
bool BoolFirstChild()
{
bool b = false;
QueryBoolFirstChild(&b);
return b;
}
XMLError QueryBoolFirstChild( bool *outBool );
/** /**
Convenience method to query the value of a child text node. This is probably best Convenience method to query the value of a child text node. This is probably best