ndn::signal::Signal< Owner, TArgs > Class Template Reference

Provides a lightweight signal / event system. More...

#include <ndn-cxx/util/signal/signal.hpp>

+ Inheritance diagram for ndn::signal::Signal< Owner, TArgs >:
+ Collaboration diagram for ndn::signal::Signal< Owner, TArgs >:

Public Types

using Handler = std::function< void(const TArgs &...)>
 Represents a function that can connect to the signal. More...
 

Public Member Functions

 ~Signal () noexcept
 
Connection connect (Handler handler)
 Connects a handler to the signal. More...
 
Connection connectSingleShot (Handler handler)
 Connects a single-shot handler to the signal. More...
 

Detailed Description

template<typename Owner, typename... TArgs>
class ndn::signal::Signal< Owner, TArgs >

Provides a lightweight signal / event system.

To declare a signal: public: Signal<Owner, T1, T2> signalName; To connect to a signal: owner->signalName.connect(f); Multiple functions can connect to the same signal. To emit a signal from owner: this->signalName(arg1, arg2);

Template Parameters
Ownerthe signal owner class; only this class can emit the signal
TArgstypes of signal arguments
See also
signal-emit.hpp allows owner's derived classes to emit signals

Definition at line 50 of file signal.hpp.

Member Typedef Documentation

◆ Handler

template<typename Owner , typename... TArgs>
using ndn::signal::Signal< Owner, TArgs >::Handler = std::function<void(const TArgs&...)>

Represents a function that can connect to the signal.

Definition at line 63 of file signal.hpp.

Constructor & Destructor Documentation

◆ ~Signal()

template<typename Owner , typename... TArgs>
ndn::signal::Signal< Owner, TArgs >::~Signal ( )
inlinenoexcept

Definition at line 54 of file signal.hpp.

Member Function Documentation

◆ connect()

template<typename Owner , typename... TArgs>
Connection ndn::signal::Signal< Owner, TArgs >::connect ( Handler  handler)

Connects a handler to the signal.

Note
If invoked from a handler, the new handler won't receive the current emitted signal.
Warning
The handler is permitted to disconnect itself, but it must ensure its validity.

Definition at line 152 of file signal.hpp.

◆ connectSingleShot()

template<typename Owner , typename... TArgs>
Connection ndn::signal::Signal< Owner, TArgs >::connectSingleShot ( Handler  handler)

Connects a single-shot handler to the signal.

After the handler is executed once, it is automatically disconnected.

Definition at line 162 of file signal.hpp.