// file : odb/qt/smart-ptr/lazy-ptr.txx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file template template bool QLazySharedPointer:: equal (const QLazySharedPointer& r) const { 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 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 odb::object_traits::object_type object_type1; typedef typename odb::object_traits::object_type object_type2; return i_.database () == r.i_.database () && objectId () == r.template objectId (); } // // QLazyWeakPointer // template template bool QLazyWeakPointer:: equal (const QLazyWeakPointer& r) const { if (isNull () && r.isNull ()) return true; QLazySharedPointer sp1 (toStrongRef ()); QLazySharedPointer sp2 (r.toStrongRef ()); // If either one has expired, they are not equal. // if (!sp1 || !sp2) return false; return sp1.equal (sp2); } template template bool QLazyWeakPointer:: equal (const QLazySharedPointer& r) const { if (isNull () && r.isNull ()) return true; QLazySharedPointer sp (toStrongRef ()); // If the weak pointer has expired, they are not equal. // if (!sp) return false; return r.equal (sp); } template QLazySharedPointer QLazyWeakPointer:: toStrongRef () const { QSharedPointer sp (p_.toStrongRef ()); if (sp) { if (database_type* db = i_.database ()) return QLazySharedPointer (*db, sp); else return QLazySharedPointer (sp); } else { if (i_) return QLazySharedPointer ( *i_.database (), i_.template object_id ()); else return QLazySharedPointer (); } }