diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-09-06 12:52:53 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-09-06 12:52:53 +0200 |
commit | cb9ea47e7825b5073d4d645afb94f6326cb7cf4d (patch) | |
tree | 201c215b08df918924153a60520046c294438a6b /cutl/shared-ptr/base.hxx |
Start the libcutl repository
Diffstat (limited to 'cutl/shared-ptr/base.hxx')
-rw-r--r-- | cutl/shared-ptr/base.hxx | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/cutl/shared-ptr/base.hxx b/cutl/shared-ptr/base.hxx new file mode 100644 index 0000000..bb297cb --- /dev/null +++ b/cutl/shared-ptr/base.hxx @@ -0,0 +1,90 @@ +// file : cutl/shared-ptr/base.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef CUTL_SHARED_PTR_BASE_HXX +#define CUTL_SHARED_PTR_BASE_HXX + +#include <new> +#include <cstddef> // std::size_t +#include <exception> // std::exception + +namespace cutl +{ + struct share + { + explicit + share (char id); + + bool + operator== (share) const; + + private: + char id_; + }; +} + +extern cutl::share shared; +extern cutl::share exclusive; + +void* +operator new (std::size_t, cutl::share) throw (std::bad_alloc); + +void +operator delete (void*, cutl::share) throw (); + +namespace cutl +{ + struct not_shared: std::exception + { + virtual char const* + what () const throw (); + }; + + struct shared_base + { + shared_base (); + shared_base (shared_base const&); + shared_base& + operator= (shared_base const&); + + 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 (); + + protected: + std::size_t counter_; + }; + + template <typename X> + inline X* + inc_ref (X*); + + template <typename X> + inline void + dec_ref (X*); + + template <typename X> + inline std::size_t + ref_count (X const*); +} + +#include <cutl/shared-ptr/base.ixx> +#include <cutl/shared-ptr/base.txx> + +#endif // CUTL_SHARED_PTR_BASE_HXX |