OpenASIP  2.0
Public Member Functions | Private Member Functions | List of all members
CmdHelp Class Reference

#include <CmdHelp.hh>

Inheritance diagram for CmdHelp:
Inheritance graph
Collaboration diagram for CmdHelp:
Collaboration graph

Public Member Functions

 CmdHelp ()
 
 CmdHelp (const CmdHelp &cmd)
 
virtual ~CmdHelp ()
 
virtual bool execute (const std::vector< DataObject > &arguments)
 
virtual std::string helpText () const
 
- Public Member Functions inherited from CustomCommand
 CustomCommand (std::string name)
 
 CustomCommand (const CustomCommand &cmd)
 
virtual ~CustomCommand ()
 
std::string name () const
 
void setContext (InterpreterContext *context)
 
InterpreterContextcontext () const
 
void setInterpreter (ScriptInterpreter *si)
 
ScriptInterpreterinterpreter () const
 
bool checkArgumentCount (int argumentCount, int minimum, int maximum)
 
bool checkIntegerArgument (const DataObject &argument)
 
bool checkPositiveIntegerArgument (const DataObject &argument)
 
bool checkUnsignedIntegerArgument (const DataObject &argument)
 
bool checkDoubleArgument (const DataObject &argument)
 

Private Member Functions

CmdHelpoperator= (const CmdHelp &)
 Assignment not allowed. More...
 

Detailed Description

Help command.

Prints the help text of the CustomCommand that is given as parameter to execute.

Definition at line 50 of file CmdHelp.hh.

Constructor & Destructor Documentation

◆ CmdHelp() [1/2]

CmdHelp::CmdHelp ( )

Constructor.

Definition at line 47 of file CmdHelp.cc.

47  : CustomCommand("help") {
48 }

◆ CmdHelp() [2/2]

CmdHelp::CmdHelp ( const CmdHelp cmd)

◆ ~CmdHelp()

CmdHelp::~CmdHelp ( )
virtual

Destructor.

Definition at line 53 of file CmdHelp.cc.

53  {
54 }

Member Function Documentation

◆ execute()

bool CmdHelp::execute ( const std::vector< DataObject > &  arguments)
virtual

Executes the help command.

Parameters
argumentsArguments for the command.
Returns
True if execution is succesfull, false otherwise
Exceptions
NumberFormatExceptionIf conversion of DataObject fails.

Implements CustomCommand.

Definition at line 64 of file CmdHelp.cc.

64  {
65  ScriptInterpreter* interp = interpreter();
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 }

References assert, ScriptInterpreter::customCommand(), ScriptInterpreter::customCommandsSortedByName(), CustomCommand::helpText(), CustomCommand::interpreter(), ScriptInterpreter::setResult(), and DataObject::setString().

Here is the call graph for this function:

◆ helpText()

string CmdHelp::helpText ( ) const
virtual

Returns help text.

Returns
Help text.

Implements CustomCommand.

Definition at line 105 of file CmdHelp.cc.

105  {
106  return "Use help command to get help";
107 }

◆ operator=()

CmdHelp& CmdHelp::operator= ( const CmdHelp )
private

Assignment not allowed.


The documentation for this class was generated from the following files:
DataObject
Definition: DataObject.hh:50
assert
#define assert(condition)
Definition: Application.hh:86
CustomCommand::CustomCommand
CustomCommand(std::string name)
Definition: CustomCommand.cc:48
ScriptInterpreter::customCommandsSortedByName
std::vector< std::string > customCommandsSortedByName()
Definition: ScriptInterpreter.cc:342
CustomCommand
Definition: CustomCommand.hh:54
ScriptInterpreter::customCommand
virtual CustomCommand * customCommand(const std::string &commandName)
Definition: ScriptInterpreter.cc:110
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
ScriptInterpreter
Definition: ScriptInterpreter.hh:55
CustomCommand::helpText
virtual std::string helpText() const =0