EnTT 3.13.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
entt::delegate< Ret(Args...)> Class Template Reference

Utility class to use to send around functions and members. More...

#include <delegate.hpp>

Public Types

using function_type = Ret(const void *, Args...)
 Function type of the contained target.
 
using type = Ret(Args...)
 Function type of the delegate.
 
using result_type = Ret
 Return type of the delegate.
 

Public Member Functions

 delegate () noexcept
 Default constructor.
 
template<auto Candidate, typename... Type>
 delegate (connect_arg_t< Candidate >, Type &&...value_or_instance) noexcept
 Constructs a delegate with a given object or payload, if any.
 
 delegate (function_type *function, const void *payload=nullptr) noexcept
 Constructs a delegate and connects an user defined function with optional payload.
 
template<auto Candidate>
void connect () noexcept
 Connects a free function or an unbound member to a delegate.
 
template<auto Candidate, typename Type >
void connect (Type &value_or_instance) noexcept
 Connects a free function with payload or a bound member to a delegate.
 
template<auto Candidate, typename Type >
void connect (Type *value_or_instance) noexcept
 Connects a free function with payload or a bound member to a delegate.
 
void connect (function_type *function, const void *payload=nullptr) noexcept
 Connects an user defined function with optional payload to a delegate.
 
void reset () noexcept
 Resets a delegate.
 
function_typetarget () const noexcept
 Returns a pointer to the stored callable function target, if any.
 
const void * data () const noexcept
 Returns the instance or the payload linked to a delegate, if any.
 
Ret operator() (Args... args) const
 Triggers a delegate.
 
 operator bool () const noexcept
 Checks whether a delegate actually stores a listener.
 
bool operator== (const delegate< Ret(Args...)> &other) const noexcept
 Compares the contents of two delegates.
 

Detailed Description

template<typename Ret, typename... Args>
class entt::delegate< Ret(Args...)>

Utility class to use to send around functions and members.

Unmanaged delegate for function pointers and members. Users of this class are in charge of disconnecting instances before deleting them.

A delegate can be used as a general purpose invoker without memory overhead for free functions possibly with payloads and bound or unbound members.

Template Parameters
RetReturn type of a function type.
ArgsTypes of arguments of a function type.

Definition at line 66 of file delegate.hpp.

Member Typedef Documentation

◆ function_type

template<typename Ret , typename... Args>
using entt::delegate< Ret(Args...)>::function_type = Ret(const void *, Args...)

Function type of the contained target.

Definition at line 113 of file delegate.hpp.

◆ result_type

template<typename Ret , typename... Args>
using entt::delegate< Ret(Args...)>::result_type = Ret

Return type of the delegate.

Definition at line 117 of file delegate.hpp.

◆ type

template<typename Ret , typename... Args>
using entt::delegate< Ret(Args...)>::type = Ret(Args...)

Function type of the delegate.

Definition at line 115 of file delegate.hpp.

Constructor & Destructor Documentation

◆ delegate() [1/3]

template<typename Ret , typename... Args>
entt::delegate< Ret(Args...)>::delegate ( )
inlinenoexcept

Default constructor.

Definition at line 120 of file delegate.hpp.

◆ delegate() [2/3]

template<typename Ret , typename... Args>
template<auto Candidate, typename... Type>
entt::delegate< Ret(Args...)>::delegate ( connect_arg_t< Candidate >  ,
Type &&...  value_or_instance 
)
inlinenoexcept

Constructs a delegate with a given object or payload, if any.

Template Parameters
CandidateFunction or member to connect to the delegate.
TypeType of class or type of payload, if any.
Parameters
value_or_instanceOptional valid object that fits the purpose.

Definition at line 131 of file delegate.hpp.

◆ delegate() [3/3]

template<typename Ret , typename... Args>
entt::delegate< Ret(Args...)>::delegate ( function_type function,
const void *  payload = nullptr 
)
inlinenoexcept

Constructs a delegate and connects an user defined function with optional payload.

Parameters
functionFunction to connect to the delegate.
payloadUser defined arbitrary data.

Definition at line 141 of file delegate.hpp.

