![]() |
FastEngine 0.9.5
A multiplayer oriented 2D engine made with Vulkan.
|
This class is a useful utility to "link" multiple objects around a specific use with automatic lifetime management. More...
#include <C_subscription.hpp>
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::Subscription & | operator= (fge::Subscription const &r) |
| fge::Subscription & | operator= (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. | |
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.
|
inline |
|
inlineoverride |
When the object is destroyed, it will detach all subscribers.
|
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.
| subscriber | The subscriber to attach |
Implements fge::BaseSubscription.
|
overrideprotectedvirtual |
Detach a specific subscriber.
Detaching a nullptr global scope subscriber will do nothing.
| subscriber | The subscriber to detach |
Implements fge::BaseSubscription.
|
overrideprotectedvirtual |
Detach all subscribers.
Implements fge::BaseSubscription.
|
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.
| subscriber | The subscriber to detach |
Implements fge::BaseSubscription.
|
overrideprotectedvirtual |
Get the SubscriberCount of a specific subscriber.
| subscriber | The subscriber to get the SubscriberCount |
Implements fge::BaseSubscription.
|
protectedpure virtualinherited |
Callback called when a subscriber is detached.
The subscriber, at this point, can't be nullptr.
| subscriber | The 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 & >.
|
inline |