VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::PerSlot< T > Class Template Reference

Per-player-slot value store that never leaks state across occupants. More...

#include <PerSlot.hpp>

Public Member Functions

 PerSlot ()=default
 PerSlot (SlotEvents &slots)
 ~PerSlot ()
 PerSlot (const PerSlot &)=delete
PerSlot & operator= (const PerSlot &)=delete
T & operator[] (int slot)
const T & operator[] (int slot) const
void Reset (int slot)
void ResetAll ()

Detailed Description

template<class T>
class VoltMod::PerSlot< T >

Per-player-slot value store that never leaks state across occupants.

A plain std::array<T, MaxPlayers>. Constructed with the slot-change feed, the entry for a slot is value-reset whenever a player joins or leaves it: PerSlot<State> _state{runtime.Slots};. Default construction is inert, for an owner that resets entries itself.

Takes SlotEvents rather than the runtime so a plugin translation unit that includes only this header still compiles.

Definition at line 24 of file PerSlot.hpp.

Constructor & Destructor Documentation

◆ PerSlot() [1/3]

template<class T>
VoltMod::PerSlot< T >::PerSlot ( )
default

Referenced by operator=(), and PerSlot().

◆ PerSlot() [2/3]

template<class T>
VoltMod::PerSlot< T >::PerSlot ( SlotEvents & slots)
inlineexplicit

Resets a slot's entry on player connect/disconnect. slots must outlive this object.

Definition at line 29 of file PerSlot.hpp.

References Reset().

◆ ~PerSlot()

template<class T>
VoltMod::PerSlot< T >::~PerSlot ( )
inline

Unsubscribes directly, so the feed cannot reset entries that are going away.

Definition at line 31 of file PerSlot.hpp.

◆ PerSlot() [3/3]

template<class T>
VoltMod::PerSlot< T >::PerSlot ( const PerSlot< T > & )
delete

References PerSlot().

Member Function Documentation

◆ operator=()

template<class T>
PerSlot & VoltMod::PerSlot< T >::operator= ( const PerSlot< T > & )
delete

References PerSlot().

◆ operator[]() [1/2]

template<class T>
T & VoltMod::PerSlot< T >::operator[] ( int slot)
inline
Precondition
IsValidSlot(slot); asserted, not checked - callers that can receive an unvalidated slot (console callers, CallerSlot() == -1) must check IsValidSlot before indexing.

Definition at line 37 of file PerSlot.hpp.

References VoltMod::IsValidSlot().

◆ operator[]() [2/2]

template<class T>
const T & VoltMod::PerSlot< T >::operator[] ( int slot) const
inline

Definition at line 42 of file PerSlot.hpp.

References VoltMod::IsValidSlot().

◆ Reset()

template<class T>
void VoltMod::PerSlot< T >::Reset ( int slot)
inline

Definition at line 48 of file PerSlot.hpp.

References VoltMod::IsValidSlot(), and VoltMod::T.

Referenced by PerSlot().

◆ ResetAll()

template<class T>
void VoltMod::PerSlot< T >::ResetAll ( )
inline

Assigned one by one rather than through fill, which would copy: the common T here is move-only (a Subscription), and dropping one is exactly what cancels it.

Definition at line 58 of file PerSlot.hpp.

References VoltMod::T.


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