From 9c275a93cec797a021571ba8545906e0b4ffbfbc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 5 Sep 2011 10:20:47 +0200 Subject: Support for views; native part --- odb/traits.hxx | 90 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 17 deletions(-) (limited to 'odb/traits.hxx') diff --git a/odb/traits.hxx b/odb/traits.hxx index 838373d..3f400cb 100644 --- a/odb/traits.hxx +++ b/odb/traits.hxx @@ -13,22 +13,6 @@ namespace odb { - // template - // class access::object_traits; - // - // Specializations should define the following members: - // - // id_type - object id (primary key) type - // id_type id (const T&) - get object id - // - // void persist (database&, T&) - // void update (database&, T&) - // void erase (database&, const id_type&) - // pointer_type find (database&, const id_type&) - // bool find (database&, const id_type&, T&) - // - // - template class access::object_factory { @@ -46,10 +30,26 @@ namespace odb }; template + class access::view_factory + { + public: + typedef T view_type; + typedef P pointer_type; + + static P + create () + { + // By default use pointer-specific construction. + // + return pointer_factory::create (); + } + }; + + template class access::pointer_factory { public: - typedef T object_type; + typedef T value_type; typedef P pointer_type; static P @@ -61,6 +61,7 @@ namespace odb g.release (); return p; } + private: struct mem_guard { @@ -71,6 +72,33 @@ namespace odb }; }; + // + // class_traits + // + enum class_kind + { + class_object, + class_view, + class_composite, + class_other + }; + + template + struct class_traits + { + static const class_kind kind = class_other; + }; + + template + struct class_traits + { + static const class_kind kind = class_traits::kind; + }; + + // + // object_traits + // + template struct object_traits: access::object_traits, @@ -142,6 +170,34 @@ namespace odb struct id_type {}; }; + // + // view_traits + // + + template + struct view_traits: + access::view_traits, + access::view_factory::pointer_type> + { + // + // If a C++ compiler issues an error pointing to this struct and + // saying that it is incomplete, then you are most likely trying to + // perform a database operation on a C++ type that is not a view + // Or you forgot to include the corresponding -odb.hxx file. + // + + typedef + odb::pointer_traits::pointer_type> + pointer_traits; + + typedef typename access::view_traits::view_type view_type; + typedef typename access::view_traits::pointer_type pointer_type; + }; + + // + // composite_value_traits + // + template struct composite_value_traits: access::composite_value_traits { -- cgit v1.1