Merge 883af0827c into 38edf255ae
This commit is contained in:
commit
a2a0ea7662
@ -5172,6 +5172,13 @@ namespace pugi
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUGIXML_NO_STL
|
||||
PUGI__FN istringstream_t xml_attribute::as_stringstream() const
|
||||
{
|
||||
return (_attr && _attr->value) ? istringstream_t(string_t(static_cast<char_t*>(_attr->value))) : istringstream_t();
|
||||
}
|
||||
#endif
|
||||
|
||||
PUGI__FN bool xml_attribute::empty() const
|
||||
{
|
||||
return !_attr;
|
||||
@ -6422,6 +6429,15 @@ namespace pugi
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUGIXML_NO_STL
|
||||
PUGI__FN istringstream_t xml_text::as_stringstream() const
|
||||
{
|
||||
xml_node_struct* d = _data();
|
||||
|
||||
return (d && d->value) ? istringstream_t(string_t(static_cast<char_t*>(d->value))) : istringstream_t();
|
||||
}
|
||||
#endif
|
||||
|
||||
PUGI__FN bool xml_text::set(const char_t* rhs)
|
||||
{
|
||||
xml_node_struct* dn = _data_new();
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
|
||||
// Include STL headers
|
||||
#ifndef PUGIXML_NO_STL
|
||||
# include <sstream>
|
||||
# include <iterator>
|
||||
# include <iosfwd>
|
||||
# include <string>
|
||||
@ -107,6 +108,7 @@ namespace pugi
|
||||
#ifndef PUGIXML_NO_STL
|
||||
// String type used for operations that work with STL string; depends on PUGIXML_WCHAR_MODE
|
||||
typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > string_t;
|
||||
typedef std::basic_istringstream<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > istringstream_t;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -373,6 +375,21 @@ namespace pugi
|
||||
// Get attribute value as bool (returns true if first character is in '1tTyY' set), or the default value if attribute is empty
|
||||
bool as_bool(bool def = false) const;
|
||||
|
||||
#ifndef PUGIXML_NO_STL
|
||||
// Get attribute value as std::istringstream, an empty std::istringstream if the attribute is empty
|
||||
istringstream_t as_stringstream() const;
|
||||
|
||||
// Get attribute value as Type (template parameter: try to read a Type value from the attribute value string)
|
||||
template <typename Type>
|
||||
Type as() const
|
||||
{
|
||||
istringstream_t stream(as_stringstream());
|
||||
Type value;
|
||||
stream >> value;
|
||||
return value;
|
||||
}
|
||||
#endif
|
||||
|
||||
// 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);
|
||||
@ -391,6 +408,16 @@ namespace pugi
|
||||
bool set_value(unsigned long long rhs);
|
||||
#endif
|
||||
|
||||
#ifndef PUGIXML_NO_STL
|
||||
template <typename Type>
|
||||
bool set_value(const Type& rhs) const
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << rhs;
|
||||
return set_value(stream.str().c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
// Set attribute value (equivalent to set_value without error checking)
|
||||
xml_attribute& operator=(const char_t* rhs);
|
||||
xml_attribute& operator=(int rhs);
|
||||
@ -725,6 +752,21 @@ namespace pugi
|
||||
// Get text as bool (returns true if first character is in '1tTyY' set), or the default value if object is empty
|
||||
bool as_bool(bool def = false) const;
|
||||
|
||||
#ifndef PUGIXML_NO_STL
|
||||
// Get attribute value as std::istringstream, an empty std::istringstream if the attribute is empty
|
||||
istringstream_t as_stringstream() const;
|
||||
|
||||
// Get attribute value as Type (template parameter: try to read a Type value from the attribute value string)
|
||||
template <typename Type>
|
||||
Type as() const
|
||||
{
|
||||
istringstream_t stream(as_stringstream());
|
||||
Type value;
|
||||
stream >> value;
|
||||
return value;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Set text (returns false if object is empty or there is not enough memory)
|
||||
bool set(const char_t* rhs);
|
||||
|
||||
@ -742,6 +784,16 @@ namespace pugi
|
||||
bool set(unsigned long long rhs);
|
||||
#endif
|
||||
|
||||
#ifndef PUGIXML_NO_STL
|
||||
template <typename Type>
|
||||
bool set(const Type& rhs)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << rhs;
|
||||
return set(stream.str().c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
// Set text (equivalent to set without error checking)
|
||||
xml_text& operator=(const char_t* rhs);
|
||||
xml_text& operator=(int rhs);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user