Type-safe signal/slot mechanism for decoupled event notification. More...
#include <signal.h>
Classes | |
| struct | removeConstAndRef |
| Metafunction that strips const and reference qualifiers from a type. More... | |
Public Types | |
| using | Function = std::function< void(Args...)> |
| Callable type that slots must conform to. | |
| template<typename T > | |
| using | RemoveConstAndRef = typename removeConstAndRef< T >::type |
| Convenience alias for removeConstAndRef. | |
Public Member Functions | |
| Signal (void *owner=nullptr, const char *prototype=nullptr) | |
| Signal constructor. | |
| void * | owner () const |
| Returns the owner of this signal, or nullptr if not defined. | |
| const char * | prototype () const |
| Returns the prototype string, or nullptr if not defined. | |
| size_t | connect (Function slot, void *ptr=nullptr) |
| Connects this signal to a callable (lambda or function). | |
| template<typename T > | |
| size_t | connect (T *obj, void(T::*memberFunction)(Args...)) |
| Connects this signal to an object member function. | |
| void | disconnect (size_t slotID) |
| Disconnects a slot by its connection ID. | |
| template<typename T > | |
| void | disconnect (const T *object, void(T::*memberFunction)(Args...)) |
| Disconnects a slot by its object and member function. | |
| template<typename T > | |
| void | disconnectFromObject (const T *object) |
| Disconnects all slots connected from the given object. | |
| void | emit (Args... args) const |
| Emits this signal. | |
Static Public Member Functions | |
| static VariantList | pack (Args... args) |
| Packs the arguments into a VariantList. | |
Type-safe signal/slot mechanism for decoupled event notification.
Allows connecting callable slots (lambdas or member functions) that are invoked when the signal is emitted. Template parameters define the argument types passed through the signal.
| Args | The argument types carried by the signal. |
|
inline |
Signal constructor.
| [in] | owner | Pointer to the object/data that owns this signal. |
| [in] | prototype | Optional prototype string describing the signal signature. |
|
inline |
Connects this signal to a callable (lambda or function).
The callable prototype must match the argument types used to define this signal.
| slot | The callable to invoke when the signal is emitted. |
| ptr | Optional pointer associated with this connection, used for later disconnection by object. |
|
inline |
Connects this signal to an object member function.
The member function prototype must match the argument types used to define this signal.
Example usage:
| T | The object type. |
| obj | Pointer to the object instance. |
| memberFunction | Pointer to the member function to call. |
|
inline |
Disconnects a slot by its object and member function.
Example usage:
| T | The object type. |
| object | Pointer to the object whose slot should be removed. |
| memberFunction | Pointer to the member function to disconnect. |
Disconnects all slots connected from the given object.
| T | The object type. |
| object | Pointer to the object whose slots should be removed. |
Emits this signal.
Invokes every connected slot with the supplied arguments, in the order they were connected.
| args | The arguments to forward to each slot. |
|
inlinestatic |
Packs the arguments into a VariantList.
Packs all the signal parameters into a VariantList object that can be used to marshal the data to either defer the emit or pass it as an event to another object (e.g. on another thread). Note, this will also make copies of any arguments passed by reference as the references probably won't be valid by the time you want to use the container.
| args | The signal arguments to pack. |