aboutsummaryrefslogtreecommitdiff
path: root/odb/boost/smart-ptr/lazy-ptr.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-02-04 13:56:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-02-04 13:56:09 +0200
commitf1c2a621ac2695dfe4a3bc71dbc9ce3079008d2f (patch)
treed0c45ecd5489cd1b4beb57fc5afda3263ad0d2b2 /odb/boost/smart-ptr/lazy-ptr.txx
parent6a07b88cdf6419440b19e7b7dbc9231519c32c62 (diff)
Add support for smart-ptr, unordered, and date_time (basic)
Diffstat (limited to 'odb/boost/smart-ptr/lazy-ptr.txx')
-rw-r--r--odb/boost/smart-ptr/lazy-ptr.txx59
1 files changed, 59 insertions, 0 deletions
diff --git a/odb/boost/smart-ptr/lazy-ptr.txx b/odb/boost/smart-ptr/lazy-ptr.txx
new file mode 100644
index 0000000..bca6fdb
--- /dev/null
+++ b/odb/boost/smart-ptr/lazy-ptr.txx
@@ -0,0 +1,59 @@
+// file : odb/boost/smart-ptr/lazy-ptr.txx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+namespace odb
+{
+ namespace boost
+ {
+ //
+ // lazy_shared_ptr
+ //
+
+ template <class T>
+ template <class Y>
+ bool lazy_shared_ptr<T>::
+ equal (const lazy_shared_ptr<Y>& r) const
+ {
+ if (loaded () && r.loaded ())
+ 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.
+ //
+ typedef typename object_traits<T>::object_type object_type1;
+ typedef typename object_traits<Y>::object_type object_type2;
+
+ return i_.database () == r.i_.database () &&
+ object_id<object_type1> () == r.object_id<object_type2> ();
+ }
+
+ //
+ // lazy_weak_ptr
+ //
+
+ template <class T>
+ lazy_shared_ptr<T> lazy_weak_ptr<T>::
+ lock () const
+ {
+ ::boost::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_.object_id<T> ());
+ else
+ return lazy_shared_ptr<T> ();
+ }
+ }
+ }
+}