+/**
+ * Helper functor to use an arbitrary member function as an event handler.
+ *
+ * With this wrapper, you can use any object method, which accepts the right
+ * parameters (int, short) and returns void, as an event handler. This way you
+ * don't have to overload the operator() which can be confusing depending on the
+ * context.
+ *
+ * You can see an usage example in the Examples Section.
+ */
+template < typename O, typename M >
+struct mem_cb
+{
+ /**
+ * Member function callback constructor.
+ *
+ * It expects to receive a class as the first parameter (O), and a
+ * member function (of that class O) as the second parameter.
+ *
+ * When this instance is called with fd and ev as function arguments,
+ * object.method(fd, ev) will be called.
+ *
+ * @param object Object to be used.
+ * @param method Method to be called.
+ */
+ mem_cb(O& object, M method) throw():
+ _object(object), _method(method) {}
+ void operator() (int fd, short ev) { (_object.*_method)(fd, ev); }
+ protected:
+ O& _object;
+ M _method;
+}; // struct mem_cb