ListComponentsCommand.cc Source File

Back to the index.

ListComponentsCommand.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2018 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
29 #include "ComponentFactory.h"
30 #include "GXemul.h"
31 
32 
34  : Command("list-components", "")
35 {
36 }
37 
38 
40 {
41 }
42 
43 
44 bool ListComponentsCommand::Execute(GXemul& gxemul, const vector<string>& arguments)
45 {
46  vector<string> allComponents =
48 
49  size_t maxLen = 0;
50  size_t i;
51  for (i=0; i<allComponents.size(); i++)
52  if (allComponents[i].length() > maxLen)
53  maxLen = allComponents[i].length();
54 
55  for (i=0; i<allComponents.size(); i++) {
56  stringstream msg;
57  const string& name = allComponents[i];
58  refcount_ptr<Component> creatable =
60  if (creatable.IsNULL()) {
61  // msg << " (un-creatable)";
62  continue;
63  }
64 
65  msg << " " + name;
66  for (size_t j = 0; j < 3 + maxLen - name.length(); j++)
67  msg << " ";
68  msg << ComponentFactory::GetAttribute(name, "description");
69  msg << "\n";
70 
71  gxemul.GetUI()->ShowDebugMessage(msg.str());
72  }
73 
74  return true;
75 }
76 
77 
79 {
80  return "Displays all available components.";
81 }
82 
83 
85 {
86  return "Displays a list of all available components.";
87 }
88 
refcount_ptr::IsNULL
bool IsNULL() const
Checks whether or not an object is referenced by the reference counted pointer.
Definition: refcount_ptr.h:218
ComponentFactory.h
GXemul
The main emulator class.
Definition: GXemul.h:55
ListComponentsCommand.h
refcount_ptr< Component >
ComponentFactory::GetAllComponentNames
static vector< string > GetAllComponentNames(bool onlyTemplates)
Returns a vector of all available component names.
Definition: ComponentFactory.cc:212
Command
A Command is a named function, executed by the CommandInterpreter.
Definition: Command.h:51
ListComponentsCommand::~ListComponentsCommand
virtual ~ListComponentsCommand()
Definition: ListComponentsCommand.cc:39
UI::ShowDebugMessage
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
ComponentFactory::CreateComponent
static refcount_ptr< Component > CreateComponent(const string &componentNameAndOptionalArgs, GXemul *gxemul=NULL)
Creates a component given a short component name.
Definition: ComponentFactory.cc:87
ListComponentsCommand::Execute
virtual bool Execute(GXemul &gxemul, const vector< string > &arguments)
Executes the command on a given GXemul instance.
Definition: ListComponentsCommand.cc:44
ComponentFactory::GetAttribute
static string GetAttribute(const string &name, const string &attributeName)
Gets a specific attribute value for a component.
Definition: ComponentFactory.cc:184
GXemul::GetUI
UI * GetUI()
Gets a pointer to the GXemul instance' active UI.
Definition: GXemul.cc:653
ListComponentsCommand::ListComponentsCommand
ListComponentsCommand()
Constructs a ListComponentsCommand.
Definition: ListComponentsCommand.cc:33
ListComponentsCommand::GetLongDescription
virtual string GetLongDescription() const
Returns a long description/help message for the command.
Definition: ListComponentsCommand.cc:84
GXemul.h
ListComponentsCommand::GetShortDescription
virtual string GetShortDescription() const
Returns a short (one-line) description of the command.
Definition: ListComponentsCommand.cc:78

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18