Member Function Documentation

◆ connect() [1/4]

template<typename Ret , typename... Args>
template<auto Candidate>
void entt::delegate< Ret(Args...)>::connect ( )
inlinenoexcept

Connects a free function or an unbound member to a delegate.

Template Parameters
CandidateFunction or member to connect to the delegate.

Definition at line 150 of file delegate.hpp.

◆ connect() [2/4]

template<typename Ret , typename... Args>
void entt::delegate< Ret(Args...)>::connect ( function_type function,
const void *  payload = nullptr 
)
inlinenoexcept

Connects an user defined function with optional payload to a delegate.

The delegate isn't responsible for the connected object or the payload. Users must always guarantee that the lifetime of an instance overcomes the one of the delegate.
The payload is returned as the first argument to the target function in all cases.

Parameters
functionFunction to connect to the delegate.
payloadUser defined arbitrary data.

Definition at line 230 of file delegate.hpp.

◆ connect() [3/4]

template<typename Ret , typename... Args>
template<auto Candidate, typename Type >
void entt::delegate< Ret(Args...)>::connect ( Type &  value_or_instance)
inlinenoexcept

Connects a free function with payload or a bound member to a delegate.

The delegate isn't responsible for the connected object or the payload. Users must always guarantee that the lifetime of the instance overcomes the one of the delegate.
When used to connect a free function with payload, its signature must be such that the instance is the first argument before the ones used to define the delegate itself.

Template Parameters
CandidateFunction or member to connect to the delegate.
TypeType of class or type of payload.
Parameters
value_or_instanceA valid reference that fits the purpose.

Definition at line 180 of file delegate.hpp.

◆ connect() [4/4]

template<typename Ret , typename... Args>
template<auto Candidate, typename Type >
void entt::delegate< Ret(Args...)>::connect ( Type *  value_or_instance)
inlinenoexcept

Connects a free function with payload or a bound member to a delegate.

See also
connect(Type &)
Template Parameters
CandidateFunction or member to connect to the delegate.
TypeType of class or type of payload.
Parameters
value_or_instanceA valid pointer that fits the purpose.

Definition at line 204 of file delegate.hpp.

◆ data()

template<typename Ret , typename... Args>
const void * entt::delegate< Ret(Args...)>::data ( ) const
inlinenoexcept

Returns the instance or the payload linked to a delegate, if any.

Returns
An opaque pointer to the underlying data.

Definition at line 258 of file delegate.hpp.

◆ operator bool()

template<typename Ret , typename... Args>
entt::delegate< Ret(Args...)>::operator bool ( ) const
inlineexplicitnoexcept

Checks whether a delegate actually stores a listener.

Returns
False if the delegate is empty, true otherwise.

Definition at line 283 of file delegate.hpp.

◆ operator()()

template<typename Ret , typename... Args>
Ret entt::delegate< Ret(Args...)>::operator() ( Args...  args) const
inline

Triggers a delegate.

The delegate invokes the underlying function and returns the result.

Warning
Attempting to trigger an invalid delegate results in undefined behavior.
Parameters
argsArguments to use to invoke the underlying function.
Returns
The value returned by the underlying function.

Definition at line 274 of file delegate.hpp.

◆ operator==()

template<typename Ret , typename... Args>
bool entt::delegate< Ret(Args...)>::operator== ( const delegate< Ret(Args...)> &  other) const
inlinenoexcept

Compares the contents of two delegates.

Parameters
otherDelegate with which to compare.
Returns
False if the two contents differ, true otherwise.

Definition at line 293 of file delegate.hpp.

◆ reset()

template<typename Ret , typename... Args>
void entt::delegate< Ret(Args...)>::reset ( )
inlinenoexcept

Resets a delegate.

After a reset, a delegate cannot be invoked anymore.

Definition at line 241 of file delegate.hpp.

◆ target()

template<typename Ret , typename... Args>
function_type * entt::delegate< Ret(Args...)>::target ( ) const
inlinenoexcept

Returns a pointer to the stored callable function target, if any.

Returns
An opaque pointer to the stored callable function target.

Definition at line 250 of file delegate.hpp.


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