FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::Subscription Class Referenceabstract

This class is a useful utility to "link" multiple objects around a specific use with automatic lifetime management. More...

#include <C_subscription.hpp>

Inheritance diagram for fge::Subscription:
fge::CallbackHandler< fge::Event const &, SDL_QuitEvent const & > fge::CallbackHandler< fge::Event const &, SDL_CommonEvent const & > fge::CallbackHandler< fge::Event const &, SDL_WindowEvent const & > fge::CallbackHandler< fge::Event const &, SDL_SysWMEvent const & > fge::CallbackHandler< fge::Event const &, SDL_KeyboardEvent const & > fge::CallbackHandler< fge::Event const &, SDL_TextEditingEvent const & > fge::CallbackHandler< fge::Event const &, SDL_TextInputEvent const & > fge::CallbackHandler< fge::Event const &, SDL_MouseMotionEvent const & > fge::CallbackHandler< fge::Event const &, SDL_MouseButtonEvent const & > fge::CallbackHandler< fge::Event const &, SDL_MouseWheelEvent const & > fge::CallbackHandler< fge::Event const &, SDL_JoyAxisEvent const & > fge::CallbackHandler< fge::Event const &, SDL_JoyBallEvent const & > fge::CallbackHandler< fge::Event const &, SDL_JoyHatEvent const & > fge::CallbackHandler< fge::Event const &, SDL_JoyButtonEvent const & > fge::CallbackHandler< fge::Event const &, SDL_JoyDeviceEvent const & > fge::CallbackHandler< fge::Event const &, SDL_ControllerAxisEvent const & > fge::CallbackHandler< fge::Event const &, SDL_ControllerButtonEvent const & > fge::CallbackHandler< fge::Event const &, SDL_ControllerDeviceEvent const & > fge::CallbackHandler< fge::Event const &, SDL_TouchFingerEvent const & > fge::CallbackHandler< fge::Event const &, SDL_DollarGestureEvent const & > fge::CallbackHandler< fge::Event const &, SDL_MultiGestureEvent const & > fge::CallbackHandler< fge::Event const &, SDL_DropEvent const & > fge::CallbackHandler< fge::Event const &, SDL_AudioDeviceEvent const & > fge::CallbackHandler< fge::Event const &, SDL_MouseWheelEvent const &, fge::GuiElementContext & > fge::CallbackHandler< fge::Event const &, SDL_MouseButtonEvent const &, fge::GuiElementContext & > fge::CallbackHandler< fge::Event const &, SDL_MouseMotionEvent const &, fge::GuiElementContext & > fge::CallbackHandler< fge::Vector2f const & > fge::CallbackHandler< fge::Event const &, SDL_EventType, fge::GuiElementContext & > fge::CallbackHandler< fge::GuiElementHandler const &, fge::Vector2f const & > fge::CallbackHandler< fge::ObjButton * > fge::CallbackHandler< fge::ObjSelectBox &, std::size_t > fge::CallbackHandler< float > fge::CallbackHandler< fge::ObjTextInputBox & > fge::CallbackHandler< fge::ObjWindow & > fge::CallbackHandler< fge::Scene const &, fge::RenderTarget & > fge::CallbackHandler< fge::Scene &, fge::ObjectDataShared const & > fge::CallbackHandler< fge::Scene &, fge::ObjectPlan > fge::CallbackHandler< fge::Scene & > fge::CallbackHandler< fge::TaskHandler & > fge::CallbackHandler< fge::Timer & > fge::CallbackHandler< fge::net::Client & > fge::CallbackHandler< ClientSharedPtr const & > fge::CallbackHandler< Types >

Public Types

using SubscriberCount = unsigned int
 

Public Member Functions

 Subscription (fge::Subscription const &r)
 
 Subscription (fge::Subscription &&r) noexcept
 
virtual ~Subscription ()
 When the object is destroyed, it will detach all subscribers.
 
fge::Subscriptionoperator= (fge::Subscription const &r)
 
fge::Subscriptionoperator= (fge::Subscription &&r) noexcept
 

Protected Member Functions

virtual void onDetach (fge::Subscriber *subscriber)=0
 Callback called when a subscriber is detached.
 
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.
 

