OXYGENHUB
◆ main openmsx / src / commands / Command.cc
1.6 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "Command.hh"
2
3
#include "CommandController.hh"
4
#include "GlobalCommandController.hh"
5
#include "MSXCommandController.hh"
6
7
#include "checked_cast.hh"
8
9
namespace openmsx {
10
11
// class CommandCompleter
12
13
CommandCompleter::CommandCompleter(CommandController& controller_,
14
                                   std::string_view name_)
15
	: Completer(name_)
16
	, commandController(controller_)
17
{
18
	getCommandController().registerCompleter(*this, getName());
19
}
20
21
CommandCompleter::~CommandCompleter()
22
{
23
	getCommandController().unregisterCompleter(*this, getName());
24
}
25
26
// TODO: getCommandController(), getGlobalCommandController() and
27
//       getInterpreter() occur both here and in Setting.
28
29
GlobalCommandController& CommandCompleter::getGlobalCommandController() const
30
{
31
	if (auto* globalCommandController =
32
	    dynamic_cast<GlobalCommandController*>(&commandController)) {
33
		return *globalCommandController;
34
	} else {
35
		return checked_cast<MSXCommandController*>(&commandController)
36
			->getGlobalCommandController();
37
	}
38
}
39
40
Interpreter& CommandCompleter::getInterpreter() const
41
{
42
	return getCommandController().getInterpreter();
43
}
44
45
CliComm& CommandCompleter::getCliComm() const
46
{
47
	return getCommandController().getCliComm();
48
}
49
50
// class Command
51
52
Command::Command(CommandController& controller_, std::string_view name_)
53
	: CommandCompleter(controller_, name_)
54
{
55
	getCommandController().registerCommand(*this, getName());
56
}
57
58
Command::~Command()
59
{
60
	getCommandController().unregisterCommand(*this, getName());
61
}
62
63
void Command::tabCompletion(std::vector<std::string>& /*tokens*/) const
64
{
65
	// do nothing
66
}
67
68
} // namespace openmsx