From 2615896faa646e5830abf2c269150e1165c66515 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 18 Dec 2020 18:48:46 +0300 Subject: Switch to build2 --- libxsd/libxsd/cxx/tree/parsing/float.hxx | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 libxsd/libxsd/cxx/tree/parsing/float.hxx (limited to 'libxsd/libxsd/cxx/tree/parsing/float.hxx') diff --git a/libxsd/libxsd/cxx/tree/parsing/float.hxx b/libxsd/libxsd/cxx/tree/parsing/float.hxx new file mode 100644 index 0000000..d0187a3 --- /dev/null +++ b/libxsd/libxsd/cxx/tree/parsing/float.hxx @@ -0,0 +1,92 @@ +// file : libxsd/cxx/tree/parsing/float.hxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef LIBXSD_CXX_TREE_PARSING_FLOAT_HXX +#define LIBXSD_CXX_TREE_PARSING_FLOAT_HXX + +#include +#include + +#include +#include + +#include // xml::transcode + +#include // text_content +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template + struct traits + { + typedef float 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& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template + float traits:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (tree::text_content (e), 0, f, c); + } + + template + float traits:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode (a.getValue ()), 0, f, c); + } + + template + float traits:: + create (const std::basic_string& 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 tmp (s); + trim (tmp); + + if (tmp == bits::positive_inf ()) + return std::numeric_limits::infinity (); + + if (tmp == bits::negative_inf ()) + return -std::numeric_limits::infinity (); + + if (tmp == bits::nan ()) + return std::numeric_limits::quiet_NaN (); + + zc_istream is (tmp); + is.imbue (std::locale::classic ()); + + type t; + is >> t; + + return t; + } + } + } +} + +#endif // LIBXSD_CXX_TREE_PARSING_FLOAT_HXX -- cgit v1.1