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