aboutsummaryrefslogtreecommitdiff
path: root/odb/details/shared-ptr
diff options
context:
space:
mode:
Diffstat (limited to 'odb/details/shared-ptr')
-rw-r--r--odb/details/shared-ptr/base.cxx21
-rw-r--r--odb/details/shared-ptr/base.hxx10
-rw-r--r--odb/details/shared-ptr/base.ixx6
-rw-r--r--odb/details/shared-ptr/base.txx26
-rw-r--r--odb/details/shared-ptr/exception.hxx30
5 files changed, 70 insertions, 23 deletions
diff --git a/odb/details/shared-ptr/base.cxx b/odb/details/shared-ptr/base.cxx
index 590d844..0214c54 100644
--- a/odb/details/shared-ptr/base.cxx
+++ b/odb/details/shared-ptr/base.cxx
@@ -3,6 +3,7 @@
// license : GNU GPL v2; see accompanying LICENSE file
#include <odb/details/shared-ptr/base.hxx>
+#include <odb/details/shared-ptr/exception.hxx>
using std::size_t;
@@ -19,6 +20,12 @@ namespace odb
return "object is not shared";
}
+ not_shared* not_shared::
+ clone () const
+ {
+ return new not_shared (*this);
+ }
+
bool shared_base::
_dec_ref_callback ()
{
@@ -29,6 +36,20 @@ namespace odb
return r;
}
+
+ namespace bits
+ {
+ size_t* locator_common::
+ counter (void* x)
+ {
+ size_t* p (static_cast<size_t*> (x));
+
+ if (*(--p) != 0xDEADBEEF)
+ throw not_shared ();
+
+ return --p;
+ }
+ }
}
}
diff --git a/odb/details/shared-ptr/base.hxx b/odb/details/shared-ptr/base.hxx
index 6cfe1c9..b16bc8b 100644
--- a/odb/details/shared-ptr/base.hxx
+++ b/odb/details/shared-ptr/base.hxx
@@ -10,7 +10,6 @@
#include <new>
#include <cstddef> // std::size_t
-#include <odb/exception.hxx>
#include <odb/details/export.hxx>
#include <odb/details/shared-ptr/counter-type.hxx>
@@ -45,12 +44,6 @@ namespace odb
{
namespace details
{
- struct LIBODB_EXPORT not_shared: exception
- {
- virtual const char*
- what () const throw ();
- };
-
class LIBODB_EXPORT shared_base
{
public:
@@ -69,6 +62,9 @@ namespace odb
_ref_count () const;
void*
+ operator new (std::size_t) throw (std::bad_alloc);
+
+ void*
operator new (std::size_t, share) throw (std::bad_alloc);
void
diff --git a/odb/details/shared-ptr/base.ixx b/odb/details/shared-ptr/base.ixx
index 53105ce..c5beec6 100644
--- a/odb/details/shared-ptr/base.ixx
+++ b/odb/details/shared-ptr/base.ixx
@@ -64,6 +64,12 @@ namespace odb
}
inline void* shared_base::
+ operator new (std::size_t n) throw (std::bad_alloc)
+ {
+ return ::operator new (n);
+ }
+
+ inline void* shared_base::
operator new (std::size_t n, share) throw (std::bad_alloc)
{
return ::operator new (n);
diff --git a/odb/details/shared-ptr/base.txx b/odb/details/shared-ptr/base.txx
index e00bd5c..7047b7a 100644
--- a/odb/details/shared-ptr/base.txx
+++ b/odb/details/shared-ptr/base.txx
@@ -13,38 +13,32 @@ namespace odb
{
// Support for locating the counter in the memory block.
//
+ struct LIBODB_EXPORT locator_common
+ {
+ static std::size_t*
+ counter (void*);
+ };
+
template <typename X, bool poly = meta::polymorphic_p<X>::result>
struct locator;
template <typename X>
- struct locator<X, false>
+ struct locator<X, false>: locator_common
{
static std::size_t*
counter (X* x)
{
- std::size_t* p (reinterpret_cast<std::size_t*> (x));
-
- if (*(--p) != 0xDEADBEEF)
- throw not_shared ();
-
- return --p;
+ return locator_common::counter (x);
}
};
template <typename X>
- struct locator<X, true>
+ struct locator<X, true>: locator_common
{
static std::size_t*
counter (X* x)
{
- std::size_t* p (
- static_cast<std::size_t*> (
- dynamic_cast<void*> (x)));
-
- if (*(--p) != 0xDEADBEEF)
- throw not_shared ();
-
- return --p;
+ return locator_common::counter (dynamic_cast<void*> (x));
}
};
diff --git a/odb/details/shared-ptr/exception.hxx b/odb/details/shared-ptr/exception.hxx
new file mode 100644
index 0000000..bd7ea38
--- /dev/null
+++ b/odb/details/shared-ptr/exception.hxx
@@ -0,0 +1,30 @@
+// file : odb/details/shared-ptr/exception.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_DETAILS_SHARED_PTR_EXCEPTION_HXX
+#define ODB_DETAILS_SHARED_PTR_EXCEPTION_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/exception.hxx>
+#include <odb/details/export.hxx>
+
+namespace odb
+{
+ namespace details
+ {
+ struct LIBODB_EXPORT not_shared: exception
+ {
+ virtual const char*
+ what () const throw ();
+
+ virtual not_shared*
+ clone () const;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_DETAILS_SHARED_PTR_EXCEPTION_HXX