|
| template<typename T > |
| std::string | getTypeName () |
| | Helper to get readable type names for error messages.
|
| |
| template<typename T > |
| Validator< T > | field (const toml::table &config_, const std::string &key_) |
| | Creates a scalar field validator.
|
| |
| template<typename T > |
| VectorValidator< T > | vectorField (const toml::table &config_, const std::string &key_) |
| | Creates a vector field validator.
|
| |
| template<typename T , typename NodeType > |
| std::optional< T > | getOptional (const toml::node_view< NodeType > &node) |
| | Extracts an optional scalar value from a TOML node.
|
| |
| template<typename T , typename NodeType > |
| std::optional< std::vector< T > > | getOptionalVector (const toml::node_view< NodeType > &node) |
| | Extracts an optional vector from a TOML node.
|
| |
| const toml::table & | getRequiredTable (const toml::table &config, const std::string &key) |
| | Extracts a required table from a TOML configuration.
|
| |
| template<typename T > |
| std::vector< T > | scalarOrVector (const toml::table &config, const std::string &key, size_t expected_size) |
| | Parses a field that can be either a scalar (applied to all) or an exact-size array.
|
| |
| template<typename T > |
| std::vector< T > | scalarOrVectorOr (const toml::table &config, const std::string &key, size_t expected_size, const std::vector< T > &default_value) |
| | Parses an optional field that can be either a scalar or an exact-size array.
|
| |
Validation utilities for TOML configuration parsing.
Provides a chainable API for type-safe TOML field extraction and validation. Chain validation methods together, then extract the final value in one operation with clear error messages.
Basic Usage
- Create a validator for option "key" within toml_table using
- Append chainable validation methods from below as needed: For scalar fields:
greaterThan(value): Field must be > value
greaterThanEqual(value): Field must be >= value
lessThan(value): Field must be < value
positive(): Field must be > 0 (shorthand for greaterThan(0)) For vector fields:
minLength(size): Vector must have at least size elements
hasLength(size): Vector must have exactly size elements
positive(): All elements must be > 0
- Extract the value by appending .value() - for required fields .valueOr(default) - for optional fields with default
Examples
double step_size = validators::field<double>(toml, "step_size").positive().value();
std::string output_dir = validators::field<std::string>(toml, "output_dir").valueOr("./data_out");
std::vector<double> frequencies = validators::vectorField<double>(toml, "frequencies").minLength(1).positive().valueOr(std::vector<double>{1.0, 2.0});
Supported Types
Scalar fields: int, size_t, double, std::string, bool, etc. Vector fields: std::vector<T> where T is any supported scalar type
template<typename T , typename NodeType >
| std::optional< T > validators::getOptional |
( |
const toml::node_view< NodeType > & |
node | ) |
|
Extracts an optional scalar value from a TOML node.
Helper for extracting optional scalar values when the validator API doesn't fit well (e.g., nested structures or conditional parsing). If the node doesn't exist or contains a type mismatch, returns nullopt.
- Template Parameters
-
| T | Type of the scalar value |
| NodeType | Type of the TOML node |
- Parameters
-
| node | TOML node that may contain a value |
- Returns
- Value if node exists and has matching type, nullopt otherwise
template<typename T , typename NodeType >
| std::optional< std::vector< T > > validators::getOptionalVector |
( |
const toml::node_view< NodeType > & |
node | ) |
|
Extracts an optional vector from a TOML node.
Helper for extracting vectors when the validator API doesn't fit well (e.g., nested structures or conditional parsing). If the node is not an array or contains type mismatches, returns nullopt.
- Template Parameters
-
| T | Element type of the vector |
| NodeType | Type of the TOML node |
- Parameters
-
| node | TOML node that may contain an array |
- Returns
- Vector if node is a valid array with matching types, nullopt otherwise