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-ptr-impl.txx | |
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-ptr-impl.txx')
-rw-r--r-- | odb/lazy-ptr-impl.txx | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/odb/lazy-ptr-impl.txx b/odb/lazy-ptr-impl.txx new file mode 100644 index 0000000..c3055c9 --- /dev/null +++ b/odb/lazy-ptr-impl.txx @@ -0,0 +1,51 @@ +// file : odb/lazy-ptr-impl.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include <odb/database.hxx> + +namespace odb +{ + // + // lazy_ptr_base + // + + template <typename T> + void lazy_ptr_base:: + free (void* p) + { + delete static_cast<T*> (p); + } + + template <typename T> + void* lazy_ptr_base:: + copy (const void* p) + { + return new T (*static_cast<const T*> (p)); + } + + // + // lazy_ptr_impl + // + + template <typename T> + template <typename O> + inline typename object_traits<O>::pointer_type lazy_ptr_impl<T>:: + load (bool reset) + { + typedef typename object_traits<T>::id_type id_type; + typedef typename object_traits<T>::pointer_type pointer_type; + + const id_type& id (*static_cast<const id_type*> (id_)); + pointer_type p (db_->load<T> (id)); + + if (reset) + reset_id (); + + // If you get a compile error pointing here, then you most likely + // used a wrong type as a template argument in the load() call. + // + return p; + } +} |