1 /*=========================================================================
4 Module: $RCSfile: bbtkInterpreter.h,v $ $
6 Date: $Date: 2008/03/14 14:58:53 $
7 Version: $Revision: 1.14 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
20 * \brief class Interpreter : The bbtk language interpreter
23 * \class bbtk::Interpreter
24 * \brief The bbtk language interpreter
27 #ifndef __bbtkInterpreter_h__
28 #define __bbtkInterpreter_h__
30 #include "bbtkVirtualExec.h"
31 #include "bbtkExecuter.h"
32 #include "bbtkTranscriptor.h"
40 #ifdef _USE_WXWIDGETS_
44 class BBTK_EXPORT Interpreter
49 /// The enumeration of command codes == Command name
80 /// The structure storing the informations on a command
90 /// The type of dictionnary of commands
91 typedef std::map<std::string,CommandInfoType> CommandDictType;
100 /// Launches a command line interpreter (with a prompt)
101 void CommandLineInterpreter();
103 /// Sets the inputs of the workspace :
104 /// the map is passed as is to the Executer
105 void SetInputs(const std::map<std::string,std::string>& m)
106 { mExecuter->SetInputs(m); }
108 /// Puts the executer in "no exec" mode,
109 /// which creates but does not execute pipelines.
110 void SetNoExecMode(bool b) { mExecuter->SetNoExecMode(b); }
113 //typedef Executer::DialogModeType DialogModeType;
114 typedef VirtualExec::DialogModeType DialogModeType;
116 void SetDialogMode(DialogModeType t) { mExecuter->SetDialogMode(t); }
118 /// Runs the interpretation of a file
119 void InterpretFile( const std::string& filename);
121 /// Interprets a line (either from a file or typed interactively)
122 void InterpretLine( const std::string& line, bool &insideComment );
124 /// Reads a line from prompt
125 void GetLineFromPrompt( std::string& line );
127 /// Splits a line into words
128 void SplitLine ( const std::string& line,
129 std::vector<std::string>& words );
131 /// Executes the right action depending on the command name
132 void InterpretCommand( const std::vector<std::string>& words,
133 CommandInfoType& info );
135 /// Switch to the interpretation of a file
136 void SwitchToFile( const std::string& filename );
138 /// Switch to the interpretation of a stringstream
139 void SwitchToStream( std::stringstream* stream );
141 /// Closes the currently open file
142 void CloseCurrentFile();
144 /// Closes all open files
145 void CloseAllFiles();
147 /// Displays help (entry point of any help)
148 void Help(const std::vector<std::string>& words);
150 /// Displays help on all the commands
153 /// Displays help on a particular command
154 void HelpCommand( const std::string& command );
157 void Graph(const std::vector<std::string>& words);
162 void Print(const std::string&);
164 void Index(const std::string& filename,
165 const std::string& type = "Initials");
167 void FindCommandsWithPrefix( char* buf,
169 std::vector<std::string>& commands );
171 /// Sets the bool that indicates wether we are in command line context
172 void SetCommandLine(bool v = true) { mCommandLine = v; }
174 #ifdef _USE_WXWIDGETS_
175 /// Sets the WxConsole that created the interpreter (if any)
176 void SetWxConsole(WxConsole* c) { mWxConsole = c; }
177 /// Gets the WxConsole that created the interpreter (if any)
178 WxConsole* GetWxConsole() { return mWxConsole; }
179 /// Gets the WxConsole that created the interpreter (if any) - const
180 const WxConsole* GetWxConsole() const { return mWxConsole; }
183 /// Gets the Executer
184 VirtualExec* GetExecuter() { return mExecuter; }
185 /// Gets the Executer (const)
186 const VirtualExec* GetExecuter() const { return mExecuter; }
190 /// Opens the file fullPathScriptName
191 /// includeScriptName is the name as given to the include command
192 void LoadScript( std::string fullPathScriptName,
193 std::string includeScriptName);
197 //==================================================================
200 /// The command executer used
201 bbtk::VirtualExec* mExecuter;
203 #ifdef _USE_WXWIDGETS_
204 /// The WxConsole which uses the interpreter (0 if none)
205 bbtk::WxConsole* mWxConsole;
208 /// Vector of open files / buffers (can be stringstream)
209 std::vector<std::istream*> mFile;
211 /// Vector of names of open files with full path (as open)
212 std::vector<std::string> mFileName;
214 /// Vector of names of open files as given to the include command
215 std::vector<std::string> mIncludeFileName;
217 /// Stores the current line number in each open file
218 std::vector<int> mLine;
220 /// The dictionnary of commands
221 CommandDictType mCommandDict;
223 /// Are we in a command line context ?
226 /// The history of commands
227 std::deque< char* > mHistory;
231 // EO class Interpreter
234 // The "Quit" exception
235 struct QuitException : public bbtk::Exception
237 QuitException() : bbtk::Exception("","","") {}