Gaia-ECS v0.9.3
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::util::delegate< Ret(Args...)> Class Template Reference

Delegate for function pointers and members. It can be used as a general-purpose invoker for any free function with no memory overhead. More...

#include <signal.h>

Public Member Functions

template<auto FuncToBind>
 delegate (detail::connect_arg_t< FuncToBind >) noexcept
 Constructs a delegate by binding a free function or an unbound member to it.
 
template<auto FuncToBind, typename Type >
 delegate (detail::connect_arg_t< FuncToBind >, Type &&value_or_instance) noexcept
 Constructs a delegate by binding a free function with context or a bound member to it.
 
 delegate (func_type *func, const void *data=nullptr) noexcept
 Constructs a delegate by binding a function with optional context to it.
 
template<auto FuncToBind>
void bind () noexcept
 Binds a free function or an unbound member to a delegate.
 
template<auto FuncToBind, typename Type >
void bind (Type &value_or_instance) noexcept
 Binds a free function with context or a bound member to a delegate. When used to bind a ree function with context, its signature must be such that the instance is the first argument before the ones used to define the delegate itself.
 
template<auto FuncToBind, typename Type >
void bind (Type *value_or_instance) noexcept
 Binds a free function with context or a bound member to a delegate.
 
void bind (func_type *function, const void *context=nullptr) noexcept
 Binds an user defined function with optional context to a delegate. The context is returned as the first argument to the target function in all cases.
 
void reset () noexcept
 Resets a delegate. After a reset, a delegate cannot be invoked anymore.
 
GAIA_NODISCARD bool has_func () const noexcept
 Returns the functor pointer linked to a delegate, if any.
 
GAIA_NODISCARD const void * instance () const noexcept
 Returns the instance or the context linked to a delegate, if any.
 
Ret operator() (Args... args) const
 The delegate invokes the underlying function and returns the result.
 
GAIA_NODISCARD operator bool () const noexcept
 Checks whether a delegate actually points to something.
 
GAIA_NODISCARD bool operator== (const delegate< Ret(Args...)> &other) const noexcept
 Compares the contents of two delegates.
 
GAIA_NODISCARD bool operator!= (const delegate< Ret(Args...)> &other) const noexcept
 Compares the contents of two delegates.
 

Detailed Description

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

Delegate for function pointers and members. It can be used as a general-purpose invoker for any free function with no memory overhead.

Warning
The delegate isn't responsible for the connected object or its context. User is in charge of disconnecting instances before deleting them and guarantee the lifetime of the instance is longer than that of the delegate.
Template Parameters
RetReturn type of a function type.
ArgsTypes of arguments of a function type.

Constructor & Destructor Documentation

◆ delegate() [1/3]

template<typename Ret , typename... Args>
template<auto FuncToBind>
gaia::util::delegate< Ret(Args...)>::delegate ( detail::connect_arg_t< FuncToBind >  )
inlinenoexcept

Constructs a delegate by binding a free function or an unbound member to it.

Template Parameters
FuncToBindFunction or member to bind to the delegate.

◆ delegate() [2/3]

template<typename Ret , typename... Args>
template<auto FuncToBind, typename Type >
gaia::util::delegate< Ret(Args...)>::delegate ( detail::connect_arg_t< FuncToBind >  ,
Type &&  value_or_instance 
)
inlinenoexcept

Constructs a delegate by binding a free function with context or a bound member to it.

Template Parameters
FuncToBindFunction or member to bind to the delegate.
TypeType of class or type of context.
Parameters
value_or_instanceA valid object that fits the purpose.

◆ delegate() [3/3]

template<typename Ret , typename... Args>
gaia::util::delegate< Ret(Args...)>::delegate ( func_type *  func,
const void *  data = nullptr 
)
inlinenoexcept

Constructs a delegate by binding a function with optional context to it.

Parameters
funcFunction to bind to the delegate.
dataUser defined arbitrary data.

Member Function Documentation

◆ bind() [1/4]

template<typename Ret , typename... Args>
template<auto FuncToBind>
void gaia::util::delegate< Ret(Args...)>::bind ( )
inlinenoexcept

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

Template Parameters
FuncToBindFunction or member to bind to the delegate.

◆ bind() [2/4]

template<typename Ret , typename... Args>
void gaia::util::delegate< Ret(Args...)>::bind ( func_type *  function,
const void *  context = nullptr 
)
inlinenoexcept

Binds an user defined function with optional context to a delegate. The context is returned as the first argument to the target function in all cases.

Parameters
functionFunction to bind* to* the delegate.
contextUser defined arbitrary ctx.

◆ bind() [3/4]

template<typename Ret , typename... Args>
template<auto FuncToBind, typename Type >
void gaia::util::delegate< Ret(Args...)>::bind ( Type &  value_or_instance)
inlinenoexcept

Binds a free function with context or a bound member to a delegate. When used to bind a ree function with context, its signature must be such that the instance is the first argument before the ones used to define the delegate itself.

Template Parameters
FuncToBindFunction or member to bind to the delegate.
TypeType of class or type of context.
Parameters
value_or_instance*A valid* reference that fits the purpose.

◆ bind() [4/4]

template<typename Ret , typename... Args>
template<auto FuncToBind, typename Type >
void gaia::util::delegate< Ret(Args...)>::bind ( Type *  value_or_instance)
inlinenoexcept

Binds a free function with context or a bound member to a delegate.

Template Parameters
FuncToBindFunction or member to bind to the delegate.
TypeType of class or type of context.
Parameters
value_or_instanceA valid pointer that fits the purpose.

◆ has_func()

template<typename Ret , typename... Args>
GAIA_NODISCARD bool gaia::util::delegate< Ret(Args...)>::has_func ( ) const
inlinenoexcept

Returns the functor pointer linked to a delegate, if any.

Returns
An opaque pointer to the underlying data.

◆ instance()

template<typename Ret , typename... Args>
GAIA_NODISCARD const void * gaia::util::delegate< Ret(Args...)>::instance ( ) const
inlinenoexcept

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

Returns
An opaque pointer to the underlying data.

◆ operator bool()

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

Checks whether a delegate actually points to something.

Returns
False if the delegate is empty, true otherwise.

◆ operator!=()

template<typename Ret , typename... Args>
GAIA_NODISCARD bool gaia::util::delegate< Ret(Args...)>::operator!= ( const delegate< Ret(Args...)> &  other) const
inlinenoexcept

Compares the contents of two delegates.

Parameters
otherDelegate with which to compare.
Returns
True if the two contents differ, false otherwise.

◆ operator()()

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

The delegate invokes the underlying function and returns the result.

Parameters
args*Arguments* to use to invoke the underlying function.
Returns
The value returned by the underlying * function.

◆ operator==()

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

Compares the contents of two delegates.

Parameters
otherDelegate with which to compare.
Returns
True if the two contents are equal, false otherwise.

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