From 5398b886ed0da065fe084da0f107bebba0a163ba Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 14 Aug 2015 11:27:36 +0200 Subject: Reimplement lazy_weak_ptr lock() to preserve database type Now we initialize the returned lazy_shared_ptr with the same loader function as the one set for weak_ptr. --- odb/qt/smart-ptr/lazy-ptr.hxx | 7 +++++++ odb/qt/smart-ptr/lazy-ptr.ixx | 7 +++++++ odb/qt/smart-ptr/lazy-ptr.txx | 23 ----------------------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/odb/qt/smart-ptr/lazy-ptr.hxx b/odb/qt/smart-ptr/lazy-ptr.hxx index e964837..664eb7f 100644 --- a/odb/qt/smart-ptr/lazy-ptr.hxx +++ b/odb/qt/smart-ptr/lazy-ptr.hxx @@ -196,6 +196,13 @@ private: template friend class QLazySharedPointer; template friend class QLazyWeakPointer; + // For QLazyWeakPointer::toStrongRef(). + // + QLazySharedPointer (const QSharedPointer& p, + const odb::lazy_ptr_impl& i) + : p_ (p), i_ (i) {} + +private: mutable QSharedPointer p_; mutable odb::lazy_ptr_impl i_; }; diff --git a/odb/qt/smart-ptr/lazy-ptr.ixx b/odb/qt/smart-ptr/lazy-ptr.ixx index d2b462f..181044c 100644 --- a/odb/qt/smart-ptr/lazy-ptr.ixx +++ b/odb/qt/smart-ptr/lazy-ptr.ixx @@ -196,6 +196,13 @@ loaded () const } template +inline QLazySharedPointer QLazyWeakPointer:: +toStrongRef () const +{ + return QLazySharedPointer (p_.toStrongRef (), i_); +} + +template inline QSharedPointer QLazySharedPointer:: load () const { diff --git a/odb/qt/smart-ptr/lazy-ptr.txx b/odb/qt/smart-ptr/lazy-ptr.txx index 9e8be80..2497811 100644 --- a/odb/qt/smart-ptr/lazy-ptr.txx +++ b/odb/qt/smart-ptr/lazy-ptr.txx @@ -73,26 +73,3 @@ equal (const QLazySharedPointer& r) const 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 (); - } -} -- cgit v1.1