Loading...
Searching...
No Matches
Subscribable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith. All rights reserved.
2// Malena Framework — Proprietary Software. See LICENSE for terms.
3
4//
5// Created by Dave R. Smith on 3/5/25.
6//
7
8#ifndef MALENA_SUBSCRIBABLE_H
9#define MALENA_SUBSCRIBABLE_H
10
11#pragma once
12
18#include <optional>
19namespace ml
20{
64 {
65 public:
79 template<typename ENUM_TYPE>
80 void subscribe(ENUM_TYPE event, EventCallback callback);
81
92 template<typename ENUM_TYPE>
93 void subscribe(ENUM_TYPE event, Callback callback);
94
113 template<typename ENUM_TYPE>
114 void publish(ENUM_TYPE event,
115 FilterCallback filter = [](EventReceiver&){ return true; },
116 SystemCallback resolve = nullptr,
117 SystemCallback reject = nullptr);
118 };
119
121 class MALENA_API SubscribableDispatcher : public EventDispatcher
122 {
123 public:
124 void fire(const std::optional<sf::Event>& event) override {};
125 bool occurred(const std::optional<sf::Event>& event) override {return false;};
126 };
128
129} // namespace ml
130#include "../../../../src/Traits/Communication/Subscribable.tpp"
131
132ML_EXPORT(SubscribableDispatcher)
133#endif // MESSAGEMANAGER_H
#define ML_EXPORT(ClassName)
Register a Malena type with the framework.
Definition Export.h:43
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:35
std::function< void()> Callback
Callback type for no-argument event handlers.
Definition Callback.h:49
#define MALENA_API
Definition Component.h:22