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/session.txx | 49 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) (limited to 'odb/session.txx') diff --git a/odb/session.txx b/odb/session.txx index e2d7734..31814f8 100644 --- a/odb/session.txx +++ b/odb/session.txx @@ -13,28 +13,20 @@ namespace odb const typename object_traits::id_type& id, const typename object_traits::pointer_type& obj) { - // T can be const T while object_type will always be T. - // - typedef typename object_traits::object_type object_type; - typedef odb::object_traits object_traits; - - typedef typename odb::object_traits::pointer_type pointer_type; + typedef odb::object_traits object_traits; + typedef typename object_traits::pointer_type pointer_type; typedef odb::pointer_traits pointer_traits; type_map& tm (db_map_[&db]); - details::shared_ptr& pom (tm[&typeid (object_type)]); + details::shared_ptr& pom (tm[&typeid (T)]); if (!pom) - pom.reset (new (details::shared) object_map); + pom.reset (new (details::shared) object_map); - object_map& om ( - static_cast&> (*pom)); + object_map& om (static_cast&> (*pom)); - typename object_map::value_type vt ( - id, object_pointers ()); - vt.second.set (obj); - std::pair::iterator, bool> r ( - om.insert (vt)); + typename object_map::value_type vt (id, obj); + std::pair::iterator, bool> r (om.insert (vt)); // In what situation may we possibly attempt to reinsert the object? // For example, when the user loads the same object in to different @@ -42,7 +34,7 @@ namespace odb // we should probably update our entries accordingly. // if (!r.second) - r.first->second.set (obj); + r.first->second = obj; return object_position (om, r.first); } @@ -51,9 +43,6 @@ namespace odb typename object_traits::pointer_type session:: find (database_type& db, const typename object_traits::id_type& id) const { - // T can be const T while object_type will always be T. - // - typedef typename object_traits::object_type object_type; typedef typename object_traits::pointer_type pointer_type; database_map::const_iterator di (db_map_.find (&db)); @@ -62,45 +51,37 @@ namespace odb return pointer_type (); const type_map& tm (di->second); - type_map::const_iterator ti (tm.find (&typeid (object_type))); + type_map::const_iterator ti (tm.find (&typeid (T))); if (ti == tm.end ()) return pointer_type (); - const object_map& om ( - static_cast&> (*ti->second)); - typename object_map::const_iterator oi (om.find (id)); + const object_map& om (static_cast&> (*ti->second)); + typename object_map::const_iterator oi (om.find (id)); if (oi == om.end ()) return pointer_type (); - pointer_type r; - oi->second.get (r); - return r; + return oi->second; } template void session:: erase (database_type& db, const typename object_traits::id_type& id) { - // T can be const T while object_type will always be T. - // - typedef typename object_traits::object_type object_type; - database_map::iterator di (db_map_.find (&db)); if (di == db_map_.end ()) return; type_map& tm (di->second); - type_map::iterator ti (tm.find (&typeid (object_type))); + type_map::iterator ti (tm.find (&typeid (T))); if (ti == tm.end ()) return; - object_map& om ( - static_cast&> (*ti->second)); - typename object_map::iterator oi (om.find (id)); + object_map& om (static_cast&> (*ti->second)); + typename object_map::iterator oi (om.find (id)); if (oi == om.end ()) return; -- cgit v1.1