HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions
hi::v1::callback< ResultType(ArgTypes...)> Class Template Reference

#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
 
callbackoperator= (callback const &)=default
 
 callback (callback &&)=default
 
callbackoperator= (callback &&)=default
 
 callback (std::nullptr_t) noexcept
 
callbackoperator= (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.
 

Detailed Description

template<typename ResultType, typename... ArgTypes>
class hi::v1::callback< ResultType(ArgTypes...)>

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.

Template Parameters
RThe result of the function.
ArgsThe arguments of the function.

Member Function Documentation

◆ operator()()

template<typename ResultType , typename... ArgTypes>
template<typename... Args>
decltype(auto) hi::v1::callback< ResultType(ArgTypes...)>::operator() ( Args... args)
inline

Call the callback function.

Note
A callback is not re-enterable from the same thread.
It is undefined behavior to destroy a callback while it is in-flight.
Parameters
argsThe arguments forwarded to callback-function.
Returns
The result of the callback-function.
Exceptions
std::base_function_callif the callback does not store a function object.
Theexception thrown from the callback-function.

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