LoRaWANCH341 Library
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ConfigManager Class Reference

Manages configuration settings stored in a JSON file. More...

#include <ConfigManager.hpp>

Collaboration diagram for ConfigManager:
Collaboration graph

Public Member Functions

 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.
 

Private Member Functions

cJSON * getNestedItem (const std::string &path)
 Retrieves a nested JSON item from the configuration.
 
void cleanupJSON ()
 Cleans up the JSON object.
 

Private Attributes

std::string configFilePath
 The path to the configuration file.
 
cJSON * root
 The root JSON object representing the configuration.
 

Detailed Description

Manages configuration settings stored in a JSON file.

Constructor & Destructor Documentation

◆ ConfigManager()

ConfigManager::ConfigManager ( const std::string &  configFile = "config.json")

Constructs a ConfigManager object.

Parameters
configFileThe path to the configuration file. Defaults to "config.json".
Here is the call graph for this function:

◆ ~ConfigManager()

ConfigManager::~ConfigManager ( )

Destructs the ConfigManager object.

Here is the call graph for this function:

Member Function Documentation

◆ cleanupJSON()

void ConfigManager::cleanupJSON ( )
private

Cleans up the JSON object.

Here is the caller graph for this function:

◆ getBool()

bool ConfigManager::getBool ( const std::string &  key,
bool  defaultValue = false 
)

Retrieves a boolean value from the configuration.

Parameters
keyThe key of the configuration setting.
defaultValueThe 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
keyThe key of the configuration setting.
defaultValueThe 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
pathThe path to the nested configuration setting.
defaultValueThe 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNestedInt()

int ConfigManager::getNestedInt ( const std::string &  path,
int  defaultValue = 0 
)

Retrieves a nested integer value from the configuration.

Parameters
pathThe path to the nested configuration setting.
defaultValueThe 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNestedItem()

cJSON * ConfigManager::getNestedItem ( const std::string &  path)
private

Retrieves a nested JSON item from the configuration.

Parameters
pathThe path to the nested JSON item.
Returns
A pointer to the nested JSON item, or nullptr if the item is not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNestedString()

std::string ConfigManager::getNestedString ( const std::string &  path,
const std::string &  defaultValue = "" 
)

Retrieves a nested string value from the configuration.

Parameters
pathThe path to the nested configuration setting.
defaultValueThe 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getString()

std::string ConfigManager::getString ( const std::string &  key,
const std::string &  defaultValue = "" 
)

Retrieves a string value from the configuration.

Parameters
keyThe key of the configuration setting.
defaultValueThe 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
keyThe key of the configuration setting.
valueThe boolean value to set.

◆ setInt()

void ConfigManager::setInt ( const std::string &  key,
int  value 
)

Sets an integer value in the configuration.

Parameters
keyThe key of the configuration setting.
valueThe integer value to set.

◆ setString()

void ConfigManager::setString ( const std::string &  key,
const std::string &  value 
)

Sets a string value in the configuration.

Parameters
keyThe key of the configuration setting.
valueThe string value to set.

Member Data Documentation

◆ 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: