VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::Options< TSettings, TSnapshot > Class Template Reference

Owns a plugin's settings and republishes them whole on every Load. More...

#include <Options.hpp>

Public Types

using Builder = std::function< TSnapshot(TSettings)>
 Validates the parsed settings and derives whatever Get() offers beside them.
 

Public Member Functions

 Options ()
 
 Options (Builder build)
 
Status Load (std::string_view path)
 Load path (JSONC tolerated), build the snapshot, then publish it in one move.
 
Status Reload ()
 
const TSnapshot & Get () const
 

Detailed Description

template<class TSettings, class TSnapshot = TSettings>
class VoltMod::Options< TSettings, TSnapshot >

Owns a plugin's settings and republishes them whole on every Load.

TSettings is a plain aggregate whose member names are the JSON keys. A missing key keeps the member's initializer and unknown keys are ignored. To validate or derive values, name a TSnapshot and pass the function that builds it from the parsed settings. The snapshot is built before it is published, so a failed Load keeps the previous one. See docs/config.md.

Definition at line 24 of file Options.hpp.

Member Typedef Documentation

◆ Builder

template<class TSettings , class TSnapshot = TSettings>
using VoltMod::Options< TSettings, TSnapshot >::Builder = std::function<TSnapshot(TSettings)>

Validates the parsed settings and derives whatever Get() offers beside them.

Definition at line 28 of file Options.hpp.

Constructor & Destructor Documentation

◆ Options() [1/2]

template<class TSettings , class TSnapshot = TSettings>
VoltMod::Options< TSettings, TSnapshot >::Options ( )
inline

Publishes the parsed settings unchanged.

Definition at line 31 of file Options.hpp.

◆ Options() [2/2]

template<class TSettings , class TSnapshot = TSettings>
VoltMod::Options< TSettings, TSnapshot >::Options ( Builder  build)
inlineexplicit

Definition at line 36 of file Options.hpp.

Member Function Documentation

◆ Get()

template<class TSettings , class TSnapshot = TSettings>
const TSnapshot & VoltMod::Options< TSettings, TSnapshot >::Get ( ) const
inline

The effective settings.

Definition at line 68 of file Options.hpp.

◆ Load()

template<class TSettings , class TSnapshot = TSettings>
Status VoltMod::Options< TSettings, TSnapshot >::Load ( std::string_view  path)
inline

Load path (JSONC tolerated), build the snapshot, then publish it in one move.

On failure the previously published snapshot stands, and the error names the offending key with its line and column.

Definition at line 42 of file Options.hpp.

References VoltMod::Log::Info(), VoltMod::ReadFile(), and VoltMod::Json::ReadFile().

Referenced by VoltMod::Options< TSettings, TSnapshot >::Reload().

◆ Reload()

template<class TSettings , class TSnapshot = TSettings>
Status VoltMod::Options< TSettings, TSnapshot >::Reload ( )
inline

Load the path the last Load read, again.

Definition at line 58 of file Options.hpp.

References VoltMod::Options< TSettings, TSnapshot >::Load(), and VoltMod::Error::NotReady().


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