summaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-04-25 11:29:06 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-04-25 11:29:06 +0200
commit82d1a3918899958cb26ed77119fbf908beb94dbc (patch)
tree9b58aaff1435f8142dfa8685c8b3e84922492016 /odb
parentbbd0aa5d1f6e58dbbe900d2f15692fa2b24ed1f1 (diff)
Reuse container traits from base objects
Diffstat (limited to 'odb')
-rw-r--r--odb/relational/header.hxx60
-rw-r--r--odb/relational/source.hxx18
2 files changed, 51 insertions, 27 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);
}
diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx
index dbb3d4a..844dc11 100644
--- a/odb/relational/source.hxx
+++ b/odb/relational/source.hxx
@@ -582,6 +582,10 @@ namespace relational
{
using semantics::type;
+ // 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));
@@ -828,6 +832,9 @@ namespace relational
<< endl;
}
+ if (base)
+ return;
+
//
// Functions.
//
@@ -1213,8 +1220,7 @@ namespace relational
{
os << "using namespace " << db << ";"
<< endl
- << "typedef container_statements< " << name << " > statements;"
- << "statements& sts (*static_cast< statements* > (d));"
+ << "statements_type& sts (*static_cast< statements_type* > (d));"
<< "binding& b (sts.data_image_binding ());"
<< "data_image_type& di (sts.data_image ());"
<< endl;
@@ -1284,8 +1290,7 @@ namespace relational
os << "{"
<< "using namespace " << db << ";"
<< endl
- << "typedef container_statements< " << name << " > statements;"
- << "statements& sts (*static_cast< statements* > (d));"
+ << "statements_type& sts (*static_cast< statements_type* > (d));"
<< "data_image_type& di (sts.data_image ());";
// Extract current element.
@@ -1372,8 +1377,7 @@ namespace relational
if (!inverse)
os << "using namespace " << db << ";"
<< endl
- << "typedef container_statements< " << name << " > statements;"
- << "statements& sts (*static_cast< statements* > (d));"
+ << "statements_type& sts (*static_cast< statements_type* > (d));"
<< "sts.delete_all_statement ().execute ();";
os << "}";
@@ -1562,7 +1566,7 @@ namespace relational
container (semantics::data_member& m)
{
string traits (prefix_ + public_name (m) + "_traits");
- os << db << "::container_statements< " << traits << " > " <<
+ os << db << "::container_statements_impl< " << traits << " > " <<
prefix_ << m.name () << ";";
}
};