diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-02-28 12:42:00 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-02-28 12:42:00 +0200 |
commit | eaf07e23f93813fa2c2e6b4d67e69fc6f4c48673 (patch) | |
tree | 3b6a54db5d3019121b0bbd553322248ce45db4c2 /odb/lazy-pointer-traits.hxx | |
parent | 3012187847b2783c49153db3f5486b84074cb2b0 (diff) |
Support for C++11 std::shared_ptr/weak_ptr as object pointers
This includes odb::lazy_shared_ptr and odb::lazy_weak_ptr implementations.
Diffstat (limited to 'odb/lazy-pointer-traits.hxx')
-rw-r--r-- | odb/lazy-pointer-traits.hxx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/odb/lazy-pointer-traits.hxx b/odb/lazy-pointer-traits.hxx index cd2b535..910e1e4 100644 --- a/odb/lazy-pointer-traits.hxx +++ b/odb/lazy-pointer-traits.hxx @@ -9,6 +9,7 @@ #include <odb/pointer-traits.hxx> #include <odb/lazy-ptr.hxx> +#include <odb/details/config.hxx> // ODB_CXX11 namespace odb { @@ -61,6 +62,52 @@ namespace odb return p.object_id<O> (); } }; + +#ifdef ODB_CXX11 + template <typename T> + class pointer_traits<lazy_shared_ptr<T> > + { + public: + static const pointer_kind kind = pk_shared; + static const bool lazy = true; + + typedef T element_type; + typedef lazy_shared_ptr<element_type> pointer_type; + typedef std::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.object_id<O> (); + } + }; + + template <typename T> + class pointer_traits<lazy_weak_ptr<T> > + { + public: + static const pointer_kind kind = pk_weak; + static const bool lazy = true; + + typedef T element_type; + typedef lazy_weak_ptr<element_type> pointer_type; + typedef lazy_shared_ptr<element_type> strong_pointer_type; + typedef std::weak_ptr<element_type> eager_pointer_type; + + static strong_pointer_type + lock (const pointer_type& p) + { + return p.lock (); + } + }; +#endif // ODB_CXX11 } #include <odb/post.hxx> |