TimedManager
TimedManager
#include <icy/timedmanager.h>Inherits:
KeyedStore< TKey, TValue >
Timed pointer manager
Provides timed persistent data storage for class instances. TValue must implement the clone() method.
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 | Removes all items and their associated timeouts. |
TimedManager
inline
inline TimedManager(uv::Loop * loop)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)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)Update the item expiry timeout.
expires
virtual inline
virtual inline bool expires(TValue * item, long timeout)Update the item expiry timeout.
clear
virtual inline
virtual inline void clear()Removes all items and their associated timeouts.
Protected Attributes
_tmutex
std::mutex _tmutex_timeouts
TimeoutMap _timeouts_timer
Timer _timerProtected 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 | 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)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
virtual inline void onRemove(constTKey & key, TValue * item)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.
onTimeout
virtual inline
virtual inline void onTimeout(TValue * item)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()Internal timer callback; iterates all tracked timeouts and calls onTimeout() for any that have expired.
Public Types
| Name | Description |
|---|---|
Base | |
TimeoutMap |
Base
KeyedStore< TKey, TValue > Base()TimeoutMap
std::map< TValue *, Timeout > TimeoutMap()