From 5df8fc85147cc89f083f53d2b1ccd2d8fedaab29 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 9 Jan 2013 11:25:38 +0200 Subject: Add support for using custom session implementations New option, --session-type. --- odb/header.cxx | 28 ++++++++++++++++++++-------- odb/options.cli | 11 +++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/odb/header.cxx b/odb/header.cxx index 3259a6a..0f8061a 100644 --- a/odb/header.cxx +++ b/odb/header.cxx @@ -241,28 +241,35 @@ traverse_object (type& c) } else { - char const* p (session (c) ? "odb::" : "no_op_"); - - if (poly_derived) + char const* obj (poly_derived ? "root_type" : "object_type"); + char const* ptr (poly_derived + ? "object_traits::pointer_type" + : "pointer_type"); + if (session (c)) { + string const& s (options.session_type ()); + os << "typedef" << endl - << p << "pointer_cache_traits<" << - "object_traits::pointer_type>" << endl + << "odb::pointer_cache_traits<" << endl + << " " << ptr << "," << endl + << " " << s << " >" << endl << "pointer_cache_traits;" << endl << "typedef" << endl - << p << "reference_cache_traits" << endl + << "odb::reference_cache_traits<" << endl + << " " << obj << "," << endl + << " " << s << " >" << endl << "reference_cache_traits;" << endl; } else { os << "typedef" << endl - << p << "pointer_cache_traits" << endl + << "no_op_pointer_cache_traits<" << ptr << ">" << endl << "pointer_cache_traits;" << endl << "typedef" << endl - << p << "reference_cache_traits" << endl + << "no_op_reference_cache_traits<" << obj << ">" << endl << "reference_cache_traits;" << endl; } @@ -721,7 +728,12 @@ namespace header os << "#include " << endl; if (ctx.features.session_object) + { + if (ctx.options.session_type () == "odb::session") + os << "#include " << endl; + os << "#include " << endl; + } else os << "#include " << endl; diff --git a/odb/options.cli b/odb/options.cli index 5b67708..621db9f 100644 --- a/odb/options.cli +++ b/odb/options.cli @@ -181,6 +181,17 @@ class options directive to the generated code." }; + std::string --session-type = "odb::session" + { + "", + "Use as the alternative session type instead of the default + \cb{odb::session}. This option can be used to specify a custom + session implementation to be use by the persistent classes. Note + that you will also need to include the definition of the custom + session type into the generated header file. This is normally + achieved with the \cb{--hxx-prologue*} options." + }; + // The following option is "fake" in that it is actually handled by // argv_file_scanner. We have it here to get the documentation. // -- cgit v1.1