Base module

Configuration

[Configuration]({#ref classicy_1_1Configuration #}) is an abstract base class for managing different kinds of configuration storage back ends such as JSON, XML, or database.

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

ReturnNameDescription
ThreadSignal< void(const std::string &, const std::string &)>PropertyChangedThe Key and Value of the changed configuration property.

PropertyChanged

ThreadSignal< void(const std::string &, const std::string &)> PropertyChanged

The Key and Value of the changed configuration property.

Public Methods

ReturnNameDescription
ConfigurationCreates the Configuration.
~Configuration virtualDestroys the Configuration.
boolexists constReturns true if the property with the given key exists.
std::stringgetString constReturns the string value of the property with the given name. Throws a NotFoundException if the key does not exist.
std::stringgetString constIf a property with the given key exists, returns the property's string value, otherwise returns the given default value.
std::stringgetRawString 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.
std::stringgetRawString 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.
intgetInt 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.
intgetInt 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.
std::int64_tgetLargeInt 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.
std::int64_tgetLargeInt 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.
doublegetDouble 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.
doublegetDouble 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.
boolgetBool 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.
boolgetBool 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:
voidsetStringSets the property with the given key to the given value. An already existing value for the key is overwritten.
voidsetIntSets the property with the given key to the given value. An already existing value for the key is overwritten.
voidsetLargeIntSets the property with the given key to the given value. An already existing value for the key is overwritten.
voidsetDoubleSets the property with the given key to the given value. An already existing value for the key is overwritten.
voidsetBoolSets 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) const

Returns true if the property with the given key exists.


getString

const

std::string getString(const std::string & key) const

Returns 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) const

If 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) 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.


getRawString

const

std::string getRawString(const std::string & key, const std::string & defaultValue) 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.


getInt

const

int getInt(const std::string & key) 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.


getInt

const

int getInt(const std::string & key, int defaultValue) 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.


getLargeInt

const

std::int64_t getLargeInt(const std::string & key) 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.


getLargeInt

const

std::int64_t getLargeInt(const std::string & key, std::int64_t defaultValue) 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.


getDouble

const

double getDouble(const std::string & key) 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.


getDouble

const

double getDouble(const std::string & key, double defaultValue) 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.


getBool

const

bool getBool(const std::string & key) 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.


getBool

const

bool getBool(const std::string & key, bool defaultValue) 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:

  • 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

ReturnNameDescription
boolgetRaw constIf the property with the given key exists, stores the property's value in value and returns true. Otherwise, returns false.
voidsetRawSets the property with the given key to the given value. An already existing value for the key is overwritten.
ConfigurationDeleted constructor.
ConfigurationDeleted constructor.

getRaw

const

bool getRaw(const std::string & key, std::string & value) const

If 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 &) = delete

Deleted constructor.


Configuration

Configuration(Configuration &&) = delete

Deleted constructor.

Private Attributes

ReturnNameDescription
std::mutex_mutex

_mutex

std::mutex _mutex