diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-12-16 20:29:05 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-02-24 16:40:04 +0300 |
commit | 8e761289a2446367267c6c0d9a26e734f0f78306 (patch) | |
tree | fb495d8c18801f271d124ee48731f10df396ca89 /libcutl/shared-ptr/base.hxx | |
parent | 4c8104756b92b9fa16b3a725e8a6aa620dfd606e (diff) |
Get rid of legacy build systems and rename cutl/ to libcutl/
Diffstat (limited to 'libcutl/shared-ptr/base.hxx')
-rw-r--r-- | libcutl/shared-ptr/base.hxx | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/libcutl/shared-ptr/base.hxx b/libcutl/shared-ptr/base.hxx new file mode 100644 index 0000000..f49a532 --- /dev/null +++ b/libcutl/shared-ptr/base.hxx @@ -0,0 +1,91 @@ +// file : libcutl/shared-ptr/base.hxx +// license : MIT; see accompanying LICENSE file + +#ifndef LIBCUTL_SHARED_PTR_BASE_HXX +#define LIBCUTL_SHARED_PTR_BASE_HXX + +#include <new> +#include <cstddef> // std::size_t + +#include <libcutl/exception.hxx> + +#include <libcutl/export.hxx> + +namespace cutl +{ + struct share + { + explicit + share (char id); + + bool + operator== (share) const; + + private: + char id_; + }; +} + +extern LIBCUTL_EXPORT cutl::share shared; +extern LIBCUTL_EXPORT cutl::share exclusive; + +LIBCUTL_EXPORT void* +operator new (std::size_t, cutl::share); + +LIBCUTL_EXPORT void +operator delete (void*, cutl::share) noexcept; + +namespace cutl +{ + struct LIBCUTL_EXPORT not_shared: exception + { + virtual char const* + what () const noexcept; + }; + + struct LIBCUTL_EXPORT 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); + + void + operator delete (void*, share) noexcept; + + void + operator delete (void*) noexcept; + + 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 <libcutl/shared-ptr/base.ixx> +#include <libcutl/shared-ptr/base.txx> + +#endif // LIBCUTL_SHARED_PTR_BASE_HXX |