CyberzOrg::Event library: typesafe event handling in C++
Event is a little library built on top of boost::signal and boost::mpl that allows the user to declare in a simple way an object that can emit events and allow connection of (type-safe) callbacks as event handler to them. Usage is pretty straightforward, as shown in test/hello.cc:
#include <iostream>
#include "event.h"
enum { HELLO /* event type */ };
using namespace CyberzOrg::Event;
struct HelloEmitter
: Emitter<
Event<HELLO, void (const std::string &)>
>
{ };
void callback(const std::string &s) {
std::cout << "Event HELLO: " << s << std::endl;
}
int main() {
HelloEmitter hello;
// preferred syntax (useful if event emitter has the event table depending on itself,
// in such case getSignal method is not directly visible).
getSignal<HELLO>(hello).connect(callback); // connect signal handler (callback)
getSignal<HELLO>(hello)("hello world"); // fire signal
// easy syntax
hello.getSignal<HELLO>().connect(callback); // connect signal handler (callback)
hello.getSignal<HELLO>()("hello world"); // fire signal
}
You can look at sources or download a tarball. Any feedback is well accepted.