# Configuration

<a id="configuration"></a>

# Configuration

```cpp
#include <icy/configuration.h>

class Configuration
```

[Defined in src/base/include/icy/configuration.h:31](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L31)

> **Subclassed by:** [`Configuration`](https://auscaster.com/icey/docs/api-reference/icy-json-Configuration.md#configuration-5)

[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()](#getraw) and [setRaw()](#setraw) and methods.

This class is safe for multithreaded use.

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`ThreadSignal`](https://auscaster.com/icey/docs/api-reference/base.md#threadsignal)< void(const std::string &, const std::string &)> | [`PropertyChanged`](#propertychanged)  | The Key and Value of the changed configuration property. |

---

<a id="propertychanged"></a>

### PropertyChanged

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

Type: [`ThreadSignal`](https://auscaster.com/icey/docs/api-reference/base.md#threadsignal)< void(const std::string &, const std::string &)>

[Defined in src/base/include/icy/configuration.h:138](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L138)

The Key and Value of the changed configuration property.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Configuration`](#configuration-1)  | Creates the [Configuration](#configuration). |
|  | [`~Configuration`](#configuration-2) `virtual` | Destroys the [Configuration](#configuration). |
| `bool` | [`exists`](#exists) `const` | Returns true if the property with the given key exists. |
| `std::string` | [`getString`](#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`](#getstring-1) `const` | If a property with the given key exists, returns the property's string value, otherwise returns the given default value. |
| `std::string` | [`getRawString`](#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`](#getrawstring-1) `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`](#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`](#getint-1) `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`](#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`](#getlargeint-1) `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`](#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`](#getdouble-1) `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`](#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`](#getbool-1) `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`](#setstring)  | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |
| `void` | [`setInt`](#setint)  | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |
| `void` | [`setLargeInt`](#setlargeint)  | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |
| `void` | [`setDouble`](#setdouble)  | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |
| `void` | [`setBool`](#setbool)  | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |

---

<a id="configuration-1"></a>

### Configuration

```cpp
Configuration()
```

[Defined in src/base/include/icy/configuration.h:35](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L35)

Creates the [Configuration](#configuration).

---

<a id="configuration-2"></a>

### ~Configuration

`virtual`

```cpp
virtual ~Configuration()
```

[Defined in src/base/include/icy/configuration.h:38](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L38)

Destroys the [Configuration](#configuration).

#### Reimplemented by

- [`Configuration::~Configuration`](https://auscaster.com/icey/docs/api-reference/icy-json-Configuration.md#configuration-7)

---

<a id="exists"></a>

### exists

`const`

```cpp
bool exists(const std::string & key) const
```

[Defined in src/base/include/icy/configuration.h:41](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L41)

Returns true if the property with the given key exists.

---

<a id="getstring"></a>

### getString

`const`

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

[Defined in src/base/include/icy/configuration.h:45](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L45)

Returns the string value of the property with the given name. Throws a NotFoundException if the key does not exist.

---

<a id="getstring-1"></a>

### getString

`const`

```cpp
std::string getString(const std::string & key, const std::string & defaultValue) const
```

[Defined in src/base/include/icy/configuration.h:49](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L49)

If a property with the given key exists, returns the property's string value, otherwise returns the given default value.

---

<a id="getrawstring"></a>

### getRawString

`const`

```cpp
std::string getRawString(const std::string & key) const
```

[Defined in src/base/include/icy/configuration.h:54](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L54)

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.

---

<a id="getrawstring-1"></a>

### getRawString

`const`

```cpp
std::string getRawString(const std::string & key, const std::string & defaultValue) const
```

[Defined in src/base/include/icy/configuration.h:59](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L59)

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.

---

<a id="getint"></a>

### getInt

`const`

```cpp
int getInt(const std::string & key) const
```

[Defined in src/base/include/icy/configuration.h:66](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L66)

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.

---

<a id="getint-1"></a>

### getInt

`const`

```cpp
int getInt(const std::string & key, int defaultValue) const
```

[Defined in src/base/include/icy/configuration.h:73](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L73)

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.

---

<a id="getlargeint"></a>

### getLargeInt

`const`

```cpp
std::int64_t getLargeInt(const std::string & key) const
```

[Defined in src/base/include/icy/configuration.h:80](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L80)

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.

---

<a id="getlargeint-1"></a>

### getLargeInt

`const`

```cpp
std::int64_t getLargeInt(const std::string & key, std::int64_t defaultValue) const
```

[Defined in src/base/include/icy/configuration.h:88](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L88)

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.

---

<a id="getdouble"></a>

### getDouble

`const`

```cpp
double getDouble(const std::string & key) const
```

[Defined in src/base/include/icy/configuration.h:94](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L94)

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.

---

<a id="getdouble-1"></a>

### getDouble

`const`

```cpp
double getDouble(const std::string & key, double defaultValue) const
```

[Defined in src/base/include/icy/configuration.h:100](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L100)

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.

---

<a id="getbool"></a>

### getBool

`const`

```cpp
bool getBool(const std::string & key) const
```

[Defined in src/base/include/icy/configuration.h:106](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L106)

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.

---

<a id="getbool-1"></a>

### getBool

`const`

```cpp
bool getBool(const std::string & key, bool defaultValue) const
```

[Defined in src/base/include/icy/configuration.h:115](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L115)

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.

---

<a id="setstring"></a>

### setString

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

[Defined in src/base/include/icy/configuration.h:119](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L119)

Sets the property with the given key to the given value. An already existing value for the key is overwritten.

---

<a id="setint"></a>

### setInt

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

[Defined in src/base/include/icy/configuration.h:123](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L123)

Sets the property with the given key to the given value. An already existing value for the key is overwritten.

---

<a id="setlargeint"></a>

### setLargeInt

```cpp
void setLargeInt(const std::string & key, std::int64_t value)
```

[Defined in src/base/include/icy/configuration.h:127](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L127)

Sets the property with the given key to the given value. An already existing value for the key is overwritten.

---

<a id="setdouble"></a>

### setDouble

```cpp
void setDouble(const std::string & key, double value)
```

[Defined in src/base/include/icy/configuration.h:131](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L131)

Sets the property with the given key to the given value. An already existing value for the key is overwritten.

---

<a id="setbool"></a>

### setBool

```cpp
void setBool(const std::string & key, bool value)
```

[Defined in src/base/include/icy/configuration.h:135](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L135)

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`](#getraw) `virtual` `const` | If the property with the given key exists, stores the property's value in value and returns true. Otherwise, returns false. |
| `void` | [`setRaw`](#setraw) `virtual` | Sets the property with the given key to the given value. An already existing value for the key is overwritten. |
|  | [`Configuration`](#configuration-3)  | Deleted constructor. |
| [`Configuration`](#configuration) & | [`operator=`](#operator-9)  | Deleted assignment operator. |
|  | [`Configuration`](#configuration-4)  | Deleted constructor. |
| [`Configuration`](#configuration) & | [`operator=`](#operator-10)  | Deleted assignment operator. |

---

<a id="getraw"></a>

### getRaw

`virtual` `const`

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

[Defined in src/base/include/icy/configuration.h:145](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L145)

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.

#### Reimplemented by

- [`Configuration::getRaw`](https://auscaster.com/icey/docs/api-reference/icy-json-Configuration.md#getraw-1)

---

<a id="setraw"></a>

### setRaw

`virtual`

```cpp
virtual void setRaw(const std::string & key, const std::string & value)
```

[Defined in src/base/include/icy/configuration.h:151](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L151)

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.

#### Reimplemented by

- [`Configuration::setRaw`](https://auscaster.com/icey/docs/api-reference/icy-json-Configuration.md#setraw-1)

---

<a id="configuration-3"></a>

### Configuration

```cpp
Configuration(const Configuration &) = delete
```

[Defined in src/base/include/icy/configuration.h:170](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L170)

Deleted constructor.

---

<a id="operator-9"></a>

### operator=

```cpp
Configuration & operator=(const Configuration &) = delete
```

[Defined in src/base/include/icy/configuration.h:171](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L171)

Deleted assignment operator.

---

<a id="configuration-4"></a>

### Configuration

```cpp
Configuration(Configuration &&) = delete
```

[Defined in src/base/include/icy/configuration.h:172](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L172)

Deleted constructor.

---

<a id="operator-10"></a>

### operator=

```cpp
Configuration & operator=(Configuration &&) = delete
```

[Defined in src/base/include/icy/configuration.h:173](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L173)

Deleted assignment operator.

## Private Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::mutex` | [`_mutex`](#_mutex-1)  |  |

---

<a id="_mutex-1"></a>

### _mutex

```cpp
std::mutex _mutex
```

[Defined in src/base/include/icy/configuration.h:176](https://github.com/auscaster/icey/blob/main/src/base/include/icy/configuration.h#L176)
