diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-09-21 13:00:33 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-09-21 13:00:33 +0200 |
commit | a28444da4ca6adb016f719e032174ccb54e1692e (patch) | |
tree | 75fe8ceae2d20baa3d4b5375a832598efe8b2fce /odb/pointer-traits.hxx | |
parent | 0046a34d5ad5fc1e88b33279605f179646b0ea59 (diff) |
Rework const object handling
Now objects are always loaded as non-const and the object cache in
session treats all objects as non-const.
Diffstat (limited to 'odb/pointer-traits.hxx')
-rw-r--r-- | odb/pointer-traits.hxx | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/odb/pointer-traits.hxx b/odb/pointer-traits.hxx index 8882309..f8eed3a 100644 --- a/odb/pointer-traits.hxx +++ b/odb/pointer-traits.hxx @@ -12,6 +12,8 @@ #include <memory> // std::auto_ptr #include <cstddef> // std::size_t +#include <odb/details/meta/remove-const.hxx> + namespace odb { enum pointer_kind @@ -81,6 +83,8 @@ namespace odb typedef T element_type; typedef T* pointer_type; typedef const T* const_pointer_type; + typedef typename details::meta::remove_const<T>::result* + unrestricted_pointer_type; typedef raw_ptr_guard<pointer_type> guard; // Return raw pointer to the pointed-to element, including NULL. @@ -107,6 +111,14 @@ namespace odb return p == 0; } + // Cast away constness. + // + static unrestricted_pointer_type + cast (pointer_type p) + { + return const_cast<unrestricted_pointer_type> (p); + } + public: // Allocate memory for an element that will be managed by this // pointer. @@ -162,6 +174,9 @@ namespace odb return p.get () == 0; } + // cast() is not provided since it transfers the ownership. + // + public: static void* allocate (std::size_t n) |