diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 1f08b10..cd97c22 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -5234,68 +5234,6 @@ namespace pugi return _attr; } - PUGI__FN xml_attribute& xml_attribute::operator=(const char_t* rhs) - { - set_value(rhs); - return *this; - } - - PUGI__FN xml_attribute& xml_attribute::operator=(int rhs) - { - set_value(rhs); - return *this; - } - - PUGI__FN xml_attribute& xml_attribute::operator=(unsigned int rhs) - { - set_value(rhs); - 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); - return *this; - } - - PUGI__FN xml_attribute& xml_attribute::operator=(float rhs) - { - set_value(rhs); - return *this; - } - - PUGI__FN xml_attribute& xml_attribute::operator=(bool rhs) - { - set_value(rhs); - return *this; - } - -#ifdef PUGIXML_HAS_LONG_LONG - PUGI__FN xml_attribute& xml_attribute::operator=(long long rhs) - { - set_value(rhs); - return *this; - } - - PUGI__FN xml_attribute& xml_attribute::operator=(unsigned long long rhs) - { - set_value(rhs); - return *this; - } -#endif - PUGI__FN bool xml_attribute::set_name(const char_t* rhs) { if (!_attr) return false; @@ -5303,42 +5241,42 @@ namespace pugi return impl::strcpy_insitu(_attr->name, _attr->header, impl::xml_memory_page_name_allocated_mask, rhs, impl::strlength(rhs)); } - PUGI__FN bool xml_attribute::set_value(const char_t* rhs) + template<> PUGI__FN bool xml_attribute::set_value(const char_t* rhs) { if (!_attr) return false; return impl::strcpy_insitu(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs)); } - PUGI__FN bool xml_attribute::set_value(int rhs) + template<> PUGI__FN bool xml_attribute::set_value(int rhs) { if (!_attr) return false; return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0); } - PUGI__FN bool xml_attribute::set_value(unsigned int rhs) + template<> PUGI__FN bool xml_attribute::set_value(unsigned int rhs) { if (!_attr) return false; return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, false); } - PUGI__FN bool xml_attribute::set_value(long rhs) + template<> PUGI__FN bool xml_attribute::set_value(long rhs) { if (!_attr) return false; return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0); } - PUGI__FN bool xml_attribute::set_value(unsigned long rhs) + template<> PUGI__FN bool xml_attribute::set_value(unsigned long rhs) { if (!_attr) return false; return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, false); } - PUGI__FN bool xml_attribute::set_value(double rhs) + template<> PUGI__FN bool xml_attribute::set_value(double rhs) { if (!_attr) return false; @@ -5352,7 +5290,8 @@ 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) + + template<> PUGI__FN bool xml_attribute::set_value(float rhs) { if (!_attr) return false; @@ -5366,7 +5305,7 @@ 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(bool rhs) + template<> PUGI__FN bool xml_attribute::set_value(bool rhs) { if (!_attr) return false; @@ -5374,14 +5313,14 @@ namespace pugi } #ifdef PUGIXML_HAS_LONG_LONG - PUGI__FN bool xml_attribute::set_value(long long rhs) + template<> PUGI__FN bool xml_attribute::set_value(long long rhs) { if (!_attr) return false; return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0); } - - PUGI__FN bool xml_attribute::set_value(unsigned long long rhs) + + template<> PUGI__FN bool xml_attribute::set_value(unsigned long long rhs) { if (!_attr) return false; @@ -6519,71 +6458,71 @@ namespace pugi return (d && d->value) ? impl::get_value_ullong(d->value) : def; } #endif - - PUGI__FN bool xml_text::set(const char_t* rhs) + + template<> PUGI__FN bool xml_text::set(const char_t* rhs) { xml_node_struct* dn = _data_new(); return dn ? impl::strcpy_insitu(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs)) : false; } - - PUGI__FN bool xml_text::set(int rhs) + + template<> PUGI__FN bool xml_text::set(int rhs) { xml_node_struct* dn = _data_new(); return dn ? impl::set_value_integer(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) : false; } - PUGI__FN bool xml_text::set(unsigned int rhs) + template<> PUGI__FN bool xml_text::set(unsigned int rhs) { xml_node_struct* dn = _data_new(); return dn ? impl::set_value_integer(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, false) : false; } - PUGI__FN bool xml_text::set(long rhs) + template<> PUGI__FN bool xml_text::set(long rhs) { xml_node_struct* dn = _data_new(); return dn ? impl::set_value_integer(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) : false; } - PUGI__FN bool xml_text::set(unsigned long rhs) + template<> PUGI__FN bool xml_text::set(unsigned long rhs) { xml_node_struct* dn = _data_new(); return dn ? impl::set_value_integer(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, false) : false; } - PUGI__FN bool xml_text::set(float rhs) + template<> PUGI__FN bool xml_text::set(float 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, default_float_precision) : false; } - PUGI__FN bool xml_text::set(float rhs, int precision) + PUGI__FN bool xml_text::set(float rhs, int precision) { xml_node_struct* dn = _data_new(); return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, precision) : false; } - PUGI__FN bool xml_text::set(double rhs) + template<> PUGI__FN bool xml_text::set(double 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, default_double_precision) : false; } - PUGI__FN bool xml_text::set(double rhs, int precision) + PUGI__FN bool xml_text::set(double rhs, int precision) { xml_node_struct* dn = _data_new(); return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, precision) : false; } - PUGI__FN bool xml_text::set(bool rhs) + template<> PUGI__FN bool xml_text::set(bool rhs) { xml_node_struct* dn = _data_new(); @@ -6591,14 +6530,14 @@ namespace pugi } #ifdef PUGIXML_HAS_LONG_LONG - PUGI__FN bool xml_text::set(long long rhs) + template<> PUGI__FN bool xml_text::set(long long rhs) { xml_node_struct* dn = _data_new(); return dn ? impl::set_value_integer(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) : false; } - PUGI__FN bool xml_text::set(unsigned long long rhs) + template<> PUGI__FN bool xml_text::set(unsigned long long rhs) { xml_node_struct* dn = _data_new(); @@ -6606,68 +6545,6 @@ namespace pugi } #endif - PUGI__FN xml_text& xml_text::operator=(const char_t* rhs) - { - set(rhs); - return *this; - } - - PUGI__FN xml_text& xml_text::operator=(int rhs) - { - set(rhs); - return *this; - } - - PUGI__FN xml_text& xml_text::operator=(unsigned int rhs) - { - set(rhs); - 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); - return *this; - } - - PUGI__FN xml_text& xml_text::operator=(float rhs) - { - set(rhs); - return *this; - } - - PUGI__FN xml_text& xml_text::operator=(bool rhs) - { - set(rhs); - return *this; - } - -#ifdef PUGIXML_HAS_LONG_LONG - PUGI__FN xml_text& xml_text::operator=(long long rhs) - { - set(rhs); - return *this; - } - - PUGI__FN xml_text& xml_text::operator=(unsigned long long rhs) - { - set(rhs); - return *this; - } -#endif - PUGI__FN xml_node xml_text::data() const { return xml_node(_data()); diff --git a/src/pugixml.hpp b/src/pugixml.hpp index f658109..999f3be 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -405,38 +405,14 @@ namespace pugi // Set attribute name/value (returns false if attribute is empty or there is not enough memory) bool set_name(const char_t* rhs); - bool set_value(const char_t* rhs); + + template bool set_value(_T rhs); - // Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") - bool set_value(int rhs); - bool set_value(unsigned int rhs); - bool set_value(long rhs); - bool set_value(unsigned long rhs); - 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 - bool set_value(long long rhs); - bool set_value(unsigned long long rhs); - #endif + bool set_value(float rhs, int precision); + bool set_value(double rhs, int precision); // Set attribute value (equivalent to set_value without error checking) - xml_attribute& operator=(const char_t* rhs); - xml_attribute& operator=(int rhs); - xml_attribute& operator=(unsigned int rhs); - xml_attribute& operator=(long rhs); - xml_attribute& operator=(unsigned long rhs); - xml_attribute& operator=(double rhs); - xml_attribute& operator=(float rhs); - xml_attribute& operator=(bool rhs); - - #ifdef PUGIXML_HAS_LONG_LONG - xml_attribute& operator=(long long rhs); - xml_attribute& operator=(unsigned long long rhs); - #endif + template xml_attribute& operator=(_T rhs) { set_value<_T>(rhs); return *this; } // Get next/previous attribute in the attribute list of the parent node xml_attribute next_attribute() const; @@ -455,6 +431,22 @@ namespace pugi bool PUGIXML_FUNCTION operator||(const xml_attribute& lhs, bool rhs); #endif + template<> bool xml_attribute::set_value(const char_t* rhs); + + // Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") + template<> bool xml_attribute::set_value(int rhs); + template<> bool xml_attribute::set_value(unsigned int rhs); + template<> bool xml_attribute::set_value(long rhs); + template<> bool xml_attribute::set_value(unsigned long rhs); + template<> bool xml_attribute::set_value(double rhs); + template<> bool xml_attribute::set_value(float rhs); + template<> bool xml_attribute::set_value(bool rhs); + +#ifdef PUGIXML_HAS_LONG_LONG + template<> bool xml_attribute::set_value(long long rhs); + template<> bool xml_attribute::set_value(unsigned long long rhs); +#endif + // A light-weight handle for manipulating nodes in DOM tree class PUGIXML_CLASS xml_node { @@ -764,42 +756,35 @@ namespace pugi bool as_bool(bool def = false) const; // Set text (returns false if object is empty or there is not enough memory) - bool set(const char_t* rhs); + template bool set(_T rhs); - // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") - bool set(int rhs); - bool set(unsigned int rhs); - bool set(long rhs); - bool set(unsigned long rhs); - bool set(double rhs); - bool set(double rhs, int precision); - bool set(float rhs); - bool set(float rhs, int precision); - bool set(bool rhs); - - #ifdef PUGIXML_HAS_LONG_LONG - bool set(long long rhs); - bool set(unsigned long long rhs); - #endif + bool set(float rhs, int precision); + bool set(double rhs, int precision); // Set text (equivalent to set without error checking) - xml_text& operator=(const char_t* rhs); - xml_text& operator=(int rhs); - xml_text& operator=(unsigned int rhs); - xml_text& operator=(long rhs); - xml_text& operator=(unsigned long rhs); - xml_text& operator=(double rhs); - xml_text& operator=(float rhs); - xml_text& operator=(bool rhs); - - #ifdef PUGIXML_HAS_LONG_LONG - xml_text& operator=(long long rhs); - xml_text& operator=(unsigned long long rhs); - #endif + template + xml_text& operator=(_T rhs) { set(rhs); return *this; } // Get the data node (node_pcdata or node_cdata) for this object xml_node data() const; }; + + // Set text (returns false if object is empty or there is not enough memory) + template<> bool xml_text::set(const char_t* rhs); + + // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") + template<> bool xml_text::set(int rhs); + template<> bool xml_text::set(unsigned int rhs); + template<> bool xml_text::set(long rhs); + template<> bool xml_text::set(unsigned long rhs); + template<> bool xml_text::set(double rhs); + template<> bool xml_text::set(float rhs); + template<> bool xml_text::set(bool rhs); + +#ifdef PUGIXML_HAS_LONG_LONG + template<> bool xml_text::set(long long rhs); + template<> bool xml_text::set(unsigned long long rhs); +#endif #ifdef __BORLANDC__ // Borland C++ workaround