aboutsummaryrefslogtreecommitdiffstats
path: root/native/include/event.h
blob: 46366590b493512b77ea0ba963cd581254287ba4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef EVENT_H
#define EVENT_H

#include <queue>

template <class time_t>
class Event
{
  public:
    virtual void fire(const time_t &cur_time) {};  /* callback */
};


template <class time_t>
class Timeout
{
  private:
    time_t          fire_time;
    Event<time_t>   *handler;

  public:
    Timeout(time_t when, Event<time_t> *what)
        : fire_time(when), handler(what) {}

    const time_t& time() const
    {
        return fire_time;
    }

    Event<time_t>& event() const
    {
        return *handler;
    }

    bool operator<(const Timeout<time_t> &that) const
    {
        return this->time() < that.time();
    }

    bool operator>(const Timeout<time_t> &that) const
    {
        return this->time() > that.time();
    }
};


#endif