Signal slots for the D programming language

To summarize, signals are used to store multiple callbacks and invoke them in one call. This library uses a templated design with managed connections, inspired by boost::signals. The documentation has examples and an explanation, see the testcases.d module for more.

Comments, bugs, suggestions are welcome at: lutger.blijdestijn at gmail.com.

Example:
import std.stdio, sslot.signal;

void main()
{
    auto output = new Signal!(void, char[]);
    output ~= (char[] msg) { writefln(msg); };
    output("hello world");
}

(3 july 2007) - sslot version 0.32

sslot is fixed to work with dmd 1.014 and above and set up to work with dsss

(5 March 2007) - sslot version 0.31, fixes and thread-safety

Disconnection issues have been fixed and a thread-safe signal implementation has been added. Thanks to Sean Kelly for suggesting an implementation.
The thread safe implementation has not been tested very much yet...

(29 March 2007) - sslot version 0.3 is bugged

Although I have been careful with corner cases, sslot has a bug that can appear if a slot is disconnected when a signal is emitting. I hope to fix it soon.

(28 March 2007) - sslot version 0.3

sslot now requires dmd 1.10. A lot of changes are under the hood, most visible is the ability to connect an Object delegate without the need to supply the object reference for a managed connection.
Here is the full changelog: The Slot policy template and combiners as mapReduce will need some more work and documentation. Once this is done it should be relatively easy to customize a signal in order to, for example, integrate it with a reflection api. That should allow for connections being made from resource descriptions, amongst other things.

(16 December 2006) - sslot version 0.22

Another bugfix related to malloc & friends. This one occured when clearing a signal multiple times.
I've also added opAssign which is just clear + connect and reduced the size of a signal object by moving some stuff into the module / static class level.

(7 December 2006) - sslot version 0.21, bugfix

Fixed an array bounds error occuring in the case of deletion of multiple slots. Oops.

(17 November 2006) - sslot version 0.2

sslot is updated to make use of the new features in D, and some minor improvements have been added. I've also included a test module.

(2 November 2006) - I love deprecation, don't you?

It is the sign of moving forward, time to kill your darlings. D has template varargs now and a standard signal slots implementation. Furthermore, all the fluff that's needed for slots - mixin, interface - has become redundant due to the possibility of hooking a callback delegate on object destruction.
I'm not sure yet what to do with sslot, the current signals implementation in Phobos is nice but lacks some features I would like to have myself (return values, connecting other types than delegates from Ojects). With the hooks available and template varargs it is trivial to implement however. In fact the implementation of sslot is similar enough (but much more verbose) to phobos Signals to just refactor it a little to make use of the new features.

Whilst signals are very nice to have in standard D, the really cool feature is template varargs. Just as an example, here is a function similar to one in the boost fusion docs that takes an arbitrary sequence of objects and writes the xml values of only the pointer types:

void xmlPrintPointers(T...)(T seq)
{
    foreach(element; seq)
        static if(is(typeof(element) a : a*))
            writefln("<",  typeid(typeof(*element)), ">", *element,
                     "</", typeid(typeof(*element)), ">");
}

int a = 5;
char[] Foo = "bar";

xmlPrintPointers(&a, a, &Foo);

Output:

<int> 5 </int>
<char[]> bar </char[]>

(27 October 2006) - new version

Someone in the D newsgroup pointed out that connected objects in sslot are not garbage collected. I have been working on a new version in which this flaw is corrected, and uploaded a freshly rewritten sslot. The api remains mostly the same, but some minor things have changed, which you can see in the docs. I gave this one a version number because I think I got it right now.
Garbage collection works now properly. At the same time I have removed some bloat, performance should be better (I have done no benchmarks yet).
Beware though, I have done some testing but for the most part this version is untested, so some bugs might have to be squashed still. Besides this, I still haven't coded support for more than 4 parameters, I'll fix this soon. Enjoy.

Site is under construction ...

I plan to construct this site with more content (mostly) related to programming in D. For now, there is only the signal slot library I wrote. As I learn how to make a reasonably nice website, this will be updated.


iFastNet Banner Free Hosting