| 1 | // file : xsd/cxx/tree/parsing/boolean.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_BOOLEAN_HXX |
|---|
| 7 | #define XSD_CXX_TREE_PARSING_BOOLEAN_HXX |
|---|
| 8 | |
|---|
| 9 | #include <xsd/cxx/ro-string.hxx> |
|---|
| 10 | #include <xsd/cxx/zc-istream.hxx> |
|---|
| 11 | |
|---|
| 12 | #include <xsd/cxx/xml/string.hxx> // xml::transcode |
|---|
| 13 | |
|---|
| 14 | #include <xsd/cxx/tree/text.hxx> // text_content |
|---|
| 15 | #include <xsd/cxx/tree/bits/literals.hxx> |
|---|
| 16 | |
|---|
| 17 | namespace xsd |
|---|
| 18 | { |
|---|
| 19 | namespace cxx |
|---|
| 20 | { |
|---|
| 21 | namespace tree |
|---|
| 22 | { |
|---|
| 23 | template <typename C> |
|---|
| 24 | struct traits<bool, C> |
|---|
| 25 | { |
|---|
| 26 | typedef bool type; |
|---|
| 27 | |
|---|
| 28 | static type |
|---|
| 29 | create (const xercesc::DOMElement& e, flags f, container* c); |
|---|
| 30 | |
|---|
| 31 | static type |
|---|
| 32 | create (const xercesc::DOMAttr& a, flags f, container* c); |
|---|
| 33 | |
|---|
| 34 | static type |
|---|
| 35 | create (const std::basic_string<C>& s, |
|---|
| 36 | const xercesc::DOMElement*, |
|---|
| 37 | flags, |
|---|
| 38 | container*); |
|---|
| 39 | }; |
|---|
| 40 | |
|---|
| 41 | template <typename C> |
|---|
| 42 | bool traits<bool, C>:: |
|---|
| 43 | create (const xercesc::DOMElement& e, flags f, container* c) |
|---|
| 44 | { |
|---|
| 45 | return create (text_content<C> (e), 0, f, c); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | template <typename C> |
|---|
| 49 | bool traits<bool, C>:: |
|---|
| 50 | create (const xercesc::DOMAttr& a, flags f, container* c) |
|---|
| 51 | { |
|---|
| 52 | return create (xml::transcode<C> (a.getValue ()), 0, f, c); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | template <typename C> |
|---|
| 56 | bool traits<bool, C>:: |
|---|
| 57 | create (const std::basic_string<C>& s, |
|---|
| 58 | const xercesc::DOMElement*, |
|---|
| 59 | flags, |
|---|
| 60 | container*) |
|---|
| 61 | { |
|---|
| 62 | // This type cannot have whitespaces in its values. As result we |
|---|
| 63 | // don't need to waste time collapsing whitespaces. All we need to |
|---|
| 64 | // do is trim the string representation which can be done without |
|---|
| 65 | // copying. |
|---|
| 66 | // |
|---|
| 67 | ro_string<C> tmp (s); |
|---|
| 68 | trim (tmp); |
|---|
| 69 | |
|---|
| 70 | return tmp == bits::true_<C> () || tmp == bits::one<C> (); |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | #endif // XSD_CXX_TREE_PARSING_BOOLEAN_HXX |
|---|