diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-04-25 11:29:06 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-04-25 11:29:06 +0200 |
commit | 82d1a3918899958cb26ed77119fbf908beb94dbc (patch) | |
tree | 9b58aaff1435f8142dfa8685c8b3e84922492016 /odb/relational/header.hxx | |
parent | bbd0aa5d1f6e58dbbe900d2f15692fa2b24ed1f1 (diff) |
Reuse container traits from base objects
Diffstat (limited to 'odb/relational/header.hxx')
-rw-r--r-- | odb/relational/header.hxx | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/odb/relational/header.hxx b/odb/relational/header.hxx index 944a997..9e258ea 100644 --- a/odb/relational/header.hxx +++ b/odb/relational/header.hxx @@ -181,7 +181,10 @@ namespace relational { typedef container_traits base; - container_traits (): object_members_base (true, false) {} + container_traits (semantics::class_& obj) + : object_members_base (true, false), object_ (obj) + { + } virtual void container (semantics::data_member& m) @@ -189,6 +192,10 @@ namespace relational using semantics::type; using semantics::class_; + // Figure out if this member is from a base object. + // + bool base (context::object != &object_); + type& t (m.type ()); container_kind_type ck (container_kind (t)); @@ -293,8 +300,34 @@ namespace relational os << "// " << m.name () << endl << "//" << endl - << "struct " << name - << "{"; + << "struct " << name; + + if (base) + os << ": access::object_traits< " << context::object->fq_name () << + " >::" << name; + + os << "{"; + + // column_count + // + os << "static const std::size_t cond_column_count = " << + cond_columns << "UL;" + << "static const std::size_t data_column_count = " << + data_columns << "UL;" + << endl; + + // Statements. + // + os << "static const char* const insert_one_statement;" + << "static const char* const select_all_statement;" + << "static const char* const delete_all_statement;" + << endl; + + if (base) + { + os << "};"; + return; + } // container_type // container_traits @@ -302,7 +335,6 @@ namespace relational // key_type // value_type // - os << "typedef " << t.fq_name (m.belongs ().hint ()) << " container_type;"; os << "typedef odb::access::container_traits< container_type > " << @@ -359,14 +391,6 @@ namespace relational " > statements_type;" << endl; - // column_count - // - os << "static const std::size_t cond_column_count = " << - cond_columns << "UL;" - << "static const std::size_t data_column_count = " << - data_columns << "UL;" - << endl; - // cond_image_type (object id is taken from the object image) // os << "struct cond_image_type" @@ -450,13 +474,6 @@ namespace relational os << "std::size_t version;" << "};"; - // Statements. - // - os << "static const char* const insert_one_statement;" - << "static const char* const select_all_statement;" - << "static const char* const delete_all_statement;" - << endl; - // bind (cond_image) // os << "static void" << endl @@ -640,6 +657,9 @@ namespace relational os << "};"; } + + private: + semantics::class_& object_; }; // @@ -772,7 +792,7 @@ namespace relational // Traits types. // { - instance<container_traits> t; + instance<container_traits> t (c); t->traverse (c); } |