20 std::string_view name_)
21 :
Command(commandController_, name_)
22 , stateChangeDistributor(stateChangeDistributor_)
23 , scheduler(scheduler_)
24 , currentResultObject(&dummyResultObject)
40 std::make_shared<MSXCommandEvent>(tokens, time));
51 [[nodiscard]]
static std::string_view getBaseName(std::string_view str)
53 auto pos = str.rfind(
"::");
54 return (pos == std::string_view::npos) ? str : str.substr(pos + 2);
57 void RecordedCommand::signalStateChange(
const std::shared_ptr<StateChange>& event)
59 auto* commandEvent =
dynamic_cast<MSXCommandEvent*
>(
event.get());
60 if (!commandEvent)
return;
62 const auto& tokens = commandEvent->getTokens();
63 if (getBaseName(tokens[0].getString()) !=
getName())
return;
66 execute(tokens, *currentResultObject, commandEvent->getTime());
82 void RecordedCommand::stopReplay(EmuTime::param ) noexcept
93 tokens = to_vector<TclObject>(tokens_);
102 template<
typename Archive>
105 ar.template serializeBase<StateChange>(*
this);
109 if constexpr (!Archive::IS_LOADER) {
111 tokens, [](
auto&
t) {
return string(
t.getString()); }));
113 ar.serialize(
"tokens", str);
114 if constexpr (Archive::IS_LOADER) {
115 assert(tokens.
empty());
117 str, [](
auto& s) {
return TclObject(s); }));
Assign new value to some variable and restore the original value when this object goes out of scope.
const std::string & getName() const
This class is used to for Tcl commands that directly influence the MSX state (e.g.
void serialize(Archive &ar, unsigned version)
MSXCommandEvent()=default
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)
EmuTime::param getCurrentTime() const
Get the current scheduler time.
void registerListener(StateChangeListener &listener)
(Un)registers the given object to receive state change events.
void distributeNew(const EventPtr &event)
Deliver the event to all registered listeners MSX input devices should call the distributeNew() versi...
void unregisterListener(StateChangeListener &listener)
Base class for all external MSX state changing events.
constexpr bool empty() const noexcept
This file implemented 3 utility functions:
REGISTER_POLYMORPHIC_CLASS(DiskContainer, NowindRomDisk, "NowindRomDisk")
constexpr auto transform(Range &&range, UnaryOp op)
auto to_vector(Range &&range) -> std::vector< detail::ToVectorType< T, decltype(std::begin(range))>>