Toast Engine
Loading...
Searching...
No Matches
toast::Box< T > Class Template Reference

Intrusive reference-counted handle to a Node. More...

#include <box.hpp>

Inheritance diagram for toast::Box< T >:

Public Member Functions

 Box () noexcept=default
 Default-constructs an empty (null) box; does not allocate anything.
 Box (std::nullptr_t) noexcept
 Constructs an empty (null) box; equivalent to the default constructor.
 Box (_detail::ControlBox *control_box) noexcept
 Low-level constructor used internally by the node allocation path; prefer constructing from a Node& or Node*.
 Box (const T *node) noexcept
 Constructs from a live node pointer; safe to call with null (produces an empty box); increments ref count.
 Box (const T &node) noexcept
 Constructs from a live node reference; increments ref count.
 Box (const Box &other) noexcept
 Shares ownership with other; increments ref count.
auto operator= (const Box &other) noexcept -> Box &
 Shares ownership with other; increments ref count.
 Box (Box &&other) noexcept
 Transfers ownership from other; source becomes empty without touching the ref count.
auto operator= (Box &&other) noexcept -> Box &
 Transfers ownership from other; source becomes empty without touching the ref count.
template<typename U>
requires std::convertible_to<U*, T*>
 Box (const Box< U > &other) noexcept
 Derived-type copy; only enabled when U* is implicitly convertible to T*; increments ref count.
template<typename U>
requires std::convertible_to<U*, T*>
auto operator= (const Box< U > &other) noexcept -> Box &
 Derived-type copy assignment; only enabled when U* is implicitly convertible to T*.
template<typename U>
requires std::convertible_to<U*, T*>
 Box (Box< U > &&other) noexcept
 Derived-type move; transfers ownership without touching the ref count.
template<typename U>
requires std::convertible_to<U*, T*>
auto operator= (Box< U > &&other) noexcept -> Box &
 Derived-type move assignment.
auto exists () const noexcept -> bool
 Whether this box holds a live node.
auto operator<=> (const Box &other) const noexcept -> std::strong_ordering
auto operator== (const Box &other) const noexcept -> bool
 operator bool () const noexcept
 operator T& () noexcept
auto operator-> () noexcept -> T *
auto operator* () noexcept -> T &
 operator const T & () const noexcept
auto operator-> () const noexcept -> const T *
auto operator* () const noexcept -> const T &
template<typename U>
requires std::derived_from<U, T>
auto as () const noexcept -> Box< U >
 Downcasts to a derived type; a null Box returns a null Box rather than throwing.
auto rid () const noexcept -> size_t
 Raw identity of the underlying ControlBox as a pointer value; stable for the node's lifetime; used as a hash key.

Friends

struct _detail::ControlBox

Detailed Description

template<typename T>
class toast::Box< T >

Intrusive reference-counted handle to a Node.

The ControlBox lives inside the Node allocation itself, so all Box<Node> handles that refer to the same node share one reference count without any extra heap allocation. This design also makes the ref-count safe across DLL boundaries, where std::shared_ptr's control block would differ between modules.

A Box is null (empty) when default-constructed or after the node has been freed. Always call exists() before dereferencing.

Template Parameters
TA Node subtype
See also
ControlBox, Node

Member Function Documentation

◆ exists()

template<typename T>
auto toast::Box< T >::exists ( ) const -> bool
nodiscardnoexcept

Whether this box holds a live node.

Returns
false if the box is empty or if the node has been freed by World::drainDestroyQueue(); always check exists() before dereferencing
Here is the caller graph for this function:

The documentation for this class was generated from the following files: