carb::delegate::DelegateRef< void(Args…)>¶
Defined in carb/delegate/Delegate.h
-
template<class ...
Args
>
classcarb::delegate
::
DelegateRef
<void(Args...)>¶ Holds a reference to a Delegate.
Though Delegate is non-copyable,
DelegateRef
can be thought of as astd::shared_ptr
for Delegate. This allows a Delegate’s bindings to remain active even though the original Delegate has been destroyed, which can allow calls in progress to complete, or a mutex protecting the original Delegate to be unlocked.Public Functions
-
constexpr
DelegateRef
() noexcept¶ Default constructor.
Creates an empty DelegateRef such that
bool(*this)
would befalse
.
-
explicit
DelegateRef
(DelegateType &delegate)¶ Constructor.
Constructs a DelegateRef that holds a strong reference to
delegate
.- Parameters
delegate – The Delegate object to hold a reference to.
-
DelegateRef
(const DelegateRef &other)¶ Copy constructor.
References the same underlying Delegate that
other
references. Ifother
is empty,*this
will also be empty.- Parameters
other – A DelegateRef to copy.
-
DelegateRef
(DelegateRef &&other) = default¶ Move constructor.
Moves the reference from
other
to*this
. Ifother
is empty,*this
will also be empty.other
is left in a valid but empty state.- Parameters
other – A DelegateRef to move.
-
DelegateRef &
operator=
(const DelegateRef &other)¶ Copy-assign.
References the same underlying Delegate that
other
references and releases any existing reference. The order of these operations is unspecified, so assignment from*this
is undefined behavior.- Parameters
other – A DelegateRef to copy.
- Returns
*this
.
-
DelegateRef &
operator=
(DelegateRef &&other) = default¶ Move-assign.
Moves the reference from
other
to*this
and releases any existing reference. The order of these operations is unspecified, so assignment from*this
is undefined behavior. Ifother
is empty,*this
will also be empty.other
is left in a valid but empty state.- Parameters
other – A DelegateRef to move.
- Returns
*this
.
-
explicit
operator bool
() const noexcept¶ Checks whether the DelegateRef holds a valid reference.
- Returns
true
if*this
holds a valid reference;false
otherwise.
-
void
reset
()¶ Clears the DelegateRef to an empty reference.
Postcondition:
bool(*this)
will befalse
.
-
void
reset
(DelegateType &delegate)¶ References a different Delegate and releases any existing reference.
- Parameters
delegate – The Delegate to reference.
-
void
swap
(DelegateRef &other)¶ Swaps the reference with another DelegateRef.
- Parameters
other – A DelegateRef to swap with.
-
DelegateType *
get
() const noexcept¶ Retrieves the underlying DelegateType.
- Returns
a pointer to the referenced Delegate, or
nullptr
ifbool(*this)
would return false.
-
DelegateType &
operator*
() const noexcept¶ Dereferences *this.
- Returns
a reference to the referenced Delegate. If
bool(*this)
would return false, behavior is undefined.
-
DelegateType *
operator->
() const noexcept¶ Dereferences *this.
- Returns
a pointer to the referenced Delegate. If
bool(*this)
would return false, behavior is undefined.
-
constexpr