neosigslot

neosigslot is a lightweight C++ signals and slots library that has the following features:

neosigslot requires at least C++98/C++03 and TR1 to work as it uses std::bind and friends in its implementation.

neosigslot requires Boost for the mutex locking threading policy; if you cannot use (or don't want to use) Boost then the just edit locking_policy.hpp to remove the dependency but you should be using Boost, really.

Coming soon: more documentation on how to use neosigslot.

You can download the implementation here (v1.1.2) (changelog).

Example which demonstrates re-entrancy and a slot being be destroyed whilst it is being notified of a signal:

#include <neolib/neolib.hpp>
#include <neolib/signal.hpp>
#include <neolib/slot.hpp>
#include <iostream>

class foo : public neolib::has_slots<>
{
public:
	neolib::signal<void(const std::string&)> on_event;
public:
	foo()
	{
		on_event(*this, &foo::handler);
	}
public:
	void handler(const std::string& aArgument)
	{
		static int counter;
		std::cout << "In handler, counter = " << counter << ", argument = '" << aArgument << "'" << std::endl;
		switch(counter)
		{
		case 0:
			++counter;
			on_event.trigger(", world!");
			break;
		case 1:
			delete this;
			break;
		}
	}
};

int main()
{
	foo* o = new foo;
	o->on_event.trigger("Hello");
}

The output of which is:

In handler, counter = 0, argument = 'Hello'
In handler, counter = 1, argument = ', world!'

Example of using "signals with keys":

class app
{
    ...
    neolib::signal_with_key<int, void()> on_command;
    ...
};

...

myApp.on_command(ID_FILE_OPEN, *this, &my_view::on_file_open);
myApp.on_command(ID_FILE_CLOSE, *this, &my_view::on_file_close);
myApp.on_command(ID_FILE_SAVE, *this, &my_view::on_file_save);

 


You can e-mail comments to the author.

Back to project page