carb::eventdispatcher::ObserverGuard
Defined in carb/eventdispatcher/EventDispatcherTypes.h
-
class ObserverGuard
Structure to manage the lifetime of an observer. Similar to
std::unique_ptr
.Public Functions
-
constexpr ObserverGuard() noexcept
Default constructor.
Constructs an empty
ObserverGuard
.
-
explicit constexpr ObserverGuard(Observer o) noexcept
Constructor that accepts an Observer handle.
- Parameters
o – The Observer to manage.
-
ObserverGuard(ObserverGuard &&other) noexcept
Move constructor.
Moves the Observer managed by
other
to*this
and leavesother
empty.- Parameters
other – The other
ObserverGuard
.
-
~ObserverGuard() noexcept
Destructor.
-
ObserverGuard &operator=(ObserverGuard &&other) noexcept
Move-assign operator.
Moves the Observer managed by
other
to*this
.- Parameters
other – The other
ObserverGuard
.
-
Observer release() noexcept
Releases the managed Observer to the caller and leaves
*this
empty.Note
This does not stop the managed Observer.
- Returns
The Observer previously managed by
*this
.
-
void reset(Observer o = kInvalidObserver) noexcept
Stops any currently managed observer (as via IEventDispatcher::stopObserving()) and takes ownership of the given Observer.
- Parameters
o – The new Observer to manage, or kInvalidObserver to remain empty.
-
void swap(ObserverGuard &o) noexcept
Exchanges state with another
ObserverGuard
.- Parameters
o – The other
ObserverGuard
.
-
constexpr Observer get() const noexcept
Returns the managed Observer while maintaining management of it.
- Returns
The managed Observer.
-
explicit operator bool() const noexcept
Validation test.
- Returns
true
if*this
is non-empty (manages a valid observer);false
otherwise.
-
constexpr ObserverGuard() noexcept