![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/Signal.h>
Implementation for a specific signal with the given signature. More...
Inheritance diagram for SignalImpl< UseMutex, ArgTypes >:Implementation for a specific signal with the given signature.
You can connect an arbitrary amount of slots (i.e. function pointers) to this signal which will be called on emitSignal(). If you connect slots to member functions of classes inheriting from SignalReceiver, SignalImpl will track the lifetime of the object and automatically disconnect the slot if the object is deleted. Thus, in this case the order of destruction of signal and slot does not matter.
Based on the first template parameter the signal will be thread-safe or not. If you set UseMutex to false concurrent access will not be safe. Setting UseMutex to true will increase the signal's memory footprint by a mutex in order to make this class thread-safe. You can use the aliases Signal and ProtectedSignal to choose between the reentrant and thread-safe implementation.
By default, if a recursive emission of the same signal is detected, observers will not be notified and an assertion will be raised — unless the connection that initiated the recursion is blocked. This design was chosen since such situations usually indicate an accidental signal loop due to bidirectional dependencies which should be avoided. However, you can explicitly disable these checks by calling allowOneRecursion() if you expect a recursion to occur.
Furthermore, it is safe to connect or disconnect a to/from signal while it is currently emitting: disconnecting will have immediate effect while new connections will only become active after emitting has completed.
| UseMutex | Flag whether to protect access to the signal by a mutex. |
| ArgTypes | Signature of the signal/function to call. |
Public Types | |
| using | FunctionType = std::function<void(ArgTypes...)> |
| Typedef for a std::function matching ths signal type. | |
| using | ArgumentTuple = std::tuple<ArgTypes...> |
Public Member Functions | |
| SignalImpl () | |
| Default constructor. | |
| SignalImpl (const SignalImpl< UseMutex, ArgTypes... > &other) | |
| Copy constructor, will not copy any connections.. | |
| SignalImpl< UseMutex, ArgTypes... > & | operator= (const SignalImpl< UseMutex, ArgTypes... > &rhs) |
| Assignment operator, disconnects all existing connections but does not transfer the connections of rhs. | |
| ~SignalImpl () override | |
| Virtual destructor, deletes all connections and thereby also disconnects from all connected slots. | |
| template<typename T> | |
| std::shared_ptr< SignalConnection > | connect (const T *object, void(T::*methodptr)(ArgTypes...)) const |
| Connects the given method pointer as slot to this signal. | |
| std::shared_ptr< SignalConnection > | connect (const SignalReceiver *object, FunctionType func) const |
| Connects the given free function as slot to this signal using object as lifetime tracker. | |
| std::shared_ptr< SignalConnection > | connect (FunctionType func) const |
| Connects the given free function as slot to this signal. | |
| bool | disconnect (SignalConnection *connection) const override |
| Removes the given connection. | |
| int | disconnect (const SignalReceiver *object) const |
| Disconnects all slots of the given object from this signal. | |
| int | disconnectAll () const |
| Disconnects all slots from this signal. | |
| void | emitSignal (ArgTypes... args) const |
| Calls all connected slots with the given arguments. | |
| void | allowOneRecursion () const |
| Allows a single recursive emitting of this signal if called while the signal is emitting. | |
| bool | setBlocked (bool muteSignal) override |
| Set the flag whether to block notifications of observers for this signal. | |
| bool | isBlocked () const |
| Returns whether notifications of observers for this signal are currently blocked. | |
| int | numConnections () const |
| Returns the current number of connections. | |
| bool | isConnectedTo (const SignalReceiver *receiver) const |
| Returns whether this signal is connected to receiver. | |
| std::shared_ptr< SignalConnection > connect | ( | const T * | object, |
| void(T::* | methodptr )(ArgTypes...) ) const |
Connects the given method pointer as slot to this signal.
| object | Pointer to the receiver object holding the method. Must derive from SignalReceiver. Must not be 0. |
| methodptr | Pointer to method to call on emitSignal(). |
| std::shared_ptr< SignalConnection > connect | ( | const SignalReceiver * | object, |
| FunctionType | func ) const |
Connects the given free function as slot to this signal using object as lifetime tracker.
| object | SignalReceiver to be used for lifetime tracking. If not null the connection will be disconnected automatically when the receiver is deleted. |
| func | Function to call on emitSignal(). |
| std::shared_ptr< SignalConnection > connect | ( | FunctionType | func | ) | const |
Connects the given free function as slot to this signal.
| func | Function to call on emitSignal(). |
|
overridevirtual |
Removes the given connection.
| connection | Pointer to the SignalConnection object returned during connect(). |
Implements SignalBase.
| int disconnect | ( | const SignalReceiver * | object | ) | const |
Disconnects all slots of the given object from this signal.
| object | Pointer to the object holding the slot. If the pointer is 0 all connections to free functions are disconnected. |
| int disconnectAll | ( | ) | const |
Disconnects all slots from this signal.
| void emitSignal | ( | ArgTypes... | args | ) | const |
Calls all connected slots with the given arguments.
| void allowOneRecursion | ( | ) | const |
Allows a single recursive emitting of this signal if called while the signal is emitting.
Otherwise does nothing.
|
overridevirtual |
Set the flag whether to block notifications of observers for this signal.
If muteSignal is true, any subsequent call to emitSignal will do nothing. The caller is responsible to reset the blocked state to its original value when appropriate.
Implements SignalBase.