2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkInterpreter.h,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.46 $
34 =========================================================================*/
40 * \brief class Interpreter : The bbtk language interpreter
43 * \class bbtk::Interpreter
44 * \brief The bbtk language interpreter
47 #ifndef __bbtkInterpreter_h__
48 #define __bbtkInterpreter_h__
50 #include "bbtkVirtualExec.h"
51 #include "bbtkExecuter.h"
52 #include "bbtkInterpreterVirtual.h"
70 //=======================================================================
71 class BBTK_EXPORT Interpreter : public InterpreterVirtual
73 BBTK_OBJECT_INTERFACE_NO_CONDES(Interpreter);
74 typedef Object InterpreterVirtual;
76 static Pointer New(const std::string& cpp_file = "");
77 static Pointer New(VirtualExec::Pointer);
80 /// Sets the inputs of the workspace :
81 /// the map is passed as is to the Executer
82 void SetInputs(const std::map<std::string,std::string>& m)
83 { mVirtualExecuter->SetInputs(m); }
85 /// Puts the executer in "no exec" mode,
86 /// which creates but does not execute pipelines.
87 void SetNoExecMode(bool m) { mVirtualExecuter->SetNoExecMode(m); }
89 /// Puts the executer in "no error" mode,
90 /// Errors do not stop execution (but warnings are produced)
91 void SetNoErrorMode(bool m) { mVirtualExecuter->SetNoErrorMode(m);}
93 //typedef Executer::DialogModeType DialogModeType;
94 typedef VirtualExec::DialogModeType DialogModeType;
96 void SetDialogMode(DialogModeType t) { mVirtualExecuter->SetDialogMode(t);}
100 VirtualExec::Pointer GetExecuter() const { return mVirtualExecuter; }
103 // For 'break' commands observation
104 typedef boost::signals::trackable BreakObserverType;
105 typedef boost::signal<void ()> BreakSignalType;
106 typedef BreakSignalType::slot_function_type BreakCallbackType;
108 // Adds a callback when 'break' command issued
109 void AddBreakObserver( BreakCallbackType );
116 virtual void commandReset();
119 /// Displays help (entry point of any help)
120 virtual void commandHelp(const std::vector<std::string>& words);
122 /// Displays help on all the commands
126 /// Displays help on a particular command
127 virtual void commandHelp( const std::string& command );
130 virtual void commandGraph(const std::vector<std::string>& words);
133 virtual void commandConfig() const;
135 // void Print(const std::string&);
137 virtual void commandIndex(const std::string& filename,
138 const std::string& type = "Initials");
141 /// Creates and connects the piece of pipeline which defines a GUI
143 /// Define it as a complex box type with name instanceName+"Type"
144 /// The instance is called instanceName
145 /// and connected to the existing pipeline
146 virtual void commandNewGUI(const std::string& box,const std::string& instanceName);
147 virtual void commandDebug(const std::string& arg);
148 virtual void commandNew(const std::string &boxType,const std::string &boxName);
149 virtual void commandDelete(const std::string &boxName);
150 virtual void commandConnection(const std::string &nodeFrom,const std::string &outputLabel,const std::string &nodeTo,const std::string &inputLabel);
151 virtual void commandPackage(const std::string &packageName);
152 virtual void commandEndPackage();
153 virtual void commandDefine(const std::string &name,const std::string &pack,const std::string &scriptfilename);
154 virtual void commandEndDefine();
155 virtual void commandKind(const std::string &kind);
156 virtual void commandPrint(const std::string &value);
157 virtual void commandExec(const std::string &word);
158 virtual void commandInput(const std::string &name,const std::string &box,const std::string &input,const std::string &help);
159 virtual void commandOutput(const std::string &name,const std::string &box,const std::string &output,const std::string &help);
160 virtual void commandSet(const std::string &box,const std::string &input,const std::string &value);
161 virtual void commandAuthor(const std::string &author);
162 virtual void commandCategory(const std::string &categorytype);
163 virtual void commandDescription(const std::string &description);
164 virtual void commandClear();
165 virtual void commandInclude(const std::string &word, bool ok);
166 virtual void commandLoad(const std::string &packageName);
167 virtual void commandUnload(const std::string &packageName);
168 virtual void commandBreak();
169 virtual void commandQuit();
170 virtual void commandMessage();
171 virtual void commandMessage(const std::string &kind,const std::string &levelstr);
172 virtual void SetCurrentFileName(const std::string &fullPathScriptName);
173 virtual void SetTypeOfScript_Application();
178 Interpreter(const std::string& cpp_file = "");
179 Interpreter(VirtualExec::Pointer);
184 void Init(VirtualExec::Pointer, const std::string& cpp_file);
187 //==================================================================
190 /// The command executer used
191 bbtk::VirtualExec::Pointer mVirtualExecuter;
192 bbtk::Executer::WeakPointer mRealExecuter;
199 virtual void CatchInterpreterException( const InterpreterException& e );
200 virtual void CatchBbtkException( const bbtk::Exception& e );
201 virtual void CatchStdException( const std::exception& e );
202 virtual void CatchUnknownException();
206 // EO class Interpreter