psychic-ui 0.0.0
Loading...
Searching...
No Matches
psychic_ui::Signal< T > Class Template Reference

#include <Signal.hpp>

Public Types

using SlotPtr = std::shared_ptr<Slot<T...>>

Public Member Functions

 Signal (const Signal &)=delete
Signal & operator= (const Signal &)=delete
 Signal (Signal &&)=delete
Signal & operator= (Signal &&)=delete
bool hasSubscriptions () const
std::size_t subscriptionCount () const
template<class F>
requires std::invocable<F &, const T &...> || std::invocable<F &>
SlotPtr subscribe (F &&callback)
void emit (const T &... args)

Detailed Description

template<class... T>
class psychic_ui::Signal< T >

Signal Create a signal with template arguments matching the arguments required for emit and parameters that will be used in the callback/lambda. Callbacks receive the arguments as const T &, or take no parameters to ignore them.

Handlers may connect, disconnect (themselves or others) and destroy the signal while it is emitting:

  • a slot connected during an emission is first called by the next emission;
  • a slot disconnected during an emission is not called anymore, even by the running one;
  • when a handler destroys the signal, the emission stops after that handler (destroying it disconnects them all).

Signals can't be copied or moved: their slots and the handlers' captures refer to them.

Member Function Documentation

◆ emit()

template<class... T>
void psychic_ui::Signal< T >::emit ( const T &... args)
inline

Emit a signal

Parameters
argsArguments matching the types used as template arguments, converted once for all the slots

◆ hasSubscriptions()

template<class... T>
bool psychic_ui::Signal< T >::hasSubscriptions ( ) const
inlinenodiscard

Check if the signal has any subscriptions

◆ subscribe()

template<class... T>
template<class F>
requires std::invocable<F &, const T &...> || std::invocable<F &>
SlotPtr psychic_ui::Signal< T >::subscribe ( F && callback)
inline

Subscribe to this signal The signal keeps the slot: keep the returned pointer in a ScopedSlot to disconnect later. When the callback refers to something that can die before the signal, do that, or extend from Observer and use subscribeTo.

◆ subscriptionCount()

template<class... T>
std::size_t psychic_ui::Signal< T >::subscriptionCount ( ) const
inlinenodiscard

Get the number of subscriptions


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