… | |
… | |
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 | // method callback |
31 | template<class K, void (K::*method)(watcher &w, int)> |
32 | template<class K, void (K::*method)(watcher &w, int)> |
32 | void set (K *object) |
33 | void set (K *object) |
33 | { |
34 | { |
34 | set_ (object, method_thunk<K, method>); |
35 | set_ (object, method_thunk<K, method>); |
35 | } |
36 | } |
36 | |
37 | |
37 | template<class K, void (K::*method)(watcher &w, int)> |
38 | template<class K, void (K::*method)(watcher &w, int)> |
38 | static void method_thunk (EV_P_ watcher *w, int revents) |
39 | static void method_thunk (EV_P_ ev_watcher *w, int revents) |
39 | { |
40 | { |
40 | K *obj = static_cast<K *>(w->data); |
41 | K *obj = static_cast<K *>(w->data); |
41 | (obj->*method) (*w, revents); |
42 | (obj->*method) (*static_cast<watcher *>(w), revents); |
42 | } |
43 | } |
43 | |
44 | |
|
|
45 | // const method callback |
44 | template<class K, void (K::*method)(watcher &w, int) const> |
46 | template<class K, void (K::*method)(watcher &w, int) const> |
45 | void set (const K *object) |
47 | void set (const K *object) |
46 | { |
48 | { |
47 | set_ (object, const_method_thunk<K, method>); |
49 | set_ (object, const_method_thunk<K, method>); |
48 | } |
50 | } |
49 | |
51 | |
50 | template<class K, void (K::*method)(watcher &w, int) const> |
52 | template<class K, void (K::*method)(watcher &w, int) const> |
51 | static void const_method_thunk (EV_P_ watcher *w, int revents) |
53 | static void const_method_thunk (EV_P_ ev_watcher *w, int revents) |
52 | { |
54 | { |
53 | K *obj = static_cast<K *>(w->data); |
55 | K *obj = static_cast<K *>(w->data); |
54 | (obj->*method) (*w, revents); |
56 | (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents); |
55 | } |
57 | } |
56 | |
58 | |
|
|
59 | // function callback |
57 | template<void (*function)(watcher &w, int)> |
60 | template<void (*function)(watcher &w, int)> |
58 | void set (void *data = 0) |
61 | void set (void *data = 0) |
59 | { |
62 | { |
60 | set_ (data, function_thunk<function>); |
63 | set_ (data, function_thunk<function>); |
61 | } |
64 | } |
62 | |
65 | |
63 | template<void (*function)(watcher &w, int)> |
66 | template<void (*function)(watcher &w, int)> |
64 | static void function_thunk (EV_P_ watcher *w, int revents) |
67 | static void function_thunk (EV_P_ ev_watcher *w, int revents) |
|
|
68 | { |
|
|
69 | function (*static_cast<watcher *>(w), revents); |
65 | { |
70 | } |
66 | function (*w, revents); |
71 | |
|
|
72 | // simple callback |
|
|
73 | template<class K, void (K::*method)()> |
|
|
74 | void set (K *object) |
|
|
75 | { |
|
|
76 | set_ (object, method_noargs_thunk<K, method>); |
|
|
77 | } |
|
|
78 | |
|
|
79 | template<class K, void (K::*method)()> |
|
|
80 | static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) |
|
|
81 | { |
|
|
82 | K *obj = static_cast<K *>(w->data); |
|
|
83 | (obj->*method) (); |
67 | } |
84 | } |
68 | |
85 | |
69 | void operator ()(int events = EV_UNDEF) |
86 | void operator ()(int events = EV_UNDEF) |
70 | { |
87 | { |
71 | return ev_cb (static_cast<ev_watcher *>(this)) |
88 | return ev_cb (static_cast<ev_watcher *>(this)) |