WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 <Signal.h>

Public Types

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

Public Member Functions

 SignalBase (const SignalBase &)=delete
 
SignalBaseoperator= (const SignalBase &)=delete
 
 SignalBase (SignalBase &&o)
 
SignalBaseoperator= (SignalBase &&o)
 
template<typename... A>
void operator() (A &&...a)
 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 >
, Connection
connect_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 >
, Connection
connect_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 >, Connection
connect (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 >, Connection
connect_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 >, Connection
connect (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 >, Connection
connect (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.
 
void disconnect_all ()
 Disconnects all the slots Safety: Thread safety depends on locking policy.
 
void block () noexcept
 Blocks signal emission Safety: thread safe.
 
void unblock () noexcept
 Unblocks signal emission Safety: thread safe.
 
bool blocked () const noexcept
 Tests blocking state of signal emission.
 

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 Function Documentation

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
Returns
a Connection object that can be used to interact with the slot
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
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
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
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
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
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
template<typename Lockable, typename... T>
template<typename... A>
void wpi::sig::SignalBase< Lockable, T >::operator() ( A &&...  a)
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
a...arguments to emit

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