Home
Base module

TimedManager

Timed pointer manager Provides timed persistent data storage for class instances.

TimedManager

#include <icy/timedmanager.h>
template<classTKey, classTValue>
class TimedManager

Defined 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

NameKindOwner
TimedManagerfunctionDeclared here
~TimedManagerfunctionDeclared here
addfunctionDeclared here
expiresfunctionDeclared here
expiresfunctionDeclared here
clearfunctionDeclared here
_tmutexvariableDeclared here
_timeoutsvariableDeclared here
_timervariableDeclared here
setTimeoutfunctionDeclared here
onRemovefunctionDeclared here
onTimeoutfunctionDeclared here
onTimerUpdatefunctionDeclared here
BasetypedefDeclared here
TimeoutMaptypedefDeclared here
KeyedStorefunctionInherited from KeyedStore
~KeyedStorefunctionInherited from KeyedStore
KeyedStorefunctionInherited from KeyedStore
operator=functionInherited from KeyedStore
KeyedStorefunctionInherited from KeyedStore
operator=functionInherited from KeyedStore
getfunctionInherited from KeyedStore
addfunctionInherited from KeyedStore
tryAddfunctionInherited from KeyedStore
putfunctionInherited from KeyedStore
erasefunctionInherited from KeyedStore
containsfunctionInherited from KeyedStore
emptyfunctionInherited from KeyedStore
sizefunctionInherited from KeyedStore
clearfunctionInherited from KeyedStore
mapfunctionInherited from KeyedStore
mapfunctionInherited from KeyedStore
beginfunctionInherited from KeyedStore
endfunctionInherited from KeyedStore
beginfunctionInherited from KeyedStore
endfunctionInherited from KeyedStore
_mapvariableInherited from KeyedStore
onAddfunctionInherited from KeyedStore
onRemovefunctionInherited from KeyedStore
MaptypedefInherited from KeyedStore

Inherited from KeyedStore

KindNameDescription
functionKeyedStoreDefaulted constructor.
function~KeyedStore virtual inline
functionKeyedStoreDeleted constructor.
functionoperator=Deleted assignment operator.
functionKeyedStoreDefaulted constructor.
functionoperator=Defaulted assignment operator.
functionget const inlineReturns the item for key, or nullptr if not found.
functionadd inlineInserts a uniquely owned item. Returns a reference to the stored item.
functiontryAdd inlineInserts if absent; returns false on duplicate (never throws).
functionput inlineInserts or replaces the item under key.
functionerase inlineRemoves and destroys the item under key.
functioncontains const inline
functionempty const inline
functionsize const inline
functionclear inline
functionmap inlineDirect map access for iteration.
functionmap const inline
functionbegin inline
functionend inline
functionbegin const inline
functionend const inline
variable_map
functiononAdd virtual inlineOverride for lifecycle reactions.
functiononRemove virtual inline
typedefMap

Public Methods

ReturnNameDescription
TimedManager inlineConstructs a TimedManager and starts the internal expiry-check timer.
voidadd inlineAdd 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.
boolexpires virtual inlineUpdate the item expiry timeout.
boolexpires virtual inlineUpdate the item expiry timeout.
voidclear virtual inline overrideRemoves 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

  • loop Event 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() override

Defined in src/base/include/icy/timedmanager.h:74

Removes all items and their associated timeouts.

Protected Attributes

ReturnNameDescription
std::mutex_tmutex
TimeoutMap_timeouts
Timer_timer

_tmutex

std::mutex _tmutex

Defined in src/base/include/icy/timedmanager.h:153


_timeouts

TimeoutMap _timeouts

Defined in src/base/include/icy/timedmanager.h:154


_timer

Timer _timer

Defined in src/base/include/icy/timedmanager.h:155

Protected Methods

ReturnNameDescription
boolsetTimeout virtual inlineSets or removes the expiry timeout for a specific item pointer. If timeout > 0, starts a countdown; if timeout == 0, removes any existing timeout.
voidonRemove virtual inline overrideCalled when an item is removed from the collection. Erases the item's timeout entry and calls the base implementation.
voidonTimeout virtual inlineCalled when an item's timeout expires. Default implementation removes and deletes the item.
voidonTimerUpdate inlineInternal 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

  • item Pointer to the managed item.

  • timeout Delay in milliseconds, or 0 to clear the timeout.

Returns

true on success.

Exceptions

  • std::logic_error if item is nullptr.

onRemove

virtual inline override

virtual inline void onRemove(constTKey & key, TValue * item) override

Defined 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

  • key Key of the removed item.

  • item Pointer 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

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

NameDescription
Base
TimeoutMap

Base

using Base = KeyedStore< TKey, TValue >

Defined in src/base/include/icy/timedmanager.h:32


TimeoutMap

using TimeoutMap = std::map< TValue *, Timeout >

Defined in src/base/include/icy/timedmanager.h:33