FastEngine 0.9.5
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::UniqueCallbackHandler< Types > Class Template Reference

This class is used for cases where only one callback is needed. More...

#include <C_callback.hpp>

Inheritance diagram for fge::UniqueCallbackHandler< Types >:
fge::UniqueSubscription fge::BaseSubscription

Public Types

using CalleePtr = CalleeUniquePtr<void, Types...>
using StaticHelpers = CallbackStaticHelpers<void, CalleePtr, Types...>
using SubscriberCount = unsigned int

Public Member Functions

 UniqueCallbackHandler (fge::UniqueCallbackHandler< Types... > const &n)
 Copy constructor that does nothing.
 UniqueCallbackHandler (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 ()
fge::CallbackBase< void, Types... > * set (CalleePtr &&callback, fge::Subscriber *subscriber=nullptr)
 Set a new callback to the handler, replacing the previous one if it exists.
fge::CallbackFunctor< void, Types... > * setFunctor (typename fge::CallbackFunctor< void, Types... >::CallbackFunction func, fge::Subscriber *subscriber=nullptr)
 Helper method to set a callback functor.
template<typename TLambda>
fge::CallbackLambda< void, Types... > * setLambda (TLambda const &lambda, fge::Subscriber *subscriber=nullptr)
 Helper method to set a callback lambda.
template<class TObject>
fge::CallbackObjectFunctor< void, TObject, Types... > * setObjectFunctor (typename fge::CallbackObjectFunctor< void, TObject, Types... >::CallbackFunctionObject func, TObject *object, Subscriber *subscriber=nullptr)
 Helper method to set a callback object functor.
void delPtr (void *ptr)
 Remove the callback if the function/object pointer is the same as the one used to construct the callback.
void delSub (fge::Subscriber *subscriber)
 Remove the callback if the subscriber is the same as the one used to construct the callback.
void del (fge::CallbackBase< Types... > *callback)
 Remove the callback if the callback pointer is the same as the one used to construct the callback.
void call (Types... args)
 Call the callback with the given arguments.

Protected Member Functions

void onDetach (fge::Subscriber *subscriber) override
 This method is called when a subscriber is destroyed (destructor called).
void detachAll () override
 Detach all subscribers.
bool detach (fge::Subscriber *subscriber) override
 Detach a specific subscriber.
SubscriberCount detachOnce (fge::Subscriber *subscriber) override
 Detach only once a specific subscriber.
SubscriberCount attach (fge::Subscriber *subscriber) override
 Attach a specific subscriber.
SubscriberCount getCount (fge::Subscriber *subscriber) const override
 Get the SubscriberCount of a specific subscriber.

Detailed Description

template<class... Types>
class fge::UniqueCallbackHandler< Types >

This class is used for cases where only one callback is needed.

See also
CallbackHandler
Template Parameters
TypesThe list of arguments types passed to the callbacks

Constructor & Destructor Documentation

◆ UniqueCallbackHandler() [1/2]

template<class... Types>
fge::UniqueCallbackHandler< Types >::UniqueCallbackHandler ( fge::UniqueCallbackHandler< Types... > const & n)
inline

Copy constructor that does nothing.

◆ UniqueCallbackHandler() [2/2]

template<class... Types>
fge::UniqueCallbackHandler< Types >::UniqueCallbackHandler ( fge::CallbackHandler< Types... > && n)
delete

Move constructor prohibited.

Member Function Documentation

◆ attach()

SubscriberCount fge::UniqueSubscription::attach ( fge::Subscriber * subscriber)
overrideprotectedvirtualinherited

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.

Parameters
subscriberThe subscriber to attach
Returns
The SubscriberCount

Implements fge::BaseSubscription.

◆ call()

template<class... Types>
void fge::UniqueCallbackHandler< Types >::call ( Types... args)

Call the callback with the given arguments.

Parameters
argsThe list of arguments

◆ del()

template<class... Types>
void fge::UniqueCallbackHandler< Types >::del ( fge::CallbackBase< Types... > * callback)

Remove the callback if the callback pointer is the same as the one used to construct the callback.

Parameters
CallbackThe callback to remove

◆ delPtr()

template<class... Types>
void fge::UniqueCallbackHandler< Types >::delPtr ( void * ptr)

Remove the callback if the function/object pointer is the same as the one used to construct the callback.

Parameters
ptrThe function/object pointer to remove

◆ delSub()

template<class... Types>
void fge::UniqueCallbackHandler< Types >::delSub ( fge::Subscriber * subscriber)

Remove the callback if the subscriber is the same as the one used to construct the callback.

Parameters
subscriberThe potential subscriber associated to the callback to remove

◆ detach()

bool fge::UniqueSubscription::detach ( fge::Subscriber * subscriber)
overrideprotectedvirtualinherited

Detach a specific subscriber.

Detaching a nullptr global scope subscriber will do nothing.

Parameters
subscriberThe subscriber to detach
Returns
true if the subscriber was detached, false otherwise

Implements fge::BaseSubscription.

◆ detachAll()

void fge::UniqueSubscription::detachAll ( )
overrideprotectedvirtualinherited

Detach all subscribers.

Implements fge::BaseSubscription.

◆ detachOnce()

SubscriberCount fge::UniqueSubscription::detachOnce ( fge::Subscriber * subscriber)
overrideprotectedvirtualinherited

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.

Parameters
subscriberThe subscriber to detach
Returns
The remaining SubscriberCount

Implements fge::BaseSubscription.

◆ getCount()

SubscriberCount fge::UniqueSubscription::getCount ( fge::Subscriber * subscriber) const
overrideprotectedvirtualinherited

Get the SubscriberCount of a specific subscriber.

Parameters
subscriberThe subscriber to get the SubscriberCount
Returns
The SubscriberCount

Implements fge::BaseSubscription.

◆ onDetach()

template<class... Types>
void fge::UniqueCallbackHandler< Types >::onDetach ( fge::Subscriber * subscriber)
overrideprotectedvirtual

This method is called when a subscriber is destroyed (destructor called).

This avoids calling the callbacks when the subscriber is destroyed.

Parameters
subscriberThe subscriber that is destroyed (or going to be destroyed)

Implements fge::BaseSubscription.

◆ operator=() [1/2]

template<class... Types>
fge::CallbackHandler< Types... > & fge::UniqueCallbackHandler< Types >::operator= ( fge::CallbackHandler< Types... > && n)
delete

Move operator prohibited.

◆ operator=() [2/2]

template<class... Types>
fge::CallbackHandler< Types... > & fge::UniqueCallbackHandler< Types >::operator= ( fge::CallbackHandler< Types... > const & n)
inline

Copy operator that does nothing.

◆ set()

template<class... Types>
fge::CallbackBase< void, Types... > * fge::UniqueCallbackHandler< Types >::set ( CalleePtr && callback,
fge::Subscriber * subscriber = nullptr )
inline

Set a new callback to the handler, replacing the previous one if it exists.

See also
fge::CallbackHandler::add()
Parameters
CallbackThe new callback to set
subscriberThe subscriber to use to categorize the callback
Returns
The callback pointer

◆ setFunctor()

template<class... Types>
fge::CallbackFunctor< void, Types... > * fge::UniqueCallbackHandler< Types >::setFunctor ( typename fge::CallbackFunctor< void, Types... >::CallbackFunction func,
fge::Subscriber * subscriber = nullptr )
inline

Helper method to set a callback functor.

See also
fge::CallbackHandler::add()
Parameters
funcThe callback function
subscriberThe subscriber to use to categorize the callback
Returns
The callback pointer

◆ setLambda()

template<class... Types>
template<typename TLambda>
fge::CallbackLambda< void, Types... > * fge::UniqueCallbackHandler< Types >::setLambda ( TLambda const & lambda,
fge::Subscriber * subscriber = nullptr )
inline

Helper method to set a callback lambda.

See also
fge::CallbackHandler::add()
Template Parameters
TLambdaThe lambda type
Parameters
lambdaThe callback lambda
subscriberThe subscriber to use to categorize the callback
Returns
The callback pointer

◆ setObjectFunctor()

template<class... Types>
template<class TObject>
fge::CallbackObjectFunctor< void, TObject, Types... > * fge::UniqueCallbackHandler< Types >::setObjectFunctor ( typename fge::CallbackObjectFunctor< void, TObject, Types... >::CallbackFunctionObject func,
TObject * object,
Subscriber * subscriber = nullptr )
inline

Helper method to set a callback object functor.

See also
fge::CallbackHandler::add()
Template Parameters
TObjectThe object type
Parameters
funcThe callback method of the object
objectThe object pointer
subscriberThe subscriber to use to categorize the callback
Returns
The callback pointer

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