SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
spark::patterns::Signal< Args > Class Template Reference

A signal is a class used to emit events. More...

#include <Signal.h>

Public Member Functions

 Signal (const Signal &signal)=delete
 
 Signal (Signal &&signal) noexcept
 
Signaloperator= (const Signal &signal)=delete
 
Signaloperator= (Signal &&signal) noexcept
 
std::size_t connect (Slot< Args... > *slot)
 Connects a slot to the signal.
 
std::size_t connect (Slot< Args... > &slot)
 Connects a slot to the signal.
 
std::size_t connect (Slot< Args... > &&slot)
 Connects a slot to the signal.
 
std::size_t connect (const std::function< void(Args...)> &callback)
 Connects a callback to the signal. This will create an internal slot. Avoids the need to create an slot in place.
 
std::size_t connect (std::function< void(Args...)> &&callback)
 Connects a callback to the signal. This will create an internal slot. Avoids the need to create an slot in place.
 
void disconnect (std::size_t key)
 Disconnects a slot from the signal.
 
void disconnect (Slot< Args... > *slot)
 Disconnects a slot from the signal.
 
void disconnect (Slot< Args... > &slot)
 Disconnects a slot from the signal.
 
void clear ()
 Disconnects all connected slots from the signal.
 
bool isConnected (std::size_t key) const
 Finds if a slot is connected to the signal.
 
std::vector< std::size_t > connectedKeys () const
 Gets all the keys of the connected slots.
 
std::vector< const Slot< Args... > * > connectedSlots () const
 Gets all the connected slots.
 
template<typename... FnArgs>
void emit (FnArgs &&... args) const
 Emits the signal to all connected slots.
 
void operator() (Args &&... args) const
 Emits the signal to all connected slots. Same as emit.
 

Detailed Description

template<typename... Args>
class spark::patterns::Signal< Args >

A signal is a class used to emit events.

Template Parameters
ArgsThe types of the arguments emitted in the event.

Member Function Documentation

◆ connect() [1/5]

template<typename... Args>
std::size_t spark::patterns::Signal< Args >::connect ( const std::function< void(Args...)> & callback)

Connects a callback to the signal. This will create an internal slot. Avoids the need to create an slot in place.

Parameters
callbackA callback to connect.
Returns
The key of the slot.

◆ connect() [2/5]

template<typename... Args>
std::size_t spark::patterns::Signal< Args >::connect ( Slot< Args... > && slot)

Connects a slot to the signal.

Parameters
slotThe slot to connect.
Returns
The key of the slot.

◆ connect() [3/5]

template<typename... Args>
std::size_t spark::patterns::Signal< Args >::connect ( Slot< Args... > & slot)

Connects a slot to the signal.

Parameters
slotA reference to the slot to connect.
Returns
The key of the slot.

◆ connect() [4/5]

template<typename... Args>
std::size_t spark::patterns::Signal< Args >::connect ( Slot< Args... > * slot)

Connects a slot to the signal.

Parameters
slotThe address of the slot to connect.
Returns
The key of the slot.

◆ connect() [5/5]

template<typename... Args>
std::size_t spark::patterns::Signal< Args >::connect ( std::function< void(Args...)> && callback)

Connects a callback to the signal. This will create an internal slot. Avoids the need to create an slot in place.

Parameters
callbackA callback to connect.
Returns
The key of the slot.

◆ connectedKeys()

template<typename... Args>
std::vector< std::size_t > spark::patterns::Signal< Args >::connectedKeys ( ) const
nodiscard

Gets all the keys of the connected slots.

Returns
A std::vector containing the keys of the connected slots.

◆ connectedSlots()

template<typename... Args>
std::vector< const Slot< Args... > * > spark::patterns::Signal< Args >::connectedSlots ( ) const
nodiscard

Gets all the connected slots.

Returns
A std::vector containing pointers to the connected slots.

◆ disconnect() [1/3]

template<typename... Args>
void spark::patterns::Signal< Args >::disconnect ( Slot< Args... > & slot)

Disconnects a slot from the signal.

Parameters
slotA reference to the slot to disconnect.

◆ disconnect() [2/3]

template<typename... Args>
void spark::patterns::Signal< Args >::disconnect ( Slot< Args... > * slot)

Disconnects a slot from the signal.

Parameters
slotThe address of the slot to disconnect.

◆ disconnect() [3/3]

template<typename... Args>
void spark::patterns::Signal< Args >::disconnect ( std::size_t key)

Disconnects a slot from the signal.

Parameters
keyThe key of the slot to disconnect.

◆ emit()

template<typename... Args>
template<typename... FnArgs>
void spark::patterns::Signal< Args >::emit ( FnArgs &&... args) const

Emits the signal to all connected slots.

Template Parameters
FnArgsThe types of the arguments to emit. Must be convertible to the signal arguments.
Parameters
argsThe arguments for the slots.

◆ isConnected()

template<typename... Args>
bool spark::patterns::Signal< Args >::isConnected ( std::size_t key) const
nodiscard

Finds if a slot is connected to the signal.

Parameters
keyThe key of the slot to find.
Returns
True if the slot is connected, false otherwise.

◆ operator()()

template<typename... Args>
void spark::patterns::Signal< Args >::operator() ( Args &&... args) const

Emits the signal to all connected slots. Same as emit.

Parameters
argsThe arguments for the slots.