/* * Copyright (c) 2023 Fancy Code. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file ConfigBaseImpl.h * @brief Provides an implementation of the IConfigBase interface using libconfig. * * This header file declares the ConfigBaseImpl class which implements the configuration * interface defined by IConfigBase. It uses the libconfig library to handle the * configuration file parsing and saving. */ #ifndef CONFIG_BASE_IMPL_H #define CONFIG_BASE_IMPL_H #include "IConfigBase.h" #include #include /** * @class ConfigBaseImpl * @brief Concrete implementation of the IConfigBase interface. * * ConfigBaseImpl is a class that provides an implementation of the IConfigBase interface. * It uses the libconfig library to manage configuration files and settings. */ class ConfigBaseImpl : public IConfigBase { public: ConfigBaseImpl(const std::string &fileName); virtual ~ConfigBaseImpl() = default; /** * @brief Opens the configuration file for reading and writing. * * @return true if the file was successfully opened, false otherwise. */ bool OpenConfigFile(void) override; /** * @brief Closes the configuration file. */ void CloseConfigFile(void) override; /** * @brief Saves the current configuration to the file. * * This function writes the current in-memory configuration settings to the file * specified during the construction of the ConfigBaseImpl object. It uses the libconfig * library to perform the save operation. * * @return A StatusCode indicating the success or failure of the operation. */ StatusCode ConfigSaveFile(void) override; /** * @brief Retrieves an integer configuration value. * * This function gets the integer value associated with the specified configuration * parameter name. * * @param name The name of the configuration parameter to retrieve. * @param value A pointer to store the retrieved integer value. * @return A StatusCode indicating the success or failure of the operation. */ StatusCode ConfigGetInt(const char *name, int *value) override; /** * @brief Sets an integer configuration value. * * This function sets the integer value for the specified configuration parameter name. * * @param name The name of the configuration parameter to set. * @param value The integer value to set. * @return A StatusCode indicating the success or failure of the operation. */ StatusCode ConfigSetInt(const char *name, const int value) override; /** * @brief Retrieves a long long integer configuration value. * * @param name The name of the configuration parameter to retrieve. * @param value A pointer to store the retrieved long long integer value. * @return A StatusCode for the operation. */ StatusCode ConfigGetShort(const char *name, short *value) override; /** * @brief Sets a long long integer configuration value. * * @param name The name of the configuration parameter to set. * @param value The long long integer value to set. * @return A StatusCode for the operation. */ StatusCode ConfigSetShort(const char *name, const short value) override; /** * @brief Retrieves a long integer configuration value. * * @param name The name of the configuration setting to retrieve. * @param value A pointer to a long integer where the retrieved value will be stored. * @return StatusCode::SUCCESS if the operation was successful, an error code otherwise. */ StatusCode ConfigGetLong(const char *name, long *value) override; /** * @brief Sets a long integer configuration value. * * @param name The name of the configuration setting to set. * @param value The long integer value to set for the configuration setting. * @return StatusCode::SUCCESS if the operation was successful, an error code otherwise. */ StatusCode ConfigSetLong(const char *name, const long value) override; /** * @brief Retrieves a long long integer configuration value. * * @param name The name of the configuration parameter to retrieve. * @param value A pointer to store the retrieved long long integer value. * @return A StatusCode for the operation. */ StatusCode ConfigGetLLong(const char *name, long long *value) override; /** * @brief Sets a long long integer configuration value. * * @param name The name of the configuration parameter to set. * @param value The long long integer value to set. * @return A StatusCode for the operation. */ StatusCode ConfigSetLLong(const char *name, const long long value) override; /** * @brief Retrieves a character configuration value. * * @param name The name of the configuration parameter to retrieve. * @param value A pointer to store the retrieved character value. * @return A StatusCode for the operation. */ StatusCode ConfigGetChar(const char *name, char *value) override; /** * @brief Sets a character configuration value. * * @param name The name of the configuration parameter to set. * @param value The character value to set. * @return A StatusCode for the operation. */ StatusCode ConfigSetChar(const char *name, const char value) override; /** * @brief Retrieves a boolean configuration value. * * @param name The name of the configuration setting to retrieve. * @param value A pointer to a bool where the retrieved value will be stored. * @return StatusCode::SUCCESS if the operation was successful, an error code otherwise. */ StatusCode ConfigGetBool(const char *name, bool *value) override; /** * @brief Sets a boolean configuration value. * * @param name The name of the configuration setting to set. * @param value The boolean value to set for the configuration setting. * @return StatusCode::SUCCESS if the operation was successful, an error code otherwise. */ StatusCode ConfigSetBool(const char *name, const bool value) override; /** * @brief Retrieves a floating-point configuration value. * * @param name The name of the configuration setting to retrieve. * @param value A pointer to a float where the retrieved value will be stored. * @return StatusCode::SUCCESS if the operation was successful, an error code otherwise. */ StatusCode ConfigGetFloat(const char *name, float *value) override; /** * @brief Sets a floating-point configuration value. * * @param name The name of the configuration setting to set. * @param value The float value to set for the configuration setting. * @return StatusCode::SUCCESS if the operation was successful, an error code otherwise. */ StatusCode ConfigSetFloat(const char *name, const float value) override; /** * @brief Retrieves a double-precision floating-point configuration value. * * @param name The name of the configuration setting to retrieve. * @param value A pointer to a double where the retrieved value will be stored. * @return StatusCode::SUCCESS if the operation was successful, an error code otherwise. */ StatusCode ConfigGetDouble(const char *name, double *value) override; /** * @brief Sets a double-precision floating-point configuration value. * * @param name The name of the configuration setting to set. * @param value The double value to set for the configuration setting. * @return StatusCode::SUCCESS if the operation was successful, an error code otherwise. */ StatusCode ConfigSetDouble(const char *name, const double value) override; /** * @brief Retrieves a string configuration value. * * This function gets the string value associated with the specified configuration * parameter name. The returned string is managed by the libconfig library and should * not be freed by the caller. * * @param name The name of the configuration parameter to retrieve. * @param value A pointer to store the retrieved string value. * @return A StatusCode indicating the success or failure of the operation. */ StatusCode ConfigGetString(const char *name, const char **value) override; /** * @brief Retrieves a string configuration value. * * This function gets the string value associated with the specified configuration * parameter name. The returned string is managed by the libconfig library and should * not be freed by the caller. * * @param name The name of the configuration parameter to retrieve. * @param value A pointer to store the retrieved string value. * @return A StatusCode indicating the success or failure of the operation. */ StatusCode ConfigSetString(const char *name, const char *value) override; private: /** * @brief The file name of the configuration file managed by this instance. */ const std::string mFileName; /** * @brief The libconfig structure used to hold the configuration settings. */ config_t mCfg; }; #endif