openMSX
RecordedCommand.hh
Go to the documentation of this file.
1 #ifndef RECORDEDCOMMAND_HH
2 #define RECORDEDCOMMAND_HH
3 
4 #include "Command.hh"
5 #include "StateChangeListener.hh"
6 #include "StateChange.hh"
7 #include "TclObject.hh"
8 #include "EmuTime.hh"
9 #include "dynarray.hh"
10 
11 namespace openmsx {
12 
13 class CommandController;
14 class StateChangeDistributor;
15 class Scheduler;
16 
21 class MSXCommandEvent final : public StateChange
22 {
23 public:
24  MSXCommandEvent() = default; // for serialize
25  MSXCommandEvent(EmuTime::param time, span<const TclObject> tokens);
26  [[nodiscard]] const auto& getTokens() const { return tokens; }
27 
28  template<typename Archive>
29  void serialize(Archive& ar, unsigned version);
30 private:
31  dynarray<TclObject> tokens;
32 };
33 
34 
46 {
47 public:
51  virtual void execute(
52  span<const TclObject> tokens, TclObject& result,
53  EmuTime::param time) = 0;
54 
60  [[nodiscard]] virtual bool needRecord(span<const TclObject> tokens) const;
61 
62 protected:
63  RecordedCommand(CommandController& commandController,
64  StateChangeDistributor& stateChangeDistributor,
65  Scheduler& scheduler,
66  std::string_view name);
68 
69 private:
70  // Command
71  void execute(span<const TclObject> tokens, TclObject& result) override;
72 
73  // StateChangeListener
74  void signalStateChange(const StateChange& event) override;
75  void stopReplay(EmuTime::param time) noexcept override;
76 
77 private:
78  StateChangeDistributor& stateChangeDistributor;
79  Scheduler& scheduler;
80  TclObject dummyResultObject;
81  TclObject* currentResultObject;
82 };
83 
84 } // namespace openmsx
85 
86 #endif
This class is used to for Tcl commands that directly influence the MSX state (e.g.
void serialize(Archive &ar, unsigned version)
const auto & getTokens() const
Commands that directly influence the MSX state should send and events so that they can be recorded by...
virtual void execute(span< const TclObject > tokens, TclObject &result, EmuTime::param time)=0
This is like the execute() method of the Command class, it only has an extra time parameter.
virtual bool needRecord(span< const TclObject > tokens) const
It's possible that in some cases the command doesn't need to be recorded after all (e....
RecordedCommand(CommandController &commandController, StateChangeDistributor &stateChangeDistributor, Scheduler &scheduler, std::string_view name)
Base class for all external MSX state changing events.
Definition: StateChange.hh:20
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9