HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions
tt::notifier< Result(Args...)> Class Template Reference

#include <ttauri/notifier.hpp>

Public Types

using result_type = Result
 
using callback_type = std::function<Result(Args const &...)>
 
using callback_ptr_type = std::shared_ptr<callback_type>
 

Public Member Functions

callback_ptr_type subscribe (callback_ptr_type const &callback_ptr) noexcept
 Add a callback to the notifier.
 
template<typename Callback >
requires (std::is_invocable_v<Callback>)
callback_ptr_type subscribe (Callback &&callback) noexcept
 Add a callback to the notifier.
 
void unsubscribe (callback_ptr_type const &callback_ptr) noexcept
 Remove a callback from the notifier.
 
std::vector< std::weak_ptr< callback_type > > callbacks () const noexcept
 
void operator() (Args const &...args) const noexcept
 Call the subscribed callbacks with the given arguments.
 
generator< result_type > operator() (Args const &...args) const noexcept
 Call the subscribed callbacks with the given arguments.
 

Detailed Description

template<typename Result, typename... Args>
class tt::notifier< Result(Args...)>

A notifier which can be used to call a set of registered callbacks.

This class is thread-safe; however you must not use this object from within the callback.

Template Parameters
ResultThe result of calling the callback.
ArgsThe argument types of the callback function.

Member Function Documentation

◆ operator()() [1/2]

template<typename Result , typename... Args>
void tt::notifier< Result(Args...)>::operator() ( Args const &... args) const
inlinenoexcept

Call the subscribed callbacks with the given arguments.

The callbacks will be run from the main thread, asynchronously.

Parameters
argsThe arguments to pass with the invocation of the callback

◆ operator()() [2/2]

template<typename Result , typename... Args>
generator< result_type > tt::notifier< Result(Args...)>::operator() ( Args const &... args) const
inlinenoexcept

Call the subscribed callbacks with the given arguments.

The callbacks will be called from the current thread.

Parameters
argsThe arguments to pass with the invocation of the callback
Returns
The result of each callback.

◆ subscribe() [1/2]

template<typename Result , typename... Args>
template<typename Callback >
requires (std::is_invocable_v<Callback>)
callback_ptr_type tt::notifier< Result(Args...)>::subscribe ( Callback && callback)
inlinenoexcept

Add a callback to the notifier.

Ownership of the callback belongs with the caller of subscribe(). The notifier will hold a weak_ptr to the callback so that when the callback is destroyed it will no longer be called.

Parameters
callbackThe callback-function to register.
Returns
A shared_ptr to a function object holding the callback.

◆ subscribe() [2/2]

template<typename Result , typename... Args>
callback_ptr_type tt::notifier< Result(Args...)>::subscribe ( callback_ptr_type const & callback_ptr)
inlinenoexcept

Add a callback to the notifier.

Ownership of the callback belongs with the caller of subscribe(). The notifier will hold a weak_ptr to the callback so that when the callback is destroyed it will no longer be called.

Parameters
callback_ptrA shared_ptr to a callback function.

◆ unsubscribe()

template<typename Result , typename... Args>
void tt::notifier< Result(Args...)>::unsubscribe ( callback_ptr_type const & callback_ptr)
inlinenoexcept

Remove a callback from the notifier.

Parameters
callback_ptrA share_ptr to the callback function to unsubscribe.

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