CopyComponentCommand.cc Source File
Back to the index.
Go to the documentation of this file.
33 :
Command(
"copy",
"path-from path-to")
43 static void ShowMsg(
GXemul& gxemul,
const string& msg)
51 if (arguments.size() != 2) {
52 ShowMsg(gxemul,
"syntax: copy path-from path-to\n");
56 string pathFrom = arguments[0];
57 string pathTo = arguments[1];
60 FindPathByPartialMatch(pathFrom);
61 if (matchesFrom.size() == 0) {
62 ShowMsg(gxemul, pathFrom +
" is not a path to a known component.\n");
65 if (matchesFrom.size() > 1) {
66 ShowMsg(gxemul, pathFrom +
" matches multiple components:\n");
67 for (
size_t i=0; i<matchesFrom.size(); i++)
68 ShowMsg(gxemul,
" " + matchesFrom[i] +
"\n");
73 FindPathByPartialMatch(pathTo);
74 if (matchesTo.size() == 0) {
75 ShowMsg(gxemul, pathTo +
" is not a path to a known component.\n");
78 if (matchesTo.size() > 1) {
79 ShowMsg(gxemul, pathTo +
" matches multiple components:\n");
80 for (
size_t i=0; i<matchesTo.size(); i++)
81 ShowMsg(gxemul,
" " + matchesTo[i] +
"\n");
89 ShowMsg(gxemul,
"Lookup of origin path " + pathFrom +
" failed.\n");
95 ShowMsg(gxemul,
"Failed to clone " + pathFrom +
".\n");
101 if (whereToAddIt.
IsNULL()) {
102 ShowMsg(gxemul,
"Lookup of destination path " + pathTo +
" failed.\n");
114 return "Copies (clones) a component.";
121 "Copies a component (given a path) from one place in the configuration\n"
122 "tree to another. The following example duplicates a CPU component:\n"
126 " \\-- machine0 [testmips]\n"
128 " |-- ram0 (32 MB at offset 0)\n"
129 " |-- rom0 (16 MB at offset 0x1fc00000)\n"
130 " \\-- cpu0 (MIPS, 100 MHz)\n"
131 "> copy cpu0 mainbus\n"
134 " \\-- machine0 [testmips]\n"
136 " |-- ram0 (32 MB at offset 0)\n"
137 " |-- rom0 (16 MB at offset 0x1fc00000)\n"
138 " |-- cpu0 (MIPS, 100 MHz)\n"
139 " \\-- cpu1 (MIPS, 100 MHz)\n"
141 "(Note that the cloned CPU was automatically renamed to cpu1, to avoid a\n"
144 "See also: add (to add new components)\n"
145 " move (to move components within the tree)\n"
146 " remove (to remove components)\n"
147 " root (to inspect the current emulation setup)\n";
156 static void Test_CopyComponentCommand_Copy()
181 UnitTest::Assert(
"there should now be 2 entries (machine0 and machine1) under root",
193 UNITTEST(Test_CopyComponentCommand_Copy);
Components & GetChildren()
Gets pointers to child components.
bool IsNULL() const
Checks whether or not an object is referenced by the reference counted pointer.
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.
A Command which copies (clones) a Component from one location to another in the component tree.
void AddChild(refcount_ptr< Component > childComponent, size_t insertPosition=(size_t) -1)
Adds a reference to a child component.
CommandInterpreter & GetCommandInterpreter()
Gets a reference to the CommandInterpreter.
virtual string GetShortDescription() const
Returns a short (one-line) description of the command.
#define UNITTESTS(class)
Helper for unit test case execution.
A Command is a named function, executed by the CommandInterpreter.
refcount_ptr< Component > GetRootComponent()
Gets a pointer to the root configuration component.
#define UNITTEST(functionname)
Helper for unit test case execution.
static void Assert(const string &strFailMessage, bool condition)
Asserts that a boolean condition is correct.
CopyComponentCommand()
Constructs a CopyComponentCommand.
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
const refcount_ptr< Component > LookupPath(string path) const
Looks up a path from this Component, and returns a pointer to the found Component,...
virtual ~CopyComponentCommand()
string ToString() const
Returns the variable as a readable string.
bool RunCommand(const string &command, bool *pSuccess=NULL)
Runs a command, given as a string.
UI * GetUI()
Gets a pointer to the GXemul instance' active UI.
StateVariable * GetVariable(const string &name)
Gets a pointer to a state variable.
refcount_ptr< Component > Clone() const
Clones the component and all its children.
Generated on Tue Aug 25 2020 19:25:06 for GXemul by
1.8.18