From 8d4d2568f356cb9beb1553bf58ad69c1c800b996 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 14 Aug 2014 09:37:06 +0200 Subject: Implement bulk database operation support for Oracle and SQL Server --- odb/details/shared-ptr/base.cxx | 21 +++++++++++++++++++++ odb/details/shared-ptr/base.hxx | 10 +++------- odb/details/shared-ptr/base.ixx | 6 ++++++ odb/details/shared-ptr/base.txx | 26 ++++++++++---------------- odb/details/shared-ptr/exception.hxx | 30 ++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 23 deletions(-) create mode 100644 odb/details/shared-ptr/exception.hxx (limited to 'odb/details/shared-ptr') 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 +#include 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 (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 #include // std::size_t -#include #include #include @@ -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 ::result> struct locator; template - struct locator + struct locator: locator_common { static std::size_t* counter (X* x) { - std::size_t* p (reinterpret_cast (x)); - - if (*(--p) != 0xDEADBEEF) - throw not_shared (); - - return --p; + return locator_common::counter (x); } }; template - struct locator + struct locator: locator_common { static std::size_t* counter (X* x) { - std::size_t* p ( - static_cast ( - dynamic_cast (x))); - - if (*(--p) != 0xDEADBEEF) - throw not_shared (); - - return --p; + return locator_common::counter (dynamic_cast (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 + +#include +#include + +namespace odb +{ + namespace details + { + struct LIBODB_EXPORT not_shared: exception + { + virtual const char* + what () const throw (); + + virtual not_shared* + clone () const; + }; + } +} + +#include + +#endif // ODB_DETAILS_SHARED_PTR_EXCEPTION_HXX -- cgit v1.1