1 /*=========================================================================
4 Module: $RCSfile: bbtkInterpreter.h,v $ $
6 Date: $Date: 2008/01/22 15:02:00 $
7 Version: $Revision: 1.1 $
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__
31 #include "bbtkExecuter.h"
39 class BBTK_EXPORT Interpreter
44 /// The enumeration of command codes == Command name
71 /// The structure storing the informations on a command
83 /// The type of dictionnary of commands
84 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;
109 void SetDialogMode(DialogModeType t) { mExecuter->SetDialogMode(t); }
111 /// Runs the interpretation of a file
112 void InterpretFile( const std::string& filename, bool use_configuration_file=true, bool verbose=false);
114 /// Interprets a line (either from a file or typed interactively)
115 void InterpretLine( const std::string& line, bool &insideComment );
117 /// Reads a line from prompt
118 void GetLineFromPrompt( std::string& line );
120 /// Splits a line into words
121 void SplitLine ( const std::string& line,
122 std::vector<std::string>& words );
124 /// Executes the right action depending on the command name
125 void InterpretCommand( const std::vector<std::string>& words,
126 CommandInfoType& info );
128 /// Switch to the interpretation of a file
129 void SwitchToFile( const std::string& filename, bool use_configuration_file=true, bool verbose=false );
131 /// Closes the currently open file
132 void CloseCurrentFile();
134 /// Closes all open files
135 void CloseAllFiles();
137 /// Displays help (entry point of any help)
138 void Help(const std::vector<std::string>& words);
140 /// Displays help on all the commands
143 /// Displays help on a particular command
144 void HelpCommand( const std::string& command );
147 void Graph(const std::vector<std::string>& words);
150 void Config(bool verbose) const; // JPR
152 void Print(const std::string&);
154 /// Splits the string in around the first dot encountered
155 void SplitAroundFirstDot( const std::string& in,
159 void FindCommandsWithPrefix( char* buf,
161 std::vector<std::string>& commands );
163 /// Sets the bool that indicates wether we are in command line context
164 void SetCommandLine(bool v = true) { mCommandLine = v; }
167 /// the methods for include bbs
168 bool FileExists(std::string strFilename);
169 std::string ExtractScriptName(const std::string &name);
170 std::string ExpandLibName(const std::string &name, bool v);
171 std::string MakeLibnameFromPath(std::string path, std::string pkgname);
172 bool IsAtRoot(std::string cwd);
176 //==================================================================
179 // bbtk::Factory* mFactory;
180 /// The command executer
181 bbtk::Executer* mExecuter;
182 /// Vector of opened files
183 std::vector<std::ifstream*> mFile;
184 /// Vector of names of open files
185 std::vector<std::string> mFileName;
186 /// Stores the current line number in each open file
187 std::vector<int> mLine;
188 /// The dictionnary of commands
189 CommandDictType mCommandDict;
190 /// 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("","","") {}