openMSX
SaveStateCLI.cc
Go to the documentation of this file.
1#include "SaveStateCLI.hh"
3#include "TclObject.hh"
4#include <array>
5
6namespace openmsx {
7
9 : parser(parser_)
10{
11 parser.registerOption("-savestate", *this);
12 parser.registerFileType(std::array<std::string_view, 1>{"oms"}, *this);
13}
14
15void SaveStateCLI::parseOption(const std::string& option, std::span<std::string>& cmdLine)
16{
17 parseFileType(getArgument(option, cmdLine), cmdLine);
18}
19
20std::string_view SaveStateCLI::optionHelp() const
21{
22 return "Load savestate and start emulation from there";
23}
24
25void SaveStateCLI::parseFileType(const std::string& filename,
26 std::span<std::string>& /*cmdLine*/)
27{
28 // TODO: this is basically a C++ version of a part of savestate.tcl.
29 // Can that be improved?
30 auto& interp = parser.getInterpreter();
31
32 TclObject command1 = makeTclList("restore_machine", filename);
33 auto newId = command1.executeCommand(interp);
34
35 TclObject command2 = makeTclList("machine");
36 if (auto currentId = command2.executeCommand(interp);
37 !currentId.empty()) {
38 TclObject command3 = makeTclList("delete_machine", currentId);
39 command3.executeCommand(interp);
40 }
41
42 TclObject command4 = makeTclList("activate_machine", newId);
43 command4.executeCommand(interp);
44}
45
46std::string_view SaveStateCLI::fileTypeHelp() const
47{
48 return "openMSX savestate";
49}
50
51std::string_view SaveStateCLI::fileTypeCategoryName() const
52{
53 return "savestate";
54}
55
56} // namespace openmsx
static std::string getArgument(const std::string &option, std::span< std::string > &cmdLine)
Definition CLIOption.cc:9
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
void registerFileType(std::span< const std::string_view > extensions, CLIFileType &cliFileType)
Interpreter & getInterpreter() const
void parseFileType(const std::string &filename, std::span< std::string > &cmdLine) override
SaveStateCLI(CommandLineParser &parser)
std::string_view fileTypeCategoryName() const override
void parseOption(const std::string &option, std::span< std::string > &cmdLine) override
std::string_view optionHelp() const override
std::string_view fileTypeHelp() const override
TclObject executeCommand(Interpreter &interp, bool compile=false)
Interpret this TclObject as a command and execute it.
Definition TclObject.cc:248
This file implemented 3 utility functions:
Definition Autofire.cc:11
TclObject makeTclList(Args &&... args)
Definition TclObject.hh:293