summaryrefslogtreecommitdiff
path: root/libodb/odb/tr1
diff options
context:
space:
mode:
Diffstat (limited to 'libodb/odb/tr1')
-rw-r--r--libodb/odb/tr1/lazy-pointer-traits.hxx61
-rw-r--r--libodb/odb/tr1/lazy-ptr.hxx267
-rw-r--r--libodb/odb/tr1/lazy-ptr.ixx638
-rw-r--r--libodb/odb/tr1/lazy-ptr.txx43
-rw-r--r--libodb/odb/tr1/memory.hxx37
-rw-r--r--libodb/odb/tr1/pointer-traits.hxx121
-rw-r--r--libodb/odb/tr1/wrapper-traits.hxx76
7 files changed, 1243 insertions, 0 deletions
diff --git a/libodb/odb/tr1/lazy-pointer-traits.hxx b/libodb/odb/tr1/lazy-pointer-traits.hxx
new file mode 100644
index 0000000..7adf957
--- /dev/null
+++ b/libodb/odb/tr1/lazy-pointer-traits.hxx
@@ -0,0 +1,61 @@
+// file : odb/tr1/lazy-pointer-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_TR1_LAZY_POINTER_TRAITS_HXX
+#define ODB_TR1_LAZY_POINTER_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/pointer-traits.hxx>
+#include <odb/tr1/lazy-ptr.hxx>
+
+namespace odb
+{
+ template <typename T>
+ class pointer_traits<tr1::lazy_shared_ptr<T> >
+ {
+ public:
+ static const pointer_kind kind = pk_shared;
+ static const bool lazy = true;
+
+ typedef T element_type;
+ typedef tr1::lazy_shared_ptr<element_type> pointer_type;
+ typedef std::tr1::shared_ptr<element_type> eager_pointer_type;
+
+ static bool
+ null_ptr (const pointer_type& p)
+ {
+ return !p;
+ }
+
+ template <class O /* = T */>
+ static typename object_traits<O>::id_type
+ object_id (const pointer_type& p)
+ {
+ return p.template object_id<O> ();
+ }
+ };
+
+ template <typename T>
+ class pointer_traits<tr1::lazy_weak_ptr<T> >
+ {
+ public:
+ static const pointer_kind kind = pk_weak;
+ static const bool lazy = true;
+
+ typedef T element_type;
+ typedef tr1::lazy_weak_ptr<element_type> pointer_type;
+ typedef tr1::lazy_shared_ptr<element_type> strong_pointer_type;
+ typedef std::tr1::weak_ptr<element_type> eager_pointer_type;
+
+ static strong_pointer_type
+ lock (const pointer_type& p)
+ {
+ return p.lock ();
+ }
+ };
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_TR1_LAZY_POINTER_TRAITS_HXX
diff --git a/libodb/odb/tr1/lazy-ptr.hxx b/libodb/odb/tr1/lazy-ptr.hxx
new file mode 100644
index 0000000..b4946ec
--- /dev/null
+++ b/libodb/odb/tr1/lazy-ptr.hxx
@@ -0,0 +1,267 @@
+// file : odb/tr1/lazy-ptr.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_TR1_LAZY_PTR_HXX
+#define ODB_TR1_LAZY_PTR_HXX
+
+#include <odb/pre.hxx>
+
+//
+// This header assumes that the necessary TR1 header has already
+// been included.
+//
+
+#include <memory> // std::auto_ptr
+
+#include <odb/forward.hxx> // odb::database
+#include <odb/traits.hxx>
+#include <odb/lazy-ptr-impl.hxx>
+#include <odb/details/config.hxx> // ODB_CXX11
+
+namespace odb
+{
+ namespace tr1
+ {
+ template <class T>
+ class lazy_weak_ptr;
+
+ //
+ //
+ template <class T>
+ class lazy_shared_ptr
+ {
+ // The standard shared_ptr interface.
+ //
+ public:
+ typedef T element_type;
+
+ lazy_shared_ptr ();
+ template <class Y> explicit lazy_shared_ptr (Y*);
+ template <class Y, class D> lazy_shared_ptr (Y*, D);
+
+ lazy_shared_ptr (const lazy_shared_ptr&);
+ template <class Y> lazy_shared_ptr (const lazy_shared_ptr<Y>&);
+ template <class Y> explicit lazy_shared_ptr (const lazy_weak_ptr<Y>&);
+ template <class Y> explicit lazy_shared_ptr (std::auto_ptr<Y>&);
+
+ ~lazy_shared_ptr ();
+
+ lazy_shared_ptr& operator= (const lazy_shared_ptr&);
+ template <class Y> lazy_shared_ptr& operator= (const lazy_shared_ptr<Y>&);
+ template <class Y> lazy_shared_ptr& operator= (std::auto_ptr<Y>&);
+
+ void swap (lazy_shared_ptr&);
+ void reset ();
+ template <class Y> void reset (Y*);
+ template <class Y, class D> void reset (Y*, D);
+
+ T& operator* () const;
+ T* operator-> () const;
+ T* get () const;
+
+ bool unique () const;
+ long use_count () const;
+
+ typedef std::tr1::shared_ptr<T> lazy_shared_ptr::*unspecified_bool_type;
+ operator unspecified_bool_type () const
+ {
+ return (p_ || i_) ? &lazy_shared_ptr::p_ : 0;
+ }
+
+ // Initialization/assignment from shared_ptr and weak_ptr.
+ //
+ public:
+ template <class Y> lazy_shared_ptr (const std::tr1::shared_ptr<Y>&);
+ template <class Y> explicit lazy_shared_ptr (const std::tr1::weak_ptr<Y>&);
+
+ template <class Y> lazy_shared_ptr& operator= (const std::tr1::shared_ptr<Y>&);
+
+ // Lazy loading interface.
+ //
+ public:
+ typedef odb::database database_type;
+
+ // NULL loaded()
+ //
+ // true true NULL pointer to transient object
+ // false true valid pointer to persistent object
+ // true false unloaded pointer to persistent object
+ // false false valid pointer to transient object
+ //
+ bool loaded () const;
+
+ std::tr1::shared_ptr<T> load () const;
+
+ // Unload the pointer. For transient objects this function is
+ // equivalent to reset().
+ //
+ void unload () const;
+
+ // Get the underlying eager pointer. If this is an unloaded pointer
+ // to a persistent object, then the returned pointer will be NULL.
+ //
+ std::tr1::shared_ptr<T> get_eager () const;
+
+ template <class DB, class ID> lazy_shared_ptr (DB&, const ID&);
+ template <class DB, class Y> lazy_shared_ptr (DB&, Y*);
+ template <class DB, class Y, class D> lazy_shared_ptr (DB&, Y*, D);
+ template <class DB, class Y> lazy_shared_ptr (DB&, std::auto_ptr<Y>&);
+ template <class DB, class Y> lazy_shared_ptr (DB&, const std::tr1::shared_ptr<Y>&);
+ template <class DB, class Y> lazy_shared_ptr (DB&, const std::tr1::weak_ptr<Y>&);
+
+ template <class DB, class ID> void reset (DB&, const ID&);
+ template <class DB, class Y> void reset (DB&, Y*);
+ template <class DB, class Y, class D> void reset (DB&, Y*, D);
+ template <class DB, class Y> void reset (DB&, std::auto_ptr<Y>&);
+ template <class DB, class Y> void reset (DB&, const std::tr1::shared_ptr<Y>&);
+
+#ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT
+ template <class O = T>
+#else
+ template <class O /*= T*/>
+#endif
+ typename object_traits<O>::id_type object_id () const;
+
+ database_type& database () const;
+
+ // Helpers.
+ //
+ public:
+ template <class Y> bool equal (const lazy_shared_ptr<Y>&) const;
+
+ private:
+ 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_;
+ };
+
+ // operator< and operator<< are not provided.
+ //
+ template<class T, class Y>
+ bool operator== (const lazy_shared_ptr<T>&, const lazy_shared_ptr<Y>&);
+
+ template<class T, class Y>
+ bool operator!= (const lazy_shared_ptr<T>&, const lazy_shared_ptr<Y>&);
+
+ template<class T> void swap (lazy_shared_ptr<T>&, lazy_shared_ptr<T>&);
+
+ template<class D, class T>
+ D* get_deleter (const lazy_shared_ptr<T>&);
+
+ //
+ //
+ template <class T>
+ class lazy_weak_ptr
+ {
+ // The standard weak_ptr interface.
+ //
+ public:
+ typedef T element_type;
+
+ lazy_weak_ptr ();
+ template <class Y> lazy_weak_ptr (const lazy_shared_ptr<Y>&);
+ lazy_weak_ptr (const lazy_weak_ptr&);
+ template <class Y> lazy_weak_ptr (const lazy_weak_ptr<Y>&);
+
+ ~lazy_weak_ptr ();
+
+ lazy_weak_ptr& operator= (const lazy_weak_ptr&);
+ template <class Y> lazy_weak_ptr& operator= (const lazy_weak_ptr<Y>&);
+ template <class Y> lazy_weak_ptr& operator= (const lazy_shared_ptr<Y>&);
+
+ void swap (lazy_weak_ptr<T>&);
+ void reset ();
+
+ long use_count () const;
+ bool expired () const;
+
+ lazy_shared_ptr<T> lock () const;
+
+ // Initialization/assignment from shared_ptr and weak_ptr.
+ //
+ public:
+ template <class Y> lazy_weak_ptr (const std::tr1::weak_ptr<Y>&);
+ template <class Y> lazy_weak_ptr (const std::tr1::shared_ptr<Y>&);
+
+ template <class Y> lazy_weak_ptr& operator= (const std::tr1::weak_ptr<Y>&);
+ template <class Y> lazy_weak_ptr& operator= (const std::tr1::shared_ptr<Y>&);
+
+ // Lazy loading interface.
+ //
+ public:
+ typedef odb::database database_type;
+
+ // expired() loaded()
+ //
+ // true true expired pointer to transient object
+ // false true valid pointer to persistent object
+ // true false expired pointer to persistent object
+ // false false valid pointer to transient object
+ //
+ bool loaded () const;
+
+ // Performs both lock and load.
+ //
+ std::tr1::shared_ptr<T> load () const;
+
+ // Unload the pointer. For transient objects this function is
+ // equivalent to reset().
+ //
+ void unload () const;
+
+ // Get the underlying eager pointer. If this is an unloaded pointer
+ // to a persistent object, then the returned pointer will be NULL.
+ //
+ std::tr1::weak_ptr<T> get_eager () const;
+
+ template <class DB, class ID> lazy_weak_ptr (DB&, const ID&);
+ template <class DB, class Y> lazy_weak_ptr (DB&, const std::tr1::shared_ptr<Y>&);
+ template <class DB, class Y> lazy_weak_ptr (DB&, const std::tr1::weak_ptr<Y>&);
+
+ template <class DB, class ID> void reset (DB&, const ID&);
+ template <class DB, class Y> void reset (DB&, const std::tr1::shared_ptr<Y>&);
+ template <class DB, class Y> void reset (DB&, const std::tr1::weak_ptr<Y>&);
+
+ // The object_id() function can only be called when the object is
+ // persistent, or: expired() XOR loaded() (can use != for XOR).
+ //
+#ifdef ODB_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGUMENT
+ template <class O = T>
+#else
+ template <class O /* = T */>
+#endif
+ typename object_traits<O>::id_type object_id () const;
+
+ database_type& database () const;
+
+ private:
+ template <class Y> friend class lazy_shared_ptr;
+ template <class Y> friend class lazy_weak_ptr;
+
+ mutable std::tr1::weak_ptr<T> p_;
+ mutable lazy_ptr_impl<T> i_;
+ };
+
+ // operator< is not provided.
+ //
+ template<class T> void swap (lazy_weak_ptr<T>&, lazy_weak_ptr<T>&);
+ }
+}
+
+#include <odb/tr1/lazy-ptr.ixx>
+#include <odb/tr1/lazy-ptr.txx>
+
+#include <odb/tr1/lazy-pointer-traits.hxx>
+
+#include <odb/post.hxx>
+
+#endif // ODB_TR1_LAZY_PTR_HXX
diff --git a/libodb/odb/tr1/lazy-ptr.ixx b/libodb/odb/tr1/lazy-ptr.ixx
new file mode 100644
index 0000000..dc5000f
--- /dev/null
+++ b/libodb/odb/tr1/lazy-ptr.ixx
@@ -0,0 +1,638 @@
+// file : odb/tr1/lazy-ptr.ixx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+namespace odb
+{
+ namespace tr1
+ {
+ //
+ // lazy_shared_ptr
+ //
+
+ template <class T>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr () {}
+
+ template <class T>
+ template <class Y>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (Y* p): p_ (p) {}
+
+ template <class T>
+ template <class Y, class D>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (Y* p, D d): p_ (p, d) {}
+
+ template <class T>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (const lazy_shared_ptr& r): p_ (r.p_), i_ (r.i_) {}
+
+ template <class T>
+ template <class Y>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (const lazy_shared_ptr<Y>& r): p_ (r.p_), i_ (r.i_) {}
+
+ template <class T>
+ template <class Y>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (const lazy_weak_ptr<Y>& r): i_ (r.i_)
+ {
+ // If the pointer has expired but can be re-loaded, then don't throw.
+ //
+ p_ = r.lock ();
+
+ if (!p_ && !i_)
+ throw std::tr1::bad_weak_ptr ();
+ }
+
+ template <class T>
+ template <class Y>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (std::auto_ptr<Y>& r): p_ (r) {}
+
+ template <class T>
+ inline lazy_shared_ptr<T>::
+ ~lazy_shared_ptr () {}
+
+ template <class T>
+ inline lazy_shared_ptr<T>& lazy_shared_ptr<T>::
+ operator= (const lazy_shared_ptr& r)
+ {
+ p_ = r.p_;
+ i_ = r.i_;
+ return *this;
+ }
+
+ template <class T>
+ template <class Y>
+ inline lazy_shared_ptr<T>& lazy_shared_ptr<T>::
+ operator= (const lazy_shared_ptr<Y>& r)
+ {
+ p_ = r.p_;
+ i_ = r.i_;
+ return *this;
+ }
+
+ template <class T>
+ template <class Y>
+ inline lazy_shared_ptr<T>& lazy_shared_ptr<T>::
+ operator= (std::auto_ptr<Y>& r)
+ {
+ p_ = r;
+ i_.reset ();
+ return *this;
+ }
+
+ template <class T>
+ inline void lazy_shared_ptr<T>::
+ swap (lazy_shared_ptr& b)
+ {
+ p_.swap (b.p_);
+ i_.swap (b.i_);
+ }
+
+ template <class T>
+ inline void lazy_shared_ptr<T>::
+ reset ()
+ {
+ p_.reset ();
+ i_.reset ();
+ }
+
+ template <class T>
+ template <class Y>
+ inline void lazy_shared_ptr<T>::
+ reset (Y* p)
+ {
+ p_.reset (p);
+ i_.reset ();
+ }
+
+ template <class T>
+ template <class Y, class D>
+ inline void lazy_shared_ptr<T>::
+ reset (Y* p, D d)
+ {
+ p_.reset (p, d);
+ i_.reset ();
+ }
+
+ template <class T>
+ inline T& lazy_shared_ptr<T>::
+ operator* () const
+ {
+ return *p_;
+ }
+
+ template <class T>
+ inline T* lazy_shared_ptr<T>::
+ operator-> () const
+ {
+ return p_.operator-> ();
+ }
+
+ template <class T>
+ inline T* lazy_shared_ptr<T>::
+ get () const
+ {
+ return p_.get ();
+ }
+
+ template <class T>
+ inline bool lazy_shared_ptr<T>::
+ unique () const
+ {
+ return p_.unique ();
+ }
+
+ template <class T>
+ inline long lazy_shared_ptr<T>::
+ use_count () const
+ {
+ return p_.use_count ();
+ }
+
+ template <class T>
+ template <class Y>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (const std::tr1::shared_ptr<Y>& r): p_ (r) {}
+
+ template <class T>
+ template <class Y>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (const std::tr1::weak_ptr<Y>& r): p_ (r) {}
+
+ template <class T>
+ template <class Y>
+ inline lazy_shared_ptr<T>& lazy_shared_ptr<T>::
+ operator= (const std::tr1::shared_ptr<Y>& r)
+ {
+ p_ = r;
+ i_.reset ();
+ return *this;
+ }
+
+ template <class T>
+ inline bool lazy_shared_ptr<T>::
+ loaded () const
+ {
+ bool i (i_);
+ return !p_ != i; // !p_ XOR i_
+ }
+
+ template <class T>
+ inline std::tr1::shared_ptr<T> lazy_shared_ptr<T>::
+ load () const
+ {
+ if (!p_ && i_)
+ p_ = i_.template load<T> (true); // Reset id.
+
+ return p_;
+ }
+
+ template <class T>
+ inline void lazy_shared_ptr<T>::
+ unload () const
+ {
+ typedef typename object_traits<T>::object_type object_type;
+
+ if (p_)
+ {
+ if (i_.database () != 0)
+ i_.reset_id (object_traits<object_type>::id (*p_));
+
+ p_.reset ();
+ }
+ }
+
+ template <class T>
+ inline std::tr1::shared_ptr<T> lazy_shared_ptr<T>::
+ get_eager () const
+ {
+ return p_;
+ }
+
+ template <class T>
+ template <class DB, class ID>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (DB& db, const ID& id): i_ (db, id) {}
+
+ template <class T>
+ template <class DB, class Y>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (DB& db, Y* p)
+ : p_ (p)
+ {
+ if (p_)
+ i_.reset_db (db);
+ }
+
+ template <class T>
+ template <class DB, class Y, class D>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (DB& db, Y* p, D d)
+ : p_ (p, d)
+ {
+ if (p_)
+ i_.reset_db (db);
+ }
+
+ template <class T>
+ template <class DB, class Y>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (DB& db, std::auto_ptr<Y>& r)
+ : p_ (r)
+ {
+ if (p_)
+ i_.reset_db (db);
+ }
+
+ template <class T>
+ template <class DB, class Y>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (DB& db, const std::tr1::shared_ptr<Y>& r)
+ : p_ (r)
+ {
+ if (p_)
+ i_.reset_db (db);
+ }
+
+ template <class T>
+ template <class DB, class Y>
+ inline lazy_shared_ptr<T>::
+ lazy_shared_ptr (DB& db, const std::tr1::weak_ptr<Y>& r)
+ : p_ (r)
+ {
+ if (p_)
+ i_.reset_db (db);
+ }
+
+ template <class T>
+ template <class DB, class ID>
+ inline void lazy_shared_ptr<T>::
+ reset (DB& db, const ID& id)
+ {
+ p_.reset ();
+ i_.reset (db, id);
+ }
+
+ template <class T>
+ template <class DB, class Y>
+ inline void lazy_shared_ptr<T>::
+ reset (DB& db, Y* p)
+ {
+ p_.reset (p);
+
+ if (p_)
+ i_.reset_db (db);
+ else
+ i_.reset ();
+ }
+
+ template <class T>
+ template <class DB, class Y, class D>
+ inline void lazy_shared_ptr<T>::
+ reset (DB& db, Y* p, D d)
+ {
+ p_.reset (p, d);
+
+ if (p_)
+ i_.reset_db (db);
+ else
+ i_.reset ();
+ }
+
+ template <class T>
+ template <class DB, class Y>
+ inline void lazy_shared_ptr<T>::
+ reset (DB& db, std::auto_ptr<Y>& r)
+ {
+ p_ = r;
+
+ if (p_)
+ i_.reset_db (db);
+ else
+ i_.reset ();
+ }
+
+ template <class T>
+ template <class DB, class Y>
+ inline void lazy_shared_ptr<T>::
+ reset (DB& db, const std::tr1::shared_ptr<Y>& r)
+ {
+ p_ = r;
+
+ if (p_)
+ i_.reset_db (db);
+ else
+ i_.reset ();
+ }
+
+ template <class T>
+ template <class O>
+ inline typename object_traits<O>::id_type lazy_shared_ptr<T>::
+ object_id () const
+ {
+ typedef typename object_traits<T>::object_type object_type;
+
+ return p_
+ ? object_traits<object_type>::id (*p_)
+ : i_.template object_id<O> ();
+ }
+
+ template <class T>
+ inline typename lazy_shared_ptr<T>::database_type& lazy_shared_ptr<T>::
+ database () const
+ {
+ return *i_.database ();
+ }
+
+ template<class T, class Y>
+ inline bool
+ operator== (const lazy_shared_ptr<T>& a, const lazy_shared_ptr<Y>& b)
+ {
+ return a.equal (b);
+ }
+
+ template<class T, class Y>
+ inline bool
+ operator!= (const lazy_shared_ptr<T>& a, const lazy_shared_ptr<Y>& b)
+ {
+ return !a.equal (b);
+ }
+
+ template<class T>
+ inline void
+ swap (lazy_shared_ptr<T>& a, lazy_shared_ptr<T>& b)
+ {
+ a.swap (b);
+ }
+
+ template<class D, class T>
+ inline D*
+ get_deleter (const lazy_shared_ptr<T>& p)
+ {
+ return std::tr1::get_deleter<D> (p.p_);
+ }
+
+
+ //
+ // lazy_weak_ptr
+ //
+
+ template <class T>
+ inline lazy_weak_ptr<T>::
+ lazy_weak_ptr () {}
+
+ template <class T>
+ template <class Y>
+ inline lazy_weak_ptr<T>::
+ lazy_weak_ptr (const lazy_shared_ptr<Y>& r): p_ (r.p_), i_ (r.i_) {}
+
+ template <class T>
+ inline lazy_weak_ptr<T>::
+ lazy_weak_ptr (const lazy_weak_ptr& r): p_ (r.p_), i_ (r.i_) {}
+
+ template <class T>
+ template <class Y>
+ inline lazy_weak_ptr<T>::
+ lazy_weak_ptr (const lazy_weak_ptr<Y>& r): p_ (r.p_), i_ (r.i_) {}
+
+ template <class T>
+ inline lazy_weak_ptr<T>::
+ ~lazy_weak_ptr () {}
+
+ template <class T>
+ inline lazy_weak_ptr<T>& lazy_weak_ptr<T>::
+ operator= (const lazy_weak_ptr& r)
+ {
+ p_ = r.p_;
+ i_ = r.i_;
+ return *this;
+ }
+
+ template <class T>
+ template <class Y>
+ inline lazy_weak_ptr<T>& lazy_weak_ptr<T>::
+ operator= (const lazy_weak_ptr<Y>& r)
+ {
+ p_ = r.p_;
+ i_ = r.i_;
+ return *this;
+ }
+
+ template <class T>
+ template <class Y>
+ inline lazy_weak_ptr<T>& lazy_weak_ptr<T>::
+ operator= (const lazy_shared_ptr<Y>& r)
+ {
+ p_ = r.p_;
+ i_ = r.i_;
+ return *this;
+ }
+
+ template <class T>
+ inline void lazy_weak_ptr<T>::
+ swap (lazy_weak_ptr<T>& r)
+ {
+ p_.swap (r.p_);
+ i_.swap (r.i_);
+ }
+
+ template <class T>
+ inline void lazy_weak_ptr<T>::
+ reset ()
+ {
+ p_.reset ();
+ i_.reset ();
+ }
+
+ template <class T>
+ inline long lazy_weak_ptr<T>::
+ use_count () const
+ {
+ return p_.use_count ();
+ }
+
+ template <class T>
+ inline bool lazy_weak_ptr<T>::
+ expired () const
+ {
+ return p_.expired ();
+ }
+
+ template <class T>
+ template <class Y>
+ inline lazy_weak_ptr<T>::
+ lazy_weak_ptr (const std::tr1::weak_ptr<Y>& r): p_ (r) {}
+
+ template <class T>
+ template <class Y>
+ inline lazy_weak_ptr<T>::
+ lazy_weak_ptr (const std::tr1::shared_ptr<Y>& r): p_ (r) {}
+
+ template <class T>
+ template <class Y>
+ inline lazy_weak_ptr<T>& lazy_weak_ptr<T>::
+ operator= (const std::tr1::weak_ptr<Y>& r)
+ {
+ p_ = r;
+ i_.reset ();
+ return *this;
+ }
+
+ template <class T>
+ template <class Y>
+ inline lazy_weak_ptr<T>& lazy_weak_ptr<T>::
+ operator= (const std::tr1::shared_ptr<Y>& r)
+ {
+ p_ = r;
+ i_.reset ();
+ return *this;
+ }
+
+ template <class T>
+ inline bool lazy_weak_ptr<T>::
+ loaded () const
+ {
+ bool i (i_);
+ return expired () != i; // expired () XOR i_
+ }
+
+ 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
+ {
+ std::tr1::shared_ptr<T> r (p_.lock ());
+
+ if (!r && i_)
+ {
+ r = i_.template load<T> (false); // Keep id.
+ p_ = r;
+ }
+
+ return r;
+ }
+
+ template <class T>
+ inline void lazy_weak_ptr<T>::
+ unload () const
+ {
+ // With weak pointer we always keep i_ up to date.
+ //
+ p_.reset ();
+ }
+
+ template <class T>
+ inline std::tr1::weak_ptr<T> lazy_weak_ptr<T>::
+ get_eager () const
+ {
+ return p_;
+ }
+
+ template <class T>
+ template <class DB, class ID>
+ inline lazy_weak_ptr<T>::
+ lazy_weak_ptr (DB& db, const ID& id): i_ (db, id) {}
+
+ template <class T>
+ template <class DB, class Y>
+ inline lazy_weak_ptr<T>::
+ lazy_weak_ptr (DB& db, const std::tr1::shared_ptr<Y>& r)
+ : p_ (r)
+ {
+ typedef typename object_traits<T>::object_type object_type;
+
+ if (r)
+ i_.reset (db, object_traits<object_type>::id (*r));
+ }
+
+ template <class T>
+ template <class DB, class Y>
+ inline lazy_weak_ptr<T>::
+ lazy_weak_ptr (DB& db, const std::tr1::weak_ptr<Y>& r)
+ : p_ (r)
+ {
+ typedef typename object_traits<T>::object_type object_type;
+
+ std::tr1::shared_ptr<T> sp (p_.lock ());
+
+ if (sp)
+ i_.reset (db, object_traits<object_type>::id (*sp));
+ }
+
+ template <class T>
+ template <class DB, class ID>
+ inline void lazy_weak_ptr<T>::
+ reset (DB& db, const ID& id)
+ {
+ p_.reset ();
+ i_.reset (db, id);
+ }
+
+ template <class T>
+ template <class DB, class Y>
+ inline void lazy_weak_ptr<T>::
+ reset (DB& db, const std::tr1::shared_ptr<Y>& r)
+ {
+ typedef typename object_traits<T>::object_type object_type;
+
+ p_ = r;
+
+ if (r)
+ i_.reset (db, object_traits<object_type>::id (*r));
+ else
+ i_.reset ();
+ }
+
+ template <class T>
+ template <class DB, class Y>
+ inline void lazy_weak_ptr<T>::
+ reset (DB& db, const std::tr1::weak_ptr<Y>& r)
+ {
+ typedef typename object_traits<T>::object_type object_type;
+
+ p_ = r;
+ std::tr1::shared_ptr<T> sp (p_.lock ());
+
+ if (sp)
+ i_.reset (db, object_traits<object_type>::id (*sp));
+ else
+ i_.reset ();
+ }
+
+ template <class T>
+ template <class O>
+ inline typename object_traits<O>::id_type lazy_weak_ptr<T>::
+ object_id () const
+ {
+ typedef typename object_traits<T>::object_type object_type;
+
+ std::tr1::shared_ptr<T> sp (p_.lock ());
+ return sp
+ ? object_traits<object_type>::id (*sp)
+ : i_.template object_id<O> ();
+ }
+
+ template <class T>
+ inline typename lazy_weak_ptr<T>::database_type& lazy_weak_ptr<T>::
+ database () const
+ {
+ return *i_.database ();
+ }
+
+ template<class T>
+ inline void
+ swap (lazy_weak_ptr<T>& a, lazy_weak_ptr<T>& b)
+ {
+ a.swap (b);
+ }
+ }
+}
diff --git a/libodb/odb/tr1/lazy-ptr.txx b/libodb/odb/tr1/lazy-ptr.txx
new file mode 100644
index 0000000..7e36cd9
--- /dev/null
+++ b/libodb/odb/tr1/lazy-ptr.txx
@@ -0,0 +1,43 @@
+// file : odb/tr1/lazy-ptr.txx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+namespace odb
+{
+ namespace tr1
+ {
+ //
+ // lazy_shared_ptr
+ //
+
+ template <class T>
+ template <class Y>
+ bool lazy_shared_ptr<T>::
+ equal (const lazy_shared_ptr<Y>& 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 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.template object_id<object_type2> ();
+ }
+ }
+}
diff --git a/libodb/odb/tr1/memory.hxx b/libodb/odb/tr1/memory.hxx
new file mode 100644
index 0000000..b9e9f45
--- /dev/null
+++ b/libodb/odb/tr1/memory.hxx
@@ -0,0 +1,37 @@
+// file : odb/tr1/memory.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_TR1_MEMORY_HXX
+#define ODB_TR1_MEMORY_HXX
+
+//
+// Try to include TR1 <memory> in a compiler-specific manner. Fall back
+// on the Boost TR1 implementation if the compiler does not support TR1.
+//
+
+#include <cstddef> // __GLIBCXX__, _HAS_TR1
+
+// GNU C++ or Intel C++ using libstd++.
+//
+#if defined (__GNUC__) && __GNUC__ >= 4 && defined (__GLIBCXX__)
+# include <tr1/memory>
+//
+// IBM XL C++.
+//
+#elif defined (__xlC__) && __xlC__ >= 0x0900
+# define __IBMCPP_TR1__
+# include <memory>
+//
+// VC++ or Intel C++ using VC++ standard library.
+//
+#elif defined (_MSC_VER) && \
+ (_MSC_VER == 1500 && defined (_HAS_TR1) || _MSC_VER > 1500)
+# include <memory>
+//
+// Boost fall-back.
+//
+#else
+# include <boost/tr1/memory.hpp>
+#endif
+
+#endif // ODB_TR1_MEMORY_HXX
diff --git a/libodb/odb/tr1/pointer-traits.hxx b/libodb/odb/tr1/pointer-traits.hxx
new file mode 100644
index 0000000..df4f25f
--- /dev/null
+++ b/libodb/odb/tr1/pointer-traits.hxx
@@ -0,0 +1,121 @@
+// file : odb/tr1/pointer-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_TR1_POINTER_TRAITS_HXX
+#define ODB_TR1_POINTER_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/details/config.hxx> // ODB_CXX11
+
+// In VC++ std::shared_ptr and std::tr1::shared_ptr is the same class
+// template. One is just a using-declaration for the other.
+//
+#if !(defined(ODB_CXX11) && defined(_MSC_VER))
+
+//
+// This header assumes that the necessary TR1 header has already
+// been included.
+//
+
+#include <odb/pointer-traits.hxx>
+#include <odb/details/meta/remove-const.hxx>
+
+namespace odb
+{
+ // Specialization for std::tr1::shared_ptr.
+ //
+ template <typename T>
+ class pointer_traits<std::tr1::shared_ptr<T> >
+ {
+ public:
+ static const pointer_kind kind = pk_shared;
+ static const bool lazy = false;
+
+ typedef T element_type;
+ typedef std::tr1::shared_ptr<element_type> pointer_type;
+ typedef std::tr1::shared_ptr<const element_type> const_pointer_type;
+ typedef typename odb::details::meta::remove_const<element_type>::result
+ unrestricted_element_type;
+ typedef std::tr1::shared_ptr<unrestricted_element_type>
+ unrestricted_pointer_type;
+ typedef smart_ptr_guard<pointer_type> guard;
+
+ static element_type*
+ get_ptr (const pointer_type& p)
+ {
+ return p.get ();
+ }
+
+ static element_type&
+ get_ref (const pointer_type& p)
+ {
+ return *p;
+ }
+
+ static bool
+ null_ptr (const pointer_type& p)
+ {
+ return !p;
+ }
+
+ static unrestricted_pointer_type
+ const_pointer_cast (const pointer_type& p)
+ {
+ return std::tr1::const_pointer_cast<unrestricted_element_type> (p);
+ }
+
+ template <typename T1>
+ static std::tr1::shared_ptr<T1>
+ static_pointer_cast (const pointer_type& p)
+ {
+ return std::tr1::static_pointer_cast<T1> (p);
+ }
+
+ template <typename T1>
+ static std::tr1::shared_ptr<T1>
+ dynamic_pointer_cast (const pointer_type& p)
+ {
+ return std::tr1::dynamic_pointer_cast<T1> (p);
+ }
+
+ public:
+ static void*
+ allocate (std::size_t n)
+ {
+ return operator new (n);
+ }
+
+ static void
+ free (void* p)
+ {
+ operator delete (p);
+ }
+ };
+
+ // Specialization for std::tr1::weak_ptr.
+ //
+ template <typename T>
+ class pointer_traits<std::tr1::weak_ptr<T> >
+ {
+ public:
+ static const pointer_kind kind = pk_weak;
+ static const bool lazy = false;
+
+ typedef T element_type;
+ typedef std::tr1::weak_ptr<element_type> pointer_type;
+ typedef std::tr1::shared_ptr<element_type> strong_pointer_type;
+
+ static strong_pointer_type
+ lock (const pointer_type& p)
+ {
+ return p.lock ();
+ }
+ };
+}
+
+#endif // !(ODB_CXX11 && _MSC_VER)
+
+#include <odb/post.hxx>
+
+#endif // ODB_TR1_POINTER_TRAITS_HXX
diff --git a/libodb/odb/tr1/wrapper-traits.hxx b/libodb/odb/tr1/wrapper-traits.hxx
new file mode 100644
index 0000000..f878ef6
--- /dev/null
+++ b/libodb/odb/tr1/wrapper-traits.hxx
@@ -0,0 +1,76 @@
+// file : odb/tr1/wrapper-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_TR1_WRAPPER_TRAITS_HXX
+#define ODB_TR1_WRAPPER_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/details/config.hxx> // ODB_CXX11
+
+// In VC++ std::shared_ptr and std::tr1::shared_ptr is the same class
+// template. One is just a using-declaration for the other.
+//
+#if !(defined(ODB_CXX11) && defined(_MSC_VER))
+
+//
+// This header assumes that the necessary TR1 header has already
+// been included.
+//
+
+#include <odb/wrapper-traits.hxx>
+
+namespace odb
+{
+ // Specialization for std::tr1::shared_ptr.
+ //
+ template <typename T>
+ class wrapper_traits< std::tr1::shared_ptr<T> >
+ {
+ public:
+ typedef T wrapped_type;
+ typedef std::tr1::shared_ptr<T> wrapper_type;
+
+ // T can be const.
+ //
+ typedef
+ typename odb::details::meta::remove_const<T>::result
+ unrestricted_wrapped_type;
+
+ static const bool null_handler = true;
+ static const bool null_default = false;
+
+ static bool
+ get_null (const wrapper_type& p)
+ {
+ return !p;
+ }
+
+ static void
+ set_null (wrapper_type& p)
+ {
+ p.reset ();
+ }
+
+ static const wrapped_type&
+ get_ref (const wrapper_type& p)
+ {
+ return *p;
+ }
+
+ static unrestricted_wrapped_type&
+ set_ref (wrapper_type& p)
+ {
+ if (!p)
+ p.reset (new unrestricted_wrapped_type);
+
+ return const_cast<unrestricted_wrapped_type&> (*p);
+ }
+ };
+}
+
+#endif // !(ODB_CXX11 && _MSC_VER)
+
+#include <odb/post.hxx>
+
+#endif // ODB_TR1_WRAPPER_TRAITS_HXX