LiteFX 0.4.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
LiteFX::Delegate< TResult, TArgs > Class Template Referencefinal

Represents a handler for an Event, that is assigned a unique token when created, so that it can be identified later. More...

#include <app.hpp>

Public Types

using function_type = std::function<TResult(TArgs...)>
 
using token_type = size_t
 

Public Member Functions

 Delegate (function_type fn, token_type t) noexcept
 Creates a new delegate.
 
TResult invoke (TArgs... args) const
 Invokes the delegate function.
 
token_type token () const
 Returns the unique token of the delegate.
 
TResult operator() (TArgs... args) const
 Invokes the delegate function.
 

Detailed Description

template<typename TResult, typename... TArgs>
class LiteFX::Delegate< TResult, TArgs >

Represents a handler for an Event, that is assigned a unique token when created, so that it can be identified later.

Since a std::function or callable us not comparable, it is not possible to identify and remove event handlers from an event, after registering them. To support this functionality, the event handler will be encapsulated in a delegate, which gets assigned with a token. This token is unique for the event, the delegate has been registered to.

Template Parameters
TResultThe result of the delegate function.
...TArgsThe arguments of the delegate function.

Member Typedef Documentation

◆ function_type

template<typename TResult , typename... TArgs>
using LiteFX::Delegate< TResult, TArgs >::function_type = std::function<TResult(TArgs...)>

◆ token_type

template<typename TResult , typename... TArgs>
using LiteFX::Delegate< TResult, TArgs >::token_type = size_t

Constructor & Destructor Documentation

◆ Delegate()

template<typename TResult , typename... TArgs>
LiteFX::Delegate< TResult, TArgs >::Delegate ( function_type fn,
token_type t )
inlinenoexcept

Creates a new delegate.

Parameters
fnThe delegate function.
tThe unique token of the delegate within the parent event.

Member Function Documentation

◆ invoke()

template<typename TResult , typename... TArgs>
TResult LiteFX::Delegate< TResult, TArgs >::invoke ( TArgs... args) const
inline

Invokes the delegate function.

Parameters
...argsThe arguments passed to the function.
Returns
The result of the delegate function call.

◆ operator()()

template<typename TResult , typename... TArgs>
TResult LiteFX::Delegate< TResult, TArgs >::operator() ( TArgs... args) const
inline

Invokes the delegate function.

Parameters
...argsThe arguments passed to the function.
Returns
The result of the delegate function call.

◆ token()

template<typename TResult , typename... TArgs>
token_type LiteFX::Delegate< TResult, TArgs >::token ( ) const
inline

Returns the unique token of the delegate.

Returns
The unique token of the delegate.