From 30b664c0561cc9f6d2bd24f7bce9b6c57fb52320 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 15 Nov 2010 17:46:28 +0200 Subject: Add support for custom object pointers New option: --default-pointer. New object pragma specifier: pointer. --- odb/traits.hxx | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'odb/traits.hxx') diff --git a/odb/traits.hxx b/odb/traits.hxx index 318d88b..bc25dcb 100644 --- a/odb/traits.hxx +++ b/odb/traits.hxx @@ -16,8 +16,7 @@ namespace odb // template // class access::object_traits; // - // Specializations should inherit from object_memory, object_factory - // and define the following members: + // Specializations should define the following members: // // id_type - object id (primary key) type // id_type id (const T&) - get object id @@ -30,39 +29,35 @@ namespace odb // // - template - class access::object_memory - { - public: - typedef T* pointer_type; - }; - - template + template class access::object_factory { public: - static typename object_memory::pointer_type + typedef T object_type; + typedef P pointer_type; + + static P create () { // By default use pointer-specific construction. // - return - pointer_factory::pointer_type>::create (); + return pointer_factory::create (); } }; - template + template class access::pointer_factory { public: - typedef typename pointer_traits

::type object_type; + typedef T object_type; + typedef P pointer_type; static P create () { - void* v (pointer_traits

::allocate (sizeof (object_type))); + void* v (pointer_traits

::allocate (sizeof (T))); mem_guard g (v); - P p (new (v) object_type); + P p (new (v) T); g.release (); return p; } @@ -77,8 +72,12 @@ namespace odb }; template - struct object_traits: access::object_traits + struct object_traits: access::object_traits, + access::object_factory::pointer_type> { + typedef typename access::object_traits::object_type object_type; + typedef typename access::object_traits::pointer_type pointer_type; + typedef odb::pointer_traits::pointer_type> pointer_traits; -- cgit v1.1