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

Functions

void NormalizeTag (std::string &value, std::size_t maxLen, std::string_view fallback, std::string_view what)
 Declarative helpers for post-load config validation: skip bad entries with a warning instead of failing the whole load, and fall back to sane defaults.
 
template<class T >
void FilterValid (std::vector< T > &items, std::invocable< const T &, std::size_t > auto &&validate, std::string_view what)
 
template<class T >
bool FallbackIfEmpty (std::vector< T > &items, const std::vector< T > &defaults, std::string_view what)
 
template<class T >
bool FallbackIfEmpty (std::vector< T > &items, std::invocable auto &&makeDefaults, std::string_view what)
 
std::vector< int > ParseDurations (const std::vector< std::string > &entries, const std::vector< std::string > &defaults, std::string_view what)
 

Function Documentation

◆ FallbackIfEmpty() [1/2]

template<class T >
bool VoltMod::Validation::FallbackIfEmpty ( std::vector< T > &  items,
const std::vector< T > &  defaults,
std::string_view  what 
)

Restore defaults (warning names what) when filtering left items empty, so a list that would dead-end a menu falls back instead. Returns true when the defaults were applied.

Definition at line 56 of file Validation.hpp.

References VoltMod::ReadFile(), and VoltMod::Log::Warn().

Referenced by ParseDurations().

◆ FallbackIfEmpty() [2/2]

template<class T >
bool VoltMod::Validation::FallbackIfEmpty ( std::vector< T > &  items,
std::invocable auto &&  makeDefaults,
std::string_view  what 
)

As above, but makeDefaults runs only when the fallback is needed and its result is moved rather than copied. Prefer it when building the defaults costs anything - passing them by value makes every caller build a list it almost always discards.

Definition at line 72 of file Validation.hpp.

References VoltMod::ReadFile(), and VoltMod::Log::Warn().

◆ FilterValid()

template<class T >
void VoltMod::Validation::FilterValid ( std::vector< T > &  items,
std::invocable< const T &, std::size_t > auto &&  validate,
std::string_view  what 
)

Keep only items where validate returns nullopt; each rejection logs the reason it returned.

Definition at line 35 of file Validation.hpp.

References VoltMod::ReadFile(), and VoltMod::Log::Warn().

Referenced by ParseDurations().

◆ NormalizeTag()

void VoltMod::Validation::NormalizeTag ( std::string &  value,
std::size_t  maxLen,
std::string_view  fallback,
std::string_view  what 
)
inline

Declarative helpers for post-load config validation: skip bad entries with a warning instead of failing the whole load, and fall back to sane defaults.

Reset value to fallback (warning names what) when it is blank or longer than maxLen.

Definition at line 22 of file Validation.hpp.

References VoltMod::ReadFile(), VoltMod::Strings::Trim(), and VoltMod::Log::Warn().

◆ ParseDurations()

std::vector< int > VoltMod::Validation::ParseDurations ( const std::vector< std::string > &  entries,
const std::vector< std::string > &  defaults,
std::string_view  what 
)
inline

Parse ParseDuration strings, dropping invalid entries with warnings. Falls back to parsing defaults when nothing valid remains (so the list exists in exactly one place).

Definition at line 92 of file Validation.hpp.

References FallbackIfEmpty(), FilterValid(), VoltMod::ParseDuration(), and VoltMod::ReadFile().