Home
Base module

KeyedStore

A keyed store of unique_ptr values with optional lifecycle hooks.

KeyedStore

#include <icy/collection.h>
template<classTKey, classTValue>
class KeyedStore

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

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.

List of all members

NameKindOwner
KeyedStorefunctionDeclared here
~KeyedStorefunctionDeclared here
KeyedStorefunctionDeclared here
operator=functionDeclared here
KeyedStorefunctionDeclared here
operator=functionDeclared here
getfunctionDeclared here
addfunctionDeclared here
tryAddfunctionDeclared here
putfunctionDeclared here
erasefunctionDeclared here
containsfunctionDeclared here
emptyfunctionDeclared here
sizefunctionDeclared here
clearfunctionDeclared here
mapfunctionDeclared here
mapfunctionDeclared here
beginfunctionDeclared here
endfunctionDeclared here
beginfunctionDeclared here
endfunctionDeclared here
_mapvariableDeclared here
onAddfunctionDeclared here
onRemovefunctionDeclared here
MaptypedefDeclared here

Public Methods

ReturnNameDescription
KeyedStoreDefaulted constructor.
KeyedStoreDeleted constructor.
KeyedStoreDefaulted constructor.
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

KeyedStore(constKeyedStore &) = delete

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

Deleted constructor.


KeyedStore

KeyedStore(KeyedStore &&) = default

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

Defaulted constructor.


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

  • std::runtime_error if 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

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 > >

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