SaveCommand.cc Source File
Back to the index.
Go to the documentation of this file.
35 :
Command(
"save",
"[filename [component-path]]")
45 static void ShowMsg(
GXemul& gxemul,
const string& msg)
56 if (arguments.size() > 2) {
57 ShowMsg(gxemul,
"Too many arguments.\n");
61 if (arguments.size() > 0)
62 filename = arguments[0];
65 ShowMsg(gxemul,
"No filename given.\n");
69 if (arguments.size() > 1)
73 FindPathByPartialMatch(path);
74 if (matches.size() == 0) {
75 ShowMsg(gxemul, path+
" is not a path to a known component.\n");
78 if (matches.size() > 1) {
79 ShowMsg(gxemul, path+
" matches multiple components:\n");
80 for (
size_t i=0; i<matches.size(); i++)
81 ShowMsg(gxemul,
" " + matches[i] +
"\n");
88 ShowMsg(gxemul,
"Lookup of " + path +
" failed.\n");
92 const string extension =
".gxemul";
93 if (filename.length() < extension.length() || filename.substr(
94 filename.length() - extension.length()) != extension)
95 ShowMsg(gxemul,
"Warning: the name "+filename+
" does not have"
96 " a .gxemul extension. Continuing anyway.\n");
100 std::fstream outputstream(filename.c_str(),
101 std::ios::out | std::ios::trunc);
102 if (outputstream.fail()) {
103 ShowMsg(gxemul,
"Error: Could not open " + filename +
109 component->
Serialize(outputstream, context);
114 std::fstream inputstream(filename.c_str(), std::ios::in);
115 if (inputstream.fail()) {
116 ShowMsg(gxemul,
"Error: Could not open " + filename +
117 " for reading after writing to it; saving "
118 " the emulation setup failed!\n");
123 ShowMsg(gxemul,
"Emulation setup saved to " + filename +
"\n");
132 return "Saves the emulation to a file.";
139 "Saves the entire emulation setup, or a part of it, to a file in the filesystem.\n"
140 "The filename may be omitted, if it is known from an earlier save or load\n"
141 "command. If the component path is omitted, the entire emulation setup, starting\n"
142 "from the 'root' component, is saved.\n"
144 "The filename extension should usually be .gxemul.\n"
146 "See also: load (to load an emulation setup)\n";
bool IsNULL() const
Checks whether or not an object is referenced by the reference counted pointer.
A Command is a named function, executed by the CommandInterpreter.
refcount_ptr< Component > GetRootComponent()
Gets a pointer to the root configuration component.
void SetEmulationFilename(const string &filename)
Sets the current emulation setup's filename.
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
A context used during serialization of objects.
const refcount_ptr< Component > LookupPath(string path) const
Looks up a path from this Component, and returns a pointer to the found Component,...
virtual bool Execute(GXemul &gxemul, const vector< string > &arguments)
Executes the command on a given GXemul instance.
virtual string GetLongDescription() const
Returns a long description/help message for the command.
UI * GetUI()
Gets a pointer to the GXemul instance' active UI.
const string & GetEmulationFilename() const
Gets the current emulation setup's filename.
SaveCommand()
Constructs an SaveCommand.
void Serialize(ostream &ss, SerializationContext &context) const
Serializes the Component into a string stream.
virtual string GetShortDescription() const
Returns a short (one-line) description of the command.
Generated on Tue Aug 25 2020 19:25:06 for GXemul by
1.8.18