Template Class timeout_queue_t
Defined in File timeout_queue.hpp
Nested Relationships
Nested Types
Inheritance Relationships
Base Type
public std::list< pair_t< type, timer_t > >
Class Documentation
-
template<typename type>
class timeout_queue_t : public std::list<pair_t<type, timer_t>> Timeout-aware queue wrapper around
std::list.Timeout checks are performed during iteration. Expired items are collected in a side buffer and can be retrieved with
timed_out().Thread-safety is managed manually via
read_lock()/unlock_read()andlock()/unlock().Example:
timeout_queue_t<item_t> q(duration_t::from_s(5));q.read_lock(); for (const auto& v : q) { ... } q.unlock_read();auto expired = q.timed_out();- Template Parameters:
type – Type of elements stored in the queue.
Public Types
Shared pointer type.
Public Functions
-
inline timeout_queue_t(duration_t timeOut_ = duration_t::from_s(10))
Construct a new timeout_queue_t object.
- Parameters:
timeOut_ – Maximum allowed age for each element in the queue.
-
inline iterator begin()
Returns iterator to the beginning (first non-expired element)
- Returns:
Iterator to the first non-expired element.
-
inline iterator end()
Returns iterator to the end.
- Returns:
Iterator representing the end sentinel.
-
inline const_iterator begin() const
Returns const_iterator to the beginning (first non-expired element)
- Returns:
Const iterator to the first non-expired element.
-
inline const_iterator end() const
Returns const_iterator to the end.
- Returns:
Const iterator representing the end sentinel.
-
inline const_iterator cbegin() const
Returns const_iterator to the beginning (first non-expired element)
- Returns:
Const iterator to the first non-expired element.
-
inline const_iterator cend() const
Returns const_iterator to the end.
- Returns:
Const iterator representing the end sentinel.
-
inline void insert(const type &item_)
Insert item into the queue with current time.
- Parameters:
item_ – Element inserted with a fresh timestamp.
-
inline void clear(const vector_t<type> &elements_)
Remove elements from the queue that match the given elements.
- Parameters:
elements_ – Values to remove from the queue when matched by equality.
-
inline void clear()
Clear all elements from the queue.
-
inline vector_t<type> &timed_out()
Get the vector of timed out items (and clear the internal buffer)
- Returns:
Reference to the vector of timed out items
-
inline void clear_timed_out(const vector_t<type> &elements_, bool dumpVerbose_ = false, const std::string &prefix_ = "")
Clear timed out items. If elements are given, clear only those.
- Parameters:
elements_ – Timed-out items that should be removed from the buffer.
dumpVerbose_ – Enables per-item timeout messages before removal.
prefix_ – Text prefix prepended to each timeout message.
-
inline void clear_timed_out(bool dumpVerbose_ = false, const std::string &prefix_ = "")
Clear all timed out items.
- Parameters:
dumpVerbose_ – Enables per-item timeout messages before clearing.
prefix_ – Text prefix prepended to each timeout message.
-
inline void read_lock() const
Acquire a shared (read) lock for thread safety.
-
inline void lock() const
Acquire an exclusive (write) lock for thread safety.
-
inline void unlock_read() const
Release a shared (read) lock.
-
inline void unlock() const
Release an exclusive (write) lock.
Private Functions
Private Members
-
duration_t timeOut
Timeout duration for elements in the queue.
-
mutable std::shared_mutex mutex
Mutex for thread safety (shared/exclusive)
-
struct const_iterator
Const iterator that yields only non-expired elements in the queue.
Public Types
-
using iterator_category = std::forward_iterator_tag
Public Functions
-
const_iterator() = default
Default constructor.
-
inline const_iterator(const timeout_queue_t *o_, base_iter i_, base_iter e_)
Construct a const_iterator.
- Parameters:
o_ – Queue instance that owns this iterator.
i_ – Current list iterator position.
e_ – Sentinel iterator marking the end position.
-
inline const_iterator(const iterator &other_)
Allow converting iterator to const_iterator.
- Parameters:
other_ – Mutable iterator whose state is copied.
-
inline const_iterator &operator++()
Pre-increment operator.
-
inline const_iterator operator++(int int_)
Post-increment operator.
- Parameters:
int_ – Dummy integer used to select postfix increment syntax.
- Returns:
Iterator snapshot before incrementing.
Public Members
-
const timeout_queue_t *owner = nullptr
Pointer to the owning queue.
Private Functions
-
inline void __skip_expired()
Skip expired elements and collect them in timedOutItems.
Friends
-
inline friend bool operator==(const const_iterator &a_, const const_iterator &b_)
Equality comparison.
- Parameters:
a_ – Left iterator in the comparison.
b_ – Right iterator in the comparison.
- Returns:
truewhen both iterators point to the same list position.
-
inline friend bool operator!=(const const_iterator &a_, const const_iterator &b_)
Inequality comparison.
- Parameters:
a_ – Left iterator in the comparison.
b_ – Right iterator in the comparison.
- Returns:
truewhen iterators point to different list positions.
-
using iterator_category = std::forward_iterator_tag
-
struct iterator
Filtered iterator (yields only non-expired type)
Iterator that yields only non-expired elements in the queue.
Public Types
-
using iterator_category = std::forward_iterator_tag
Public Functions
-
iterator() = default
Default constructor.
-
inline iterator(timeout_queue_t *o_, base_iter i_, base_iter e_)
Construct an iterator.
- Parameters:
o_ – Queue instance that owns this iterator.
i_ – Current list iterator position.
e_ – Sentinel iterator marking the end position.
Public Members
-
timeout_queue_t *owner = nullptr
Pointer to the owning queue.
Private Functions
-
inline void __skip_expired()
Skip expired elements and collect them in timedOutItems.
-
using iterator_category = std::forward_iterator_tag