Manages configuration settings stored in a JSON file.
More...
#include <ConfigManager.hpp>
|
| | ConfigManager (const std::string &configFile="config.json") |
| | Constructs a ConfigManager object.
|
| |
| | ~ConfigManager () |
| | Destructs the ConfigManager object.
|
| |
| bool | loadConfig () |
| | Loads the configuration from the JSON file.
|
| |
| std::string | getString (const std::string &key, const std::string &defaultValue="") |
| | Retrieves a string value from the configuration.
|
| |
| int | getInt (const std::string &key, int defaultValue=0) |
| | Retrieves an integer value from the configuration.
|
| |
| bool | getBool (const std::string &key, bool defaultValue=false) |
| | Retrieves a boolean value from the configuration.
|
| |
| std::string | getNestedString (const std::string &path, const std::string &defaultValue="") |
| | Retrieves a nested string value from the configuration.
|
| |
| int | getNestedInt (const std::string &path, int defaultValue=0) |
| | Retrieves a nested integer value from the configuration.
|
| |
| bool | getNestedBool (const std::string &path, bool defaultValue=false) |
| | Retrieves a nested boolean value from the configuration.
|
| |
| bool | saveConfig () |
| | Saves the current configuration to the JSON file.
|
| |
| void | setString (const std::string &key, const std::string &value) |
| | Sets a string value in the configuration.
|
| |
| void | setInt (const std::string &key, int value) |
| | Sets an integer value in the configuration.
|
| |
| void | setBool (const std::string &key, bool value) |
| | Sets a boolean value in the configuration.
|
| |
|
| cJSON * | getNestedItem (const std::string &path) |
| | Retrieves a nested JSON item from the configuration.
|
| |
| void | cleanupJSON () |
| | Cleans up the JSON object.
|
| |
|
| std::string | configFilePath |
| | The path to the configuration file.
|
| |
| cJSON * | root |
| | The root JSON object representing the configuration.
|
| |
Manages configuration settings stored in a JSON file.
◆ ConfigManager()
| ConfigManager::ConfigManager |
( |
const std::string & |
configFile = "config.json" | ) |
|
Constructs a ConfigManager object.
- Parameters
-
| configFile | The path to the configuration file. Defaults to "config.json". |
◆ ~ConfigManager()
| ConfigManager::~ConfigManager |
( |
| ) |
|
◆ cleanupJSON()
| void ConfigManager::cleanupJSON |
( |
| ) |
|
|
private |
Cleans up the JSON object.
◆ getBool()
| bool ConfigManager::getBool |
( |
const std::string & |
key, |
|
|
bool |
defaultValue = false |
|
) |
| |
Retrieves a boolean value from the configuration.
- Parameters
-
| key | The key of the configuration setting. |
| defaultValue | The default value to return if the key is not found. Defaults to false. |
- Returns
- The boolean value associated with the key, or the default value if the key is not found.
◆ getInt()
| int ConfigManager::getInt |
( |
const std::string & |
key, |
|
|
int |
defaultValue = 0 |
|
) |
| |
Retrieves an integer value from the configuration.
- Parameters
-
| key | The key of the configuration setting. |
| defaultValue | The default value to return if the key is not found. Defaults to 0. |
- Returns
- The integer value associated with the key, or the default value if the key is not found.
◆ getNestedBool()
| bool ConfigManager::getNestedBool |
( |
const std::string & |
path, |
|
|
bool |
defaultValue = false |
|
) |
| |
Retrieves a nested boolean value from the configuration.
- Parameters
-
| path | The path to the nested configuration setting. |
| defaultValue | The default value to return if the path is not found. Defaults to false. |
- Returns
- The boolean value associated with the path, or the default value if the path is not found.
◆ getNestedInt()
| int ConfigManager::getNestedInt |
( |
const std::string & |
path, |
|
|
int |
defaultValue = 0 |
|
) |
| |
Retrieves a nested integer value from the configuration.
- Parameters
-
| path | The path to the nested configuration setting. |
| defaultValue | The default value to return if the path is not found. Defaults to 0. |
- Returns
- The integer value associated with the path, or the default value if the path is not found.
◆ getNestedItem()
| cJSON * ConfigManager::getNestedItem |
( |
const std::string & |
path | ) |
|
|
private |
Retrieves a nested JSON item from the configuration.
- Parameters
-
| path | The path to the nested JSON item. |
- Returns
- A pointer to the nested JSON item, or nullptr if the item is not found.
◆ getNestedString()
| std::string ConfigManager::getNestedString |
( |
const std::string & |
path, |
|
|
const std::string & |
defaultValue = "" |
|
) |
| |
Retrieves a nested string value from the configuration.
- Parameters
-
| path | The path to the nested configuration setting. |
| defaultValue | The default value to return if the path is not found. Defaults to an empty string. |
- Returns
- The string value associated with the path, or the default value if the path is not found.
◆ getString()
| std::string ConfigManager::getString |
( |
const std::string & |
key, |
|
|
const std::string & |
defaultValue = "" |
|
) |
| |
Retrieves a string value from the configuration.
- Parameters
-
| key | The key of the configuration setting. |
| defaultValue | The default value to return if the key is not found. Defaults to an empty string. |
- Returns
- The string value associated with the key, or the default value if the key is not found.
◆ loadConfig()
| bool ConfigManager::loadConfig |
( |
| ) |
|
Loads the configuration from the JSON file.
- Returns
- True if the configuration was successfully loaded, false otherwise.
◆ saveConfig()
| bool ConfigManager::saveConfig |
( |
| ) |
|
Saves the current configuration to the JSON file.
- Returns
- True if the configuration was successfully saved, false otherwise.
◆ setBool()
| void ConfigManager::setBool |
( |
const std::string & |
key, |
|
|
bool |
value |
|
) |
| |
Sets a boolean value in the configuration.
- Parameters
-
| key | The key of the configuration setting. |
| value | The boolean value to set. |
◆ setInt()
| void ConfigManager::setInt |
( |
const std::string & |
key, |
|
|
int |
value |
|
) |
| |
Sets an integer value in the configuration.
- Parameters
-
| key | The key of the configuration setting. |
| value | The integer value to set. |
◆ setString()
| void ConfigManager::setString |
( |
const std::string & |
key, |
|
|
const std::string & |
value |
|
) |
| |
Sets a string value in the configuration.
- Parameters
-
| key | The key of the configuration setting. |
| value | The string value to set. |
◆ configFilePath
| std::string ConfigManager::configFilePath |
|
private |
The path to the configuration file.
◆ root
| cJSON* ConfigManager::root |
|
private |
The root JSON object representing the configuration.
The documentation for this class was generated from the following files: