ImFusion SDK 4.3
DeprecatedSignal< MainSignalType, ArgTypes > Class Template Referencefinal

#include <ImFusion/Core/DeprecatedSignal.h>

Deprecation layer for signals. More...

+ Inheritance diagram for DeprecatedSignal< MainSignalType, ArgTypes >:

Detailed Description

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
MainSignalTypeThe type of the main signal to which this signal is linked.
ArgTypesThe types of the arguments of this signal.

Example:

// Previous signal definition (pre-deprecation)
Signal<int> signalNewNumber;
// New signal definition including the old signal as deprecated signal
Signal<std::string> signalNewMeasurement;
signalNewNumber,
// Conversion of the old signal arguments to the new signal arguments, returned as a tuple
[](int number) -> std::tuple<std::string> {
},
// Conversion of the new signal arguments (passed as a tuple) to the old signal arguments, returned as a tuple
const std::string& measurementString = std::get<0>(newArguments);
return std::make_tuple(std::stoi(measurementString));
}};
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
T make_tuple(T... args)
T stoi(T... args)
T to_string(T... args)
See also
Signals and Slots, SignalReceiver, Signal, ProtectedSignal, SignalConnection, DeprecatedSignal

Public Types

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.
 

Public Member Functions

 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< SignalConnectionconnect (const T *object, void(T::*methodptr)(ArgTypes...)) const
 Connects the given method pointer as slot to this signal.
 
std::shared_ptr< SignalConnectionconnect (const SignalReceiver *object, FunctionType func) const
 Connects the given free function as slot to this signal using object as lifetime tracker.
 
std::shared_ptr< SignalConnectionconnect (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.
 

Member Function Documentation

◆ connect() [1/3]

template<typename MainSignalType, typename... ArgTypes>
template<typename T>
std::shared_ptr< SignalConnection > connect ( const T * object,
void(T::* methodptr )(ArgTypes...) ) const
inline

Connects the given method pointer as slot to this signal.

Parameters
objectPointer to the receiver object holding the method. Must derive from SignalReceiver. Must not be 0.
methodptrPointer 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>
std::shared_ptr< SignalConnection > connect ( const SignalReceiver * object,
FunctionType func ) const
inline

Connects the given free function as slot to this signal using object as lifetime tracker.

Parameters
objectSignalReceiver to be used for lifetime tracking. If not null the connection will be disconnected automatically when the receiver is deleted.
funcFunction 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>
std::shared_ptr< SignalConnection > connect ( FunctionType func) const
inline

Connects the given free function as slot to this signal.

Parameters
funcFunction 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.
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>
bool disconnect ( SignalConnection * connection) const
inlineoverridevirtual

Removes the given connection.

Parameters
connectionPointer to the SignalConnection object returned during connect().
Returns
True if a slot was found and deleted, false otherwise.

Implements SignalBase.

◆ disconnect() [2/2]

template<typename MainSignalType, typename... ArgTypes>
int disconnect ( const SignalReceiver * object) const
inline

Disconnects all slots of the given object from this signal.

Parameters
objectPointer 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:
Search Tab / S to search, Esc to close