From 30d797ffff4a8e2492500aea2135567f91b15aa0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 23 Jul 2010 14:42:52 +0200 Subject: Add generation of the image class definition --- odb/tracer/header.cxx | 216 +++++++++++++++++++++++++------------------------- 1 file changed, 108 insertions(+), 108 deletions(-) (limited to 'odb/tracer/header.cxx') diff --git a/odb/tracer/header.cxx b/odb/tracer/header.cxx index c023e58..8c7254d 100644 --- a/odb/tracer/header.cxx +++ b/odb/tracer/header.cxx @@ -6,131 +6,131 @@ #include #include -namespace +namespace tracer { - struct class_: traversal::class_, context + namespace { - class_ (context& c) - : context (c) + struct class_: traversal::class_, context { - } + class_ (context& c) + : context (c) + { + } - virtual void - traverse (type& c) - { - if (c.file () != unit.file ()) - return; + virtual void + traverse (type& c) + { + if (c.file () != unit.file ()) + return; - if (!c.count ("object")) - return; + if (!c.count ("object")) + return; - string const& type (c.fq_name ()); + string const& type (c.fq_name ()); - // Find the id member and type. - // - id_member t (*this); - t.traverse (c); + // Find the id member and type. + // + id_member t (*this); + t.traverse (c); + + if (t.member () == 0) + { + cerr << c.file () << ":" << c.line () << ":" << c.column () + << " error: no data member designated as object id" << endl; + + cerr << c.file () << ":" << c.line () << ":" << c.column () + << " info: use '#pragma odb id' to specify object id member" + << endl; + + throw generation_failed (); + } + + semantics::data_member& id (*t.member ()); + semantics::type& id_type (id.type ()); + + if (id_type.anonymous ()) + { + // Can be a template-id (which we should handle eventually) or an + // anonymous type in member declaration (e.g., struct {...} m_;). + // + cerr << id.file () << ":" << id.line () << ":" << id.column () + << " error: unnamed type in data member declaration" << endl; + + cerr << id.file () << ":" << id.line () << ":" << id.column () + << " info: use 'typedef' to name this type" + << endl; + + throw generation_failed (); + } + + os << "// " << c.name () << endl + << "//" << endl; + + os << "template <>" << endl + << "class access::object_traits< " << type << " >: " << endl + << " public access::object_memory< " << type << " >," << endl + << " public access::object_factory< " << type << " >" + << "{" + << "public:" << endl; + + // object_type & shared_ptr + // + os << "typedef " << type << " object_type;"; - if (t.member () == 0) - { - cerr << c.file () << ":" << c.line () << ":" << c.column () - << " error: no data member designated as object id" << endl; + // id_type + // + os << "typedef " << id_type.fq_name () << " id_type;" + << endl; - cerr << c.file () << ":" << c.line () << ":" << c.column () - << " info: use '#pragma odb id' to specify object id member" - << endl; + // id_source + // + os << "static const odb::id_source id_source = odb::ids_assigned;" + << endl; - throw generation_failed (); - } + // type_name () + // + os << "static const char*" << endl + << "type_name ();" + << endl; - semantics::data_member& id (*t.member ()); - semantics::type& id_type (id.type ()); + // id () + // + os << "static id_type" << endl + << "id (const object_type&);" + << endl; - if (id_type.anonymous ()) - { - // Can be a template-id (which we should handle eventually) or an - // anonymous type in member declaration (e.g., struct {...} m_;). + // persist () // - cerr << id.file () << ":" << id.line () << ":" << id.column () - << " error: unnamed type in data member declaration" << endl; + os << "static void" << endl + << "persist (database&, object_type&);" + << endl; - cerr << id.file () << ":" << id.line () << ":" << id.column () - << " info: use 'typedef' to name this type" - << endl; + // store () + // + os << "static void" << endl + << "store (database&, object_type&);" + << endl; - throw generation_failed (); - } + // erase () + // + os << "static void" << endl + << "erase (database&, const id_type&);" + << endl; - os << "// " << c.name () << endl - << "//" << endl; - - os << "template <>" << endl - << "class access::object_traits< " << type << " >: " << endl - << " public access::object_memory< " << type << " >," << endl - << " public access::object_factory< " << type << " >" - << "{" - << "public:" << endl; - - // object_type & shared_ptr - // - os << "typedef " << type << " object_type;"; - - // id_type - // - os << "typedef " << id_type.fq_name () << " id_type;" - << endl; - - // id_source - // - os << "static const odb::id_source id_source = odb::ids_assigned;" - << endl; - - // type_name () - // - os << "static const char*" << endl - << "type_name ();" - << endl; - - // id () - // - os << "static id_type" << endl - << "id (const object_type&);" - << endl; - - // persist () - // - os << "static void" << endl - << "persist (database&, object_type&);" - << endl; - - // store () - // - os << "static void" << endl - << "store (database&, object_type&);" - << endl; - - // erase () - // - os << "static void" << endl - << "erase (database&, const id_type&);" - << endl; - - // find () - // - os << "static pointer_type" << endl - << "find (database&, const id_type&);" - << endl; - - os << "static bool" << endl - << "find (database&, const id_type&, object_type&);"; - - os << "};"; - } - }; -} + // find () + // + os << "static pointer_type" << endl + << "find (database&, const id_type&);" + << endl; + + os << "static bool" << endl + << "find (database&, const id_type&, object_type&);"; + + os << "};"; + } + }; + } -namespace tracer -{ void generate_header (context& ctx) { -- cgit v1.1