|
VoltMod
C++23 framework for CS2 server plugins
|
A multicast signal with a fixed handler signature: the one way to subscribe in VoltMod. More...
#include <Event.hpp>
Public Types | |
| using | Handler = std::function< void(Args...)> |
| using | Lifecycle = EventLifecycle |
Public Member Functions | |
| Event ()=default | |
| Event (Lifecycle lifecycle) | |
| Event (const Event &)=delete | |
| Event & | operator= (const Event &)=delete |
| Subscription | operator+= (Handler handler) |
| bool | Empty () const noexcept |
| size_t | Count () const noexcept |
| void | Raise (Args... args) |
A multicast signal with a fixed handler signature: the one way to subscribe in VoltMod.
The owner declares it as a public member and is the only caller of Raise. Everyone else adds a handler with += and keeps the returned Subscription beside the state that handler captured:
A handler never runs after its Subscription drops, not even from inside a Raise already under way.
Lifetime. The Subscription points at the event, so the event has to outlive it. Declaring the subscription in the object that owns the handler state gives that for free; storing it above the service it points at does not.
Lazy install. An event whose source costs something to run - a vtable hook, an engine-wide callback - takes an EventLifecycle. Subscribing starts the source and dropping the last subscription stops it; nothing else installs it. An engine hook, alone or feeding several events, is a LazyHook.
Not copyable or movable: subscriptions point at one address for their whole life.
| using VoltMod::Event< Args >::Handler = std::function<void(Args...)> |
| using VoltMod::Event< Args >::Lifecycle = EventLifecycle |
EventLifecycle, reachable as Event<...>::Lifecycle where that reads better.
|
default |
|
inlineexplicit |
|
delete |
|
inlinenoexcept |
Definition at line 90 of file Event.hpp.
References VoltMod::CallbackRegistry< T >::Size().
|
inlinenoexcept |
Definition at line 89 of file Event.hpp.
References VoltMod::CallbackRegistry< T >::Empty().
|
inline |
Subscribe handler for as long as the returned Subscription lives. An empty Subscription means nothing was stored: handler was empty, or a Lifecycle refused.
Definition at line 68 of file Event.hpp.
References VoltMod::CallbackRegistry< T >::Add(), VoltMod::CallbackRegistry< T >::Empty(), VoltMod::EventLifecycle::OnFirst, VoltMod::EventLifecycle::OnLast, VoltMod::ReadFile(), and VoltMod::CallbackRegistry< T >::Remove().
|
delete |
|
inline |
Invoke every handler. The owner raises; a consumer with a += subscription does not.
Re-entrancy safe: a handler may subscribe, unsubscribe another, or drop its own Subscription while this runs. One added during the raise first fires on the next one.
Definition at line 98 of file Event.hpp.
References VoltMod::CallbackRegistry< T >::Dispatch(), and VoltMod::ReadFile().
Referenced by VoltMod::PlayerManager::OnClientFullyConnected(), VoltMod::SlotEvents::Raise(), and VoltMod::MenuStack::Step().