diff options
-rw-r--r-- | odb/cache-traits.hxx | 22 | ||||
-rw-r--r-- | odb/session.hxx | 18 | ||||
-rw-r--r-- | odb/session.ixx | 2 | ||||
-rw-r--r-- | odb/session.txx | 4 |
4 files changed, 30 insertions, 16 deletions
diff --git a/odb/cache-traits.hxx b/odb/cache-traits.hxx index c0c1272..6a6741e 100644 --- a/odb/cache-traits.hxx +++ b/odb/cache-traits.hxx @@ -27,7 +27,17 @@ namespace odb typedef odb::pointer_traits<pointer_type> pointer_traits; typedef typename pointer_traits::element_type object_type; typedef typename object_traits<object_type>::id_type id_type; - typedef session::object_position<object_type> position_type; + + struct position_type + { + typedef session::position<object_type> base_type; + + position_type (): empty_ (true) {} + position_type (const base_type& pos): empty_ (false), pos_ (pos) {} + + bool empty_; + base_type pos_; + }; struct insert_guard { @@ -35,13 +45,13 @@ namespace odb insert_guard (const position_type& pos): pos_ (pos) {} ~insert_guard () {erase (pos_);} - position_type + const position_type& position () const {return pos_;} void - release () {pos_.map_ = 0;} + release () {pos_.empty_ = true;} - // Note: doesn't call erase() on the old position (assumes not set). + // Note: doesn't call erase() on the old position (assumes empty). // void reset (const position_type& pos) {pos_ = pos;} @@ -94,8 +104,8 @@ namespace odb static void erase (const position_type& p) { - if (p.map_ != 0) - session::current ().erase<object_type> (p); + if (!p.empty_) + session::current ().erase<object_type> (p.pos_); } }; diff --git a/odb/session.hxx b/odb/session.hxx index cfeebce..f9c8739 100644 --- a/odb/session.hxx +++ b/odb/session.hxx @@ -83,22 +83,26 @@ namespace odb // Object cache. // public: + // Position in the cache of an inserted element. The requirements + // for this class template are: default and copy-constructible and + // copy-assignable. In particular, a standard iterator can be used + // as a position. + // template <typename T> - struct object_position + struct position { - typedef T object_type; - typedef object_map<object_type> map; + typedef object_map<T> map; typedef typename map::iterator iterator; - object_position (): map_ (0) {} - object_position (map& m, const iterator& p): map_ (&m), pos_ (p) {} + position () {} + position (map& m, const iterator& p): map_ (&m), pos_ (p) {} map* map_; iterator pos_; }; template <typename T> - object_position<T> + position<T> insert (database_type&, const typename object_traits<T>::id_type&, const typename object_traits<T>::pointer_type&); @@ -113,7 +117,7 @@ namespace odb template <typename T> void - erase (const object_position<T>&); + erase (const position<T>&); protected: typedef std::map<const std::type_info*, diff --git a/odb/session.ixx b/odb/session.ixx index b359e95..50a2ca1 100644 --- a/odb/session.ixx +++ b/odb/session.ixx @@ -8,7 +8,7 @@ namespace odb { template <typename T> inline void session:: - erase (const object_position<T>& p) + erase (const position<T>& p) { // @@ Empty maps are not cleaned up by this version of erase. // diff --git a/odb/session.txx b/odb/session.txx index ce13970..42aa965 100644 --- a/odb/session.txx +++ b/odb/session.txx @@ -7,7 +7,7 @@ namespace odb { template <typename T> - typename session::object_position<T> session:: + typename session::position<T> session:: insert (database_type& db, const typename object_traits<T>::id_type& id, const typename object_traits<T>::pointer_type& obj) @@ -33,7 +33,7 @@ namespace odb if (!r.second) r.first->second = obj; - return object_position<T> (om, r.first); + return position<T> (om, r.first); } template <typename T> |