GLIM
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
glim::Config Class Reference

Configuration loader from JSON files. More...

#include <config.hpp>

Inheritance diagram for glim::Config:
Inheritance graph
[legend]

Public Member Functions

 Config (const std::string &config_filename)
 Configuration JSON filename.
 
template<typename T >
std::optional< T > param (const std::string &module_name, const std::string &param_name) const
 Get a parameter.
 
template<typename T >
param (const std::string &module_name, const std::string &param_name, const T &default_value) const
 Get a parameter with default value.
 
template<typename T >
param_cast (const std::string &module_name, const std::string &param_name) const
 Get a parameter.
 
template<typename T >
std::optional< T > param_nested (const std::vector< std::string > &nested_module_names, const std::string &param_name) const
 Get a parameter from a nested module.
 
template<typename T >
param_nested (const std::vector< std::string > &nested_module_names, const std::string &param_name, const T &default_value) const
 Get a parameter from a nested module with default value.
 
template<typename T >
param_cast_nested (const std::vector< std::string > &nested_module_names, const std::string &param_name) const
 Get a parameter.
 
template<typename T >
bool override_param (const std::string &module_name, const std::string &param_name, const T &value)
 Override a parameter value.
 
void save (const std::string &path) const
 Save config parameters as a JSON file.
 

Protected Attributes

std::any config
 

Detailed Description

Configuration loader from JSON files.

Member Function Documentation

◆ override_param()

template<typename T >
bool glim::Config::override_param ( const std::string &  module_name,
const std::string &  param_name,
const T &  value 
)

Override a parameter value.

Note
This parameter override is volatile and does not make any changes on the JSON file
Parameters
module_nameModule name
param_nameParameter name
valueValue to override the parameter
Returns
True if the parameter exists, otherwise false

◆ param() [1/2]

template<typename T >
std::optional< T > glim::Config::param ( const std::string &  module_name,
const std::string &  param_name 
) const

Get a parameter.

Parameters
module_nameModule name
param_nameParameter name
Returns
Parameter value if the param is found, otherwise nullopt

◆ param() [2/2]

template<typename T >
T glim::Config::param ( const std::string &  module_name,
const std::string &  param_name,
const T &  default_value 
) const

Get a parameter with default value.

Parameters
module_nameModule name
param_nameParameter name
default_valueDefault value
Returns
Parameter value if the param is found, otherwise the default value

◆ param_cast()

template<typename T >
T glim::Config::param_cast ( const std::string &  module_name,
const std::string &  param_name 
) const

Get a parameter.

Note
If the parameter is not found, this method aborts the program
Parameters
module_nameModule name
param_nameParameter name
Returns
Returns the parameter value

◆ param_cast_nested()

template<typename T >
T glim::Config::param_cast_nested ( const std::vector< std::string > &  nested_module_names,
const std::string &  param_name 
) const

Get a parameter.

Note
If the parameter is not found, this method aborts the program
Parameters
nested_module_namesNested module names
param_nameParameter name
Returns
Returns the parameter value

◆ param_nested() [1/2]

template<typename T >
std::optional< T > glim::Config::param_nested ( const std::vector< std::string > &  nested_module_names,
const std::string &  param_name 
) const

Get a parameter from a nested module.

Parameters
nested_module_namesNested module names
param_nameParameter name
Returns
Parameter value if the param is found, otherwise nullopt

◆ param_nested() [2/2]

template<typename T >
T glim::Config::param_nested ( const std::vector< std::string > &  nested_module_names,
const std::string &  param_name,
const T &  default_value 
) const

Get a parameter from a nested module with default value.

Parameters
nested_module_namesNested module names
param_nameParameter name
default_valueDefault value
Returns
Parameter value if the param is found, otherwise the default value

◆ save()

void glim::Config::save ( const std::string &  path) const

Save config parameters as a JSON file.

Parameters
pathDestination path

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