diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-11-02 12:18:43 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-11-21 13:13:50 +0200 |
commit | 1f777ed4b8cc816817e1ce6cb8d9af970ad9b423 (patch) | |
tree | fc6be8482dfa11fa26b387ca4763d9b282b27638 /odb/relational/source.cxx | |
parent | 8a637f5697fdee3e7ae2d46f64a64d40cba5954b (diff) |
Rework query alias tag system
Now each object pointer or view-associated object with alias gets its
own unique tag.
Diffstat (limited to 'odb/relational/source.cxx')
-rw-r--r-- | odb/relational/source.cxx | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/odb/relational/source.cxx b/odb/relational/source.cxx index 7fc3ce6..21c0f57 100644 --- a/odb/relational/source.cxx +++ b/odb/relational/source.cxx @@ -22,8 +22,6 @@ traverse_object (type& c) bool base_id (id && &id->scope () != &c); // Comes from base. member_access* id_ma (id ? &id->get<member_access> ("get") : 0); - bool has_ptr (has_a (c, test_pointer)); - data_member* opt (optimistic (c)); member_access* opt_ma_get (opt ? &opt->get<member_access> ("get") : 0); member_access* opt_ma_set (opt ? &opt->get<member_access> ("set") : 0); @@ -61,16 +59,30 @@ traverse_object (type& c) object_extra (c); // - // Query. + // Query (abstract and concrete). // if (options.generate_query ()) { + bool has_ptr (has_a (c, test_pointer | exclude_base)); + + // Generate alias_traits specializations. While the class + // is generated even if our base has a pointer, there is + // not source code if we don't have pointers ourselves. + // + if (has_ptr) + { + bool false_ (false); //@@ (im)perfect forwarding + instance<query_alias_traits> t (c, false_); + t->traverse (c); + } + // query_columns_base // if (has_ptr) { - instance<query_columns_base> t (c); + bool false_ (false); //@@ (im)perfect forwarding. + instance<query_columns_base> t (c, false_); t->traverse (c); } } @@ -2865,6 +2877,39 @@ traverse_view (type& c) view_extra (c); + if (c.get<size_t> ("object-count") != 0) + { + view_objects& objs (c.get<view_objects> ("objects")); + + // Generate alias_traits specializations. + // + { + bool false_ (false); //@@ (im)perfect forwarding + instance<query_alias_traits> at (c, false_); + + for (view_objects::const_iterator i (objs.begin ()); + i < objs.end (); + ++i) + { + if (i->kind != view_object::object) + continue; // Skip tables. + + if (i->alias.empty ()) + continue; + + semantics::class_& o (*i->obj); + qname const& t (table_name (o)); + + // Check that the alias is not the same as the table name + // (if this is a polymorphic object, then the alias is just + // a prefix). + // + if (polymorphic (o) || t.qualified () || i->alias != t.uname ()) + at->generate_def (i->alias, o, i->alias); + } + } + } + // // Functions. // |