s11n.net
Bringing serialization into the 21st century... bit by bit.
Project powered by:
SourceForge.net

The sigslot library

A simple templates-based signals/slots implementation.



This distribution of sigslot is a hacked copy of Sarah Thompson's signals and slots lib. It is a Public Domain templates-based implementation of the "signals and slots" model of object messaging. It ships as a standalone set of header files, with no 3rd-party library requirements other than the STL. It's Makefile requires perl in order to generate some header files, however.

This mutation of Sarah's work has been updated to work with newer gcc versions, has a slightly different interface, and has been generally refactored significantly, but works essentially the same as Sarah intended it to. It goes without saying: bug reports go to me, not her, and praise goes to her, not me.

You can download the sources from the downloads page. The list of changes from Sarah's distribution is in sigslot.hpp.

There are several examples in the distribution tarball: see test.cpp and run make to see a list of the test-related targets.

Things worth being aware of, especially if you've used Sarah's original distribution of this library:
  • There is no shared or static library to build: this is a header-only implementation. The provided Makefile will install the headers under SOMEPREFIX/include/s11n.net/sigslot. When compiling with sigslot you should add -ISOMEPREFIX/include to your compiler flags and use #include <s11n.net/sigslot/sigslot.hpp> to include the sigslot support (which also includes several generated files, for signals with more than 1 argument). The classes all live in the sigslot namespace.
  • The provided Makefile creates some repetative implementation code for signals/slots with up to 6 arguments. If you need slots with more arguments, look at the Makefile for instructions on how it's done.
  • It is very strict in it's typing rules. It is not as flexible as, e.g., the Boost signals/slots library in this regard (but also does not require the Boost libraries). Sarah's documentation, available via her site, explains why this is so.
  • It's slots system only allows for slots which return void. An annoying, but relatively minor, limitation. i don't see a way to fix this in the current architecture, and i don't have any clever solutions of my own. :/
  • Client-side types connecting to signals must either subclass sigslot::has_slots or connect using a sigslot::slot_proxy object.
  • The interface used in this distribution is slightly different from Sarah's original interface, partly to ease maintenance and client-side usage, and partly to allow the mixing of this library and Qt in the same code. (Qt unfortunately defines macros which collide with the 'emit' and 'connect' functions used by almost all other sig/slot interfaces.)
  • The threading model which is so central to Sarah's interface no longer intrudes into the public interface. This notably simplifies client-side usage. Locking is still supported, but is no longer controlled on a per-type basis (which i thought was way overkill for this library, and unduly intruded on the client). See the header file for how this is done.