TimedManager
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. | |
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
loopEvent loop used by the internal timer (default: process-wide default loop).
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
_tmutex
std::mutex _tmutexDefined in src/base/include/icy/timedmanager.h:153
_timeouts
TimeoutMap _timeoutsDefined in src/base/include/icy/timedmanager.h:154
_timer
Timer _timerDefined 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.
Parameters
itemPointer to the managed item.timeoutDelay in milliseconds, or 0 to clear the timeout.
Returns
true on success.
Exceptions
std::logic_errorif 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.
Parameters
keyKey of the removed item.itemPointer to the removed item.
Reimplements
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
itemPointer 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 >Defined in src/base/include/icy/timedmanager.h:32
TimeoutMap
using TimeoutMap = std::map< TValue *, Timeout >