OpenASIP 2.2
Loading...
Searching...
No Matches
CmdHelp.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 CmdHelp.cc
26 *
27 * Declaration of CmdHelp class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @note reviewed 2 June 2004 by jm, pj, tr, jn
31 * @note rating: green
32 */
33
34#include <vector>
35#include <string>
36
37#include "CmdHelp.hh"
38#include "Application.hh"
39
40using std::vector;
41using std::string;
42
43
44/**
45 * Constructor.
46 */
49
50/**
51 * Destructor.
52 */
55
56/**
57 * Executes the help command.
58 *
59 * @param arguments Arguments for the command.
60 * @return True if execution is succesfull, false otherwise
61 * @exception NumberFormatException If conversion of DataObject fails.
62 */
63bool
64CmdHelp::execute(const std::vector<DataObject>& arguments) {
66 assert(interp != NULL);
67 DataObject* obj = new DataObject();
68
69 if (arguments.size() == 1) {
70 string result = "Commands available:\n";
71 vector<string> names = interp->customCommandsSortedByName();
72 for (size_t i = 0; i < names.size(); i++) {
73 result += names[i] + " ";
74 }
75 obj->setString(result);
76 interp->setResult(obj);
77 return true;
78 }
79
80 if (arguments.size() != 2) {
81 obj->setString("Wrong number of arguments");
82 interp->setResult(obj);
83 return false;
84 }
85
86 string cmdName = arguments[1].stringValue();
87 CustomCommand* command = interp->customCommand(cmdName);
88 if (command == NULL) {
89 obj->setString("Unknown command: " + cmdName);
90 interp->setResult(obj);
91 return false;
92 } else {
93 obj->setString(command->helpText());
94 interp->setResult(obj);
95 return true;
96 }
97}
98
99/**
100 * Returns help text.
101 *
102 * @return Help text.
103 */
104string
106 return "Use help command to get help";
107}
#define assert(condition)
CmdHelp()
Definition CmdHelp.cc:47
virtual std::string helpText() const
Definition CmdHelp.cc:105
virtual bool execute(const std::vector< DataObject > &arguments)
Definition CmdHelp.cc:64
virtual ~CmdHelp()
Definition CmdHelp.cc:53
virtual std::string helpText() const =0
ScriptInterpreter * interpreter() const
virtual void setString(std::string value)
virtual CustomCommand * customCommand(const std::string &commandName)
std::vector< std::string > customCommandsSortedByName()
virtual void setResult(DataObject *result)