From a28444da4ca6adb016f719e032174ccb54e1692e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 21 Sep 2011 13:00:33 +0200 Subject: Rework const object handling Now objects are always loaded as non-const and the object cache in session treats all objects as non-const. --- odb/cache-traits.hxx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'odb/cache-traits.hxx') diff --git a/odb/cache-traits.hxx b/odb/cache-traits.hxx index 596ee35..e4b2495 100644 --- a/odb/cache-traits.hxx +++ b/odb/cache-traits.hxx @@ -21,9 +21,14 @@ namespace odb struct pointer_cache_traits { typedef P pointer_type; - typedef typename pointer_traits::element_type element_type; + typedef odb::pointer_traits pointer_traits; + typedef typename pointer_traits::element_type element_type; + + // element_type can be const while object_type is always non-const. + // + typedef typename object_traits::object_type object_type; typedef typename object_traits::id_type id_type; - typedef session::object_position position_type; + typedef session::object_position position_type; struct insert_guard { @@ -46,7 +51,10 @@ namespace odb insert (odb::database& db, const id_type& id, const pointer_type& p) { if (session::has_current ()) - return session::current ().insert (db, id, p); + // Cast away constness if any. + // + return session::current ().insert ( + db, id, pointer_traits::cast (p)); else return position_type (); } @@ -55,7 +63,7 @@ namespace odb find (odb::database& db, const id_type& id) { if (session::has_current ()) - return session::current ().find (db, id); + return session::current ().find (db, id); else return pointer_type (); } @@ -64,14 +72,14 @@ namespace odb erase (odb::database& db, const id_type& id) { if (session::has_current ()) - session::current ().erase (db, id); + session::current ().erase (db, id); } static void erase (const position_type& p) { if (p.map_ != 0) - session::current ().erase (p); + session::current ().erase (p); } }; -- cgit v1.1