1 /*=========================================================================
4 Module: $RCSfile: bbtkInterpreter.h,v $ $
6 Date: $Date: 2008/01/22 16:55:04 $
7 Version: $Revision: 1.2 $
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 class BBTK_EXPORT Interpreter
45 /// The enumeration of command codes == Command name
72 /// The structure storing the informations on a command
82 /// The type of dictionnary of commands
83 typedef std::map<std::string,CommandInfoType> CommandDictType;
92 static Interpreter* mGlobalInterpreter;
94 /// Launches a command line interpreter (with a prompt)
95 void CommandLineInterpreter();
97 /// Sets the inputs of the workspace :
98 /// the map is passed as is to the Executer
99 void SetInputs(const std::map<std::string,std::string>& m)
100 { mExecuter->SetInputs(m); }
102 /// Puts the executer in "no exec" mode,
103 /// which creates but does not execute pipelines.
104 void SetNoExecMode(bool b) { mExecuter->SetNoExecMode(b); }
107 //typedef Executer::DialogModeType DialogModeType;
108 typedef VirtualExec::DialogModeType DialogModeType;
110 void SetDialogMode(DialogModeType t) { mExecuter->SetDialogMode(t); }
112 /// Runs the interpretation of a file
113 void InterpretFile( const std::string& filename, bool use_configuration_file=true, bool verbose=false);
115 /// Interprets a line (either from a file or typed interactively)
116 void InterpretLine( const std::string& line, bool &insideComment );
118 /// Reads a line from prompt
119 void GetLineFromPrompt( std::string& line );
121 /// Splits a line into words
122 void SplitLine ( const std::string& line,
123 std::vector<std::string>& words );
125 /// Executes the right action depending on the command name
126 void InterpretCommand( const std::vector<std::string>& words,
127 CommandInfoType& info );
129 /// Switch to the interpretation of a file
130 void SwitchToFile( const std::string& filename, bool use_configuration_file=true, bool verbose=false );
132 /// Closes the currently open file
133 void CloseCurrentFile();
135 /// Closes all open files
136 void CloseAllFiles();
138 /// Displays help (entry point of any help)
139 void Help(const std::vector<std::string>& words);
141 /// Displays help on all the commands
144 /// Displays help on a particular command
145 void HelpCommand( const std::string& command );
148 void Graph(const std::vector<std::string>& words);
151 void Config(bool verbose) const; // JPR
153 void Print(const std::string&);
156 void FindCommandsWithPrefix( char* buf,
158 std::vector<std::string>& commands );
160 /// Sets the bool that indicates wether we are in command line context
161 void SetCommandLine(bool v = true) { mCommandLine = v; }
167 //==================================================================
171 // bbtk::Factory* mFactory;
173 /// The command executer
174 // bbtk::Executer* mExecuter;
175 bbtk::VirtualExec* mExecuter;
177 /// Vector of opened files
178 std::vector<std::ifstream*> mFile;
180 /// Vector of names of open files
181 std::vector<std::string> mFileName;
183 /// Stores the current line number in each open file
184 std::vector<int> mLine;
186 /// The dictionnary of commands
187 CommandDictType mCommandDict;
189 /// Are we in a command line context ?
192 /// The history of commands
193 std::deque< char* > mHistory;
195 bool verbose; // true -> displays the search results (for packages)
199 // The "Quit" exception
200 struct QuitException : public bbtk::Exception
202 QuitException() : bbtk::Exception("","","") {}