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

#include <ConfCommand.hh>

Inheritance diagram for ConfCommand:
Inheritance graph
Collaboration diagram for ConfCommand:
Collaboration graph

Public Member Functions

 ConfCommand ()
 
virtual ~ConfCommand ()
 
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

Implementation of the "conf" command of the Simulator Control Language.

Definition at line 46 of file ConfCommand.hh.

Constructor & Destructor Documentation

◆ ConfCommand()

ConfCommand::ConfCommand ( )

Constructor.

Sets the name of the command to the base class.

Definition at line 47 of file ConfCommand.cc.

47 : CustomCommand("conf") {}

◆ ~ConfCommand()

ConfCommand::~ConfCommand ( )
virtual

Destructor.

Does nothing.

Definition at line 54 of file ConfCommand.cc.

54 {}

Member Function Documentation

◆ execute()

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

Executes the "conf" command.

Loads a new machine file using the ProcessorConfigurationFile and SimulatorFrontend.

Parameters
argumentsProcessor configuration file name is given as argument to the command.
Returns
True if loading the program was successful.
Exceptions
NumberFormatExceptionIs never thrown by this command.

Implements CustomCommand.

Definition at line 69 of file ConfCommand.cc.

69  {
70  assert(interpreter() != NULL);
71 
73  if (arguments.size() < 2) {
74  DataObject* errorMessage = new DataObject();
75  errorMessage->setString(
76  textGen.text(Texts::TXT_NO_FILENAME_DEFINED).str());
77  interpreter()->setResult(errorMessage);
78  return false;
79  }
80 
81  if (arguments.size() > 2) {
82  DataObject* errorMessage = new DataObject();
83  errorMessage->setString(
85  interpreter()->setResult(errorMessage);
86  return false;
87  }
88 
89  SimulatorInterpreterContext& interpreterContext =
90  dynamic_cast<SimulatorInterpreterContext&>(interpreter()->context());
91 
92  SimulatorFrontend& simulatorFrontend =
93  interpreterContext.simulatorFrontend();
94 
95  try {
96  const std::string fileName =
97  FileSystem::expandTilde(arguments.at(1).stringValue());
98  simulatorFrontend.loadProcessorConfiguration(fileName);
99  } catch (const Exception& e) {
100  DataObject* errorMessage = new DataObject();
101  errorMessage->setString(e.errorMessageStack(true));
102  interpreter()->setResult(errorMessage);
103  return false;
104  }
105  catch (...) {
106  assert(false);
107  return false;
108  }
109  return true;
110 }

References assert, ScriptInterpreter::context(), Exception::errorMessageStack(), FileSystem::expandTilde(), CustomCommand::interpreter(), SimulatorFrontend::loadProcessorConfiguration(), ScriptInterpreter::setResult(), DataObject::setString(), SimulatorInterpreterContext::simulatorFrontend(), Texts::TextGenerator::text(), SimulatorToolbox::textGenerator(), Texts::TXT_NO_FILENAME_DEFINED, and Texts::TXT_ONLY_ONE_FILENAME_EXPECTED.

Here is the call graph for this function:

◆ helpText()

std::string ConfCommand::helpText ( ) const
virtual

Returns the help text for this command.

Help text is searched from SimulatorTextGenerator.

Returns
The help text.
Todo:
Use SimulatorTextGenerator to get the help text.

Implements CustomCommand.

Definition at line 121 of file ConfCommand.cc.

121  {
124 }

References Texts::TextGenerator::text(), SimulatorToolbox::textGenerator(), and Texts::TXT_INTERP_HELP_CONF.

Here is the call graph for this function:

The documentation for this class was generated from the following files:
SimulatorInterpreterContext
Definition: SimulatorInterpreterContext.hh:45
DataObject
Definition: DataObject.hh:50
SimulatorInterpreterContext::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition: SimulatorInterpreterContext.cc:61
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
SimulatorFrontend::loadProcessorConfiguration
void loadProcessorConfiguration(const std::string &fileName)
Definition: SimulatorFrontend.cc:600
Texts::TXT_ONLY_ONE_FILENAME_EXPECTED
@ TXT_ONLY_ONE_FILENAME_EXPECTED
Definition: TextGenerator.hh:62
assert
#define assert(condition)
Definition: Application.hh:86
SimulatorTextGenerator
Definition: SimulatorTextGenerator.hh:41
CustomCommand::CustomCommand
CustomCommand(std::string name)
Definition: CustomCommand.cc:48
SimulatorToolbox::textGenerator
static SimulatorTextGenerator & textGenerator()
Definition: SimulatorToolbox.cc:75
Exception::errorMessageStack
std::string errorMessageStack(bool messagesOnly=false) const
Definition: Exception.cc:138
Exception
Definition: Exception.hh:54
FileSystem::expandTilde
static std::string expandTilde(const std::string &stringWithTilde)
Definition: FileSystem.cc:217
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
Texts::TXT_NO_FILENAME_DEFINED
@ TXT_NO_FILENAME_DEFINED
Definition: TextGenerator.hh:61
Texts::TXT_INTERP_HELP_CONF
@ TXT_INTERP_HELP_CONF
Help text for command "conf" of the CLI.
Definition: SimulatorTextGenerator.hh:63
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
ScriptInterpreter::context
virtual InterpreterContext & context() const =0