OpenASIP 2.2
Loading...
Searching...
No Matches
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
41using std::vector;
42using std::string;
43
44/**
45 * Constructor.
46 */
49
50/**
51 * Destructor.
52 */
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 */
66bool
67HelpCommand::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 */
111string
bool checkArgumentCount(int argumentCount, int minimum, int maximum)
virtual std::string helpText() const =0
ScriptInterpreter * interpreter() const
virtual void setString(std::string value)
virtual ~HelpCommand()
virtual std::string helpText() const
virtual bool execute(const std::vector< DataObject > &arguments)
virtual CustomCommand * customCommand(const std::string &commandName)
std::vector< std::string > customCommandsSortedByName()
virtual void setResult(DataObject *result)
virtual std::ostream & outputStream()
static SimulatorTextGenerator & textGenerator()
virtual boost::format text(int textId)
@ TXT_CLI_ONLINE_HELP
Online help text.
@ TXT_INTERP_HELP_HELP
Help text for command "help" of the CLI.
@ TXT_INTERP_HELP_COMMANDS_AVAILABLE
Description of the execution trace setting.
@ TXT_UNKNOWN_COMMAND