From 821e1bdf35c6fc208c421fa630ad3f77e841b60e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 9 Jan 2013 11:25:37 +0200 Subject: Add support for using custom session implementations New option, --session-type. --- odb/cache-traits.hxx | 40 +++++++++++++++++++++------------------- odb/forward.hxx | 4 ++-- odb/session.hxx | 6 +++--- odb/session.txx | 2 -- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/odb/cache-traits.hxx b/odb/cache-traits.hxx index 6a6741e..13363da 100644 --- a/odb/cache-traits.hxx +++ b/odb/cache-traits.hxx @@ -20,17 +20,18 @@ namespace odb // Caching traits for objects passed by pointer. P should be the canonical // pointer (non-const). // - template + template struct pointer_cache_traits_impl { typedef P pointer_type; + typedef S session_type; typedef odb::pointer_traits pointer_traits; typedef typename pointer_traits::element_type object_type; typedef typename object_traits::id_type id_type; struct position_type { - typedef session::position base_type; + typedef typename session_type::template position base_type; position_type (): empty_ (true) {} position_type (const base_type& pos): empty_ (false), pos_ (pos) {} @@ -69,8 +70,9 @@ namespace odb static position_type insert (odb::database& db, const id_type& id, const pointer_type& p) { - if (session::has_current ()) - return session::current ().insert (db, id, p); + if (session_type::has_current ()) + return session_type::current ().template insert ( + db, id, p); else return position_type (); } @@ -88,8 +90,8 @@ namespace odb static pointer_type find (odb::database& db, const id_type& id) { - if (session::has_current ()) - return session::current ().find (db, id); + if (session_type::has_current ()) + return session_type::current ().template find (db, id); else return pointer_type (); } @@ -97,27 +99,27 @@ namespace odb static void erase (odb::database& db, const id_type& id) { - if (session::has_current ()) - session::current ().erase (db, id); + if (session_type::has_current ()) + session_type::current ().template erase (db, id); } static void erase (const position_type& p) { if (!p.empty_) - session::current ().erase (p.pos_); + session_type::current ().template erase (p.pos_); } }; // Unique pointers don't work with the object cache. // - template - struct pointer_cache_traits_impl: + template + struct pointer_cache_traits_impl: no_op_pointer_cache_traits

{}; - template + template struct pointer_cache_traits: - pointer_cache_traits_impl::kind> {}; + pointer_cache_traits_impl::kind> {}; // reference_cache_traits // @@ -125,17 +127,17 @@ namespace odb // canonical object type (non-const). Only if the object pointer // kind is raw do we add the object to the session. // - template + template struct reference_cache_traits_impl: no_op_reference_cache_traits {}; - template - struct reference_cache_traits_impl + template + struct reference_cache_traits_impl { typedef T object_type; typedef typename object_traits::pointer_type pointer_type; typedef typename object_traits::id_type id_type; - typedef pointer_cache_traits pointer_traits; + typedef pointer_cache_traits pointer_traits; typedef typename pointer_traits::position_type position_type; typedef typename pointer_traits::insert_guard insert_guard; @@ -154,10 +156,10 @@ namespace odb } }; - template + template struct reference_cache_traits: reference_cache_traits_impl< - T, pointer_traits::pointer_type>::kind> {}; + T, S, pointer_traits::pointer_type>::kind> {}; } #include diff --git a/odb/forward.hxx b/odb/forward.hxx index fe23c5f..f9c2d18 100644 --- a/odb/forward.hxx +++ b/odb/forward.hxx @@ -128,10 +128,10 @@ namespace odb // template struct no_id_pointer_cache_traits; template struct no_op_pointer_cache_traits; - template struct pointer_cache_traits; + template struct pointer_cache_traits; template struct no_id_reference_cache_traits; template struct no_op_reference_cache_traits; - template struct reference_cache_traits; + template struct reference_cache_traits; // // diff --git a/odb/session.hxx b/odb/session.hxx index 4db10b3..472ea79 100644 --- a/odb/session.hxx +++ b/odb/session.hxx @@ -65,7 +65,7 @@ namespace odb session (const session&); session& operator= (const session&); - protected: + public: struct LIBODB_EXPORT object_map_base: details::shared_base { virtual @@ -84,8 +84,7 @@ namespace odb public: // Position in the cache of an inserted element. The requirements // for this class template are: default and copy-constructible as - // well as copy-assignable. In particular, a standard iterator can - // be used as a position. + // well as copy-assignable. // template struct position @@ -118,6 +117,7 @@ namespace odb void erase (const position&); + // Low-level object cache access (iteration, etc). // public: diff --git a/odb/session.txx b/odb/session.txx index 42aa965..941f059 100644 --- a/odb/session.txx +++ b/odb/session.txx @@ -2,8 +2,6 @@ // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file -#include - namespace odb { template -- cgit v1.1