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

#include <TestOsal.hh>

Inheritance diagram for CmdReset:
Inheritance graph
Collaboration diagram for CmdReset:
Collaboration graph

Public Member Functions

 CmdReset ()
 
 CmdReset (const CmdReset &cmd)
 
virtual ~CmdReset ()
 
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)
 

Detailed Description

Custom command that executes the reset command.

Reset command resets the state of the operation.

Definition at line 77 of file TestOsal.hh.

Constructor & Destructor Documentation

◆ CmdReset() [1/2]

CmdReset::CmdReset ( )

Constructor.

Definition at line 186 of file TestOsal.cc.

186  : CustomCommand("reset") {
187 }

◆ CmdReset() [2/2]

CmdReset::CmdReset ( const CmdReset cmd)
explicit

Copy constructor.

Parameters
cmdCommand to be copied.

Definition at line 194 of file TestOsal.cc.

194  : CustomCommand(cmd) {
195 }

◆ ~CmdReset()

CmdReset::~CmdReset ( )
virtual

Destructor

Definition at line 200 of file TestOsal.cc.

200  {
201 }

Member Function Documentation

◆ execute()

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

Executes the command.

Parameters
argumentsArguments for the command.
Returns
True if the command is executed succesfully, otherwise false.

Implements CustomCommand.

Definition at line 210 of file TestOsal.cc.

210  {
211  ScriptInterpreter* scriptInterp = interpreter();
212  OsalInterpreter* interp = dynamic_cast<OsalInterpreter*>(scriptInterp);
213  assert(interp != NULL);
214 
215  DataObject* result = new DataObject();
216  if (arguments.size() != 2) {
217  result->setString("wrong number of arguments");
218  interp->setResult(result);
219  return false;
220  }
221 
222  string opName = arguments[1].stringValue();
223 
224  Operation& op = interp->operation(opName);
225 
226  if (&op == &NullOperation::instance()) {
227  result->setString("unknown operation \"" + opName + "\"");
228  interp->setResult(result);
229  return false;
230  }
231 
232  TesterContext& context = *dynamic_cast<TesterContext*>(&interp->context());
233  OperationContext& opContext = context.operationContext();
234 
235  OperationBehavior& behavior = op.behavior();
236  behavior.deleteState(opContext);
237  result->setString("");
238  interp->setResult(result);
239  return true;
240 }

References assert, Operation::behavior(), CustomCommand::context(), SimpleScriptInterpreter::context(), OperationBehavior::deleteState(), NullOperation::instance(), CustomCommand::interpreter(), OsalInterpreter::operation(), ScriptInterpreter::setResult(), and DataObject::setString().

Here is the call graph for this function:

◆ helpText()

string CmdReset::helpText ( ) const
virtual

Returns the help text of the command.

Returns
The help text.

Implements CustomCommand.

Definition at line 248 of file TestOsal.cc.

248  {
249  return "Resets the state of the operation.\n\n"
250  "!reset <command name>";
251 }

The documentation for this class was generated from the following files:
DataObject
Definition: DataObject.hh:50
OperationContext
Definition: OperationContext.hh:56
SimpleScriptInterpreter::context
virtual InterpreterContext & context() const
Definition: SimpleScriptInterpreter.cc:185
CustomCommand::context
InterpreterContext * context() const
NullOperation::instance
static NullOperation & instance()
assert
#define assert(condition)
Definition: Application.hh:86
OsalInterpreter::operation
Operation & operation(const std::string &name)
Definition: TestOsal.cc:388
CustomCommand::CustomCommand
CustomCommand(std::string name)
Definition: CustomCommand.cc:48
TesterContext
Definition: TestOsal.hh:212
Operation
Definition: Operation.hh:59
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
OsalInterpreter
Definition: TestOsal.hh:249
OperationBehavior
Definition: OperationBehavior.hh:53
OperationBehavior::deleteState
virtual void deleteState(OperationContext &context) const
Definition: OperationBehavior.cc:141
Operation::behavior
virtual OperationBehavior & behavior() const
Definition: Operation.cc:388
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
ScriptInterpreter
Definition: ScriptInterpreter.hh:55