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

Revision 111, 2.4 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/float.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_FLOAT_HXX
7#define XSD_CXX_TREE_PARSING_FLOAT_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<float, C>
28      {
29        typedef float 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      float traits<float, 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      float traits<float, 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      float traits<float, 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        if (tmp == bits::positive_inf<C> ())
74          return std::numeric_limits<float>::infinity ();
75
76        if (tmp == bits::negative_inf<C> ())
77          return -std::numeric_limits<float>::infinity ();
78
79        if (tmp == bits::nan<C> ())
80          return std::numeric_limits<float>::quiet_NaN ();
81
82        zc_istream<C> is (tmp);
83        is.imbue (std::locale::classic ());
84
85        type t;
86        is >> t;
87
88        return t;
89      }
90    }
91  }
92}
93
94#endif // XSD_CXX_TREE_PARSING_FLOAT_HXX
Note: See TracBrowser for help on using the browser.