diff options
Diffstat (limited to 'xsd/libxsd/xsd/cxx/parser/validating')
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/exceptions.hxx | 153 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/exceptions.ixx | 163 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/exceptions.txx | 97 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/inheritance-map.hxx | 101 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/inheritance-map.txx | 73 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/parser.hxx | 471 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/parser.txx | 667 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx | 1121 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.ixx | 676 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx | 2746 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx | 647 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.ixx | 1249 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.txx | 69 |
13 files changed, 8233 insertions, 0 deletions
diff --git a/xsd/libxsd/xsd/cxx/parser/validating/exceptions.hxx b/xsd/libxsd/xsd/cxx/parser/validating/exceptions.hxx new file mode 100644 index 0000000..c0efda8 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/exceptions.hxx @@ -0,0 +1,153 @@ +// file : xsd/cxx/parser/validating/exceptions.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_HXX +#define XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_HXX + +#include <string> + +#include <xsd/cxx/parser/schema-exceptions.hxx> +#include <xsd/cxx/ro-string.hxx> + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // + // + template <typename C> + struct expected_attribute: schema_exception<C> + { + virtual + ~expected_attribute (); + + expected_attribute (const std::basic_string<C>& expected_namespace, + const std::basic_string<C>& expected_name); + + const std::basic_string<C>& + expected_namespace () const + { + return expected_namespace_; + } + + const std::basic_string<C>& + expected_name () const + { + return expected_name_; + } + + virtual std::basic_string<C> + message () const; + + private: + std::basic_string<C> expected_namespace_; + std::basic_string<C> expected_name_; + }; + + // + // + template <typename C> + struct unexpected_attribute: schema_exception<C> + { + virtual + ~unexpected_attribute (); + + unexpected_attribute ( + const std::basic_string<C>& encountered_namespace, + const std::basic_string<C>& encountered_name); + + + const std::basic_string<C>& + encountered_namespace () const + { + return encountered_namespace_; + } + + const std::basic_string<C>& + encountered_name () const + { + return encountered_name_; + } + + virtual std::basic_string<C> + message () const; + + private: + std::basic_string<C> encountered_namespace_; + std::basic_string<C> encountered_name_; + }; + + + // + // + template <typename C> + struct unexpected_characters: schema_exception<C> + { + virtual + ~unexpected_characters (); + + unexpected_characters (const std::basic_string<C>& s); + + const std::basic_string<C>& + characters () const + { + return characters_; + } + + virtual std::basic_string<C> + message () const; + + private: + std::basic_string<C> characters_; + }; + + // + // + template <typename C> + struct invalid_value: schema_exception<C> + { + virtual + ~invalid_value (); + + invalid_value (const C* type, const std::basic_string<C>& value); + + invalid_value (const C* type, const ro_string<C>& value); + + invalid_value (const std::basic_string<C>& type, + const std::basic_string<C>& value); + + const std::basic_string<C>& + type () const + { + return type_; + } + + const std::basic_string<C>& + value () const + { + return value_; + } + + virtual std::basic_string<C> + message () const; + + private: + std::basic_string<C> type_; + std::basic_string<C> value_; + }; + } + } + } +} + +#include <xsd/cxx/parser/validating/exceptions.txx> + +#endif // XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_HXX + +#include <xsd/cxx/parser/validating/exceptions.ixx> diff --git a/xsd/libxsd/xsd/cxx/parser/validating/exceptions.ixx b/xsd/libxsd/xsd/cxx/parser/validating/exceptions.ixx new file mode 100644 index 0000000..74bb909 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/exceptions.ixx @@ -0,0 +1,163 @@ +// file : xsd/cxx/parser/validating/exceptions.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#if defined(XSD_CXX_PARSER_USE_CHAR) || !defined(XSD_CXX_PARSER_USE_WCHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_CHAR +#define XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // expected_attribute + // + template<> + inline + std::basic_string<char> expected_attribute<char>:: + message () const + { + std::basic_string<char> r ("expected attribute '"); + r += expected_namespace_; + r += expected_namespace_.empty () ? "" : "#"; + r += expected_name_; + r += "'"; + return r; + } + + // unexpected_attribute + // + template<> + inline + std::basic_string<char> unexpected_attribute<char>:: + message () const + { + std::basic_string<char> r ("unexpected attribute '"); + r += encountered_namespace_; + r += encountered_namespace_.empty () ? "" : "#"; + r += encountered_name_; + r += "'"; + return r; + } + + // unexpected_characters + // + template<> + inline + std::basic_string<char> unexpected_characters<char>:: + message () const + { + std::basic_string<char> r ("unexpected characters '"); + r += characters_; + r += "'"; + return r; + } + + // invalid_value + // + template<> + inline + std::basic_string<char> invalid_value<char>:: + message () const + { + std::basic_string<char> r ("'"); + r += value_; + r += "' is not a valid value representation "; + r += "for type '"; + r += type_; + r += "'"; + return r; + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_CHAR +#endif // XSD_CXX_PARSER_USE_CHAR + + +#if defined(XSD_CXX_PARSER_USE_WCHAR) || !defined(XSD_CXX_PARSER_USE_CHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_WCHAR +#define XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // expected_attribute + // + template<> + inline + std::basic_string<wchar_t> expected_attribute<wchar_t>:: + message () const + { + std::basic_string<wchar_t> r (L"expected attribute '"); + r += expected_namespace_; + r += expected_namespace_.empty () ? L"" : L"#"; + r += expected_name_; + r += L"'"; + return r; + } + + // unexpected_attribute + // + template<> + inline + std::basic_string<wchar_t> unexpected_attribute<wchar_t>:: + message () const + { + std::basic_string<wchar_t> r (L"unexpected attribute '"); + r += encountered_namespace_; + r += encountered_namespace_.empty () ? L"" : L"#"; + r += encountered_name_; + r += L"'"; + return r; + } + + // unexpected_characters + // + template<> + inline + std::basic_string<wchar_t> unexpected_characters<wchar_t>:: + message () const + { + std::basic_string<wchar_t> r (L"unexpected characters '"); + r += characters_; + r += L"'"; + return r; + } + + // invalid_value + // + template<> + inline + std::basic_string<wchar_t> invalid_value<wchar_t>:: + message () const + { + std::basic_string<wchar_t> r (L"'"); + r += value_; + r += L"' is not a valid value representation "; + r += L"for type '"; + r += type_; + r += L"'"; + return r; + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_IXX_WCHAR +#endif // XSD_CXX_PARSER_USE_WCHAR diff --git a/xsd/libxsd/xsd/cxx/parser/validating/exceptions.txx b/xsd/libxsd/xsd/cxx/parser/validating/exceptions.txx new file mode 100644 index 0000000..6205215 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/exceptions.txx @@ -0,0 +1,97 @@ +// file : xsd/cxx/parser/validating/exceptions.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // expected_attribute + // + template <typename C> + expected_attribute<C>:: + ~expected_attribute () + { + } + + template <typename C> + expected_attribute<C>:: + expected_attribute (const std::basic_string<C>& expected_namespace, + const std::basic_string<C>& expected_name) + : expected_namespace_ (expected_namespace), + expected_name_ (expected_name) + { + } + + // unexpected_attribute + // + template <typename C> + unexpected_attribute<C>:: + ~unexpected_attribute () + { + } + + template <typename C> + unexpected_attribute<C>:: + unexpected_attribute (const std::basic_string<C>& encountered_namespace, + const std::basic_string<C>& encountered_name) + : encountered_namespace_ (encountered_namespace), + encountered_name_ (encountered_name) + { + } + + // unexpected_characters + // + template <typename C> + unexpected_characters<C>:: + ~unexpected_characters () + { + } + + template <typename C> + unexpected_characters<C>:: + unexpected_characters (const std::basic_string<C>& s) + : characters_ (s) + { + } + + // invalid_value + // + template <typename C> + invalid_value<C>:: + ~invalid_value () + { + } + + template <typename C> + invalid_value<C>:: + invalid_value (const C* type, + const std::basic_string<C>& value) + : type_ (type), value_ (value) + { + } + + template <typename C> + invalid_value<C>:: + invalid_value (const C* type, + const ro_string<C>& value) + : type_ (type), value_ (value) + { + } + + template <typename C> + invalid_value<C>:: + invalid_value (const std::basic_string<C>& type, + const std::basic_string<C>& value) + : type_ (type), value_ (value) + { + } + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/parser/validating/inheritance-map.hxx b/xsd/libxsd/xsd/cxx/parser/validating/inheritance-map.hxx new file mode 100644 index 0000000..d9307b4 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/inheritance-map.hxx @@ -0,0 +1,101 @@ +// file : xsd/cxx/parser/validating/inheritance-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX +#define XSD_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX + +#include <map> +#include <cstddef> // std::size_t + +#include <xsd/cxx/ro-string.hxx> + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + template <typename C> + struct string_comparison + { + bool + operator() (const C* x, const C* y) const + { + ro_string<C> s (x); + return s.compare (y) < 0; + } + }; + + template <typename C> + struct inheritance_map + { + void + insert (const C* derived, const C* base) + { + map_[derived] = base; + } + + void + erase (const C* derived) + { + map_.erase (derived); + } + + bool + check (const C* derived, const ro_string<C>& base) const; + + private: + typedef std::map<const C*, const C*, string_comparison<C> > map; + map map_; + }; + + + // Translation unit initializer. + // + template<typename C> + struct inheritance_map_init + { + static inheritance_map<C>* map; + static std::size_t count; + + inheritance_map_init (); + ~inheritance_map_init (); + }; + + template<typename C> + inheritance_map<C>* inheritance_map_init<C>::map = 0; + + template<typename C> + std::size_t inheritance_map_init<C>::count = 0; + + template<typename C> + inline inheritance_map<C>& + inheritance_map_instance () + { + return *inheritance_map_init<C>::map; + } + + + // Map entry initializer. + // + template<typename C> + struct inheritance_map_entry + { + inheritance_map_entry (const C* derived, const C* base); + ~inheritance_map_entry (); + + private: + const C* derived_; + }; + } + } + } +} + +#include <xsd/cxx/parser/validating/inheritance-map.txx> + +#endif // XSD_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX diff --git a/xsd/libxsd/xsd/cxx/parser/validating/inheritance-map.txx b/xsd/libxsd/xsd/cxx/parser/validating/inheritance-map.txx new file mode 100644 index 0000000..1a63e65 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/inheritance-map.txx @@ -0,0 +1,73 @@ +// file : xsd/cxx/parser/validating/inheritance-map.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + template <typename C> + bool inheritance_map<C>:: + check (const C* derived, const ro_string<C>& base) const + { + if (base == derived) + return true; + + typename map::const_iterator i (map_.find (derived)); + + if (i != map_.end ()) + { + if (base == i->second) + return true; + else + return check (i->second, base); + } + + return false; + } + + // inheritance_map_init + // + template<typename C> + inheritance_map_init<C>:: + inheritance_map_init () + { + if (count == 0) + map = new inheritance_map<C>; + + ++count; + } + + template<typename C> + inheritance_map_init<C>:: + ~inheritance_map_init () + { + if (--count == 0) + delete map; + } + + // inheritance_map_entry + // + template<typename C> + inheritance_map_entry<C>:: + inheritance_map_entry (const C* derived, const C* base) + : derived_ (derived) + { + inheritance_map_instance<C> ().insert (derived, base); + } + + template<typename C> + inheritance_map_entry<C>:: + ~inheritance_map_entry () + { + inheritance_map_instance<C> ().erase (derived_); + } + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/parser/validating/parser.hxx b/xsd/libxsd/xsd/cxx/parser/validating/parser.hxx new file mode 100644 index 0000000..da297d9 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/parser.hxx @@ -0,0 +1,471 @@ +// file : xsd/cxx/parser/validating/parser.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_VALIDATING_PARSER_HXX +#define XSD_CXX_PARSER_VALIDATING_PARSER_HXX + +#include <stack> +#include <cstddef> // std::size_t +#include <cstring> // std::memcpy + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/parser/elements.hxx> + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // + // + template <typename C> + struct empty_content: parser_base<C> + { + // These functions are called when wildcard content + // is encountered. Use them to handle mixed content + // models, any/anyAttribute, and anyType/anySimpleType. + // By default these functions do nothing. + // + + // The type argument is a type name and namespace from the + // xsi:type attribute in the form "<name> <namespace>" with + // the space and namespace part absent if the type does not + // have a namespace or 0 if xsi:type is not present. + // + virtual void + _start_any_element (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>* type); + + virtual void + _end_any_element (const ro_string<C>& ns, + const ro_string<C>& name); + + virtual void + _any_attribute (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value); + + virtual void + _any_characters (const ro_string<C>&); + + + // + // + virtual bool + _start_element_impl (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>*); + + virtual bool + _end_element_impl (const ro_string<C>&, + const ro_string<C>&); + + virtual bool + _attribute_impl (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>&); + + virtual bool + _characters_impl (const ro_string<C>&); + + + // + // + virtual void + _start_element (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>*); + + virtual void + _end_element (const ro_string<C>&, + const ro_string<C>&); + + virtual void + _attribute (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>&); + + virtual void + _characters (const ro_string<C>&); + + + // + // + virtual void + _expected_element (const C* expected_ns, + const C* expected_name); + + virtual void + _expected_element (const C* expected_ns, + const C* expected_name, + const ro_string<C>& encountered_ns, + const ro_string<C>& encountered_name); + + virtual void + _unexpected_element (const ro_string<C>& ns, + const ro_string<C>& name); + + virtual void + _expected_attribute (const C* expected_ns, + const C* expected_name); + + virtual void + _unexpected_attribute (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value); + + virtual void + _unexpected_characters (const ro_string<C>&); + }; + + + // + // + template <typename C> + struct simple_content: empty_content<C> + { + // + // + virtual void + _attribute (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value); + + virtual void + _characters (const ro_string<C>&); + + // + // + virtual bool + _attribute_impl (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>&); + + // + // + virtual void + _pre_impl (); + + virtual void + _post_impl (); + + + // Implementation callbacks. + // + virtual void + _pre_a_validate (); + + virtual void + _post_a_validate (); + + + // Attribute validation: during phase one we are searching for + // matching attributes (Structures, section 3.4.4, clause 2.1). + // During phase two we are searching for attribute wildcards + // (section 3.4.4, clause 2.2). Both phases run across + // inheritance hierarchy from derived to base for extension + // only. Both functions return true if the match was found and + // validation has been performed. + // + virtual bool + _attribute_impl_phase_one (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value); + + virtual bool + _attribute_impl_phase_two (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value); + }; + + + // + // + template <typename C> + struct complex_content: empty_content<C> + { + // + // + virtual void + _start_element (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>* type); + + virtual void + _end_element (const ro_string<C>& ns, + const ro_string<C>& name); + + virtual void + _attribute (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value); + + virtual void + _characters (const ro_string<C>&); + + // + // + virtual bool + _attribute_impl (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>&); + + // + // + virtual void + _pre_impl (); + + virtual void + _post_impl (); + + + // Implementation callbacks. + // + virtual void + _pre_e_validate (); + + virtual void + _post_e_validate (); + + virtual void + _pre_a_validate (); + + virtual void + _post_a_validate (); + + + // Attribute validation: during phase one we are searching for + // matching attributes (Structures, section 3.4.4, clause 2.1). + // During phase two we are searching for attribute wildcards + // (section 3.4.4, clause 2.2). Both phases run across + // inheritance hierarchy from derived to base for extension + // only. Both functions return true if the match was found and + // validation has been performed. + // + virtual bool + _attribute_impl_phase_one (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value); + + virtual bool + _attribute_impl_phase_two (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value); + protected: + struct state + { + state () + : any_ (false), depth_ (0), parser_ (0) + { + } + + bool any_; + std::size_t depth_; + parser_base<C>* parser_; + }; + + // Optimized state stack for non-recursive case (one element). + // + struct state_stack + { + state_stack () + : size_ (0) + { + } + + void + push (const state& s) + { + if (size_ > 0) + rest_.push (top_); + + top_ = s; + ++size_; + } + + void + pop () + { + if (size_ > 1) + { + top_ = rest_.top (); + rest_.pop (); + } + + --size_; + } + + const state& + top () const + { + return top_; + } + + state& + top () + { + return top_; + } + + state& + under_top () + { + return rest_.top (); + } + + private: + state top_; + std::stack<state> rest_; + std::size_t size_; + }; + + state_stack context_; + }; + + // Base for xsd:list. + // + template <typename C> + struct list_base: simple_content<C> + { + virtual void + _xsd_parse_item (const ro_string<C>&) = 0; + + virtual void + _pre_impl (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post_impl (); + + protected: + std::basic_string<C> buf_; + }; + } + + // POD stack with pre-allocated first element. You may + // need to pad your elements to get the proper alignment. + // + struct pod_stack + { + ~pod_stack () + { + delete[] data_; + } + + pod_stack (std::size_t element_size, void* first_element) + : el_size_ (element_size), first_ (first_element), + data_ (0), size_ (0), capacity_ (0) + { + } + + public: + void + pop () + { + --size_; + } + + void + push () + { + if (size_ > capacity_) + grow (); + + ++size_; + } + + void* + top () + { + return size_ == 1 ? first_ : data_ + (size_ - 1) * el_size_; + } + + void* + under_top () + { + return size_ == 2 ? first_ : data_ + (size_ - 2) * el_size_; + } + + std::size_t + element_size () const + { + return el_size_; + } + + private: + void + grow () + { + std::size_t c (capacity_ ? capacity_ * 2 : 8); + char* d (new char[c * el_size_]); + + if (size_ > 1) + std::memcpy (d, data_, (size_ - 1) * el_size_); + + delete[] data_; + + data_ = d; + capacity_ = c; + } + + private: + std::size_t el_size_; + void* first_; + char* data_; + std::size_t size_; + std::size_t capacity_; + }; + + namespace validating + { + // Validation state stack for the 'all' particle. + // + struct all_stack + { + all_stack (std::size_t n, unsigned char* first) + : stack_ (n, first) + { + } + + void + push () + { + stack_.push (); + + unsigned char* p (static_cast<unsigned char*> (stack_.top ())); + + for (std::size_t i (0); i < stack_.element_size (); ++i) + p[i] = 0; + } + + void + pop () + { + stack_.pop (); + } + + unsigned char* + top () + { + return static_cast<unsigned char*> (stack_.top ()); + } + + private: + pod_stack stack_; + }; + } + } + } +} + +#include <xsd/cxx/parser/validating/parser.txx> + +#endif // XSD_CXX_PARSER_VALIDATING_PARSER_HXX diff --git a/xsd/libxsd/xsd/cxx/parser/validating/parser.txx b/xsd/libxsd/xsd/cxx/parser/validating/parser.txx new file mode 100644 index 0000000..d447725 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/parser.txx @@ -0,0 +1,667 @@ +// file : xsd/cxx/parser/validating/parser.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <cassert> + +#include <xsd/cxx/xml/bits/literals.hxx> +#include <xsd/cxx/parser/validating/exceptions.hxx> + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + + // empty_content + // + + + template <typename C> + void empty_content<C>:: + _start_any_element (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>*) + { + } + + template <typename C> + void empty_content<C>:: + _end_any_element (const ro_string<C>&, + const ro_string<C>&) + { + } + + template <typename C> + void empty_content<C>:: + _any_attribute (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>&) + { + } + + template <typename C> + void empty_content<C>:: + _any_characters (const ro_string<C>&) + { + } + + // + // + template <typename C> + bool empty_content<C>:: + _start_element_impl (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>*) + { + return false; + } + + template <typename C> + bool empty_content<C>:: + _end_element_impl (const ro_string<C>&, + const ro_string<C>&) + { + return false; + } + + template <typename C> + bool empty_content<C>:: + _attribute_impl (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>&) + { + return false; + } + + template <typename C> + bool empty_content<C>:: + _characters_impl (const ro_string<C>&) + { + return false; + } + + // + // + template <typename C> + void empty_content<C>:: + _start_element (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>* type) + { + if (!this->_start_element_impl (ns, name, type)) + this->_unexpected_element (ns, name); + } + + template <typename C> + void empty_content<C>:: + _end_element (const ro_string<C>& ns, + const ro_string<C>& name) + { + if (!this->_end_element_impl (ns, name)) + this->_unexpected_element (ns, name); + } + + template <typename C> + void empty_content<C>:: + _attribute (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xml::bits::xsi_namespace<C> () && + (name == xml::bits::type<C> () || + name == xml::bits::nil_lit<C> () || + name == xml::bits::schema_location<C> () || + name == xml::bits::no_namespace_schema_location<C> ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace<C> ()) + return; + + if (!this->_attribute_impl (ns, name, value)) + this->_unexpected_attribute (ns, name, value); + } + + template <typename C> + void empty_content<C>:: + _characters (const ro_string<C>& s) + { + if (!this->_characters_impl (s)) + this->_unexpected_characters (s); + } + + // + // + template <typename C> + void empty_content<C>:: + _expected_element (const C* ex_ns, const C* ex_name) + { + throw expected_element<C> (ex_ns, ex_name); + } + + template <typename C> + void empty_content<C>:: + _expected_element (const C* ex_ns, + const C* ex_name, + const ro_string<C>& en_ns, + const ro_string<C>& en_name) + { + throw expected_element<C> (ex_ns, ex_name, en_ns, en_name); + } + + template <typename C> + void empty_content<C>:: + _unexpected_element (const ro_string<C>& ns, + const ro_string<C>& name) + { + throw unexpected_element<C> (ns, name); + } + + template <typename C> + void empty_content<C>:: + _expected_attribute (const C* ex_ns, const C* ex_name) + { + throw expected_attribute<C> (ex_ns, ex_name); + } + + template <typename C> + void empty_content<C>:: + _unexpected_attribute (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>&) + { + throw unexpected_attribute<C> (ns, name); + } + + template <typename C> + void empty_content<C>:: + _unexpected_characters (const ro_string<C>& s) + { + throw unexpected_characters<C> (s); + } + + + // simple_content + // + + template <typename C> + void simple_content<C>:: + _attribute (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and xsi:noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xml::bits::xsi_namespace<C> () && + (name == xml::bits::type<C> () || + name == xml::bits::nil_lit<C> () || + name == xml::bits::schema_location<C> () || + name == xml::bits::no_namespace_schema_location<C> ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace<C> ()) + return; + + if (!this->_attribute_impl (ns, name, value)) + this->_unexpected_attribute (ns, name, value); + } + + template <typename C> + void simple_content<C>:: + _characters (const ro_string<C>& str) + { + if (!this->_characters_impl (str)) + { + // Mixed content is implemented in the generated code + // by overriding _characters_impl and forwarding to + // _any_characters. + // + + // Scan the string for any non-whitespace characters + // (Structures, section 3.4.4, clause 1.3). + // + for (typename ro_string<C>::size_type i (0), e (str.size ()); + i < e; ++i) + { + C c (str[i]); + + if (c != C (0x20) && // space + c != C (0x0D) && // carriage return + c != C (0x09) && // tab + c != C (0x0A)) + this->_unexpected_characters (str); + } + } + } + + template <typename C> + void simple_content<C>:: + _pre_impl () + { + this->_pre (); + _pre_a_validate (); + } + + template <typename C> + void simple_content<C>:: + _post_impl () + { + _post_a_validate (); + this->_post (); + } + + template <typename C> + void simple_content<C>:: + _pre_a_validate () + { + } + + template <typename C> + void simple_content<C>:: + _post_a_validate () + { + } + + template <typename C> + bool simple_content<C>:: + _attribute_impl (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value) + { + return _attribute_impl_phase_one (ns, name, value) || + _attribute_impl_phase_two (ns, name, value); + } + + template <typename C> + bool simple_content<C>:: + _attribute_impl_phase_one (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>&) + { + return false; + } + + template <typename C> + bool simple_content<C>:: + _attribute_impl_phase_two (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>&) + { + return false; + } + + + // complex_content + // + + + template <typename C> + void complex_content<C>:: + _start_element (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>* type) + { + state& s (context_.top ()); + + if (s.depth_++ > 0) + { + if (s.any_) + this->_start_any_element (ns, name, type); + else if (s.parser_) + s.parser_->_start_element (ns, name, type); + } + else + { + if (!this->_start_element_impl (ns, name, type)) + this->_unexpected_element (ns, name); + else if (s.parser_ != 0) + s.parser_->_pre_impl (); + } + } + + template <typename C> + void complex_content<C>:: + _end_element (const ro_string<C>& ns, + const ro_string<C>& name) + { + // To understand what's going on here it is helpful to think of + // a "total depth" as being the sum of individual depths over + // all elements. + // + + if (context_.top ().depth_ == 0) + { + state& s (context_.under_top ()); // One before last. + + if (--s.depth_ > 0) + { + // Indirect recursion. + // + if (s.parser_) + s.parser_->_end_element (ns, name); + } + else + { + // Direct recursion. + // + assert (this == s.parser_); + + this->_post_impl (); + + if (!this->_end_element_impl (ns, name)) + assert (false); + } + } + else + { + state& s (context_.top ()); + + if (--s.depth_ > 0) + { + if (s.any_) + this->_end_any_element (ns, name); + else if (s.parser_) + s.parser_->_end_element (ns, name); + } + else + { + if (s.parser_ != 0 && !s.any_) + s.parser_->_post_impl (); + + if (!this->_end_element_impl (ns, name)) + this->_unexpected_element (ns, name); + } + } + } + + template <typename C> + void complex_content<C>:: + _attribute (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and xsi:noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xml::bits::xsi_namespace<C> () && + (name == xml::bits::type<C> () || + name == xml::bits::nil_lit<C> () || + name == xml::bits::schema_location<C> () || + name == xml::bits::no_namespace_schema_location<C> ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace<C> ()) + return; + + const state& s (context_.top ()); + + if (s.depth_ > 0) + { + if (s.any_) + this->_any_attribute (ns, name, value); + else if (s.parser_) + s.parser_->_attribute (ns, name, value); + } + else + { + if (!this->_attribute_impl (ns, name, value)) + this->_unexpected_attribute (ns, name, value); + } + } + + template <typename C> + void complex_content<C>:: + _characters (const ro_string<C>& str) + { + const state& s (context_.top ()); + + if (s.depth_ > 0) + { + if (s.any_) + this->_any_characters (str); + else if (s.parser_) + s.parser_->_characters (str); + } + else + { + if (!this->_characters_impl (str)) + { + // Mixed content is implemented in the generated code + // by overriding _characters_impl and forwarding to + // _any_characters. + // + + // Scan the string for any non-whitespace characters + // (Structures, section 3.4.4, clause 1.3). + // + for (typename ro_string<C>::size_type i (0), e (str.size ()); + i < e; ++i) + { + C c (str[i]); + + if (c != C (0x20) && // space + c != C (0x0D) && // carriage return + c != C (0x09) && // tab + c != C (0x0A)) + this->_unexpected_characters (str); + } + } + } + } + + template <typename C> + void complex_content<C>:: + _pre_impl () + { + context_.push (state ()); + this->_pre (); + _pre_a_validate (); + _pre_e_validate (); + } + + template <typename C> + void complex_content<C>:: + _post_impl () + { + _post_e_validate (); + _post_a_validate (); + this->_post (); + context_.pop (); + } + + template <typename C> + void complex_content<C>:: + _pre_e_validate () + { + } + + template <typename C> + void complex_content<C>:: + _post_e_validate () + { + } + + template <typename C> + void complex_content<C>:: + _pre_a_validate () + { + } + + template <typename C> + void complex_content<C>:: + _post_a_validate () + { + } + + template <typename C> + bool complex_content<C>:: + _attribute_impl (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value) + { + return _attribute_impl_phase_one (ns, name, value) || + _attribute_impl_phase_two (ns, name, value); + } + + template <typename C> + bool complex_content<C>:: + _attribute_impl_phase_one (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>&) + { + return false; + } + + template <typename C> + bool complex_content<C>:: + _attribute_impl_phase_two (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>&) + { + return false; + } + + + // list_base + // + namespace bits + { + // Find first non-space character. + // + template <typename C> + typename ro_string<C>::size_type + find_ns (const C* s, + typename ro_string<C>::size_type size, + typename ro_string<C>::size_type pos) + { + while (pos < size && + (s[pos] == C (0x20) || s[pos] == C (0x0A) || + s[pos] == C (0x0D) || s[pos] == C (0x09))) + ++pos; + + return pos < size ? pos : ro_string<C>::npos; + } + + // Find first space character. + // + template <typename C> + typename ro_string<C>::size_type + find_s (const C* s, + typename ro_string<C>::size_type size, + typename ro_string<C>::size_type pos) + { + while (pos < size && + s[pos] != C (0x20) && s[pos] != C (0x0A) && + s[pos] != C (0x0D) && s[pos] != C (0x09)) + ++pos; + + return pos < size ? pos : ro_string<C>::npos; + } + } + + // Relevant XML Schema Part 2: Datatypes sections: 4.2.1.2, 4.3.6. + // + + template <typename C> + void list_base<C>:: + _pre_impl () + { + simple_content<C>::_pre_impl (); + buf_.clear (); + } + + template <typename C> + void list_base<C>:: + _characters (const ro_string<C>& s) + { + typedef typename ro_string<C>::size_type size_type; + + const C* data (s.data ()); + size_type size (s.size ()); + + // Handle the previous chunk if we start with a ws. + // + if (!buf_.empty () && + (data[0] == C (0x20) || data[0] == C (0x0A) || + data[0] == C (0x0D) || data[0] == C (0x09))) + { + ro_string<C> tmp (buf_); // Private copy ctor. + _xsd_parse_item (tmp); + buf_.clear (); + } + + // Traverse the data while logically collapsing spaces. + // + for (size_type i (bits::find_ns (data, size, 0)); + i != ro_string<C>::npos;) + { + size_type j (bits::find_s (data, size, i)); + + if (j != ro_string<C>::npos) + { + if (buf_.empty ()) + { + ro_string<C> tmp (data + i, j - i); // Private copy ctor. + _xsd_parse_item (tmp); + } + else + { + // Assemble the first item in str from buf_ and s. + // + std::basic_string<C> str; + str.swap (buf_); + str.append (data + i, j - i); + ro_string<C> tmp (str); // Private copy ctor. + _xsd_parse_item (tmp); + } + + i = bits::find_ns (data, size, j); + } + else + { + // Last fragment, append it to the buf_. + // + buf_.append (data + i, size - i); + break; + } + } + } + + template <typename C> + void list_base<C>:: + _post_impl () + { + // Handle the last item. + // + if (!buf_.empty ()) + { + ro_string<C> tmp (buf_); // Private copy ctor. + _xsd_parse_item (tmp); + } + + simple_content<C>::_post_impl (); + } + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx new file mode 100644 index 0000000..619a8c7 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx @@ -0,0 +1,1121 @@ +// file : xsd/cxx/parser/validating/xml-schema-pimpl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX + +#include <string> + +#include <xsd/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type + // + template <typename C> + struct any_type_pimpl: virtual any_type_pskel<C> + { + virtual void + post_any_type (); + }; + + // any_simple_type + // + template <typename C> + struct any_simple_type_pimpl: virtual any_simple_type_pskel<C> + { + virtual void + post_any_simple_type (); + }; + + // boolean + // + template <typename C> + struct boolean_pimpl: virtual boolean_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual bool + post_boolean (); + + protected: + std::basic_string<C> str_; + bool value_; + }; + + + // 8-bit + // + template <typename C> + struct byte_pimpl: virtual byte_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual signed char + post_byte (); + + protected: + std::basic_string<C> str_; + signed char value_; + }; + + + template <typename C> + struct unsigned_byte_pimpl: virtual unsigned_byte_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual unsigned char + post_unsigned_byte (); + + protected: + std::basic_string<C> str_; + unsigned char value_; + }; + + + // 16-bit + // + template <typename C> + struct short_pimpl: virtual short_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual short + post_short (); + + protected: + std::basic_string<C> str_; + short value_; + }; + + + template <typename C> + struct unsigned_short_pimpl: virtual unsigned_short_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual unsigned short + post_unsigned_short (); + + protected: + std::basic_string<C> str_; + unsigned short value_; + }; + + + // 32-bit + // + template <typename C> + struct int_pimpl: virtual int_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual int + post_int (); + + protected: + std::basic_string<C> str_; + int value_; + }; + + + template <typename C> + struct unsigned_int_pimpl: virtual unsigned_int_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual unsigned int + post_unsigned_int (); + + protected: + std::basic_string<C> str_; + unsigned int value_; + }; + + + // 64-bit + // + template <typename C> + struct long_pimpl: virtual long_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual long long + post_long (); + + protected: + std::basic_string<C> str_; + long long value_; + }; + + + template <typename C> + struct unsigned_long_pimpl: virtual unsigned_long_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual unsigned long long + post_unsigned_long (); + + protected: + std::basic_string<C> str_; + unsigned long long value_; + }; + + + // Arbitrary-length integers. + // + template <typename C> + struct integer_pimpl: virtual integer_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual long long + post_integer (); + + protected: + std::basic_string<C> str_; + long long value_; + }; + + template <typename C> + struct negative_integer_pimpl: virtual negative_integer_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual long long + post_negative_integer (); + + protected: + std::basic_string<C> str_; + long long value_; + }; + + template <typename C> + struct non_positive_integer_pimpl: virtual non_positive_integer_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual long long + post_non_positive_integer (); + + protected: + std::basic_string<C> str_; + long long value_; + }; + + template <typename C> + struct positive_integer_pimpl: virtual positive_integer_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual unsigned long long + post_positive_integer (); + + protected: + std::basic_string<C> str_; + unsigned long long value_; + }; + + template <typename C> + struct non_negative_integer_pimpl: virtual non_negative_integer_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual unsigned long long + post_non_negative_integer (); + + protected: + std::basic_string<C> str_; + unsigned long long value_; + }; + + + // Floats. + // + template <typename C> + struct float_pimpl: virtual float_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual float + post_float (); + + protected: + std::basic_string<C> str_; + float value_; + }; + + + template <typename C> + struct double_pimpl: virtual double_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual double + post_double (); + + protected: + std::basic_string<C> str_; + double value_; + }; + + + template <typename C> + struct decimal_pimpl: virtual decimal_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual double + post_decimal (); + + protected: + std::basic_string<C> str_; + double value_; + }; + + + // Strings. + // + template <typename C> + struct string_pimpl: virtual string_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual std::basic_string<C> + post_string (); + + protected: + std::basic_string<C> str_; + }; + + template <typename C> + struct normalized_string_pimpl: virtual normalized_string_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual std::basic_string<C> + post_normalized_string (); + + protected: + std::basic_string<C> str_; + }; + + template <typename C> + struct token_pimpl: virtual token_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual std::basic_string<C> + post_token (); + + protected: + std::basic_string<C> str_; + }; + + template <typename C> + struct name_pimpl: virtual name_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual std::basic_string<C> + post_name (); + + protected: + std::basic_string<C> str_; + }; + + template <typename C> + struct nmtoken_pimpl: virtual nmtoken_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual std::basic_string<C> + post_nmtoken (); + + protected: + std::basic_string<C> str_; + }; + + template <typename C> + struct nmtokens_pimpl: virtual nmtokens_pskel<C> + { + virtual void + _pre (); + + virtual void + _xsd_parse_item (const ro_string<C>&); + + virtual void + _post (); + + virtual string_sequence<C> + post_nmtokens (); + + protected: + string_sequence<C> seq_; + nmtoken_pimpl<C> parser_; + }; + + template <typename C> + struct ncname_pimpl: virtual ncname_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual std::basic_string<C> + post_ncname (); + + protected: + std::basic_string<C> str_; + }; + + template <typename C> + struct id_pimpl: virtual id_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual std::basic_string<C> + post_id (); + + protected: + std::basic_string<C> str_; + }; + + template <typename C> + struct idref_pimpl: virtual idref_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual std::basic_string<C> + post_idref (); + + protected: + std::basic_string<C> str_; + }; + + template <typename C> + struct idrefs_pimpl: virtual idrefs_pskel<C> + { + virtual void + _pre (); + + virtual void + _xsd_parse_item (const ro_string<C>&); + + virtual void + _post (); + + virtual string_sequence<C> + post_idrefs (); + + protected: + string_sequence<C> seq_; + idref_pimpl<C> parser_; + }; + + // language + // + template <typename C> + struct language_pimpl: virtual language_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual std::basic_string<C> + post_language (); + + protected: + std::basic_string<C> str_; + }; + + // anyURI + // + template <typename C> + struct uri_pimpl: virtual uri_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual std::basic_string<C> + post_uri (); + + protected: + std::basic_string<C> str_; + }; + + // QName + // + template <typename C> + struct qname_pimpl: virtual qname_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual qname<C> + post_qname (); + + protected: + std::basic_string<C> str_; + std::basic_string<C> name_; + std::basic_string<C> prefix_; + }; + + // base64Binary + // + template <typename C> + struct base64_binary_pimpl: virtual base64_binary_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual std::auto_ptr<buffer> + post_base64_binary (); + + protected: + std::basic_string<C> str_; + std::auto_ptr<buffer> buf_; + }; + + // hexBinary + // + template <typename C> + struct hex_binary_pimpl: virtual hex_binary_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual std::auto_ptr<buffer> + post_hex_binary (); + + protected: + std::basic_string<C> str_; + std::auto_ptr<buffer> buf_; + }; + + // gday + // + template <typename C> + struct gday_pimpl: virtual gday_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual gday + post_gday (); + + protected: + std::basic_string<C> str_; + unsigned short day_; + bool z_; + short zh_, zm_; + }; + + // gmonth + // + template <typename C> + struct gmonth_pimpl: virtual gmonth_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual gmonth + post_gmonth (); + + protected: + std::basic_string<C> str_; + unsigned short month_; + bool z_; + short zh_, zm_; + }; + + // gyear + // + template <typename C> + struct gyear_pimpl: virtual gyear_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual gyear + post_gyear (); + + protected: + std::basic_string<C> str_; + int year_; + bool z_; + short zh_, zm_; + }; + + // gmonth_day + // + template <typename C> + struct gmonth_day_pimpl: virtual gmonth_day_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual gmonth_day + post_gmonth_day (); + + protected: + std::basic_string<C> str_; + unsigned short month_; + unsigned short day_; + bool z_; + short zh_, zm_; + }; + + // gyear_month + // + template <typename C> + struct gyear_month_pimpl: virtual gyear_month_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual gyear_month + post_gyear_month (); + + protected: + std::basic_string<C> str_; + int year_; + unsigned short month_; + bool z_; + short zh_, zm_; + }; + + // date + // + template <typename C> + struct date_pimpl: virtual date_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual date + post_date (); + + protected: + std::basic_string<C> str_; + int year_; + unsigned short month_; + unsigned short day_; + bool z_; + short zh_, zm_; + }; + + // time + // + template <typename C> + struct time_pimpl: virtual time_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual time + post_time (); + + protected: + std::basic_string<C> str_; + unsigned short hours_; + unsigned short minutes_; + double seconds_; + bool z_; + short zh_, zm_; + }; + + // date_time + // + template <typename C> + struct date_time_pimpl: virtual date_time_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual date_time + post_date_time (); + + protected: + std::basic_string<C> str_; + int year_; + unsigned short month_; + unsigned short day_; + unsigned short hours_; + unsigned short minutes_; + double seconds_; + bool z_; + short zh_, zm_; + }; + + // duration + // + template <typename C> + struct duration_pimpl: virtual duration_pskel<C> + { + virtual void + _pre (); + + virtual void + _characters (const ro_string<C>&); + + virtual void + _post (); + + virtual duration + post_duration (); + + protected: + std::basic_string<C> str_; + bool negative_; + unsigned int years_; + unsigned int months_; + unsigned int days_; + unsigned int hours_; + unsigned int minutes_; + double seconds_; + }; + + // Literals. + // + namespace bits + { + template<typename C> + const C* + boolean (); + + template<typename C> + const C* + byte (); + + template<typename C> + const C* + unsigned_byte (); + + template<typename C> + const C* + short_ (); + + template<typename C> + const C* + unsigned_short (); + + template<typename C> + const C* + int_ (); + + template<typename C> + const C* + unsigned_int (); + + template<typename C> + const C* + long_ (); + + template<typename C> + const C* + unsigned_long (); + + template<typename C> + const C* + integer (); + + template<typename C> + const C* + negative_integer (); + + template<typename C> + const C* + non_positive_integer (); + + template<typename C> + const C* + non_negative_integer (); + + template<typename C> + const C* + positive_integer (); + + template<typename C> + const C* + float_ (); + + template<typename C> + const C* + double_ (); + + template<typename C> + const C* + decimal (); + + template<typename C> + const C* + name (); + + template<typename C> + const C* + nmtoken (); + + template<typename C> + const C* + nmtokens (); + + template<typename C> + const C* + ncname (); + + template<typename C> + const C* + id (); + + template<typename C> + const C* + idref (); + + template<typename C> + const C* + idrefs (); + + template<typename C> + const C* + language (); + + template<typename C> + const C* + qname (); + + template<typename C> + const C* + base64_binary (); + + template<typename C> + const C* + hex_binary (); + + template<typename C> + const C* + gday (); + + template<typename C> + const C* + gmonth (); + + template<typename C> + const C* + gyear (); + + template<typename C> + const C* + gmonth_day (); + + template<typename C> + const C* + gyear_month (); + + template<typename C> + const C* + date (); + + template<typename C> + const C* + time (); + + template<typename C> + const C* + date_time (); + + template<typename C> + const C* + duration (); + + // float literals: INF -INF NaN + // + template<typename C> + const C* + positive_inf (); + + template<typename C> + const C* + negative_inf (); + + template<typename C> + const C* + nan (); + + // boolean literals + // + template<typename C> + const C* + true_ (); + + template<typename C> + const C* + false_ (); + + template<typename C> + const C* + one (); + + template<typename C> + const C* + zero (); + } + } + } + } +} + +#include <xsd/cxx/parser/validating/xml-schema-pimpl.txx> + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX + +#include <xsd/cxx/parser/validating/xml-schema-pimpl.ixx> diff --git a/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.ixx b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.ixx new file mode 100644 index 0000000..c6f8127 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.ixx @@ -0,0 +1,676 @@ +// file : xsd/cxx/parser/validating/xml-schema-pimpl.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#if defined(XSD_CXX_PARSER_USE_CHAR) || !defined(XSD_CXX_PARSER_USE_WCHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_CHAR +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + namespace bits + { + template<> + inline const char* + boolean<char> () + { + return "boolean"; + } + + template<> + inline const char* + byte<char> () + { + return "byte"; + } + + template<> + inline const char* + unsigned_byte<char> () + { + return "unsignedByte"; + } + + template<> + inline const char* + short_<char> () + { + return "short"; + } + + template<> + inline const char* + unsigned_short<char> () + { + return "unsignedShort"; + } + + template<> + inline const char* + int_<char> () + { + return "int"; + } + + template<> + inline const char* + unsigned_int<char> () + { + return "unsignedInt"; + } + + template<> + inline const char* + long_<char> () + { + return "long"; + } + + template<> + inline const char* + unsigned_long<char> () + { + return "unsignedLong"; + } + + template<> + inline const char* + integer<char> () + { + return "integer"; + } + + template<> + inline const char* + negative_integer<char> () + { + return "negativeInteger"; + } + + template<> + inline const char* + non_positive_integer<char> () + { + return "nonPositiveInteger"; + } + + template<> + inline const char* + non_negative_integer<char> () + { + return "nonNegativeInteger"; + } + + template<> + inline const char* + positive_integer<char> () + { + return "positiveInteger"; + } + + template<> + inline const char* + float_<char> () + { + return "float"; + } + + template<> + inline const char* + double_<char> () + { + return "double"; + } + + template<> + inline const char* + decimal<char> () + { + return "decimal"; + } + + template<> + inline const char* + name<char> () + { + return "Name"; + } + + template<> + inline const char* + nmtoken<char> () + { + return "NMTOKEN"; + } + + template<> + inline const char* + nmtokens<char> () + { + return "NMTOKENS"; + } + + template<> + inline const char* + ncname<char> () + { + return "NCName"; + } + + template<> + inline const char* + id<char> () + { + return "ID"; + } + + template<> + inline const char* + idref<char> () + { + return "IDREF"; + } + + template<> + inline const char* + idrefs<char> () + { + return "IDREFS"; + } + + template<> + inline const char* + language<char> () + { + return "language"; + } + + template<> + inline const char* + qname<char> () + { + return "QName"; + } + + template<> + inline const char* + base64_binary<char> () + { + return "base64Binary"; + } + + template<> + inline const char* + hex_binary<char> () + { + return "hexBinary"; + } + + template<> + inline const char* + gday<char> () + { + return "gDay"; + } + + template<> + inline const char* + gmonth<char> () + { + return "gMonth"; + } + + template<> + inline const char* + gyear<char> () + { + return "gYear"; + } + + template<> + inline const char* + gmonth_day<char> () + { + return "gMonthDay"; + } + + template<> + inline const char* + gyear_month<char> () + { + return "gYearMonth"; + } + + template<> + inline const char* + date<char> () + { + return "date"; + } + + template<> + inline const char* + time<char> () + { + return "time"; + } + + template<> + inline const char* + date_time<char> () + { + return "dateTime"; + } + + template<> + inline const char* + duration<char> () + { + return "duration"; + } + + // + // + template<> + inline const char* + positive_inf<char> () + { + return "INF"; + } + + template<> + inline const char* + negative_inf<char> () + { + return "-INF"; + } + + template<> + inline const char* + nan<char> () + { + return "NaN"; + } + + // + // + template<> + inline const char* + true_<char> () + { + return "true"; + } + + template<> + inline const char* + false_<char> () + { + return "false"; + } + + template<> + inline const char* + one<char> () + { + return "1"; + } + + template<> + inline const char* + zero<char> () + { + return "0"; + } + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_CHAR +#endif // XSD_CXX_PARSER_USE_CHAR + + +#if defined(XSD_CXX_PARSER_USE_WCHAR) || !defined(XSD_CXX_PARSER_USE_CHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_WCHAR +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + namespace bits + { + template<> + inline const wchar_t* + boolean<wchar_t> () + { + return L"boolean"; + } + + template<> + inline const wchar_t* + byte<wchar_t> () + { + return L"byte"; + } + + template<> + inline const wchar_t* + unsigned_byte<wchar_t> () + { + return L"unsignedByte"; + } + + template<> + inline const wchar_t* + short_<wchar_t> () + { + return L"short"; + } + + template<> + inline const wchar_t* + unsigned_short<wchar_t> () + { + return L"unsignedShort"; + } + + template<> + inline const wchar_t* + int_<wchar_t> () + { + return L"int"; + } + + template<> + inline const wchar_t* + unsigned_int<wchar_t> () + { + return L"unsignedInt"; + } + + template<> + inline const wchar_t* + long_<wchar_t> () + { + return L"long"; + } + + template<> + inline const wchar_t* + unsigned_long<wchar_t> () + { + return L"unsignedLong"; + } + + template<> + inline const wchar_t* + integer<wchar_t> () + { + return L"integer"; + } + + template<> + inline const wchar_t* + negative_integer<wchar_t> () + { + return L"negativeInteger"; + } + + template<> + inline const wchar_t* + non_positive_integer<wchar_t> () + { + return L"nonPositiveInteger"; + } + + template<> + inline const wchar_t* + non_negative_integer<wchar_t> () + { + return L"nonNegativeInteger"; + } + + template<> + inline const wchar_t* + positive_integer<wchar_t> () + { + return L"positiveInteger"; + } + + template<> + inline const wchar_t* + float_<wchar_t> () + { + return L"float"; + } + + template<> + inline const wchar_t* + double_<wchar_t> () + { + return L"double"; + } + + template<> + inline const wchar_t* + decimal<wchar_t> () + { + return L"decimal"; + } + + template<> + inline const wchar_t* + name<wchar_t> () + { + return L"Name"; + } + + template<> + inline const wchar_t* + nmtoken<wchar_t> () + { + return L"NMTOKEN"; + } + + template<> + inline const wchar_t* + nmtokens<wchar_t> () + { + return L"NMTOKENS"; + } + + template<> + inline const wchar_t* + ncname<wchar_t> () + { + return L"NCName"; + } + + template<> + inline const wchar_t* + id<wchar_t> () + { + return L"ID"; + } + + template<> + inline const wchar_t* + idref<wchar_t> () + { + return L"IDREF"; + } + + template<> + inline const wchar_t* + idrefs<wchar_t> () + { + return L"IDREFS"; + } + + template<> + inline const wchar_t* + language<wchar_t> () + { + return L"language"; + } + + template<> + inline const wchar_t* + qname<wchar_t> () + { + return L"QName"; + } + + template<> + inline const wchar_t* + base64_binary<wchar_t> () + { + return L"base64Binary"; + } + + template<> + inline const wchar_t* + hex_binary<wchar_t> () + { + return L"hexBinary"; + } + + template<> + inline const wchar_t* + gday<wchar_t> () + { + return L"gDay"; + } + + template<> + inline const wchar_t* + gmonth<wchar_t> () + { + return L"gMonth"; + } + + template<> + inline const wchar_t* + gyear<wchar_t> () + { + return L"gYear"; + } + + template<> + inline const wchar_t* + gmonth_day<wchar_t> () + { + return L"gMonthDay"; + } + + template<> + inline const wchar_t* + gyear_month<wchar_t> () + { + return L"gYearMonth"; + } + + template<> + inline const wchar_t* + date<wchar_t> () + { + return L"date"; + } + + template<> + inline const wchar_t* + time<wchar_t> () + { + return L"time"; + } + + template<> + inline const wchar_t* + date_time<wchar_t> () + { + return L"dateTime"; + } + + template<> + inline const wchar_t* + duration<wchar_t> () + { + return L"duration"; + } + + + // + // + template<> + inline const wchar_t* + positive_inf<wchar_t> () + { + return L"INF"; + } + + template<> + inline const wchar_t* + negative_inf<wchar_t> () + { + return L"-INF"; + } + + template<> + inline const wchar_t* + nan<wchar_t> () + { + return L"NaN"; + } + + // + // + template<> + inline const wchar_t* + true_<wchar_t> () + { + return L"true"; + } + + template<> + inline const wchar_t* + false_<wchar_t> () + { + return L"false"; + } + + template<> + inline const wchar_t* + one<wchar_t> () + { + return L"1"; + } + + template<> + inline const wchar_t* + zero<wchar_t> () + { + return L"0"; + } + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_WCHAR +#endif // XSD_CXX_PARSER_USE_WCHAR diff --git a/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx new file mode 100644 index 0000000..55121c2 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx @@ -0,0 +1,2746 @@ +// file : xsd/cxx/parser/validating/xml-schema-pimpl.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <limits> +#include <locale> + +#include <xsd/cxx/zc-istream.hxx> +#include <xsd/cxx/parser/validating/exceptions.hxx> + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Note that most of the types implemented here cannot have + // whitespaces in the value. 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. + // + + // Character table. + // + namespace bits + { + const unsigned char ncname_mask = 0x1; + const unsigned char name_first_mask = 0x2; + const unsigned char name_mask = 0x4; + + template <typename C> + struct char_table + { + static C table[0x80]; + }; + + template <typename C> + C char_table<C>::table[0x80] = + { + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8, 0xD0, 0x00, 0x00, 0xD0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xD8, 0x48, 0x58, 0x48, 0x48, 0x48, 0x40, 0x58, 0x48, 0x48, 0x48, 0x48, 0x48, 0x4D, 0x4D, 0x58, + 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4E, 0x48, 0x50, 0x48, 0x58, 0x48, + 0x48, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, + 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x48, 0x48, 0x40, 0x48, 0x4F, + 0x48, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, + 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x48, 0x48, 0x48, 0x48, 0x48 + }; + } + + // any_type + // + + template <typename C> + void any_type_pimpl<C>:: + post_any_type () + { + } + + // any_simple_type + // + + template <typename C> + void any_simple_type_pimpl<C>:: + post_any_simple_type () + { + } + + // boolean + // + + template <typename C> + void boolean_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void boolean_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void boolean_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + if (str == bits::true_<C> () || str == bits::one<C> ()) + value_ = true; + else if (str == bits::false_<C> () || str == bits::zero<C> ()) + value_ = false; + else + throw invalid_value<C> (bits::boolean<C> (), str); + } + + template <typename C> + bool boolean_pimpl<C>:: + post_boolean () + { + return value_; + } + + // byte + // + + template <typename C> + void byte_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void byte_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void byte_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + short t; + zc_istream<C> is (str); + + if (is >> t && is.exhausted () && t >= -128 && t <= 127) + value_ = static_cast<signed char> (t); + else + throw invalid_value<C> (bits::byte<C> (), str); + } + + template <typename C> + signed char byte_pimpl<C>:: + post_byte () + { + return value_; + } + + // unsigned_byte + // + + template <typename C> + void unsigned_byte_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void unsigned_byte_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void unsigned_byte_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + unsigned short t; + zc_istream<C> is (str); + + if (is >> t && is.exhausted () && t <= 255) + value_ = static_cast<unsigned char> (t); + else + throw invalid_value<C> (bits::unsigned_byte<C> (), str); + } + + template <typename C> + unsigned char unsigned_byte_pimpl<C>:: + post_unsigned_byte () + { + return value_; + } + + // short + // + + template <typename C> + void short_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void short_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void short_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value<C> (bits::short_<C> (), str); + } + + template <typename C> + short short_pimpl<C>:: + post_short () + { + return value_; + } + + + // unsigned_short + // + + template <typename C> + void unsigned_short_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void unsigned_short_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void unsigned_short_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value<C> (bits::unsigned_short<C> (), str); + } + + template <typename C> + unsigned short unsigned_short_pimpl<C>:: + post_unsigned_short () + { + return value_; + } + + // int + // + + template <typename C> + void int_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void int_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void int_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value<C> (bits::int_<C> (), str); + } + + template <typename C> + int int_pimpl<C>:: + post_int () + { + return value_; + } + + + // unsigned_int + // + + template <typename C> + void unsigned_int_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void unsigned_int_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void unsigned_int_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value<C> (bits::unsigned_int<C> (), str); + } + + template <typename C> + unsigned int unsigned_int_pimpl<C>:: + post_unsigned_int () + { + return value_; + } + + + // long + // + template <typename C> + void long_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void long_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void long_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value<C> (bits::long_<C> (), str); + } + + template <typename C> + long long long_pimpl<C>:: + post_long () + { + return value_; + } + + // unsigned_long + // + template <typename C> + void unsigned_long_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void unsigned_long_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void unsigned_long_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value<C> (bits::unsigned_long<C> (), str); + } + + template <typename C> + unsigned long long unsigned_long_pimpl<C>:: + post_unsigned_long () + { + return value_; + } + + + // integer + // + template <typename C> + void integer_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void integer_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void integer_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value<C> (bits::integer<C> (), str); + } + + template <typename C> + long long integer_pimpl<C>:: + post_integer () + { + return value_; + } + + // negative_integer + // + template <typename C> + void negative_integer_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void negative_integer_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void negative_integer_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + + if (!(is >> value_ && is.exhausted () && value_ < 0)) + throw invalid_value<C> (bits::negative_integer<C> (), str); + } + + template <typename C> + long long negative_integer_pimpl<C>:: + post_negative_integer () + { + return value_; + } + + + // non_positive_integer + // + template <typename C> + void non_positive_integer_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void non_positive_integer_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void non_positive_integer_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + + if (!(is >> value_ && is.exhausted () && value_ <= 0)) + throw invalid_value<C> (bits::non_positive_integer<C> (), str); + } + + template <typename C> + long long non_positive_integer_pimpl<C>:: + post_non_positive_integer () + { + return value_; + } + + // positive_integer + // + template <typename C> + void positive_integer_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void positive_integer_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void positive_integer_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + + if (!(is >> value_ && is.exhausted () && value_ > 0)) + throw invalid_value<C> (bits::positive_integer<C> (), str); + } + + template <typename C> + unsigned long long positive_integer_pimpl<C>:: + post_positive_integer () + { + return value_; + } + + + // non_negative_integer + // + template <typename C> + void non_negative_integer_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void non_negative_integer_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void non_negative_integer_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value<C> (bits::non_negative_integer<C> (), str); + } + + template <typename C> + unsigned long long non_negative_integer_pimpl<C>:: + post_non_negative_integer () + { + return value_; + } + + + // float + // + template <typename C> + void float_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void float_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void float_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + if (str == bits::positive_inf<C> ()) + value_ = std::numeric_limits<float>::infinity (); + else if (str == bits::negative_inf<C> ()) + value_ = -std::numeric_limits<float>::infinity (); + else if (str == bits::nan<C> ()) + value_ = std::numeric_limits<float>::quiet_NaN (); + else + { + zc_istream<C> is (str); + is.imbue (std::locale::classic ()); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value<C> (bits::float_<C> (), str); + } + } + + template <typename C> + float float_pimpl<C>:: + post_float () + { + return value_; + } + + + // double + // + template <typename C> + void double_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void double_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void double_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + if (str == bits::positive_inf<C> ()) + value_ = std::numeric_limits<double>::infinity (); + else if (str == bits::negative_inf<C> ()) + value_ = -std::numeric_limits<double>::infinity (); + else if (str == bits::nan<C> ()) + value_ = std::numeric_limits<double>::quiet_NaN (); + else + { + zc_istream<C> is (str); + is.imbue (std::locale::classic ()); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value<C> (bits::double_<C> (), str); + } + } + + template <typename C> + double double_pimpl<C>:: + post_double () + { + return value_; + } + + // decimal + // + template <typename C> + void decimal_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void decimal_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + void decimal_pimpl<C>:: + _post () + { + ro_string<C> str (str_); + trim (str); + + zc_istream<C> is (str); + is.imbue (std::locale::classic ()); + + //@@ TODO: now we accept scientific notations and INF/NaN. + // + if (!(is >> value_ && is.exhausted ())) + throw invalid_value<C> (bits::decimal<C> (), str); + } + + template <typename C> + double decimal_pimpl<C>:: + post_decimal () + { + return value_; + } + + // string + // + template <typename C> + void string_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void string_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + std::basic_string<C> string_pimpl<C>:: + post_string () + { + std::basic_string<C> r; + r.swap (str_); + return r; + } + + // normalized_string + // + template <typename C> + void normalized_string_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void normalized_string_pimpl<C>:: + _characters (const ro_string<C>& s) + { + str_ += s; + } + + template <typename C> + std::basic_string<C> normalized_string_pimpl<C>:: + post_normalized_string () + { + typedef typename std::basic_string<C>::size_type size_type; + + size_type size (str_.size ()); + + for (size_type i (0); i < size; ++i) + { + C& c = str_[i]; + + if (c == C (0x0A) || c == C (0x0D) || c == C (0x09)) + c = C (0x20); + } + + std::basic_string<C> r; + r.swap (str_); + return r; + } + + // token + // + template <typename C> + void token_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void token_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + std::basic_string<C> token_pimpl<C>:: + post_token () + { + typedef typename std::basic_string<C>::size_type size_type; + + size_type size (str_.size ()); + size_type j (0); + + bool subs (false); + + for (size_type i (0); i < size; ++i) + { + C c = str_[i]; + + if (c == C (0x20) || c == C (0x0A) || + c == C (0x0D) || c == C (0x09)) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + str_[j++] = C (0x20); + } + + str_[j++] = c; + } + } + + str_.resize (j); + + std::basic_string<C> r; + r.swap (str_); + return r; + } + + // name + // + template <typename C> + void name_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void name_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void name_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + + // For now we are only checking the US-ASCII characters. + // + + bool ok (size != 0); + + if (ok) + { + unsigned int c (static_cast<unsigned int> (str_[0])); + + ok = c >= 0x80 || + (bits::char_table<unsigned char>::table[c] & + bits::name_first_mask); + + if (ok) + { + for (size_type i (1); i < size; ++i) + { + c = static_cast<unsigned int> (str_[i]); + + if (c < 0x80 && + !(bits::char_table<unsigned char>::table[c] & + bits::name_mask)) + { + ok = false; + break; + } + } + } + } + + if (!ok) + throw invalid_value<C> (bits::name<C> (), tmp); + + str_.resize (size); + } + + template <typename C> + std::basic_string<C> name_pimpl<C>:: + post_name () + { + std::basic_string<C> r; + r.swap (str_); + return r; + } + + // nmtoken + // + template <typename C> + void nmtoken_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void nmtoken_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void nmtoken_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + + // For now we are only checking the US-ASCII characters. + // + + bool ok (size != 0); + + if (ok) + { + for (size_type i (0); i < size; ++i) + { + unsigned int c (static_cast<unsigned int> (str_[i])); + + if (c < 0x80 && + !(bits::char_table<unsigned char>::table[c] & + bits::name_mask)) + { + ok = false; + break; + } + } + } + + if (!ok) + throw invalid_value<C> (bits::nmtoken<C> (), tmp); + + str_.resize (size); + } + + template <typename C> + std::basic_string<C> nmtoken_pimpl<C>:: + post_nmtoken () + { + std::basic_string<C> r; + r.swap (str_); + return r; + } + + // nmtokens + // + template <typename C> + void nmtokens_pimpl<C>:: + _pre () + { + nmtokens_pskel<C>::_pre (); + seq_.clear (); + } + + template <typename C> + void nmtokens_pimpl<C>:: + _post () + { + nmtokens_pskel<C>::_post (); + + // Should have at least one element. + // + if (seq_.size () < 1) + { + ro_string<C> tmp; + throw invalid_value<C> (bits::nmtokens<C> (), tmp); + } + } + + template <typename C> + string_sequence<C> nmtokens_pimpl<C>:: + post_nmtokens () + { + string_sequence<C> r; + r.swap (seq_); + return r; + } + + template <typename C> + void nmtokens_pimpl<C>:: + _xsd_parse_item (const ro_string<C>& s) + { + parser_.pre (); + parser_._pre (); + parser_._characters (s); + parser_._post (); + seq_.push_back (parser_.post_nmtoken ()); + } + + // ncname + // + namespace bits + { + template <typename C> + bool + valid_ncname (const C* s, typename ro_string<C>::size_type size) + { + typedef typename ro_string<C>::size_type size_type; + + // For now we are only checking the US-ASCII characters. + // + bool ok (size != 0); + + if (ok) + { + unsigned int c (static_cast<unsigned int> (s[0])); + + ok = c >= 0x80 || + ((bits::char_table<unsigned char>::table[c] & + bits::name_first_mask) && c != C (':')); + + if (ok) + { + for (size_type i (1); i < size; ++i) + { + c = static_cast<unsigned int> (s[i]); + + if (c < 0x80 && + !(bits::char_table<unsigned char>::table[c] & + bits::ncname_mask)) + { + ok = false; + break; + } + } + } + } + + return ok; + } + } + + template <typename C> + void ncname_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void ncname_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void ncname_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + + if (!bits::valid_ncname (tmp.data (), size)) + throw invalid_value<C> (bits::ncname<C> (), tmp); + + str_.resize (size); + } + + template <typename C> + std::basic_string<C> ncname_pimpl<C>:: + post_ncname () + { + std::basic_string<C> r; + r.swap (str_); + return r; + } + + // id + // + template <typename C> + void id_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void id_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void id_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + + if (!bits::valid_ncname (tmp.data (), size)) + throw invalid_value<C> (bits::id<C> (), tmp); + + str_.resize (size); + } + + template <typename C> + std::basic_string<C> id_pimpl<C>:: + post_id () + { + std::basic_string<C> r; + r.swap (str_); + return r; + } + + // idref + // + template <typename C> + void idref_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void idref_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void idref_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + + if (!bits::valid_ncname (tmp.data (), size)) + throw invalid_value<C> (bits::idref<C> (), tmp); + + str_.resize (size); + } + + template <typename C> + std::basic_string<C> idref_pimpl<C>:: + post_idref () + { + std::basic_string<C> r; + r.swap (str_); + return r; + } + + // idrefs + // + template <typename C> + void idrefs_pimpl<C>:: + _pre () + { + idrefs_pskel<C>::_pre (); + seq_.clear (); + } + + template <typename C> + void idrefs_pimpl<C>:: + _post () + { + idrefs_pskel<C>::_post (); + + // Should have at least one element. + // + if (seq_.size () < 1) + { + ro_string<C> tmp; + throw invalid_value<C> (bits::idrefs<C> (), tmp); + } + } + + template <typename C> + string_sequence<C> idrefs_pimpl<C>:: + post_idrefs () + { + string_sequence<C> r; + r.swap (seq_); + return r; + } + + template <typename C> + void idrefs_pimpl<C>:: + _xsd_parse_item (const ro_string<C>& s) + { + parser_.pre (); + parser_._pre (); + parser_._characters (s); + parser_._post (); + seq_.push_back (parser_.post_idref ()); + } + + // language + // + template <typename C> + void language_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void language_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void language_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + + // language := ALPHA{1,8} *(-(ALPHA | DIGIT){1,8}) + // + bool ok (true); + + for (size_type tag (0), i (0); ; ++tag) + { + size_type n (0); + + for (; i < size && n < 8; ++n, ++i) + { + C c (tmp[i]); + + if (!((c >= C ('a') && c <= C ('z')) || + (c >= C ('A') && c <= C ('Z')) || + (tag != 0 && c >= C ('0') && c <= C ('9')))) + break; + } + + if (n == 0) + { + ok = false; + break; + } + + if (i == size) + break; + + if (tmp[i++] != C ('-')) + { + ok = false; + break; + } + } + + if (!ok) + throw invalid_value<C> (bits::language<C> (), tmp); + + str_.resize (size); + } + + template <typename C> + std::basic_string<C> language_pimpl<C>:: + post_language () + { + std::basic_string<C> r; + r.swap (str_); + return r; + } + + // uri + // + template <typename C> + void uri_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void uri_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + std::basic_string<C> uri_pimpl<C>:: + post_uri () + { + // According to Datatypes 3.2.17 and RFC2396 pretty much anything + // can be a URI and conforming processors do not need to figure + // out and verify particular URI schemes. + // + ro_string<C> tmp (str_); + str_.resize (trim_right (tmp)); + + std::basic_string<C> r; + r.swap (str_); + return r; + } + + // qname + // + template <typename C> + void qname_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void qname_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void qname_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + size_type pos (tmp.find (C (':'))); + + const C* s (tmp.data ()); + + if (pos != ro_string<C>::npos) + { + if (!bits::valid_ncname (s, pos) || + !bits::valid_ncname (s + pos + 1, size - pos - 1)) + throw invalid_value<C> (bits::qname<C> (), tmp); + + prefix_.assign (s, pos); + name_.assign (s + pos + 1, size - pos - 1); + } + else + { + if (!bits::valid_ncname (s, size)) + throw invalid_value<C> (bits::qname<C> (), tmp); + + prefix_.clear (); + str_.resize (size); + name_.swap (str_); + } + } + + template <typename C> + qname<C> qname_pimpl<C>:: + post_qname () + { + return prefix_.empty () + ? qname<C> (name_) + : qname<C> (prefix_, name_); + } + + // base64_binary + // + template <typename C> + void base64_binary_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void base64_binary_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template <typename C> + inline unsigned char + base64_decode (C c) + { + unsigned char r (0xFF); + + if (c >= C('A') && c <= C ('Z')) + r = static_cast<unsigned char> (c - C ('A')); + else if (c >= C('a') && c <= C ('z')) + r = static_cast<unsigned char> (c - C ('a') + 26); + else if (c >= C('0') && c <= C ('9')) + r = static_cast<unsigned char> (c - C ('0') + 52); + else if (c == C ('+')) + r = 62; + else if (c == C ('/')) + r = 63; + + return r; + } + } + + template <typename C> + void base64_binary_pimpl<C>:: + _post () + { + typedef typename std::basic_string<C>::size_type size_type; + + size_type size (str_.size ()); + const C* src (str_.c_str ()); + + // Remove all whitespaces. + // + { + size_type j (0); + + bool subs (false); + + for (size_type i (0); i < size; ++i) + { + C c = str_[i]; + + if (c == C (0x20) || c == C (0x0A) || + c == C (0x0D) || c == C (0x09)) + { + subs = true; + } + else + { + if (subs) + subs = false; + + str_[j++] = c; + } + } + + size = j; + str_.resize (size); + } + + // Our length should be a multiple of four. + // + if (size == 0 || size % 4 != 0) + throw invalid_value<C> (bits::base64_binary<C> (), str_); + + size_type quad_count (size / 4); + size_type capacity (quad_count * 3 + 1); + + buf_.reset (new buffer (capacity, capacity)); + char* dst (buf_->data ()); + + size_type si (0), di (0); // Source and destination indexes. + + // Process all quads except the last one. + // + unsigned char b1, b2, b3, b4; + + for (size_type q (0); q < quad_count - 1; ++q) + { + b1 = bits::base64_decode (src[si++]); + b2 = bits::base64_decode (src[si++]); + b3 = bits::base64_decode (src[si++]); + b4 = bits::base64_decode (src[si++]); + + if (b1 == 0xFF || b2 == 0xFF || b3 == 0xFF || b4 == 0xFF) + throw invalid_value<C> (bits::base64_binary<C> (), str_); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Process the last quad. The first two octets are always there. + // + b1 = bits::base64_decode (src[si++]); + b2 = bits::base64_decode (src[si++]); + + if (b1 == 0xFF || b2 == 0xFF) + throw invalid_value<C> (bits::base64_binary<C> (), str_); + + C e3 (src[si++]); + C e4 (src[si++]); + + if (e4 == C ('=')) + { + if (e3 == C ('=')) + { + // Two pads. Last 4 bits in b2 should be zero. + // + if ((b2 & 0x0F) != 0) + throw invalid_value<C> (bits::base64_binary<C> (), str_); + + dst[di++] = (b1 << 2) | (b2 >> 4); + } + else + { + // One pad. Last 2 bits in b3 should be zero. + // + b3 = bits::base64_decode (e3); + + if (b3 == 0xFF || (b3 & 0x03) != 0) + throw invalid_value<C> (bits::base64_binary<C> (), str_); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + } + } + else + { + // No pads. + // + b3 = bits::base64_decode (e3); + b4 = bits::base64_decode (e4); + + if (b3 == 0xFF || b4 == 0xFF) + throw invalid_value<C> (bits::base64_binary<C> (), str_); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Set the real size. + // + buf_->size (di); + } + + template <typename C> + std::auto_ptr<buffer> base64_binary_pimpl<C>:: + post_base64_binary () + { + return buf_; + } + + // hex_binary + // + template <typename C> + void hex_binary_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void hex_binary_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template <typename C> + inline unsigned char + hex_decode (C c) + { + unsigned char r (0xFF); + + if (c >= C('0') && c <= C ('9')) + r = static_cast<unsigned char> (c - C ('0')); + else if (c >= C ('A') && c <= C ('F')) + r = static_cast<unsigned char> (10 + (c - C ('A'))); + else if (c >= C ('a') && c <= C ('f')) + r = static_cast<unsigned char> (10 + (c - C ('a'))); + + return r; + } + } + + template <typename C> + void hex_binary_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + + if (size % 2 != 0) + throw invalid_value<C> (bits::hex_binary<C> (), tmp); + + buffer::size_t n (size / 2); + buf_.reset (new buffer (n)); + + if (n != 0) + { + const C* src (tmp.data ()); + char* dst (buf_->data ()); + buffer::size_t i (0); + + for (; i < n; ++i) + { + unsigned char h (bits::hex_decode (src[2 * i])); + unsigned char l (bits::hex_decode (src[2 * i + 1])); + + if (h == 0xFF || l == 0xFF) + break; + + dst[i] = (h << 4) | l; + } + + if (i != n) + throw invalid_value<C> (bits::hex_binary<C> (), tmp); + } + } + + template <typename C> + std::auto_ptr<buffer> hex_binary_pimpl<C>:: + post_hex_binary () + { + return buf_; + } + + // time_zone + // + namespace bits + { + // Datatypes 3.2.7.3. Return false if time zone is invalid. + // + template <typename C> + bool + parse_tz (const C* s, + typename std::basic_string<C>::size_type n, + short& h, short& m) + { + // time_zone := Z|(+|-)HH:MM + // + if (n == 0) + { + return false; + } + else if (s[0] == 'Z') + { + if (n != 1) + return false; + + h = 0; + m = 0; + } + else + { + if (n != 6 || (s[0] != '-' && s[0] != '+') || s[3] != ':') + return false; + + // Parse hours. + // + char d1 = s[1]; + char d2 = s[2]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + return false; + + h = 10 * (d1 - '0') + (d2 - '0'); + + if (h > 14) + return false; + + // Parse minutes. + // + d1 = s[4]; + d2 = s[5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + return false; + + m = 10 * (d1 - '0') + (d2 - '0'); + + if (m > 59 || (h == 14 && m != 0)) + return false; + + if (s[0] == '-') + { + h = -h; + m = -m; + } + } + + return true; + } + } + + // gday + // + template <typename C> + void gday_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void gday_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void gday_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // gday := ---DD[Z|(+|-)HH:MM] + // + if (size < 5 || + s[0] != C ('-') || s[1] != C ('-') || s[2] != C ('-')) + throw invalid_value<C> (bits::gday<C> (), tmp); + + C d1 (s[3]), d2 (s[4]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::gday<C> (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value<C> (bits::gday<C> (), tmp); + + if (size > 5) + { + if (!bits::parse_tz (s + 5, size - 5, zh_, zm_)) + throw invalid_value<C> (bits::gday<C> (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template <typename C> + gday gday_pimpl<C>:: + post_gday () + { + return z_ ? gday (day_, zh_, zm_) : gday (day_); + } + + // gmonth + // + template <typename C> + void gmonth_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void gmonth_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void gmonth_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // gmonth := --MM[Z|(+|-)HH:MM] + // + if (size < 4 || s[0] != C ('-') || s[1] != C ('-')) + throw invalid_value<C> (bits::gmonth<C> (), tmp); + + C d1 (s[2]), d2 (s[3]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::gmonth<C> (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value<C> (bits::gmonth<C> (), tmp); + + if (size > 4) + { + if (!bits::parse_tz (s + 4, size - 4, zh_, zm_)) + throw invalid_value<C> (bits::gmonth<C> (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template <typename C> + gmonth gmonth_pimpl<C>:: + post_gmonth () + { + return z_ ? gmonth (month_, zh_, zm_) : gmonth (month_); + } + + // gyear + // + template <typename C> + void gyear_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void gyear_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void gyear_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // gyear := [-]CCYY[N]*[Z|(+|-)HH:MM] + // + + if (size < 4 || (s[0] == C ('-') && size < 5)) + throw invalid_value<C> (bits::gyear<C> (), tmp); + + // Find the end of the year token. + // + size_type pos (s[0] == C ('-') ? 5 : 4); + for (; pos < size; ++pos) + { + C c (s[pos]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + ro_string<C> year_fragment (s, pos); + zc_istream<C> is (year_fragment); + + if (!(is >> year_ && is.exhausted () && year_ != 0)) + throw invalid_value<C> (bits::gyear<C> (), tmp); + + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value<C> (bits::gyear<C> (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template <typename C> + gyear gyear_pimpl<C>:: + post_gyear () + { + return z_ ? gyear (year_, zh_, zm_) : gyear (year_); + } + + // gmonth_day + // + template <typename C> + void gmonth_day_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void gmonth_day_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void gmonth_day_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // gmonth_day := --MM-DD[Z|(+|-)HH:MM] + // + if (size < 7 || + s[0] != C ('-') || s[1] != C ('-') || s[4] != C ('-')) + throw invalid_value<C> (bits::gmonth_day<C> (), tmp); + + // month + // + C d1 (s[2]), d2 (s[3]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::gmonth_day<C> (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value<C> (bits::gmonth_day<C> (), tmp); + + // day + // + d1 = s[5]; + d2 = s[6]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::gmonth_day<C> (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value<C> (bits::gmonth_day<C> (), tmp); + + // zone + // + if (size > 7) + { + if (!bits::parse_tz (s + 7, size - 7, zh_, zm_)) + throw invalid_value<C> (bits::gmonth_day<C> (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template <typename C> + gmonth_day gmonth_day_pimpl<C>:: + post_gmonth_day () + { + return z_ + ? gmonth_day (month_, day_, zh_, zm_) + : gmonth_day (month_, day_); + } + + // gyear_month + // + template <typename C> + void gyear_month_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void gyear_month_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void gyear_month_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // gyear_month := [-]CCYY[N]*-MM[Z|(+|-)HH:MM] + // + + if (size < 7 || (s[0] == C ('-') && size < 8)) + throw invalid_value<C> (bits::gyear_month<C> (), tmp); + + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), s[0] == C ('-') ? 5 : 4)); + + if (pos == ro_string<C>::npos || (size - pos - 1) < 2) + throw invalid_value<C> (bits::gyear_month<C> (), tmp); + + ro_string<C> year_fragment (s, pos); + zc_istream<C> yis (year_fragment); + + if (!(yis >> year_ && yis.exhausted () && year_ != 0)) + throw invalid_value<C> (bits::gyear_month<C> (), tmp); + + // month + // + C d1 (s[pos + 1]), d2 (s[pos + 2]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::gyear_month<C> (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value<C> (bits::gyear_month<C> (), tmp); + + // zone + // + pos += 3; + + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value<C> (bits::gyear_month<C> (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template <typename C> + gyear_month gyear_month_pimpl<C>:: + post_gyear_month () + { + return z_ + ? gyear_month (year_, month_, zh_, zm_) + : gyear_month (year_, month_); + } + + // date + // + template <typename C> + void date_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void date_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void date_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // date := [-]CCYY[N]*-MM-DD[Z|(+|-)HH:MM] + // + + if (size < 10 || (s[0] == C ('-') && size < 11)) + throw invalid_value<C> (bits::date<C> (), tmp); + + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), s[0] == C ('-') ? 5 : 4)); + + if (pos == ro_string<C>::npos + || (size - pos - 1) < 5 + || s[pos + 3] != C ('-')) + throw invalid_value<C> (bits::date<C> (), tmp); + + ro_string<C> year_fragment (s, pos); + zc_istream<C> yis (year_fragment); + + if (!(yis >> year_ && yis.exhausted () && year_ != 0)) + throw invalid_value<C> (bits::date<C> (), tmp); + + // month + // + C d1 (s[pos + 1]), d2 (s[pos + 2]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::date<C> (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value<C> (bits::date<C> (), tmp); + + // day + // + d1 = s[pos + 4]; + d2 = s[pos + 5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::date<C> (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value<C> (bits::date<C> (), tmp); + + // zone + // + pos += 6; + + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value<C> (bits::date<C> (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template <typename C> + date date_pimpl<C>:: + post_date () + { + return z_ + ? date (year_, month_, day_, zh_, zm_) + : date (year_, month_, day_); + } + + // time + // + template <typename C> + void time_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void time_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void time_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // time := HH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (size < 8 || s[2] != C (':') || s[5] != C (':')) + throw invalid_value<C> (bits::time<C> (), tmp); + + // hours + // + C d1 (s[0]), d2 (s[1]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::time<C> (), tmp); + + hours_ = 10 * (d1 - '0') + (d2 - '0'); + + if (hours_ > 24) + throw invalid_value<C> (bits::time<C> (), tmp); + + // minutes + // + d1 = s[3]; + d2 = s[4]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::time<C> (), tmp); + + minutes_ = 10 * (d1 - '0') + (d2 - '0'); + + if (minutes_ > 59) + throw invalid_value<C> (bits::time<C> (), tmp); + + // Find the end of the seconds fragment. + // + size_type pos (8); + for (; pos < size; ++pos) + { + C c (s[pos]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + // At least one digit should follow the fraction point. + // + if ((pos - 6) == 3) + throw invalid_value<C> (bits::time<C> (), tmp); + + ro_string<C> seconds_fragment (s + 6, pos - 6); + zc_istream<C> sis (seconds_fragment); + + if (!(sis >> seconds_ && sis.exhausted () && seconds_ < 60.0)) + throw invalid_value<C> (bits::time<C> (), tmp); + + if (hours_ == 24 && (minutes_ != 0 || seconds_ != 0.0)) + throw invalid_value<C> (bits::time<C> (), tmp); + + // zone + // + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value<C> (bits::time<C> (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template <typename C> + time time_pimpl<C>:: + post_time () + { + return z_ + ? time (hours_, minutes_, seconds_, zh_, zm_) + : time (hours_, minutes_, seconds_); + } + + + // date_time + // + template <typename C> + void date_time_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void date_time_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template <typename C> + void date_time_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + const C* s (tmp.data ()); + + // date_time := [-]CCYY[N]*-MM-DDTHH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (size < 19 || (s[0] == C ('-') && size < 20)) + throw invalid_value<C> (bits::date_time<C> (), tmp); + + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), s[0] == C ('-') ? 5 : 4)); + + if (pos == ro_string<C>::npos || (size - pos - 1) < 14 + || s[pos + 3] != C ('-') || s[pos + 6] != C ('T') + || s[pos + 9] != C (':') || s[pos + 12] != C (':')) + throw invalid_value<C> (bits::date_time<C> (), tmp); + + // year + // + ro_string<C> year_fragment (s, pos); + zc_istream<C> yis (year_fragment); + + if (!(yis >> year_ && yis.exhausted () && year_ != 0)) + throw invalid_value<C> (bits::date_time<C> (), tmp); + + // month + // + C d1 (s[pos + 1]), d2 (s[pos + 2]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::date_time<C> (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value<C> (bits::date_time<C> (), tmp); + + // day + // + d1 = s[pos + 4]; + d2 = s[pos + 5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::date_time<C> (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value<C> (bits::date_time<C> (), tmp); + + pos += 7; // Point to the first H. + + // hours + // + d1 = s[pos]; + d2 = s[pos + 1]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::date_time<C> (), tmp); + + hours_ = 10 * (d1 - '0') + (d2 - '0'); + + if (hours_ > 24) + throw invalid_value<C> (bits::date_time<C> (), tmp); + + // minutes + // + d1 = s[pos + 3]; + d2 = s[pos + 4]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value<C> (bits::date_time<C> (), tmp); + + minutes_ = 10 * (d1 - '0') + (d2 - '0'); + + if (minutes_ > 59) + throw invalid_value<C> (bits::date_time<C> (), tmp); + + // Find the end of the seconds fragment. + // + pos += 6; // Point to the first S. + + size_type sec_end (pos + 2); + for (; sec_end < size; ++sec_end) + { + C c (s[sec_end]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + // At least one digit should should follow the fraction point. + // + if ((sec_end - pos) == 3) + throw invalid_value<C> (bits::date_time<C> (), tmp); + + ro_string<C> seconds_fragment (s + pos, sec_end - pos); + zc_istream<C> sis (seconds_fragment); + + if (!(sis >> seconds_ && sis.exhausted () && seconds_ < 60.0)) + throw invalid_value<C> (bits::date_time<C> (), tmp); + + if (hours_ == 24 && (minutes_ != 0 || seconds_ != 0.0)) + throw invalid_value<C> (bits::date_time<C> (), tmp); + + // zone + // + if (sec_end < size) + { + if (!bits::parse_tz (s + sec_end, size - sec_end, zh_, zm_)) + throw invalid_value<C> (bits::date_time<C> (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template <typename C> + date_time date_time_pimpl<C>:: + post_date_time () + { + return z_ + ? date_time (year_, month_, day_, hours_, minutes_, seconds_, + zh_, zm_) + : date_time (year_, month_, day_, hours_, minutes_, seconds_); + } + + // duration + // + template <typename C> + void duration_pimpl<C>:: + _pre () + { + str_.clear (); + } + + template <typename C> + void duration_pimpl<C>:: + _characters (const ro_string<C>& s) + { + if (str_.size () == 0) + { + ro_string<C> tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template <typename C> + inline typename ro_string<C>::size_type + duration_delim (const C* s, + typename ro_string<C>::size_type pos, + typename ro_string<C>::size_type size) + { + const C* p (s + pos); + for (; p < (s + size); ++p) + { + if (*p == C ('Y') || *p == C ('D') || *p == C ('M') || + *p == C ('H') || *p == C ('M') || *p == C ('S') || + *p == C ('T')) + break; + } + + return p - s; + } + } + + template <typename C> + void duration_pimpl<C>:: + _post () + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str_); + size_type size (trim_right (tmp)); + + negative_ = false; + years_ = 0; + months_ = 0; + days_ = 0; + hours_ = 0; + minutes_ = 0; + seconds_ = 0.0; + + // duration := [-]P[nY][nM][nD][TnHnMn[.n+]S] + // + const C* s (tmp.data ()); + + if (size < 3 || (s[0] == C ('-') && size < 4)) + throw invalid_value<C> (bits::duration<C> (), tmp); + + size_type pos (0); + + if (s[0] == C ('-')) + { + negative_ = true; + pos++; + } + + if (s[pos++] != C ('P')) + throw invalid_value<C> (bits::duration<C> (), tmp); + + size_type del (bits::duration_delim (s, pos, size)); + + // Duration should contain at least one component. + // + if (del == size) + throw invalid_value<C> (bits::duration<C> (), tmp); + + if (s[del] == C ('Y')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + + if (!(is >> years_ && is.exhausted ())) + throw invalid_value<C> (bits::duration<C> (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('M')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + + if (!(is >> months_ && is.exhausted ())) + throw invalid_value<C> (bits::duration<C> (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('D')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + + if (!(is >> days_ && is.exhausted ())) + throw invalid_value<C> (bits::duration<C> (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('T')) + { + pos = del + 1; + del = bits::duration_delim (s, pos, size); + + // At least one time component should be present. + // + if (del == size) + throw invalid_value<C> (bits::duration<C> (), tmp); + + if (s[del] == C ('H')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + + if (!(is >> hours_ && is.exhausted ())) + throw invalid_value<C> (bits::duration<C> (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('M')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + + if (!(is >> minutes_ && is.exhausted ())) + throw invalid_value<C> (bits::duration<C> (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('S')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + + if (!(is >> seconds_ && is.exhausted () && seconds_ >= 0.0)) + throw invalid_value<C> (bits::duration<C> (), tmp); + + pos = del + 1; + } + } + + // Something did not match or appeared in the wrong order. + // + if (pos != size) + throw invalid_value<C> (bits::duration<C> (), tmp); + } + + template <typename C> + duration duration_pimpl<C>:: + post_duration () + { + return duration ( + negative_, years_, months_, days_, hours_, minutes_, seconds_); + } + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx new file mode 100644 index 0000000..67c8057 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx @@ -0,0 +1,647 @@ +// file : xsd/cxx/parser/validating/xml-schema-pskel.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX + +#include <string> +#include <memory> // auto_ptr + +#include <xsd/cxx/parser/xml-schema.hxx> +#include <xsd/cxx/parser/validating/parser.hxx> + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // anyType and anySimpleType. All events are routed to the + // _any_* callbacks. + // + template <typename C> + struct any_type_pskel: complex_content<C> + { + virtual bool + _start_element_impl (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>*); + + virtual bool + _end_element_impl (const ro_string<C>&, + const ro_string<C>&); + + virtual bool + _attribute_impl_phase_two (const ro_string<C>&, + const ro_string<C>&, + const ro_string<C>&); + + virtual bool + _characters_impl (const ro_string<C>&); + + virtual void + post_any_type () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct any_simple_type_pskel: simple_content<C> + { + virtual bool + _characters_impl (const ro_string<C>&); + + virtual void + post_any_simple_type () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Boolean. + // + template <typename C> + struct boolean_pskel: simple_content<C> + { + virtual bool + post_boolean () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 8-bit + // + template <typename C> + struct byte_pskel: simple_content<C> + { + virtual signed char + post_byte () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct unsigned_byte_pskel: simple_content<C> + { + virtual unsigned char + post_unsigned_byte () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 16-bit + // + template <typename C> + struct short_pskel: simple_content<C> + { + virtual short + post_short () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct unsigned_short_pskel: simple_content<C> + { + virtual unsigned short + post_unsigned_short () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 32-bit + // + template <typename C> + struct int_pskel: simple_content<C> + { + virtual int + post_int () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct unsigned_int_pskel: simple_content<C> + { + virtual unsigned int + post_unsigned_int () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 64-bit + // + template <typename C> + struct long_pskel: simple_content<C> + { + virtual long long + post_long () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct unsigned_long_pskel: simple_content<C> + { + virtual unsigned long long + post_unsigned_long () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Arbitrary-length integers. + // + template <typename C> + struct integer_pskel: simple_content<C> + { + virtual long long + post_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct negative_integer_pskel: simple_content<C> + { + virtual long long + post_negative_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct non_positive_integer_pskel: simple_content<C> + { + virtual long long + post_non_positive_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct positive_integer_pskel: simple_content<C> + { + virtual unsigned long long + post_positive_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct non_negative_integer_pskel: simple_content<C> + { + virtual unsigned long long + post_non_negative_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Floats. + // + template <typename C> + struct float_pskel: simple_content<C> + { + virtual float + post_float () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct double_pskel: simple_content<C> + { + virtual double + post_double () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct decimal_pskel: simple_content<C> + { + virtual double + post_decimal () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Strings. + // + template <typename C> + struct string_pskel: simple_content<C> + { + virtual std::basic_string<C> + post_string () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct normalized_string_pskel: simple_content<C> + { + virtual std::basic_string<C> + post_normalized_string () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct token_pskel: simple_content<C> + { + virtual std::basic_string<C> + post_token () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct name_pskel: simple_content<C> + { + virtual std::basic_string<C> + post_name () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct nmtoken_pskel: simple_content<C> + { + virtual std::basic_string<C> + post_nmtoken () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct nmtokens_pskel: list_base<C> + { + virtual string_sequence<C> + post_nmtokens () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct ncname_pskel: simple_content<C> + { + virtual std::basic_string<C> + post_ncname () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct id_pskel: simple_content<C> + { + virtual std::basic_string<C> + post_id () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct idref_pskel: simple_content<C> + { + virtual std::basic_string<C> + post_idref () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct idrefs_pskel: list_base<C> + { + virtual string_sequence<C> + post_idrefs () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Language. + // + template <typename C> + struct language_pskel: simple_content<C> + { + virtual std::basic_string<C> + post_language () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // URI. + // + template <typename C> + struct uri_pskel: simple_content<C> + { + virtual std::basic_string<C> + post_uri () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // QName. + // + template <typename C> + struct qname_pskel: simple_content<C> + { + virtual qname<C> + post_qname () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Base64 and hex binaries. + // + template <typename C> + struct base64_binary_pskel: simple_content<C> + { + virtual std::auto_ptr<buffer> + post_base64_binary () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct hex_binary_pskel: simple_content<C> + { + virtual std::auto_ptr<buffer> + post_hex_binary () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Time and date types. + // + template <typename C> + struct gday_pskel: simple_content<C> + { + virtual gday + post_gday () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct gmonth_pskel: simple_content<C> + { + virtual gmonth + post_gmonth () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct gyear_pskel: simple_content<C> + { + virtual gyear + post_gyear () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct gmonth_day_pskel: simple_content<C> + { + virtual gmonth_day + post_gmonth_day () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct gyear_month_pskel: simple_content<C> + { + virtual gyear_month + post_gyear_month () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct date_pskel: simple_content<C> + { + virtual date + post_date () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct time_pskel: simple_content<C> + { + virtual time + post_time () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct date_time_pskel: simple_content<C> + { + virtual date_time + post_date_time () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template <typename C> + struct duration_pskel: simple_content<C> + { + virtual duration + post_duration () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + } + } + } +} + +#include <xsd/cxx/parser/validating/xml-schema-pskel.txx> + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX + +#include <xsd/cxx/parser/validating/xml-schema-pskel.ixx> diff --git a/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.ixx b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.ixx new file mode 100644 index 0000000..6958bea --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.ixx @@ -0,0 +1,1249 @@ +// file : xsd/cxx/parser/validating/xml-schema-pskel.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#if defined(XSD_CXX_PARSER_USE_CHAR) || !defined(XSD_CXX_PARSER_USE_WCHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_CHAR +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + template<> + inline const char* any_type_pskel<char>:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* any_type_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* any_simple_type_pskel<char>:: + _static_type () + { + return "anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* any_simple_type_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* boolean_pskel<char>:: + _static_type () + { + return "boolean http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* boolean_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* byte_pskel<char>:: + _static_type () + { + return "byte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* byte_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_byte_pskel<char>:: + _static_type () + { + return "unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_byte_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* short_pskel<char>:: + _static_type () + { + return "short http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* short_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_short_pskel<char>:: + _static_type () + { + return "unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_short_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* int_pskel<char>:: + _static_type () + { + return "int http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* int_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_int_pskel<char>:: + _static_type () + { + return "unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_int_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* long_pskel<char>:: + _static_type () + { + return "long http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* long_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_long_pskel<char>:: + _static_type () + { + return "unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_long_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* integer_pskel<char>:: + _static_type () + { + return "integer http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* integer_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* negative_integer_pskel<char>:: + _static_type () + { + return "negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* negative_integer_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* non_positive_integer_pskel<char>:: + _static_type () + { + return "nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* non_positive_integer_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* positive_integer_pskel<char>:: + _static_type () + { + return "positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* positive_integer_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* non_negative_integer_pskel<char>:: + _static_type () + { + return "nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* non_negative_integer_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* float_pskel<char>:: + _static_type () + { + return "float http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* float_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* double_pskel<char>:: + _static_type () + { + return "double http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* double_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* decimal_pskel<char>:: + _static_type () + { + return "decimal http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* decimal_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* string_pskel<char>:: + _static_type () + { + return "string http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* string_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* normalized_string_pskel<char>:: + _static_type () + { + return "normalizedString http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* normalized_string_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* token_pskel<char>:: + _static_type () + { + return "token http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* token_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* name_pskel<char>:: + _static_type () + { + return "Name http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* name_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* nmtoken_pskel<char>:: + _static_type () + { + return "NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* nmtoken_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* nmtokens_pskel<char>:: + _static_type () + { + return "NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* nmtokens_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* ncname_pskel<char>:: + _static_type () + { + return "NCName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* ncname_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* id_pskel<char>:: + _static_type () + { + return "ID http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* id_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* idref_pskel<char>:: + _static_type () + { + return "IDREF http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* idref_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* idrefs_pskel<char>:: + _static_type () + { + return "IDREFS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* idrefs_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* language_pskel<char>:: + _static_type () + { + return "language http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* language_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* uri_pskel<char>:: + _static_type () + { + return "anyURI http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* uri_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* qname_pskel<char>:: + _static_type () + { + return "QName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* qname_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* base64_binary_pskel<char>:: + _static_type () + { + return "base64Binary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* base64_binary_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* hex_binary_pskel<char>:: + _static_type () + { + return "hexBinary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* hex_binary_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gday_pskel<char>:: + _static_type () + { + return "gDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gday_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gmonth_pskel<char>:: + _static_type () + { + return "gMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gmonth_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gyear_pskel<char>:: + _static_type () + { + return "gYear http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gyear_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gmonth_day_pskel<char>:: + _static_type () + { + return "gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gmonth_day_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gyear_month_pskel<char>:: + _static_type () + { + return "gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gyear_month_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* date_pskel<char>:: + _static_type () + { + return "date http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* date_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* time_pskel<char>:: + _static_type () + { + return "time http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* time_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* date_time_pskel<char>:: + _static_type () + { + return "dateTime http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* date_time_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* duration_pskel<char>:: + _static_type () + { + return "duration http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* duration_pskel<char>:: + _dynamic_type () const + { + return _static_type (); + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_CHAR +#endif // XSD_CXX_PARSER_USE_CHAR + + +#if defined(XSD_CXX_PARSER_USE_WCHAR) || !defined(XSD_CXX_PARSER_USE_CHAR) + +#ifndef XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_WCHAR +#define XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + template<> + inline const wchar_t* any_type_pskel<wchar_t>:: + _static_type () + { + return L"anyType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* any_type_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* any_simple_type_pskel<wchar_t>:: + _static_type () + { + return L"anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* any_simple_type_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* boolean_pskel<wchar_t>:: + _static_type () + { + return L"boolean http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* boolean_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* byte_pskel<wchar_t>:: + _static_type () + { + return L"byte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* byte_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_byte_pskel<wchar_t>:: + _static_type () + { + return L"unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_byte_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* short_pskel<wchar_t>:: + _static_type () + { + return L"short http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* short_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_short_pskel<wchar_t>:: + _static_type () + { + return L"unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_short_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* int_pskel<wchar_t>:: + _static_type () + { + return L"int http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* int_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_int_pskel<wchar_t>:: + _static_type () + { + return L"unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_int_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* long_pskel<wchar_t>:: + _static_type () + { + return L"long http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* long_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_long_pskel<wchar_t>:: + _static_type () + { + return L"unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_long_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* integer_pskel<wchar_t>:: + _static_type () + { + return L"integer http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* integer_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* negative_integer_pskel<wchar_t>:: + _static_type () + { + return L"negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* negative_integer_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* non_positive_integer_pskel<wchar_t>:: + _static_type () + { + return L"nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* non_positive_integer_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* positive_integer_pskel<wchar_t>:: + _static_type () + { + return L"positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* positive_integer_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* non_negative_integer_pskel<wchar_t>:: + _static_type () + { + return L"nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* non_negative_integer_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* float_pskel<wchar_t>:: + _static_type () + { + return L"float http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* float_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* double_pskel<wchar_t>:: + _static_type () + { + return L"double http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* double_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* decimal_pskel<wchar_t>:: + _static_type () + { + return L"decimal http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* decimal_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* string_pskel<wchar_t>:: + _static_type () + { + return L"string http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* string_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* normalized_string_pskel<wchar_t>:: + _static_type () + { + return L"normalizedString http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* normalized_string_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* token_pskel<wchar_t>:: + _static_type () + { + return L"token http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* token_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* name_pskel<wchar_t>:: + _static_type () + { + return L"Name http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* name_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* nmtoken_pskel<wchar_t>:: + _static_type () + { + return L"NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* nmtoken_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* nmtokens_pskel<wchar_t>:: + _static_type () + { + return L"NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* nmtokens_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* ncname_pskel<wchar_t>:: + _static_type () + { + return L"NCName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* ncname_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* id_pskel<wchar_t>:: + _static_type () + { + return L"ID http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* id_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* idref_pskel<wchar_t>:: + _static_type () + { + return L"IDREF http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* idref_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* idrefs_pskel<wchar_t>:: + _static_type () + { + return L"IDREFS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* idrefs_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* language_pskel<wchar_t>:: + _static_type () + { + return L"language http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* language_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* uri_pskel<wchar_t>:: + _static_type () + { + return L"anyURI http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* uri_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* qname_pskel<wchar_t>:: + _static_type () + { + return L"QName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* qname_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* base64_binary_pskel<wchar_t>:: + _static_type () + { + return L"base64Binary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* base64_binary_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* hex_binary_pskel<wchar_t>:: + _static_type () + { + return L"hexBinary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* hex_binary_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gday_pskel<wchar_t>:: + _static_type () + { + return L"gDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gday_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gmonth_pskel<wchar_t>:: + _static_type () + { + return L"gMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gmonth_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gyear_pskel<wchar_t>:: + _static_type () + { + return L"gYear http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gyear_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gmonth_day_pskel<wchar_t>:: + _static_type () + { + return L"gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gmonth_day_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gyear_month_pskel<wchar_t>:: + _static_type () + { + return L"gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gyear_month_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* date_pskel<wchar_t>:: + _static_type () + { + return L"date http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* date_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* time_pskel<wchar_t>:: + _static_type () + { + return L"time http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* time_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* date_time_pskel<wchar_t>:: + _static_type () + { + return L"dateTime http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* date_time_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* duration_pskel<wchar_t>:: + _static_type () + { + return L"duration http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* duration_pskel<wchar_t>:: + _dynamic_type () const + { + return _static_type (); + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_IXX_WCHAR +#endif // XSD_CXX_PARSER_USE_WCHAR diff --git a/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.txx b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.txx new file mode 100644 index 0000000..4ae50e3 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.txx @@ -0,0 +1,69 @@ +// file : xsd/cxx/parser/validating/xml-schema-pskel.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type + // + + template <typename C> + bool any_type_pskel<C>:: + _start_element_impl (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>* type) + { + this->_start_any_element (ns, name, type); + this->complex_content<C>::context_.top ().any_ = true; + return true; + } + + template <typename C> + bool any_type_pskel<C>:: + _end_element_impl (const ro_string<C>& ns, const ro_string<C>& name) + { + this->complex_content<C>::context_.top ().any_ = false; + this->_end_any_element (ns, name); + return true; + } + + + template <typename C> + bool any_type_pskel<C>:: + _attribute_impl_phase_two (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value) + { + this->_any_attribute (ns, name, value); + return true; + } + + template <typename C> + bool any_type_pskel<C>:: + _characters_impl (const ro_string<C>& s) + { + this->_any_characters (s); + return true; + } + + // any_simple_type + // + + template <typename C> + bool any_simple_type_pskel<C>:: + _characters_impl (const ro_string<C>& s) + { + this->_any_characters (s); + return true; + } + } + } + } +} |