openMSX
StateChangeDistributor.hh
Go to the documentation of this file.
1 #ifndef STATECHANGEDISTRIBUTOR_HH
2 #define STATECHANGEDISTRIBUTOR_HH
3 
4 #include "EmuTime.hh"
5 #include <memory>
6 #include <vector>
7 
8 namespace openmsx {
9 
10 class StateChangeListener;
11 class StateChangeRecorder;
12 class StateChange;
13 
15 {
16 public:
17  using EventPtr = std::shared_ptr<StateChange>;
18 
21 
25  void registerListener (StateChangeListener& listener);
27 
35  void registerRecorder (StateChangeRecorder& recorder);
37 
49  void distributeNew (const EventPtr& event);
50  void distributeReplay(const EventPtr& event);
51 
58  void stopReplay(EmuTime::param time);
59 
65  void setViewOnlyMode(bool value) { viewOnlyMode = value; }
66  bool isViewOnlyMode() const { return viewOnlyMode; }
67 
68  bool isReplaying() const;
69 
70 private:
71  bool isRegistered(StateChangeListener* listener) const;
72  void distribute(const EventPtr& event);
73 
74  std::vector<StateChangeListener*> listeners; // unordered
75  StateChangeRecorder* recorder = nullptr;
76  bool viewOnlyMode = false;
77 };
78 
79 } // namespace openmsx
80 
81 #endif
openmsx::StateChangeDistributor::EventPtr
std::shared_ptr< StateChange > EventPtr
Definition: StateChangeDistributor.hh:17
openmsx::StateChangeDistributor::unregisterRecorder
void unregisterRecorder(StateChangeRecorder &recorder)
Definition: StateChangeDistributor.cc:36
openmsx::StateChangeDistributor::StateChangeDistributor
StateChangeDistributor()=default
openmsx::StateChangeDistributor::distributeReplay
void distributeReplay(const EventPtr &event)
Definition: StateChangeDistributor.cc:53
openmsx::StateChangeDistributor::registerRecorder
void registerRecorder(StateChangeRecorder &recorder)
(Un)registers the given object to receive state change events.
Definition: StateChangeDistributor.cc:30
openmsx::StateChangeDistributor::registerListener
void registerListener(StateChangeListener &listener)
(Un)registers the given object to receive state change events.
Definition: StateChangeDistributor.cc:19
openmsx::StateChangeDistributor::distributeNew
void distributeNew(const EventPtr &event)
Deliver the event to all registered listeners MSX input devices should call the distributeNew() versi...
Definition: StateChangeDistributor.cc:43
openmsx::StateChangeDistributor
Definition: StateChangeDistributor.hh:15
openmsx::StateChangeDistributor::isReplaying
bool isReplaying() const
Definition: StateChangeDistributor.cc:87
openmsx::StateChangeDistributor::stopReplay
void stopReplay(EmuTime::param time)
Explicitly stop replay.
Definition: StateChangeDistributor.cc:77
openmsx::StateChangeDistributor::setViewOnlyMode
void setViewOnlyMode(bool value)
Set viewOnlyMode.
Definition: StateChangeDistributor.hh:65
EmuTime.hh
openmsx::StateChangeDistributor::unregisterListener
void unregisterListener(StateChangeListener &listener)
Definition: StateChangeDistributor.cc:25
openmsx::StateChangeDistributor::isViewOnlyMode
bool isViewOnlyMode() const
Definition: StateChangeDistributor.hh:66
openmsx::StateChangeRecorder
Definition: StateChangeListener.hh:36
openmsx::StateChangeDistributor::~StateChangeDistributor
~StateChangeDistributor()
Definition: StateChangeDistributor.cc:9
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::StateChangeListener
Definition: StateChangeListener.hh:12