OpenASIP  2.0
Public Member Functions | Protected Attributes | Private Attributes | List of all members
Script Class Reference

#include <Script.hh>

Inheritance diagram for Script:
Inheritance graph
Collaboration diagram for Script:
Collaboration graph

Public Member Functions

 Script (ScriptInterpreter *interpreter, std::string scriptLine)
 
 Script (ScriptInterpreter *interpreter, std::vector< std::string > &script)
 
virtual ~Script ()
 
virtual DataObject execute ()
 
DataObject lastResult ()
 
virtual std::vector< std::string > script () const
 

Protected Attributes

ScriptInterpreterinterpreter_
 Interpreter executing the commands. More...
 

Private Attributes

DataObject result_
 Result of execution. More...
 
bool executeCalled_
 Flag indicating whether script has been executed or not. More...
 
std::vector< std::string > scriptLines_
 Contains script. More...
 

Detailed Description

Helper class that contains line(s) of script that can be executed on demand.

Definition at line 47 of file Script.hh.

Constructor & Destructor Documentation

◆ Script() [1/2]

Script::Script ( ScriptInterpreter interpreter,
std::string  scriptLine 
)

Constructor.

Parameters
interpreterInterpreter for script.
scriptLineA line of script.

Definition at line 47 of file Script.cc.

47  :
48  interpreter_(interpreter), executeCalled_(false) {
49  scriptLines_.push_back(scriptLine);
50 }

References scriptLines_.

◆ Script() [2/2]

Script::Script ( ScriptInterpreter interpreter,
std::vector< std::string > &  script 
)

Constructor.

Parameters
interpreterInterpreter for script.
scriptScript lines.

Definition at line 58 of file Script.cc.

60  {
61 
62  interpreter_ = interpreter;
63  for (unsigned int i = 0; i < script.size(); i++) {
64  scriptLines_.push_back(script[i]);
65  }
66 }

References interpreter_, script(), and scriptLines_.

Here is the call graph for this function:

◆ ~Script()

Script::~Script ( )
virtual

Destructor.

Definition at line 71 of file Script.cc.

71  {
72 }

Member Function Documentation

◆ execute()

DataObject Script::execute ( )
virtual

Executes the script.

Returns
The result of execution as a DataObject.
Exceptions
ScriptExecutionFailureIf execution of script fails.
NumberFormatExceptionIf DataObject operation fails.

Definition at line 82 of file Script.cc.

82  {
84 
85  for (unsigned int i = 0; i < scriptLines_.size(); i++) {
87  string method = "Script::execute()";
88  string message = "Interpreter error: " +
90  throw ScriptExecutionFailure(__FILE__, __LINE__, method, message);
91  }
92  }
93  DataObject obj;
95  result_ = obj;
96  executeCalled_ = true;
97  return obj;
98 }

References executeCalled_, Application::initialize(), ScriptInterpreter::interpret(), interpreter_, ScriptInterpreter::result(), result_, scriptLines_, and DataObject::setString().

Referenced by SimControlLanguageCommand::askConditionFromUser(), SimControlLanguageCommand::askExpressionFromUser(), ConditionScript::conditionOk(), ExpressionScript::resultChanged(), ProximToolbox::testCondition(), and ProximToolbox::testExpression().

Here is the call graph for this function:

◆ lastResult()

DataObject Script::lastResult ( )

◆ script()

std::vector< std::string > Script::script ( ) const
virtual

Member Data Documentation

◆ executeCalled_

bool Script::executeCalled_
private

Flag indicating whether script has been executed or not.

Definition at line 63 of file Script.hh.

Referenced by execute().

◆ interpreter_

ScriptInterpreter* Script::interpreter_
protected

Interpreter executing the commands.

Definition at line 58 of file Script.hh.

Referenced by ConditionScript::conditionOk(), execute(), ExpressionScript::resultChanged(), and Script().

◆ result_

DataObject Script::result_
private

Result of execution.

Definition at line 61 of file Script.hh.

Referenced by execute().

◆ scriptLines_

std::vector<std::string> Script::scriptLines_
private

Contains script.

Definition at line 65 of file Script.hh.

Referenced by execute(), Script(), and script().


The documentation for this class was generated from the following files:
Script::scriptLines_
std::vector< std::string > scriptLines_
Contains script.
Definition: Script.hh:65
Script::script
virtual std::vector< std::string > script() const
Definition: Script.cc:106
Script::executeCalled_
bool executeCalled_
Flag indicating whether script has been executed or not.
Definition: Script.hh:63
ScriptInterpreter::result
virtual std::string result()
Definition: ScriptInterpreter.cc:191
DataObject
Definition: DataObject.hh:50
Script::result_
DataObject result_
Result of execution.
Definition: Script.hh:61
Script::interpreter_
ScriptInterpreter * interpreter_
Interpreter executing the commands.
Definition: Script.hh:58
ScriptInterpreter::interpret
virtual bool interpret(const std::string &commandLine)=0
Application::initialize
static void initialize()
Definition: Application.cc:99
ScriptExecutionFailure
Definition: Exception.hh:657
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130