|
HikoGUI
A low latency retained GUI
|
#include <hikogui/concurrency/callback.hpp>
Public Types | |
| using | result_type = ResultType |
| using | weak_callback_type = weak_callback<ResultType(ArgTypes...)> |
Public Member Functions | |
| callback (callback const &)=default | |
| callback & | operator= (callback const &)=default |
| callback (callback &&)=default | |
| callback & | operator= (callback &&)=default |
| callback (std::nullptr_t) noexcept | |
| callback & | operator= (std::nullptr_t) noexcept |
| template<typename Func > | |
| callback (Func &&func) | |
| void | reset () noexcept |
| long | use_count () const noexcept |
| operator bool () const noexcept | |
| template<typename... Args> | |
| decltype(auto) | operator() (Args... args) |
| Call the callback function. | |
A callback function.
This callback object holds a function object that can be called. It works mostly as std::function<R(Args...)>.
The ownership model of a callback is designed around a std::shared_ptr and std::weak_ptr.
In many cases the subscribe() function of an object will store a weak_callback and return a callback object. This caller of subscribe() will become the owner of the callback. When the callback is destroyed weak_callback can no longer be called and be automatically cleaned up.
This way subscribing a lambda-callback that captures the this pointer can be safely handled, by having the this object store the callback. When this gets destroyed, the callback is destroyed and the subscription is automatically cleaned up.
However it may still be dangerous when the callback is called from multiple threads.
The callback may also not re-enter from the same thread, nor is it allowed to destroy the callback from within the callback.
| R | The result of the function. |
| Args | The arguments of the function. |
|
inline |
Call the callback function.
| args | The arguments forwarded to callback-function. |
| std::base_function_call | if the callback does not store a function object. |
| The | exception thrown from the callback-function. |