X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkInterpreter.h;h=c53e76b4acba1d5fc297bb976a67398c554040b3;hb=fc399c5aab38ad24ea5d57552701411b4d805181;hp=24dbd89f29079743afdb46b14a5f0374f5b14f76;hpb=2d76cd309d74d5f83d701d6bb0a4140d5d122b36;p=bbtk.git diff --git a/kernel/src/bbtkInterpreter.h b/kernel/src/bbtkInterpreter.h index 24dbd89..c53e76b 100644 --- a/kernel/src/bbtkInterpreter.h +++ b/kernel/src/bbtkInterpreter.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkInterpreter.h,v $ $ Language: C++ - Date: $Date: 2008/01/30 09:28:15 $ - Version: $Revision: 1.6 $ + Date: $Date: 2008/03/21 14:59:39 $ + Version: $Revision: 1.20 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -36,6 +36,50 @@ namespace bbtk { + +#ifdef _USE_WXWIDGETS_ + class WxConsole; +#endif + + class BBTK_EXPORT InterpreterUser + { + public: + InterpreterUser() {} + ~InterpreterUser() {} + + virtual bool InterpreterUserHasOwnHtmlPageViewer() { return false; } + virtual void InterpreterUserViewHtmlPage(const std::string&) {} + + + }; + + /// + class BBTK_EXPORT InterpreterError : public Exception + { + public: + InterpreterError( const std::string& message, + bool in_script_file, + const std::string& script_file, + int script_line + ); + InterpreterError( const Exception& excep, + bool in_script_file, + const std::string& script_file, + int script_line + ); + ~InterpreterError() throw() {} + + bool IsInScriptFile() const { return mInScriptFile; } + const std::string& GetScriptFile() const { return mScriptFile; } + int GetScriptLine() const { return mScriptLine; } + private: + bool mInScriptFile; + std::string mScriptFile; + int mScriptLine; + }; + + + /// class BBTK_EXPORT Interpreter { @@ -58,7 +102,7 @@ namespace bbtk cConfig, // JPR cReset, // EED cAuthor, - cKeyword, // JPR + cCategory, // JPR cDescription, cHelp, cMessage, @@ -68,13 +112,14 @@ namespace bbtk cUnload, cGraph, cPrint, + cIndex, cWorkspace // LG } CommandCodeType; /// The structure storing the informations on a command typedef struct { - std::string keyword; + std::string category; int argmin, argmax; CommandCodeType code; std::string syntax; @@ -91,11 +136,30 @@ namespace bbtk /// Destructor ~Interpreter(); - static Interpreter* mGlobalInterpreter; + + typedef enum + { + Interpreter_OK, + Interpreter_ERROR, + Interpreter_QUIT + } + ExitStatus; + + /// Runs the interpretation of a file + ExitStatus InterpretFile( const std::string& filename); + + /// Runs the interpretation of a buffer and deletes it ! + ExitStatus InterpretBuffer( std::stringstream* buffer ); + + /// Runs the interpretation of a command + ExitStatus InterpretLine( const std::string& line ); + /// Launches a command line interpreter (with a prompt) void CommandLineInterpreter(); + + /// Sets the inputs of the workspace : /// the map is passed as is to the Executer void SetInputs(const std::map& m) @@ -111,10 +175,31 @@ namespace bbtk void SetDialogMode(DialogModeType t) { mExecuter->SetDialogMode(t); } - /// Runs the interpretation of a file - void InterpretFile( const std::string& filename, bool use_configuration_file=true, bool verbose=false); + /// Sets the bool that indicates wether we are in command line context + void SetCommandLine(bool v = true) { mCommandLine = v; } + + void SetThrow(bool b) { mThrow = b; } + + + +#ifdef _USE_WXWIDGETS_ + /// Sets the user of the interpreter (if any) + void SetUser(InterpreterUser* c) { mUser = c; } + /// Gets the InterpreterUser of this + InterpreterUser* GetUser() { return mUser; } + /// Gets the InterpreterUser of this (const) + const InterpreterUser* GetUser() const { return mUser; } + +#endif + + /// Gets the Executer + VirtualExec* GetExecuter() { return mExecuter; } + /// Gets the Executer (const) + const VirtualExec* GetExecuter() const { return mExecuter; } + - /// Interprets a line (either from a file or typed interactively) + protected: + /// Interprets a line void InterpretLine( const std::string& line, bool &insideComment ); /// Reads a line from prompt @@ -129,7 +214,10 @@ namespace bbtk CommandInfoType& info ); /// Switch to the interpretation of a file - void SwitchToFile( const std::string& filename, bool use_configuration_file=true, bool verbose=false ); + void SwitchToFile( const std::string& filename ); + + /// Switch to the interpretation of a stringstream + void SwitchToStream( std::stringstream* stream ); /// Closes the currently open file void CloseCurrentFile(); @@ -150,39 +238,51 @@ namespace bbtk void Graph(const std::vector& words); /// - void Config(bool verbose) const; // JPR + void Config() const; /// void Print(const std::string&); + void Index(const std::string& filename, + const std::string& type = "Initials"); /// void FindCommandsWithPrefix( char* buf, int n, std::vector& commands ); - /// Sets the bool that indicates wether we are in command line context - void SetCommandLine(bool v = true) { mCommandLine = v; } + private: - void LoadScript( std::string fullPathScriptName); + /// Opens the file fullPathScriptName + /// includeScriptName is the name as given to the include command + void LoadScript( std::string fullPathScriptName, + std::string includeScriptName); + + /// + void CatchBbtkException( const bbtk::Exception& e ); + void CatchStdException( const std::exception& e ); + void CatchUnknownException(); private: //================================================================== // ATTRIBUTES - /// The factory - // bbtk::Factory* mFactory; - - /// The command executer + /// The command executer used bbtk::VirtualExec* mExecuter; - /// Vector of opened files - std::vector mFile; + /// The user of the interpreter (0 if none) + bbtk::InterpreterUser* mUser; + + /// Vector of open files / buffers (can be stringstream) + std::vector mFile; - /// Vector of names of open files + /// Vector of names of open files with full path (as open) std::vector mFileName; + /// Vector of names of open files as given to the include command + std::vector mIncludeFileName; + /// Stores the current line number in each open file std::vector mLine; @@ -195,14 +295,18 @@ namespace bbtk /// The history of commands std::deque< char* > mHistory; - bool verbose; // true -> displays the search results (for packages) + int bufferNb; + + bool mThrow; + }; + // EO class Interpreter // The "Quit" exception struct QuitException : public bbtk::Exception { - QuitException() : bbtk::Exception("","","") {} + QuitException() : bbtk::Exception("Interpreter","","Quit") {} }; }