Base module

KeyedStore

A keyed store of unique_ptr values with optional lifecycle hooks.

#include <icy/collection.h>

template<classTKey, classTValue>
class KeyedStore

Defined in src/base/include/icy/collection.h:37

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

ReturnNameDescription
KeyedStoreDefaulted constructor.
~KeyedStore virtual inline
KeyedStoreDeleted constructor.
KeyedStore &operator=Deleted assignment operator.
KeyedStoreDefaulted constructor.
KeyedStore &operator=Defaulted assignment operator.
TValue *get const inlineReturns the item for key, or nullptr if not found.
TValue &add inlineInserts a uniquely owned item. Returns a reference to the stored item.
booltryAdd inlineInserts if absent; returns false on duplicate (never throws).
TValue &put inlineInserts or replaces the item under key.
boolerase inlineRemoves and destroys the item under key.
boolcontains const inline
boolempty const inline
size_tsize const inline
voidclear inline
Map &map inlineDirect map access for iteration.
const Map &map const inline
autobegin inline
autoend inline
autobegin const inline
autoend const inline

KeyedStore

KeyedStore() = default

Defined in src/base/include/icy/collection.h:42

Defaulted constructor.


~KeyedStore

virtual inline

virtual inline ~KeyedStore()

Defined in src/base/include/icy/collection.h:43


KeyedStore

KeyedStore(constKeyedStore &) = delete

Defined in src/base/include/icy/collection.h:46

Deleted constructor.


operator=

KeyedStore & operator=(constKeyedStore &) = delete

Defined in src/base/include/icy/collection.h:47

Deleted assignment operator.


KeyedStore

KeyedStore(KeyedStore &&) = default

Defined in src/base/include/icy/collection.h:48

Defaulted constructor.


operator=

KeyedStore & operator=(KeyedStore &&) = default

Defined in src/base/include/icy/collection.h:49

Defaulted assignment operator.


get

const inline

inline TValue * get(constTKey & key) const

Defined in src/base/include/icy/collection.h:52

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


add

inline

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

Defined in src/base/include/icy/collection.h:60

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

Exceptions

ExceptionDescription
std::runtime_errorif the key already exists.

tryAdd

inline

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

Defined in src/base/include/icy/collection.h:71

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


put

inline

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

Defined in src/base/include/icy/collection.h:82

Inserts or replaces the item under key.


erase

inline

inline bool erase(constTKey & key)

Defined in src/base/include/icy/collection.h:92

Removes and destroys the item under key.

Returns

true if the item existed and was removed.


contains

const inline

inline bool contains(constTKey & key) const

Defined in src/base/include/icy/collection.h:104


empty

const inline

inline bool empty() const

Defined in src/base/include/icy/collection.h:105


size

const inline

inline size_t size() const

Defined in src/base/include/icy/collection.h:106


clear

inline

inline void clear()

Defined in src/base/include/icy/collection.h:107


map

inline

inline Map & map()

Defined in src/base/include/icy/collection.h:110

Direct map access for iteration.


map

const inline

inline const Map & map() const

Defined in src/base/include/icy/collection.h:111


begin

inline

inline auto begin()

Defined in src/base/include/icy/collection.h:114


end

inline

inline auto end()

Defined in src/base/include/icy/collection.h:115


begin

const inline

inline auto begin() const

Defined in src/base/include/icy/collection.h:116


end

const inline

inline auto end() const

Defined in src/base/include/icy/collection.h:117

Protected Attributes

ReturnNameDescription
Map_map

_map

Map _map

Type: Map

Defined in src/base/include/icy/collection.h:124

Protected Methods

ReturnNameDescription
voidonAdd virtual inlineOverride for lifecycle reactions.
voidonRemove virtual inline

onAdd

virtual inline

virtual inline void onAdd(constTKey &, TValue *)

Defined in src/base/include/icy/collection.h:121

Override for lifecycle reactions.

Reimplemented by


onRemove

virtual inline

virtual inline void onRemove(constTKey &, TValue *)

Defined in src/base/include/icy/collection.h:122

Reimplemented by

Public Types

NameDescription
Map

Map

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

Type: std::map< TKey, std::unique_ptr< TValue > >

Defined in src/base/include/icy/collection.h:40