#include <ImFusion/Core/DeprecatedSignal.h>
Deprecation layer for signals.
More...
template<typename MainSignalType, typename... ArgTypes>
class ImFusion::DeprecatedSignal< MainSignalType, ArgTypes >
Deprecation layer for signals.
Allows to change the name and signature of a signal without breaking existing code.
By turning an existing Signal into a DeprecatedSignal and linking it to the new signal (the main signal), you can change signals while keeping backwards compatibility. Both emission of the DeprecatedSignal and the main signal will cause the same observers to be called, and there can be observers connected to both signals at the same time. The DeprecatedSignal and the main signal share the same connections and other state, but the arguments are converted between the old and the new signal with conversion function specified during instantiation of the DeprecatedSignal.
- Note
- The thread safety of the DeprecatedSignal is the same as the main signal. DeprecatedSignal can be used in combination with ProtectedSignal as the main signal.
- Template Parameters
-
MainSignalType | The type of the main signal to which this signal is linked. |
ArgTypes | The types of the arguments of this signal. |
Example:
signalNewNumber,
},
const std::string& measurementString = std::get<0>(newArguments);
}};
DeprecatedSignal(MainSignalType &mainSignal, ConversionFunctionToMainSignal convertToMainSignal, ConversionFunctionFromMainSignal convertFromMainSignal)
Construct the DeprecatedSignal with the main signal and the conversion functions.
Definition DeprecatedSignal.h:63
SignalImpl< false, ArgTypes... > Signal
Alias for a non-protected signal, which is reentrant but not thread-safe.
Definition Signal.h:341
- See also
- Signals and Slots, SignalReceiver, Signal, ProtectedSignal, SignalConnection, DeprecatedSignal
|
using | FunctionType = std::function<void(ArgTypes...)> |
| Typedef for a std::function matching ths signal type.
|
|
using | ArgumentTuple = std::tuple<ArgTypes...> |
| Typedef for a tuple of the arguments of this signal.
|
|
using | ConversionFunctionToMainSignal = std::function<typename MainSignalType::ArgumentTuple(ArgTypes...)> |
| Function type for converting the arguments of this signal to the main signal.
|
|
using | ConversionFunctionFromMainSignal = std::function<ArgumentTuple(typename MainSignalType::ArgumentTuple)> |
| Function type for converting the arguments of the main signal to this signal.
|
|
|
| DeprecatedSignal (MainSignalType &mainSignal, ConversionFunctionToMainSignal convertToMainSignal, ConversionFunctionFromMainSignal convertFromMainSignal) |
| Construct the DeprecatedSignal with the main signal and the conversion functions.
|
|
| DeprecatedSignal (const DeprecatedSignal< MainSignalType, ArgTypes... > &other)=delete |
|
DeprecatedSignal< MainSignalType, ArgTypes... > & | operator= (const DeprecatedSignal< MainSignalType, ArgTypes... > &rhs)=delete |
|
| ~DeprecatedSignal () 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.
|
|
◆ connect() [1/3]
template<typename MainSignalType, typename... ArgTypes>
template<typename T>
Connects the given method pointer as slot to this signal.
- Parameters
-
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(). |
- Returns
- SignalConnection object for identifying the established signal-slot connection. You can use this to disconnect from the signal at any time.
- Note
- SignalImpl will track the lifetime of object and automatically disconnect the slot if object is deleted during the lifetime of this signal.
◆ connect() [2/3]
template<typename MainSignalType, typename... ArgTypes>
Connects the given free function as slot to this signal using object as lifetime tracker.
- Parameters
-
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(). |
- Returns
- SignalConnection object for identifying the established signal-slot connection. You can use this to disconnect from the signal at any time.
- Note
- SignalImpl will track the lifetime of object and automatically disconnect the slot if object is deleted during the lifetime of this signal.
◆ connect() [3/3]
template<typename MainSignalType, typename... ArgTypes>
Connects the given free function as slot to this signal.
- Parameters
-
- Returns
- SignalConnection object for identifying the established signal-slot connection. You can use this to disconnect from the signal at any time.
- Warning
- This overload is potentially dangerous, since there is no way for this signal to track the lifetime of func. Thus, you have to ensure that func will remain valid for the entire lifetime of this signal or use disconnect() on the returned SignalConnection object when needed.
◆ disconnect() [1/2]
template<typename MainSignalType, typename... ArgTypes>
Removes the given connection.
- Parameters
-
- Returns
- True if a slot was found and deleted, false otherwise.
Implements SignalBase.
◆ disconnect() [2/2]
template<typename MainSignalType, typename... ArgTypes>
Disconnects all slots of the given object from this signal.
- Parameters
-
object | Pointer to the object holding the slot. If the pointer is 0 all connections to free functions are disconnected. |
- Returns
- The number of connections that were found and disconnected.
◆ disconnectAll()
template<typename MainSignalType, typename... ArgTypes>
int disconnectAll |
( |
| ) |
const |
|
inline |
Disconnects all slots from this signal.
- Returns
- The number of connections that were found and disconnected.
◆ emitSignal()
template<typename MainSignalType, typename... ArgTypes>
void emitSignal |
( |
ArgTypes... | args | ) |
const |
|
inline |
Calls all connected slots with the given arguments.
- Note
- This function will not allow for recursive emitting of the same signal and nested emits will be discarded. Use allowOneRecursion() to explicitly opt-in for recursive signal emitting support.
◆ allowOneRecursion()
template<typename MainSignalType, typename... ArgTypes>
void allowOneRecursion |
( |
| ) |
const |
|
inline |
Allows a single recursive emitting of this signal if called while the signal is emitting.
Otherwise does nothing.
- Note
- Call this within your slot function if you need to re-emit the same signal. You may use a SignalBlocker to avoid an infinite recursion.
◆ setBlocked()
template<typename MainSignalType, typename... ArgTypes>
bool setBlocked |
( |
bool | muteSignal | ) |
|
|
inlineoverridevirtual |
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.
- Returns
- Previous value of isBlocked().
- See also
- SignalBlocker for a more convenient and exception-safe interface to temporarily block a signal.
Implements SignalBase.
The documentation for this class was generated from the following file:
- ImFusion/Core/DeprecatedSignal.h