17#ifndef _FGE_C_CALLBACKHANDLER_HPP_INCLUDED
18#define _FGE_C_CALLBACKHANDLER_HPP_INCLUDED
20#include "FastEngine/C_subscription.hpp"
35template<
class... Types>
41 virtual void call(Types... args) = 0;
42 virtual bool check(
void* ptr) = 0;
52template<
class... Types>
56 using CallbackFunction = void (*)(Types... args);
63 explicit CallbackFunctor(fge::CallbackFunctor<Types...>::CallbackFunction func);
71 void call(Types... args)
override;
78 inline bool check(
void* ptr)
override;
91template<
class... Types>
101 template<
typename TLambda>
110 void call(Types... args)
override;
117 inline bool check(
void* ptr)
override;
121 void (*g_executeLambda)(
void*, Types...);
122 void (*g_deleteLambda)(
void*);
133template<
class TObject,
class... Types>
137 using CallbackFunctionObject = void (TObject::*)(Types... args);
145 CallbackObjectFunctor(fge::CallbackObjectFunctor<TObject, Types...>::CallbackFunctionObject func, TObject*
object);
153 void call(Types... args)
override;
160 inline bool check(
void* ptr)
override;
167template<
class... Types>
169template<
class... Types>
187template<
class... Types>
191 using CalleePtr = CalleeUniquePtr<Types...>;
261 template<
typename TLambda>
274 template<
class TObject>
276 addObjectFunctor(
typename fge::CallbackObjectFunctor<TObject, Types...>::CallbackFunctionObject func,
310 void call(Types... args);
340 _subscriber(subscriber)
346 using CalleeList = std::vector<CalleeData>;
348 CalleeList g_callees;
350 mutable std::recursive_mutex g_mutex;
361template<
class TCalleePtr,
class... Types>
364 using CalleePtr = TCalleePtr;
372 [[nodiscard]]
inline static CalleePtr
newFunctor(
typename fge::CallbackFunctor<Types...>::CallbackFunction func)
384 template<
typename TLambda>
385 [[nodiscard]]
inline static CalleePtr
newLambda(TLambda
const& lambda)
398 template<
class TObject>
399 [[nodiscard]]
inline static CalleePtr
400 newObjectFunctor(
typename fge::CallbackObjectFunctor<TObject, Types...>::CallbackFunctionObject func,
409#include "FastEngine/C_callback.inl"
Base class for callbacks.
Definition C_callback.hpp:37
Callback functor.
Definition C_callback.hpp:54
bool check(void *ptr) override
Check if the given pointer is the same as the one used to construct the functor.
Definition C_callback.inl:33
void call(Types... args) override
Call the callback function with the given arguments.
Definition C_callback.inl:28
CallbackFunctor(fge::CallbackFunctor< Types... >::CallbackFunction func)
Constructor.
Definition C_callback.inl:23
This class is used to handle callbacks in a safe way.
Definition C_callback.hpp:189
void delPtr(void *ptr)
Remove a callback from the list.
Definition C_callback.inl:159
fge::CallbackHandler< Types... > & operator=(fge::CallbackHandler< Types... > &&n)=delete
Move operator prohibited.
fge::CallbackFunctor< Types... > * addFunctor(typename fge::CallbackFunctor< Types... >::CallbackFunction func, fge::Subscriber *subscriber=nullptr)
Helper method to add a callback functor.
Definition C_callback.inl:133
CallbackHandler(fge::CallbackHandler< Types... > const &n)
Copy constructor that does nothing.
Definition C_callback.hpp:199
void del(fge::CallbackBase< Types... > *callback)
Remove a callback from the list.
Definition C_callback.inl:199
fge::CallbackBase< Types... > * add(CalleePtr &&callback, fge::Subscriber *subscriber=nullptr)
Add a new callback to the list.
Definition C_callback.inl:110
fge::CallbackHandler< Types... > & operator=(fge::CallbackHandler< Types... > const &n)
Copy operator that does nothing.
Definition C_callback.hpp:209
void onDetach(fge::Subscriber *subscriber) override
This method is called when a subscriber is destroyed (destructor called)
Definition C_callback.inl:261
void call(Types... args)
Call all the callbacks with the given arguments.
Definition C_callback.inl:218
void hook(fge::CallbackHandler< Types... > &handler, fge::Subscriber *subscriber=nullptr)
Hook a callback handler to this handler.
Definition C_callback.inl:247
void delSub(fge::Subscriber *subscriber)
Remove a callback from the list.
Definition C_callback.inl:177
CallbackHandler(fge::CallbackHandler< Types... > &&n)=delete
Move constructor prohibited.
void clear()
Clear the list of callbacks.
Definition C_callback.inl:99
fge::CallbackObjectFunctor< TObject, Types... > * addObjectFunctor(typename fge::CallbackObjectFunctor< TObject, Types... >::CallbackFunctionObject func, TObject *object, Subscriber *subscriber=nullptr)
Helper method to add a callback object functor.
Definition C_callback.inl:149
fge::CallbackLambda< Types... > * addLambda(TLambda const &lambda, fge::Subscriber *subscriber=nullptr)
Helper method to add a callback lambda.
Definition C_callback.inl:141
Callback lambda (with/without capture)
Definition C_callback.hpp:93
bool check(void *ptr) override
Always return false.
Definition C_callback.inl:91
void call(Types... args) override
Call the callback function with the given arguments.
Definition C_callback.inl:86
CallbackLambda(TLambda const &lambda)
Constructor.
Definition C_callback.inl:64
Callback functor of a method with an object.
Definition C_callback.hpp:135
bool check(void *ptr) override
Check if the given object pointer is the same as the one used to construct the functor.
Definition C_callback.inl:55
void call(Types... args) override
Call the callback method with the given arguments.
Definition C_callback.inl:49
CallbackObjectFunctor(fge::CallbackObjectFunctor< TObject, Types... >::CallbackFunctionObject func, TObject *object)
Constructor.
Definition C_callback.inl:41
This class is a useful utility to "link" multiple objects around.
Definition C_subscription.hpp:150
This class is a useful utility to "link" multiple objects around a specific use with automatic lifeti...
Definition C_subscription.hpp:48
This struct helper is used to create callbacks.
Definition C_callback.hpp:363
static CalleePtr newLambda(TLambda const &lambda)
Helper function to create a new callback lambda.
Definition C_callback.hpp:385
static CalleePtr newFunctor(typename fge::CallbackFunctor< Types... >::CallbackFunction func)
Helper function to create a new callback functor.
Definition C_callback.hpp:372
static CalleePtr newObjectFunctor(typename fge::CallbackObjectFunctor< TObject, Types... >::CallbackFunctionObject func, TObject *object)
Helper function to create a new callback object functor.
Definition C_callback.hpp:400