aboutsummaryrefslogtreecommitdiff
path: root/odb/traits.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-11-22 12:03:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-11-22 12:03:11 +0200
commit531c792dd4eecd246cc1ccebac812d6888464a78 (patch)
tree9bed050c98a2c407c68e808ae1f1d296a65c5fee /odb/traits.hxx
parent1cddfd09a7007f77fc243f178b1ca88ea4d0f4f6 (diff)
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.
Diffstat (limited to 'odb/traits.hxx')
-rw-r--r--odb/traits.hxx61
1 files changed, 60 insertions, 1 deletions
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 <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>
{
+ //
+ // 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<typename access::object_traits<T>::pointer_type>
+ pointer_traits;
+
typedef typename access::object_traits<T>::object_type object_type;
typedef typename access::object_traits<T>::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 <typename T>
+ struct object_traits<const T>
+ {
+ private:
typedef
odb::pointer_traits<typename access::object_traits<T>::pointer_type>
pointer_traits;
+
+ public:
+ typedef typename access::object_traits<T>::id_type id_type;
+ typedef typename access::object_traits<T>::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 <typename T>
+ struct object_traits<T*>
+ {
+ struct id_type {};
+ };
+
+ template <typename T>
+ struct object_traits<T* const>
+ {
+ struct id_type {};
+ };
+
+ template <typename T, template <typename> class P>
+ struct object_traits< P<T> >
+ {
+ struct id_type {};
+ };
+
+ template <typename T, template <typename> class P>
+ struct object_traits< const P<T> >
+ {
+ struct id_type {};
};
template <typename T>