diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-12-09 10:36:15 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-12-09 10:36:15 +0200 |
commit | ec355c48c49074bebeb597f6e5dcedfeb9d52fae (patch) | |
tree | 9adb18bffe27c6d0bce53c7e6bad6be583dc59ee /odb/lazy-pointer-traits.hxx | |
parent | d2b7cfe47694cef008949255426cc57ab9a8e18a (diff) |
Add lazy pointer support
Built-in support is provided for raw, auto, and tr1 shared/weak pointers.
New test: common/lazy-ptr.
Diffstat (limited to 'odb/lazy-pointer-traits.hxx')
-rw-r--r-- | odb/lazy-pointer-traits.hxx | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/odb/lazy-pointer-traits.hxx b/odb/lazy-pointer-traits.hxx new file mode 100644 index 0000000..599b051 --- /dev/null +++ b/odb/lazy-pointer-traits.hxx @@ -0,0 +1,69 @@ +// file : odb/lazy-pointer-traits.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_LAZY_POINTER_TRAITS_HXX +#define ODB_LAZY_POINTER_TRAITS_HXX + +#include <odb/pre.hxx> + +#include <odb/pointer-traits.hxx> +#include <odb/lazy-ptr.hxx> + +namespace odb +{ + template <typename T> + class pointer_traits< lazy_ptr<T> > + { + public: + static pointer_kind const kind = pk_naked; + static bool const lazy = true; + + typedef T element_type; + typedef lazy_ptr<element_type> pointer_type; + typedef 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_auto_ptr<T> > + { + public: + static pointer_kind const kind = pk_unique; + static bool const lazy = true; + + typedef T element_type; + typedef lazy_auto_ptr<element_type> pointer_type; + typedef std::auto_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> (); + } + }; +} + +#include <odb/post.hxx> + +#endif // ODB_LAZY_POINTER_TRAITS_HXX |