… | |
… | |
44 | # include EV_H |
44 | # include EV_H |
45 | #else |
45 | #else |
46 | # include "ev.h" |
46 | # include "ev.h" |
47 | #endif |
47 | #endif |
48 | |
48 | |
49 | #ifndef EV_CXX_EXCEPTIONS |
49 | #ifndef EV_USE_STDEXCEPT |
50 | #define EV_CXX_EXCEPTIONS 1 |
50 | # define EV_USE_STDEXCEPT 1 |
51 | #endif |
51 | #endif |
52 | |
52 | |
53 | #undef EV_THROW |
53 | #if EV_USE_STDEXCEPT |
54 | #if EV_CXX_EXCEPTIONS |
|
|
55 | # include <stdexcept> |
54 | # include <stdexcept> |
56 | # define EV_THROW(exception) throw (exception) |
|
|
57 | #else |
|
|
58 | # define EV_THROW(exception) |
|
|
59 | #endif |
55 | #endif |
60 | |
56 | |
61 | namespace ev { |
57 | namespace ev { |
62 | |
58 | |
63 | typedef ev_tstamp tstamp; |
59 | typedef ev_tstamp tstamp; |
… | |
… | |
103 | { |
99 | { |
104 | ONE = EVUNLOOP_ONE, |
100 | ONE = EVUNLOOP_ONE, |
105 | ALL = EVUNLOOP_ALL |
101 | ALL = EVUNLOOP_ALL |
106 | }; |
102 | }; |
107 | |
103 | |
108 | #if EV_CXX_EXCEPTIONS |
104 | struct bad_loop |
109 | struct bad_loop : std::runtime_error |
105 | #if EV_USE_STDEXCEPT |
|
|
106 | : std::runtime_error |
|
|
107 | #endif |
110 | { |
108 | { |
|
|
109 | #if EV_USE_STDEXCEPT |
111 | bad_loop () |
110 | bad_loop () |
112 | : std::runtime_error ("loop can't be initialized") |
111 | : std::runtime_error ("libev event loop cannot be initialized, bad value of LIBEV_FLAGS?") |
113 | { |
|
|
114 | } |
112 | { |
115 | }; |
113 | } |
116 | #endif |
114 | #endif |
|
|
115 | }; |
117 | |
116 | |
118 | #ifdef EV_AX |
117 | #ifdef EV_AX |
119 | # undef EV_AX |
118 | # undef EV_AX |
120 | #endif |
119 | #endif |
121 | |
120 | |
… | |
… | |
134 | struct loop_ref |
133 | struct loop_ref |
135 | { |
134 | { |
136 | |
135 | |
137 | loop_ref (EV_P) |
136 | loop_ref (EV_P) |
138 | #if EV_MULTIPLICITY |
137 | #if EV_MULTIPLICITY |
139 | EV_THROW (bad_loop) : EV_AX (EV_A) |
138 | throw (bad_loop) : EV_AX (EV_A) |
140 | #endif |
|
|
141 | { |
139 | { |
142 | #if EV_MULTIPLICIY && EV_CXX_EXCEPTIONS |
|
|
143 | if (!EV_A) |
140 | if (!EV_AX) |
144 | throw bad_loop (); |
141 | throw bad_loop (); |
145 | #endif |
142 | } |
|
|
143 | #else |
|
|
144 | throw () |
146 | } |
145 | { |
|
|
146 | } |
|
|
147 | #endif |
147 | |
148 | |
148 | bool operator== (const loop_ref &other) const throw () |
149 | bool operator == (const loop_ref &other) const throw () |
149 | { |
150 | { |
150 | #if EV_MULTIPLICITY |
151 | #if EV_MULTIPLICITY |
151 | return this->EV_AX == other.EV_AX; |
152 | return EV_AX == other.EV_AX; |
152 | #else |
153 | #else |
153 | return true; |
154 | return true; |
154 | #endif |
155 | #endif |
155 | } |
156 | } |
156 | |
157 | |
157 | bool operator!= (const loop_ref &other) const throw () |
158 | bool operator != (const loop_ref &other) const throw () |
158 | { |
159 | { |
159 | #if EV_MULTIPLICITY |
160 | #if EV_MULTIPLICITY |
160 | return ! (*this == other); |
161 | return ! (*this == other); |
161 | #else |
162 | #else |
162 | return false; |
163 | return false; |
… | |
… | |
346 | |
347 | |
347 | #if EV_MULTIPLICITY |
348 | #if EV_MULTIPLICITY |
348 | struct dynamic_loop: loop_ref |
349 | struct dynamic_loop: loop_ref |
349 | { |
350 | { |
350 | |
351 | |
351 | dynamic_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) |
352 | dynamic_loop (unsigned int flags = AUTO) throw (bad_loop) |
352 | : loop_ref (ev_loop_new (flags)) |
353 | : loop_ref (ev_loop_new (flags)) |
353 | { |
354 | { |
354 | } |
355 | } |
355 | |
356 | |
356 | ~dynamic_loop () throw () |
357 | ~dynamic_loop () throw () |
… | |
… | |
369 | #endif |
370 | #endif |
370 | |
371 | |
371 | struct default_loop: loop_ref |
372 | struct default_loop: loop_ref |
372 | { |
373 | { |
373 | |
374 | |
374 | default_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) |
375 | default_loop (unsigned int flags = AUTO) throw (bad_loop) |
375 | #if EV_MULTIPLICITY |
376 | #if EV_MULTIPLICITY |
376 | : loop_ref (ev_default_loop (flags)) |
377 | : loop_ref (ev_default_loop (flags)) |
377 | { |
378 | #endif |
378 | } |
379 | { |
379 | #else |
380 | #ifndef EV_MULTIPLICITY |
380 | { |
|
|
381 | #if EV_CXX_EXCEPTIONS |
|
|
382 | int r = |
|
|
383 | #endif |
|
|
384 | ev_default_loop (flags); |
381 | if (!ev_default_loop (flags)) |
385 | #if EV_CXX_EXCEPTIONS |
|
|
386 | if (!r) |
|
|
387 | throw bad_loop (); |
382 | throw bad_loop (); |
388 | #endif |
383 | #endif |
389 | } |
384 | } |
390 | #endif |
|
|
391 | |
385 | |
392 | ~default_loop () throw () |
386 | ~default_loop () throw () |
393 | { |
387 | { |
394 | ev_default_destroy (); |
388 | ev_default_destroy (); |
395 | #if EV_MULTIPLICITY |
|
|
396 | EV_AX = 0; |
|
|
397 | #endif |
|
|
398 | } |
389 | } |
399 | |
390 | |
400 | private: |
391 | private: |
401 | |
|
|
402 | default_loop (const default_loop &); |
392 | default_loop (const default_loop &); |
403 | |
|
|
404 | default_loop & operator= (const default_loop &); |
393 | default_loop &operator = (const default_loop &); |
405 | |
|
|
406 | }; |
394 | }; |
407 | |
395 | |
408 | inline loop_ref get_default_loop () throw () |
396 | inline loop_ref get_default_loop () throw () |
409 | { |
397 | { |
410 | #if EV_MULTIPLICITY |
398 | #if EV_MULTIPLICITY |
… | |
… | |
788 | #undef EV_BEGIN_WATCHER |
776 | #undef EV_BEGIN_WATCHER |
789 | #undef EV_END_WATCHER |
777 | #undef EV_END_WATCHER |
790 | |
778 | |
791 | } |
779 | } |
792 | |
780 | |
793 | #undef EV_THROW |
|
|
794 | |
|
|
795 | #endif |
781 | #endif |
796 | |
782 | |