aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/cache-traits.hxx180
-rw-r--r--odb/database.txx3
-rw-r--r--odb/no-op-cache-traits.hxx208
-rw-r--r--odb/polymorphic-object-result.txx1
-rw-r--r--odb/simple-object-result.txx2
5 files changed, 210 insertions, 184 deletions
diff --git a/odb/cache-traits.hxx b/odb/cache-traits.hxx
index 1e5ccdb..c0c1272 100644
--- a/odb/cache-traits.hxx
+++ b/odb/cache-traits.hxx
@@ -11,145 +11,15 @@
#include <odb/forward.hxx>
#include <odb/session.hxx>
#include <odb/pointer-traits.hxx>
+#include <odb/no-op-cache-traits.hxx>
namespace odb
{
- // pointer_cache_type
- //
- // Used to convert an object pointer to the canonical form (non-const),
- // suitable for insertion into the cache.
- //
- template <typename P,
- typename E = typename pointer_traits<P>::element_type,
- typename O = typename object_traits<E>::object_type,
- pointer_kind pk = pointer_traits<P>::kind>
- struct pointer_cache_type
- {
- typedef typename object_traits<O>::pointer_type pointer_type;
-
- static pointer_type
- convert (const P& p)
- {
- return pointer_traits<P>::const_pointer_cast (p);
- }
- };
-
- template <typename P, typename T, pointer_kind pk>
- struct pointer_cache_type<P, T, T, pk>
- {
- // If element_type and object_type are the same, then it is already
- // the canonical pointer.
- //
- static const P&
- convert (const P& p) {return p;}
- };
-
- template <typename P, typename E, typename O>
- struct pointer_cache_type<P, E, O, pk_unique>
- {
- // If the pointer is unique, then casting it can transfer ownership.
- // So return null pointer, which will be ignored down the chain.
- //
- typedef typename object_traits<O>::pointer_type pointer_type;
-
- static pointer_type
- convert (const P&) {return pointer_type ();}
- };
-
- template <typename P, typename T>
- struct pointer_cache_type<P, T, T, pk_unique>
- {
- typedef typename object_traits<T>::pointer_type pointer_type;
-
- static pointer_type
- convert (const P&) {return pointer_type ();}
- };
-
- // reference_cache_type
- //
- // Used to convert an object reference to the canonical form (non-const),
- // suitable for insertion into the cache.
- //
- template <typename T,
- typename O = typename object_traits<T>::object_type>
- struct reference_cache_type
- {
- static O&
- convert (T& r)
- {
- return const_cast<O&> (r);
- }
- };
-
- template <typename T>
- struct reference_cache_type<T, T>
- {
- // If the types are the same, then it is already the canonical form.
- //
- static T&
- convert (T& r) {return r;}
- };
-
// pointer_cache_traits
//
// Caching traits for objects passed by pointer. P should be the canonical
// pointer (non-const).
//
- template <typename P>
- struct no_id_pointer_cache_traits
- {
- typedef P pointer_type;
- struct position_type {};
-
- static position_type
- insert (odb::database&, const pointer_type&)
- {
- return position_type ();
- }
- };
-
- template <typename P>
- struct no_op_pointer_cache_traits
- {
- typedef P pointer_type;
- typedef typename pointer_traits<pointer_type>::element_type object_type;
- typedef typename object_traits<object_type>::id_type id_type;
- struct position_type {};
-
- struct insert_guard
- {
- insert_guard () {}
- insert_guard (const position_type&) {}
-
- position_type
- position () const {return position_type ();}
-
- void
- release () {}
-
- void
- reset (const position_type&) {}
- };
-
- static position_type
- insert (odb::database&, const id_type&, const pointer_type&)
- {
- return position_type ();
- }
-
- static position_type
- insert (odb::database&, const pointer_type&) {return position_type ();}
-
- static pointer_type
- find (odb::database&, const id_type&) {return pointer_type ();}
-
- static void
- erase (odb::database&, const id_type&) {}
-
- static void
- erase (const position_type&) {}
- };
-
template <typename P, pointer_kind pk>
struct pointer_cache_traits_impl
{
@@ -245,54 +115,6 @@ namespace odb
// canonical object type (non-const). Only if the object pointer
// kind is raw do we add the object to the session.
//
- template <typename T>
- struct no_id_reference_cache_traits
- {
- typedef T object_type;
- struct position_type {};
-
- static position_type
- insert (odb::database&, object_type&)
- {
- return position_type ();
- }
- };
-
- template <typename T>
- struct no_op_reference_cache_traits
- {
- typedef T object_type;
- typedef typename object_traits<object_type>::id_type id_type;
- struct position_type {};
-
- struct insert_guard
- {
- insert_guard () {}
- insert_guard (const position_type&) {}
-
- position_type
- position () const {return position_type ();}
-
- void
- release () {}
-
- void
- reset () {}
- };
-
- static position_type
- insert (odb::database&, const id_type&, object_type&)
- {
- return position_type ();
- }
-
- static position_type
- insert (odb::database&, object_type&)
- {
- return position_type ();
- }
- };
-
template <typename T, pointer_kind pk>
struct reference_cache_traits_impl: no_op_reference_cache_traits<T> {};
diff --git a/odb/database.txx b/odb/database.txx
index abc6ba3..7f7b90f 100644
--- a/odb/database.txx
+++ b/odb/database.txx
@@ -4,8 +4,7 @@
#include <odb/exceptions.hxx>
#include <odb/transaction.hxx>
-#include <odb/session.hxx>
-#include <odb/cache-traits.hxx>
+#include <odb/no-op-cache-traits.hxx>
#include <odb/pointer-traits.hxx>
namespace odb
diff --git a/odb/no-op-cache-traits.hxx b/odb/no-op-cache-traits.hxx
new file mode 100644
index 0000000..84d1c7a
--- /dev/null
+++ b/odb/no-op-cache-traits.hxx
@@ -0,0 +1,208 @@
+// file : odb/no-op-cache-traits.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_NO_OP_CACHE_TRAITS_HXX
+#define ODB_NO_OP_CACHE_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/traits.hxx>
+#include <odb/forward.hxx>
+#include <odb/pointer-traits.hxx>
+
+namespace odb
+{
+ // pointer_cache_type
+ //
+ // Used to convert an object pointer to the canonical form (non-const),
+ // suitable for insertion into the cache.
+ //
+ template <typename P,
+ typename E = typename pointer_traits<P>::element_type,
+ typename O = typename object_traits<E>::object_type,
+ pointer_kind pk = pointer_traits<P>::kind>
+ struct pointer_cache_type
+ {
+ typedef typename object_traits<O>::pointer_type pointer_type;
+
+ static pointer_type
+ convert (const P& p)
+ {
+ return pointer_traits<P>::const_pointer_cast (p);
+ }
+ };
+
+ template <typename P, typename T, pointer_kind pk>
+ struct pointer_cache_type<P, T, T, pk>
+ {
+ // If element_type and object_type are the same, then it is already
+ // the canonical pointer.
+ //
+ static const P&
+ convert (const P& p) {return p;}
+ };
+
+ template <typename P, typename E, typename O>
+ struct pointer_cache_type<P, E, O, pk_unique>
+ {
+ // If the pointer is unique, then casting it can transfer ownership.
+ // So return null pointer, which will be ignored down the chain.
+ //
+ typedef typename object_traits<O>::pointer_type pointer_type;
+
+ static pointer_type
+ convert (const P&) {return pointer_type ();}
+ };
+
+ template <typename P, typename T>
+ struct pointer_cache_type<P, T, T, pk_unique>
+ {
+ typedef typename object_traits<T>::pointer_type pointer_type;
+
+ static pointer_type
+ convert (const P&) {return pointer_type ();}
+ };
+
+ // reference_cache_type
+ //
+ // Used to convert an object reference to the canonical form (non-const),
+ // suitable for insertion into the cache.
+ //
+ template <typename T,
+ typename O = typename object_traits<T>::object_type>
+ struct reference_cache_type
+ {
+ static O&
+ convert (T& r)
+ {
+ return const_cast<O&> (r);
+ }
+ };
+
+ template <typename T>
+ struct reference_cache_type<T, T>
+ {
+ // If the types are the same, then it is already the canonical form.
+ //
+ static T&
+ convert (T& r) {return r;}
+ };
+
+ // pointer_cache_traits
+ //
+ // Caching traits for objects passed by pointer. P should be the canonical
+ // pointer (non-const).
+ //
+ template <typename P>
+ struct no_op_pointer_cache_traits
+ {
+ typedef P pointer_type;
+ typedef typename pointer_traits<pointer_type>::element_type object_type;
+ typedef typename object_traits<object_type>::id_type id_type;
+ struct position_type {};
+
+ struct insert_guard
+ {
+ insert_guard () {}
+ insert_guard (const position_type&) {}
+
+ position_type
+ position () const {return position_type ();}
+
+ void
+ release () {}
+
+ void
+ reset (const position_type&) {}
+ };
+
+ static position_type
+ insert (odb::database&, const id_type&, const pointer_type&)
+ {
+ return position_type ();
+ }
+
+ static position_type
+ insert (odb::database&, const pointer_type&) {return position_type ();}
+
+ static pointer_type
+ find (odb::database&, const id_type&) {return pointer_type ();}
+
+ static void
+ erase (odb::database&, const id_type&) {}
+
+ static void
+ erase (const position_type&) {}
+ };
+
+ template <typename P>
+ struct no_id_pointer_cache_traits
+ {
+ typedef P pointer_type;
+ struct position_type {};
+
+ static position_type
+ insert (odb::database&, const pointer_type&)
+ {
+ return position_type ();
+ }
+ };
+
+ // reference_cache_traits
+ //
+ // Caching traits for objects passed by reference. T should be the
+ // canonical object type (non-const).
+ //
+ template <typename T>
+ struct no_op_reference_cache_traits
+ {
+ typedef T object_type;
+ typedef typename object_traits<object_type>::id_type id_type;
+ struct position_type {};
+
+ struct insert_guard
+ {
+ insert_guard () {}
+ insert_guard (const position_type&) {}
+
+ position_type
+ position () const {return position_type ();}
+
+ void
+ release () {}
+
+ void
+ reset () {}
+ };
+
+ static position_type
+ insert (odb::database&, const id_type&, object_type&)
+ {
+ return position_type ();
+ }
+
+ static position_type
+ insert (odb::database&, object_type&)
+ {
+ return position_type ();
+ }
+ };
+
+ template <typename T>
+ struct no_id_reference_cache_traits
+ {
+ typedef T object_type;
+ struct position_type {};
+
+ static position_type
+ insert (odb::database&, object_type&)
+ {
+ return position_type ();
+ }
+ };
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_NO_OP_CACHE_TRAITS_HXX
diff --git a/odb/polymorphic-object-result.txx b/odb/polymorphic-object-result.txx
index 28331c6..e673483 100644
--- a/odb/polymorphic-object-result.txx
+++ b/odb/polymorphic-object-result.txx
@@ -2,7 +2,6 @@
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
-#include <odb/cache-traits.hxx>
#include <odb/exceptions.hxx>
namespace odb
diff --git a/odb/simple-object-result.txx b/odb/simple-object-result.txx
index 832ff7f..b440f13 100644
--- a/odb/simple-object-result.txx
+++ b/odb/simple-object-result.txx
@@ -2,8 +2,6 @@
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
-#include <odb/cache-traits.hxx>
-
namespace odb
{
//