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/document.txx | 129 +++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 libxsd/xsd/cxx/parser/document.txx (limited to 'libxsd/xsd/cxx/parser/document.txx') diff --git a/libxsd/xsd/cxx/parser/document.txx b/libxsd/xsd/cxx/parser/document.txx new file mode 100644 index 0000000..451eb71 --- /dev/null +++ b/libxsd/xsd/cxx/parser/document.txx @@ -0,0 +1,129 @@ +// file : xsd/cxx/parser/document.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace parser + { + // document + // + template + document:: + ~document () + { + } + + template + document:: + document (parser_base& root, + const std::basic_string& ns, + const std::basic_string& name) + : root_ (&root), ns_ (ns), name_ (name), depth_ (0) + { + } + + template + document:: + document () + : root_ (0), depth_ (0) + { + } + + template + void document:: + start_element (const ro_string& ns, + const ro_string& name, + const ro_string* 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 + void document:: + end_element (const ro_string& ns, const ro_string& 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 + void document:: + attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + if (root_) + root_->_attribute (ns, name, value); + } + + template + void document:: + characters (const ro_string& s) + { + if (root_) + root_->_characters (s); + } + + template + parser_base* document:: + start_root_element (const ro_string& ns, + const ro_string& name, + const ro_string*) + { + if (name_ == name && ns_ == ns) + { + return root_; + } + else + throw expected_element (ns_, name_, ns, name); + } + + template + void document:: + end_root_element (const ro_string&, + const ro_string&, + parser_base*) + { + } + } + } +} -- cgit v1.1