version 0.4.2
Ikarus::Listener Class Reference

Implements a listener. More...

#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 >
auto subscribe (Broadcaster &broadcaster, std::function< void(typename Broadcaster::MessageType, const typename Broadcaster::State &)> callback)
 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 (const Token &token)
 Unsubscribe from a specific token. More...
 

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()

template<typename Broadcaster >
auto Ikarus::Listener::subscribe ( Broadcaster broadcaster,
std::function< void(typename Broadcaster::MessageType, const typename Broadcaster::State &)>  callback 
)
inline
Template Parameters
Broadcasterthe type of the Broadcaster (for example a NonlinearSolver or ControlRoutine)
Parameters
broadcasterthe broadcaster
callbackthe function
Here is the caller graph for this function:

◆ unSubscribe()

void Ikarus::Listener::unSubscribe ( const Token token)
inline

◆ unSubscribeAll()

void Ikarus::Listener::unSubscribeAll ( )
inline

◆ unSubscribeLast()

void Ikarus::Listener::unSubscribeLast ( )
inline

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