use Explicit Specialization of Function Templates to make serializing could extend with custom type

This commit is contained in:
halx99 2019-11-28 01:59:08 +08:00
parent 51d177e938
commit 60d8a663ab
2 changed files with 69 additions and 207 deletions

View File

@ -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*>(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>(int rhs)
{
if (!_attr) return false;
return impl::set_value_integer<unsigned int>(_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>(unsigned int rhs)
{
if (!_attr) return false;
return impl::set_value_integer<unsigned int>(_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>(long rhs)
{
if (!_attr) return false;
return impl::set_value_integer<unsigned long>(_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>(unsigned long rhs)
{
if (!_attr) return false;
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)
template<> PUGI__FN bool xml_attribute::set_value<double>(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>(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>(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>(long long rhs)
{
if (!_attr) return false;
return impl::set_value_integer<unsigned long long>(_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>(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*>(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>(int rhs)
{
xml_node_struct* dn = _data_new();
return dn ? impl::set_value_integer<unsigned int>(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>(unsigned int rhs)
{
xml_node_struct* dn = _data_new();
return dn ? impl::set_value_integer<unsigned int>(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>(long rhs)
{
xml_node_struct* dn = _data_new();
return dn ? impl::set_value_integer<unsigned long>(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>(unsigned long rhs)
{
xml_node_struct* dn = _data_new();
return dn ? impl::set_value_integer<unsigned long>(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>(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>(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>(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>(long long rhs)
{
xml_node_struct* dn = _data_new();
return dn ? impl::set_value_integer<unsigned long long>(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>(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());

View File

@ -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<typename _T> 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<typename _T> 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*>(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>(int rhs);
template<> bool xml_attribute::set_value<unsigned int>(unsigned int rhs);
template<> bool xml_attribute::set_value<long>(long rhs);
template<> bool xml_attribute::set_value<unsigned long>(unsigned long rhs);
template<> bool xml_attribute::set_value<double>(double rhs);
template<> bool xml_attribute::set_value<float>(float rhs);
template<> bool xml_attribute::set_value<bool>(bool rhs);
#ifdef PUGIXML_HAS_LONG_LONG
template<> bool xml_attribute::set_value<long long>(long long rhs);
template<> bool xml_attribute::set_value<unsigned long long>(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<typename _T> 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<typename _T>
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*>(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>(int rhs);
template<> bool xml_text::set<unsigned int>(unsigned int rhs);
template<> bool xml_text::set<long>(long rhs);
template<> bool xml_text::set<unsigned long>(unsigned long rhs);
template<> bool xml_text::set<double>(double rhs);
template<> bool xml_text::set<float>(float rhs);
template<> bool xml_text::set<bool>(bool rhs);
#ifdef PUGIXML_HAS_LONG_LONG
template<> bool xml_text::set<long long>(long long rhs);
template<> bool xml_text::set<unsigned long long>(unsigned long long rhs);
#endif
#ifdef __BORLANDC__
// Borland C++ workaround