From ab135a6c31cd0e8c8b63b78781baa22442c1c129 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 Mar 2013 08:42:38 +0200 Subject: Add changelog, changeset, and add_table semantics nodes --- odb/semantics/relational/changelog.cxx | 116 +++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 odb/semantics/relational/changelog.cxx (limited to 'odb/semantics/relational/changelog.cxx') diff --git a/odb/semantics/relational/changelog.cxx b/odb/semantics/relational/changelog.cxx new file mode 100644 index 0000000..c8a4053 --- /dev/null +++ b/odb/semantics/relational/changelog.cxx @@ -0,0 +1,116 @@ +// file : odb/semantics/relational/changelog.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : GNU GPL v3; see accompanying LICENSE file + +#include + +#include +#include + +namespace semantics +{ + namespace relational + { + changelog:: + changelog (xml::parser& p) + : contains_model_ (0) + { + using namespace xml; + + p.next_expect (parser::start_element, xmlns, "changelog"); + p.content (parser::complex); + + if (p.attribute ("version") != 1) + throw parsing (p, "unsupported changelog format version"); + + // Get the changesets. Because they are stored in the reverse order, + // first save them to the temporary vector. + // + typedef std::vector changesets; + changesets cs; + + for (parser::event_type e (p.peek ()); + e == parser::start_element; + e = p.peek ()) + { + if (p.qname () != xml::qname (xmlns, "changeset")) + break; // Not our elements. + + p.next (); + cs.push_back (&new_node (p, *this)); + p.next_expect (parser::end_element); + } + + for (changesets::reverse_iterator i (cs.rbegin ()); i != cs.rend (); ++i) + new_edge (*this, **i); + + // Get the model. + // + p.next_expect (parser::start_element, xmlns, "model"); + + model_type& m (new_node (p, *this)); + new_edge (*this, m); + + p.next_expect (parser::end_element); + p.next_expect (parser::end_element); + } + + void changelog:: + serialize (xml::serializer& s) const + { + s.start_element (xmlns, "changelog"); + s.namespace_decl (xmlns, ""); + s.attribute ("version", 1); // Format version. + + // For better readability serialize things in reverse order so that + // the most recent changeset appears first. + // + for (contains_changeset_list::const_reverse_iterator i ( + contains_changeset_.rbegin ()); + i != contains_changeset_.rend (); ++i) + { + (*i)->changeset ().serialize (s); + } + + model ().serialize (s); + s.end_element (); + } + + // type info + // + namespace + { + struct init + { + init () + { + using compiler::type_info; + + // contains_model + // + { + type_info ti (typeid (contains_model)); + ti.add_base (typeid (edge)); + insert (ti); + } + + // contains_changeset + // + { + type_info ti (typeid (contains_changeset)); + ti.add_base (typeid (edge)); + insert (ti); + } + + // changelog + // + { + type_info ti (typeid (changelog)); + ti.add_base (typeid (node)); + insert (ti); + } + } + } init_; + } + } +} -- cgit v1.1