1 /*=========================================================================
4 Module: $RCSfile: bbtkInterpreter.h,v $ $
6 Date: $Date: 2008/02/04 13:02:58 $
7 Version: $Revision: 1.7 $
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, bool use_configuration_file=true, bool verbose=false);
118 /// Interprets a line (either from a file or typed interactively)
119 void InterpretLine( const std::string& line, bool &insideComment );
121 /// Reads a line from prompt
122 void GetLineFromPrompt( std::string& line );
124 /// Splits a line into words
125 void SplitLine ( const std::string& line,
126 std::vector<std::string>& words );
128 /// Executes the right action depending on the command name
129 void InterpretCommand( const std::vector<std::string>& words,
130 CommandInfoType& info );
132 /// Switch to the interpretation of a file
133 void SwitchToFile( const std::string& filename, bool use_configuration_file=true, bool verbose=false );
135 /// Closes the currently open file
136 void CloseCurrentFile();
138 /// Closes all open files
139 void CloseAllFiles();
141 /// Displays help (entry point of any help)
142 void Help(const std::vector<std::string>& words);
144 /// Displays help on all the commands
147 /// Displays help on a particular command
148 void HelpCommand( const std::string& command );
151 void Graph(const std::vector<std::string>& words);
154 void Config(bool verbose) const; // JPR
156 void Print(const std::string&);
158 void Index(const std::string& filename,
159 const std::string& type = "Initials");
161 void FindCommandsWithPrefix( char* buf,
163 std::vector<std::string>& commands );
165 /// Sets the bool that indicates wether we are in command line context
166 void SetCommandLine(bool v = true) { mCommandLine = v; }
170 void LoadScript( std::string fullPathScriptName);
174 //==================================================================
178 // bbtk::Factory* mFactory;
180 /// The command executer
181 bbtk::VirtualExec* mExecuter;
183 /// Vector of opened files
184 std::vector<std::ifstream*> mFile;
186 /// Vector of names of open files
187 std::vector<std::string> mFileName;
189 /// Stores the current line number in each open file
190 std::vector<int> mLine;
192 /// The dictionnary of commands
193 CommandDictType mCommandDict;
195 /// Are we in a command line context ?
198 /// The history of commands
199 std::deque< char* > mHistory;
201 bool verbose; // true -> displays the search results (for packages)
205 // The "Quit" exception
206 struct QuitException : public bbtk::Exception
208 QuitException() : bbtk::Exception("","","") {}