diff --git a/six/modules/c++/six/include/six/XmlLite.h b/six/modules/c++/six/include/six/XmlLite.h index e2d3b847f..a1b0ad510 100644 --- a/six/modules/c++/six/include/six/XmlLite.h +++ b/six/modules/c++/six/include/six/XmlLite.h @@ -164,6 +164,8 @@ struct SIX_SIX_API XmlLite final xml::lite::Element& createInt(const xml::lite::QName& name, int32_t p, xml::lite::Element& parent) const; xml::lite::Element& createLong(const xml::lite::QName& name, const std::string& p, xml::lite::Element& parent) const; xml::lite::Element& createLong(const xml::lite::QName& name, int64_t p, xml::lite::Element& parent) const; + xml::lite::Element& createInteger(const xml::lite::QName& name, const std::string& p, xml::lite::Element& parent) const; + xml::lite::Element& createInteger(const xml::lite::QName& name, const XsInteger& p, xml::lite::Element& parent) const; xml::lite::Element& createDouble(const xml::lite::QName&, double p, xml::lite::Element& parent) const; xml::lite::Element& createDouble(const xml::lite::QName&, const std::optional& p, xml::lite::Element& parent) const; @@ -310,6 +312,7 @@ struct SIX_SIX_API XmlLite final private: xml::lite::Element& createInt_(const std::string& name, int32_t p, xml::lite::Element& parent) const; xml::lite::Element& createLong_(const std::string& name, int64_t p, xml::lite::Element& parent) const; + xml::lite::Element& createInteger_(const std::string& name, const XsInteger& p, xml::lite::Element& parent) const; xml::lite::Element& createString_(const std::string& name, const std::string& p, xml::lite::Element& parent) const; xml::lite::QName makeQName(const std::string& name) const; diff --git a/six/modules/c++/six/include/six/XsInteger.h b/six/modules/c++/six/include/six/XsInteger.h index 4f2bb11ce..fbe432ca1 100644 --- a/six/modules/c++/six/include/six/XsInteger.h +++ b/six/modules/c++/six/include/six/XsInteger.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -114,6 +115,7 @@ namespace details // Be sure we can round-trip the value; to_int64() does validation. const auto str_value = std::to_string(v); const auto i64 = to_int64(str_value); // validation + std::ignore = i64; // compiler warning assert(v == i64); assert(str_value == std::to_string(i64)); return str_value; diff --git a/six/modules/c++/six/source/XmlLite.cpp b/six/modules/c++/six/source/XmlLite.cpp index a01360004..b59ef8cb4 100644 --- a/six/modules/c++/six/source/XmlLite.cpp +++ b/six/modules/c++/six/source/XmlLite.cpp @@ -200,6 +200,11 @@ inline std::string toString_(const xml::lite::QName& name, const std::u8string& { return toString(name, str::to_native(v), parent); } +template<> +inline std::string toString_(const xml::lite::QName& name, const XsInteger& v, const xml::lite::Element& parent) +{ + return toString(name, to_string(v), parent); +} template static xml::lite::Element& createValue(const xml::lite::QName& name, @@ -278,6 +283,22 @@ xml::lite::Element& XmlLite::createLong_(const std::string& name, int64_t p, xml return createLong(makeQName(name), p, parent); } +// https://www.oreilly.com/library/view/xml-schema/0596002521/re80.html +xml::lite::Element& XmlLite::createInteger(const xml::lite::QName& name, const XsInteger& p, xml::lite::Element& parent) const +{ + return createValue(name, p, parent, "xs:integer"); // unbounded, not xs:int +} +xml::lite::Element& XmlLite::createInteger(const xml::lite::QName& name, const std::string& p, xml::lite::Element& parent) const +{ + auto& elem = newElement(name, p, parent); + addClassAttributes(elem, "xs:integer"); // unbounded, not xs:int + return elem; +} +xml::lite::Element& XmlLite::createInteger_(const std::string& name, const XsInteger& p, xml::lite::Element& parent) const +{ + return createInteger(makeQName(name), p, parent); +} + xml::lite::Element& XmlLite::createDouble(const xml::lite::QName& name, double p, xml::lite::Element& parent) const { p = value(p); // be sure this is initialized; throws if not