WPILibC++ 2024.3.2
wpi::sig::SignalBase< Lockable, T > Class Template Reference

SignalBase is an implementation of the observer pattern, through the use of an emitting object and slots that are connected to the signal and called with supplied arguments when a signal is emitted. More...

#include </home/runner/work/allwpilib/allwpilib/wpiutil/src/main/native/thirdparty/sigslot/include/wpi/Signal.h>

Public Types

using arg_list = trait::typelist< T... >
 
using ext_arg_list = trait::typelist< Connection &, T... >
 

Public Member Functions

 SignalBase () noexcept
 
 ~SignalBase ()
 
 SignalBase (const SignalBase &)=delete
 
SignalBaseoperator= (const SignalBase &)=delete
 
 SignalBase (SignalBase &&o)
 
SignalBaseoperator= (SignalBase &&o)
 
template<typename... A>
void operator() (A &&... a) const
 Emit a signal. More...
 
template<typename Callable >
void connect (Callable &&c)
 Connect a callable of compatible arguments. More...
 
template<typename Callable >
std::enable_if_t< trait::is_callable_v< arg_list, Callable >, Connectionconnect_connection (Callable &&c)
 Connect a callable of compatible arguments, returning a Connection. More...
 
template<typename Callable >
std::enable_if_t< trait::is_callable_v< ext_arg_list, Callable >, Connectionconnect_extended (Callable &&c)
 Connect a callable with an additional Connection argument. More...
 
template<typename Pmf , typename Ptr >
std::enable_if_t< trait::is_callable_v< arg_list, Pmf, Ptr > &&!trait::is_weak_ptr_compatible_v< Ptr >, Connectionconnect (Pmf &&pmf, Ptr &&ptr)
 Overload of connect for pointers over member functions. More...
 
template<typename Pmf , typename Ptr >
std::enable_if_t< trait::is_callable_v< ext_arg_list, Pmf, Ptr > &&!trait::is_weak_ptr_compatible_v< Ptr >, Connectionconnect_extended (Pmf &&pmf, Ptr &&ptr)
 Overload of connect for pointer over member functions and. More...
 
template<typename Pmf , typename Ptr >
std::enable_if_t<!trait::is_callable_v< arg_list, Pmf > &&trait::is_weak_ptr_compatible_v< Ptr >, Connectionconnect (Pmf &&pmf, Ptr &&ptr)
 Overload of connect for lifetime object tracking and automatic disconnection. More...
 
template<typename Callable , typename Trackable >
std::enable_if_t< trait::is_callable_v< arg_list, Callable > &&trait::is_weak_ptr_compatible_v< Trackable >, Connectionconnect (Callable &&c, Trackable &&ptr)
 Overload of connect for lifetime object tracking and automatic disconnection. More...
 
template<typename... CallArgs>
ScopedConnection connect_scoped (CallArgs &&...args)
 Creates a connection whose duration is tied to the return object Use the same semantics as connect. More...
 
void disconnect_all ()
 Disconnects all the slots Safety: Thread safety depends on locking policy. More...
 
void block () noexcept
 Blocks signal emission Safety: thread safe. More...
 
void unblock () noexcept
 Unblocks signal emission Safety: thread safe. More...
 
bool blocked () const noexcept
 Tests blocking state of signal emission. More...
 

Detailed Description

template<typename Lockable, typename... T>
class wpi::sig::SignalBase< Lockable, T >

SignalBase is an implementation of the observer pattern, through the use of an emitting object and slots that are connected to the signal and called with supplied arguments when a signal is emitted.

wpi::SignalBase is the general implementation, whose locking policy must be set in order to decide thread safety guarantees. wpi::Signal and wpi::Signal_st are partial specializations for multi-threaded and single-threaded use.

It does not allow slots to return a value.

Template Parameters
Lockablea lock type to decide the lock policy
T...the argument types of the emitting and slots functions.

Member Typedef Documentation

◆ arg_list

template<typename Lockable , typename... T>
using wpi::sig::SignalBase< Lockable, T >::arg_list = trait::typelist<T...>

◆ ext_arg_list

template<typename Lockable , typename... T>
using wpi::sig::SignalBase< Lockable, T >::ext_arg_list = trait::typelist<Connection&, T...>

Constructor & Destructor Documentation

◆ SignalBase() [1/3]

template<typename Lockable , typename... T>
wpi::sig::SignalBase< Lockable, T >::SignalBase ( )
inlinenoexcept

◆ ~SignalBase()

template<typename Lockable , typename... T>
wpi::sig::SignalBase< Lockable, T >::~SignalBase ( )
inline

◆ SignalBase() [2/3]

template<typename Lockable , typename... T>
wpi::sig::SignalBase< Lockable, T >::SignalBase ( const SignalBase< Lockable, T > &  )
delete

◆ SignalBase() [3/3]

template<typename Lockable , typename... T>
wpi::sig::SignalBase< Lockable, T >::SignalBase ( SignalBase< Lockable, T > &&  o)
inline

Member Function Documentation

◆ block()

template<typename Lockable , typename... T>
void wpi::sig::SignalBase< Lockable, T >::block ( )
inlinenoexcept

Blocks signal emission Safety: thread safe.

◆ blocked()

template<typename Lockable , typename... T>
bool wpi::sig::SignalBase< Lockable, T >::blocked ( ) const
inlinenoexcept

Tests blocking state of signal emission.

◆ connect() [1/4]

template<typename Lockable , typename... T>
template<typename Callable >
void wpi::sig::SignalBase< Lockable, T >::connect ( Callable &&  c)
inline

Connect a callable of compatible arguments.

