diff options
Diffstat (limited to 'odb/relational/header.hxx')
-rw-r--r-- | odb/relational/header.hxx | 256 |
1 files changed, 41 insertions, 215 deletions
diff --git a/odb/relational/header.hxx b/odb/relational/header.hxx index 25f9480..c0e1e89 100644 --- a/odb/relational/header.hxx +++ b/odb/relational/header.hxx @@ -64,9 +64,11 @@ namespace relational string const& type (class_fq_name (c)); if (obj) - os << "object_traits< " << type << " >::image_type"; + os << "object_traits_impl< " << type << ", id_" << db << + " >::image_type"; else - os << "composite_value_traits< " << type << " >::image_type"; + os << "composite_value_traits< " << type << ", id_" << db << + " >::image_type"; } private: @@ -117,7 +119,7 @@ namespace relational os << "{"; if (poly_derived) - os << "object_traits<base_type>::image_type* base;" + os << "base_traits::image_type* base;" << endl; names (c); @@ -173,7 +175,7 @@ namespace relational } os << (ptr_ ? "pointer_query_columns" : "query_columns") << "< " << - class_fq_name (c) << ", "; + class_fq_name (c) << ", id_" << db << ", "; // If our base is polymorphic, then it has its own table/alias. // @@ -213,7 +215,7 @@ namespace relational << "//" << endl << "typedef " << (ptr_ ? "pointer_query_columns" : "query_columns") << "< " << - class_fq_name (c) << ", "; + class_fq_name (c) << ", id_" << db << ", "; if (polymorphic (c)) os << "typename A::base_traits"; @@ -246,7 +248,8 @@ namespace relational if (ptr_) { os << "template <typename A>" << endl - << "struct pointer_query_columns< " << type << ", A >"; + << "struct pointer_query_columns< " << type << ", id_" << db << + ", A >"; // If we don't have pointers (in the whole hierarchy), then // pointer_query_columns and query_columns are the same. @@ -254,7 +257,7 @@ namespace relational if (!has_a (c, test_pointer | include_base)) { os << ":" << endl - << " query_columns< " << type << ", A >" + << " query_columns< " << type << ", id_" << db << ", A >" << "{" << "};"; } @@ -298,7 +301,8 @@ namespace relational // table alias (A) template argument. // os << "template <>" << endl - << "struct query_columns_base< " << type << " >" + << "struct query_columns_base< " << type << ", id_" << + db << " >" << "{"; instance<query_columns_base> t; @@ -308,11 +312,11 @@ namespace relational } os << "template <typename A>" << endl - << "struct query_columns< " << type << ", A >"; + << "struct query_columns< " << type << ", id_" << db << ", A >"; if (has_ptr) os << ":" << endl - << " query_columns_base< " << type << " >"; + << " query_columns_base< " << type << ", id_" << db << " >"; { instance<query_columns_bases> b (ptr_, !has_ptr); @@ -540,10 +544,11 @@ namespace relational string const& type (class_fq_name (b)); if (object (b)) - os << ": access::object_traits< " << type << " >::" << name; + os << ": access::object_traits_impl< " << type << ", id_" << + db << " >::" << name; else - os << ": access::composite_value_traits< " << type << " >::" << - public_name (m) << "_traits"; // No prefix_. + os << ": access::composite_value_traits< " << type << ", id_" << + db << " >::" << public_name (m) << "_traits"; // No prefix_. } os << "{"; @@ -992,7 +997,7 @@ namespace relational } virtual void - traverse_object (type& c); + traverse_object (type&); virtual void view_public_extra_pre (type&) @@ -1005,196 +1010,10 @@ namespace relational } virtual void - traverse_view (type& c) - { - string const& type (class_fq_name (c)); - - os << "// " << class_name (c) << endl - << "//" << endl; - - os << "template <>" << endl - << "struct class_traits< " << type << " >" - << "{" - << "static const class_kind kind = class_view;" - << "};"; - - os << "template <>" << endl - << "class access::view_traits< " << type << " >" - << "{" - << "public:" << endl; - - view_public_extra_pre (c); - - // view_type & pointer_type - // - os << "typedef " << type << " view_type;" - << "typedef " << c.get<string> ("object-pointer") << " pointer_type;" - << endl; - - // image_type - // - image_type_->traverse (c); - - // - // Query. - // - - // query_base_type and query_columns (definition generated by class2). - // - os << "typedef " << db << "::query query_base_type;" - << "struct query_columns"; - - if (c.get<size_t> ("object-count") == 0) - os << "{" - << "};"; - else - os << ";" - << endl; - - // - // Functions. - // - - // grow () - // - if (generate_grow) - { - os << "static bool" << endl - << "grow (image_type&, " << truncated_vector << ");" - << endl; - } - - // bind (image_type) - // - os << "static void" << endl - << "bind (" << bind_vector << ", image_type&);" - << endl; - - // init (view, image) - // - os << "static void" << endl - << "init (view_type&, const image_type&, database*);" - << endl; - - // column_count - // - os << "static const std::size_t column_count = " << - column_count (c).total << "UL;" - << endl; - - // Statements. - // - view_query& vq (c.get<view_query> ("query")); - - if (vq.kind != view_query::runtime) - { - os << "static query_base_type" << endl - << "query_statement (const query_base_type&);" - << endl; - } - - // - // Functions. - // - - // callback () - // - os << "static void" << endl - << "callback (database&, view_type&, callback_event);" - << endl; - - // query () - // - os << "static result<view_type>" << endl - << "query (database&, const query_base_type&);" - << endl; - - view_public_extra_post (c); - - os << "};"; - } + traverse_view (type&); virtual void - traverse_composite (type& c) - { - string const& type (class_fq_name (c)); - - os << "// " << class_name (c) << endl - << "//" << endl; - - os << "template <>" << endl - << "struct class_traits< " << type << " >" - << "{" - << "static const class_kind kind = class_composite;" - << "};"; - - os << "template <>" << endl - << "class access::composite_value_traits< " << type << " >" - << "{" - << "public:" << endl; - - // value_type - // - os << "typedef " << type << " value_type;" - << endl; - - // image_type - // - image_type_->traverse (c); - - // Containers. - // - { - instance<container_traits> t (c); - t->traverse (c); - } - - // grow () - // - if (generate_grow) - { - os << "static bool" << endl - << "grow (image_type&, " << truncated_vector << ");" - << endl; - } - - // bind (image_type) - // - os << "static void" << endl - << "bind (" << bind_vector << ", image_type&, " << - db << "::statement_kind);" - << endl; - - // init (image, value) - // - os << "static " << (generate_grow ? "bool" : "void") << endl - << "init (image_type&, const value_type&, " << - db << "::statement_kind);" - << endl; - - // init (value, image) - // - os << "static void" << endl - << "init (value_type&, const image_type&, database*);" - << endl; - - if (!has_a (c, test_container)) - { - // get_null (image) - // - os << "static bool" << endl - << "get_null (const image_type&);" - << endl; - - // set_null (image) - // - os << "static void" << endl - << "set_null (image_type&, " << db << "::statement_kind);" - << endl; - } - - os << "};"; - } + traverse_composite (type&); private: instance<image_type> image_type_; @@ -1306,7 +1125,8 @@ namespace relational } } - os << "struct access::view_traits< " << type << " >::query_columns"; + os << "struct access::view_traits_impl< " << type << ", id_" << + db << " >::query_columns"; if (obj_count > 1) { @@ -1329,19 +1149,20 @@ namespace relational << "//" << endl << "typedef" << endl << "odb::pointer_query_columns<" << endl - << " " << otype << "," << endl; + << " " << otype << "," << endl + << " id_" << db << "," << endl; if (alias && (polymorphic (o) || table.qualified () || i->alias != table.uname ())) { string tag (escape (i->alias + "_alias_tag")); - os << " odb::alias_traits< " << otype << ", " << - tag << " > >" << endl; + os << " odb::alias_traits< " << otype << ", id_" << db << + ", " << tag << " > >" << endl; } else - os << " odb::access::object_traits< " << otype << - " > >" << endl; + os << " odb::access::object_traits_impl< " << otype << + ", id_" << db << " > >" << endl; os << oname << ";" << endl; @@ -1370,18 +1191,20 @@ namespace relational os << ":" << endl << " odb::pointer_query_columns<" << endl - << " " << otype << "," << endl; + << " " << otype << "," << endl + << " id_" << db << "," << endl; if (alias && (polymorphic (o) || table.qualified () || vo->alias != table.uname ())) { string tag (escape (vo->alias + "_alias_tag")); - os << " odb::alias_traits< " << otype << ", " << - tag << " > >"; + os << " odb::alias_traits< " << otype << ", id_" << + db << ", " << tag << " > >"; } else - os << " odb::access::object_traits< " << otype << " > >"; + os << " odb::access::object_traits_impl< " << otype << + ", id_" << db << " > >"; os << "{" << "};"; @@ -1410,9 +1233,12 @@ namespace relational virtual void generate () { - os << "#include <odb/details/buffer.hxx>" << endl - << "#include <odb/details/unused.hxx>" << endl - << endl; + os << "#include <odb/details/buffer.hxx>" << endl; + + if (options.generate_query ()) + os << "#include <odb/details/shared-ptr.hxx>" << endl; + + os << endl; os << "#include <odb/" << db << "/version.hxx>" << endl << "#include <odb/" << db << "/forward.hxx>" << endl |