aboutsummaryrefslogtreecommitdiff
path: root/odb/session.ixx
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/session.ixx
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/session.ixx')
-rw-r--r--odb/session.ixx65
1 files changed, 65 insertions, 0 deletions
diff --git a/odb/session.ixx b/odb/session.ixx
new file mode 100644
index 0000000..0be6bfa
--- /dev/null
+++ b/odb/session.ixx
@@ -0,0 +1,65 @@
+// file : odb/session.ixx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <odb/exceptions.hxx>
+
+namespace odb
+{
+ template <typename T>
+ inline void session::
+ erase (const object_position<T>& p)
+ {
+ // @@ Empty maps are not cleaned up by this version of erase.
+ //
+ p.map_->erase (p.pos_);
+ }
+
+ //
+ // object_pointers
+ //
+ template <typename T>
+ inline session::object_pointers<T>::
+ object_pointers () : p_ (), cp_ () {}
+
+ template <typename T>
+ inline void session::object_pointers<T>::
+ set (const pointer_type& p)
+ {
+ p_ = p;
+ cp_ = const_pointer_type ();
+ }
+
+ template <typename T>
+ inline void session::object_pointers<T>::
+ set (const const_pointer_type& cp)
+ {
+ p_ = pointer_type ();
+ cp_ = cp;
+ }
+
+ template <typename T>
+ inline void session::object_pointers<T>::
+ get (pointer_type& p) const
+ {
+ if (!pointer_traits<pointer_type>::null_ptr (p_))
+ p = p_;
+ else if (!pointer_traits<const_pointer_type>::null_ptr (cp_))
+ throw const_object ();
+ else
+ p = pointer_type ();
+ }
+
+ template <typename T>
+ inline void session::object_pointers<T>::
+ get (const_pointer_type& cp) const
+ {
+ if (!pointer_traits<pointer_type>::null_ptr (p_))
+ cp = const_pointer_type (p_);
+ else if (!pointer_traits<const_pointer_type>::null_ptr (cp_))
+ cp = cp_;
+ else
+ cp = const_pointer_type ();
+ }
+}