OpenASIP  2.0
ScriptInterpreter.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file ScriptInterpreter.hh
26  *
27  * The declaration of ScriptInterpreter class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
31  * @note reviewed 27 May 2004 by pj, jn, vpj, ll
32  * @note rating: yellow
33  */
34 
35 #ifndef TTA_SCRIPT_INTERPRETER_HH
36 #define TTA_SCRIPT_INTERPRETER_HH
37 
38 #include <map>
39 #include <string>
40 #include <vector>
41 
42 #include "CustomCommand.hh"
43 #include "DataObject.hh"
44 #include "Exception.hh"
45 #include "LineReader.hh"
46 
47 class CustomCommand;
48 
49 /**
50  * Abstract base class for all interpreters.
51  *
52  * Interpreter processes its input, takes actions according to it and returns
53  * to wait more input.
54  */
56 public:
58  virtual ~ScriptInterpreter();
59 
60  virtual void addCustomCommand(CustomCommand* command);
61  virtual void removeCustomCommand(const std::string& commandName);
62 
63  virtual CustomCommand* customCommand(const std::string& commandName);
64  virtual void setResult(DataObject* result);
65  virtual void setResult(const std::string& result);
66  virtual void setResult(int result);
67  virtual void setResult(double result);
68  virtual std::string result();
69 
70  virtual void setError(bool state);
71  virtual void setError(std::string errorMessage);
72  virtual bool error() const;
73 
74  virtual void setVariable(
75  const std::string& interpreterVariableName,
76  const std::string& value);
77  virtual void setVariable(
78  const std::string& interpreterVariableName,
79  int value);
80 
81  virtual std::string variableStringValue(
82  const std::string& interpreterVariableName);
83  virtual int variableIntegerValue(
84  const std::string& interpreterVariableName);
85 
86  virtual bool processScriptFile(const std::string& scriptFileName);
87 
88  virtual void finalize();
89 
90  virtual void setLineReader(LineReader* reader);
91  virtual LineReader* lineReader() const;
92 
93  std::vector<std::string> customCommandsSortedByName();
94 
95  virtual void initialize(
96  int argc,
97  char* argv[],
99  LineReader* reader) = 0;
100 
101  virtual void setVariableToInterpreter(
102  const std::string& name, const DataObject& value) = 0;
103  virtual DataObject variable(const std::string& name) = 0;
104  virtual bool interpret(const std::string& commandLine) = 0;
105  virtual void setResultToInterpreter(const DataObject& value) = 0;
106 
107  virtual InterpreterContext& context() const = 0;
108 
109 protected:
110  virtual void addCustomCommandToInterpreter(
111  const CustomCommand& command) = 0;
113  const CustomCommand& command) = 0;
114 
115 private:
116  /// Iterator for map.
117  typedef std::map<std::string, CustomCommand*>::iterator MapIter;
118  /// val_type for map.
119  typedef std::map<std::string, CustomCommand*>::value_type ValType;
120 
121  /// Copying not allowed.
123  /// Assignment not allowed.
125 
126  /// Map containing all custom commands for interpreter.
127  std::map<std::string, CustomCommand*> commands_;
128  /// The latest interpreter result.
130  /// Indicates whether we are in error state.
132  /// True if Interpreter is finalized.
134  /// LineReader for interpreter.
136 };
137 
138 #endif
ScriptInterpreter::finalize
virtual void finalize()
Definition: ScriptInterpreter.cc:329
ScriptInterpreter::result
virtual std::string result()
Definition: ScriptInterpreter.cc:191
Exception.hh
DataObject
Definition: DataObject.hh:50
ScriptInterpreter::variable
virtual DataObject variable(const std::string &name)=0
ScriptInterpreter::variableIntegerValue
virtual int variableIntegerValue(const std::string &interpreterVariableName)
Definition: ScriptInterpreter.cc:288
ScriptInterpreter::commands_
std::map< std::string, CustomCommand * > commands_
Map containing all custom commands for interpreter.
Definition: ScriptInterpreter.hh:127
ScriptInterpreter::initialize
virtual void initialize(int argc, char *argv[], InterpreterContext *context, LineReader *reader)=0
ScriptInterpreter::reader_
LineReader * reader_
LineReader for interpreter.
Definition: ScriptInterpreter.hh:135
ScriptInterpreter::setVariableToInterpreter
virtual void setVariableToInterpreter(const std::string &name, const DataObject &value)=0
ScriptInterpreter::errorState_
bool errorState_
Indicates whether we are in error state.
Definition: ScriptInterpreter.hh:131
ScriptInterpreter::operator=
ScriptInterpreter & operator=(const ScriptInterpreter &)
Assignment not allowed.
ScriptInterpreter::result_
DataObject * result_
The latest interpreter result.
Definition: ScriptInterpreter.hh:129
ScriptInterpreter::addCustomCommandToInterpreter
virtual void addCustomCommandToInterpreter(const CustomCommand &command)=0
CustomCommand.hh
ScriptInterpreter::~ScriptInterpreter
virtual ~ScriptInterpreter()
Definition: ScriptInterpreter.cc:57
ScriptInterpreter::setLineReader
virtual void setLineReader(LineReader *reader)
Definition: ScriptInterpreter.cc:377
ScriptInterpreter::processScriptFile
virtual bool processScriptFile(const std::string &scriptFileName)
Definition: ScriptInterpreter.cc:303
ScriptInterpreter::ValType
std::map< std::string, CustomCommand * >::value_type ValType
val_type for map.
Definition: ScriptInterpreter.hh:119
ScriptInterpreter::customCommandsSortedByName
std::vector< std::string > customCommandsSortedByName()
Definition: ScriptInterpreter.cc:342
ScriptInterpreter::removeCustomCommand
virtual void removeCustomCommand(const std::string &commandName)
Definition: ScriptInterpreter.cc:92
LineReader.hh
ScriptInterpreter::error
virtual bool error() const
Definition: ScriptInterpreter.cc:229
CustomCommand
Definition: CustomCommand.hh:54
InterpreterContext
Definition: InterpreterContext.hh:40
ScriptInterpreter::ScriptInterpreter
ScriptInterpreter()
Definition: ScriptInterpreter.cc:50
ScriptInterpreter::removeCustomCommandFromInterpreter
virtual void removeCustomCommandFromInterpreter(const CustomCommand &command)=0
ScriptInterpreter::interpret
virtual bool interpret(const std::string &commandLine)=0
DataObject.hh
ScriptInterpreter::customCommand
virtual CustomCommand * customCommand(const std::string &commandName)
Definition: ScriptInterpreter.cc:110
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
LineReader
Definition: LineReader.hh:52
ScriptInterpreter::MapIter
std::map< std::string, CustomCommand * >::iterator MapIter
Iterator for map.
Definition: ScriptInterpreter.hh:117
ScriptInterpreter::setVariable
virtual void setVariable(const std::string &interpreterVariableName, const std::string &value)
Definition: ScriptInterpreter.cc:240
ScriptInterpreter::setError
virtual void setError(bool state)
Definition: ScriptInterpreter.cc:205
ScriptInterpreter
Definition: ScriptInterpreter.hh:55
ScriptInterpreter::variableStringValue
virtual std::string variableStringValue(const std::string &interpreterVariableName)
Definition: ScriptInterpreter.cc:273
ScriptInterpreter::lineReader
virtual LineReader * lineReader() const
Definition: ScriptInterpreter.cc:367
ScriptInterpreter::setResultToInterpreter
virtual void setResultToInterpreter(const DataObject &value)=0
ScriptInterpreter::context
virtual InterpreterContext & context() const =0
ScriptInterpreter::addCustomCommand
virtual void addCustomCommand(CustomCommand *command)
Definition: ScriptInterpreter.cc:78
ScriptInterpreter::finalized_
bool finalized_
True if Interpreter is finalized.
Definition: ScriptInterpreter.hh:133