siplasplas
A library for C++ reflection and introspection
Signals

A simple multi-threaded message passing system. More...

Classes

class  cpp::AsyncSink
 Implements an asynchronous signal sink suited for communication between different threads. More...
 
class  cpp::SignalEmitter
 Class that can send and receive signals from other emitters. More...
 
class  cpp::SignalSink
 Interface to the signals sink API. More...
 
class  cpp::SyncSink
 Implements a direct connection to the destination function. More...
 

Functions

template<typename Class >
auto cpp::emit (const Class &object)
 Emits a const signal from the given const SignalEmitter. More...
 
template<typename Class >
auto cpp::emit (Class &object)
 Emits a signal from the given SignalEmitter. More...
 

Detailed Description

A simple multi-threaded message passing system.

The siplasplas-signals module implements a simple message passing system where objects raise signals in the form of member functions which cause connected functions to be invoked.

Despite other message passing systems, siplasplas does not have a class representation for the connection concept, but represents connections as associations between SignalEmitters and SignalSinks. A signal sink is the destination of a raised signal, and keeps track of the callee function (And or callee object).

siplasplas-signals is not specifically designed with performance in mind but with simplicity of user code:

Function Documentation

template<typename Class >
auto cpp::emit ( const Class &  object)

Emits a const signal from the given const SignalEmitter.

This function provides a succint way to emit signals from objects by providing a fake object to pick the required signal. Overloaded signals are supported.

Template Parameters
ClassType of the signal emitter. Static reflection metadata of this class should be available in the translation unit the emit() function is invoked.
Parameters
objectObject which emits the signal
Returns
A cpp::static_reflection::Class<Class>::FakeObject instance which invokes the selected signal.
class Foo : public cpp::SignalEmitter
{
public:
void signal();
void signal(int i);
};
Foo foo;
cpp::emit(foo).signal(); // Emits &Foo::signal from foo
cpp::emit(foo).signal(42); // Emits &Foo::signal(int) with param '42' from Foo
Examples:
signals/signals.cpp.
template<typename Class >
auto cpp::emit ( Class &  object)

Emits a signal from the given SignalEmitter.

This function provides a succint way to emit signals from objects by providing a fake object to pick the required signal. Overloaded signals are supported.

Template Parameters
ClassType of the signal emitter. Static reflection metadata of this class should be available in the translation unit the emit() function is invoked.
Parameters
objectObject which emits the signal
Returns
A cpp::static_reflection::Class<Class>::FakeObject instance which invokes the selected signal.
class Foo : public cpp::SignalEmitter
{
public:
void signal();
void signal(int i);
};
Foo foo;
cpp::emit(foo).signal(); // Emits &Foo::signal from foo
cpp::emit(foo).signal(42); // Emits &Foo::signal(int) with param '42' from Foo