From 531c792dd4eecd246cc1ccebac812d6888464a78 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 22 Nov 2010 12:03:11 +0200 Subject: Add session, database operations on pointers and const objects Currently, session is just an object cache. The persist, update, and erase database operations are overloaded to also work on object pointers. All the database operations and the query facility now support const objects. New session-related exceptions: not_in_session, already_in_session, const_object. --- odb/traits.hxx | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'odb/traits.hxx') diff --git a/odb/traits.hxx b/odb/traits.hxx index bc25dcb..87fcec5 100644 --- a/odb/traits.hxx +++ b/odb/traits.hxx @@ -72,15 +72,74 @@ namespace odb }; template - struct object_traits: access::object_traits, + struct object_traits: + access::object_traits, access::object_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 persistent + // object. Or you forgot to include the corresponding -odb.hxx file. + // + + typedef + odb::pointer_traits::pointer_type> + pointer_traits; + typedef typename access::object_traits::object_type object_type; typedef typename access::object_traits::pointer_type pointer_type; + typedef typename pointer_traits::const_pointer_type const_pointer_type; + }; + // Specialization for const objects. It only defines the id, object, + // pointer, and const_pointer types with pointer and const_pointer + // being the same. The idea is to only use this specialization in the + // interfaces, with the implementations detecting this situation and + // using the non-const object_traits version. + // + template + struct object_traits + { + private: typedef odb::pointer_traits::pointer_type> pointer_traits; + + public: + typedef typename access::object_traits::id_type id_type; + typedef typename access::object_traits::object_type object_type; + typedef typename pointer_traits::const_pointer_type const_pointer_type; + typedef const_pointer_type pointer_type; + }; + + // Specializations for pointer types to allow the C++ compiler to + // instantiate persist(), etc., signatures in class database. The + // overloads that use these specializations would never actually + // be selected by the compiler. + // + template + struct object_traits + { + struct id_type {}; + }; + + template + struct object_traits + { + struct id_type {}; + }; + + template class P> + struct object_traits< P > + { + struct id_type {}; + }; + + template class P> + struct object_traits< const P > + { + struct id_type {}; }; template -- cgit v1.1