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 auto currentId = command2.executeCommand(interp);
37
38 if (!currentId.empty()) {
39 TclObject command3 = makeTclList("delete_machine", currentId);
40 command3.executeCommand(interp);
41 }
42
43 TclObject command4 = makeTclList("activate_machine", newId);
44 command4.executeCommand(interp);
45}
46
47std::string_view SaveStateCLI::fileTypeHelp() const
48{
49 return "openMSX savestate";
50}
51
52std::string_view SaveStateCLI::fileTypeCategoryName() const
53{
54 return "savestate";
55}
56
57} // 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:249
This file implemented 3 utility functions:
Definition Autofire.cc:9
TclObject makeTclList(Args &&... args)
Definition TclObject.hh:289