mirror of https://github.com/AxioDL/tinyxml2.git
Add typed convenience setters for SetText().
This commit is contained in:
parent
869bb599c1
commit
dcefa0e43f
66
tinyxml2.cpp
66
tinyxml2.cpp
|
@ -1270,6 +1270,72 @@ void XMLElement::SetText( const char* inText )
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void XMLElement::SetText( int 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::SetText( unsigned 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::SetText( bool inBool )
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
XMLUtil::ToStr( inBool, buf, BUF_SIZE );
|
||||
if ( FirstChild() && FirstChild()->ToText() )
|
||||
FirstChild()->SetValue( buf );
|
||||
else {
|
||||
XMLText* theText = GetDocument()->NewText( buf );
|
||||
InsertFirstChild( theText );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XMLElement::SetText( double 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::SetText( float 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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XMLError XMLElement::QueryIntText( int* ival ) const
|
||||
{
|
||||
if ( FirstChild() && FirstChild()->ToText() ) {
|
||||
|
|
18
tinyxml2.h
18
tinyxml2.h
|
@ -1405,6 +1405,22 @@ public:
|
|||
*/
|
||||
void SetText( const char* inText );
|
||||
|
||||
/// Sets the text to the given number.
|
||||
void SetText( int inNum );
|
||||
|
||||
/// Sets the text to the given number.
|
||||
void SetText( unsigned inNum );
|
||||
|
||||
/// Sets the text to the given boolean.
|
||||
void SetText( bool inBool );
|
||||
|
||||
/// Sets the text to the given double.
|
||||
void SetText( double inNum );
|
||||
|
||||
/// Sets the text to the given float.
|
||||
void SetText( float inNum );
|
||||
|
||||
|
||||
/**
|
||||
Convenience method to query the value of a child text node. This is probably best
|
||||
shown by example. Given you have a document is this form:
|
||||
|
@ -1455,6 +1471,8 @@ public:
|
|||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
||||
|
||||
private:
|
||||
enum { BUF_SIZE = 200 };
|
||||
|
||||
XMLElement( XMLDocument* doc );
|
||||
virtual ~XMLElement();
|
||||
XMLElement( const XMLElement& ); // not supported
|
||||
|
|
Loading…
Reference in New Issue