Effect: Creates and stores a new slot responsible for executing the supplied callable for every subsequent signal emission. Safety: Thread-safety depends on locking policy.

Parameters
ca callable

◆ connect() [2/4]

template<typename Lockable , typename... T>
template<typename Callable , typename Trackable >
std::enable_if_t< trait::is_callable_v< arg_list, Callable > && trait::is_weak_ptr_compatible_v< Trackable >, Connection > wpi::sig::SignalBase< Lockable, T >::connect ( Callable &&  c,
Trackable &&  ptr 
)
inline

Overload of connect for lifetime object tracking and automatic disconnection.

Trackable must be convertible to an object following a loose form of weak pointer concept, by implementing the ADL-detected conversion function to_weak().

This overload covers the case of a standalone callable and unrelated trackable object.

Note: only weak references are stored, a slot does not extend the lifetime of a suppied object.

Parameters
ca callable
ptra trackable object pointer
Returns
a Connection object that can be used to interact with the slot

◆ connect() [3/4]

template<typename Lockable , typename... T>
template<typename Pmf , typename Ptr >
std::enable_if_t< trait::is_callable_v< arg_list, Pmf, Ptr > && !trait::is_weak_ptr_compatible_v< Ptr >, Connection > wpi::sig::SignalBase< Lockable, T >::connect ( Pmf &&  pmf,
Ptr &&  ptr 
)
inline

Overload of connect for pointers over member functions.

Parameters
pmfa pointer over member function
ptran object pointer
Returns
a Connection object that can be used to interact with the slot

◆ connect() [4/4]

template<typename Lockable , typename... T>
template<typename Pmf , typename Ptr >
std::enable_if_t<!trait::is_callable_v< arg_list, Pmf > && trait::is_weak_ptr_compatible_v< Ptr >, Connection > wpi::sig::SignalBase< Lockable, T >::connect ( Pmf &&  pmf,
Ptr &&  ptr 
)
inline

Overload of connect for lifetime object tracking and automatic disconnection.

Ptr must be convertible to an object following a loose form of weak pointer concept, by implementing the ADL-detected conversion function to_weak().

This overload covers the case of a pointer over member function and a trackable pointer of that class.

Note: only weak references are stored, a slot does not extend the lifetime of a suppied object.

Parameters
pmfa pointer over member function
ptra trackable object pointer
Returns
a Connection object that can be used to interact with the slot

◆ connect_connection()

template<typename Lockable , typename... T>
template<typename Callable >
std::enable_if_t< trait::is_callable_v< arg_list, Callable >, Connection > wpi::sig::SignalBase< Lockable, T >::connect_connection ( Callable &&  c)
inline

Connect a callable of compatible arguments, returning a Connection.

Effect: Creates and stores a new slot responsible for executing the supplied callable for every subsequent signal emission. Safety: Thread-safety depends on locking policy.

Parameters
ca callable
Returns
a Connection object that can be used to interact with the slot

◆ connect_extended() [1/2]

template<typename Lockable , typename... T>
template<typename Callable >
std::enable_if_t< trait::is_callable_v< ext_arg_list, Callable >, Connection > wpi::sig::SignalBase< Lockable, T >::connect_extended ( Callable &&  c)
inline

Connect a callable with an additional Connection argument.

The callable's first argument must be of type Connection. This overload the callable to manage it's own connection through this argument.

Parameters
ca callable
Returns
a Connection object that can be used to interact with the slot

◆ connect_extended() [2/2]

template<typename Lockable , typename... T>
template<typename Pmf , typename Ptr >
std::enable_if_t< trait::is_callable_v< ext_arg_list, Pmf, Ptr > && !trait::is_weak_ptr_compatible_v< Ptr >, Connection > wpi::sig::SignalBase< Lockable, T >::connect_extended ( Pmf &&  pmf,
Ptr &&  ptr 
)
inline

Overload of connect for pointer over member functions and.

Parameters
pmfa pointer over member function
ptran object pointer
Returns
a Connection object that can be used to interact with the slot

◆ connect_scoped()

template<typename Lockable , typename... T>
template<typename... CallArgs>
ScopedConnection wpi::sig::SignalBase< Lockable, T >::connect_scoped ( CallArgs &&...  args)
inline

Creates a connection whose duration is tied to the return object Use the same semantics as connect.

◆ disconnect_all()

template<typename Lockable , typename... T>
void wpi::sig::SignalBase< Lockable, T >::disconnect_all ( )
inline

Disconnects all the slots Safety: Thread safety depends on locking policy.

◆ operator()()

template<typename Lockable , typename... T>
template<typename... A>
void wpi::sig::SignalBase< Lockable, T >::operator() ( A &&...  a) const
inline

Emit a signal.

Effect: All non blocked and connected slot functions will be called with supplied arguments. Safety: With proper locking (see wpi::Signal), emission can happen from multiple threads simultaneously. The guarantees only apply to the signal object, it does not cover thread safety of potentially shared state used in slot functions.

Parameters
aarguments to emit

◆ operator=() [1/2]

template<typename Lockable , typename... T>
SignalBase & wpi::sig::SignalBase< Lockable, T >::operator= ( const SignalBase< Lockable, T > &  )
delete

◆ operator=() [2/2]

template<typename Lockable , typename... T>
SignalBase & wpi::sig::SignalBase< Lockable, T >::operator= ( SignalBase< Lockable, T > &&  o)
inline

◆ unblock()

template<typename Lockable , typename... T>
void wpi::sig::SignalBase< Lockable, T >::unblock ( )
inlinenoexcept

Unblocks signal emission Safety: thread safe.


The documentation for this class was generated from the following file: