# KeyedStore

<a id="keyedstore"></a>

# KeyedStore

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

template<classTKey, classTValue>
class KeyedStore
```

[Defined in src/base/include/icy/collection.h:37](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L37)

> **Subclassed by:** [`TimedManager< TKey, TValue >`](https://auscaster.com/icey/docs/api-reference/icy-TimedManager.md#timedmanager)

A keyed store of unique_ptr values with optional lifecycle hooks. Not thread-safe; designed for single-threaded event loop contexts.

Subclasses can override onAdd/onRemove for lifecycle reactions, and add [Signal](https://auscaster.com/icey/docs/api-reference/icy-Signal.md#signal) members for external observers.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`KeyedStore`](#keyedstore-1)  | Defaulted constructor. |
|  | [`~KeyedStore`](#keyedstore-2) `virtual` `inline` |  |
|  | [`KeyedStore`](#keyedstore-3)  | Deleted constructor. |
| [`KeyedStore`](#keyedstore) & | [`operator=`](#operator-43)  | Deleted assignment operator. |
|  | [`KeyedStore`](#keyedstore-4)  | Defaulted constructor. |
| [`KeyedStore`](#keyedstore) & | [`operator=`](#operator-44)  | Defaulted assignment operator. |
| [`TValue`](#map) * | [`get`](#get-3) `const` `inline` | Returns the item for `key`, or nullptr if not found. |
| [`TValue`](#map) & | [`add`](#add-1) `inline` | Inserts a uniquely owned item. Returns a reference to the stored item. |
| [`bool`](#map) | [`tryAdd`](#tryadd) `inline` | Inserts if absent; returns false on duplicate (never throws). |
| [`TValue`](#map) & | [`put`](#put-3) `inline` | Inserts or replaces the item under `key`. |
| [`bool`](#map) | [`erase`](#erase) `inline` | Removes and destroys the item under `key`. |
| [`bool`](#map) | [`contains`](#contains) `const` `inline` |  |
| [`bool`](#map) | [`empty`](#empty) `const` `inline` |  |
| [`size_t`](#map) | [`size`](#size-2) `const` `inline` |  |
| [`void`](#map) | [`clear`](#clear-1) `inline` |  |
| [`Map`](#map-2) & | [`map`](#map) `inline` | Direct map access for iteration. |
| const [`Map`](#map-2) & | [`map`](#map-1) `const` `inline` |  |
| [`auto`](#map) | [`begin`](#begin-3) `inline` |  |
| [`auto`](#map) | [`end`](#end) `inline` |  |
| [`auto`](#map) | [`begin`](#begin-4) `const` `inline` |  |
| [`auto`](#map) | [`end`](#end-1) `const` `inline` |  |

---

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

### KeyedStore

```cpp
KeyedStore() = default
```

[Defined in src/base/include/icy/collection.h:42](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L42)

Defaulted constructor.

---

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

### ~KeyedStore

`virtual` `inline`

```cpp
virtual inline ~KeyedStore()
```

[Defined in src/base/include/icy/collection.h:43](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L43)

---

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

### KeyedStore

```cpp
KeyedStore(constKeyedStore &) = delete
```

[Defined in src/base/include/icy/collection.h:46](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L46)

Deleted constructor.

---

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

### operator=

```cpp
KeyedStore & operator=(constKeyedStore &) = delete
```

[Defined in src/base/include/icy/collection.h:47](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L47)

Deleted assignment operator.

---

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

### KeyedStore

```cpp
KeyedStore(KeyedStore &&) = default
```

[Defined in src/base/include/icy/collection.h:48](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L48)

Defaulted constructor.

---

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

### operator=

```cpp
KeyedStore & operator=(KeyedStore &&) = default
```

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

Defaulted assignment operator.

---

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

### get

`const` `inline`

```cpp
inline TValue * get(constTKey & key) const
```

[Defined in src/base/include/icy/collection.h:52](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L52)

Returns the item for `key`, or nullptr if not found.

---

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

### add

`inline`

```cpp
inline TValue & add(constTKey & key, std::unique_ptr< TValue > item)
```

[Defined in src/base/include/icy/collection.h:60](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L60)

Inserts a uniquely owned item. Returns a reference to the stored item.

#### Exceptions

| Exception | Description |
|-----------|-------------|
| `std::runtime_error` | if the key already exists. |

---

<a id="tryadd"></a>

### tryAdd

`inline`

```cpp
inline bool tryAdd(constTKey & key, std::unique_ptr< TValue > item)
```

[Defined in src/base/include/icy/collection.h:71](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L71)

Inserts if absent; returns false on duplicate (never throws).

---

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

### put

`inline`

```cpp
inline TValue & put(constTKey & key, std::unique_ptr< TValue > item)
```

[Defined in src/base/include/icy/collection.h:82](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L82)

Inserts or replaces the item under `key`.

---

<a id="erase"></a>

### erase

`inline`

```cpp
inline bool erase(constTKey & key)
```

[Defined in src/base/include/icy/collection.h:92](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L92)

Removes and destroys the item under `key`. 
#### Returns
true if the item existed and was removed.

---

<a id="contains"></a>

### contains

`const` `inline`

```cpp
inline bool contains(constTKey & key) const
```

[Defined in src/base/include/icy/collection.h:104](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L104)

---

<a id="empty"></a>

### empty

`const` `inline`

```cpp
inline bool empty() const
```

[Defined in src/base/include/icy/collection.h:105](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L105)

---

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

### size

`const` `inline`

```cpp
inline size_t size() const
```

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

---

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

### clear

`inline`

```cpp
inline void clear()
```

[Defined in src/base/include/icy/collection.h:107](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L107)

---

<a id="map"></a>

### map

`inline`

```cpp
inline Map & map()
```

[Defined in src/base/include/icy/collection.h:110](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L110)

Direct map access for iteration.

---

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

### map

`const` `inline`

```cpp
inline const Map & map() const
```

[Defined in src/base/include/icy/collection.h:111](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L111)

---

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

### begin

`inline`

```cpp
inline auto begin()
```

[Defined in src/base/include/icy/collection.h:114](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L114)

---

<a id="end"></a>

### end

`inline`

```cpp
inline auto end()
```

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

---

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

### begin

`const` `inline`

```cpp
inline auto begin() const
```

[Defined in src/base/include/icy/collection.h:116](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L116)

---

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

### end

`const` `inline`

```cpp
inline auto end() const
```

[Defined in src/base/include/icy/collection.h:117](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L117)

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`Map`](#map-2) | [`_map`](#_map)  |  |

---

<a id="_map"></a>

### _map

```cpp
Map _map
```

Type: [`Map`](#map-2)

[Defined in src/base/include/icy/collection.h:124](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L124)

## Protected Methods

| Return | Name | Description |
|--------|------|-------------|
| [`void`](#map) | [`onAdd`](#onadd) `virtual` `inline` | Override for lifecycle reactions. |
| [`void`](#map) | [`onRemove`](#onremove) `virtual` `inline` |  |

---

<a id="onadd"></a>

### onAdd

`virtual` `inline`

```cpp
virtual inline void onAdd(constTKey &, TValue *)
```

[Defined in src/base/include/icy/collection.h:121](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L121)

Override for lifecycle reactions.

#### Reimplemented by

- [`StreamManager::onAdd`](https://auscaster.com/icey/docs/api-reference/icy-StreamManager.md#onadd-1)

---

<a id="onremove"></a>

### onRemove

`virtual` `inline`

```cpp
virtual inline void onRemove(constTKey &, TValue *)
```

[Defined in src/base/include/icy/collection.h:122](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L122)

#### Reimplemented by

- [`StreamManager::onRemove`](https://auscaster.com/icey/docs/api-reference/icy-StreamManager.md#onremove-1)
- [`TimedManager::onRemove`](https://auscaster.com/icey/docs/api-reference/icy-TimedManager.md#onremove-3)

## Public Types

| Name | Description |
|------|-------------|
| [`Map`](#map-2)  |  |

---

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

### Map

```cpp
using Map = std::map< TKey, std::unique_ptr< TValue > >
```

Type: std::map< [`TKey`](#map), std::unique_ptr< [`TValue`](#map) > >

[Defined in src/base/include/icy/collection.h:40](https://github.com/auscaster/icey/blob/main/src/base/include/icy/collection.h#L40)
