OpenASIP  2.0
Public Member Functions | Static Public Attributes | List of all members
CmdOutput Class Reference

#include <TestOsal.hh>

Inheritance diagram for CmdOutput:
Inheritance graph
Collaboration diagram for CmdOutput:
Collaboration graph

Public Member Functions

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

Static Public Attributes

static const std::string OUTPUT_FORMAT_INT_SIGNED = "signed"
 
static const std::string OUTPUT_FORMAT_INT_UNSIGNED = "unsigned"
 
static const std::string OUTPUT_FORMAT_LONG_SIGNED = "long"
 
static const std::string OUTPUT_FORMAT_LONG_UNSIGNED = "ulong"
 
static const std::string OUTPUT_FORMAT_DOUBLE = "double"
 
static const std::string OUTPUT_FORMAT_FLOAT = "float"
 
static const std::string OUTPUT_FORMAT_HALF = "half"
 
static const std::string OUTPUT_FORMAT_BIN = "bin"
 
static const std::string OUTPUT_FORMAT_HEX = "hex"
 

Detailed Description

Custom command that executes the output command.

Output command changes the format of the output. Possible output formats are decimal, binary and hexadecimal.

Definition at line 114 of file TestOsal.hh.

Constructor & Destructor Documentation

◆ CmdOutput() [1/2]

CmdOutput::CmdOutput ( )

Constructor.

Definition at line 270 of file TestOsal.cc.

270  : CustomCommand("output") {
271 }

◆ CmdOutput() [2/2]

CmdOutput::CmdOutput ( const CmdOutput cmd)
explicit

Copy constructor.

Parameters
cmdCommand to be copied.

Definition at line 278 of file TestOsal.cc.

278  : CustomCommand(cmd) {
279 }

◆ ~CmdOutput()

CmdOutput::~CmdOutput ( )
virtual

Destructor

Definition at line 284 of file TestOsal.cc.

284  {
285 }

Member Function Documentation

◆ execute()

bool CmdOutput::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 294 of file TestOsal.cc.

294  {
295  ScriptInterpreter* scriptInterp = interpreter();
296  OsalInterpreter* interp = dynamic_cast<OsalInterpreter*>(scriptInterp);
297  assert(interp != NULL);
298  DataObject* result = new DataObject();
299 
300  if (arguments.size() != 2) {
301  result->setString("wrong number of arguments");
302  interp->setResult(result);
303  return false;
304  }
305 
306  string outputFormat = arguments[1].stringValue();
307 
308  if (outputFormat == OUTPUT_FORMAT_INT_SIGNED ||
309  outputFormat == OUTPUT_FORMAT_INT_UNSIGNED ||
310  outputFormat == OUTPUT_FORMAT_LONG_SIGNED ||
311  outputFormat == OUTPUT_FORMAT_LONG_UNSIGNED ||
312  outputFormat == OUTPUT_FORMAT_DOUBLE ||
313  outputFormat == OUTPUT_FORMAT_FLOAT ||
314  outputFormat == OUTPUT_FORMAT_HALF ||
315  outputFormat == OUTPUT_FORMAT_BIN ||
316  outputFormat == OUTPUT_FORMAT_HEX) {
317 
319  *dynamic_cast<TesterContext*>(&interp->context());
320  context.setOutputFormat(outputFormat);
321  result->setString("");
322  interp->setResult(result);
323  } else {
324  result->setString("illegal output format \"" +
325  outputFormat +"\"");
326  interp->setResult(result);
327  return false;
328  }
329 
330  return true;
331 }

References assert, CustomCommand::context(), SimpleScriptInterpreter::context(), CustomCommand::interpreter(), OUTPUT_FORMAT_BIN, OUTPUT_FORMAT_DOUBLE, OUTPUT_FORMAT_FLOAT, OUTPUT_FORMAT_HALF, OUTPUT_FORMAT_HEX, OUTPUT_FORMAT_INT_SIGNED, OUTPUT_FORMAT_INT_UNSIGNED, OUTPUT_FORMAT_LONG_SIGNED, OUTPUT_FORMAT_LONG_UNSIGNED, ScriptInterpreter::setResult(), and DataObject::setString().

Here is the call graph for this function:

◆ helpText()

string CmdOutput::helpText ( ) const
virtual

Returns the help text of the command.

Returns
The help text.

Implements CustomCommand.

Definition at line 339 of file TestOsal.cc.

339  {
340 
341  ScriptInterpreter* scriptInterp = interpreter();
342  OsalInterpreter* interp = dynamic_cast<OsalInterpreter*>(scriptInterp);
344  *dynamic_cast<TesterContext*>(&interp->context());
345 
346  return
347  "Changes the format of the output between "
348  "int, double, float, bin and hex.\n"
349  "Currently \"" +
350  context.outputFormat() +
351  "\" is used.\n\n"
352  "!output {" +
355  OUTPUT_FORMAT_DOUBLE + "|" +
356  OUTPUT_FORMAT_FLOAT + "|" +
357  OUTPUT_FORMAT_HALF + "|" +
358  OUTPUT_FORMAT_BIN + "|" +
359  OUTPUT_FORMAT_HEX + "}";
360 }

