92 void (*
destroy)(
void*)
noexcept =
nullptr;
155 requires
Type::ConvertibleTo<U*, T*>
164 requires
Type::ConvertibleTo<U*, T*>
215 std::add_lvalue_reference_t<T> operator*() const noexcept;
221 T* operator->() const noexcept;
227 explicit operator
bool() const noexcept;
272 template<class Target, class... Args>
273 requires
Type::SameAs<Target, T> ||
Type::DerivedFrom<Target, T>
281 if (m_control ==
nullptr)
283 m_control->Strong.fetch_add(1, std::memory_order_relaxed);
285 return std::shared_ptr<T>(m_object, [control](T*)
noexcept {
286 if (control->
Strong.fetch_sub(1, std::memory_order_acq_rel) == 1) {
288 if (control->
Weak.fetch_sub(1, std::memory_order_acq_rel) == 1)
316 template<class U, class... Args>
319 template<class X, class Y>
322 template<class X, class Y>
325 template<class X, class Y>
328 template<class X, class Y>
331 Detail::Control* m_control;
366 requires
Type::ConvertibleTo<U*, T*>
410 std::add_lvalue_reference_t<T> operator*() const noexcept;
416 T* operator->() const noexcept;
422 explicit operator
bool() const noexcept;
443 template<class Target, class... Args>
444 requires
Type::SameAs<Target, T> ||
Type::DerivedFrom<Target, T>
453 T*
object = m_object;
456 return std::unique_ptr<T, Heap::ObjectDeleter>(
object, deleter);
465 Unique(T*
object,
void (*destroy)(
void*)
noexcept)
noexcept;
470 template<
class U,
class... Args>
474 void (*m_destroy)(
void*)
noexcept;
506 requires
Type::ConvertibleTo<U*, T*>
591 void Release() noexcept;
602 Detail::Control* m_control;
661 template<class U, class... Args>
664 mutable
Weak<T> m_weak;
717 explicit operator
bool() const noexcept;
758 void Lock() const noexcept;
763 void Unlock() const noexcept;
765 mutable
std::atomic_flag m_lock;
766 Detail::Control* m_control;
778 template<class T, class... Args>
789 template<class T, class... Args>
799 template<class T, class U>
809 template<class T, class U>
819 template<class T, class U>
829 template<class T, class U>
840 template<class T, class U>
842 return left.get() == right.get();
853 template<
class T,
class U>
855 return std::compare_three_way{}(left.get(), right.get());
867 return left.get() == null;
879 return std::compare_three_way{}(left.get(),
static_cast<T*
>(null));
890 template<
class T,
class U>
892 return left.get() == right.get();
903 template<
class T,
class U>
905 return std::compare_three_way{}(left.get(), right.get());
917 return left.get() == null;
929 return std::compare_three_way{}(left.get(),
static_cast<T*
>(null));
Atomic publication of a Shared.
Definition pointers.hxx:675
Shared< T > exchange(Shared< T > owner) noexcept
Replace the published owner and return the previous one.
AtomicShared() noexcept
Construct an empty atomic owner.
bool compare_exchange_weak(Shared< T > &expected, Shared< T > desired) noexcept
Replace the published owner when it compares equal by address.
bool compare_exchange_strong(Shared< T > &expected, Shared< T > desired) noexcept
Replace the published owner when it compares equal by address.
Shared< T > load() const noexcept
Copy the published owner.
void store(Shared< T > owner) noexcept
Replace the published owner.
Base that can recover a Shared from an object owned by one.
Definition pointers.hxx:614
Shared< T > SharedFromThis() const
Recover an owner of this object.
friend Shared< U > MakeShared(Args &&...)
EnableSharedFromThis() noexcept=default
Construct an unlinked base.
Forward declaration of shared ownership.
Definition pointers.hxx:133
friend Shared< X > ConstPointerCast(const Shared< Y > &) noexcept
friend Shared< X > ReinterpretPointerCast(const Shared< Y > &) noexcept
friend Shared< X > DynamicPointerCast(const Shared< Y > &) noexcept
friend class AtomicShared
Definition pointers.hxx:314
void swap(Shared &other) noexcept
Exchange owners.
Weak< T > weak_type
Matching observer.
Definition pointers.hxx:136
friend Shared< X > StaticPointerCast(const Shared< Y > &) noexcept
Shared() noexcept
Construct an empty owner.
bool owner_before(const Shared< U > &other) const noexcept
Order control blocks by identity.
friend class Shared
Definition pointers.hxx:308
void reset() noexcept
Drop this owner.
friend Shared< U > MakeShared(Args &&...)
T element_type
Pointee type.
Definition pointers.hxx:135
static Shared< T > MakePointer(Args &&... args)
Allocate Target on Base's heap and own it as T.
long use_count() const noexcept
Return the number of owners.
friend class Weak
Definition pointers.hxx:311
T * get() const noexcept
Return the stored pointer.
Forward declaration of unique ownership.
Definition pointers.hxx:343
T element_type
Pointee type.
Definition pointers.hxx:345
void reset() noexcept
Destroy the object and leave this owner empty.
friend Unique< U > MakeUnique(Args &&...)
T * get() const noexcept
Return the stored pointer.
Heap::ObjectDeleter deleter_type
Deleter used by the STL conversion.
Definition pointers.hxx:347
void swap(Unique &other) noexcept
Exchange owners.
friend class Unique
Definition pointers.hxx:468
static Unique< T > MakePointer(Args &&... args)
Allocate Target on Base's heap and own it as T.
Unique() noexcept
Construct an empty owner.
T * pointer
Stored pointer.
Definition pointers.hxx:346
Forward declaration of weak ownership.
Definition pointers.hxx:485
void swap(Weak &other) noexcept
Exchange observers.
Weak() noexcept
Construct an empty observer.
void reset() noexcept
Drop this observer.
bool expired() const noexcept
Test whether the object is already gone.
friend class Shared
Definition pointers.hxx:597
Shared< T > lock() const noexcept
Lock the control block.
friend class EnableSharedFromThis
Definition pointers.hxx:600
long use_count() const noexcept
Return the number of owners.
bool owner_before(const Weak< U > &other) const noexcept
Order control blocks by identity.
T element_type
Pointee type.
Definition pointers.hxx:487
friend class Weak
Definition pointers.hxx:594
Private Base heap used by StormByte::Safe::Shared, StormByte::Safe::Unique and StormByte::Safe::Clona...
Allocate and free raw blocks on Base's heap.
void Free(void *pointer) noexcept
Release a block obtained from Allocate.
Owned values that cross a DLL without the caller's CRT.
bool operator==(std::span< const std::byte > bytes, const Binary &data) noexcept
Equality of a span against a sequence.
Definition binary.hxx:770
Shared< T > MakeShared(Args &&... args)
Construct T on Base's heap and share it.
Shared< T > ReinterpretPointerCast(const Shared< U > &from) noexcept
reinterpret_cast of the stored pointer.
Shared< T > ConstPointerCast(const Shared< U > &from) noexcept
const_cast of the stored pointer.
constexpr First & get(Pair< First, Second > &pair) noexcept
Access the first pair member.
void swap(Binary &left, Binary &right) noexcept
Exchange two sequences.
Definition binary.hxx:760
Unique< T > MakeUnique(Args &&... args)
Construct T on Base's heap and own it.
STORMBYTE_FORCE_INLINE std::strong_ordering operator<=>(std::span< const std::byte > bytes, const Binary &data) noexcept
Three-way comparison of a span against a sequence.
Definition binary.hxx:790
Shared< T > StaticPointerCast(const Shared< U > &from) noexcept
static_cast of the stored pointer.
Shared< T > DynamicPointerCast(const Shared< U > &from) noexcept
dynamic_cast of the stored pointer.
@ Release
Release.
Definition memory_order.hxx:64
Root namespace of the StormByte suite.
Octet count. Defined in byte_size.hxx. Forwarded so Type::Numeral can name it.
Base-owned reference counts and the real destructor.
Definition pointers.hxx:117
void(* Destroy)(Control *) noexcept
Destructor of the concrete object.
Definition pointers.hxx:120
void * Object
Address of the concrete object inside this block.
Definition pointers.hxx:121
std::atomic< long > Weak
Owners plus observers. Zero frees the block.
Definition pointers.hxx:119
std::atomic< long > Strong
Owners. Zero destroys the object.
Definition pointers.hxx:118
STORMBYTE_FORCE_INLINE std::size_t operator()(const StormByte::Safe::Shared< T > &value) const noexcept
Hash the stored address.
Definition pointers.hxx:968
STORMBYTE_FORCE_INLINE std::size_t operator()(const StormByte::Safe::Unique< T > &value) const noexcept
Hash the stored address.
Definition pointers.hxx:980
STORMBYTE_FORCE_INLINE std::size_t operator()(const StormByte::Safe::Weak< T > &value) const noexcept
Hash the observed address.
Definition pointers.hxx:992
Cross-module hash.
Definition hash.hxx:95
Destroy the concrete object and return its block to Free.
Definition pointers.hxx:91
void operator()(U *pointer) const noexcept
Destroy pointer with the concrete destructor.
Definition pointers.hxx:100
void(* destroy)(void *) noexcept
Concrete destructor stored by Unique.
Definition pointers.hxx:92
std::size_t operator()(const StormByte::Safe::Shared< T > &value) const noexcept
Hash the stored address.
Definition pointers.hxx:1004
std::size_t operator()(const StormByte::Safe::Unique< T > &value) const noexcept
Hash the stored address.
Definition pointers.hxx:1016
std::size_t operator()(const StormByte::Safe::Weak< T > &value) const noexcept
Hash the observed address.
Definition pointers.hxx:1028
#define STORMBYTE_PUBLIC_TYPE
Definition visibility.h:57