λ61
Loading...
Searching...
No Matches
EventBus.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Tetex7
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18//
19// Created by tete on 05/30/2025.
20//
21#pragma once
22#ifndef L61_EVENT_SYSTEM_EVENTBUS_HPP
23#define L61_EVENT_SYSTEM_EVENTBUS_HPP
24#include <cstdint>
25#include <map>
26#include <variant>
27#include <string>
28#include <queue>
29#include <memory>
30#include <set>
31#include <format>
32
35#include "l61/meta.hpp"
37#include "l61/baseTypes.hpp"
39
40
41
42
43namespace l61::EventSystem
44{
48 class EventBus final : public IEventBusContainer
49 {
50 private:
51 std::unordered_map<bus_frequency_t, std::unordered_map<bus_frequency_t, std::unique_ptr<Event>>> _map;
52 std::queue<bus_frequency_t> _freq_stack;
53 public:
54
55 bool addEvent(const bus_frequency_t& freq, const bus_frequency_t& sub_freq, const Event& event) override;
56 void removeEvent(const bus_frequency_t& freq, const bus_frequency_t& sub_freq) override;
57
58 void removeFrequency(const bus_frequency_t& freq) override;
59
60 void pumpIt();
61
62 void push(const bus_frequency_t& freq);
63 void pushBand(const std::set<bus_frequency_t>& freqBand);
64
66 void pushBand(Ty&&... vals)
67 {
68 this->pushBand({std::forward<Ty>(vals)...});
69 }
70
71 void addEventBand(const std::set<std::tuple<const bus_frequency_t&, const bus_frequency_t&, const Event&>>& eventBand);
72
73 explicit EventBus() = default;
74 ~EventBus() override = default;
75
76 void operator[](const bus_frequency_t &frequency);
77
78 EventBus(EventBus&&) = delete;
79 EventBus(EventBus&) = delete;
80 EventBus(const EventBus&) = delete;
81 EventBus& operator=(const EventBus&) = delete;
82 };
83
84
85 void runEventBus(EventBus& bus, SignalQueue_t& signals);
86}
87
88
89
90#endif //L61_EVENT_SYSTEM_EVENTBUS_HPP
This is an event bus leveraging l61::EventSystem::Event.
Definition EventBus.hpp:49
void operator[](const bus_frequency_t &frequency)
Definition EventBus.cpp:93
std::queue< bus_frequency_t > _freq_stack
Definition EventBus.hpp:52
EventBus(const EventBus &)=delete
EventBus(EventBus &)=delete
void push(const bus_frequency_t &freq)
Definition EventBus.cpp:72
void pushBand(Ty &&... vals)
Definition EventBus.hpp:66
~EventBus() override=default
void pumpIt()
Definition EventBus.cpp:54
void addEventBand(const std::set< std::tuple< const bus_frequency_t &, const bus_frequency_t &, const Event & > > &eventBand)
Definition EventBus.cpp:85
void removeFrequency(const bus_frequency_t &freq) override
Definition EventBus.cpp:46
EventBus & operator=(const EventBus &)=delete
void pushBand(const std::set< bus_frequency_t > &freqBand)
Definition EventBus.cpp:77
bool addEvent(const bus_frequency_t &freq, const bus_frequency_t &sub_freq, const Event &event) override
Definition EventBus.cpp:31
void removeEvent(const bus_frequency_t &freq, const bus_frequency_t &sub_freq) override
Definition EventBus.cpp:38
std::unordered_map< bus_frequency_t, std::unordered_map< bus_frequency_t, std::unique_ptr< Event > > > _map
Definition EventBus.hpp:51
EventBus(EventBus &&)=delete
Definition Event.hpp:32
Definition Event.hpp:27
l61_interface IEventBusContainer
Definition IEventBusContainer.hpp:31
void runEventBus(EventBus &bus, SignalQueue_t &signals)
Definition EventBus.cpp:99
std::variant< std::int32_t, std::string > bus_frequency_t
Definition types.hpp:39
std::queue< c_signal_t > SignalQueue_t
Definition baseTypes.hpp:29