openMSX
Command.hh
Go to the documentation of this file.
1 #ifndef COMMAND_HH
2 #define COMMAND_HH
3 
4 #include "Completer.hh"
5 #include "span.hh"
6 #include "string_view.hh"
7 #include <vector>
8 
9 namespace openmsx {
10 
11 class CommandController;
12 class GlobalCommandController;
13 class Interpreter;
14 class TclObject;
15 class CliComm;
16 
18 {
19 public:
20  CommandCompleter(const CommandCompleter&) = delete;
22 
23  CommandController& getCommandController() const { return commandController; }
24  Interpreter& getInterpreter() const final;
25 
26 protected:
29 
31  CliComm& getCliComm() const;
32 
33 private:
34  CommandController& commandController;
35 };
36 
37 
38 class Command : public CommandCompleter
39 {
40 public:
49  virtual void execute(span<const TclObject> tokens, TclObject& result) = 0;
50 
57  void tabCompletion(std::vector<std::string>& tokens) const override;
58 
59  // see comments in MSXMotherBoard::loadMachineCommand
60  void setAllowedInEmptyMachine(bool value) { allowInEmptyMachine = value; }
61  bool isAllowedInEmptyMachine() const { return allowInEmptyMachine; }
62 
63  // used by Interpreter::(un)registerCommand()
64  void setToken(void* token_) { assert(!token); token = token_; }
65  void* getToken() const { return token; }
66 
67 protected:
68  Command(CommandController& controller, string_view name);
69  ~Command();
70 
71 private:
72  bool allowInEmptyMachine;
73  void* token;
74 };
75 
76 } // namespace openmsx
77 
78 #endif
GlobalCommandController & getGlobalCommandController() const
Definition: Command.cc:30
virtual void tabCompletion(std::vector< std::string > &tokens) const =0
Attempt tab completion for this command.
Definition: span.hh:34
CommandCompleter(const CommandCompleter &)=delete
bool isAllowedInEmptyMachine() const
Definition: Command.hh:61
void setAllowedInEmptyMachine(bool value)
Definition: Command.hh:60
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
CommandController & getCommandController() const
Definition: Command.hh:23
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
Interpreter & getInterpreter() const final
Definition: Command.cc:41
CommandCompleter & operator=(const CommandCompleter &)=delete
CliComm & getCliComm() const
Definition: Command.cc:46
void setToken(void *token_)
Definition: Command.hh:64
void * getToken() const
Definition: Command.hh:65