openMSX
SaveStateCLI.cc
Go to the documentation of this file.
1 #include "SaveStateCLI.hh"
2 #include "CommandLineParser.hh"
4 #include "TclObject.hh"
5 
6 using std::string;
7 
8 namespace openmsx {
9 
11  : parser(parser_)
12 {
13  parser.registerOption("-savestate", *this);
14  parser.registerFileType("oms", *this);
15 }
16 
17 void SaveStateCLI::parseOption(const string& option, array_ref<string>& cmdLine)
18 {
19  parseFileType(getArgument(option, cmdLine), cmdLine);
20 }
21 
23 {
24  return "Load savestate and start emulation from there";
25 }
26 
27 void SaveStateCLI::parseFileType(const string& filename,
28  array_ref<string>& /*cmdLine*/)
29 {
30  // TODO: this is basically a C++ version of a part of savestate.tcl.
31  // Can that be improved?
33  TclObject command(controller.getInterpreter());
34  command.addListElement("restore_machine");
35  command.addListElement(filename);
36  string newId = command.executeCommand();
37  command = TclObject(controller.getInterpreter());
38  command.addListElement("machine");
39  string currentId = command.executeCommand();
40  if (currentId != "") {
41  command = TclObject(controller.getInterpreter());
42  command.addListElement("delete_machine");
43  command.addListElement(currentId);
44  command.executeCommand();
45  }
46  command = TclObject(controller.getInterpreter());
47  command.addListElement("activate_machine");
48  command.addListElement(newId);
49  command.executeCommand();
50 }
51 
53 {
54  return "openMSX savestate";
55 }
56 
57 } // namespace openmsx
virtual void parseFileType(const std::string &filename, array_ref< std::string > &cmdLine)
Definition: SaveStateCLI.cc:27
virtual void parseOption(const std::string &option, array_ref< std::string > &cmdLine)
Definition: SaveStateCLI.cc:17
SaveStateCLI(CommandLineParser &commandLineParser)
Definition: SaveStateCLI.cc:10
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)
void registerFileType(string_ref extensions, CLIFileType &cliFileType)
GlobalCommandController & getGlobalCommandController() const
void addListElement(string_ref element)
Definition: TclObject.cc:154
virtual string_ref optionHelp() const
Definition: SaveStateCLI.cc:22
virtual string_ref fileTypeHelp() const
Definition: SaveStateCLI.cc:52