diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2016-02-02 08:39:45 -0800 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2016-02-02 08:39:45 -0800 |
commit | f441c63ea491f30fbbaa3e557badc5752ebca7d3 (patch) | |
tree | 617aca32f5e499e68cfd84f3e77b6864bdb3b12d /src/pugixml.cpp | |
parent | c712dd84ba3aa81db172debfb2ad76c1fffadb75 (diff) |
Implement set/set_value/operator= for long types
This makes the coverage for basic numeric types complete (sans long double).
Fixes #78.
Diffstat (limited to 'src/pugixml.cpp')
-rw-r--r-- | src/pugixml.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp index ad6fbc2..8535879 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4551,6 +4551,26 @@ PUGI__NS_BEGIN } template <typename String, typename Header> + PUGI__FN bool set_value_convert(String& dest, Header& header, uintptr_t header_mask, long value) + { + char_t buf[64]; + char_t* end = buf + sizeof(buf) / sizeof(buf[0]); + char_t* begin = integer_to_string<unsigned long>(buf, end, value, value < 0); + + return strcpy_insitu(dest, header, header_mask, begin, end - begin); + } + + template <typename String, typename Header> + PUGI__FN bool set_value_convert(String& dest, Header& header, uintptr_t header_mask, unsigned long value) + { + char_t buf[64]; + char_t* end = buf + sizeof(buf) / sizeof(buf[0]); + char_t* begin = integer_to_string<unsigned long>(buf, end, value, false); + + return strcpy_insitu(dest, header, header_mask, begin, end - begin); + } + + template <typename String, typename Header> PUGI__FN bool set_value_convert(String& dest, Header& header, uintptr_t header_mask, float value) { char buf[128]; @@ -5154,6 +5174,18 @@ namespace pugi return *this; } + PUGI__FN xml_attribute& xml_attribute::operator=(long rhs) + { + set_value(rhs); + return *this; + } + + PUGI__FN xml_attribute& xml_attribute::operator=(unsigned long rhs) + { + set_value(rhs); + return *this; + } + PUGI__FN xml_attribute& xml_attribute::operator=(double rhs) { set_value(rhs); @@ -5214,6 +5246,20 @@ namespace pugi return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs); } + PUGI__FN bool xml_attribute::set_value(long rhs) + { + if (!_attr) return false; + + return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs); + } + + PUGI__FN bool xml_attribute::set_value(unsigned long rhs) + { + if (!_attr) return false; + + return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs); + } + PUGI__FN bool xml_attribute::set_value(double rhs) { if (!_attr) return false; @@ -6355,6 +6401,20 @@ namespace pugi return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs) : false; } + PUGI__FN bool xml_text::set(long rhs) + { + xml_node_struct* dn = _data_new(); + + return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs) : false; + } + + PUGI__FN bool xml_text::set(unsigned long rhs) + { + xml_node_struct* dn = _data_new(); + + return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs) : false; + } + PUGI__FN bool xml_text::set(float rhs) { xml_node_struct* dn = _data_new(); @@ -6410,6 +6470,18 @@ namespace pugi return *this; } + PUGI__FN xml_text& xml_text::operator=(long rhs) + { + set(rhs); + return *this; + } + + PUGI__FN xml_text& xml_text::operator=(unsigned long rhs) + { + set(rhs); + return *this; + } + PUGI__FN xml_text& xml_text::operator=(double rhs) { set(rhs); |