Loading...
Searching...
No Matches
Subscribable.h
Go to the documentation of this file.
1//
2// Created by Dave R. Smith on 3/5/25.
3//
4
5#ifndef SUBSCRIBABLE_H
6#define SUBSCRIBABLE_H
7
8#pragma once
9
14namespace ml
15{
59 {
60 public:
74 template<typename ENUM_TYPE>
75 void subscribe(ENUM_TYPE event, EventCallback callback);
76
87 template<typename ENUM_TYPE>
88 void subscribe(ENUM_TYPE event, Callback callback);
89
108 template<typename ENUM_TYPE>
109 void publish(ENUM_TYPE event,
110 FilterCallback filter = [](EventReceiver&){ return true; },
111 SystemCallback resolve = nullptr,
112 SystemCallback reject = nullptr);
113 };
114
116 class SubscribableDispatcher : public EventDispatcher
117 {
118 public:
119 void fire(const std::optional<sf::Event>& event) override {};
120 bool occurred(const std::optional<sf::Event>& event) override {};
121 };
123
124} // namespace ml
125#include "../../../src/Traits/Subscribable.tpp"
126
127ML_EXPORT(SubscribableDispatcher)
128#endif // MESSAGEMANAGER_H
#define ML_EXPORT(ClassName)
Register a Malena type with the framework.
Definition Export.h:38
Base class for all event-receiving traits.
Trait that allows a component to subscribe to and publish framework events.
void subscribe(ENUM_TYPE event, Callback callback)
Subscribe to an enum-keyed event with a no-argument callback.
void subscribe(ENUM_TYPE event, EventCallback callback)
Subscribe to an enum-keyed event with a full SFML event callback.
void publish(ENUM_TYPE event, FilterCallback filter=[](EventReceiver &){ return true;}, SystemCallback resolve=nullptr, SystemCallback reject=nullptr)
Fire an enum-keyed event to all matching subscribers.
std::function< void(const std::optional< sf::Event > &)> EventCallback
Callback type for event handlers that receive the raw SFML event.
Definition Callback.h:31
std::function< void()> Callback
Callback type for no-argument event handlers.
Definition Callback.h:45
Definition Component.h:18