Program: bbtk
Module: $RCSfile: bbtkInterpreter.h,v $
Language: C++
- Date: $Date: 2008/10/17 08:18:13 $
- Version: $Revision: 1.35 $
+ 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
{
-#ifdef _USE_WXWIDGETS_
+#ifdef USE_WXWIDGETS
class WxConsole;
#endif
//=======================================================================
- 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; }
};
//=======================================================================
+ /*
+ //=======================================================================
+ // 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
{
Interpreter_OK,
Interpreter_ERROR,
- Interpreter_QUIT
+ Interpreter_QUIT,
+ Interpreter_BREAK,
}
ExitStatus;
/// 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();
void SetThrow(bool b) { mThrow = b; }
-#ifdef _USE_WXWIDGETS_
+#ifdef USE_WXWIDGETS
/// Sets the user of the interpreter (if any)
void SetUser(InterpreterUser* c) { mUser = c; }
/// Gets the InterpreterUser of this
/// 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
{
+ 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,
/// 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 );
void Debug(const std::string& arg);
+
private:
/// Constructor
std::string includeScriptName);
///
+ void CatchInterpreterException( const InterpreterException& e );
void CatchBbtkException( const bbtk::Exception& e );
void CatchStdException( const std::exception& e );
void CatchUnknownException();
/// 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