Class for managing hierarchical configuration parameters. More...
#include <configuration.h>
Public Member Functions | |
| Configuration () | |
| Default constructor creates an empty configuration. | |
| Configuration (const YAML::Node &node) | |
| Construct Configuration from an existing YAML::Node. | |
| void | load (const std::string &file_name) |
| Loads configuration parameters from a YAML file. | |
| Configuration | operator[] (const std::string &key) const |
| Access a sub-configuration. | |
| Configuration | at_path (const std::string &dotted_key) const |
| Access a nested sub-configuration via a dotted path (supports '.' to escape dots). | |
| template<typename T> | |
| T | get_path (const std::string &dotted_key, const T &default_value=T()) const |
| Read a value at a dotted path with a default (convenience wrapper around at_path(...).get(...)). | |
| template<typename T> | |
| T | get (const T &default_value=T()) const |
| Retrieves the configuration value cast to type T. | |
| template<typename T> | |
| void | set (const std::string &key, const T &value) |
| Sets the configuration entry for the given key. | |
| bool | exists () const |
| Checks if the current node is defined. | |
| std::string | summary () const |
| Provides a summary of the configuration. | |
| std::vector< std::pair< std::string, Configuration > > | children () const |
| Returns the children (sub-entries) of the current node. | |
Class for managing hierarchical configuration parameters.
The Configuration class wraps a YAML::Node, preserving the nested structure of the configuration. It provides direct access to sub-parts of the configuration via the [] operator and allows iteration over sub-entries.
| Configuration::Configuration | ( | ) |
Default constructor creates an empty configuration.
|
explicit |
Construct Configuration from an existing YAML::Node.
| Configuration Configuration::at_path | ( | const std::string & | dotted_key | ) | const |
Access a nested sub-configuration via a dotted path (supports '.' to escape dots).
| std::vector< std::pair< std::string, Configuration > > Configuration::children | ( | ) | const |
Returns the children (sub-entries) of the current node.
If the current node is a map or sequence, returns a vector of pairs where each pair consists of the key (or index as a string) and the corresponding Configuration. If the node is not a container, returns an empty vector.
| bool Configuration::exists | ( | ) | const |
Checks if the current node is defined.
| T Configuration::get | ( | const T & | default_value = T() | ) | const |
Retrieves the configuration value cast to type T.
If the current node is defined, attempts to cast it to type T; otherwise returns default_value.
| T | The expected type. |
| default_value | The default value to return if the node is not defined or conversion fails. |
| T Configuration::get_path | ( | const std::string & | dotted_key, |
| const T & | default_value = T() ) const |
Read a value at a dotted path with a default (convenience wrapper around at_path(...).get(...)).
| void Configuration::load | ( | const std::string & | file_name | ) |
Loads configuration parameters from a YAML file.
| file_name | The path to the YAML configuration file. |
| std::runtime_error | if the YAML file cannot be read or parsed. |
| Configuration Configuration::operator[] | ( | const std::string & | key | ) | const |
Access a sub-configuration.
Returns a Configuration object wrapping the sub-node corresponding to the provided key.
| key | The key for the sub-configuration. |
| void Configuration::set | ( | const std::string & | key, |
| const T & | value ) |
Sets the configuration entry for the given key.
If the current node is not a map, it is converted to one.
| T | The type of the value. |
| key | The key where the value should be set. |
| value | The value to set. |
| std::string Configuration::summary | ( | ) | const |
Provides a summary of the configuration.