33 :
Command(
"move",
"path-from path-to")
43 static void ShowMsg(
GXemul& gxemul,
const string& msg)
51 if (arguments.size() != 2) {
52 ShowMsg(gxemul,
"syntax: move 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,
"Cannot find the component's parent.\n");
101 if (whereToAddIt.
IsNULL()) {
102 ShowMsg(gxemul,
"Lookup of destination path " + pathTo +
" failed.\n");
115 return "Moves a component within the tree.";
122 "Moves a component (given a path) from one place in the configuration\n" 123 "tree to another. Example: Let's say a CPU component has by accident\n" 124 "been added outside of the machine's mainbus0 (where it is supposed to\n" 125 "be located). The move command fixes the problem:\n" 131 " |-- machine0 [testmips]\n" 133 " | |-- ram0 (32 MB at offset 0)\n" 134 " | |-- rom0 (16 MB at offset 0x1fc00000)\n" 135 " | \\-- cpu0 (MIPS, 100 MHz)\n" 136 " \\-- cpu0 (MIPS, 100 MHz)\n" 137 "> move root.cpu0 mainbus0 \n" 140 " \\-- machine0 [testmips]\n" 142 " |-- ram0 (32 MB at offset 0)\n" 143 " |-- rom0 (16 MB at offset 0x1fc00000)\n" 144 " |-- cpu0 (MIPS, 100 MHz)\n" 145 " \\-- cpu1 (MIPS, 100 MHz)\n" 147 "(Note that the moved cpu was automatically renamed to cpu1, to avoid a\n" 150 "See also: add (to add new components)\n" 151 " root (to inspect the current emulation setup)\n";
160 static void Test_MoveComponentCommand_Move()
189 machine0->GetChildren().size(), 1);
194 mainbus0->GetChildren().size(), 5);
199 UNITTEST(Test_MoveComponentCommand_Move);
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
Component * GetParent()
Gets this component's parent component, if any.
MoveComponentCommand()
Constructs a MoveComponentCommand.
bool RunCommand(const string &command, bool *pSuccess=NULL)
Runs a command, given as a string.
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.
Components & GetChildren()
Gets pointers to child components.
#define UNITTESTS(class)
Helper for unit test case execution.
CommandInterpreter & GetCommandInterpreter()
Gets a reference to the CommandInterpreter.
A Command which moves a Component from one location to another in the component tree.
virtual ~MoveComponentCommand()
virtual string GetShortDescription() const
Returns a short (one-line) description of the command.
size_t RemoveChild(Component *childToRemove)
Removes a reference to a child component.
A Command is a named function, executed by the CommandInterpreter.
static void Assert(const string &strFailMessage, bool condition)
Asserts that a boolean condition is correct.
refcount_ptr< Component > GetRootComponent()
Gets a pointer to the root configuration component.
void AddChild(refcount_ptr< Component > childComponent, size_t insertPosition=(size_t) -1)
Adds a reference to a child component.
UI * GetUI()
Gets a pointer to the GXemul instance' active UI.
const refcount_ptr< Component > LookupPath(string path) const
Looks up a path from this Component, and returns a pointer to the found Component, if any.
#define UNITTEST(functionname)
Helper for unit test case execution.
bool IsNULL() const
Checks whether or not an object is referenced by the reference counted pointer.