openMSX
ProxyCommand.cc
Go to the documentation of this file.
1 #include "ProxyCommand.hh"
4 #include "CommandException.hh"
5 #include "MSXMotherBoard.hh"
6 #include "Reactor.hh"
7 #include "checked_cast.hh"
8 
9 using std::vector;
10 using std::string;
11 
12 namespace openmsx {
13 
15  : Command(reactor_.getGlobalCommandController(), name_)
16  , reactor(reactor_)
17 {
18 }
19 
20 Command* ProxyCmd::getMachineCommand() const
21 {
22  MSXMotherBoard* motherBoard = reactor.getMotherBoard();
23  if (!motherBoard) return nullptr;
24  return motherBoard->getMSXCommandController().findCommand(getName());
25 }
26 
28 {
29  if (Command* command = getMachineCommand()) {
30  if (!command->isAllowedInEmptyMachine()) {
31  auto controller = checked_cast<MSXCommandController*>(
32  &command->getCommandController());
33  if (!controller->getMSXMotherBoard().getMachineConfig()) {
34  throw CommandException(
35  "Can't execute command in empty machine");
36  }
37  }
38  command->execute(tokens, result);
39  } else {
40  throw CommandException("Invalid command name \"", getName(), '"');
41  }
42 }
43 
44 string ProxyCmd::help(const vector<string>& tokens) const
45 {
46  if (Command* command = getMachineCommand()) {
47  return command->help(tokens);
48  } else {
49  return "unknown command: " + getName();
50  }
51 }
52 
53 void ProxyCmd::tabCompletion(vector<string>& tokens) const
54 {
55  if (Command* command = getMachineCommand()) {
56  command->tabCompletion(tokens);
57  }
58 }
59 
60 } // namespace openmsx
MSXCommandController & getMSXCommandController()
Contains the main loop of openMSX.
Definition: Reactor.hh:64
Definition: span.hh:34
void execute(span< const TclObject > tokens, TclObject &result) override
Execute this command.
Definition: ProxyCommand.cc:27
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
Definition: ProxyCommand.cc:53
const std::string & getName() const
Definition: Completer.hh:19
MSXMotherBoard * getMotherBoard() const
Definition: Reactor.cc:342
std::string help(const std::vector< std::string > &tokens) const override
Print help for this command.
Definition: ProxyCommand.cc:44
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
ProxyCmd(Reactor &reactor, string_view name)
Definition: ProxyCommand.cc:14
Command * findCommand(string_view name) const