Welcome to cyberz's homepage

Sections

Main
Projects
Miscellanea

Links

Links (delicious)

CyberzOrg::Event C++ Library

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 who can emit events and allows connection of (type-safe) callbacks as event handler. 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
}

The new version (0.2) allows emitters to be declared without using previous (useless) EmitterTable syntax and having signals depending on the emitter type too (eg a signal who has the emitter type as parameter).

You can look at sources or download a tarball. Any feedback is well accepted at (email image).

OpenSolaris: Love at First Boot