Friends

class fge::Subscriber
 

Detailed Description

This class is a useful utility to "link" multiple objects around a specific use with automatic lifetime management.

A good example is the callback system. When inheriting from Subscriber, you will be able to subscribe a function to a CallbackHandler (inheriting from Subscription) and you don't have to worry about unsubscribing it when the object is destroyed.

A nullptr subscriber mean that you are subscribing something that is not class related. (sort of a global scope).

Alone this class will not do much as you have to implement the required functionality around it.

See also
CallbackHandler

Constructor & Destructor Documentation

◆ Subscription()

fge::Subscription::Subscription ( fge::Subscription const & r)
inline
Warning
Empty copy constructor as it's not permitted (does nothing)

◆ ~Subscription()

virtual fge::Subscription::~Subscription ( )
inlinevirtual

When the object is destroyed, it will detach all subscribers.

Member Function Documentation

◆ attach()

fge::Subscription::SubscriberCount fge::Subscription::attach ( fge::Subscriber * subscriber)
protected

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

◆ detach()

bool fge::Subscription::detach ( fge::Subscriber * subscriber)
protected

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

◆ detachAll()

void fge::Subscription::detachAll ( )
protected

Detach all subscribers.

◆ detachOnce()

fge::Subscription::SubscriberCount fge::Subscription::detachOnce ( fge::Subscriber * subscriber)
protected

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

◆ getCount()

fge::Subscription::SubscriberCount fge::Subscription::getCount ( fge::Subscriber * subscriber) const
protected

Get the SubscriberCount of a specific subscriber.

Parameters
subscriberThe subscriber to get the SubscriberCount
Returns
The SubscriberCount

◆ onDetach()

virtual void fge::Subscription::onDetach ( fge::Subscriber * subscriber)
protectedpure virtual

Callback called when a subscriber is detached.

The subscriber, at this point, can't be nullptr.

Parameters
subscriberThe subscriber that was detached

Implemented in fge::CallbackHandler< Types >, fge::CallbackHandler< ClientSharedPtr const & >, fge::CallbackHandler< fge::Event const &, SDL_AudioDeviceEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_CommonEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_ControllerAxisEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_ControllerButtonEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_ControllerDeviceEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_DollarGestureEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_DropEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_EventType, fge::GuiElementContext & >, fge::CallbackHandler< fge::Event const &, SDL_JoyAxisEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_JoyBallEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_JoyButtonEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_JoyDeviceEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_JoyHatEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_KeyboardEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_MouseButtonEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_MouseButtonEvent const &, fge::GuiElementContext & >, fge::CallbackHandler< fge::Event const &, SDL_MouseMotionEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_MouseMotionEvent const &, fge::GuiElementContext & >, fge::CallbackHandler< fge::Event const &, SDL_MouseWheelEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_MouseWheelEvent const &, fge::GuiElementContext & >, fge::CallbackHandler< fge::Event const &, SDL_MultiGestureEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_QuitEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_SysWMEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_TextEditingEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_TextInputEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_TouchFingerEvent const & >, fge::CallbackHandler< fge::Event const &, SDL_WindowEvent const & >, fge::CallbackHandler< fge::GuiElementHandler const &, fge::Vector2f const & >, fge::CallbackHandler< fge::net::Client & >, fge::CallbackHandler< fge::ObjButton * >, fge::CallbackHandler< fge::ObjSelectBox &, std::size_t >, fge::CallbackHandler< fge::ObjTextInputBox & >, fge::CallbackHandler< fge::ObjWindow & >, fge::CallbackHandler< fge::Scene & >, fge::CallbackHandler< fge::Scene &, fge::ObjectDataShared const & >, fge::CallbackHandler< fge::Scene &, fge::ObjectPlan >, fge::CallbackHandler< fge::Scene const &, fge::RenderTarget & >, fge::CallbackHandler< fge::TaskHandler & >, fge::CallbackHandler< fge::Timer & >, fge::CallbackHandler< fge::Vector2f const & >, and fge::CallbackHandler< float >.

◆ operator=()

fge::Subscription & fge::Subscription::operator= ( fge::Subscription const & r)
inline
Warning
Empty copy operator as it's not permitted (does nothing)

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