1 /*=========================================================================
4 Module: $RCSfile: bbtkInterpreter.h,v $ $
6 Date: $Date: 2008/02/05 12:16:55 $
7 Version: $Revision: 1.9 $
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"
39 class BBTK_EXPORT Interpreter
44 /// The enumeration of command codes == Command name
75 /// The structure storing the informations on a command
85 /// The type of dictionnary of commands
86 typedef std::map<std::string,CommandInfoType> CommandDictType;
95 static Interpreter* mGlobalInterpreter;
97 /// Launches a command line interpreter (with a prompt)
98 void CommandLineInterpreter();
100 /// Sets the inputs of the workspace :
101 /// the map is passed as is to the Executer
102 void SetInputs(const std::map<std::string,std::string>& m)
103 { mExecuter->SetInputs(m); }
105 /// Puts the executer in "no exec" mode,
106 /// which creates but does not execute pipelines.
107 void SetNoExecMode(bool b) { mExecuter->SetNoExecMode(b); }
110 //typedef Executer::DialogModeType DialogModeType;
111 typedef VirtualExec::DialogModeType DialogModeType;
113 void SetDialogMode(DialogModeType t) { mExecuter->SetDialogMode(t); }
115 /// Runs the interpretation of a file
116 void InterpretFile( const std::string& filename,
117 bool use_configuration_file=true);
119 /// Interprets a line (either from a file or typed interactively)
120 void InterpretLine( const std::string& line, bool &insideComment );
122 /// Reads a line from prompt
123 void GetLineFromPrompt( std::string& line );
125 /// Splits a line into words
126 void SplitLine ( const std::string& line,
127 std::vector<std::string>& words );
129 /// Executes the right action depending on the command name
130 void InterpretCommand( const std::vector<std::string>& words,
131 CommandInfoType& info );
133 /// Switch to the interpretation of a file
134 void SwitchToFile( const std::string& filename,
135 bool use_configuration_file=true);
137 /// Closes the currently open file
138 void CloseCurrentFile();
140 /// Closes all open files
141 void CloseAllFiles();
143 /// Displays help (entry point of any help)
144 void Help(const std::vector<std::string>& words);
146 /// Displays help on all the commands
149 /// Displays help on a particular command
150 void HelpCommand( const std::string& command );
153 void Graph(const std::vector<std::string>& words);
158 void Print(const std::string&);
160 void Index(const std::string& filename,
161 const std::string& type = "Initials");
163 void FindCommandsWithPrefix( char* buf,
165 std::vector<std::string>& commands );
167 /// Sets the bool that indicates wether we are in command line context
168 void SetCommandLine(bool v = true) { mCommandLine = v; }
172 void LoadScript( std::string fullPathScriptName);
176 //==================================================================
180 // bbtk::Factory* mFactory;
182 /// The command executer
183 bbtk::VirtualExec* mExecuter;
185 /// Vector of opened files
186 std::vector<std::ifstream*> mFile;
188 /// Vector of names of open files
189 std::vector<std::string> mFileName;
191 /// Stores the current line number in each open file
192 std::vector<int> mLine;
194 /// The dictionnary of commands
195 CommandDictType mCommandDict;
197 /// Are we in a command line context ?
200 /// The history of commands
201 std::deque< char* > mHistory;
206 // The "Quit" exception
207 struct QuitException : public bbtk::Exception
209 QuitException() : bbtk::Exception("","","") {}