Skip to main content

Event.ixx File

Base class for events in the helios framework. More...

Included Headers

#include <memory> #include <string> #include <helios.util.Guid>

Namespaces Index

namespacehelios
namespaceevent

Event system. More...

Classes Index

classEvent

Base class for events in the helios framework. More...

Description

Base class for events in the helios framework.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file Event.ixx
3 * @brief Base class for events in the helios framework.
4 */
5module;
6
7#include <memory>
8#include <string>
9
10export module helios.event.Event;
11
12import helios.util.Guid;
13
14export namespace helios::event {
15
16 /**
17 * @brief Base class for events in the helios framework.
18 *
19 * `Event` provides a common interface for all application related events.
20 * Each event instance is uniquely identified by a `Guid` generated upon
21 * construction. An additional tag can be provided to identify groups of events
22 * for further categorization or filtering.
23 *
24 * Events should be treated as immutable after construction.
25 *
26 * @todo can we reset the value for Guids in between frames, if events
27 * are guaranteed to be dispatched and processed in between frames?
28 */
29 class Event {
30 private:
31 /**
32 * @brief The guid uniquely identifying _this_ event.
33 */
34 const helios::util::Guid guid_;
35
36 /**
37 * @brief An optional tag for this event. Defaults to 0
38 */
39 const uint64_t tag_;
40
41 public:
42 virtual ~Event() =default;
43
44
45 /**
46 * @brief Constructs a new event with a unique Guid and a default tag of 0
47 */
48 Event(): guid_(helios::util::Guid::generate()), tag_(0) {}
49
50
51 /**
52 * @brief Constructs a new event with a unique Guid and the specified default tag.
53 *
54 * @param tag
55 */
56 explicit Event(uint64_t tag): guid_(helios::util::Guid::generate()), tag_(tag) {}
57
58
59 /**
60 * @brief Returns a const reference to this event's unique Guid.
61 *
62 * @return
63 */
64 [[nodiscard]] const helios::util::Guid& guid() const {
65 return guid_;
66 }
67
68
69 /**
70 * @brief Returns the tag for this event.
71 * Will be 0 if none was specified.
72 *
73 * @return
74 */
75 [[nodiscard]] uint64_t tag() const {
76 return tag_;
77 }
78
79 [[nodiscard]] virtual std::string toString() const noexcept = 0;
80
81 /**
82 * @brief Compares two event instances based on their unique Guids.
83 * @param e
84 * @return
85 */
86 bool operator==(const Event& e) const {
87 return guid_ == e.guid();
88 }
89
90 };
91
92}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.