FastEngine 0.9.5
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::BaseSubscription 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< fge::net::ClientSideNetUdp & > fge::CallbackHandler< fge::net::ClientSideNetUdp &, TransmitPacketPtr & > fge::CallbackHandler< Event > fge::CallbackHandler< ClientSharedPtr const & > fge::CallbackHandler< ClientSharedPtr, fge::net::Identity const & > fge::CallbackHandler< ClientSharedPtr const &, fge::net::Identity const & > fge::CallbackHandler< Types >

Public Types

using SubscriberCount = unsigned int

Public Member Functions

 Subscription (fge::Subscription const &r)
 Subscription (fge::Subscription &&r) noexcept
 ~Subscription () override
 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

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

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 global scope).

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

See also
BaseSubscription 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()

fge::Subscription::~Subscription ( )
inlineoverride

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

Member Function Documentation

◆ attach()

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

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.

◆ detach()

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

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::Subscription::detachAll ( )
overrideprotectedvirtual

Detach all subscribers.

Implements fge::BaseSubscription.

◆ detachOnce()

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

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::Subscription::getCount ( fge::Subscriber * subscriber) const
overrideprotectedvirtual

Get the SubscriberCount of a specific subscriber.

Parameters
subscriberThe subscriber to get the SubscriberCount
Returns
The SubscriberCount

Implements fge::BaseSubscription.

◆ onDetach()

virtual void fge::BaseSubscription::onDetach ( fge::Subscriber * subscriber)
protectedpure virtualinherited

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< ClientSharedPtr const &, fge::net::Identity const & >, fge::CallbackHandler< ClientSharedPtr, fge::net::Identity const & >, fge::CallbackHandler< Event >, 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::net::ClientSideNetUdp & >, fge::CallbackHandler< fge::net::ClientSideNetUdp &, TransmitPacketPtr & >, 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 & >, fge::CallbackHandler< float >, fge::UniqueCallbackHandler< Types >, fge::UniqueCallbackHandler< ClientSharedPtr const &, fge::net::Identity const & >, fge::UniqueCallbackHandler< ClientSharedPtr const &, fge::net::Identity const &, ReceivedPacketPtr const & >, fge::UniqueCallbackHandler< ClientSharedPtr const &, fge::net::Identity const &, uint16_t >, fge::UniqueCallbackHandler< ClientSharedPtr const &, fge::net::Identity const &, uint16_t, ObjectSid, ObjectSid, ReceivedPacketPtr const & >, and fge::UniqueCallbackHandler< ClientSharedPtr const &, fge::net::Identity const &, uint16_t, ReceivedPacketPtr const & >.

◆ 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: