From b2b8dba6c149407d6657398a874c75629871d21a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 Apr 2011 11:15:37 +0200 Subject: Fix loaded() function in lazy_ptr to conform to documentation --- odb/lazy-ptr.txx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'odb/lazy-ptr.txx') diff --git a/odb/lazy-ptr.txx b/odb/lazy-ptr.txx index 56f1473..0b7bbea 100644 --- a/odb/lazy-ptr.txx +++ b/odb/lazy-ptr.txx @@ -14,12 +14,24 @@ namespace odb bool lazy_ptr:: equal (const lazy_ptr& r) const { - if (loaded () && r.loaded ()) + bool t1 ((p_ == 0) == loaded ()); + bool t2 ((r.p_ == 0) == 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_ != 0; + + // 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