Implements a listener. More...
#include <ikarus/utils/listener/listener.hh>
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... | |
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.
| using Ikarus::Listener::Token = std::shared_ptr<void> |
|
inline |
| Broadcaster | the type of the Broadcaster (for example a NonlinearSolver or ControlRoutine) |
| broadcaster | the broadcaster |
| callback | the function |
|
inline |
|
inline |
|
inline |