diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-04-25 12:30:04 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-04-25 12:30:04 +0200 |
commit | d7662d2cc72668eee0a21737edfcc1bbe41c229b (patch) | |
tree | 7a7c61af162e1bdb870a701cb54a747f6bafa0eb /odb/relational/header.hxx | |
parent | 82d1a3918899958cb26ed77119fbf908beb94dbc (diff) |
Reuse container traits from composite values
Diffstat (limited to 'odb/relational/header.hxx')
-rw-r--r-- | odb/relational/header.hxx | 85 |
1 files changed, 65 insertions, 20 deletions
diff --git a/odb/relational/header.hxx b/odb/relational/header.hxx index 9e258ea..5ad7d2e 100644 --- a/odb/relational/header.hxx +++ b/odb/relational/header.hxx @@ -181,20 +181,47 @@ namespace relational { typedef container_traits base; - container_traits (semantics::class_& obj) - : object_members_base (true, false), object_ (obj) + container_traits (semantics::class_& c) + : object_members_base (true, false), c_ (c) { } virtual void + composite (semantics::data_member* m, semantics::class_& c) + { + if (c_.count ("object")) + object_members_base::composite (m, c); + else + { + // If we are generating traits for a composite value type, then + // we don't want to go into its bases or it composite members. + // + if (m == 0 && &c == &c_) + names (c); + } + } + + virtual void container (semantics::data_member& m) { using semantics::type; using semantics::class_; - // Figure out if this member is from a base object. + // Figure out if this member is from a base object or composite + // value and whether it is abstract. // - bool base (context::object != &object_); + bool base, abst; + + if (c_.count ("object")) + { + base = context::object != &c_ || !m.scope ().count ("object"); + abst = abstract (c_); + } + else + { + base = false; // We don't go into bases. + abst = true; // Always abstract. + } type& t (m.type ()); container_kind_type ck (container_kind (t)); @@ -303,25 +330,36 @@ namespace relational << "struct " << name; if (base) - os << ": access::object_traits< " << context::object->fq_name () << - " >::" << name; + { + semantics::class_& b (dynamic_cast<semantics::class_&> (m.scope ())); + + if (b.count ("object")) + os << ": access::object_traits< " << b.fq_name () << " >::" << + name; + else + os << ": access::composite_value_traits< " << b.fq_name () << + " >::" << public_name (m) << "_traits"; // No prefix_. + } 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; + if (!abst) + { + // 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; + // 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) { @@ -659,7 +697,7 @@ namespace relational } private: - semantics::class_& object_; + semantics::class_& c_; }; // @@ -952,6 +990,13 @@ namespace relational // image_type_->traverse (c); + // Containers. + // + { + instance<container_traits> t (c); + t->traverse (c); + } + // grow () // os << "static bool" << endl |