summaryrefslogtreecommitdiff
path: root/odb/semantics
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-03-18 08:42:38 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-04-10 18:46:43 +0200
commitab135a6c31cd0e8c8b63b78781baa22442c1c129 (patch)
treea98a9cdf2e844a573e00e60264b437ce124339df /odb/semantics
parent08b159e18527c2d6844e569b1309b5033b4d47c9 (diff)
Add changelog, changeset, and add_table semantics nodes
Diffstat (limited to 'odb/semantics')
-rw-r--r--odb/semantics/relational.hxx2
-rw-r--r--odb/semantics/relational/changelog.cxx116
-rw-r--r--odb/semantics/relational/changelog.hxx137
-rw-r--r--odb/semantics/relational/changeset.cxx47
-rw-r--r--odb/semantics/relational/changeset.hxx42
-rw-r--r--odb/semantics/relational/elements.hxx2
-rw-r--r--odb/semantics/relational/foreign-key.cxx1
-rw-r--r--odb/semantics/relational/index.cxx1
-rw-r--r--odb/semantics/relational/model.cxx7
-rw-r--r--odb/semantics/relational/model.hxx2
-rw-r--r--odb/semantics/relational/primary-key.cxx1
-rw-r--r--odb/semantics/relational/table.cxx25
-rw-r--r--odb/semantics/relational/table.hxx13
13 files changed, 386 insertions, 10 deletions
diff --git a/odb/semantics/relational.hxx b/odb/semantics/relational.hxx
index 0dcc645..c2a6395 100644
--- a/odb/semantics/relational.hxx
+++ b/odb/semantics/relational.hxx
@@ -5,6 +5,8 @@
#ifndef ODB_SEMANTICS_RELATIONAL_HXX
#define ODB_SEMANTICS_RELATIONAL_HXX
+#include <odb/semantics/relational/changelog.hxx>
+#include <odb/semantics/relational/changeset.hxx>
#include <odb/semantics/relational/column.hxx>
#include <odb/semantics/relational/elements.hxx>
#include <odb/semantics/relational/foreign-key.hxx>
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 <vector>
+
+#include <cutl/compiler/type-info.hxx>
+#include <odb/semantics/relational.hxx>
+
+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<unsigned int> ("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<changeset*> 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<changeset> (p, *this));
+ p.next_expect (parser::end_element);
+ }
+
+ for (changesets::reverse_iterator i (cs.rbegin ()); i != cs.rend (); ++i)
+ new_edge<contains_changeset> (*this, **i);
+
+ // Get the model.
+ //
+ p.next_expect (parser::start_element, xmlns, "model");
+
+ model_type& m (new_node<model_type> (p, *this));
+ new_edge<contains_model_type> (*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_;
+ }
+ }
+}
diff --git a/odb/semantics/relational/changelog.hxx b/odb/semantics/relational/changelog.hxx
new file mode 100644
index 0000000..ed2323f
--- /dev/null
+++ b/odb/semantics/relational/changelog.hxx
@@ -0,0 +1,137 @@
+// file : odb/semantics/relational/changelog.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_SEMANTICS_RELATIONAL_CHANGELOG_HXX
+#define ODB_SEMANTICS_RELATIONAL_CHANGELOG_HXX
+
+#include <odb/semantics/relational/elements.hxx>
+
+namespace semantics
+{
+ namespace relational
+ {
+ class model;
+ class changeset;
+ class changelog;
+
+ class contains_model: public edge
+ {
+ public:
+ typedef relational::changelog changelog_type;
+ typedef relational::model model_type;
+
+ changelog_type&
+ changelog () const {return *changelog_;}
+
+ model_type&
+ model () const {return *model_;}
+
+ public:
+ void
+ set_left_node (changelog_type& n) {changelog_ = &n;}
+
+ void
+ set_right_node (model_type& n) {model_ = &n;}
+
+ protected:
+ changelog_type* changelog_;
+ model_type* model_;
+ };
+
+ class contains_changeset: public edge
+ {
+ public:
+ typedef relational::changelog changelog_type;
+ typedef relational::changeset changeset_type;
+
+ changelog_type&
+ changelog () const {return *changelog_;}
+
+ changeset_type&
+ changeset () const {return *changeset_;}
+
+ public:
+ void
+ set_left_node (changelog_type& n) {changelog_ = &n;}
+
+ void
+ set_right_node (changeset_type& n) {changeset_ = &n;}
+
+ protected:
+ changelog_type* changelog_;
+ changeset_type* changeset_;
+ };
+
+ class changelog: public graph, public node
+ {
+ typedef std::vector<contains_changeset*> contains_changeset_list;
+
+ public:
+ typedef relational::model model_type;
+ typedef relational::contains_model contains_model_type;
+
+ model_type&
+ model () const {return contains_model_->model ();}
+
+ contains_model_type&
+ contains_model () const {return *contains_model_;}
+
+ public:
+ typedef
+ pointer_iterator<contains_changeset_list::const_iterator>
+ contains_changeset_iterator;
+
+ contains_changeset_iterator
+ contains_changeset_begin () const
+ {
+ return contains_changeset_.begin ();
+ }
+
+ contains_changeset_iterator
+ contains_changeset_end () const
+ {
+ return contains_changeset_.end ();
+ }
+
+ contains_changeset_list::size_type
+ contains_changeset_size () const
+ {
+ return contains_changeset_.size ();
+ }
+
+ public:
+ changelog (): contains_model_ (0) {}
+ changelog (xml::parser&);
+
+ void
+ add_edge_left (contains_model_type& e)
+ {
+ assert (contains_model_ == 0);
+ contains_model_ = &e;
+ }
+
+ void
+ add_edge_left (contains_changeset& e)
+ {
+ contains_changeset_.push_back (&e);
+ }
+
+ virtual string
+ kind () const {return "changelog";}
+
+ virtual void
+ serialize (xml::serializer&) const;
+
+ private:
+ changelog (changelog const&);
+ changelog& operator= (changelog const&);
+
+ protected:
+ contains_model_type* contains_model_;
+ contains_changeset_list contains_changeset_;
+ };
+ }
+}
+
+#endif // ODB_SEMANTICS_RELATIONAL_CHANGELOG_HXX
diff --git a/odb/semantics/relational/changeset.cxx b/odb/semantics/relational/changeset.cxx
new file mode 100644
index 0000000..ecf02a2
--- /dev/null
+++ b/odb/semantics/relational/changeset.cxx
@@ -0,0 +1,47 @@
+// file : odb/semantics/relational/changeset.cxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#include <cutl/compiler/type-info.hxx>
+#include <odb/semantics/relational.hxx>
+
+namespace semantics
+{
+ namespace relational
+ {
+ changeset::
+ changeset (xml::parser& p, graph& g)
+ : qscope (p, g),
+ version_ (p.attribute<version_type> ("version"))
+ {
+ }
+
+ void changeset::
+ serialize (xml::serializer& s) const
+ {
+ s.start_element (xmlns, "changeset");
+ s.attribute ("version", version_);
+ qscope::serialize_content (s);
+ s.end_element ();
+ }
+
+ // type info
+ //
+ namespace
+ {
+ struct init
+ {
+ init ()
+ {
+ using compiler::type_info;
+
+ {
+ type_info ti (typeid (changeset));
+ ti.add_base (typeid (qscope));
+ insert (ti);
+ }
+ }
+ } init_;
+ }
+ }
+}
diff --git a/odb/semantics/relational/changeset.hxx b/odb/semantics/relational/changeset.hxx
new file mode 100644
index 0000000..74e665b
--- /dev/null
+++ b/odb/semantics/relational/changeset.hxx
@@ -0,0 +1,42 @@
+// file : odb/semantics/relational/changeset.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_SEMANTICS_RELATIONAL_CHANGESET_HXX
+#define ODB_SEMANTICS_RELATIONAL_CHANGESET_HXX
+
+#include <odb/semantics/relational/elements.hxx>
+
+namespace semantics
+{
+ namespace relational
+ {
+ class changeset: public qscope
+ {
+ public:
+ typedef relational::version version_type;
+
+ version_type
+ version () const {return version_;}
+
+ public:
+ changeset (version_type v): version_ (v) {}
+ changeset (xml::parser&, graph&);
+
+ virtual string
+ kind () const {return "changeset";}
+
+ virtual void
+ serialize (xml::serializer&) const;
+
+ public:
+ using qscope::add_edge_left;
+ using qscope::add_edge_right;
+
+ private:
+ version_type version_;
+ };
+ }
+}
+
+#endif // ODB_SEMANTICS_RELATIONAL_CHANGESET_HXX
diff --git a/odb/semantics/relational/elements.hxx b/odb/semantics/relational/elements.hxx
index 76a92bc..8dde6bc 100644
--- a/odb/semantics/relational/elements.hxx
+++ b/odb/semantics/relational/elements.hxx
@@ -31,7 +31,7 @@ namespace semantics
using container::pointer_iterator;
using compiler::context;
- typedef unsigned int version;
+ typedef unsigned long long version;
//
//
diff --git a/odb/semantics/relational/foreign-key.cxx b/odb/semantics/relational/foreign-key.cxx
index 2c73a82..52316bb 100644
--- a/odb/semantics/relational/foreign-key.cxx
+++ b/odb/semantics/relational/foreign-key.cxx
@@ -118,7 +118,6 @@ namespace semantics
{
type_info ti (typeid (foreign_key));
- ti.add_base (typeid (unameable));
ti.add_base (typeid (key));
insert (ti);
}
diff --git a/odb/semantics/relational/index.cxx b/odb/semantics/relational/index.cxx
index 0e62f98..46cc75c 100644
--- a/odb/semantics/relational/index.cxx
+++ b/odb/semantics/relational/index.cxx
@@ -51,7 +51,6 @@ namespace semantics
{
type_info ti (typeid (index));
- ti.add_base (typeid (qnameable));
ti.add_base (typeid (key));
insert (ti);
}
diff --git a/odb/semantics/relational/model.cxx b/odb/semantics/relational/model.cxx
index a9fe111..bdb95d6 100644
--- a/odb/semantics/relational/model.cxx
+++ b/odb/semantics/relational/model.cxx
@@ -10,8 +10,8 @@ namespace semantics
namespace relational
{
model::
- model (xml::parser& p)
- : qscope (p, *this),
+ model (xml::parser& p, graph& g)
+ : qscope (p, g),
version_ (p.attribute<version_type> ("version"))
{
}
@@ -20,7 +20,6 @@ namespace semantics
serialize (xml::serializer& s) const
{
s.start_element (xmlns, "model");
- s.namespace_decl (xmlns, ""); // @@ evo
s.attribute ("version", version_);
qscope::serialize_content (s);
s.end_element ();
@@ -36,8 +35,6 @@ namespace semantics
{
using compiler::type_info;
- // model
- //
{
type_info ti (typeid (model));
ti.add_base (typeid (qscope));
diff --git a/odb/semantics/relational/model.hxx b/odb/semantics/relational/model.hxx
index 31715eb..04fb729 100644
--- a/odb/semantics/relational/model.hxx
+++ b/odb/semantics/relational/model.hxx
@@ -21,7 +21,7 @@ namespace semantics
public:
model (version_type v): version_ (v) {}
- model (xml::parser&);
+ model (xml::parser&, graph&);
virtual string
kind () const {return "model";}
diff --git a/odb/semantics/relational/primary-key.cxx b/odb/semantics/relational/primary-key.cxx
index 480923d..6bcab33 100644
--- a/odb/semantics/relational/primary-key.cxx
+++ b/odb/semantics/relational/primary-key.cxx
@@ -42,7 +42,6 @@ namespace semantics
{
type_info ti (typeid (primary_key));
- ti.add_base (typeid (unameable));
ti.add_base (typeid (key));
insert (ti);
}
diff --git a/odb/semantics/relational/table.cxx b/odb/semantics/relational/table.cxx
index aac50fe..4eeaf0d 100644
--- a/odb/semantics/relational/table.cxx
+++ b/odb/semantics/relational/table.cxx
@@ -9,6 +9,8 @@ namespace semantics
{
namespace relational
{
+ // table
+ //
table::
table (xml::parser& p, qscope&, graph& g)
: qnameable (p, g), uscope (p, g)
@@ -24,6 +26,17 @@ namespace semantics
s.end_element ();
}
+ // add_table
+ //
+ void add_table::
+ serialize (xml::serializer& s) const
+ {
+ s.start_element (xmlns, "add-table");
+ table::serialize_attributes (s);
+ table::serialize_content (s);
+ s.end_element ();
+ }
+
// type info
//
namespace
@@ -33,15 +46,27 @@ namespace semantics
init ()
{
qnameable::parser_map_["table"] = &qnameable::parser_impl<table>;
+ qnameable::parser_map_["add-table"] =
+ &qnameable::parser_impl<add_table>;
using compiler::type_info;
+ // table
+ //
{
type_info ti (typeid (table));
ti.add_base (typeid (qnameable));
ti.add_base (typeid (uscope));
insert (ti);
}
+
+ // add_table
+ //
+ {
+ type_info ti (typeid (add_table));
+ ti.add_base (typeid (table));
+ insert (ti);
+ }
}
} init_;
}
diff --git a/odb/semantics/relational/table.hxx b/odb/semantics/relational/table.hxx
index a57a7db..5a38e6d 100644
--- a/odb/semantics/relational/table.hxx
+++ b/odb/semantics/relational/table.hxx
@@ -27,6 +27,19 @@ namespace semantics
//
using qnameable::scope;
};
+
+ class add_table: public table
+ {
+ public:
+ add_table (string const& id): table (id) {}
+ add_table (xml::parser& p, qscope& s, graph& g): table (p, s, g) {}
+
+ virtual string
+ kind () const {return "add table";}
+
+ virtual void
+ serialize (xml::serializer&) const;
+ };
}
}