# ScopedConfiguration

<a id="scopedconfiguration"></a>

# ScopedConfiguration

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

class ScopedConfiguration
```

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

[ScopedConfiguration](#scopedconfiguration) provides multiple levels of configuration for a module. Multiple levels means that there is a module level scope, and a default scope. When a property is accessed, the module scope value will be used if available, otherwise the default scope value will be used.

Example scoping: Module: channels.[name].modes.[name].[value] Default: modes.[name].[value]

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`Configuration`](https://auscaster.com/icey/docs/api-reference/icy-Configuration.md#configuration) & | [`config`](#config)  |  |
| `std::string` | [`currentScope`](#currentscope)  |  |
| `std::string` | [`defaultScope`](#defaultscope)  |  |

---

<a id="config"></a>

### config

```cpp
Configuration & config
```

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

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

---

<a id="currentscope"></a>

### currentScope

```cpp
std::string currentScope
```

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

---

<a id="defaultscope"></a>

### defaultScope

```cpp
std::string defaultScope
```

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

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`ScopedConfiguration`](#scopedconfiguration-1)  |  |
|  | [`ScopedConfiguration`](#scopedconfiguration-2)  |  |
| `std::string` | [`getString`](#getstring-2) `const` | Returns the string value, trying `currentScope` first then `defaultScope`. |
| `int` | [`getInt`](#getint-2) `const` | Returns the int value, trying `currentScope` first then `defaultScope`. |
| `double` | [`getDouble`](#getdouble-2) `const` | Returns the double value, trying `currentScope` first then `defaultScope`. |
| `bool` | [`getBool`](#getbool-2) `const` | Returns the bool value, trying `currentScope` first then `defaultScope`. |
| `void` | [`setString`](#setstring-1)  | Writes a string value under the scoped key. |
| `void` | [`setInt`](#setint-1)  | Writes an int value under the scoped key. |
| `void` | [`setDouble`](#setdouble-1)  | Writes a double value under the scoped key. |
| `void` | [`setBool`](#setbool-1)  | Writes a bool value under the scoped key. |
| `std::string` | [`getCurrentScope`](#getcurrentscope) `const` |  |
| `std::string` | [`getDafaultKey`](#getdafaultkey) `const` |  |
| `std::string` | [`getScopedKey`](#getscopedkey) `const` |  |

---

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

### ScopedConfiguration

```cpp
ScopedConfiguration(Configuration & config, const std::string & currentScope, const std::string & defaultScope)
```

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

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `config` | [`Configuration`](https://auscaster.com/icey/docs/api-reference/icy-Configuration.md#configuration) & | Backing configuration store. |
| `currentScope` | `const std::string &` | Key prefix for the module-level scope. |
| `defaultScope` | `const std::string &` | Key prefix for the default/fallback scope. |

---

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

### ScopedConfiguration

```cpp
ScopedConfiguration(const ScopedConfiguration & that)
```

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

---

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

### getString

`const`

```cpp
std::string getString(const std::string & key, const std::string & defaultValue, bool forceDefaultScope = false) const
```

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

Returns the string value, trying `currentScope` first then `defaultScope`. 
#### Returns
Property value or `defaultValue`.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const std::string &` | Property key (without scope prefix). |
| `defaultValue` | `const std::string &` | Fallback when neither scope has the key. |
| `forceDefaultScope` | `bool` | If true, skips `currentScope` and reads from `defaultScope` only. |

---

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

### getInt

`const`

```cpp
int getInt(const std::string & key, int defaultValue, bool forceDefaultScope = false) const
```

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

Returns the int value, trying `currentScope` first then `defaultScope`. 
#### Returns
Property value or `defaultValue`.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const std::string &` | Property key (without scope prefix). |
| `defaultValue` | `int` | Fallback when neither scope has the key. |
| `forceDefaultScope` | `bool` | If true, reads from `defaultScope` only. |

---

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

### getDouble

`const`

```cpp
double getDouble(const std::string & key, double defaultValue, bool forceDefaultScope = false) const
```

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

Returns the double value, trying `currentScope` first then `defaultScope`. 
#### Returns
Property value or `defaultValue`.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const std::string &` | Property key (without scope prefix). |
| `defaultValue` | `double` | Fallback when neither scope has the key. |
| `forceDefaultScope` | `bool` | If true, reads from `defaultScope` only. |

---

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

### getBool

`const`

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

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

Returns the bool value, trying `currentScope` first then `defaultScope`. 
#### Returns
Property value or `defaultValue`.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const std::string &` | Property key (without scope prefix). |
| `defaultValue` | `bool` | Fallback when neither scope has the key. |
| `forceDefaultScope` | `bool` | If true, reads from `defaultScope` only. |

---

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

### setString

```cpp
void setString(const std::string & key, const std::string & value, bool defaultScope = false)
```

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

Writes a string value under the scoped key.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const std::string &` | Property key (without scope prefix). |
| `value` | `const std::string &` | Value to store. |
| `defaultScope` | `bool` | If true, writes to `defaultScope`; otherwise to `currentScope`. |

---

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

### setInt

```cpp
void setInt(const std::string & key, int value, bool defaultScope = false)
```

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

Writes an int value under the scoped key.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const std::string &` | Property key (without scope prefix). |
| `value` | `int` | Value to store. |
| `defaultScope` | `bool` | If true, writes to `defaultScope`; otherwise to `currentScope`. |

---

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

### setDouble

```cpp
void setDouble(const std::string & key, double value, bool defaultScope = false)
```

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

Writes a double value under the scoped key.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const std::string &` | Property key (without scope prefix). |
| `value` | `double` | Value to store. |
| `defaultScope` | `bool` | If true, writes to `defaultScope`; otherwise to `currentScope`. |

---

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

### setBool

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

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

Writes a bool value under the scoped key.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const std::string &` | Property key (without scope prefix). |
| `value` | `bool` | Value to store. |
| `defaultScope` | `bool` | If true, writes to `defaultScope`; otherwise to `currentScope`. |

---

<a id="getcurrentscope"></a>

### getCurrentScope

`const`

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

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

#### Returns
Fully qualified key in `currentScope`.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const std::string &` | Property key (without scope prefix). |

---

<a id="getdafaultkey"></a>

### getDafaultKey

`const`

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

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

#### Returns
Fully qualified key in `defaultScope`.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const std::string &` | Property key (without scope prefix). |

---

<a id="getscopedkey"></a>

### getScopedKey

`const`

```cpp
std::string getScopedKey(const std::string & key, bool defaultScope = false) const
```

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

#### Returns
Fully qualified scoped key string.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const std::string &` | Property key (without scope prefix). |
| `defaultScope` | `bool` | If true, returns the `defaultScope` key; otherwise `currentScope` key. |

## Private Methods

| Return | Name | Description |
|--------|------|-------------|
| [`ScopedConfiguration`](#scopedconfiguration) & | [`operator=`](#operator-83)  |  |

---

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

### operator=

```cpp
ScopedConfiguration & operator=(const ScopedConfiguration &)
```

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