diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-12-18 18:48:46 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-01-13 22:32:43 +0300 |
commit | 2615896faa646e5830abf2c269150e1165c66515 (patch) | |
tree | 7d95978ec0a83094c9462ed4e1f59d42f4ff8ddb /libxsd/libxsd/cxx/tree/parsing/decimal.hxx | |
parent | 7420f85ea19b0562ffdd8123442f32bc8bac1267 (diff) |
Switch to build2
Diffstat (limited to 'libxsd/libxsd/cxx/tree/parsing/decimal.hxx')
-rw-r--r-- | libxsd/libxsd/cxx/tree/parsing/decimal.hxx | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/libxsd/libxsd/cxx/tree/parsing/decimal.hxx b/libxsd/libxsd/cxx/tree/parsing/decimal.hxx new file mode 100644 index 0000000..d2ea576 --- /dev/null +++ b/libxsd/libxsd/cxx/tree/parsing/decimal.hxx @@ -0,0 +1,83 @@ +// file : libxsd/cxx/tree/parsing/decimal.hxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef LIBXSD_CXX_TREE_PARSING_DECIMAL_HXX +#define LIBXSD_CXX_TREE_PARSING_DECIMAL_HXX + +#include <limits> +#include <locale> + +#include <libxsd/cxx/ro-string.hxx> +#include <libxsd/cxx/zc-istream.hxx> + +#include <libxsd/cxx/xml/string.hxx> // xml::transcode + +#include <libxsd/cxx/tree/text.hxx> // text_content +#include <libxsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<double, C, schema_type::decimal> + { + typedef double type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + double traits<double, C, schema_type::decimal>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (tree::text_content<C> (e), 0, f, c); + } + + template <typename C> + double traits<double, C, schema_type::decimal>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + double traits<double, C, schema_type::decimal>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + zc_istream<C> is (tmp); + is.imbue (std::locale::classic ()); + + type t; + is >> t; + + return t; + } + } + } +} + +#endif // LIBXSD_CXX_TREE_PARSING_DECIMAL_HXX |