1 /*=========================================================================
4 Module: $RCSfile: bbtkInterpreter.h,v $ $
6 Date: $Date: 2008/01/29 10:12:45 $
7 Version: $Revision: 1.5 $
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
73 /// The structure storing the informations on a command
83 /// The type of dictionnary of commands
84 typedef std::map<std::string,CommandInfoType> CommandDictType;
93 static Interpreter* mGlobalInterpreter;
95 /// Launches a command line interpreter (with a prompt)
96 void CommandLineInterpreter();
98 /// Sets the inputs of the workspace :
99 /// the map is passed as is to the Executer
100 void SetInputs(const std::map<std::string,std::string>& m)
101 { mExecuter->SetInputs(m); }
103 /// Puts the executer in "no exec" mode,
104 /// which creates but does not execute pipelines.
105 void SetNoExecMode(bool b) { mExecuter->SetNoExecMode(b); }
108 //typedef Executer::DialogModeType DialogModeType;
109 typedef VirtualExec::DialogModeType DialogModeType;
111 void SetDialogMode(DialogModeType t) { mExecuter->SetDialogMode(t); }
113 /// Runs the interpretation of a file
114 void InterpretFile( const std::string& filename, bool use_configuration_file=true, bool verbose=false);
116 /// Interprets a line (either from a file or typed interactively)
117 void InterpretLine( const std::string& line, bool &insideComment );
119 /// Reads a line from prompt
120 void GetLineFromPrompt( std::string& line );
122 /// Splits a line into words
123 void SplitLine ( const std::string& line,
124 std::vector<std::string>& words );
126 /// Executes the right action depending on the command name
127 void InterpretCommand( const std::vector<std::string>& words,
128 CommandInfoType& info );
130 /// Switch to the interpretation of a file
131 void SwitchToFile( const std::string& filename, bool use_configuration_file=true, bool verbose=false );
133 /// Closes the currently open file
134 void CloseCurrentFile();
136 /// Closes all open files
137 void CloseAllFiles();
139 /// Displays help (entry point of any help)
140 void Help(const std::vector<std::string>& words);
142 /// Displays help on all the commands
145 /// Displays help on a particular command
146 void HelpCommand( const std::string& command );
149 void Graph(const std::vector<std::string>& words);
152 void Config(bool verbose) const; // JPR
154 void Print(const std::string&);
157 void FindCommandsWithPrefix( char* buf,
159 std::vector<std::string>& commands );
161 /// Sets the bool that indicates wether we are in command line context
162 void SetCommandLine(bool v = true) { mCommandLine = v; }
166 void LoadScript( std::string fullPathScriptName);
170 //==================================================================
174 // bbtk::Factory* mFactory;
176 /// The command executer
177 bbtk::VirtualExec* mExecuter;
179 /// Vector of opened files
180 std::vector<std::ifstream*> mFile;
182 /// Vector of names of open files
183 std::vector<std::string> mFileName;
185 /// Stores the current line number in each open file
186 std::vector<int> mLine;
188 /// The dictionnary of commands
189 CommandDictType mCommandDict;
191 /// Are we in a command line context ?
194 /// The history of commands
195 std::deque< char* > mHistory;
197 bool verbose; // true -> displays the search results (for packages)
201 // The "Quit" exception
202 struct QuitException : public bbtk::Exception
204 QuitException() : bbtk::Exception("","","") {}