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/inline.hxx | 122 +++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 56 deletions(-) (limited to 'odb/relational/inline.hxx') diff --git a/odb/relational/inline.hxx b/odb/relational/inline.hxx index 9e76dea..73e0112 100644 --- a/odb/relational/inline.hxx +++ b/odb/relational/inline.hxx @@ -32,16 +32,80 @@ namespace relational virtual void traverse_object (type& c) { + bool abst (abstract (c)); string const& type (c.fq_name ()); string traits ("access::object_traits< " + type + " >"); - semantics::data_member& id (id_member (c)); - bool base_id (&id.scope () != &c); // Id comes from a base class. + semantics::data_member* id (id_member (c)); + bool base_id (id ? &id->scope () != &c : false); // Comes from base. os << "// " << c.name () << endl << "//" << endl << endl; + if (id != 0) + { + // id (object_type) + // + os << "inline" << endl + << traits << "::id_type" << endl + << traits << "::" << endl + << "id (const object_type& obj)" + << "{"; + + if (base_id) + os << "return object_traits< " << id->scope ().fq_name () << + " >::id (obj);"; + else + os << "return obj." << id->name () << ";"; + + os << "}"; + + // id (image_type) + // + if (options.generate_query () && base_id) + { + os << "inline" << endl + << traits << "::id_type" << endl + << traits << "::" << endl + << "id (const image_type& i)" + << "{" + << "return object_traits< " << id->scope ().fq_name () << + " >::id (i);" + << "}"; + } + + // bind (id_image_type) + // + if (base_id) + { + os << "inline" << endl + << "void " << traits << "::" << endl + << "bind (" << bind_vector << " b, id_image_type& i)" + << "{" + << "object_traits< " << id->scope ().fq_name () << + " >::bind (b, i);" + << "}"; + } + + if (base_id) + { + os << "inline" << endl + << "void " << traits << "::" << endl + << "init (id_image_type& i, const id_type& id)" + << "{" + << "object_traits< " << id->scope ().fq_name () << + " >::init (i, id);" + << "}"; + } + } + + // + // The rest only applies to concrete objects. + // + if (abst) + return; + // query_type // if (options.generate_query ()) @@ -67,60 +131,6 @@ namespace relational << "}"; } - // id (object_type) - // - os << "inline" << endl - << traits << "::id_type" << endl - << traits << "::" << endl - << "id (const object_type& obj)" - << "{"; - - if (base_id) - os << "return object_traits< " << id.scope ().fq_name () << - " >::id (obj);"; - else - os << "return obj." << id.name () << ";"; - - os << "}"; - - // id (image_type) - // - if (options.generate_query () && base_id) - { - os << "inline" << endl - << traits << "::id_type" << endl - << traits << "::" << endl - << "id (const image_type& i)" - << "{" - << "return object_traits< " << id.scope ().fq_name () << - " >::id (i);" - << "}"; - } - - // bind (id_image_type) - // - if (base_id) - { - os << "inline" << endl - << "void " << traits << "::" << endl - << "bind (" << bind_vector << " b, id_image_type& i)" - << "{" - << "object_traits< " << id.scope ().fq_name () << - " >::bind (b, i);" - << "}"; - } - - if (base_id) - { - os << "inline" << endl - << "void " << traits << "::" << endl - << "init (id_image_type& i, const id_type& id)" - << "{" - << "object_traits< " << id.scope ().fq_name () << - " >::init (i, id);" - << "}"; - } - // load_() // if (!has_a (c, test_container)) -- cgit v1.1