From 1a6a0652a6ef5b319cfc8ad05a0acee6910f7560 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 25 Apr 2011 15:02:43 +0200 Subject: Add support for abstract object types --- odb/relational/header.hxx | 189 +++++++++++++++++++++++++++------------------- 1 file changed, 113 insertions(+), 76 deletions(-) (limited to 'odb/relational/header.hxx') diff --git a/odb/relational/header.hxx b/odb/relational/header.hxx index 5ad7d2e..3ecc8d8 100644 --- a/odb/relational/header.hxx +++ b/odb/relational/header.hxx @@ -730,11 +730,12 @@ namespace relational virtual void traverse_object (type& c) { + bool abst (abstract (c)); string const& type (c.fq_name ()); - semantics::data_member& id (id_member (c)); - bool auto_id (id.count ("auto")); - bool base_id (&id.scope () != &c); // Id comes from a base class. + semantics::data_member* id (id_member (c)); + bool auto_id (id ? id->count ("auto") : false); + bool base_id (id ? &id->scope () != &c : false); // Comes from base. os << "// " << c.name () << endl << "//" << endl; @@ -751,109 +752,76 @@ namespace relational // id_type & id_image_type // - if (base_id) + if (id != 0) { - string const& base (id.scope ().fq_name ()); + if (base_id) + { + string const& base (id->scope ().fq_name ()); - os << "typedef object_traits< " << base << " >::id_type id_type;" - << endl - << "typedef object_traits< " << base << " >::id_image_type " << - "id_image_type;" - << endl; - } - else - { - os << "typedef " << id.type ().fq_name (id.belongs ().hint ()) << - " id_type;" - << endl; + os << "typedef object_traits< " << base << " >::id_type id_type;" + << endl + << "typedef object_traits< " << base << " >::id_image_type " << + "id_image_type;" + << endl; + } + else + { + os << "typedef " << id->type ().fq_name (id->belongs ().hint ()) << + " id_type;" + << endl; - os << "struct id_image_type" - << "{"; + os << "struct id_image_type" + << "{"; - id_image_member_->traverse (id); + id_image_member_->traverse (*id); - os << "std::size_t version;" - << "};"; + os << "std::size_t version;" + << "};"; + } } // image_type // image_type_->traverse (c); - // query types // + // Query (abstract and concrete). + // + if (options.generate_query ()) { // query_columns // query_type_->traverse (c); - - // query_base_type - // - os << "typedef " << db << "::query query_base_type;" - << endl; - - // query_type - // - os << "struct query_type: query_base_type, query_columns" - << "{" - << "query_type ();" - << "query_type (const std::string&);" - << "query_type (const query_base_type&);" - << "};"; } - // column_count - // - os << "static const std::size_t in_column_count = " << - in_column_count (c) << "UL;" - << "static const std::size_t out_column_count = " << - out_column_count (c) << "UL;" - << endl; - - // Statements. - // - os << "static const char* const persist_statement;" - << "static const char* const find_statement;" - << "static const char* const update_statement;" - << "static const char* const erase_statement;"; - - if (options.generate_query ()) - os << "static const char* const query_clause;"; - - os << endl; - // - // Containers. + // Containers (abstract and concrete). // - // Traits types. - // { instance t (c); t->traverse (c); } - // Statement cache (forward declaration). - // - os << "struct container_statement_cache_type;" - << endl; - // - // Functions. + // Functions (abstract and concrete). // // id () // - os << "static id_type" << endl - << "id (const object_type&);" - << endl; - - if (options.generate_query ()) + if (id != 0) + { os << "static id_type" << endl - << "id (const image_type&);" + << "id (const object_type&);" << endl; + if (options.generate_query ()) + os << "static id_type" << endl + << "id (const image_type&);" + << endl; + } + // grow () // os << "static bool" << endl @@ -868,9 +836,12 @@ namespace relational // bind (id_image_type) // - os << "static void" << endl - << "bind (" << bind_vector << ", id_image_type&);" - << endl; + if (id != 0) + { + os << "static void" << endl + << "bind (" << bind_vector << ", id_image_type&);" + << endl; + } // init (image, object) // @@ -886,10 +857,76 @@ namespace relational // init (id_image, id) // - os << "static void" << endl - << "init (id_image_type&, const id_type&);" + if (id != 0) + { + os << "static void" << endl + << "init (id_image_type&, const id_type&);" + << endl; + } + + // + // The rest only applies to concrete objects. + // + if (abst) + { + os << "};"; + return; + } + + // + // Query (concrete). + // + + if (options.generate_query ()) + { + // query_base_type + // + os << "typedef " << db << "::query query_base_type;" + << endl; + + // query_type + // + os << "struct query_type: query_base_type, query_columns" + << "{" + << "query_type ();" + << "query_type (const std::string&);" + << "query_type (const query_base_type&);" + << "};"; + } + + // + // Containers (concrete). + // + + // Statement cache (forward declaration). + // + os << "struct container_statement_cache_type;" + << endl; + + // column_count + // + os << "static const std::size_t in_column_count = " << + in_column_count (c) << "UL;" + << "static const std::size_t out_column_count = " << + out_column_count (c) << "UL;" << endl; + // Statements. + // + os << "static const char* const persist_statement;" + << "static const char* const find_statement;" + << "static const char* const update_statement;" + << "static const char* const erase_statement;"; + + if (options.generate_query ()) + os << "static const char* const query_clause;"; + + os << endl; + + // + // Functions (concrete). + // + // persist () // os << "static void" << endl -- cgit v1.1