OpenASIP  2.0
HelpCommand.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file HelpCommand.cc
26  *
27  * Declaration of HelpCommand class.
28  *
29  * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <vector>
34 #include <string>
35 
36 #include "SimulatorToolbox.hh"
38 #include "HelpCommand.hh"
39 #include "Application.hh"
40 
41 using std::vector;
42 using std::string;
43 
44 /**
45  * Constructor.
46  */
48 }
49 
50 /**
51  * Destructor.
52  */
54 }
55 
56 /**
57  * Executes the help command.
58  *
59  * Prints a help message briefly describing command command. If no command
60  * is given, prints general help and a listing of available commands.
61  *
62  * @param arguments Arguments for the command.
63  * @return True if execution is succesfull, false otherwise
64  * @exception NumberFormatException If conversion of DataObject fails.
65  */
66 bool
67 HelpCommand::execute(const std::vector<DataObject>& arguments) {
68  if (!checkArgumentCount(arguments.size() - 1, 0, 1)) {
69  return false;
70  }
71 
72  if (arguments.size() == 1) {
75  << std::endl << std::endl;
76 
79 
80  vector<string> names = interpreter()->customCommandsSortedByName();
81  for (size_t i = 0; i < names.size(); i++) {
82  outputStream() << names[i] + " ";
83  }
84  outputStream() << std::endl;
85  return true;
86  }
87 
88  DataObject* obj = new DataObject();
89  string cmdName = arguments[1].stringValue();
90  CustomCommand* command = interpreter()->customCommand(cmdName);
91  if (command == NULL) {
92  obj->setString(
95  interpreter()->setResult(obj);
96  return false;
97  } else {
98  outputStream() << command->helpText() << std::endl;
99  return true;
100  }
101 
102  return true;
103 }
104 
105 /**
106  * Returns help text.
107  *
108  * @return Help text.
109  * @todo TextGenerator.
110  */
111 string
115 }
CustomCommand::checkArgumentCount
bool checkArgumentCount(int argumentCount, int minimum, int maximum)
Definition: CustomCommand.cc:82
SimControlLanguageCommand::outputStream
virtual std::ostream & outputStream()
Definition: SimControlLanguageCommand.cc:351
HelpCommand.hh
Texts::TXT_UNKNOWN_COMMAND
@ TXT_UNKNOWN_COMMAND
Definition: TextGenerator.hh:64
DataObject
Definition: DataObject.hh:50
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
SimulatorToolbox.hh
Texts::TXT_CLI_ONLINE_HELP
@ TXT_CLI_ONLINE_HELP
Online help text.
Definition: SimulatorTextGenerator.hh:109
ScriptInterpreter::customCommandsSortedByName
std::vector< std::string > customCommandsSortedByName()
Definition: ScriptInterpreter.cc:342
Application.hh
HelpCommand::HelpCommand
HelpCommand()
Definition: HelpCommand.cc:47
SimulatorToolbox::textGenerator
static SimulatorTextGenerator & textGenerator()
Definition: SimulatorToolbox.cc:75
SimulatorTextGenerator.hh
CustomCommand
Definition: CustomCommand.hh:54
ScriptInterpreter::customCommand
virtual CustomCommand * customCommand(const std::string &commandName)
Definition: ScriptInterpreter.cc:110
HelpCommand::~HelpCommand
virtual ~HelpCommand()
Definition: HelpCommand.cc:53
HelpCommand::execute
virtual bool execute(const std::vector< DataObject > &arguments)
Definition: HelpCommand.cc:67
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
HelpCommand::helpText
virtual std::string helpText() const
Definition: HelpCommand.cc:112
Texts::TXT_INTERP_HELP_COMMANDS_AVAILABLE
@ TXT_INTERP_HELP_COMMANDS_AVAILABLE
Description of the execution trace setting.
Definition: SimulatorTextGenerator.hh:160
SimControlLanguageCommand
Definition: SimControlLanguageCommand.hh:63
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
CustomCommand::helpText
virtual std::string helpText() const =0
Texts::TXT_INTERP_HELP_HELP
@ TXT_INTERP_HELP_HELP
Help text for command "help" of the CLI.
Definition: SimulatorTextGenerator.hh:81