Base module

KeyedStore

A keyed store of unique_ptr values with optional lifecycle hooks.

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

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

Defaulted constructor.


KeyedStore

KeyedStore(constKeyedStore &) = delete

Deleted constructor.


KeyedStore

KeyedStore(KeyedStore &&) = default

Defaulted constructor.


get

const inline

inline TValue * get(constTKey & key) const

Returns 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_error if 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) const

empty

const inline

inline bool empty() const

size

const inline

inline size_t size() const

clear

inline

inline void clear()

map

inline

inline Map & map()

Direct map access for iteration.


map

const inline

inline const Map & map() const

begin

inline

inline auto begin()

end

inline

inline auto end()

begin

const inline

inline auto begin() const

end

const inline

inline auto end() const

Protected Attributes

ReturnNameDescription
Map_map

_map

Map _map

Protected Methods

ReturnNameDescription
voidonAdd virtual inlineOverride for lifecycle reactions.
voidonRemove 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

NameDescription
Map

Map

std::map< TKey, std::unique_ptr< TValue > > Map()