Class encapsulating parameters for generically holding configuration parameters.
More...
#include <Parameters.h>
|
| template<typename T > |
| void | add (const std::string &name, const T &value, bool overlay=false) |
| | Add a parameter to the parameter list.
|
| |
| bool | exists (const std::string &name) const |
| | Check to see if a parameter exists.
|
| |
| template<typename T > |
| const T & | get (const std::string &name) const |
| | Retrieve the parameter of the given name.
|
| |
| template<typename T > |
| const T & | get (const std::string &name, const T &def) const |
| | Retrieve a parameter with a default specified.
|
| |
| std::vector< std::string > | keys () const |
| | Get a list of the keys available.
|
| |
| void | from_yaml (const std::string &filepath, bool overlay=true) |
| | Load parameters from a YAML file.
|
| |
|
|
std::map< std::string, std::any > | parameters_ |
| | container holding parameter names and their values
|
| |
Class encapsulating parameters for generically holding configuration parameters.
The storage of arbitrary parameters recursively is done using a map from parameter names (std::string) to parameter values. The values are stored in std::any which allows the user to store any object they wish in a memory-safe environment.
◆ add()
template<typename T >
| void pflib::Parameters::add |
( |
const std::string & | name, |
|
|
const T & | value, |
|
|
bool | overlay = false ) |
|
inline |
Add a parameter to the parameter list.
If the parameter already exists in the list, throw an exception.
- Parameters
-
| [in] | name | Name of the parameter. |
| [in] | value | The value of the parameter. |
- Template Parameters
-
| T | type of parameter being added |
- Exceptions
-
| Exception | if a parameter by that name already exist in the list. |
◆ exists()
| bool pflib::Parameters::exists |
( |
const std::string & | name | ) |
const |
Check to see if a parameter exists.
- Parameters
-
| [in] | name | name of parameter to check |
- Returns
- true if parameter exists in configuration set
◆ from_yaml()
| void pflib::Parameters::from_yaml |
( |
const std::string & | filepath, |
|
|
bool | overlay = true ) |
Load parameters from a YAML file.
- Parameters
-
| [in] | filepath | path to YAML file to load into us |
| [in] | overlay | allow the input YAML to overwrite current parameters |
◆ get() [1/2]
template<typename T >
| const T & pflib::Parameters::get |
( |
const std::string & | name | ) |
const |
|
inline |
Retrieve the parameter of the given name.
- Exceptions
-
| Exception | if parameter of the given name isn't found |
| Exception | if parameter is found but not of the input type |
- Template Parameters
-
| T | the data type to cast the parameter to. |
- Parameters
-
| [in] | name | the name of the parameter value to retrieve. |
- Returns
- The user specified parameter of type T.
◆ get() [2/2]
template<typename T >
| const T & pflib::Parameters::get |
( |
const std::string & | name, |
|
|
const T & | def ) const |
|
inline |
Retrieve a parameter with a default specified.
Return the input default if a parameter is not found in map.
- Template Parameters
-
| T | type of parameter to return |
- Parameters
-
| [in] | name | parameter name to retrieve |
| [in,out] | def | default to use if parameter is not found |
- Returns
- the user parameter of type T
◆ keys()
Get a list of the keys available.
This may be helpful in debugging to make sure the parameters are spelled correctly.
- Returns
- list of all keys in this map of parameters
The documentation for this class was generated from the following files: