aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-08-14 11:27:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-08-14 11:27:35 +0200
commit8ceee297981402eb5331f357b27ebfac11706ec4 (patch)
treebb4d5d26bb450a3f0f0e499360f90d900b557521
parent9bf4ff12e6d96870fa48785846de5c96411ec5ea (diff)
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.
-rw-r--r--odb/lazy-ptr.hxx6
-rw-r--r--odb/lazy-ptr.ixx7
-rw-r--r--odb/lazy-ptr.txx28
-rw-r--r--odb/tr1/lazy-ptr.hxx7
-rw-r--r--odb/tr1/lazy-ptr.ixx7
-rw-r--r--odb/tr1/lazy-ptr.txx27
6 files changed, 27 insertions, 55 deletions
diff --git a/odb/lazy-ptr.hxx b/odb/lazy-ptr.hxx
index 5e099aa..ccc6c3c 100644
--- a/odb/lazy-ptr.hxx
+++ b/odb/lazy-ptr.hxx
@@ -519,6 +519,12 @@ namespace odb
template <class Y> friend class lazy_shared_ptr;
template <class Y> friend class lazy_weak_ptr;
+ // For lazy_weak_ptr::lock().
+ //
+ lazy_shared_ptr (std::shared_ptr<T>&& p, const lazy_ptr_impl<T>& i)
+ : p_ (std::move (p)), i_ (i) {}
+
+ private:
mutable std::shared_ptr<T> p_;
mutable lazy_ptr_impl<T> i_;
};
diff --git a/odb/lazy-ptr.ixx b/odb/lazy-ptr.ixx
index ccfcd47..9ffa945 100644
--- a/odb/lazy-ptr.ixx
+++ b/odb/lazy-ptr.ixx
@@ -1540,6 +1540,13 @@ namespace odb
}
template <class T>
+ inline lazy_shared_ptr<T> lazy_weak_ptr<T>::
+ lock () const
+ {
+ return lazy_shared_ptr<T> (p_.lock (), i_);
+ }
+
+ template <class T>
inline std::shared_ptr<T> lazy_weak_ptr<T>::
load () const
{
diff --git a/odb/lazy-ptr.txx b/odb/lazy-ptr.txx
index 81065c3..67319ec 100644
--- a/odb/lazy-ptr.txx
+++ b/odb/lazy-ptr.txx
@@ -110,34 +110,6 @@ namespace odb
return i_.database () == r.i_.database () &&
object_id<object_type1> () == r.template object_id<object_type2> ();
}
-
- //
- // lazy_weak_ptr
- //
-
- template <class T>
- lazy_shared_ptr<T> lazy_weak_ptr<T>::
- lock () const
- {
- std::shared_ptr<T> sp (p_.lock ());
-
- if (sp)
- {
- if (database_type* db = i_.database ())
- return lazy_shared_ptr<T> (*db, sp);
- else
- return lazy_shared_ptr<T> (sp);
- }
- else
- {
- if (i_)
- return lazy_shared_ptr<T> (
- *i_.database (), i_.template object_id<T> ());
- else
- return lazy_shared_ptr<T> ();
- }
- }
-
#endif // ODB_CXX11
}
diff --git a/odb/tr1/lazy-ptr.hxx b/odb/tr1/lazy-ptr.hxx
index 4579090..1c5d8ca 100644
--- a/odb/tr1/lazy-ptr.hxx
+++ b/odb/tr1/lazy-ptr.hxx
@@ -134,6 +134,13 @@ namespace odb
template <class Y> friend class lazy_shared_ptr;
template <class Y> friend class lazy_weak_ptr;
+ // For lazy_weak_ptr::lock().
+ //
+ lazy_shared_ptr (const std::tr1::shared_ptr<T>& p,
+ const lazy_ptr_impl<T>& i)
+ : p_ (p), i_ (i) {}
+
+ private:
mutable std::tr1::shared_ptr<T> p_;
mutable lazy_ptr_impl<T> i_;
};
diff --git a/odb/tr1/lazy-ptr.ixx b/odb/tr1/lazy-ptr.ixx
index 45386bd..283118c 100644
--- a/odb/tr1/lazy-ptr.ixx
+++ b/odb/tr1/lazy-ptr.ixx
@@ -501,6 +501,13 @@ namespace odb
}
template <class T>
+ inline lazy_shared_ptr<T> lazy_weak_ptr<T>::
+ lock () const
+ {
+ return lazy_shared_ptr<T> (p_.lock (), i_);
+ }
+
+ template <class T>
inline std::tr1::shared_ptr<T> lazy_weak_ptr<T>::
load () const
{
diff --git a/odb/tr1/lazy-ptr.txx b/odb/tr1/lazy-ptr.txx
index 1f39aec..2fbacb7 100644
--- a/odb/tr1/lazy-ptr.txx
+++ b/odb/tr1/lazy-ptr.txx
@@ -40,32 +40,5 @@ namespace odb
return i_.database () == r.i_.database () &&
object_id<object_type1> () == r.template object_id<object_type2> ();
}
-
- //
- // lazy_weak_ptr
- //
-
- template <class T>
- lazy_shared_ptr<T> lazy_weak_ptr<T>::
- lock () const
- {
- std::tr1::shared_ptr<T> sp (p_.lock ());
-
- if (sp)
- {
- if (database_type* db = i_.database ())
- return lazy_shared_ptr<T> (*db, sp);
- else
- return lazy_shared_ptr<T> (sp);
- }
- else
- {
- if (i_)
- return lazy_shared_ptr<T> (
- *i_.database (), i_.template object_id<T> ());
- else
- return lazy_shared_ptr<T> ();
- }
- }
}
}