fix: overload instead of default arg

This commit is contained in:
Tuan Anh Tran 2019-09-21 23:58:18 +07:00
parent b28ef74076
commit 3d3a3b9ab5
3 changed files with 25 additions and 4 deletions

View File

@ -5338,6 +5338,13 @@ namespace pugi
return impl::set_value_integer<unsigned long>(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, false);
}
PUGI__FN bool xml_attribute::set_value(double rhs)
{
if (!_attr) return false;
return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, default_double_precision);
}
PUGI__FN bool xml_attribute::set_value(double rhs, int precision)
{
if (!_attr) return false;
@ -5345,6 +5352,13 @@ namespace pugi
return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, precision);
}
PUGI__FN bool xml_attribute::set_value(float rhs)
{
if (!_attr) return false;
return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, default_float_precision);
}
PUGI__FN bool xml_attribute::set_value(float rhs, int precision)
{
if (!_attr) return false;

View File

@ -263,8 +263,8 @@ namespace pugi
// Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none.
const unsigned int format_default = format_indent;
const unsigned int default_double_precision = 17;
const unsigned int default_float_precision = 9;
const int default_double_precision = 17;
const int default_float_precision = 9;
// Forward declarations
struct xml_attribute_struct;
@ -412,8 +412,10 @@ namespace pugi
bool set_value(unsigned int rhs);
bool set_value(long rhs);
bool set_value(unsigned long rhs);
bool set_value(double rhs, int precision=default_double_precision);
bool set_value(float rhs, int precision=default_float_precision);
bool set_value(double rhs);
bool set_value(double rhs, int precision);
bool set_value(float rhs);
bool set_value(float rhs, int precision);
bool set_value(bool rhs);
#ifdef PUGIXML_HAS_LONG_LONG

View File

@ -1771,6 +1771,11 @@ TEST(dom_fp_double_custom_precision)
attr.set_value(std::numeric_limits<double>::min(), 20);
CHECK(fp_equal(attr.as_double(), std::numeric_limits<double>::min()));
attr.set_value(1.0f, 5);
CHECK(fp_equal(attr.as_double(), static_cast<double>(1.0f)));
attr.set_value(3.1415926f, 3);
CHECK(!fp_equal(attr.as_double(), static_cast<double>(3.1415926f)));
node.text().set(std::numeric_limits<double>::max());
CHECK(fp_equal(node.text().as_double(), std::numeric_limits<double>::max()));
}