Pogosim
Loading...
Searching...
No Matches
Configuration Class Reference

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>
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>
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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ Configuration() [1/2]

Configuration::Configuration ( )

Default constructor creates an empty configuration.

◆ Configuration() [2/2]

Configuration::Configuration ( const YAML::Node & node)
explicit

Construct Configuration from an existing YAML::Node.

Member Function Documentation

◆ at_path()

Configuration Configuration::at_path ( const std::string & dotted_key) const

Access a nested sub-configuration via a dotted path (supports '.' to escape dots).

◆ children()

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.

Returns
std::vector<std::pair<std::string, Configuration>> Vector of key/Configuration pairs.

◆ exists()

bool Configuration::exists ( ) const

Checks if the current node is defined.

Returns
true if the node exists and is valid; false otherwise.

◆ get()

template<typename T>
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.

Parameters
TThe expected type.
default_valueThe default value to return if the node is not defined or conversion fails.
Returns
T The value of the node cast to type T.

◆ get_path()

template<typename T>
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(...)).

◆ load()

void Configuration::load ( const std::string & file_name)

Loads configuration parameters from a YAML file.

Parameters
file_nameThe path to the YAML configuration file.
Exceptions
std::runtime_errorif the YAML file cannot be read or parsed.

◆ operator[]()

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.

Parameters
keyThe key for the sub-configuration.
Returns
Configuration The sub-configuration.

◆ set()

template<typename T>
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.

Template Parameters
TThe type of the value.
Parameters
keyThe key where the value should be set.
valueThe value to set.

◆ summary()

std::string Configuration::summary ( ) const

Provides a summary of the configuration.

Returns
A string representation of the configuration.

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