E-MailRelay

Classes | Typedefs | Functions
G::Slot Namespace Reference

A callback mechanism that isolates event sinks from event sources. More...

## Classes
struct | Binder
| A functor class template that contains the target object pointer and method pointer, similar to c++20 bind_front(&T::fn,tp). More...
struct | Signal
| A slot holder, with connect() and emit() methods. More...
struct | SignalImp
| A slot/signal scoping class. More...
struct | Slot
| A slot class template that is parameterised only on the target method's signature (with an implicit void return) and not on the target class. More...

## Typedefs
using | Signal0 = Signal<>
template<typename T >
using | Signal1 = Signal< T >
template<typename T1 , typename T2 >
using | Signal2 = Signal< T1, T2 >
template<typename T1 , typename T2 , typename T3 >
using | Signal3 = Signal< T1, T2, T3 >
template<typename T1 , typename T2 , typename T3 , typename T4 >
using | Signal4 = Signal< T1, T2, T3, T4 >
template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >
using | Signal5 = Signal< T1, T2, T3, T4, T5 >
using | Slot0 = Slot<>
template<typename T >
using | Slot1 = Slot< T >
template<typename T1 , typename T2 >
using | Slot2 = Slot< T1, T2 >
template<typename T1 , typename T2 , typename T3 >
using | Slot3 = Slot< T1, T2, T3 >
template<typename T1 , typename T2 , typename T3 , typename T4 >
using | Slot4 = Slot< T1, T2, T3, T4 >
template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >
using | Slot5 = Slot< T1, T2, T3, T4, T5 >

## Functions
template<typename TSink , typename... Args>
Slot< Args... > | slot (TSink &sink, void(TSink::*method)(Args...))
| A factory function for Slot objects. More...

## Detailed Description

A callback mechanism that isolates event sinks from event sources.

The slot/signal pattern has been used in several C++ libraries including libsigc++, Qt and boost, although it is largely redudant with modern C++. The pattern is completely unrelated to ANSI-C or POSIX signals (signal(), sigaction(2)).

Usage:

struct Source
{
G::Slot::Signal<int> m_signal ;
void Source::raiseEvent()
{
m_signal.emit( 123 ) ;
}
} ;
struct Sink
{
void onEvent( int n ) ;
Sink( Source & source ) : m_source(source)
{
source.m_signal.connect( G::Slot::slot(*this,&Sink::onEvent) ) ;
}
~Sink()
{
m_source.m_signal.disconnect() ;
}
Source & m_source ;
} ;
G::Slot::slot
Slot< Args... > slot(TSink &sink, void(TSink::*method)(Args...))
A factory function for Slot objects.
Definition: gslot.h:201
G::Slot::Signal< int >

For comparison the equivalent modern C++ looks like this:

struct Source
{
std::function<void(int)> m_signal ;
void Source::raiseEvent()
{
if( m_signal ) m_signal( 123 ) ; // emit()
}
} ;
struct Sink
{
void onEvent( int n ) ;
Sink( Source & source ) : m_source(source)
{
check( !source.m_signal ) ; // throw if already connected
source.m_signal = std::bind_front(&Sink::onEvent,this) ; // connect(slot())
}
~Sink()
{
m_source.m_signal = nullptr ; // disconnect()
}
Source & m_source ;
} ;

Slot methods should take parameters by value or const reference but beware of emit()ing references to data members of objects that might get deleted. Use temporaries in the emit() call if in doubt.

## Typedef Documentation

## ◆ Signal0

using G::Slot::Signal0 = typedef Signal<>

Definition at line 208 of file gslot.h.

## ◆ Signal1

template<typename T >

using G::Slot::Signal1 = typedef Signal<T>

Definition at line 209 of file gslot.h.

## ◆ Signal2

template<typename T1 , typename T2 >

using G::Slot::Signal2 = typedef Signal<T1,T2>

Definition at line 210 of file gslot.h.

## ◆ Signal3

template<typename T1 , typename T2 , typename T3 >

using G::Slot::Signal3 = typedef Signal<T1,T2,T3>

Definition at line 211 of file gslot.h.

## ◆ Signal4

template<typename T1 , typename T2 , typename T3 , typename T4 >

using G::Slot::Signal4 = typedef Signal<T1,T2,T3,T4>

Definition at line 212 of file gslot.h.

## ◆ Signal5

template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >

using G::Slot::Signal5 = typedef Signal<T1,T2,T3,T4,T5>

Definition at line 213 of file gslot.h.

## ◆ Slot0

using G::Slot::Slot0 = typedef Slot<>

Definition at line 214 of file gslot.h.

## ◆ Slot1

template<typename T >

using G::Slot::Slot1 = typedef Slot<T>

Definition at line 215 of file gslot.h.

## ◆ Slot2

template<typename T1 , typename T2 >

using G::Slot::Slot2 = typedef Slot<T1,T2>

Definition at line 216 of file gslot.h.

## ◆ Slot3

template<typename T1 , typename T2 , typename T3 >

using G::Slot::Slot3 = typedef Slot<T1,T2,T3>

Definition at line 217 of file gslot.h.

## ◆ Slot4

template<typename T1 , typename T2 , typename T3 , typename T4 >

using G::Slot::Slot4 = typedef Slot<T1,T2,T3,T4>

Definition at line 218 of file gslot.h.

## ◆ Slot5

template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >

using G::Slot::Slot5 = typedef Slot<T1,T2,T3,T4,T5>

Definition at line 219 of file gslot.h.

## Function Documentation

## ◆ slot()

template<typename TSink , typename... Args>

Slot< Args... > G::Slot::slot | ( | TSink & | sink,
|  | void(TSink::*)(Args...) | method
| ) |  |

A factory function for Slot objects.

Definition at line 201 of file gslot.h.