![]() |
FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
|
This class is used to handle callbacks in a safe way. More...
#include <C_callback.hpp>
Public Types | |
using | CalleePtr = CalleeUniquePtr<Types...> |
using | SubscriberCount = unsigned int |
Public Member Functions | |
CallbackHandler (fge::CallbackHandler< Types... > const &n) | |
Copy constructor that does nothing. | |
CallbackHandler (fge::CallbackHandler< Types... > &&n)=delete | |
Move constructor prohibited. | |
fge::CallbackHandler< Types... > & | operator= (fge::CallbackHandler< Types... > const &n) |
Copy operator that does nothing. | |
fge::CallbackHandler< Types... > & | operator= (fge::CallbackHandler< Types... > &&n)=delete |
Move operator prohibited. | |
void | clear () |
Clear the list of callbacks. | |
fge::CallbackBase< Types... > * | add (CalleePtr &&callback, fge::Subscriber *subscriber=nullptr) |
Add a new callback to the list. | |
fge::CallbackFunctor< Types... > * | addFunctor (typename fge::CallbackFunctor< Types... >::CallbackFunction func, fge::Subscriber *subscriber=nullptr) |
Helper method to add a callback functor. | |
template<typename TLambda > | |
fge::CallbackLambda< Types... > * | addLambda (TLambda const &lambda, fge::Subscriber *subscriber=nullptr) |
Helper method to add a callback lambda. | |
template<class TObject > | |
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. | |
void | delPtr (void *ptr) |
Remove a callback from the list. | |
void | delSub (fge::Subscriber *subscriber) |
Remove a callback from the list. | |
void | del (fge::CallbackBase< Types... > *callback) |
Remove a callback from the list. | |
void | call (Types... args) |
Call all the callbacks with the given arguments. | |
void | hook (fge::CallbackHandler< Types... > &handler, fge::Subscriber *subscriber=nullptr) |
Hook a callback handler to this handler. | |
Protected Member Functions | |
void | onDetach (fge::Subscriber *subscriber) override |
This method is called when a subscriber is destroyed (destructor called) | |
void | detachAll () |
Detach all subscribers. | |
bool | detach (fge::Subscriber *subscriber) |
Detach a specific subscriber. | |
fge::Subscription::SubscriberCount | detachOnce (fge::Subscriber *subscriber) |
Detach only once a specific subscriber. | |
fge::Subscription::SubscriberCount | attach (fge::Subscriber *subscriber) |
Attach a specific subscriber. | |
fge::Subscription::SubscriberCount | getCount (fge::Subscriber *subscriber) const |
Get the SubscriberCount of a specific subscriber. | |
This class is used to handle callbacks in a safe way.
Every callback muse use the same template parameters Types than a handler. This class is thread-safe.
This class inherits from Subscription to be able to subscribe to it. When a subscriber is added to a handler and is destroyed, all the callbacks related to this subscriber are automatically removed.
Types | The list of arguments types passed to the callbacks |
|
inline |
Copy constructor that does nothing.
|
delete |
Move constructor prohibited.
|
inline |
Add a new callback to the list.
A subscriber can be passed to this function to "categorize" the callback. The subscriber will be used to remove the group of callbacks related to him later.
You can pass a nullptr to the subscriber parameter if you don't want to use it, if so the callback will be added to the default group.
To facilitate your code, you can use the helper methods addFunctor(), addLambda() and addObjectFunctor().
callback | The new callback to add |
subscriber | The subscriber to use to categorize the callback |
|
inline |
Helper method to add a callback functor.
func | The callback function |
subscriber | The subscriber to use to categorize the callback |
|
inline |
Helper method to add a callback lambda.
TLambda | The lambda type |
lambda | The callback lambda |
subscriber | The subscriber to use to categorize the callback |
|
inline |
Helper method to add a callback object functor.
TObject | The object type |
func | The callback method of the object |
object | The object pointer |
subscriber | The subscriber to use to categorize the callback |
|
protectedinherited |
Attach a specific subscriber.
You can't directly attach a nullptr global scope subscriber. But if you do, this function will do nothing and return 1 as the SubscriberCount.
subscriber | The subscriber to attach |
void fge::CallbackHandler< Types >::call | ( | Types... | args | ) |
Call all the callbacks with the given arguments.
args | The list of arguments |
|
inline |
Clear the list of callbacks.
void fge::CallbackHandler< Types >::del | ( | fge::CallbackBase< Types... > * | callback | ) |
Remove a callback from the list.
Remove a callback with the specified pointer.
callback | The callback to remove |
void fge::CallbackHandler< Types >::delPtr | ( | void * | ptr | ) |
Remove a callback from the list.
You can remove a callback with the specified function/object pointer.
ptr | The function/object pointer to remove |
void fge::CallbackHandler< Types >::delSub | ( | fge::Subscriber * | subscriber | ) |
Remove a callback from the list.
Remove a group of callbacks with the specified subscriber or nullptr for the default group.
subscriber | The subscriber associated to the group of callbacks |
|
protectedinherited |
Detach a specific subscriber.
Detaching a nullptr global scope subscriber will do nothing.
subscriber | The subscriber to detach |
|
protectedinherited |
Detach all subscribers.
|
protectedinherited |
Detach only once a specific subscriber.
You can attach a subscriber multiple times and it will augment the SubscriberCount. This function will only detach one time the subscriber and decrement the SubscriberCount. If the SubscriberCount is 0, the subscriber will be detached.
subscriber | The subscriber to detach |
|
protectedinherited |
Get the SubscriberCount of a specific subscriber.
subscriber | The subscriber to get the SubscriberCount |
void fge::CallbackHandler< Types >::hook | ( | fge::CallbackHandler< Types... > & | handler, |
fge::Subscriber * | subscriber = nullptr ) |
Hook a callback handler to this handler.
This will propagate the calls from this handler to the given handler of the same type.
handler | Another handler of the same type |
subscriber | The subscriber associated with this handler |
|
overrideprotectedvirtual |
This method is called when a subscriber is destroyed (destructor called)
This avoid calling the callbacks when the subscriber is destroyed.
subscriber | The subscriber that is destroyed (or going to be destroyed) |
Implements fge::Subscription.
|
delete |
Move operator prohibited.
|
inline |
Copy operator that does nothing.