… | |
… | |
20 | base () |
20 | base () |
21 | { |
21 | { |
22 | ev_init (this, 0); |
22 | ev_init (this, 0); |
23 | } |
23 | } |
24 | |
24 | |
25 | void set_ (void *data, void (*cb)(EV_P_ watcher *w, int revents)) |
25 | void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) |
26 | { |
26 | { |
27 | this->data = data; |
27 | this->data = data; |
28 | ev_set_cb (static_cast<watcher *>(this), cb); |
28 | ev_set_cb (static_cast<ev_watcher *>(this), cb); |
29 | } |
29 | } |
30 | |
30 | |
31 | template<class K, void (K::*method)(watcher &w, int)> |
31 | template<class K, void (K::*method)(watcher &w, int)> |
32 | void set (K *object) |
32 | void set (K *object) |
33 | { |
33 | { |
34 | set_ (object, method_thunk<K, method>); |
34 | set_ (object, method_thunk<K, method>); |
35 | } |
35 | } |
36 | |
36 | |
37 | template<class K, void (K::*method)(watcher &w, int)> |
37 | template<class K, void (K::*method)(watcher &w, int)> |
38 | static void method_thunk (EV_P_ watcher *w, int revents) |
38 | static void method_thunk (EV_P_ ev_watcher *w, int revents) |
39 | { |
39 | { |
40 | K *obj = static_cast<K *>(w->data); |
40 | K *obj = static_cast<K *>(w->data); |
41 | (obj->*method) (*w, revents); |
41 | (obj->*method) (*static_cast<watcher *>(w), revents); |
42 | } |
42 | } |
43 | |
43 | |
44 | template<class K, void (K::*method)(watcher &w, int) const> |
44 | template<class K, void (K::*method)(watcher &w, int) const> |
45 | void set (const K *object) |
45 | void set (const K *object) |
46 | { |
46 | { |
47 | set_ (object, const_method_thunk<K, method>); |
47 | set_ (object, const_method_thunk<K, method>); |
48 | } |
48 | } |
49 | |
49 | |
50 | template<class K, void (K::*method)(watcher &w, int) const> |
50 | template<class K, void (K::*method)(watcher &w, int) const> |
51 | static void const_method_thunk (EV_P_ watcher *w, int revents) |
51 | static void const_method_thunk (EV_P_ ev_watcher *w, int revents) |
52 | { |
52 | { |
53 | K *obj = static_cast<K *>(w->data); |
53 | K *obj = static_cast<K *>(w->data); |
54 | (obj->*method) (*w, revents); |
54 | (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents); |
55 | } |
55 | } |
56 | |
56 | |
57 | template<void (*function)(watcher &w, int)> |
57 | template<void (*function)(watcher &w, int)> |
58 | void set (void *data = 0) |
58 | void set (void *data = 0) |
59 | { |
59 | { |
60 | set_ (data, function_thunk<function>); |
60 | set_ (data, function_thunk<function>); |
61 | } |
61 | } |
62 | |
62 | |
63 | template<void (*function)(watcher &w, int)> |
63 | template<void (*function)(watcher &w, int)> |
64 | static void function_thunk (EV_P_ watcher *w, int revents) |
64 | static void function_thunk (EV_P_ ev_watcher *w, int revents) |
65 | { |
65 | { |
66 | function (*w, revents); |
66 | function (*static_cast<watcher *>(w), revents); |
67 | } |
67 | } |
68 | |
68 | |
69 | void operator ()(int events = EV_UNDEF) |
69 | void operator ()(int events = EV_UNDEF) |
70 | { |
70 | { |
71 | return ev_cb (static_cast<ev_watcher *>(this)) |
71 | return ev_cb (static_cast<ev_watcher *>(this)) |