![]() |
FastEngine 0.9.3
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 | |
virtual | ~Subscription () |
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 | |
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 |
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.
|
inline |
|
inlinevirtual |
When the object is destroyed, it will detach all subscribers.
|
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.
subscriber | The subscriber to attach |
|
protected |
Detach a specific subscriber.
Detaching a nullptr global scope subscriber will do nothing.
subscriber | The subscriber to detach |
|
protected |
Detach all subscribers.
|
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.
subscriber | The subscriber to detach |
|
protected |
Get the SubscriberCount of a specific subscriber.
subscriber | The subscriber to get the SubscriberCount |
|
protectedpure virtual |
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< 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 >.
|
inline |