From 2636e266dc7a048e52b40b668c460c2793e897c4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 18 Aug 2010 20:02:11 +0200 Subject: Move shared_ptr to the details namespace --- odb/details/shared-ptr/base.hxx | 108 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 odb/details/shared-ptr/base.hxx (limited to 'odb/details/shared-ptr/base.hxx') diff --git a/odb/details/shared-ptr/base.hxx b/odb/details/shared-ptr/base.hxx new file mode 100644 index 0000000..4fbbc0b --- /dev/null +++ b/odb/details/shared-ptr/base.hxx @@ -0,0 +1,108 @@ +// file : odb/details/shared-ptr/base.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_DETAILS_SHARED_PTR_BASE_HXX +#define ODB_DETAILS_SHARED_PTR_BASE_HXX + +#include +#include // std::size_t + +#include + +namespace odb +{ + namespace details + { + struct share + { + explicit + share (char id); + + bool + operator== (share) const; + + private: + char id_; + }; + + extern share shared; + extern share exclusive; + } +} + +void* +operator new (std::size_t, odb::details::share) throw (std::bad_alloc); + +void +operator delete (void*, odb::details::share) throw (); + +namespace odb +{ + namespace details + { + struct not_shared: exception + { + virtual const char* + what () const throw (); + }; + + struct shared_base + { + shared_base (); + shared_base (const shared_base&); + shared_base& + operator= (const shared_base&); + + void + _inc_ref (); + + bool + _dec_ref (); + + std::size_t + _ref_count () const; + + void* + operator new (std::size_t, share) throw (std::bad_alloc); + + void + operator delete (void*, share) throw (); + + void + operator delete (void*) throw (); + + struct refcount_callback + { + void* arg; + void (*zero_counter) (void*); + }; + + private: + bool + _dec_ref_callback (); + + protected: + std::size_t counter_; + refcount_callback* callback_; + }; + + template + inline X* + inc_ref (X*); + + template + inline void + dec_ref (X*); + + template + inline std::size_t + ref_count (const X*); + } +} + +#include +#include + +#endif // ODB_DETAILS_SHARED_PTR_BASE_HXX -- cgit v1.1