← API Reference Class

template<typename ... Args> asge::signals::Signal

This class represents a simple Thread-safe Signal.

#include <Signal.hpp>

In the signals and slot design pattern a signal is represented by a function ( the actual emitted signal ) and a number of connections connecting the signal with a number of slots ( callback functions ) which must have the same signature of the signaling function. Valid connections are created using the Signal::Connect method. When emitting the signal, before calling all the releated slot functions, it checks for invalid connections and in case they exists it disconnects them from itself, in some sense performing automatic-disconnection.

Differently from the more generic Observer or Event Dispatching design pattern, the Signal and Slot pattern heavily relies on type safety, given that the signal and all connected slots must have the same function signature. This is obtained via its template parameter arguments.

Parameters
Args

The type of input parameters of the signal

Public Types

#using conn_type = Connection< Args... >
#using slot_type = std::function< void(Args...)>

Private Types

#using lifetime_ptr = std::shared_ptr< void >private
#using lifetime_token = std::weak_ptr< void >private
#using conn_container = std::map< size_t, slot_info >private

Friends

#friend Connection< Args... >private

Private Attributes

#std::shared_ptr< conn_container > m_Connectionsprivate

Static Private Attributes

#static std::mutex m_Mutexprivate

Public Member Functions

#Signal()
#conn_type Connect(slot_type inCallback, lifetime_ptr inLfToken=nullptr)

Connect a slot to the current signal.

The connection is managed either using a lifetime token or manually.

Parameters
inCallback

The callback to run when emitting the signal

inLfToken

The lifetime token to handle disconnection

#void Emit(Args... inArgs)
#std::size_t GetNofConnections() const