From ec355c48c49074bebeb597f6e5dcedfeb9d52fae Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 9 Dec 2010 10:36:15 +0200 Subject: Add lazy pointer support Built-in support is provided for raw, auto, and tr1 shared/weak pointers. New test: common/lazy-ptr. --- odb/lazy-ptr-impl.txx | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 odb/lazy-ptr-impl.txx (limited to 'odb/lazy-ptr-impl.txx') 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 +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +namespace odb +{ + // + // lazy_ptr_base + // + + template + void lazy_ptr_base:: + free (void* p) + { + delete static_cast (p); + } + + template + void* lazy_ptr_base:: + copy (const void* p) + { + return new T (*static_cast (p)); + } + + // + // lazy_ptr_impl + // + + template + template + inline typename object_traits::pointer_type lazy_ptr_impl:: + load (bool reset) + { + typedef typename object_traits::id_type id_type; + typedef typename object_traits::pointer_type pointer_type; + + const id_type& id (*static_cast (id_)); + pointer_type p (db_->load (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; + } +} -- cgit v1.1