|
Quandary
|
Chainable validator for scalar TOML fields. More...
#include <config_validators.hpp>
Public Member Functions | |
| Validator (const toml::table &config_, const std::string &key_) | |
| Validator & | greaterThan (T greater_than_) |
| Requires value to be strictly greater than threshold. | |
| Validator & | greaterThanEqual (T greater_than_equal_) |
| Requires value to be greater than or equal to threshold. | |
| Validator & | lessThan (T less_than_) |
| Requires value to be strictly less than threshold. | |
| Validator & | positive () |
| Requires value to be strictly positive (> 0). | |
| T | value () |
| Extracts and validates the field value. | |
| T | valueOr (T default_value_) |
| Extracts field value or returns default if missing. | |
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.
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.
greaterThan(value): Field must be > valuegreaterThanEqual(value): Field must be >= valuelessThan(value): Field must be < valuepositive(): Field must be > 0 (shorthand for greaterThan(0))value(): Extract scalar or throws an error if field is missing or invalidvalueOr(default): Extract scalar or return default if field missing| T | Type of field to validate (int, double, string, bool, etc.) |
|
inline |
Requires value to be strictly greater than threshold.
| greater_than_ | Threshold value (exclusive) |
|
inline |
Requires value to be greater than or equal to threshold.
| greater_than_equal_ | Threshold value (inclusive) |
Requires value to be strictly less than threshold.
| less_than_ | Threshold value (exclusive) |
|
inline |
Requires value to be strictly positive (> 0).
|
inline |
Extracts and validates the field value.
Throws ValidationError if the field is missing or if any validation rules fail.
| ValidationError | If validation fails |
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.
| default_value_ | Default value to use if field is missing |
| ValidationError | If field exists but validation fails |