diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-03-16 07:44:43 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-04-10 18:46:43 +0200 |
commit | 08b159e18527c2d6844e569b1309b5033b4d47c9 (patch) | |
tree | 224a1d6e7c989740e9be806c0f3cc7fc20266eb2 /odb/semantics/relational/key.cxx | |
parent | 9fe60de16cf9411a548c020cae5ac7b9e7938e82 (diff) |
Add initial support for database model serialization to XML
Diffstat (limited to 'odb/semantics/relational/key.cxx')
-rw-r--r-- | odb/semantics/relational/key.cxx | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/odb/semantics/relational/key.cxx b/odb/semantics/relational/key.cxx index e80366c..2358562 100644 --- a/odb/semantics/relational/key.cxx +++ b/odb/semantics/relational/key.cxx @@ -3,13 +3,54 @@ // license : GNU GPL v3; see accompanying LICENSE file #include <cutl/compiler/type-info.hxx> - -#include <odb/semantics/relational/key.hxx> +#include <odb/semantics/relational.hxx> namespace semantics { namespace relational { + key:: + key (xml::parser& p, uscope& s, graph& g) + : unameable (p, g) + { + using namespace xml; + p.content (parser::complex); + + for (parser::event_type e (p.peek ()); + e == parser::start_element; + e = p.peek ()) + { + if (p.qname () != xml::qname (xmlns, "column")) + break; // Not our elements. + + p.next (); + p.content (parser::empty); + + uname n (p.attribute<uname> ("name")); + column* c (s.find<column> (n)); + if (c == 0) + throw parsing (p, "invalid column name in the 'name' attribute"); + + string o (p.attribute ("options", string ())); + g.new_edge<contains> (*this, *c, o); + + p.next_expect (parser::end_element); + } + } + + void key:: + serialize_content (xml::serializer& s) const + { + for (contains_iterator i (contains_begin ()); i != contains_end (); ++i) + { + s.start_element (xmlns, "column"); + s.attribute ("name", i->column ().name ()); + if (!i->options ().empty ()) + s.attribute ("options", i->options ()); + s.end_element (); + } + } + // type info // namespace |