]> rtime.felk.cvut.cz Git - sojka/libev.git/commitdiff
compat3 for ev++.h, default args c++
authorMarc Alexander Lehmann <libev@schmorp.de>
Fri, 22 Oct 2010 05:57:55 +0000 (05:57 +0000)
committerMarc Alexander Lehmann <libev@schmorp.de>
Fri, 22 Oct 2010 05:57:55 +0000 (05:57 +0000)
Changes
ev++.h
ev.h

diff --git a/Changes b/Changes
index 0c3bb1aa3f39878b60e75f3704769c1b0fcfb622..1450f86be7d87c38ce27cd03745f80661db569e4 100644 (file)
--- a/Changes
+++ b/Changes
@@ -44,6 +44,8 @@ TODO: include ev_xyz_start in each example?
         - define _DARWIN_UNLIMITED_SELECT. just so.
         - use enum instead of #define for most constants.
         - improve compatibility to older C++ compilers.
+        - ev_run/ev_default_loop/ev_break/ev_loop_new have now default
+          arguments when compiled as C++.
 
 3.9  Thu Dec 31 07:59:59 CET 2009
        - signalfd is no longer used by default and has to be requested
diff --git a/ev++.h b/ev++.h
index b764487fdf28037f9467b8a5aebdc0696575ade9..20fcd7fe4b032acfb7fe9ea14613ccf56f3d71c3 100644 (file)
--- a/ev++.h
+++ b/ev++.h
@@ -64,7 +64,10 @@ namespace ev {
     NONE     = EV_NONE,
     READ     = EV_READ,
     WRITE    = EV_WRITE,
+#if EV_COMPAT3
     TIMEOUT  = EV_TIMEOUT,
+#endif
+    TIMER    = EV_TIMER,
     PERIODIC = EV_PERIODIC,
     SIGNAL   = EV_SIGNAL,
     CHILD    = EV_CHILD,
@@ -95,14 +98,18 @@ namespace ev {
 
   enum
   {
+#if EV_COMPAT3
     NONBLOCK = EVLOOP_NONBLOCK,
-    ONESHOT  = EVLOOP_ONESHOT
+    ONESHOT  = EVLOOP_ONESHOT,
+#endif
+    NOWAIT   = EVRUN_NOWAIT,
+    ONCE     = EVRUN_ONCE
   };
 
   enum how_t
   {
-    ONE = EVUNLOOP_ONE,
-    ALL = EVUNLOOP_ALL
+    ONE = EVBREAK_ONE,
+    ALL = EVBREAK_ALL
   };
 
   struct bad_loop
@@ -188,14 +195,26 @@ namespace ev {
     }
 #endif
 
+#if EV_COMPAT3
     void loop (int flags = 0)
     {
-      ev_loop (EV_AX_ flags);
+      ev_run (EV_AX_ flags);
     }
 
     void unloop (how_t how = ONE) throw ()
     {
-      ev_unloop (EV_AX_ how);
+      ev_break (EV_AX_ how);
+    }
+#endif
+
+    void run (int flags = 0)
+    {
+      ev_run (EV_AX_ flags);
+    }
+
+    void break_loop (how_t how = ONE) throw ()
+    {
+      ev_break (EV_AX_ how);
     }
 
     void post_fork () throw ()
diff --git a/ev.h b/ev.h
index 96e735871a79fba7a9f30e15c71b874c9e1d8c47..941190e5b4e19803aff050499a18d13cf33c24a4 100644 (file)
--- a/ev.h
+++ b/ev.h
@@ -147,6 +147,12 @@ typedef double ev_tstamp;
 # include <sys/stat.h>
 #endif
 
+#ifdef __cplusplus
+# define EV_DEFARG(x) = x
+#else
+# define EV_DEFARG(x)
+#endif
+
 /* support multiple event loops? */
 #if EV_MULTIPLICITY
 struct ev_loop;
@@ -194,7 +200,9 @@ enum {
   EV__IOFDSET =       0x80, /* internal use only */
   EV_IO       =    EV_READ, /* alias for type-detection */
   EV_TIMER    = 0x00000100, /* timer timed out */
+#if EV_COMPAT3
   EV_TIMEOUT  =   EV_TIMER, /* pre 4.0 API compatibility */
+#endif
   EV_PERIODIC = 0x00000200, /* periodic timer timed out */
   EV_SIGNAL   = 0x00000400, /* signal was received */
   EV_CHILD    = 0x00000800, /* child/pid had status change */
@@ -513,7 +521,7 @@ ev_default_loop_uc (void)
 /* the default loop is the only one that handles signals and child watchers */
 /* you can call this as often as you like */
 EV_INLINE struct ev_loop *
-ev_default_loop (unsigned int flags)
+ev_default_loop (unsigned int flags EV_DEFARG (0))
 {
   struct ev_loop *loop = ev_default_loop_uc ();
 
@@ -528,7 +536,7 @@ ev_default_loop (unsigned int flags)
 }
 
 /* create and destroy alternative loops that don't handle signals */
-struct ev_loop *ev_loop_new (unsigned int flags);
+struct ev_loop *ev_loop_new (unsigned int flags EV_DEFARG (0));
 void ev_loop_destroy (EV_P);
 void ev_loop_fork (EV_P);
 
@@ -536,7 +544,7 @@ ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after
 
 #else
 
-int ev_default_loop (unsigned int flags); /* returns true when successful */
+int ev_default_loop (unsigned int flags EV_DEFARG (0)); /* returns true when successful */
 
 EV_INLINE ev_tstamp
 ev_now (void)
@@ -593,8 +601,8 @@ enum {
 };
 
 #if EV_PROTOTYPES
-void ev_run (EV_P_ int flags);
-void ev_break (EV_P_ int how); /* set to 1 to break out of event loop, set to 2 to break out of all event loops */
+void ev_run (EV_P_ int flags EV_DEFARG (0));
+void ev_break (EV_P_ int how EV_DEFARG (EVBREAK_ONE)); /* break out of the loop */
 
 /*
  * ref/unref can be used to add or remove a refcount on the mainloop. every watcher