ActiveLib
Loading...
Searching...
No Matches
Event.h
1
6#ifndef ACTIVE_EVENT_EVENT
7#define ACTIVE_EVENT_EVENT
8
9#include "Active/Event/PostBox.h"
10#include "Active/Setting/SettingList.h"
11#include "Active/Utility/NameID.h"
12
13namespace active::event {
14
15 class Message;
16
29 public:
30
31 // MARK: - Types
32
34 using Unique = std::unique_ptr<Event>;
36 using Shared = std::shared_ptr<Event>;
38 using Option = std::optional<Event>;
39
40 // MARK: - Constructors
41
45 Event() {}
51 Event(const utility::NameID& nameID, PostBox* postBox = nullptr) : utility::NameID{nameID}, setting::SettingList{} { m_postBox = postBox; }
58 Event(const NameID& nameID, setting::SettingList&& settings, PostBox* postBox = nullptr) :
59 utility::NameID{nameID}, setting::SettingList{std::move(settings)} { m_postBox = postBox; }
63 virtual ~Event() {}
64
69 virtual Event* clonePtr() const { return new Event{*this}; }
70
71 // MARK: - Operators
72
78 bool operator== (const Event& ref) const { return utility::NameID::operator==(ref); } //Events are matched by identity
84 bool operator== (const NameID& ref) const { return utility::NameID::operator==(ref); }
90 bool operator!= (const Event& ref) const { return !(*this == ref); }
91
92 // MARK: - Functions (const)
93
98 void tellAuthor(Message&& message) const {
99 if (m_postBox != nullptr)
100 m_postBox->receive(std::move(message));
101 }
102
103 // MARK: - Functions (mutating)
104
105
106 private:
107 //The post box for message sent from subscribers to the published event author
108 PostBox* m_postBox = nullptr;
109 };
110
111}
112
113#endif //ACTIVE_EVENT_EVENT
Definition Event.h:28
Event(const NameID &nameID, setting::SettingList &&settings, PostBox *postBox=nullptr)
Definition Event.h:58
bool operator==(const Event &ref) const
Definition Event.h:78
virtual Event * clonePtr() const
Definition Event.h:69
void tellAuthor(Message &&message) const
Definition Event.h:98
std::unique_ptr< Event > Unique
Unique pointer.
Definition Event.h:34
Event(const utility::NameID &nameID, PostBox *postBox=nullptr)
Definition Event.h:51
bool operator!=(const Event &ref) const
Definition Event.h:90
std::optional< Event > Option
Optional.
Definition Event.h:38
Event()
Definition Event.h:45
std::shared_ptr< Event > Shared
Shared pointer.
Definition Event.h:36
virtual ~Event()
Definition Event.h:63
Definition Message.h:18
Definition PostBox.h:18
virtual void receive(Message &&message)
Definition PostBox.h:32
A list of settings.
Definition SettingList.h:15
SettingList()
Definition SettingList.h:36
Definition NameID.h:21
NameID()
Definition NameID.h:34
bool operator==(const NameID &ref) const
Definition NameID.h:68
Definition Event.h:13