root/win32/xsd-3.1.0-i686/libxsd/xsd/cxx/tree/parsing/double.hxx @ 111

Revision 111, 2.6 kB (checked in by mido, 16 years ago)

pridana knihovna XSD (a jeji chlebodarkyne XERCES), v ramci Win32 zprovoznen priklad tests/test_xsd_hello.cxx

Line 
1// file      : xsd/cxx/tree/parsing/double.hxx
2// author    : Boris Kolpackov <boris@codesynthesis.com>
3// copyright : Copyright (c) 2005-2008 Code Synthesis Tools CC
4// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file
5
6#ifndef XSD_CXX_TREE_PARSING_DOUBLE_HXX
7#define XSD_CXX_TREE_PARSING_DOUBLE_HXX
8
9#include <limits>
10#include <locale>
11
12#include <xsd/cxx/ro-string.hxx>
13#include <xsd/cxx/zc-istream.hxx>
14
15#include <xsd/cxx/xml/string.hxx> // xml::transcode
16
17#include <xsd/cxx/tree/text.hxx>  // text_content
18#include <xsd/cxx/tree/bits/literals.hxx>
19
20namespace xsd
21{
22  namespace cxx
23  {
24    namespace tree
25    {
26      template <typename C>
27      struct traits<double, C>
28      {
29        typedef double type;
30
31        static type
32        create (const xercesc::DOMElement& e, flags f, container* c);
33
34        static type
35        create (const xercesc::DOMAttr& a, flags f, container* c);
36
37        static type
38        create (const std::basic_string<C>& s,
39                const xercesc::DOMElement*,
40                flags,
41                container*);
42      };
43
44      template <typename C>
45      double traits<double, C>::
46      create (const xercesc::DOMElement& e, flags f, container* c)
47      {
48        return create (text_content<C> (e), 0, f, c);
49      }
50
51      template <typename C>
52      double traits<double, C>::
53      create (const xercesc::DOMAttr& a, flags f, container* c)
54      {
55        return create (xml::transcode<C> (a.getValue ()), 0, f, c);
56      }
57
58      template <typename C>
59      double traits<double, C>::
60      create (const std::basic_string<C>& s,
61              const xercesc::DOMElement*,
62              flags,
63              container*)
64      {
65        // This type cannot have whitespaces in its values. As result we
66        // don't need to waste time collapsing whitespaces. All we need to
67        // do is trim the string representation which can be done without
68        // copying.
69        //
70        ro_string<C> tmp (s);
71        trim (tmp);
72
73        // @@ We map both xsd:double and xsd:decimal to double and decimal
74        // cannot be in scientific notation or be INF/NaN.
75        //
76        if (tmp == bits::positive_inf<C> ())
77          return std::numeric_limits<double>::infinity ();
78
79        if (tmp == bits::negative_inf<C> ())
80          return -std::numeric_limits<double>::infinity ();
81
82        if (tmp == bits::nan<C> ())
83          return std::numeric_limits<double>::quiet_NaN ();
84
85        zc_istream<C> is (tmp);
86        is.imbue (std::locale::classic ());
87
88        type t;
89        is >> t;
90
91        return t;
92      }
93    }
94  }
95}
96
97#endif // XSD_CXX_TREE_PARSING_DOUBLE_HXX
Note: See TracBrowser for help on using the browser.