Cpp Utilities 1.2.3
|
A proxy class from std::enable_shared_from_this
to provide same functionality for SafeSharedPtr.
More...
#include <SafeSharedPtr.hpp>
Public Types | |
using | SharedMutex = mutex_t |
Type alias for template shared_mutex_t. More... | |
using | SharedLock = read_lock_t |
Type alias for template read_lock_t. More... | |
using | UniqueLock = write_lock_t |
Type alias for template write_lock_t. More... | |
Public Member Functions | |
constexpr | EnableSafeSharedFromThis () noexcept |
Constructs a new EnableSafeSharedFromThis object. The private std::weak_ptr<T> member is empty-initialized. More... | |
EnableSafeSharedFromThis (const EnableSafeSharedFromThis &other) noexcept | |
Constructs a new EnableSafeSharedFromThis object. The private std::weak_ptr<T> member is value-initialized. More... | |
EnableSafeSharedFromThis (const std::enable_shared_from_this< T > &other) noexcept | |
Constructs a new EnableSafeSharedFromThis object. The private std::weak_ptr<T> member is value-initialized. More... | |
~EnableSafeSharedFromThis ()=default | |
Destroys *this . More... | |
EnableSafeSharedFromThis & | operator= (const EnableSafeSharedFromThis &other) noexcept |
Does nothing; returns *this. More... | |
EnableSafeSharedFromThis< T > & | operator= (const std::enable_shared_from_this< T > &other) noexcept |
Does nothing; returns *this. More... | |
SafeSharedPtr< T, SharedMutex, SharedLock, UniqueLock > | shared_from_this () |
Returns a SafeSharedPtr<T> that shares ownership of *this with all existing SafeSharedPtr that refer to *this . More... | |
SafeSharedPtr< T const > | shared_from_this () const |
Returns a SafeSharedPtr<T const> that shares ownership of *this with all existing SafeSharedPtr that refer to *this . More... | |
SafeWeakPtr< T > | weak_from_this () |
Returns a SafeWeakPtr<T> that tracks ownership of *this by all existing SafeSharedPtr that refer to *this . More... | |
SafeWeakPtr< T const > | weak_from_this () const |
Returns a SafeWeakPtr<T const> that tracks ownership of *this by all existing SafeSharedPtr that refer to *this . More... | |
Friends | |
template<typename Y , typename M , typename R , typename W > | |
class | SafeSharedPtr |
A proxy class from std::enable_shared_from_this
to provide same functionality for SafeSharedPtr.
T | Object type same as SafeSharedPtr. |
mutex_t | Type of the mutex used, default is shared_mutex_t. |
read_lock_t | Type of the read-lock used, default is shared_lock_t. |
write_lock_t | Type of the write-lock used, default is unique_lock_t. |
This class has no member values, so could be static_cast
from std::enable_shared_from_this
directly.
See https://en.cppreference.com/w/cpp/memory/enable_shared_from_this for more details.
using Memory::EnableSafeSharedFromThis< T, mutex_t, read_lock_t, write_lock_t >::SharedMutex = mutex_t |
Type alias for template shared_mutex_t.
using Memory::EnableSafeSharedFromThis< T, mutex_t, read_lock_t, write_lock_t >::SharedLock = read_lock_t |
Type alias for template read_lock_t.
using Memory::EnableSafeSharedFromThis< T, mutex_t, read_lock_t, write_lock_t >::UniqueLock = write_lock_t |
Type alias for template write_lock_t.
|
inlineconstexprnoexcept |
Constructs a new EnableSafeSharedFromThis object. The private std::weak_ptr<T>
member is empty-initialized.
|
inlinenoexcept |
Constructs a new EnableSafeSharedFromThis object. The private std::weak_ptr<T>
member is value-initialized.
other | Another EnableSafeSharedFromThis to copy. |
|
inlinenoexcept |
Constructs a new EnableSafeSharedFromThis object. The private std::weak_ptr<T>
member is value-initialized.
other | A std::enable_shared_from_this to copy. |
|
default |
Destroys *this
.
|
inlinenoexcept |
Does nothing; returns *this.
other | Another EnableSafeSharedFromThis to assign to *this . |
*this
. std::weak_ptr<T>
member is not affected by this assignment operator.
|
inlinenoexcept |
Does nothing; returns *this.
other | A std::enable_shared_from_this to assign to *this . |
*this
. std::weak_ptr<T>
member is not affected by this assignment operator.
|
inline |
Returns a SafeSharedPtr<T>
that shares ownership of *this
with all existing SafeSharedPtr
that refer to *this
.
SafeSharedPtr<T>
that shares ownership of *this
with pre-existing SafeSharedPtr
s.Effectively executes SafeSharedPtr<T>(weak_this)
, where weak_this
is the private mutable std::weak_ptr<T>
member of std::enable_shared_from_this
base class.
SafeSharedPtr
(in particular, shared_from_this cannot be called in a constructor).std::bad_weak_ptr
is thrown (by the SafeSharedPtr constructor from a default-constructed weak_this). std::bad_weak_ptr | Since C++17: When enable_shared_from_this called in constructor, exception will be thrown by the SafeSharedPtr constructor from a default-constructed weak_this. |
|
inline |
Returns a SafeSharedPtr<T const>
that shares ownership of *this
with all existing SafeSharedPtr
that refer to *this
.
SafeSharedPtr<T const>
that shares ownership of *this
with pre-existing SafeSharedPtr
s.Effectively executes SafeSharedPtr<T>(weak_this)
, where weak_this
is the private mutable std::weak_ptr<T>
member of std::enable_shared_from_this
base class.
SafeSharedPtr
(in particular, shared_from_this cannot be called in a constructor).std::bad_weak_ptr
is thrown (by the SafeSharedPtr constructor from a default-constructed weak_this). std::bad_weak_ptr | Since C++17: When enable_shared_from_this called in constructor, exception will be thrown by the SafeSharedPtr constructor from a default-constructed weak_this. |
|
inline |
Returns a SafeWeakPtr<T>
that tracks ownership of *this
by all existing SafeSharedPtr
that refer to *this
.
SafeWeakPtr<T>
that shares ownership of *this
with pre-existing SafeSharedPtr
s; std::weak_ptr
member that is part of std::enable_shared_from_this
.
|
inline |
Returns a SafeWeakPtr<T const>
that tracks ownership of *this
by all existing SafeSharedPtr
that refer to *this
.
SafeWeakPtr<T const>
that shares ownership of *this
with pre-existing SafeSharedPtr
s; std::weak_ptr
member that is part of std::enable_shared_from_this
.
|
friend |