From 53a30dbef3bb9d60946e96adc88c4a6c1073f566 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 Apr 2011 11:16:30 +0200 Subject: Fix loaded() function in lazy_ptr to conform to documentation --- odb/boost/smart-ptr/lazy-ptr.hxx | 10 +++++++++- odb/boost/smart-ptr/lazy-ptr.ixx | 6 ++++-- odb/boost/smart-ptr/lazy-ptr.txx | 20 ++++++++++++++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/odb/boost/smart-ptr/lazy-ptr.hxx b/odb/boost/smart-ptr/lazy-ptr.hxx index 4dbf9bf..d04edcd 100644 --- a/odb/boost/smart-ptr/lazy-ptr.hxx +++ b/odb/boost/smart-ptr/lazy-ptr.hxx @@ -82,7 +82,15 @@ namespace odb public: typedef odb::database database_type; + // NULL loaded() + // + // true true NULL pointer to transient object + // false true valid pointer to persistent object + // true false unloaded pointer to persistent object + // false false valid pointer to transient object + // bool loaded () const; + ::boost::shared_ptr load () const; // Unload the pointer. For transient objects this function is @@ -184,7 +192,7 @@ namespace odb // true true expired pointer to transient object // false true valid pointer to persistent object // true false expired pointer to persistent object - // false false valid pointer to transiend object + // false false valid pointer to transient object // bool loaded () const; diff --git a/odb/boost/smart-ptr/lazy-ptr.ixx b/odb/boost/smart-ptr/lazy-ptr.ixx index 2522ab4..fced28d 100644 --- a/odb/boost/smart-ptr/lazy-ptr.ixx +++ b/odb/boost/smart-ptr/lazy-ptr.ixx @@ -192,7 +192,8 @@ namespace odb inline bool lazy_shared_ptr:: loaded () const { - return p_ || !i_; + bool i (i_); + return !p_ != i; // !p_ XOR i_ } template @@ -524,7 +525,8 @@ namespace odb inline bool lazy_weak_ptr:: loaded () const { - return !expired () || !i_; + bool i (i_); + return expired () != i; // expired () XOR i_ } template diff --git a/odb/boost/smart-ptr/lazy-ptr.txx b/odb/boost/smart-ptr/lazy-ptr.txx index bca6fdb..8ca589a 100644 --- a/odb/boost/smart-ptr/lazy-ptr.txx +++ b/odb/boost/smart-ptr/lazy-ptr.txx @@ -16,12 +16,24 @@ namespace odb bool lazy_shared_ptr:: equal (const lazy_shared_ptr& r) const { - if (loaded () && r.loaded ()) + bool t1 (!p_ == loaded ()); + bool t2 (!r.p_ == r.loaded ()); + + // If both are transient, then compare the underlying pointers. + // + if (t1 && t2) return p_ == r.p_; - // If one of the object is not loaded, then we compare databases and - // object ids. Note that NULL pointers cannot have non-NULL databases - // and if both of them are NULL, we wouldn't have gotten here. + // If one is transient and the other is persistent, then compare + // the underlying pointers but only if they are non NULL. Note + // that an unloaded persistent object is always unequal to a + // transient object. + // + if (t1 || t2) + return p_ == r.p_ && p_; + + // If both objects are persistent, then we compare databases and + // object ids. // typedef typename object_traits::object_type object_type1; typedef typename object_traits::object_type object_type2; -- cgit v1.1