From f0510d2f90467de8e8f260b47d79a9baaf9bef17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2009 07:15:29 +0200 Subject: Start tracking XSD with git --- libxsd/xsd/cxx/parser/validating/exceptions.hxx | 153 ++ libxsd/xsd/cxx/parser/validating/exceptions.ixx | 163 ++ libxsd/xsd/cxx/parser/validating/exceptions.txx | 97 + .../xsd/cxx/parser/validating/inheritance-map.hxx | 92 + .../xsd/cxx/parser/validating/inheritance-map.txx | 65 + libxsd/xsd/cxx/parser/validating/parser.hxx | 471 ++++ libxsd/xsd/cxx/parser/validating/parser.txx | 667 +++++ .../xsd/cxx/parser/validating/xml-schema-pimpl.hxx | 1121 ++++++++ .../xsd/cxx/parser/validating/xml-schema-pimpl.ixx | 676 +++++ .../xsd/cxx/parser/validating/xml-schema-pimpl.txx | 2746 ++++++++++++++++++++ .../xsd/cxx/parser/validating/xml-schema-pskel.hxx | 647 +++++ .../xsd/cxx/parser/validating/xml-schema-pskel.ixx | 1249 +++++++++ .../xsd/cxx/parser/validating/xml-schema-pskel.txx | 69 + 13 files changed, 8216 insertions(+) create mode 100644 libxsd/xsd/cxx/parser/validating/exceptions.hxx create mode 100644 libxsd/xsd/cxx/parser/validating/exceptions.ixx create mode 100644 libxsd/xsd/cxx/parser/validating/exceptions.txx create mode 100644 libxsd/xsd/cxx/parser/validating/inheritance-map.hxx create mode 100644 libxsd/xsd/cxx/parser/validating/inheritance-map.txx create mode 100644 libxsd/xsd/cxx/parser/validating/parser.hxx create mode 100644 libxsd/xsd/cxx/parser/validating/parser.txx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.ixx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pskel.ixx create mode 100644 libxsd/xsd/cxx/parser/validating/xml-schema-pskel.txx (limited to 'libxsd/xsd/cxx/parser/validating') diff --git a/libxsd/xsd/cxx/parser/validating/exceptions.hxx b/libxsd/xsd/cxx/parser/validating/exceptions.hxx new file mode 100644 index 0000000..1112c60 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/exceptions.hxx @@ -0,0 +1,153 @@ +// file : xsd/cxx/parser/validating/exceptions.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 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 + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // + // + template + struct expected_attribute: schema_exception + { + virtual + ~expected_attribute (); + + expected_attribute (const std::basic_string& expected_namespace, + const std::basic_string& expected_name); + + const std::basic_string& + expected_namespace () const + { + return expected_namespace_; + } + + const std::basic_string& + expected_name () const + { + return expected_name_; + } + + virtual std::basic_string + message () const; + + private: + std::basic_string expected_namespace_; + std::basic_string expected_name_; + }; + + // + // + template + struct unexpected_attribute: schema_exception + { + virtual + ~unexpected_attribute (); + + unexpected_attribute ( + const std::basic_string& encountered_namespace, + const std::basic_string& encountered_name); + + + const std::basic_string& + encountered_namespace () const + { + return encountered_namespace_; + } + + const std::basic_string& + encountered_name () const + { + return encountered_name_; + } + + virtual std::basic_string + message () const; + + private: + std::basic_string encountered_namespace_; + std::basic_string encountered_name_; + }; + + + // + // + template + struct unexpected_characters: schema_exception + { + virtual + ~unexpected_characters (); + + unexpected_characters (const std::basic_string& s); + + const std::basic_string& + characters () const + { + return characters_; + } + + virtual std::basic_string + message () const; + + private: + std::basic_string characters_; + }; + + // + // + template + struct invalid_value: schema_exception + { + virtual + ~invalid_value (); + + invalid_value (const C* type, const std::basic_string& value); + + invalid_value (const C* type, const ro_string& value); + + invalid_value (const std::basic_string& type, + const std::basic_string& value); + + const std::basic_string& + type () const + { + return type_; + } + + const std::basic_string& + value () const + { + return value_; + } + + virtual std::basic_string + message () const; + + private: + std::basic_string type_; + std::basic_string value_; + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_VALIDATING_EXCEPTIONS_HXX + +#include diff --git a/libxsd/xsd/cxx/parser/validating/exceptions.ixx b/libxsd/xsd/cxx/parser/validating/exceptions.ixx new file mode 100644 index 0000000..6535cb8 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/exceptions.ixx @@ -0,0 +1,163 @@ +// file : xsd/cxx/parser/validating/exceptions.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 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 expected_attribute:: + message () const + { + std::basic_string r ("expected attribute '"); + r += expected_namespace_; + r += expected_namespace_.empty () ? "" : "#"; + r += expected_name_; + r += "'"; + return r; + } + + // unexpected_attribute + // + template<> + inline + std::basic_string unexpected_attribute:: + message () const + { + std::basic_string r ("unexpected attribute '"); + r += encountered_namespace_; + r += encountered_namespace_.empty () ? "" : "#"; + r += encountered_name_; + r += "'"; + return r; + } + + // unexpected_characters + // + template<> + inline + std::basic_string unexpected_characters:: + message () const + { + std::basic_string r ("unexpected characters '"); + r += characters_; + r += "'"; + return r; + } + + // invalid_value + // + template<> + inline + std::basic_string invalid_value:: + message () const + { + std::basic_string 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 expected_attribute:: + message () const + { + std::basic_string 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 unexpected_attribute:: + message () const + { + std::basic_string 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 unexpected_characters:: + message () const + { + std::basic_string r (L"unexpected characters '"); + r += characters_; + r += L"'"; + return r; + } + + // invalid_value + // + template<> + inline + std::basic_string invalid_value:: + message () const + { + std::basic_string 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/libxsd/xsd/cxx/parser/validating/exceptions.txx b/libxsd/xsd/cxx/parser/validating/exceptions.txx new file mode 100644 index 0000000..f8ffe80 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/exceptions.txx @@ -0,0 +1,97 @@ +// file : xsd/cxx/parser/validating/exceptions.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // expected_attribute + // + template + expected_attribute:: + ~expected_attribute () + { + } + + template + expected_attribute:: + expected_attribute (const std::basic_string& expected_namespace, + const std::basic_string& expected_name) + : expected_namespace_ (expected_namespace), + expected_name_ (expected_name) + { + } + + // unexpected_attribute + // + template + unexpected_attribute:: + ~unexpected_attribute () + { + } + + template + unexpected_attribute:: + unexpected_attribute (const std::basic_string& encountered_namespace, + const std::basic_string& encountered_name) + : encountered_namespace_ (encountered_namespace), + encountered_name_ (encountered_name) + { + } + + // unexpected_characters + // + template + unexpected_characters:: + ~unexpected_characters () + { + } + + template + unexpected_characters:: + unexpected_characters (const std::basic_string& s) + : characters_ (s) + { + } + + // invalid_value + // + template + invalid_value:: + ~invalid_value () + { + } + + template + invalid_value:: + invalid_value (const C* type, + const std::basic_string& value) + : type_ (type), value_ (value) + { + } + + template + invalid_value:: + invalid_value (const C* type, + const ro_string& value) + : type_ (type), value_ (value) + { + } + + template + invalid_value:: + invalid_value (const std::basic_string& type, + const std::basic_string& value) + : type_ (type), value_ (value) + { + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/validating/inheritance-map.hxx b/libxsd/xsd/cxx/parser/validating/inheritance-map.hxx new file mode 100644 index 0000000..ebd1d03 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/inheritance-map.hxx @@ -0,0 +1,92 @@ +// file : xsd/cxx/parser/validating/inheritance-map.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 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 +#include // std::size_t + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + template + struct string_comparison + { + bool + operator() (const C* x, const C* y) const + { + ro_string s (x); + return s.compare (y) < 0; + } + }; + + template + struct inheritance_map + { + void + insert (const C* derived, const C* base) + { + map_[derived] = base; + } + + bool + check (const C* derived, const ro_string& base) const; + + private: + typedef std::map > map; + map map_; + }; + + + // Translation unit initializer. + // + template + struct inheritance_map_init + { + static inheritance_map* map; + static std::size_t count; + + inheritance_map_init (); + ~inheritance_map_init (); + }; + + template + inheritance_map* inheritance_map_init::map = 0; + + template + std::size_t inheritance_map_init::count = 0; + + template + inline inheritance_map& + inheritance_map_instance () + { + return *inheritance_map_init::map; + } + + + // Map entry initializer. + // + template + struct inheritance_map_entry + { + inheritance_map_entry (const C* derived, const C* base); + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX + diff --git a/libxsd/xsd/cxx/parser/validating/inheritance-map.txx b/libxsd/xsd/cxx/parser/validating/inheritance-map.txx new file mode 100644 index 0000000..5e70409 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/inheritance-map.txx @@ -0,0 +1,65 @@ +// file : xsd/cxx/parser/validating/inheritance-map.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + template + bool inheritance_map:: + check (const C* derived, const ro_string& 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 + inheritance_map_init:: + inheritance_map_init () + { + if (count == 0) + map = new inheritance_map; + + ++count; + } + + template + inheritance_map_init:: + ~inheritance_map_init () + { + if (--count == 0) + delete map; + } + + // inheritance_map_entry + // + template + inheritance_map_entry:: + inheritance_map_entry (const C* derived, const C* base) + { + inheritance_map_instance ().insert (derived, base); + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/validating/parser.hxx b/libxsd/xsd/cxx/parser/validating/parser.hxx new file mode 100644 index 0000000..4feb898 --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/parser.hxx @@ -0,0 +1,471 @@ +// file : xsd/cxx/parser/validating/parser.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 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 +#include // std::size_t +#include // std::memcpy + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // + // + template + struct empty_content: parser_base + { + // 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 " " 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& ns, + const ro_string& name, + const ro_string* type); + + virtual void + _end_any_element (const ro_string& ns, + const ro_string& name); + + virtual void + _any_attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _any_characters (const ro_string&); + + + // + // + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const ro_string*); + + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + + // + // + virtual void + _start_element (const ro_string&, + const ro_string&, + const ro_string*); + + virtual void + _end_element (const ro_string&, + const ro_string&); + + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + + // + // + 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& encountered_ns, + const ro_string& encountered_name); + + virtual void + _unexpected_element (const ro_string& ns, + const ro_string& name); + + virtual void + _expected_attribute (const C* expected_ns, + const C* expected_name); + + virtual void + _unexpected_attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _unexpected_characters (const ro_string&); + }; + + + // + // + template + struct simple_content: empty_content + { + // + // + virtual void + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _characters (const ro_string&); + + // + // + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + // + // + 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& ns, + const ro_string& name, + const ro_string& value); + + virtual bool + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value); + }; + + + // + // + template + struct complex_content: empty_content + { + // + // + virtual void + _start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type); + + virtual void + _end_element (const ro_string& ns, + const ro_string& name); + + virtual void + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _characters (const ro_string&); + + // + // + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + // + // + 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& ns, + const ro_string& name, + const ro_string& value); + + virtual bool + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value); + protected: + struct state + { + state () + : any_ (false), depth_ (0), parser_ (0) + { + } + + bool any_; + std::size_t depth_; + parser_base* 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 rest_; + std::size_t size_; + }; + + state_stack context_; + }; + + // Base for xsd:list. + // + template + struct list_base: simple_content + { + virtual void + _xsd_parse_item (const ro_string&) = 0; + + virtual void + _pre_impl (); + + virtual void + _characters (const ro_string&); + + virtual void + _post_impl (); + + protected: + std::basic_string 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 (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 (stack_.top ()); + } + + private: + pod_stack stack_; + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_VALIDATING_PARSER_HXX diff --git a/libxsd/xsd/cxx/parser/validating/parser.txx b/libxsd/xsd/cxx/parser/validating/parser.txx new file mode 100644 index 0000000..4cf9b7e --- /dev/null +++ b/libxsd/xsd/cxx/parser/validating/parser.txx @@ -0,0 +1,667 @@ +// file : xsd/cxx/parser/validating/parser.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + + // empty_content + // + + + template + void empty_content:: + _start_any_element (const ro_string&, + const ro_string&, + const ro_string*) + { + } + + template + void empty_content:: + _end_any_element (const ro_string&, + const ro_string&) + { + } + + template + void empty_content:: + _any_attribute (const ro_string&, + const ro_string&, + const ro_string&) + { + } + + template + void empty_content:: + _any_characters (const ro_string&) + { + } + + // + // + template + bool empty_content:: + _start_element_impl (const ro_string&, + const ro_string&, + const ro_string*) + { + return false; + } + + template + bool empty_content:: + _end_element_impl (const ro_string&, + const ro_string&) + { + return false; + } + + template + bool empty_content:: + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + template + bool empty_content:: + _characters_impl (const ro_string&) + { + return false; + } + + // + // + template + void empty_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type) + { + if (!_start_element_impl (ns, name, type)) + _unexpected_element (ns, name); + } + + template + void empty_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + if (!_end_element_impl (ns, name)) + _unexpected_element (ns, name); + } + + template + void empty_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& 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 () && + (name == xml::bits::type () || + name == xml::bits::nil () || + name == xml::bits::schema_location () || + name == xml::bits::no_namespace_schema_location ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace ()) + return; + + if (!_attribute_impl (ns, name, value)) + _unexpected_attribute (ns, name, value); + } + + template + void empty_content:: + _characters (const ro_string& s) + { + if (!_characters_impl (s)) + _unexpected_characters (s); + } + + // + // + template + void empty_content:: + _expected_element (const C* ex_ns, const C* ex_name) + { + throw expected_element (ex_ns, ex_name); + } + + template + void empty_content:: + _expected_element (const C* ex_ns, + const C* ex_name, + const ro_string& en_ns, + const ro_string& en_name) + { + throw expected_element (ex_ns, ex_name, en_ns, en_name); + } + + template + void empty_content:: + _unexpected_element (const ro_string& ns, + const ro_string& name) + { + throw unexpected_element (ns, name); + } + + template + void empty_content:: + _expected_attribute (const C* ex_ns, const C* ex_name) + { + throw expected_attribute (ex_ns, ex_name); + } + + template + void empty_content:: + _unexpected_attribute (const ro_string& ns, + const ro_string& name, + const ro_string&) + { + throw unexpected_attribute (ns, name); + } + + template + void empty_content:: + _unexpected_characters (const ro_string& s) + { + throw unexpected_characters (s); + } + + + // simple_content + // + + template + void simple_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& 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 () && + (name == xml::bits::type () || + name == xml::bits::nil () || + name == xml::bits::schema_location () || + name == xml::bits::no_namespace_schema_location ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace ()) + return; + + if (!_attribute_impl (ns, name, value)) + _unexpected_attribute (ns, name, value); + } + + template + void simple_content:: + _characters (const ro_string& str) + { + if (!_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::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)) + _unexpected_characters (str); + } + } + } + + template + void simple_content:: + _pre_impl () + { + this->_pre (); + _pre_a_validate (); + } + + template + void simple_content:: + _post_impl () + { + _post_a_validate (); + this->_post (); + } + + template + void simple_content:: + _pre_a_validate () + { + } + + template + void simple_content:: + _post_a_validate () + { + } + + template + bool simple_content:: + _attribute_impl (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + return _attribute_impl_phase_one (ns, name, value) || + _attribute_impl_phase_two (ns, name, value); + } + + template + bool simple_content:: + _attribute_impl_phase_one (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + template + bool simple_content:: + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + + // complex_content + // + + + template + void complex_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const ro_string* type) + { + state& s (context_.top ()); + + if (s.depth_++ > 0) + { + if (s.any_) + _start_any_element (ns, name, type); + else if (s.parser_) + s.parser_->_start_element (ns, name, type); + } + else + { + if (!_start_element_impl (ns, name, type)) + _unexpected_element (ns, name); + else if (s.parser_ != 0) + s.parser_->_pre_impl (); + } + } + + template + void complex_content:: + _end_element (const ro_string& ns, + const ro_string& 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 (!_end_element_impl (ns, name)) + assert (false); + } + } + else + { + state& s (context_.top ()); + + if (--s.depth_ > 0) + { + if (s.any_) + _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 (!_end_element_impl (ns, name)) + _unexpected_element (ns, name); + } + } + } + + template + void complex_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& 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 () && + (name == xml::bits::type () || + name == xml::bits::nil () || + name == xml::bits::schema_location () || + name == xml::bits::no_namespace_schema_location ())) + return; + + // Also some parsers (notably Xerces-C++) supplies us with + // namespace-prefix mapping attributes. + // + if (ns == xml::bits::xmlns_namespace ()) + return; + + const state& s (context_.top ()); + + if (s.depth_ > 0) + { + if (s.any_) + _any_attribute (ns, name, value); + else if (s.parser_) + s.parser_->_attribute (ns, name, value); + } + else + { + if (!_attribute_impl (ns, name, value)) + _unexpected_attribute (ns, name, value); + } + } + + template + void complex_content:: + _characters (const ro_string& str) + { + const state& s (context_.top ()); + + if (s.depth_ > 0) + { + if (s.any_) + _any_characters (str); + else if (s.parser_) + s.parser_->_characters (str); + } + else + { + if (!_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::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)) + _unexpected_characters (str); + } + } + } + } + + template + void complex_content:: + _pre_impl () + { + context_.push (state ()); + this->_pre (); + _pre_a_validate (); + _pre_e_validate (); + } + + template + void complex_content:: + _post_impl () + { + _post_e_validate (); + _post_a_validate (); + this->_post (); + context_.pop (); + } + + template + void complex_content:: + _pre_e_validate () + { + } + + template + void complex_content:: + _post_e_validate () + { + } + + template + void complex_content:: + _pre_a_validate () + { + } + + template + void complex_content:: + _post_a_validate () + { + } + + template + bool complex_content:: + _attribute_impl (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + return _attribute_impl_phase_one (ns, name, value) || + _attribute_impl_phase_two (ns, name, value); + } + + template + bool complex_content:: + _attribute_impl_phase_one (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + template + bool complex_content:: + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + + // list_base + // + namespace bits + { + // Find first non-space character. + // + template + typename ro_string::size_type + find_ns (const C* s, + typename ro_string::size_type size, + typename ro_string::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::npos; + } + + // Find first space character. + // + template + typename ro_string::size_type + find_s (const C* s, + typename ro_string::size_type size, + typename ro_string::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::npos; + } + } + + // Relevant XML Schema Part 2: Datatypes sections: 4.2.1.2, 4.3.6. + // + + template + void list_base:: + _pre_impl () + { + simple_content::_pre_impl (); + buf_.clear (); + } + + template + void list_base:: + _characters (const ro_string& s) + { + typedef typename ro_string::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 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::npos;) + { + size_type j (bits::find_s (data, size, i)); + + if (j != ro_string::npos) + { + if (buf_.empty ()) + { + ro_string 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 str; + str.swap (buf_); + str.append (data + i, j - i); + ro_string 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 + void list_base:: + _post_impl () + { + // Handle the last item. + // + if (!buf_.empty ()) + { + ro_string tmp (buf_); // Private copy ctor. + _xsd_parse_item (tmp); + } + + simple_content::_post_impl (); + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.hxx new file mode 100644 index 0000000..5f2f03f --- /dev/null +++ b/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 +// copyright : Copyright (c) 2005-2009 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 + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type + // + template + struct any_type_pimpl: virtual any_type_pskel + { + virtual void + post_any_type (); + }; + + // any_simple_type + // + template + struct any_simple_type_pimpl: virtual any_simple_type_pskel + { + virtual void + post_any_simple_type (); + }; + + // boolean + // + template + struct boolean_pimpl: virtual boolean_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual bool + post_boolean (); + + protected: + std::basic_string str_; + bool value_; + }; + + + // 8-bit + // + template + struct byte_pimpl: virtual byte_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual signed char + post_byte (); + + protected: + std::basic_string str_; + signed char value_; + }; + + + template + struct unsigned_byte_pimpl: virtual unsigned_byte_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned char + post_unsigned_byte (); + + protected: + std::basic_string str_; + unsigned char value_; + }; + + + // 16-bit + // + template + struct short_pimpl: virtual short_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual short + post_short (); + + protected: + std::basic_string str_; + short value_; + }; + + + template + struct unsigned_short_pimpl: virtual unsigned_short_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned short + post_unsigned_short (); + + protected: + std::basic_string str_; + unsigned short value_; + }; + + + // 32-bit + // + template + struct int_pimpl: virtual int_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual int + post_int (); + + protected: + std::basic_string str_; + int value_; + }; + + + template + struct unsigned_int_pimpl: virtual unsigned_int_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned int + post_unsigned_int (); + + protected: + std::basic_string str_; + unsigned int value_; + }; + + + // 64-bit + // + template + struct long_pimpl: virtual long_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long long + post_long (); + + protected: + std::basic_string str_; + long long value_; + }; + + + template + struct unsigned_long_pimpl: virtual unsigned_long_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long long + post_unsigned_long (); + + protected: + std::basic_string str_; + unsigned long long value_; + }; + + + // Arbitrary-length integers. + // + template + struct integer_pimpl: virtual integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long long + post_integer (); + + protected: + std::basic_string str_; + long long value_; + }; + + template + struct negative_integer_pimpl: virtual negative_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long long + post_negative_integer (); + + protected: + std::basic_string str_; + long long value_; + }; + + template + struct non_positive_integer_pimpl: virtual non_positive_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long long + post_non_positive_integer (); + + protected: + std::basic_string str_; + long long value_; + }; + + template + struct positive_integer_pimpl: virtual positive_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long long + post_positive_integer (); + + protected: + std::basic_string str_; + unsigned long long value_; + }; + + template + struct non_negative_integer_pimpl: virtual non_negative_integer_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long long + post_non_negative_integer (); + + protected: + std::basic_string str_; + unsigned long long value_; + }; + + + // Floats. + // + template + struct float_pimpl: virtual float_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual float + post_float (); + + protected: + std::basic_string str_; + float value_; + }; + + + template + struct double_pimpl: virtual double_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual double + post_double (); + + protected: + std::basic_string str_; + double value_; + }; + + + template + struct decimal_pimpl: virtual decimal_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual double + post_decimal (); + + protected: + std::basic_string str_; + double value_; + }; + + + // Strings. + // + template + struct string_pimpl: virtual string_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_string (); + + protected: + std::basic_string str_; + }; + + template + struct normalized_string_pimpl: virtual normalized_string_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_normalized_string (); + + protected: + std::basic_string str_; + }; + + template + struct token_pimpl: virtual token_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_token (); + + protected: + std::basic_string str_; + }; + + template + struct name_pimpl: virtual name_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_name (); + + protected: + std::basic_string str_; + }; + + template + struct nmtoken_pimpl: virtual nmtoken_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_nmtoken (); + + protected: + std::basic_string str_; + }; + + template + struct nmtokens_pimpl: virtual nmtokens_pskel + { + virtual void + _pre (); + + virtual void + _xsd_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence + post_nmtokens (); + + protected: + string_sequence seq_; + nmtoken_pimpl parser_; + }; + + template + struct ncname_pimpl: virtual ncname_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_ncname (); + + protected: + std::basic_string str_; + }; + + template + struct id_pimpl: virtual id_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_id (); + + protected: + std::basic_string str_; + }; + + template + struct idref_pimpl: virtual idref_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_idref (); + + protected: + std::basic_string str_; + }; + + template + struct idrefs_pimpl: virtual idrefs_pskel + { + virtual void + _pre (); + + virtual void + _xsd_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence + post_idrefs (); + + protected: + string_sequence seq_; + idref_pimpl parser_; + }; + + // language + // + template + struct language_pimpl: virtual language_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::basic_string + post_language (); + + protected: + std::basic_string str_; + }; + + // anyURI + // + template + struct uri_pimpl: virtual uri_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::basic_string + post_uri (); + + protected: + std::basic_string str_; + }; + + // QName + // + template + struct qname_pimpl: virtual qname_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual qname + post_qname (); + + protected: + std::basic_string str_; + std::basic_string name_; + std::basic_string prefix_; + }; + + // base64Binary + // + template + struct base64_binary_pimpl: virtual base64_binary_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::auto_ptr + post_base64_binary (); + + protected: + std::basic_string str_; + std::auto_ptr buf_; + }; + + // hexBinary + // + template + struct hex_binary_pimpl: virtual hex_binary_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::auto_ptr + post_hex_binary (); + + protected: + std::basic_string str_; + std::auto_ptr buf_; + }; + + // gday + // + template + struct gday_pimpl: virtual gday_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gday + post_gday (); + + protected: + std::basic_string str_; + unsigned short day_; + bool z_; + short zh_, zm_; + }; + + // gmonth + // + template + struct gmonth_pimpl: virtual gmonth_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gmonth + post_gmonth (); + + protected: + std::basic_string str_; + unsigned short month_; + bool z_; + short zh_, zm_; + }; + + // gyear + // + template + struct gyear_pimpl: virtual gyear_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gyear + post_gyear (); + + protected: + std::basic_string str_; + int year_; + bool z_; + short zh_, zm_; + }; + + // gmonth_day + // + template + struct gmonth_day_pimpl: virtual gmonth_day_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gmonth_day + post_gmonth_day (); + + protected: + std::basic_string str_; + unsigned short month_; + unsigned short day_; + bool z_; + short zh_, zm_; + }; + + // gyear_month + // + template + struct gyear_month_pimpl: virtual gyear_month_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gyear_month + post_gyear_month (); + + protected: + std::basic_string str_; + int year_; + unsigned short month_; + bool z_; + short zh_, zm_; + }; + + // date + // + template + struct date_pimpl: virtual date_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual date + post_date (); + + protected: + std::basic_string str_; + int year_; + unsigned short month_; + unsigned short day_; + bool z_; + short zh_, zm_; + }; + + // time + // + template + struct time_pimpl: virtual time_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual time + post_time (); + + protected: + std::basic_string str_; + unsigned short hours_; + unsigned short minutes_; + double seconds_; + bool z_; + short zh_, zm_; + }; + + // date_time + // + template + struct date_time_pimpl: virtual date_time_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual date_time + post_date_time (); + + protected: + std::basic_string str_; + int year_; + unsigned short month_; + unsigned short day_; + unsigned short hours_; + unsigned short minutes_; + double seconds_; + bool z_; + short zh_, zm_; + }; + + // duration + // + template + struct duration_pimpl: virtual duration_pskel + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual duration + post_duration (); + + protected: + std::basic_string str_; + bool negative_; + unsigned int years_; + unsigned int months_; + unsigned int days_; + unsigned int hours_; + unsigned int minutes_; + double seconds_; + }; + + // Literals. + // + namespace bits + { + template + const C* + boolean (); + + template + const C* + byte (); + + template + const C* + unsigned_byte (); + + template + const C* + short_ (); + + template + const C* + unsigned_short (); + + template + const C* + int_ (); + + template + const C* + unsigned_int (); + + template + const C* + long_ (); + + template + const C* + unsigned_long (); + + template + const C* + integer (); + + template + const C* + negative_integer (); + + template + const C* + non_positive_integer (); + + template + const C* + non_negative_integer (); + + template + const C* + positive_integer (); + + template + const C* + float_ (); + + template + const C* + double_ (); + + template + const C* + decimal (); + + template + const C* + name (); + + template + const C* + nmtoken (); + + template + const C* + nmtokens (); + + template + const C* + ncname (); + + template + const C* + id (); + + template + const C* + idref (); + + template + const C* + idrefs (); + + template + const C* + language (); + + template + const C* + qname (); + + template + const C* + base64_binary (); + + template + const C* + hex_binary (); + + template + const C* + gday (); + + template + const C* + gmonth (); + + template + const C* + gyear (); + + template + const C* + gmonth_day (); + + template + const C* + gyear_month (); + + template + const C* + date (); + + template + const C* + time (); + + template + const C* + date_time (); + + template + const C* + duration (); + + // float literals: INF -INF NaN + // + template + const C* + positive_inf (); + + template + const C* + negative_inf (); + + template + const C* + nan (); + + // boolean literals + // + template + const C* + true_ (); + + template + const C* + false_ (); + + template + const C* + one (); + + template + const C* + zero (); + } + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX + +#include diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.ixx b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.ixx new file mode 100644 index 0000000..61bbafb --- /dev/null +++ b/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 +// copyright : Copyright (c) 2005-2009 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 () + { + return "boolean"; + } + + template<> + inline const char* + byte () + { + return "byte"; + } + + template<> + inline const char* + unsigned_byte () + { + return "unsignedByte"; + } + + template<> + inline const char* + short_ () + { + return "short"; + } + + template<> + inline const char* + unsigned_short () + { + return "unsignedShort"; + } + + template<> + inline const char* + int_ () + { + return "int"; + } + + template<> + inline const char* + unsigned_int () + { + return "unsignedInt"; + } + + template<> + inline const char* + long_ () + { + return "long"; + } + + template<> + inline const char* + unsigned_long () + { + return "unsignedLong"; + } + + template<> + inline const char* + integer () + { + return "integer"; + } + + template<> + inline const char* + negative_integer () + { + return "negativeInteger"; + } + + template<> + inline const char* + non_positive_integer () + { + return "nonPositiveInteger"; + } + + template<> + inline const char* + non_negative_integer () + { + return "nonNegativeInteger"; + } + + template<> + inline const char* + positive_integer () + { + return "positiveInteger"; + } + + template<> + inline const char* + float_ () + { + return "float"; + } + + template<> + inline const char* + double_ () + { + return "double"; + } + + template<> + inline const char* + decimal () + { + return "decimal"; + } + + template<> + inline const char* + name () + { + return "Name"; + } + + template<> + inline const char* + nmtoken () + { + return "NMTOKEN"; + } + + template<> + inline const char* + nmtokens () + { + return "NMTOKENS"; + } + + template<> + inline const char* + ncname () + { + return "NCName"; + } + + template<> + inline const char* + id () + { + return "ID"; + } + + template<> + inline const char* + idref () + { + return "IDREF"; + } + + template<> + inline const char* + idrefs () + { + return "IDREFS"; + } + + template<> + inline const char* + language () + { + return "language"; + } + + template<> + inline const char* + qname () + { + return "QName"; + } + + template<> + inline const char* + base64_binary () + { + return "base64Binary"; + } + + template<> + inline const char* + hex_binary () + { + return "hexBinary"; + } + + template<> + inline const char* + gday () + { + return "gDay"; + } + + template<> + inline const char* + gmonth () + { + return "gMonth"; + } + + template<> + inline const char* + gyear () + { + return "gYear"; + } + + template<> + inline const char* + gmonth_day () + { + return "gMonthDay"; + } + + template<> + inline const char* + gyear_month () + { + return "gYearMonth"; + } + + template<> + inline const char* + date () + { + return "date"; + } + + template<> + inline const char* + time () + { + return "time"; + } + + template<> + inline const char* + date_time () + { + return "dateTime"; + } + + template<> + inline const char* + duration () + { + return "duration"; + } + + // + // + template<> + inline const char* + positive_inf () + { + return "INF"; + } + + template<> + inline const char* + negative_inf () + { + return "-INF"; + } + + template<> + inline const char* + nan () + { + return "NaN"; + } + + // + // + template<> + inline const char* + true_ () + { + return "true"; + } + + template<> + inline const char* + false_ () + { + return "false"; + } + + template<> + inline const char* + one () + { + return "1"; + } + + template<> + inline const char* + zero () + { + 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 () + { + return L"boolean"; + } + + template<> + inline const wchar_t* + byte () + { + return L"byte"; + } + + template<> + inline const wchar_t* + unsigned_byte () + { + return L"unsignedByte"; + } + + template<> + inline const wchar_t* + short_ () + { + return L"short"; + } + + template<> + inline const wchar_t* + unsigned_short () + { + return L"unsignedShort"; + } + + template<> + inline const wchar_t* + int_ () + { + return L"int"; + } + + template<> + inline const wchar_t* + unsigned_int () + { + return L"unsignedInt"; + } + + template<> + inline const wchar_t* + long_ () + { + return L"long"; + } + + template<> + inline const wchar_t* + unsigned_long () + { + return L"unsignedLong"; + } + + template<> + inline const wchar_t* + integer () + { + return L"integer"; + } + + template<> + inline const wchar_t* + negative_integer () + { + return L"negativeInteger"; + } + + template<> + inline const wchar_t* + non_positive_integer () + { + return L"nonPositiveInteger"; + } + + template<> + inline const wchar_t* + non_negative_integer () + { + return L"nonNegativeInteger"; + } + + template<> + inline const wchar_t* + positive_integer () + { + return L"positiveInteger"; + } + + template<> + inline const wchar_t* + float_ () + { + return L"float"; + } + + template<> + inline const wchar_t* + double_ () + { + return L"double"; + } + + template<> + inline const wchar_t* + decimal () + { + return L"decimal"; + } + + template<> + inline const wchar_t* + name () + { + return L"Name"; + } + + template<> + inline const wchar_t* + nmtoken () + { + return L"NMTOKEN"; + } + + template<> + inline const wchar_t* + nmtokens () + { + return L"NMTOKENS"; + } + + template<> + inline const wchar_t* + ncname () + { + return L"NCName"; + } + + template<> + inline const wchar_t* + id () + { + return L"ID"; + } + + template<> + inline const wchar_t* + idref () + { + return L"IDREF"; + } + + template<> + inline const wchar_t* + idrefs () + { + return L"IDREFS"; + } + + template<> + inline const wchar_t* + language () + { + return L"language"; + } + + template<> + inline const wchar_t* + qname () + { + return L"QName"; + } + + template<> + inline const wchar_t* + base64_binary () + { + return L"base64Binary"; + } + + template<> + inline const wchar_t* + hex_binary () + { + return L"hexBinary"; + } + + template<> + inline const wchar_t* + gday () + { + return L"gDay"; + } + + template<> + inline const wchar_t* + gmonth () + { + return L"gMonth"; + } + + template<> + inline const wchar_t* + gyear () + { + return L"gYear"; + } + + template<> + inline const wchar_t* + gmonth_day () + { + return L"gMonthDay"; + } + + template<> + inline const wchar_t* + gyear_month () + { + return L"gYearMonth"; + } + + template<> + inline const wchar_t* + date () + { + return L"date"; + } + + template<> + inline const wchar_t* + time () + { + return L"time"; + } + + template<> + inline const wchar_t* + date_time () + { + return L"dateTime"; + } + + template<> + inline const wchar_t* + duration () + { + return L"duration"; + } + + + // + // + template<> + inline const wchar_t* + positive_inf () + { + return L"INF"; + } + + template<> + inline const wchar_t* + negative_inf () + { + return L"-INF"; + } + + template<> + inline const wchar_t* + nan () + { + return L"NaN"; + } + + // + // + template<> + inline const wchar_t* + true_ () + { + return L"true"; + } + + template<> + inline const wchar_t* + false_ () + { + return L"false"; + } + + template<> + inline const wchar_t* + one () + { + return L"1"; + } + + template<> + inline const wchar_t* + zero () + { + return L"0"; + } + } + } + } + } +} + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_IXX_WCHAR +#endif // XSD_CXX_PARSER_USE_WCHAR diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx b/libxsd/xsd/cxx/parser/validating/xml-schema-pimpl.txx new file mode 100644 index 0000000..9dd30a3 --- /dev/null +++ b/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 +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include +#include + +#include +#include + +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 + struct char_table + { + static C table[0x80]; + }; + + template + C char_table::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 + void any_type_pimpl:: + post_any_type () + { + } + + // any_simple_type + // + + template + void any_simple_type_pimpl:: + post_any_simple_type () + { + } + + // boolean + // + + template + void boolean_pimpl:: + _pre () + { + str_.clear (); + } + + template + void boolean_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void boolean_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + if (str == bits::true_ () || str == bits::one ()) + value_ = true; + else if (str == bits::false_ () || str == bits::zero ()) + value_ = false; + else + throw invalid_value (bits::boolean (), str); + } + + template + bool boolean_pimpl:: + post_boolean () + { + return value_; + } + + // byte + // + + template + void byte_pimpl:: + _pre () + { + str_.clear (); + } + + template + void byte_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void byte_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + short t; + zc_istream is (str); + + if (is >> t && is.exhausted () && t >= -128 && t <= 127) + value_ = static_cast (t); + else + throw invalid_value (bits::byte (), str); + } + + template + signed char byte_pimpl:: + post_byte () + { + return value_; + } + + // unsigned_byte + // + + template + void unsigned_byte_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_byte_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void unsigned_byte_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + unsigned short t; + zc_istream is (str); + + if (is >> t && is.exhausted () && t <= 255) + value_ = static_cast (t); + else + throw invalid_value (bits::unsigned_byte (), str); + } + + template + unsigned char unsigned_byte_pimpl:: + post_unsigned_byte () + { + return value_; + } + + // short + // + + template + void short_pimpl:: + _pre () + { + str_.clear (); + } + + template + void short_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void short_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::short_ (), str); + } + + template + short short_pimpl:: + post_short () + { + return value_; + } + + + // unsigned_short + // + + template + void unsigned_short_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_short_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void unsigned_short_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::unsigned_short (), str); + } + + template + unsigned short unsigned_short_pimpl:: + post_unsigned_short () + { + return value_; + } + + // int + // + + template + void int_pimpl:: + _pre () + { + str_.clear (); + } + + template + void int_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void int_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::int_ (), str); + } + + template + int int_pimpl:: + post_int () + { + return value_; + } + + + // unsigned_int + // + + template + void unsigned_int_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_int_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void unsigned_int_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::unsigned_int (), str); + } + + template + unsigned int unsigned_int_pimpl:: + post_unsigned_int () + { + return value_; + } + + + // long + // + template + void long_pimpl:: + _pre () + { + str_.clear (); + } + + template + void long_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void long_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::long_ (), str); + } + + template + long long long_pimpl:: + post_long () + { + return value_; + } + + // unsigned_long + // + template + void unsigned_long_pimpl:: + _pre () + { + str_.clear (); + } + + template + void unsigned_long_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void unsigned_long_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::unsigned_long (), str); + } + + template + unsigned long long unsigned_long_pimpl:: + post_unsigned_long () + { + return value_; + } + + + // integer + // + template + void integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void integer_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::integer (), str); + } + + template + long long integer_pimpl:: + post_integer () + { + return value_; + } + + // negative_integer + // + template + void negative_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void negative_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void negative_integer_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted () && value_ < 0)) + throw invalid_value (bits::negative_integer (), str); + } + + template + long long negative_integer_pimpl:: + post_negative_integer () + { + return value_; + } + + + // non_positive_integer + // + template + void non_positive_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void non_positive_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void non_positive_integer_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted () && value_ <= 0)) + throw invalid_value (bits::non_positive_integer (), str); + } + + template + long long non_positive_integer_pimpl:: + post_non_positive_integer () + { + return value_; + } + + // positive_integer + // + template + void positive_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void positive_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void positive_integer_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted () && value_ > 0)) + throw invalid_value (bits::positive_integer (), str); + } + + template + unsigned long long positive_integer_pimpl:: + post_positive_integer () + { + return value_; + } + + + // non_negative_integer + // + template + void non_negative_integer_pimpl:: + _pre () + { + str_.clear (); + } + + template + void non_negative_integer_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void non_negative_integer_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::non_negative_integer (), str); + } + + template + unsigned long long non_negative_integer_pimpl:: + post_non_negative_integer () + { + return value_; + } + + + // float + // + template + void float_pimpl:: + _pre () + { + str_.clear (); + } + + template + void float_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void float_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + if (str == bits::positive_inf ()) + value_ = std::numeric_limits::infinity (); + else if (str == bits::negative_inf ()) + value_ = -std::numeric_limits::infinity (); + else if (str == bits::nan ()) + value_ = std::numeric_limits::quiet_NaN (); + else + { + zc_istream is (str); + is.imbue (std::locale::classic ()); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::float_ (), str); + } + } + + template + float float_pimpl:: + post_float () + { + return value_; + } + + + // double + // + template + void double_pimpl:: + _pre () + { + str_.clear (); + } + + template + void double_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void double_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + if (str == bits::positive_inf ()) + value_ = std::numeric_limits::infinity (); + else if (str == bits::negative_inf ()) + value_ = -std::numeric_limits::infinity (); + else if (str == bits::nan ()) + value_ = std::numeric_limits::quiet_NaN (); + else + { + zc_istream is (str); + is.imbue (std::locale::classic ()); + + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::double_ (), str); + } + } + + template + double double_pimpl:: + post_double () + { + return value_; + } + + // decimal + // + template + void decimal_pimpl:: + _pre () + { + str_.clear (); + } + + template + void decimal_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + void decimal_pimpl:: + _post () + { + ro_string str (str_); + trim (str); + + zc_istream is (str); + is.imbue (std::locale::classic ()); + + //@@ TODO: now we accept scientific notations and INF/NaN. + // + if (!(is >> value_ && is.exhausted ())) + throw invalid_value (bits::decimal (), str); + } + + template + double decimal_pimpl:: + post_decimal () + { + return value_; + } + + // string + // + template + void string_pimpl:: + _pre () + { + str_.clear (); + } + + template + void string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + std::basic_string string_pimpl:: + post_string () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // normalized_string + // + template + void normalized_string_pimpl:: + _pre () + { + str_.clear (); + } + + template + void normalized_string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + template + std::basic_string normalized_string_pimpl:: + post_normalized_string () + { + typedef typename std::basic_string::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 r; + r.swap (str_); + return r; + } + + // token + // + template + void token_pimpl:: + _pre () + { + str_.clear (); + } + + template + void token_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string token_pimpl:: + post_token () + { + typedef typename std::basic_string::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 r; + r.swap (str_); + return r; + } + + // name + // + template + void name_pimpl:: + _pre () + { + str_.clear (); + } + + template + void name_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void name_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (str_[0])); + + ok = c >= 0x80 || + (bits::char_table::table[c] & + bits::name_first_mask); + + if (ok) + { + for (size_type i (1); i < size; ++i) + { + c = static_cast (str_[i]); + + if (c < 0x80 && + !(bits::char_table::table[c] & + bits::name_mask)) + { + ok = false; + break; + } + } + } + } + + if (!ok) + throw invalid_value (bits::name (), tmp); + + str_.resize (size); + } + + template + std::basic_string name_pimpl:: + post_name () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // nmtoken + // + template + void nmtoken_pimpl:: + _pre () + { + str_.clear (); + } + + template + void nmtoken_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void nmtoken_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (str_[i])); + + if (c < 0x80 && + !(bits::char_table::table[c] & + bits::name_mask)) + { + ok = false; + break; + } + } + } + + if (!ok) + throw invalid_value (bits::nmtoken (), tmp); + + str_.resize (size); + } + + template + std::basic_string nmtoken_pimpl:: + post_nmtoken () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // nmtokens + // + template + void nmtokens_pimpl:: + _pre () + { + nmtokens_pskel::_pre (); + seq_.clear (); + } + + template + void nmtokens_pimpl:: + _post () + { + nmtokens_pskel::_post (); + + // Should have at least one element. + // + if (seq_.size () < 1) + { + ro_string tmp; + throw invalid_value (bits::nmtokens (), tmp); + } + } + + template + string_sequence nmtokens_pimpl:: + post_nmtokens () + { + string_sequence r; + r.swap (seq_); + return r; + } + + template + void nmtokens_pimpl:: + _xsd_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre (); + parser_._characters (s); + parser_._post (); + seq_.push_back (parser_.post_nmtoken ()); + } + + // ncname + // + namespace bits + { + template + bool + valid_ncname (const C* s, typename ro_string::size_type size) + { + typedef typename ro_string::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 (s[0])); + + ok = c >= 0x80 || + ((bits::char_table::table[c] & + bits::name_first_mask) && c != C (':')); + + if (ok) + { + for (size_type i (1); i < size; ++i) + { + c = static_cast (s[i]); + + if (c < 0x80 && + !(bits::char_table::table[c] & + bits::ncname_mask)) + { + ok = false; + break; + } + } + } + } + + return ok; + } + } + + template + void ncname_pimpl:: + _pre () + { + str_.clear (); + } + + template + void ncname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void ncname_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + if (!bits::valid_ncname (tmp.data (), size)) + throw invalid_value (bits::ncname (), tmp); + + str_.resize (size); + } + + template + std::basic_string ncname_pimpl:: + post_ncname () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // id + // + template + void id_pimpl:: + _pre () + { + str_.clear (); + } + + template + void id_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void id_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + if (!bits::valid_ncname (tmp.data (), size)) + throw invalid_value (bits::id (), tmp); + + str_.resize (size); + } + + template + std::basic_string id_pimpl:: + post_id () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // idref + // + template + void idref_pimpl:: + _pre () + { + str_.clear (); + } + + template + void idref_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void idref_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + if (!bits::valid_ncname (tmp.data (), size)) + throw invalid_value (bits::idref (), tmp); + + str_.resize (size); + } + + template + std::basic_string idref_pimpl:: + post_idref () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // idrefs + // + template + void idrefs_pimpl:: + _pre () + { + idrefs_pskel::_pre (); + seq_.clear (); + } + + template + void idrefs_pimpl:: + _post () + { + idrefs_pskel::_post (); + + // Should have at least one element. + // + if (seq_.size () < 1) + { + ro_string tmp; + throw invalid_value (bits::idrefs (), tmp); + } + } + + template + string_sequence idrefs_pimpl:: + post_idrefs () + { + string_sequence r; + r.swap (seq_); + return r; + } + + template + void idrefs_pimpl:: + _xsd_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre (); + parser_._characters (s); + parser_._post (); + seq_.push_back (parser_.post_idref ()); + } + + // language + // + template + void language_pimpl:: + _pre () + { + str_.clear (); + } + + template + void language_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void language_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (bits::language (), tmp); + + str_.resize (size); + } + + template + std::basic_string language_pimpl:: + post_language () + { + std::basic_string r; + r.swap (str_); + return r; + } + + // uri + // + template + void uri_pimpl:: + _pre () + { + str_.clear (); + } + + template + void uri_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + std::basic_string uri_pimpl:: + 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 tmp (str_); + str_.resize (trim_right (tmp)); + + std::basic_string r; + r.swap (str_); + return r; + } + + // qname + // + template + void qname_pimpl:: + _pre () + { + str_.clear (); + } + + template + void qname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void qname_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + size_type pos (tmp.find (C (':'))); + + const C* s (tmp.data ()); + + if (pos != ro_string::npos) + { + if (!bits::valid_ncname (s, pos) || + !bits::valid_ncname (s + pos + 1, size - pos - 1)) + throw invalid_value (bits::qname (), tmp); + + prefix_.assign (s, pos); + name_.assign (s + pos + 1, size - pos - 1); + } + else + { + if (!bits::valid_ncname (s, size)) + throw invalid_value (bits::qname (), tmp); + + prefix_.clear (); + str_.resize (size); + name_.swap (str_); + } + } + + template + qname qname_pimpl:: + post_qname () + { + return prefix_.empty () + ? qname (name_) + : qname (prefix_, name_); + } + + // base64_binary + // + template + void base64_binary_pimpl:: + _pre () + { + str_.clear (); + } + + template + void base64_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template + inline unsigned char + base64_decode (C c) + { + unsigned char r (0xFF); + + if (c >= C('A') && c <= C ('Z')) + r = static_cast (c - C ('A')); + else if (c >= C('a') && c <= C ('z')) + r = static_cast (c - C ('a') + 26); + else if (c >= C('0') && c <= C ('9')) + r = static_cast (c - C ('0') + 52); + else if (c == C ('+')) + r = 62; + else if (c == C ('/')) + r = 63; + + return r; + } + } + + template + void base64_binary_pimpl:: + _post () + { + typedef typename std::basic_string::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 (bits::base64_binary (), 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 (bits::base64_binary (), 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 (bits::base64_binary (), 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 (bits::base64_binary (), 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 (bits::base64_binary (), 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 (bits::base64_binary (), 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 + std::auto_ptr base64_binary_pimpl:: + post_base64_binary () + { + return buf_; + } + + // hex_binary + // + template + void hex_binary_pimpl:: + _pre () + { + str_.clear (); + } + + template + void hex_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template + inline unsigned char + hex_decode (C c) + { + unsigned char r (0xFF); + + if (c >= C('0') && c <= C ('9')) + r = static_cast (c - C ('0')); + else if (c >= C ('A') && c <= C ('F')) + r = static_cast (10 + (c - C ('A'))); + else if (c >= C ('a') && c <= C ('f')) + r = static_cast (10 + (c - C ('a'))); + + return r; + } + } + + template + void hex_binary_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size (trim_right (tmp)); + + if (size % 2 != 0) + throw invalid_value (bits::hex_binary (), 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 (bits::hex_binary (), tmp); + } + } + + template + std::auto_ptr hex_binary_pimpl:: + post_hex_binary () + { + return buf_; + } + + // time_zone + // + namespace bits + { + // Datatypes 3.2.7.3. Return false if time zone is invalid. + // + template + bool + parse_tz (const C* s, + typename std::basic_string::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 + void gday_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gday_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void gday_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (bits::gday (), tmp); + + C d1 (s[3]), d2 (s[4]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::gday (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value (bits::gday (), tmp); + + if (size > 5) + { + if (!bits::parse_tz (s + 5, size - 5, zh_, zm_)) + throw invalid_value (bits::gday (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + gday gday_pimpl:: + post_gday () + { + return z_ ? gday (day_, zh_, zm_) : gday (day_); + } + + // gmonth + // + template + void gmonth_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gmonth_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void gmonth_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (bits::gmonth (), tmp); + + C d1 (s[2]), d2 (s[3]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::gmonth (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value (bits::gmonth (), tmp); + + if (size > 4) + { + if (!bits::parse_tz (s + 4, size - 4, zh_, zm_)) + throw invalid_value (bits::gmonth (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + gmonth gmonth_pimpl:: + post_gmonth () + { + return z_ ? gmonth (month_, zh_, zm_) : gmonth (month_); + } + + // gyear + // + template + void gyear_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gyear_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void gyear_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (bits::gyear (), 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 year_fragment (s, pos); + zc_istream is (year_fragment); + + if (!(is >> year_ && is.exhausted () && year_ != 0)) + throw invalid_value (bits::gyear (), tmp); + + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value (bits::gyear (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + gyear gyear_pimpl:: + post_gyear () + { + return z_ ? gyear (year_, zh_, zm_) : gyear (year_); + } + + // gmonth_day + // + template + void gmonth_day_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gmonth_day_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void gmonth_day_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (bits::gmonth_day (), tmp); + + // month + // + C d1 (s[2]), d2 (s[3]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::gmonth_day (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value (bits::gmonth_day (), tmp); + + // day + // + d1 = s[5]; + d2 = s[6]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::gmonth_day (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value (bits::gmonth_day (), tmp); + + // zone + // + if (size > 7) + { + if (!bits::parse_tz (s + 7, size - 7, zh_, zm_)) + throw invalid_value (bits::gmonth_day (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + gmonth_day gmonth_day_pimpl:: + post_gmonth_day () + { + return z_ + ? gmonth_day (month_, day_, zh_, zm_) + : gmonth_day (month_, day_); + } + + // gyear_month + // + template + void gyear_month_pimpl:: + _pre () + { + str_.clear (); + } + + template + void gyear_month_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void gyear_month_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (bits::gyear_month (), tmp); + + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), s[0] == C ('-') ? 5 : 4)); + + if (pos == ro_string::npos || (size - pos - 1) < 2) + throw invalid_value (bits::gyear_month (), tmp); + + ro_string year_fragment (s, pos); + zc_istream yis (year_fragment); + + if (!(yis >> year_ && yis.exhausted () && year_ != 0)) + throw invalid_value (bits::gyear_month (), tmp); + + // month + // + C d1 (s[pos + 1]), d2 (s[pos + 2]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::gyear_month (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value (bits::gyear_month (), tmp); + + // zone + // + pos += 3; + + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value (bits::gyear_month (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + gyear_month gyear_month_pimpl:: + post_gyear_month () + { + return z_ + ? gyear_month (year_, month_, zh_, zm_) + : gyear_month (year_, month_); + } + + // date + // + template + void date_pimpl:: + _pre () + { + str_.clear (); + } + + template + void date_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void date_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (bits::date (), tmp); + + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), s[0] == C ('-') ? 5 : 4)); + + if (pos == ro_string::npos + || (size - pos - 1) < 5 + || s[pos + 3] != C ('-')) + throw invalid_value (bits::date (), tmp); + + ro_string year_fragment (s, pos); + zc_istream yis (year_fragment); + + if (!(yis >> year_ && yis.exhausted () && year_ != 0)) + throw invalid_value (bits::date (), tmp); + + // month + // + C d1 (s[pos + 1]), d2 (s[pos + 2]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::date (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value (bits::date (), tmp); + + // day + // + d1 = s[pos + 4]; + d2 = s[pos + 5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::date (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value (bits::date (), tmp); + + // zone + // + pos += 6; + + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value (bits::date (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + date date_pimpl:: + post_date () + { + return z_ + ? date (year_, month_, day_, zh_, zm_) + : date (year_, month_, day_); + } + + // time + // + template + void time_pimpl:: + _pre () + { + str_.clear (); + } + + template + void time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void time_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (bits::time (), tmp); + + // hours + // + C d1 (s[0]), d2 (s[1]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::time (), tmp); + + hours_ = 10 * (d1 - '0') + (d2 - '0'); + + if (hours_ > 24) + throw invalid_value (bits::time (), tmp); + + // minutes + // + d1 = s[3]; + d2 = s[4]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::time (), tmp); + + minutes_ = 10 * (d1 - '0') + (d2 - '0'); + + if (minutes_ > 59) + throw invalid_value (bits::time (), 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 (bits::time (), tmp); + + ro_string seconds_fragment (s + 6, pos - 6); + zc_istream sis (seconds_fragment); + + if (!(sis >> seconds_ && sis.exhausted () && seconds_ < 60.0)) + throw invalid_value (bits::time (), tmp); + + if (hours_ == 24 && (minutes_ != 0 || seconds_ != 0.0)) + throw invalid_value (bits::time (), tmp); + + // zone + // + if (pos < size) + { + if (!bits::parse_tz (s + pos, size - pos, zh_, zm_)) + throw invalid_value (bits::time (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + time time_pimpl:: + post_time () + { + return z_ + ? time (hours_, minutes_, seconds_, zh_, zm_) + : time (hours_, minutes_, seconds_); + } + + + // date_time + // + template + void date_time_pimpl:: + _pre () + { + str_.clear (); + } + + template + void date_time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + template + void date_time_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (bits::date_time (), tmp); + + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), s[0] == C ('-') ? 5 : 4)); + + if (pos == ro_string::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 (bits::date_time (), tmp); + + // year + // + ro_string year_fragment (s, pos); + zc_istream yis (year_fragment); + + if (!(yis >> year_ && yis.exhausted () && year_ != 0)) + throw invalid_value (bits::date_time (), tmp); + + // month + // + C d1 (s[pos + 1]), d2 (s[pos + 2]); + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::date_time (), tmp); + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + throw invalid_value (bits::date_time (), tmp); + + // day + // + d1 = s[pos + 4]; + d2 = s[pos + 5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::date_time (), tmp); + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + throw invalid_value (bits::date_time (), 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 (bits::date_time (), tmp); + + hours_ = 10 * (d1 - '0') + (d2 - '0'); + + if (hours_ > 24) + throw invalid_value (bits::date_time (), tmp); + + // minutes + // + d1 = s[pos + 3]; + d2 = s[pos + 4]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + throw invalid_value (bits::date_time (), tmp); + + minutes_ = 10 * (d1 - '0') + (d2 - '0'); + + if (minutes_ > 59) + throw invalid_value (bits::date_time (), 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 (bits::date_time (), tmp); + + ro_string seconds_fragment (s + pos, sec_end - pos); + zc_istream sis (seconds_fragment); + + if (!(sis >> seconds_ && sis.exhausted () && seconds_ < 60.0)) + throw invalid_value (bits::date_time (), tmp); + + if (hours_ == 24 && (minutes_ != 0 || seconds_ != 0.0)) + throw invalid_value (bits::date_time (), tmp); + + // zone + // + if (sec_end < size) + { + if (!bits::parse_tz (s + sec_end, size - sec_end, zh_, zm_)) + throw invalid_value (bits::date_time (), tmp); + + z_ = true; + } + else + z_ = false; + } + + template + date_time date_time_pimpl:: + 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 + void duration_pimpl:: + _pre () + { + str_.clear (); + } + + template + void duration_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + namespace bits + { + template + inline typename ro_string::size_type + duration_delim (const C* s, + typename ro_string::size_type pos, + typename ro_string::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 + void duration_pimpl:: + _post () + { + typedef typename ro_string::size_type size_type; + + ro_string 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 (bits::duration (), tmp); + + size_type pos (0); + + if (s[0] == C ('-')) + { + negative_ = true; + pos++; + } + + if (s[pos++] != C ('P')) + throw invalid_value (bits::duration (), tmp); + + size_type del (bits::duration_delim (s, pos, size)); + + // Duration should contain at least one component. + // + if (del == size) + throw invalid_value (bits::duration (), tmp); + + if (s[del] == C ('Y')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> years_ && is.exhausted ())) + throw invalid_value (bits::duration (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('M')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> months_ && is.exhausted ())) + throw invalid_value (bits::duration (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('D')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> days_ && is.exhausted ())) + throw invalid_value (bits::duration (), 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 (bits::duration (), tmp); + + if (s[del] == C ('H')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> hours_ && is.exhausted ())) + throw invalid_value (bits::duration (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('M')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> minutes_ && is.exhausted ())) + throw invalid_value (bits::duration (), tmp); + + pos = del + 1; + del = bits::duration_delim (s, pos, size); + } + + if (del != size && s[del] == C ('S')) + { + ro_string fragment (s + pos, del - pos); + zc_istream is (fragment); + + if (!(is >> seconds_ && is.exhausted () && seconds_ >= 0.0)) + throw invalid_value (bits::duration (), tmp); + + pos = del + 1; + } + } + + // Something did not match or appeared in the wrong order. + // + if (pos != size) + throw invalid_value (bits::duration (), tmp); + } + + template + duration duration_pimpl:: + post_duration () + { + return duration ( + negative_, years_, months_, days_, hours_, minutes_, seconds_); + } + } + } + } +} diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx b/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.hxx new file mode 100644 index 0000000..0fca037 --- /dev/null +++ b/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 +// copyright : Copyright (c) 2005-2009 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 +#include // auto_ptr + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // anyType and anySimpleType. All events are routed to the + // _any_* callbacks. + // + template + struct any_type_pskel: complex_content + { + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const ro_string*); + + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_type () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct any_simple_type_pskel: simple_content + { + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_simple_type () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Boolean. + // + template + struct boolean_pskel: simple_content + { + virtual bool + post_boolean () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 8-bit + // + template + struct byte_pskel: simple_content + { + virtual signed char + post_byte () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_byte_pskel: simple_content + { + virtual unsigned char + post_unsigned_byte () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 16-bit + // + template + struct short_pskel: simple_content + { + virtual short + post_short () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_short_pskel: simple_content + { + virtual unsigned short + post_unsigned_short () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 32-bit + // + template + struct int_pskel: simple_content + { + virtual int + post_int () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_int_pskel: simple_content + { + virtual unsigned int + post_unsigned_int () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // 64-bit + // + template + struct long_pskel: simple_content + { + virtual long long + post_long () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct unsigned_long_pskel: simple_content + { + virtual unsigned long long + post_unsigned_long () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Arbitrary-length integers. + // + template + struct integer_pskel: simple_content + { + virtual long long + post_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct negative_integer_pskel: simple_content + { + virtual long long + post_negative_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct non_positive_integer_pskel: simple_content + { + virtual long long + post_non_positive_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct positive_integer_pskel: simple_content + { + virtual unsigned long long + post_positive_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct non_negative_integer_pskel: simple_content + { + virtual unsigned long long + post_non_negative_integer () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Floats. + // + template + struct float_pskel: simple_content + { + virtual float + post_float () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct double_pskel: simple_content + { + virtual double + post_double () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct decimal_pskel: simple_content + { + virtual double + post_decimal () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + + // Strings. + // + template + struct string_pskel: simple_content + { + virtual std::basic_string + post_string () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct normalized_string_pskel: simple_content + { + virtual std::basic_string + post_normalized_string () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct token_pskel: simple_content + { + virtual std::basic_string + post_token () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct name_pskel: simple_content + { + virtual std::basic_string + post_name () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct nmtoken_pskel: simple_content + { + virtual std::basic_string + post_nmtoken () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct nmtokens_pskel: list_base + { + virtual string_sequence + post_nmtokens () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct ncname_pskel: simple_content + { + virtual std::basic_string + post_ncname () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct id_pskel: simple_content + { + virtual std::basic_string + post_id () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct idref_pskel: simple_content + { + virtual std::basic_string + post_idref () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct idrefs_pskel: list_base + { + virtual string_sequence + post_idrefs () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Language. + // + template + struct language_pskel: simple_content + { + virtual std::basic_string + post_language () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // URI. + // + template + struct uri_pskel: simple_content + { + virtual std::basic_string + post_uri () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // QName. + // + template + struct qname_pskel: simple_content + { + virtual qname + post_qname () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Base64 and hex binaries. + // + template + struct base64_binary_pskel: simple_content + { + virtual std::auto_ptr + post_base64_binary () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct hex_binary_pskel: simple_content + { + virtual std::auto_ptr + post_hex_binary () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + // Time and date types. + // + template + struct gday_pskel: simple_content + { + virtual gday + post_gday () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gmonth_pskel: simple_content + { + virtual gmonth + post_gmonth () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gyear_pskel: simple_content + { + virtual gyear + post_gyear () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gmonth_day_pskel: simple_content + { + virtual gmonth_day + post_gmonth_day () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct gyear_month_pskel: simple_content + { + virtual gyear_month + post_gyear_month () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct date_pskel: simple_content + { + virtual date + post_date () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct time_pskel: simple_content + { + virtual time + post_time () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct date_time_pskel: simple_content + { + virtual date_time + post_date_time () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + + template + struct duration_pskel: simple_content + { + virtual duration + post_duration () = 0; + + static const C* + _static_type (); + + virtual const C* + _dynamic_type () const; + }; + } + } + } +} + +#include + +#endif // XSD_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX + +#include diff --git a/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.ixx b/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.ixx new file mode 100644 index 0000000..7a9f5e5 --- /dev/null +++ b/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 +// copyright : Copyright (c) 2005-2009 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:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* any_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* any_simple_type_pskel:: + _static_type () + { + return "anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* any_simple_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* boolean_pskel:: + _static_type () + { + return "boolean http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* boolean_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* byte_pskel:: + _static_type () + { + return "byte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_byte_pskel:: + _static_type () + { + return "unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* short_pskel:: + _static_type () + { + return "short http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_short_pskel:: + _static_type () + { + return "unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* int_pskel:: + _static_type () + { + return "int http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_int_pskel:: + _static_type () + { + return "unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* long_pskel:: + _static_type () + { + return "long http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* unsigned_long_pskel:: + _static_type () + { + return "unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* unsigned_long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* integer_pskel:: + _static_type () + { + return "integer http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* negative_integer_pskel:: + _static_type () + { + return "negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* non_positive_integer_pskel:: + _static_type () + { + return "nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* non_positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* positive_integer_pskel:: + _static_type () + { + return "positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* non_negative_integer_pskel:: + _static_type () + { + return "nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* non_negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* float_pskel:: + _static_type () + { + return "float http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* float_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* double_pskel:: + _static_type () + { + return "double http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* double_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* decimal_pskel:: + _static_type () + { + return "decimal http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* decimal_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* string_pskel:: + _static_type () + { + return "string http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* normalized_string_pskel:: + _static_type () + { + return "normalizedString http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* normalized_string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* token_pskel:: + _static_type () + { + return "token http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* token_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* name_pskel:: + _static_type () + { + return "Name http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* name_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* nmtoken_pskel:: + _static_type () + { + return "NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* nmtoken_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* nmtokens_pskel:: + _static_type () + { + return "NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* nmtokens_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* ncname_pskel:: + _static_type () + { + return "NCName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* ncname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* id_pskel:: + _static_type () + { + return "ID http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* id_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* idref_pskel:: + _static_type () + { + return "IDREF http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* idref_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* idrefs_pskel:: + _static_type () + { + return "IDREFS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* idrefs_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* language_pskel:: + _static_type () + { + return "language http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* language_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* uri_pskel:: + _static_type () + { + return "anyURI http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* uri_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* qname_pskel:: + _static_type () + { + return "QName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* qname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* base64_binary_pskel:: + _static_type () + { + return "base64Binary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* base64_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* hex_binary_pskel:: + _static_type () + { + return "hexBinary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* hex_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gday_pskel:: + _static_type () + { + return "gDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gday_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gmonth_pskel:: + _static_type () + { + return "gMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gmonth_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gyear_pskel:: + _static_type () + { + return "gYear http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gyear_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gmonth_day_pskel:: + _static_type () + { + return "gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gmonth_day_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* gyear_month_pskel:: + _static_type () + { + return "gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* gyear_month_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* date_pskel:: + _static_type () + { + return "date http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* date_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* time_pskel:: + _static_type () + { + return "time http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* date_time_pskel:: + _static_type () + { + return "dateTime http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* date_time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const char* duration_pskel:: + _static_type () + { + return "duration http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const char* duration_pskel:: + _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:: + _static_type () + { + return L"anyType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* any_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* any_simple_type_pskel:: + _static_type () + { + return L"anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* any_simple_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* boolean_pskel:: + _static_type () + { + return L"boolean http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* boolean_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* byte_pskel:: + _static_type () + { + return L"byte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_byte_pskel:: + _static_type () + { + return L"unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* short_pskel:: + _static_type () + { + return L"short http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_short_pskel:: + _static_type () + { + return L"unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* int_pskel:: + _static_type () + { + return L"int http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_int_pskel:: + _static_type () + { + return L"unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* long_pskel:: + _static_type () + { + return L"long http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* unsigned_long_pskel:: + _static_type () + { + return L"unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* unsigned_long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* integer_pskel:: + _static_type () + { + return L"integer http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* negative_integer_pskel:: + _static_type () + { + return L"negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* non_positive_integer_pskel:: + _static_type () + { + return L"nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* non_positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* positive_integer_pskel:: + _static_type () + { + return L"positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* non_negative_integer_pskel:: + _static_type () + { + return L"nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* non_negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* float_pskel:: + _static_type () + { + return L"float http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* float_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* double_pskel:: + _static_type () + { + return L"double http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* double_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* decimal_pskel:: + _static_type () + { + return L"decimal http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* decimal_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* string_pskel:: + _static_type () + { + return L"string http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* normalized_string_pskel:: + _static_type () + { + return L"normalizedString http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* normalized_string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* token_pskel:: + _static_type () + { + return L"token http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* token_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* name_pskel:: + _static_type () + { + return L"Name http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* name_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* nmtoken_pskel:: + _static_type () + { + return L"NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* nmtoken_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* nmtokens_pskel:: + _static_type () + { + return L"NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* nmtokens_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* ncname_pskel:: + _static_type () + { + return L"NCName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* ncname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* id_pskel:: + _static_type () + { + return L"ID http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* id_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* idref_pskel:: + _static_type () + { + return L"IDREF http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* idref_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* idrefs_pskel:: + _static_type () + { + return L"IDREFS http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* idrefs_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* language_pskel:: + _static_type () + { + return L"language http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* language_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* uri_pskel:: + _static_type () + { + return L"anyURI http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* uri_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* qname_pskel:: + _static_type () + { + return L"QName http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* qname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* base64_binary_pskel:: + _static_type () + { + return L"base64Binary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* base64_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* hex_binary_pskel:: + _static_type () + { + return L"hexBinary http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* hex_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gday_pskel:: + _static_type () + { + return L"gDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gday_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gmonth_pskel:: + _static_type () + { + return L"gMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gmonth_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gyear_pskel:: + _static_type () + { + return L"gYear http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gyear_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gmonth_day_pskel:: + _static_type () + { + return L"gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gmonth_day_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* gyear_month_pskel:: + _static_type () + { + return L"gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* gyear_month_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* date_pskel:: + _static_type () + { + return L"date http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* date_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* time_pskel:: + _static_type () + { + return L"time http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* date_time_pskel:: + _static_type () + { + return L"dateTime http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* date_time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + template<> + inline const wchar_t* duration_pskel:: + _static_type () + { + return L"duration http://www.w3.org/2001/XMLSchema"; + } + + template<> + inline const wchar_t* duration_pskel:: + _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/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.txx b/libxsd/xsd/cxx/parser/validating/xml-schema-pskel.txx new file mode 100644 index 0000000..c5fe5ef --- /dev/null +++ b/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 +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type + // + + template + bool any_type_pskel:: + _start_element_impl (const ro_string& ns, + const ro_string& name, + const ro_string* type) + { + _start_any_element (ns, name, type); + this->complex_content::context_.top ().any_ = true; + return true; + } + + template + bool any_type_pskel:: + _end_element_impl (const ro_string& ns, const ro_string& name) + { + this->complex_content::context_.top ().any_ = false; + _end_any_element (ns, name); + return true; + } + + + template + bool any_type_pskel:: + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + _any_attribute (ns, name, value); + return true; + } + + template + bool any_type_pskel:: + _characters_impl (const ro_string& s) + { + _any_characters (s); + return true; + } + + // any_simple_type + // + + template + bool any_simple_type_pskel:: + _characters_impl (const ro_string& s) + { + _any_characters (s); + return true; + } + } + } + } +} -- cgit v1.1