Quandary
Loading...
Searching...
No Matches
Public Member Functions | List of all members
validators::Validator< T > Class Template Reference

Chainable validator for scalar TOML fields. More...

#include <config_validators.hpp>

Public Member Functions

 Validator (const toml::table &config_, const std::string &key_)
 
ValidatorgreaterThan (T greater_than_)
 Requires value to be strictly greater than threshold.
 
ValidatorgreaterThanEqual (T greater_than_equal_)
 Requires value to be greater than or equal to threshold.
 
ValidatorlessThan (T less_than_)
 Requires value to be strictly less than threshold.
 
Validatorpositive ()
 Requires value to be strictly positive (> 0).
 
value ()
 Extracts and validates the field value.
 
valueOr (T default_value_)
 Extracts field value or returns default if missing.
 

Detailed Description

template<typename T>
class validators::Validator< T >

Chainable validator for scalar TOML fields.

This class provides type-safe extraction and validation of single-value fields from TOML configuration using the method chaining pattern described above.

Available Validation Methods

If any of the following methods are called, the corresponding validation is applied when extracting the value, and an error is thrown if the validation fails.

Extraction Methods

Template Parameters
TType of field to validate (int, double, string, bool, etc.)

Constructor & Destructor Documentation

◆ Validator()

template<typename T >
validators::Validator< T >::Validator ( const toml::table &  config_,
const std::string &  key_ 
)
inline

Member Function Documentation

◆ greaterThan()

template<typename T >
Validator & validators::Validator< T >::greaterThan ( greater_than_)
inline

Requires value to be strictly greater than threshold.

Parameters
greater_than_Threshold value (exclusive)
Returns
Reference to this validator for chaining

◆ greaterThanEqual()

template<typename T >
Validator & validators::Validator< T >::greaterThanEqual ( greater_than_equal_)
inline

Requires value to be greater than or equal to threshold.

Parameters
greater_than_equal_Threshold value (inclusive)
Returns
Reference to this validator for chaining

◆ lessThan()

template<typename T >
Validator & validators::Validator< T >::lessThan ( less_than_)
inline

Requires value to be strictly less than threshold.

Parameters
less_than_Threshold value (exclusive)
Returns
Reference to this validator for chaining

◆ positive()

template<typename T >
Validator & validators::Validator< T >::positive ( )
inline

Requires value to be strictly positive (> 0).

Returns
Reference to this validator for chaining

◆ value()

template<typename T >
T validators::Validator< T >::value ( )
inline

Extracts and validates the field value.

Throws ValidationError if the field is missing or if any validation rules fail.

Returns
The validated field value
Exceptions
ValidationErrorIf validation fails

◆ valueOr()

template<typename T >
T validators::Validator< T >::valueOr ( default_value_)
inline

Extracts field value or returns default if missing.

If the field is present, validates it (may throw). If absent, returns the provided default without validation.

Parameters
default_value_Default value to use if field is missing
Returns
The field value or default
Exceptions
ValidationErrorIf field exists but validation fails

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