diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-12-18 18:48:46 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-01-13 22:32:43 +0300 |
commit | 2615896faa646e5830abf2c269150e1165c66515 (patch) | |
tree | 7d95978ec0a83094c9462ed4e1f59d42f4ff8ddb /libxsd/libxsd/cxx/parser/document.txx | |
parent | 7420f85ea19b0562ffdd8123442f32bc8bac1267 (diff) |
Switch to build2
Diffstat (limited to 'libxsd/libxsd/cxx/parser/document.txx')
-rw-r--r-- | libxsd/libxsd/cxx/parser/document.txx | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/libxsd/libxsd/cxx/parser/document.txx b/libxsd/libxsd/cxx/parser/document.txx new file mode 100644 index 0000000..4d7b5ba --- /dev/null +++ b/libxsd/libxsd/cxx/parser/document.txx @@ -0,0 +1,127 @@ +// file : libxsd/cxx/parser/document.txx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <cassert> + +#include <libxsd/cxx/parser/schema-exceptions.hxx> + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // document + // + template <typename C> + document<C>:: + ~document () + { + } + + template <typename C> + document<C>:: + document (parser_base<C>& root, + const std::basic_string<C>& ns, + const std::basic_string<C>& name) + : root_ (&root), ns_ (ns), name_ (name), depth_ (0) + { + } + + template <typename C> + document<C>:: + document () + : root_ (0), depth_ (0) + { + } + + template <typename C> + void document<C>:: + start_element (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>* type) + { + if (depth_++ > 0) + { + if (root_) + root_->_start_element (ns, name, type); + } + else + { + root_ = start_root_element (ns, name, type); + + if (root_) + { + // pre () is called by the user. + // + root_->_pre_impl (); + } + } + } + + template <typename C> + void document<C>:: + end_element (const ro_string<C>& ns, const ro_string<C>& name) + { + assert (depth_ > 0); + + if (--depth_ > 0) + { + if (root_) + root_->_end_element (ns, name); + } + else + { + if (root_) + { + root_->_post_impl (); + // + // post() is called by the user. + } + + end_root_element (ns, name, root_); + } + } + + template <typename C> + void document<C>:: + attribute (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>& value) + { + if (root_) + root_->_attribute (ns, name, value); + } + + template <typename C> + void document<C>:: + characters (const ro_string<C>& s) + { + if (root_) + root_->_characters (s); + } + + template <typename C> + parser_base<C>* document<C>:: + start_root_element (const ro_string<C>& ns, + const ro_string<C>& name, + const ro_string<C>*) + { + if (name_ == name && ns_ == ns) + { + return root_; + } + else + throw expected_element<C> (ns_, name_, ns, name); + } + + template <typename C> + void document<C>:: + end_root_element (const ro_string<C>&, + const ro_string<C>&, + parser_base<C>*) + { + } + } + } +} |