]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkInterpreter.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkInterpreter.h
index 490882733c83f4f9ac3b6ed7ac9f9123d4597ca4..96fe7dc56e41c58e48347e185891b1956753f96f 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkInterpreter.h,v $
   Language:  C++
-  Date:      $Date: 2008/12/12 12:11:21 $
-  Version:   $Revision: 1.38 $
+  Date:      $Date: 2008/12/15 09:04:47 $
+  Version:   $Revision: 1.39 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
 #include <fstream>
 #include <deque>
 
+// Signal/slot mechanism for 'break' commands
+//#include <boost/signal.hpp>
+//#include <boost/bind.hpp>
+
 namespace bbtk
 {
 
@@ -70,20 +74,20 @@ namespace bbtk
 
 
   //=======================================================================
-  class BBTK_EXPORT InterpreterError : public Exception
+  class BBTK_EXPORT InterpreterException : public Exception
   {
   public:
-    InterpreterError( const std::string& message,
+    InterpreterException( const std::string& message,
                      bool in_script_file,
                      const std::string& script_file,
                      int script_line 
                      );
-    InterpreterError( const Exception& excep,
+    InterpreterException( const Exception& excep,
                      bool in_script_file,
                      const std::string& script_file,
                      int script_line 
                      );
-    ~InterpreterError() throw() {}
+    ~InterpreterException() throw() {}
 
     bool IsInScriptFile() const { return mInScriptFile; }
     const std::string& GetScriptFile() const { return mScriptFile; }
@@ -95,6 +99,37 @@ namespace bbtk
   };
   //=======================================================================
 
+  /*
+  //=======================================================================
+  // The "Quit" exception
+  class BBTK_EXPORT QuitException : public InterpreterError
+  {
+  public:
+    QuitException( bool in_script_file,
+                  const std::string& script_file,
+                  int script_line 
+                  )
+      : InterpreterError("QUIT",in_script_file,script_file,script_line) 
+    {}
+    ~QuitException() throw() {}
+  };
+  //=======================================================================
+  const std::string BREAK("BREAK");
+  //=======================================================================
+  // The "Break" exception
+  class BBTK_EXPORT BreakException : public InterpreterError
+  {
+  public:
+    BreakException( bool in_script_file,
+                   std::string script_file,
+                   int script_line 
+                   )
+      : InterpreterError(BREAK,in_script_file,script_file,script_line) 
+    { std::cout << "BUILDING BREAK"<<std::endl; }
+    ~BreakException() throw() {}
+  };
+  //=======================================================================
+  */
 
   //=======================================================================
   class BBTK_EXPORT Interpreter : public Object
@@ -109,7 +144,8 @@ namespace bbtk
       {
        Interpreter_OK,
        Interpreter_ERROR,
-       Interpreter_QUIT
+       Interpreter_QUIT,
+       Interpreter_BREAK,
       }
       ExitStatus;
 
@@ -122,6 +158,8 @@ namespace bbtk
     /// Runs the interpretation of a command
     ExitStatus InterpretLine( const std::string& line );
 
+    /// Runs the interpretation of the currently open streams
+    ExitStatus InterpretCurrentStreams();
 
     /// Launches a command line interpreter (with a prompt)
     void CommandLineInterpreter();
@@ -164,13 +202,23 @@ namespace bbtk
     /// Gets the Executer 
     VirtualExec::Pointer GetExecuter() const { return mVirtualExecuter; }
 
+    /*
+    // For 'break' commands observation
+    typedef boost::signals::trackable BreakObserverType;
+    typedef boost::signal<void ()>  BreakSignalType;
+    typedef BreakSignalType::slot_function_type BreakCallbackType;
+  
+    // Adds a callback when 'break' command issued
+    void AddBreakObserver( BreakCallbackType );
+    */
 
   protected:
 
     /// The enumeration of command codes == Command name
     typedef enum
     {
-      cClear,
+      cBreak, // LG 12/12/08 : Stops the current script execution (if not exec frozen) - used in tutorial + debugging 
+      cClear, // LG 12/12/08 : Clears the current complex black box (e.g. workspace) - used in tours
       cNew,
       cDelete,
       cConnect,
@@ -217,7 +265,7 @@ namespace bbtk
 
 
     /// Interprets a line 
-    void InterpretLine( const std::string& line, bool &insideComment );
+    void DoInterpretLine( const std::string& line ); //, bool &insideComment );
 
     /// Reads a line from prompt
     void GetLineFromPrompt( std::string& line );
@@ -279,6 +327,7 @@ namespace bbtk
 
     void Debug(const std::string& arg);
 
   private:
 
     /// Constructor
@@ -294,7 +343,7 @@ namespace bbtk
                     std::string includeScriptName);
 
     /// 
-    void CatchInterpreterException( const InterpreterError& e );
+    void CatchInterpreterException( const InterpreterException& e );
     void CatchBbtkException( const bbtk::Exception& e );
     void CatchStdException( const std::exception& e );
     void CatchUnknownException();
@@ -334,25 +383,29 @@ namespace bbtk
     /// Are we in a command line context ?
     bool mCommandLine;
 
+    /// Are we inside a commented-out zone ?
+    bool mInsideComment;
+    
+    /// The current interpreter status
+    ExitStatus mStatus;
+
     /// The history of commands
     std::deque< char* > mHistory;
 
-   int bufferNb;
+    int bufferNb;
     
     bool mThrow;
 
-       protected:
-       ~Interpreter();
+    /// The break signal
+    //    BreakSignalType mBreakSignal;
+
+  protected:
+    ~Interpreter();
 
   };
   // EO class Interpreter
 
 
-  // The "Quit" exception
-  struct QuitException : public bbtk::Exception
-  {
-    QuitException() : bbtk::Exception("Interpreter","","Quit") {}
-  };
 
 }
 #endif