Configuration
Configuration
#include <icy/configuration.h>Subclassed by:
Configuration
Configuration is an abstract base class for managing different kinds of configuration storage back ends such as JSON, XML, or database.
Subclasses must override the getRaw() and setRaw() and methods.
This class is safe for multithreaded use.
Public Attributes
| Return | Name | Description |
|---|---|---|
ThreadSignal< void(const std::string &, const std::string &)> | PropertyChanged | The Key and Value of the changed configuration property. |
PropertyChanged
ThreadSignal< void(const std::string &, const std::string &)> PropertyChangedThe Key and Value of the changed configuration property.
Public Methods
| Return | Name | Description |
|---|---|---|
Configuration | Creates the Configuration. | |
~Configuration virtual | Destroys the Configuration. | |
bool | exists const | Returns true if the property with the given key exists. |
std::string | getString const | Returns the string value of the property with the given name. Throws a NotFoundException if the key does not exist. |
std::string | getString const | If a property with the given key exists, returns the property's string value, otherwise returns the given default value. |
std::string | getRawString const | Returns the raw string value of the property with the given name. Throws a NotFoundException if the key does not exist. References to other properties are not expanded. |
std::string | getRawString const | If a property with the given key exists, returns the property's raw string value, otherwise returns the given default value. References to other properties are not expanded. |
int | getInt const | Returns the int value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal. |
int | getInt const | If a property with the given key exists, returns the property's int value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal. |
std::int64_t | getLargeInt const | Returns the int value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal. |
std::int64_t | getLargeInt const | If a property with the given key exists, returns the property's int value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal. |
double | getDouble const | Returns the double value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to a double. |
double | getDouble const | If a property with the given key exists, returns the property's double value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to an double. |
bool | getBool const | Returns the double value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to a double. |
bool | getBool const | If a property with the given key exists, returns the property's bool value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to a boolean. The following string values can be converted into a boolean: |
void | setString | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |
void | setInt | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |
void | setLargeInt | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |
void | setDouble | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |
void | setBool | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |
Configuration
Configuration()Creates the Configuration.
~Configuration
virtual
virtual ~Configuration()Destroys the Configuration.
exists
const
bool exists(const std::string & key) constReturns true if the property with the given key exists.
getString
const
std::string getString(const std::string & key) constReturns the string value of the property with the given name. Throws a NotFoundException if the key does not exist.
getString
const
std::string getString(const std::string & key, const std::string & defaultValue) constIf a property with the given key exists, returns the property's string value, otherwise returns the given default value.
getRawString
const
std::string getRawString(const std::string & key) constReturns the raw string value of the property with the given name. Throws a NotFoundException if the key does not exist. References to other properties are not expanded.
getRawString
const
std::string getRawString(const std::string & key, const std::string & defaultValue) constIf a property with the given key exists, returns the property's raw string value, otherwise returns the given default value. References to other properties are not expanded.
getInt
const
int getInt(const std::string & key) constReturns the int value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal.
getInt
const
int getInt(const std::string & key, int defaultValue) constIf a property with the given key exists, returns the property's int value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal.
getLargeInt
const
std::int64_t getLargeInt(const std::string & key) constReturns the int value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal.
getLargeInt
const
std::int64_t getLargeInt(const std::string & key, std::int64_t defaultValue) constIf a property with the given key exists, returns the property's int value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal.
getDouble
const
double getDouble(const std::string & key) constReturns the double value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to a double.
getDouble
const
double getDouble(const std::string & key, double defaultValue) constIf a property with the given key exists, returns the property's double value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to an double.
getBool
const
bool getBool(const std::string & key) constReturns the double value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to a double.
getBool
const
bool getBool(const std::string & key, bool defaultValue) constIf a property with the given key exists, returns the property's bool value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to a boolean. The following string values can be converted into a boolean:
numerical values: non zero becomes true, zero becomes false
strings: true, yes, on become true, false, no, off become false Case does not matter.
setString
void setString(const std::string & key, const std::string & value)Sets the property with the given key to the given value. An already existing value for the key is overwritten.
setInt
void setInt(const std::string & key, int value)Sets the property with the given key to the given value. An already existing value for the key is overwritten.
setLargeInt
void setLargeInt(const std::string & key, std::int64_t value)Sets the property with the given key to the given value. An already existing value for the key is overwritten.
setDouble
void setDouble(const std::string & key, double value)Sets the property with the given key to the given value. An already existing value for the key is overwritten.
setBool
void setBool(const std::string & key, bool value)Sets the property with the given key to the given value. An already existing value for the key is overwritten.
Protected Methods
| Return | Name | Description |
|---|---|---|
bool | getRaw const | If the property with the given key exists, stores the property's value in value and returns true. Otherwise, returns false. |
void | setRaw | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |
Configuration | Deleted constructor. | |
Configuration | Deleted constructor. |
getRaw
const
bool getRaw(const std::string & key, std::string & value) constIf the property with the given key exists, stores the property's value in value and returns true. Otherwise, returns false.
Must be overridden by subclasses.
setRaw
void setRaw(const std::string & key, const std::string & value)Sets the property with the given key to the given value. An already existing value for the key is overwritten.
The implementation is responsible for emitting the PropertyChanged signal.
Configuration
Configuration(const Configuration &) = deleteDeleted constructor.
Configuration
Configuration(Configuration &&) = deleteDeleted constructor.
Private Attributes
| Return | Name | Description |
|---|---|---|
std::mutex | _mutex |
_mutex
std::mutex _mutex