Configuration class to store and retrieve configuration values.
More...
#include <Config.hpp>
|
| Config (const std::map< std::string, std::any > &config={}) |
| Config (const std::string &jsonString) |
std::map< std::string, std::any > | getValue () const |
bool | hasKey (const std::string &key) const |
std::any | getAny (const std::string &key) const |
template<typename T> |
T | get (const std::string &key) const |
void | set (const std::string &key, const std::any &value) |
|
template<typename T> |
static T | convert (const std::any &value) |
template<typename T> |
static T | get (const std::map< std::string, std::any > &config, const std::string &key, std::optional< T > defaultValue=std::nullopt) |
static std::optional< std::string > | findString (const std::map< std::string, std::any > &config, const std::string &preferredKey) |
| Finds a string in the configuration map.
|
static std::map< std::string, std::any > | jsonToMap (const std::string &jsonString) |
static std::string | mapToJson (const std::map< std::string, std::any > &config) |
Configuration class to store and retrieve configuration values.
◆ Config() [1/2]
switchboard::Config::Config |
( |
const std::map< std::string, std::any > & | config = {} | ) |
|
Constructor.
- Parameters
-
config | The configuration map. |
◆ Config() [2/2]
switchboard::Config::Config |
( |
const std::string & | jsonString | ) |
|
Constructor.
- Parameters
-
jsonString | The JSON string. |
◆ convert()
template<typename T>
T switchboard::Config::convert |
( |
const std::any & | value | ) |
|
|
static |
Converts an any value to a specific type.
- Template Parameters
-
- Parameters
-
- Returns
- The converted value.
◆ findString()
std::optional< std::string > switchboard::Config::findString |
( |
const std::map< std::string, std::any > & | config, |
|
|
const std::string & | preferredKey ) |
|
static |
Finds a string in the configuration map.
If the preferred key is found, the value is returned. Otherwise, the first string value is returned.
- Parameters
-
config | The configuration map. |
preferredKey | The preferred key for the string value. |
- Returns
- The string value if found, otherwise std::nullopt.
◆ get() [1/2]
template<typename T>
T switchboard::Config::get |
( |
const std::map< std::string, std::any > & | config, |
|
|
const std::string & | key, |
|
|
std::optional< T > | defaultValue = std::nullopt ) |
|
static |
Gets a value from the configuration map with an optional default value.
- Template Parameters
-
- Parameters
-
config | The configuration map. |
key | The key. |
defaultValue | The default value if the key is not found. |
- Returns
- The value if found, otherwise the default value.
◆ get() [2/2]
template<typename T>
T switchboard::Config::get |
( |
const std::string & | key | ) |
const |
|
nodiscard |
Gets a value from the configuration map.
- Template Parameters
-
- Parameters
-
- Returns
- The value.
◆ getAny()
std::any switchboard::Config::getAny |
( |
const std::string & | key | ) |
const |
|
nodiscard |
Gets a value from the configuration map.
- Parameters
-
- Returns
- The value as std::any.
◆ getValue()
std::map< std::string, std::any > switchboard::Config::getValue |
( |
| ) |
const |
|
nodiscard |
Gets the configuration map.
- Returns
- The configuration map.
◆ hasKey()
bool switchboard::Config::hasKey |
( |
const std::string & | key | ) |
const |
|
nodiscard |
Checks if a key exists in the configuration map.
- Parameters
-
- Returns
- True if the key exists, false otherwise.
◆ jsonToMap()
std::map< std::string, std::any > switchboard::Config::jsonToMap |
( |
const std::string & | jsonString | ) |
|
|
static |
Converts a JSON string to a map.
- Parameters
-
jsonString | The JSON string. |
- Returns
- The map.
◆ mapToJson()
std::string switchboard::Config::mapToJson |
( |
const std::map< std::string, std::any > & | config | ) |
|
|
static |
Converts a map to a JSON string.
- Parameters
-
config | The configuration map. |
- Returns
- The JSON string.
◆ set()
void switchboard::Config::set |
( |
const std::string & | key, |
|
|
const std::any & | value ) |
Sets a value in the configuration map.
- Parameters
-
key | The key. |
value | The value as std::any. |
The documentation for this class was generated from the following file: