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/posix/exceptions.cxx | 6 ++++++ odb/details/posix/exceptions.hxx | 3 +++ odb/details/shared-ptr.hxx | 1 + 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 ++++++++++++++++++++++++++++++ odb/details/win32/exceptions.cxx | 6 ++++++ odb/details/win32/exceptions.hxx | 3 +++ 10 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 odb/details/shared-ptr/exception.hxx (limited to 'odb/details') diff --git a/odb/details/posix/exceptions.cxx b/odb/details/posix/exceptions.cxx index 7a50a13..b8bb702 100644 --- a/odb/details/posix/exceptions.cxx +++ b/odb/details/posix/exceptions.cxx @@ -13,5 +13,11 @@ namespace odb { return "POSIX API error"; } + + posix_exception* posix_exception:: + clone () const + { + return new posix_exception (*this); + } } } diff --git a/odb/details/posix/exceptions.hxx b/odb/details/posix/exceptions.hxx index ebea763..5ff023d 100644 --- a/odb/details/posix/exceptions.hxx +++ b/odb/details/posix/exceptions.hxx @@ -24,6 +24,9 @@ namespace odb virtual const char* what () const throw (); + virtual posix_exception* + clone () const; + private: int code_; }; diff --git a/odb/details/shared-ptr.hxx b/odb/details/shared-ptr.hxx index aecde12..9d2b62f 100644 --- a/odb/details/shared-ptr.hxx +++ b/odb/details/shared-ptr.hxx @@ -9,6 +9,7 @@ #include #include +#include namespace odb { 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 diff --git a/odb/details/win32/exceptions.cxx b/odb/details/win32/exceptions.cxx index 75043b4..10605c2 100644 --- a/odb/details/win32/exceptions.cxx +++ b/odb/details/win32/exceptions.cxx @@ -13,5 +13,11 @@ namespace odb { return "Win32 API error"; } + + win32_exception* win32_exception:: + clone () const + { + return new win32_exception (*this); + } } } diff --git a/odb/details/win32/exceptions.hxx b/odb/details/win32/exceptions.hxx index ecc36b6..c987430 100644 --- a/odb/details/win32/exceptions.hxx +++ b/odb/details/win32/exceptions.hxx @@ -26,6 +26,9 @@ namespace odb virtual const char* what () const throw (); + virtual win32_exception* + clone () const; + private: DWORD code_; }; -- cgit v1.1