References CustomCommand::context(), SimpleScriptInterpreter::context(), CustomCommand::interpreter(), OUTPUT_FORMAT_BIN, OUTPUT_FORMAT_DOUBLE, OUTPUT_FORMAT_FLOAT, OUTPUT_FORMAT_HALF, OUTPUT_FORMAT_HEX, OUTPUT_FORMAT_INT_SIGNED, and OUTPUT_FORMAT_INT_UNSIGNED.

Here is the call graph for this function:

Member Data Documentation

◆ OUTPUT_FORMAT_BIN

const string CmdOutput::OUTPUT_FORMAT_BIN = "bin"
static

Definition at line 124 of file TestOsal.hh.

Referenced by execute(), helpText(), and TesterContext::toOutputFormat().

◆ OUTPUT_FORMAT_DOUBLE

const string CmdOutput::OUTPUT_FORMAT_DOUBLE = "double"
static

Definition at line 121 of file TestOsal.hh.

Referenced by execute(), helpText(), and TesterContext::toOutputFormat().

◆ OUTPUT_FORMAT_FLOAT

const string CmdOutput::OUTPUT_FORMAT_FLOAT = "float"
static

Definition at line 122 of file TestOsal.hh.

Referenced by execute(), helpText(), and TesterContext::toOutputFormat().

◆ OUTPUT_FORMAT_HALF

const string CmdOutput::OUTPUT_FORMAT_HALF = "half"
static

Definition at line 123 of file TestOsal.hh.

Referenced by execute(), helpText(), and TesterContext::toOutputFormat().

◆ OUTPUT_FORMAT_HEX

const string CmdOutput::OUTPUT_FORMAT_HEX = "hex"
static

Definition at line 125 of file TestOsal.hh.

Referenced by execute(), helpText(), and TesterContext::toOutputFormat().

◆ OUTPUT_FORMAT_INT_SIGNED

const string CmdOutput::OUTPUT_FORMAT_INT_SIGNED = "signed"
static

Definition at line 117 of file TestOsal.hh.

Referenced by execute(), helpText(), and TesterContext::toOutputFormat().

◆ OUTPUT_FORMAT_INT_UNSIGNED

const string CmdOutput::OUTPUT_FORMAT_INT_UNSIGNED = "unsigned"
static

Definition at line 118 of file TestOsal.hh.

Referenced by execute(), helpText(), and TesterContext::toOutputFormat().

◆ OUTPUT_FORMAT_LONG_SIGNED

const string CmdOutput::OUTPUT_FORMAT_LONG_SIGNED = "long"
static

Definition at line 119 of file TestOsal.hh.

Referenced by execute(), CmdMem::execute(), and TesterContext::toOutputFormat().

◆ OUTPUT_FORMAT_LONG_UNSIGNED

const string CmdOutput::OUTPUT_FORMAT_LONG_UNSIGNED = "ulong"
static

Definition at line 120 of file TestOsal.hh.

Referenced by execute(), CmdMem::execute(), and TesterContext::toOutputFormat().


The documentation for this class was generated from the following files:
DataObject
Definition: DataObject.hh:50
SimpleScriptInterpreter::context
virtual InterpreterContext & context() const
Definition: SimpleScriptInterpreter.cc:185
CmdOutput::OUTPUT_FORMAT_DOUBLE
static const std::string OUTPUT_FORMAT_DOUBLE
Definition: TestOsal.hh:121
CmdOutput::OUTPUT_FORMAT_BIN
static const std::string OUTPUT_FORMAT_BIN
Definition: TestOsal.hh:124
CustomCommand::context
InterpreterContext * context() const
CmdOutput::OUTPUT_FORMAT_HALF
static const std::string OUTPUT_FORMAT_HALF
Definition: TestOsal.hh:123
assert
#define assert(condition)
Definition: Application.hh:86
CustomCommand::CustomCommand
CustomCommand(std::string name)
Definition: CustomCommand.cc:48
TesterContext
Definition: TestOsal.hh:212
CmdOutput::OUTPUT_FORMAT_FLOAT
static const std::string OUTPUT_FORMAT_FLOAT
Definition: TestOsal.hh:122
CmdOutput::OUTPUT_FORMAT_HEX
static const std::string OUTPUT_FORMAT_HEX
Definition: TestOsal.hh:125
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
OsalInterpreter
Definition: TestOsal.hh:249
CmdOutput::OUTPUT_FORMAT_LONG_SIGNED
static const std::string OUTPUT_FORMAT_LONG_SIGNED
Definition: TestOsal.hh:119
CmdOutput::OUTPUT_FORMAT_LONG_UNSIGNED
static const std::string OUTPUT_FORMAT_LONG_UNSIGNED
Definition: TestOsal.hh:120
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
ScriptInterpreter
Definition: ScriptInterpreter.hh:55
CmdOutput::OUTPUT_FORMAT_INT_SIGNED
static const std::string OUTPUT_FORMAT_INT_SIGNED
Definition: TestOsal.hh:117
CmdOutput::OUTPUT_FORMAT_INT_UNSIGNED
static const std::string OUTPUT_FORMAT_INT_UNSIGNED
Definition: TestOsal.hh:118