VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::Subscription Class Reference

Owns one registration and releases it on destruction. More...

#include <Subscription.hpp>

Public Member Functions

 Subscription ()=default
 
 Subscription (std::move_only_function< void()> cleanup)
 
 ~Subscription ()
 
 Subscription (Subscription &&other) noexcept
 
Subscription & operator= (Subscription &&other) noexcept
 
 Subscription (const Subscription &)=delete
 
Subscription & operator= (const Subscription &)=delete
 
void Reset ()
 
 operator bool () const noexcept
 

Detailed Description

Owns one registration and releases it on destruction.

Holding one keeps the registration alive. Store it beside the state captured by its handler so it unregisters before that state is destroyed:

class Bhop {
Bhop(GameEvents& events) {
_spawn = events.On<PlayerSpawn>([this](const PlayerSpawn& e) { OnSpawn(e.Slot); });
}
Subscription _spawn;
};
Creates, fires and listens to game events.
Subscription On(std::function< void(const TEvent &)> handler)
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56

The cleanup callable may hold any registry handle, including non-handle-based registrations such as hook installs (see VoltMod::HookInterface).

Move-only. The registry must outlive its Subscription; reverse declaration order provides this when both are members of one object.

<VoltMod/Core/Signals/Subscriptions.hpp> holds several of them in one member, for an object that subscribes to a handful of things at once.

Definition at line 33 of file Subscription.hpp.

Constructor & Destructor Documentation

◆ Subscription() [1/4]

VoltMod::Subscription::Subscription ( )
default

◆ Subscription() [2/4]

VoltMod::Subscription::Subscription ( std::move_only_function< void()>  cleanup)
inlineexplicit

Run cleanup on destruction; it captures whatever handle the registry issued.

Definition at line 39 of file Subscription.hpp.

◆ ~Subscription()

VoltMod::Subscription::~Subscription ( )
inline

Definition at line 41 of file Subscription.hpp.

References Reset().

◆ Subscription() [3/4]

VoltMod::Subscription::Subscription ( Subscription &&  other)
inlinenoexcept

Definition at line 43 of file Subscription.hpp.

◆ Subscription() [4/4]

VoltMod::Subscription::Subscription ( const Subscription &  )
delete

Member Function Documentation

◆ operator bool()

VoltMod::Subscription::operator bool ( ) const
inlineexplicitnoexcept

True while this holds a live registration.

Definition at line 68 of file Subscription.hpp.

◆ operator=() [1/2]

Subscription & VoltMod::Subscription::operator= ( const Subscription &  )
delete

◆ operator=() [2/2]

Subscription & VoltMod::Subscription::operator= ( Subscription &&  other)
inlinenoexcept

Definition at line 45 of file Subscription.hpp.

References VoltMod::ReadFile(), and Reset().

◆ Reset()

void VoltMod::Subscription::Reset ( )
inline

Release now. Idempotent, and re-entrant: the callable is detached before it runs.

Definition at line 59 of file Subscription.hpp.

References VoltMod::ReadFile().

Referenced by VoltMod::Database::Disconnect(), operator=(), VoltMod::ScreenManager::ScreenManager(), VoltMod::PerSlot< T >::~PerSlot(), and ~Subscription().


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