aboutsummaryrefslogtreecommitdiff
path: root/odb/traits.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-11-15 17:46:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-11-15 17:46:28 +0200
commit30b664c0561cc9f6d2bd24f7bce9b6c57fb52320 (patch)
tree743ce4a41249c8586e81a001cf147bedfbdf9a85 /odb/traits.hxx
parent93392ca601a0cab8517a4ca8d163df4b41dd3e49 (diff)
Add support for custom object pointers
New option: --default-pointer. New object pragma specifier: pointer.
Diffstat (limited to 'odb/traits.hxx')
-rw-r--r--odb/traits.hxx35
1 files changed, 17 insertions, 18 deletions
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 <typename T>
// 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 <typename T>
- class access::object_memory
- {
- public:
- typedef T* pointer_type;
- };
-
- template <typename T>
+ template <typename T, typename P>
class access::object_factory
{
public:
- static typename object_memory<T>::pointer_type
+ typedef T object_type;
+ typedef P pointer_type;
+
+ static P
create ()
{
// By default use pointer-specific construction.
//
- return
- pointer_factory<typename object_memory<T>::pointer_type>::create ();
+ return pointer_factory<T, P>::create ();
}
};
- template <typename P>
+ template <typename T, typename P>
class access::pointer_factory
{
public:
- typedef typename pointer_traits<P>::type object_type;
+ typedef T object_type;
+ typedef P pointer_type;
static P
create ()
{
- void* v (pointer_traits<P>::allocate (sizeof (object_type)));
+ void* v (pointer_traits<P>::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 <typename T>
- struct object_traits: access::object_traits<T>
+ struct object_traits: access::object_traits<T>,
+ access::object_factory<T, typename access::object_traits<T>::pointer_type>
{
+ typedef typename access::object_traits<T>::object_type object_type;
+ typedef typename access::object_traits<T>::pointer_type pointer_type;
+
typedef
odb::pointer_traits<typename access::object_traits<T>::pointer_type>
pointer_traits;