Unsigned integer support for attributes (as_uint, operator=)
git-svn-id: http://pugixml.googlecode.com/svn/trunk@101 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
81ef99a27b
commit
5a2fa3fe50
@ -1676,6 +1676,13 @@ namespace pugi
|
|||||||
return atoi(_attr->value);
|
return atoi(_attr->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int xml_attribute::as_uint() const
|
||||||
|
{
|
||||||
|
if(empty() || !_attr->value) return 0;
|
||||||
|
int result = atoi(_attr->value);
|
||||||
|
return result < 0 ? 0 : static_cast<unsigned int>(result);
|
||||||
|
}
|
||||||
|
|
||||||
double xml_attribute::as_double() const
|
double xml_attribute::as_double() const
|
||||||
{
|
{
|
||||||
if(empty() || !_attr->value) return 0.0;
|
if(empty() || !_attr->value) return 0.0;
|
||||||
@ -1740,6 +1747,14 @@ namespace pugi
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xml_attribute& xml_attribute::operator=(unsigned int rhs)
|
||||||
|
{
|
||||||
|
char buf[128];
|
||||||
|
sprintf(buf, "%u", rhs);
|
||||||
|
set_value(buf);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
xml_attribute& xml_attribute::operator=(double rhs)
|
xml_attribute& xml_attribute::operator=(double rhs)
|
||||||
{
|
{
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|||||||
@ -458,6 +458,14 @@ namespace pugi
|
|||||||
*/
|
*/
|
||||||
int as_int() const;
|
int as_int() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast attribute value as unsigned int.
|
||||||
|
*
|
||||||
|
* \return attribute value as unsigned int, or 0 if conversion did not succeed or attribute is empty
|
||||||
|
* \note values out of non-negative int range (usually [0, 2^31-1]) get clamped to range boundaries
|
||||||
|
*/
|
||||||
|
unsigned int as_uint() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cast attribute value as double.
|
* Cast attribute value as double.
|
||||||
*
|
*
|
||||||
@ -505,6 +513,14 @@ namespace pugi
|
|||||||
*
|
*
|
||||||
* \param rhs - new attribute value
|
* \param rhs - new attribute value
|
||||||
* \return self
|
* \return self
|
||||||
|
*/
|
||||||
|
xml_attribute& operator=(unsigned int rhs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set attribute value to \a rhs.
|
||||||
|
*
|
||||||
|
* \param rhs - new attribute value
|
||||||
|
* \return self
|
||||||
*/
|
*/
|
||||||
xml_attribute& operator=(double rhs);
|
xml_attribute& operator=(double rhs);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user