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-pointer-traits.hxx | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 odb/lazy-pointer-traits.hxx (limited to 'odb/lazy-pointer-traits.hxx') 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 +// 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 + +#include +#include + +namespace odb +{ + template + class pointer_traits< lazy_ptr > + { + public: + static pointer_kind const kind = pk_naked; + static bool const lazy = true; + + typedef T element_type; + typedef lazy_ptr pointer_type; + typedef element_type* eager_pointer_type; + + static bool + null_ptr (const pointer_type& p) + { + return !p; + } + + template + static typename object_traits::id_type + object_id (const pointer_type& p) + { + return p.object_id (); + } + }; + + template + class pointer_traits< lazy_auto_ptr > + { + public: + static pointer_kind const kind = pk_unique; + static bool const lazy = true; + + typedef T element_type; + typedef lazy_auto_ptr pointer_type; + typedef std::auto_ptr eager_pointer_type; + + static bool + null_ptr (const pointer_type& p) + { + return !p; + } + + template + static typename object_traits::id_type + object_id (const pointer_type& p) + { + return p.object_id (); + } + }; +} + +#include + +#endif // ODB_LAZY_POINTER_TRAITS_HXX -- cgit v1.1