34 :
Command(
"add",
"component-name [path]")
44 static void ShowMsg(
GXemul& gxemul,
const string& msg)
52 if (arguments.size() < 1) {
53 ShowMsg(gxemul,
"No component-name given.\n");
57 if (arguments.size() > 2) {
58 ShowMsg(gxemul,
"Too many arguments.\n");
62 string componentName = arguments[0];
67 if (componentToAdd.
IsNULL()) {
68 ShowMsg(gxemul, componentName +
": unknown component," 69 " or invalid arguments given.\n");
74 if (arguments.size() == 2)
78 FindPathByPartialMatch(path);
79 if (matches.size() == 0) {
80 ShowMsg(gxemul, path +
81 ": not a path to a known component.\n");
84 if (matches.size() > 1) {
85 ShowMsg(gxemul, path +
" matches multiple components:\n");
86 for (
size_t i=0; i<matches.size(); i++)
87 ShowMsg(gxemul,
" " + matches[i] +
"\n");
93 if (whereToAddIt.
IsNULL()) {
94 ShowMsg(gxemul, path +
": lookup of path failed.\n");
98 whereToAddIt->
AddChild(componentToAdd);
106 return "Adds a component to the emulation.";
113 "Adds a component (given by the component-name) to the current emulation\n" 114 "setup. If path is omitted, the component is added at the root of the\n" 115 "component tree. For example:\n" 117 "> add testmips <-- this adds machine0\n" 120 " \\-- machine0 [testmips]\n" 122 " |-- ram0 (32 MB at offset 0)\n" 123 " |-- rom0 (16 MB at offset 0x1fc00000)\n" 124 " \\-- cpu0 (5KE, 100 MHz)\n" 126 "> add mips_cpu(model=R4400) mainbus0 <-- note that arguments\n" 127 "> root can be given during\n" 128 " root component creation\n" 129 " \\-- machine0 [testmips]\n" 131 " |-- ram0 (32 MB at offset 0)\n" 132 " |-- rom0 (16 MB at offset 0x1fc00000)\n" 133 " |-- cpu0 (5KE, 100 MHz)\n" 134 " \\-- cpu1 (R4400, 100 MHz)\n" 136 "See also: copy (to copy/clone a component in the tree)\n" 137 " list-components (to get a list of available component types)\n" 138 " remove (to remove a component from the emulation)\n" 139 " root (to inspect the current emulation setup)\n";
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
static refcount_ptr< Component > CreateComponent(const string &componentNameAndOptionalArgs, GXemul *gxemul=NULL)
Creates a component given a short component name.
virtual string GetShortDescription() const
Returns a short (one-line) description of the command.
virtual ~AddComponentCommand()
AddComponentCommand()
Constructs an AddComponentCommand.
A Command is a named function, executed by the CommandInterpreter.
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.
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.
bool IsNULL() const
Checks whether or not an object is referenced by the reference counted pointer.