]> Dogcows Code - chaz/openbox/blob - otk/timerqueue.hh
fix indenting
[chaz/openbox] / otk / timerqueue.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __timerqueue_hh
3 #define __timerqueue_hh
4
5 #ifndef DOXYGEN_IGNORE
6
7 #include "timer.hh"
8
9 #include <queue>
10 #include <vector>
11 #include <algorithm>
12
13 namespace otk {
14
15 template <class _Tp, class _Sequence, class _Compare>
16 class _timer_queue: protected std::priority_queue<_Tp, _Sequence, _Compare> {
17 public:
18 typedef std::priority_queue<_Tp, _Sequence, _Compare> _Base;
19
20 _timer_queue(): _Base() {}
21 ~_timer_queue() {}
22
23 void release(const _Tp& value) {
24 c.erase(std::remove(c.begin(), c.end(), value), c.end());
25 // after removing the item we need to make the heap again
26 std::make_heap(c.begin(), c.end(), comp);
27 }
28 bool empty() const { return _Base::empty(); }
29 size_t size() const { return _Base::size(); }
30 void push(const _Tp& value) { _Base::push(value); }
31 void pop() { _Base::pop(); }
32 const _Tp& top() const { return _Base::top(); }
33 private:
34 // no copying!
35 _timer_queue(const _timer_queue&) {}
36 _timer_queue& operator=(const _timer_queue&) {}
37 };
38
39 struct TimerLessThan {
40 bool operator()(const Timer* const l, const Timer* const r) const {
41 return *r < *l;
42 }
43 };
44
45 typedef _timer_queue<Timer*, std::vector<Timer*>, TimerLessThan> TimerQueue;
46
47 }
48
49 #endif // DOXYGEN_IGNORE
50
51 #endif // __timerqueue_hh
This page took 0.034402 seconds and 4 git commands to generate.