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

Sink is a helper class used to bind listeners to signals. The separation between signal and sink makes it possible to store signals as private data members without exposing their invoke functionality to the users of the class. It also allows for less header files contention because any binding can (and should) happen in source files. More...

#include <signal.h>

Public Member Functions

 sink (signal< Ret(Args...)> &ref) noexcept
 Constructs a sink that is allowed to modify a given signal.
 
void move_from (sink &other)
 Moves signals from another sink to this one. Result is stored in this object. The sink we merge from is cleared.
 
template<auto FuncToBind>
void bind ()
 Binds a free function or an unbound member to a signal. The signal handler performs checks to avoid multiple connections for the same function.
 
template<auto FuncToBind, typename Type >
void bind (Type &value_or_instance)
 Binds a free function with context or a bound member to a signal. When used to bind a free function with context, its signature must be such that the instance is the first argument before the ones used to define the signal itself.
 
void bind (func_type *func, const void *data=nullptr)
 Binds an user defined function with optional context to a signal. The context is returned as the first argument to the target function in all cases.
 
template<auto FuncToUnbind>
void unbind ()
 Unbinds a free function or an unbound member from a signal.
 
template<auto FuncToUnbind, typename Type >
void unbind (Type &value_or_instance)
 Unbinds a free function with context or a bound member from a signal.
 
template<typename Type >
void unbind (Type *value_or_instance)
 Unbinds a free function with context or bound members from a signal.
 
template<typename Type >
void unbind (Type &value_or_instance)
 Unbinds a free function with context or bound members from a signal.
 
void reset ()
 Unbinds all listeners from a signal.
 

Detailed Description

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

Sink is a helper class used to bind listeners to signals. The separation between signal and sink makes it possible to store signals as private data members without exposing their invoke functionality to the users of the class. It also allows for less header files contention because any binding can (and should) happen in source files.

Warning
Lifetime of any sink must not be longer than that of the signal to which it refers.
Template Parameters
RetReturn type of a function type.
ArgsTypes of arguments of a function type.

Constructor & Destructor Documentation

◆ sink()

template<typename Ret , typename... Args>
gaia::util::sink< Ret(Args...)>::sink ( signal< Ret(Args...)> &  ref)
inlinenoexcept

Constructs a sink that is allowed to modify a given signal.

Parameters
refA valid reference to a signal object.

Member Function Documentation

◆ bind() [1/3]

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

Binds a free function or an unbound member to a signal. The signal handler performs checks to avoid multiple connections for the same function.

Template Parameters
FuncToBindFunction or member to bind to the signal.

◆ bind() [2/3]

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

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

Parameters
funcFunction to bind to the signal.
dataUser defined arbitrary ctx.

◆ bind() [3/3]

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

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

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

◆ move_from()

template<typename Ret , typename... Args>
void gaia::util::sink< Ret(Args...)>::move_from ( sink< Ret(Args...)> &  other)
inline

Moves signals from another sink to this one. Result is stored in this object. The sink we merge from is cleared.

Parameters
otherSink to move signals from

◆ unbind() [1/4]

template<typename Ret , typename... Args>
template<auto FuncToUnbind>
void gaia::util::sink< Ret(Args...)>::unbind ( )
inline

Unbinds a free function or an unbound member from a signal.

Template Parameters
FuncToUnbind*Function* or member to unbind from the signal.

◆ unbind() [2/4]

template<typename Ret , typename... Args>
template<auto FuncToUnbind, typename Type >
void gaia::util::sink< Ret(Args...)>::unbind ( Type &  value_or_instance)
inline

Unbinds a free function with context or a bound member from a signal.

Template Parameters
FuncToUnbindFunction or member to unbind from the signal.
TypeType of class or type of context.
Parameters
value_or_instanceA valid object that fits the purpose.

◆ unbind() [3/4]

template<typename Ret , typename... Args>
template<typename Type >
void gaia::util::sink< Ret(Args...)>::unbind ( Type &  value_or_instance)
inline

Unbinds a free function with context or bound members from a signal.

Template Parameters
TypeType of class or type of context.
Parameters
value_or_instanceA valid object that fits the purpose.

◆ unbind() [4/4]

template<typename Ret , typename... Args>
template<typename Type >
void gaia::util::sink< Ret(Args...)>::unbind ( Type *  value_or_instance)
inline

Unbinds a free function with context or bound members from a signal.

Template Parameters
TypeType of class or type of context.
Parameters
value_or_instanceA valid object that fits the purpose.

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