openMSX
Event.hh
Go to the documentation of this file.
1 #ifndef EVENT_HH
2 #define EVENT_HH
3 
4 #include <string>
5 
6 namespace openmsx {
7 
8 class TclObject;
9 
11 {
36  OPENMSX_BOOT_EVENT, // sent when the MSX resets or power ups
37 
40 
46 
49 
52 
55 
58 
61 
66 
70 
76 
77  NUM_EVENT_TYPES // must be last
78 };
79 
80 class Event
81 {
82 public:
83  Event(const Event&) = delete;
84  Event& operator=(const Event&) = delete;
85 
86  [[nodiscard]] EventType getType() const { return type; }
87 
89  [[nodiscard]] std::string toString() const;
90 
92  [[nodiscard]] virtual TclObject toTclList() const = 0;
93 
94  [[nodiscard]] bool operator< (const Event& other) const;
95  [[nodiscard]] bool operator> (const Event& other) const;
96  [[nodiscard]] bool operator<=(const Event& other) const;
97  [[nodiscard]] bool operator>=(const Event& other) const;
98  [[nodiscard]] bool operator==(const Event& other) const;
99  [[nodiscard]] bool operator!=(const Event& other) const;
100 
104  [[nodiscard]] virtual bool isRepeatStopper(const Event& /*other*/) const {
105  return true;
106  }
107 
111  [[nodiscard]] virtual bool matches(const Event& other) const {
112  return *this == other;
113  }
114 
115 protected:
116  explicit Event(EventType type_) : type(type_) {}
117  ~Event() = default;
118 
119 private:
120  [[nodiscard]] virtual bool lessImpl(const Event& other) const = 0;
121 
122  const EventType type;
123 };
124 
125 // implementation for events that don't need additional data
126 class SimpleEvent final : public Event
127 {
128 public:
129  explicit SimpleEvent(EventType type_) : Event(type_) {}
130  [[nodiscard]] TclObject toTclList() const override;
131  [[nodiscard]] bool lessImpl(const Event& other) const override;
132 };
133 
134 } // namespace openmsx
135 
136 #endif
bool operator<(const Event &other) const
Definition: Event.cc:13
bool operator<=(const Event &other) const
Definition: Event.cc:23
std::string toString() const
Get a string representation of this event.
Definition: Event.cc:8
virtual bool isRepeatStopper(const Event &) const
Should 'bind -repeat' be stopped by 'other' event.
Definition: Event.hh:104
Event(EventType type_)
Definition: Event.hh:116
bool operator==(const Event &other) const
Definition: Event.cc:32
EventType getType() const
Definition: Event.hh:86
bool operator!=(const Event &other) const
Definition: Event.cc:36
Event(const Event &)=delete
bool operator>=(const Event &other) const
Definition: Event.cc:27
~Event()=default
virtual TclObject toTclList() const =0
Similar to toString(), but retains the structure of the event.
virtual bool matches(const Event &other) const
Does this event 'match' the given event.
Definition: Event.hh:111
bool operator>(const Event &other) const
Definition: Event.cc:19
Event & operator=(const Event &)=delete
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: Event.cc:41
bool lessImpl(const Event &other) const override
Definition: Event.cc:46
SimpleEvent(EventType type_)
Definition: Event.hh:129
This file implemented 3 utility functions:
Definition: Autofire.cc:5
EventType
Definition: Event.hh:11
@ OPENMSX_FRAME_DRAWN_EVENT
Sent when a OPENMSX_FINISH_FRAME_EVENT caused a redraw of the screen.
Definition: Event.hh:45
@ OPENMSX_MIDI_IN_READER_EVENT
Definition: Event.hh:71
@ OPENMSX_BOOT_EVENT
Definition: Event.hh:36
@ OPENMSX_RESIZE_EVENT
Definition: Event.hh:30
@ OPENMSX_OSD_CONTROL_PRESS_EVENT
Definition: Event.hh:35
@ OPENMSX_MOUSE_BUTTON_DOWN_EVENT
Definition: Event.hh:18
@ OPENMSX_MOUSE_BUTTON_UP_EVENT
Definition: Event.hh:17
@ OPENMSX_SWITCH_RENDERER_EVENT
Definition: Event.hh:48
@ OPENMSX_OSD_CONTROL_RELEASE_EVENT
Definition: Event.hh:34
@ OPENMSX_CLICOMMAND_EVENT
Command received on CliComm connection.
Definition: Event.hh:54
@ OPENMSX_JOY_HAT_GROUP_EVENT
Definition: Event.hh:25
@ OPENMSX_JOY_AXIS_MOTION_GROUP_EVENT
Definition: Event.hh:23
@ OPENMSX_FILEDROP_GROUP_EVENT
Definition: Event.hh:32
@ OPENMSX_JOY_BUTTON_GROUP_EVENT
Definition: Event.hh:28
@ OPENMSX_FINISH_FRAME_EVENT
Sent when VDP (V99x8 or V9990) reaches the end of a frame.
Definition: Event.hh:39
@ OPENMSX_EXPOSE_EVENT
Send when (part of) the openMSX window gets exposed, and thus should be repainted.
Definition: Event.hh:69
@ OPENMSX_MOUSE_WHEEL_EVENT
Definition: Event.hh:20
@ OPENMSX_MACHINE_DEACTIVATED
Definition: Event.hh:65
@ OPENMSX_MOUSE_MOTION_EVENT
Definition: Event.hh:15
@ OPENMSX_MOUSE_WHEEL_GROUP_EVENT
Definition: Event.hh:21
@ OPENMSX_AFTER_TIMED_EVENT
Send when an after-emutime command should be executed.
Definition: Event.hh:57
@ OPENMSX_MACHINE_ACTIVATED
Send when a machine is (de)activated.
Definition: Event.hh:64
@ OPENMSX_QUIT_EVENT
Definition: Event.hh:33
@ OPENMSX_KEY_GROUP_EVENT
Definition: Event.hh:14
@ OPENMSX_FILEDROP_EVENT
Definition: Event.hh:31
@ OPENMSX_FOCUS_EVENT
Definition: Event.hh:29
@ NUM_EVENT_TYPES
Definition: Event.hh:77
@ OPENMSX_RS232_TESTER_EVENT
Definition: Event.hh:75
@ OPENMSX_KEY_UP_EVENT
Definition: Event.hh:12
@ OPENMSX_MIDI_IN_COREMIDI_VIRTUAL_EVENT
Definition: Event.hh:74
@ OPENMSX_KEY_DOWN_EVENT
Definition: Event.hh:13
@ OPENMSX_JOY_HAT_EVENT
Definition: Event.hh:24
@ OPENMSX_JOY_BUTTON_UP_EVENT
Definition: Event.hh:26
@ OPENMSX_JOY_BUTTON_DOWN_EVENT
Definition: Event.hh:27
@ OPENMSX_TAKE_REVERSE_SNAPSHOT
Used to schedule 'taking reverse snapshots' between Z80 instructions.
Definition: Event.hh:51
@ OPENMSX_MOUSE_BUTTON_GROUP_EVENT
Definition: Event.hh:19
@ OPENMSX_MIDI_IN_WINDOWS_EVENT
Definition: Event.hh:72
@ OPENMSX_MOUSE_MOTION_GROUP_EVENT
Definition: Event.hh:16
@ OPENMSX_MIDI_IN_COREMIDI_EVENT
Definition: Event.hh:73
@ OPENMSX_JOY_AXIS_MOTION_EVENT
Definition: Event.hh:22
@ OPENMSX_MACHINE_LOADED_EVENT
Send when a (new) machine configuration is loaded.
Definition: Event.hh:60
@ OPENMSX_BREAK_EVENT
Definition: Event.hh:47