OpenASIP 2.2
Loading...
Searching...
No Matches
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
47class 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 */
56public:
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
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
109protected:
111 const CustomCommand& command) = 0;
113 const CustomCommand& command) = 0;
114
115private:
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
virtual InterpreterContext & context() const =0
virtual LineReader * lineReader() const
ScriptInterpreter(const ScriptInterpreter &)
Copying not allowed.
bool errorState_
Indicates whether we are in error state.
ScriptInterpreter & operator=(const ScriptInterpreter &)
Assignment not allowed.
virtual bool interpret(const std::string &commandLine)=0
virtual void setVariable(const std::string &interpreterVariableName, const std::string &value)
virtual bool processScriptFile(const std::string &scriptFileName)
virtual void setResultToInterpreter(const DataObject &value)=0
virtual int variableIntegerValue(const std::string &interpreterVariableName)
DataObject * result_
The latest interpreter result.
virtual void addCustomCommandToInterpreter(const CustomCommand &command)=0
std::map< std::string, CustomCommand * >::value_type ValType
val_type for map.
virtual void removeCustomCommandFromInterpreter(const CustomCommand &command)=0
virtual void removeCustomCommand(const std::string &commandName)
virtual void finalize()
virtual std::string result()
virtual CustomCommand * customCommand(const std::string &commandName)
virtual void setLineReader(LineReader *reader)
std::map< std::string, CustomCommand * >::iterator MapIter
Iterator for map.
virtual void setError(bool state)
virtual void setVariableToInterpreter(const std::string &name, const DataObject &value)=0
virtual void initialize(int argc, char *argv[], InterpreterContext *context, LineReader *reader)=0
LineReader * reader_
LineReader for interpreter.
virtual std::string variableStringValue(const std::string &interpreterVariableName)
virtual void addCustomCommand(CustomCommand *command)
std::vector< std::string > customCommandsSortedByName()
virtual void setResult(DataObject *result)
std::map< std::string, CustomCommand * > commands_
Map containing all custom commands for interpreter.
virtual bool error() const
virtual DataObject variable(const std::string &name)=0
bool finalized_
True if Interpreter is finalized.