TimedManager
#include <icy/timedmanager.h>
template<classTKey, classTValue>
class TimedManagerDefined in src/base/include/icy/timedmanager.h:29
- Inherits
KeyedStore< TKey, TValue >
Timed pointer manager
Provides timed persistent data storage for class instances. TValue must implement the clone() method.
List of all members
| Name | Kind | Owner |
|---|---|---|
TimedManager | function | Declared here |
~TimedManager | function | Declared here |
add | function | Declared here |
expires | function | Declared here |
expires | function | Declared here |
clear | function | Declared here |
_tmutex | variable | Declared here |
_timeouts | variable | Declared here |
_timer | variable | Declared here |
setTimeout | function | Declared here |
onRemove | function | Declared here |
onTimeout | function | Declared here |
onTimerUpdate | function | Declared here |
Base | typedef | Declared here |
TimeoutMap | typedef | Declared here |
KeyedStore | function | Inherited from KeyedStore |
~KeyedStore | function | Inherited from KeyedStore |
KeyedStore | function | Inherited from KeyedStore |
operator= | function | Inherited from KeyedStore |
KeyedStore | function | Inherited from KeyedStore |
operator= | function | Inherited from KeyedStore |
get | function | Inherited from KeyedStore |
add | function | Inherited from KeyedStore |
tryAdd | function | Inherited from KeyedStore |
put | function | Inherited from KeyedStore |
erase | function | Inherited from KeyedStore |
contains | function | Inherited from KeyedStore |
empty | function | Inherited from KeyedStore |
size | function | Inherited from KeyedStore |
clear | function | Inherited from KeyedStore |
map | function | Inherited from KeyedStore |
map | function | Inherited from KeyedStore |
begin | function | Inherited from KeyedStore |
end | function | Inherited from KeyedStore |
begin | function | Inherited from KeyedStore |
end | function | Inherited from KeyedStore |
_map | variable | Inherited from KeyedStore |
onAdd | function | Inherited from KeyedStore |
onRemove | function | Inherited from KeyedStore |
Map | typedef | Inherited from KeyedStore |
Inherited from KeyedStore
| Kind | Name | Description |
|---|---|---|
function | KeyedStore | Defaulted constructor. |
function | ~KeyedStore virtual inline | |
function | KeyedStore | Deleted constructor. |
function | operator= | Deleted assignment operator. |
function | KeyedStore | Defaulted constructor. |
function | operator= | Defaulted assignment operator. |
function | get const inline | Returns the item for key, or nullptr if not found. |
function | add inline | Inserts a uniquely owned item. Returns a reference to the stored item. |
function | tryAdd inline | Inserts if absent; returns false on duplicate (never throws). |
function | put inline | Inserts or replaces the item under key. |
function | erase inline | Removes and destroys the item under key. |
function | contains const inline | |
function | empty const inline | |
function | size const inline | |
function | clear inline | |
function | map inline | Direct map access for iteration. |
function | map const inline | |
function | begin inline | |
function | end inline | |
function | begin const inline | |
function | end const inline | |
variable | _map | |
function | onAdd virtual inline | Override for lifecycle reactions. |
function | onRemove virtual inline | |
typedef | Map |
Public Methods
| Return | Name | Description |
|---|---|---|
TimedManager inline | Constructs a TimedManager and starts the internal expiry-check timer. | |
~TimedManager virtual inline | ||
void | add inline | Add an item which will expire (and be deleted) after the specified timeout value. If the timeout is 0 the item will be stored indefinitely. The TimedManager assumes ownership of the given pointer. |
bool | expires virtual inline | Update the item expiry timeout. |
bool | expires virtual inline | Update the item expiry timeout. |
void | clear virtual inline override | Removes all items and their associated timeouts. |
TimedManager
inline
inline TimedManager(uv::Loop * loop = uv::defaultLoop())Defined in src/base/include/icy/timedmanager.h:37
Constructs a TimedManager and starts the internal expiry-check timer.
Parameters
| Parameter | Type | Description |
|---|---|---|
loop | uv::Loop * | Event loop used by the internal timer (default: process-wide default loop). |
~TimedManager
virtual inline
virtual inline ~TimedManager()Defined in src/base/include/icy/timedmanager.h:43
add
inline
inline void add(constTKey & key, std::unique_ptr< TValue > item, long timeout = 0)Defined in src/base/include/icy/timedmanager.h:51
Add an item which will expire (and be deleted) after the specified timeout value. If the timeout is 0 the item will be stored indefinitely. The TimedManager assumes ownership of the given pointer.
expires
virtual inline
virtual inline bool expires(constTKey & key, long timeout)Defined in src/base/include/icy/timedmanager.h:60
Update the item expiry timeout.
expires
virtual inline
virtual inline bool expires(TValue * item, long timeout)Defined in src/base/include/icy/timedmanager.h:67
Update the item expiry timeout.
clear
virtual inline override
virtual inline void clear() overrideDefined in src/base/include/icy/timedmanager.h:74
Removes all items and their associated timeouts.
Protected Attributes
| Return | Name | Description |
|---|---|---|
std::mutex | _tmutex | |
TimeoutMap | _timeouts | |
Timer | _timer |
_tmutex
std::mutex _tmutexDefined in src/base/include/icy/timedmanager.h:153
_timeouts
TimeoutMap _timeoutsType: TimeoutMap
Defined in src/base/include/icy/timedmanager.h:154
_timer
Timer _timerType: Timer
Defined in src/base/include/icy/timedmanager.h:155
Protected Methods
| Return | Name | Description |
|---|---|---|
bool | setTimeout virtual inline | Sets or removes the expiry timeout for a specific item pointer. If timeout > 0, starts a countdown; if timeout == 0, removes any existing timeout. |
void | onRemove virtual inline override | Called when an item is removed from the collection. Erases the item's timeout entry and calls the base implementation. |
void | onTimeout virtual inline | Called when an item's timeout expires. Default implementation removes and deletes the item. |
void | onTimerUpdate inline | Internal timer callback; iterates all tracked timeouts and calls onTimeout() for any that have expired. |
setTimeout
virtual inline
virtual inline bool setTimeout(TValue * item, long timeout)Defined in src/base/include/icy/timedmanager.h:88
Sets or removes the expiry timeout for a specific item pointer. If timeout > 0, starts a countdown; if timeout == 0, removes any existing timeout.
Returns
true on success.
Parameters
| Parameter | Type | Description |
|---|---|---|
item | TValue * | Pointer to the managed item. |
timeout | long | Delay in milliseconds, or 0 to clear the timeout. |
Exceptions
| Exception | Description |
|---|---|
std::logic_error | if item is nullptr. |
onRemove
virtual inline override
virtual inline void onRemove(constTKey & key, TValue * item) overrideDefined in src/base/include/icy/timedmanager.h:113
Called when an item is removed from the collection. Erases the item's timeout entry and calls the base implementation.
Reimplements
Parameters
| Parameter | Type | Description |
|---|---|---|
key | constTKey & | Key of the removed item. |
item | TValue * | Pointer to the removed item. |
onTimeout
virtual inline
virtual inline void onTimeout(TValue * item)Defined in src/base/include/icy/timedmanager.h:126
Called when an item's timeout expires. Default implementation removes and deletes the item.
Parameters
| Parameter | Type | Description |
|---|---|---|
item | TValue * | Pointer to the expired item. |
onTimerUpdate
inline
inline void onTimerUpdate()Defined in src/base/include/icy/timedmanager.h:139
Internal timer callback; iterates all tracked timeouts and calls onTimeout() for any that have expired.
Public Types
| Name | Description |
|---|---|
Base | |
TimeoutMap |
Base
using Base = KeyedStore< TKey, TValue >Type: KeyedStore< TKey, TValue >
Defined in src/base/include/icy/timedmanager.h:32
TimeoutMap
using TimeoutMap = std::map< TValue *, Timeout >