KeyedStore
KeyedStore
#include <icy/collection.h>Subclassed by:
TimedManager< TKey, TValue >
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 members for external observers.
Public Methods
| Return | Name | Description |
|---|---|---|
KeyedStore | Defaulted constructor. | |
KeyedStore | Deleted constructor. | |
KeyedStore | Defaulted constructor. | |
TValue * | get const inline | Returns the item for key, or nullptr if not found. |
TValue & | add inline | Inserts a uniquely owned item. Returns a reference to the stored item. |
bool | tryAdd inline | Inserts if absent; returns false on duplicate (never throws). |
TValue & | put inline | Inserts or replaces the item under key. |
bool | erase inline | Removes and destroys the item under key. |
bool | contains const inline | |
bool | empty const inline | |
size_t | size const inline | |
void | clear inline | |
Map & | map inline | Direct map access for iteration. |
const Map & | map const inline | |
auto | begin inline | |
auto | end inline | |
auto | begin const inline | |
auto | end const inline |
KeyedStore
KeyedStore() = defaultDefaulted constructor.
KeyedStore
KeyedStore(constKeyedStore &) = deleteDeleted constructor.
KeyedStore
KeyedStore(KeyedStore &&) = defaultDefaulted constructor.
get
const inline
inline TValue * get(constTKey & key) constReturns the item for key, or nullptr if not found.
add
inline
inline TValue & add(constTKey & key, std::unique_ptr< TValue > item)Inserts a uniquely owned item. Returns a reference to the stored item.
Exceptions
std::runtime_errorif the key already exists.
tryAdd
inline
inline bool tryAdd(constTKey & key, std::unique_ptr< TValue > item)Inserts if absent; returns false on duplicate (never throws).
put
inline
inline TValue & put(constTKey & key, std::unique_ptr< TValue > item)Inserts or replaces the item under key.
erase
inline
inline bool erase(constTKey & key)Removes and destroys the item under key.
Returns
true if the item existed and was removed.
contains
const inline
inline bool contains(constTKey & key) constempty
const inline
inline bool empty() constsize
const inline
inline size_t size() constclear
inline
inline void clear()map
inline
inline Map & map()Direct map access for iteration.
map
const inline
inline const Map & map() constbegin
inline
inline auto begin()end
inline
inline auto end()begin
const inline
inline auto begin() constend
const inline
inline auto end() constProtected Attributes
| Return | Name | Description |
|---|---|---|
Map | _map |
_map
Map _mapProtected Methods
| Return | Name | Description |
|---|---|---|
void | onAdd virtual inline | Override for lifecycle reactions. |
void | onRemove virtual inline |
onAdd
virtual inline
virtual inline void onAdd(constTKey &, TValue *)Override for lifecycle reactions.
onRemove
virtual inline
virtual inline void onRemove(constTKey &, TValue *)Public Types
| Name | Description |
|---|---|
Map |
Map
std::map< TKey, std::unique_ptr< TValue > > Map()