From b0a532db8adeb909fa2cd8e518ca6917a2d7df0a Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 4 Nov 2002 03:59:09 +0000 Subject: split the OBTimerQueueManager and TimerQueue into their own files --- otk/timerqueue.hh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 otk/timerqueue.hh (limited to 'otk/timerqueue.hh') diff --git a/otk/timerqueue.hh b/otk/timerqueue.hh new file mode 100644 index 00000000..f9237a67 --- /dev/null +++ b/otk/timerqueue.hh @@ -0,0 +1,52 @@ +// -*- mode: C++; indent-tabs-mode: nil; -*- +#ifndef __timerqueue_hh +#define __timerqueue_hh + +#ifndef DOXYGEN_IGNORE + +#include "timer.hh" + +#include +#include +#include + +namespace otk { + +template +class _timer_queue: protected std::priority_queue<_Tp, _Sequence, _Compare> { +public: + typedef std::priority_queue<_Tp, _Sequence, _Compare> _Base; + + _timer_queue(): _Base() {} + ~_timer_queue() {} + + void release(const _Tp& value) { + c.erase(std::remove(c.begin(), c.end(), value), c.end()); + // after removing the item we need to make the heap again + std::make_heap(c.begin(), c.end(), comp); + } + bool empty() const { return _Base::empty(); } + size_t size() const { return _Base::size(); } + void push(const _Tp& value) { _Base::push(value); } + void pop() { _Base::pop(); } + const _Tp& top() const { return _Base::top(); } +private: + // no copying! + _timer_queue(const _timer_queue&) {} + _timer_queue& operator=(const _timer_queue&) {} +}; + +struct TimerLessThan { + bool operator()(const OBTimer* const l, const OBTimer* const r) const { + return *r < *l; + } +}; + +typedef _timer_queue, TimerLessThan> TimerQueue; + +} + +#endif // DOXYGEN_IGNORE + +#endif // __timerqueue_hh -- cgit v1.2.3