version 0.4.1
Ikarus::Listener Struct Reference

#include <ikarus/utils/listener/listener.hh>

Inheritance diagram for Ikarus::Listener:
[legend]

Public Types

using Token = std::shared_ptr< void >
 

Public Member Functions

template<typename Broadcaster , typename F >
auto subscribe (Broadcaster &broadcaster, F &&f)
 Function to subscribe to a broadcaster with a given function (either a lambda, std::function or function pointer). More...
 
template<typename Broadcaster , typename Signature , typename F >
requires (not Concepts::PointerOrSmartPointer<Broadcaster>)
auto subscribe (Broadcaster &broadcaster, F &&f)
 Function to subscribe to a broadcaster with a given function (either a lambda, std::function or function pointer). More...
 
void unSubscribeAll ()
 Unsubscribe from all listeners. At the moment unsubscribing can't be done more granularly. More...
 
void unSubscribeLast ()
 Unsubscribe from the last subscribed listener. More...
 
void unSubscribe (Token &&ts)
 

Detailed Description

The functions that the listener is listening to are stored in a vector of shared_ptr<void>. This type erasure has the advantage that we can listen to different function signatures and the Listener not being a template. This works, because the deleter of the stored objects is not bound to the type information and thus there are no memory leaks possible.

Member Typedef Documentation

◆ Token

using Ikarus::Listener::Token = std::shared_ptr<void>

Member Function Documentation

◆ subscribe() [1/2]

template<typename Broadcaster , typename F >
auto Ikarus::Listener::subscribe ( Broadcaster broadcaster,
F &&  f 
)
inline

This function deducts the types of the arguments itself and then forwards it. If there are problems with type deduction use the function below and specify the types of the arguments manually.

Template Parameters
Broadcasterthe type of the Broadcaster (for example a NonlinearSolver or ControlRoutine), can either be a pointer or value.
Fthe type of the function
Parameters
broadcasterthe broadcaster
fthe function
Here is the caller graph for this function:

◆ subscribe() [2/2]

template<typename Broadcaster , typename Signature , typename F >
requires (not Concepts::PointerOrSmartPointer<Broadcaster>)
auto Ikarus::Listener::subscribe ( Broadcaster broadcaster,
F &&  f 
)
inline
Template Parameters
Broadcasterthe type of the Broadcaster (for example a NonlinearSolver or ControlRoutine), can either be a pointer or value.
Signaturethe exact signature of the function F
Fthe type of the function
Parameters
broadcasterthe broadcaster
fthe function

◆ unSubscribe()

void Ikarus::Listener::unSubscribe ( Token &&  ts)
inline

◆ unSubscribeAll()

void Ikarus::Listener::unSubscribeAll ( )
inline

◆ unSubscribeLast()

void Ikarus::Listener::unSubscribeLast ( )
inline

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