1 /*=========================================================================
4 Module: $RCSfile: bbtkInterpreter.h,v $ $
6 Date: $Date: 2008/01/30 09:28:15 $
7 Version: $Revision: 1.6 $
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
74 /// The structure storing the informations on a command
84 /// The type of dictionnary of commands
85 typedef std::map<std::string,CommandInfoType> CommandDictType;
94 static Interpreter* mGlobalInterpreter;
96 /// Launches a command line interpreter (with a prompt)
97 void CommandLineInterpreter();
99 /// Sets the inputs of the workspace :
100 /// the map is passed as is to the Executer
101 void SetInputs(const std::map<std::string,std::string>& m)
102 { mExecuter->SetInputs(m); }
104 /// Puts the executer in "no exec" mode,
105 /// which creates but does not execute pipelines.
106 void SetNoExecMode(bool b) { mExecuter->SetNoExecMode(b); }
109 //typedef Executer::DialogModeType DialogModeType;
110 typedef VirtualExec::DialogModeType DialogModeType;
112 void SetDialogMode(DialogModeType t) { mExecuter->SetDialogMode(t); }
114 /// Runs the interpretation of a file
115 void InterpretFile( const std::string& filename, bool use_configuration_file=true, bool verbose=false);
117 /// Interprets a line (either from a file or typed interactively)
118 void InterpretLine( const std::string& line, bool &insideComment );
120 /// Reads a line from prompt
121 void GetLineFromPrompt( std::string& line );
123 /// Splits a line into words
124 void SplitLine ( const std::string& line,
125 std::vector<std::string>& words );
127 /// Executes the right action depending on the command name
128 void InterpretCommand( const std::vector<std::string>& words,
129 CommandInfoType& info );
131 /// Switch to the interpretation of a file
132 void SwitchToFile( const std::string& filename, bool use_configuration_file=true, bool verbose=false );
134 /// Closes the currently open file
135 void CloseCurrentFile();
137 /// Closes all open files
138 void CloseAllFiles();
140 /// Displays help (entry point of any help)
141 void Help(const std::vector<std::string>& words);
143 /// Displays help on all the commands
146 /// Displays help on a particular command
147 void HelpCommand( const std::string& command );
150 void Graph(const std::vector<std::string>& words);
153 void Config(bool verbose) const; // JPR
155 void Print(const std::string&);
158 void FindCommandsWithPrefix( char* buf,
160 std::vector<std::string>& commands );
162 /// Sets the bool that indicates wether we are in command line context
163 void SetCommandLine(bool v = true) { mCommandLine = v; }
167 void LoadScript( std::string fullPathScriptName);
171 //==================================================================
175 // bbtk::Factory* mFactory;
177 /// The command executer
178 bbtk::VirtualExec* mExecuter;
180 /// Vector of opened files
181 std::vector<std::ifstream*> mFile;
183 /// Vector of names of open files
184 std::vector<std::string> mFileName;
186 /// Stores the current line number in each open file
187 std::vector<int> mLine;
189 /// The dictionnary of commands
190 CommandDictType mCommandDict;
192 /// Are we in a command line context ?
195 /// The history of commands
196 std::deque< char* > mHistory;
198 bool verbose; // true -> displays the search results (for packages)
202 // The "Quit" exception
203 struct QuitException : public bbtk::Exception
205 QuitException() : bbtk::Exception("","","") {}