Interpreter.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef INTERPRETER_H
00011 #define INTERPRETER_H
00012 
00013 #include "Subject.h"
00014 
00015 #include <string>
00016 
00017 class Progress;
00018 class Slot;
00019 
00020 /**
00021  *  Command interface specific to interpreter plug-ins.
00022  *
00023  *  Interpreter implementations implement this interface
00024  *  and this interface is used to execute commands
00025  *  for a given interpreter implementation.
00026  *
00027  *  An instance of this class should be retrieved
00028  *  by calling InterpreterManager::getInterpreter()
00029  *  on a InterpreterManager plug-in instance or
00030  *  using InterpreterUtilities::getInterpreter().
00031  */
00032 class Interpreter : public Subject
00033 {
00034 public:
00035    /**
00036     *  Emitted with boost::any<std::string> with output text generated
00037     *  from executing commands provided to executeCommand().  May
00038     *  also be emitted with output text generated from executing
00039     *  commands provided to executeScopedCommand() if
00040     *  isGlobalOutputShown() returns \c true.
00041     */
00042    SIGNAL_METHOD(Interpreter, OutputText);
00043 
00044    /**
00045     *  Emitted with boost::any<std::string> with error text generated
00046     *  from executing commands provided to executeCommand().  May
00047     *  also be emitted with error text generated from executing
00048     *  commands provided to executeScopedCommand() if
00049     *  isGlobalOutputShown() returns \c true.
00050     */
00051    SIGNAL_METHOD(Interpreter, ErrorText);
00052 
00053    /**
00054     *  Retrieves the current prompt.
00055     *
00056     *  @return The current prompt that will be displayed to the user.
00057     */
00058    virtual std::string getPrompt() const = 0;
00059 
00060    /**
00061     *  Execute the given command.
00062     *  Regardless of the return value, future calls can be made to this
00063     *  function. This function blocks and will not return until all provided
00064     *  statements have been executed to completion.
00065     * 
00066     *  Variables created while executing the command persist after command
00067     *  execution in a global scope. This global scope should persist for
00068     *  an Interpreter instance so that later commands can access variables
00069     *  created during execution of earlier commands.  Please read
00070     *  executeScopedCommand() which supports different scoping rules.
00071     *
00072     *  @notify Output and error text from executing this command will cause
00073     *          SIGNAL_NAME(Interpreter, OutputText) and SIGNAL_NAME(Interpreter, ErrorText)
00074     *          to be emitted.  The output and error text is still valid regardless
00075     *          of the return value of this function.
00076     *
00077     *  @param command
00078     *         The command to execute, this command can be a single statement
00079     *         or multi-statements. The syntax for single statements and
00080     *         multi-statements is defined by the given interpreter
00081     *         implementation.
00082     *
00083     *  @return \c False if there was a syntatic problem with the given command,
00084     *          the interpreter is not running, or an exception.
00085     *          was thrown from the interpreter. \c True will be returned otherwise.
00086     */
00087    virtual bool executeCommand(const std::string& command) = 0;
00088 
00089    /**
00090     *  Execute the given command.
00091     *  Regardless of the return value, future calls can be made to this
00092     *  function. This function blocks and will not return until all provided
00093     *  statements have been executed to completion.
00094     * 
00095     *  Output and error text from executing this command will be be sent
00096     *  to the provided output and error Slot instances. The output and
00097     *  error text is still valid regardless of the return value of this function.
00098     *
00099     *  Variables created while executing the provided command can be
00100     *  created in a nested scope that is closed at command completion
00101     *  causing local variables to be freed.
00102     *  A given interpreter implementation can support
00103     *  this nested scope behavior or can share the global and persistent
00104     *  scope used by executeCommand().
00105     *
00106     *  @notify Output and error text from executing this command will cause
00107     *          SIGNAL_NAME(Interpreter, OutputText) and SIGNAL_NAME(Interpreter, ErrorText)
00108     *          to be emitted if isGlobalOutputShown() returns \c true.
00109     *
00110     *  @param command
00111     *         The command to execute, this command can be a single statement
00112     *         or multi-statements. The syntax for single statements and
00113     *         multi-statements is defined by the given interpreter
00114     *         implementation.
00115     *
00116     *  @param output
00117     *         This Slot will be called as output text is generated from
00118     *         executing this command. The boost::any provided to the
00119     *         slot will contain a std::string with the output text.
00120     *
00121     *  @param error
00122     *         This Slot will be called as error text is generated from
00123     *         executing this command. The boost::any provided to the
00124     *         slot will contain a std::string with the error text.
00125     *
00126     *  @param pProgress
00127     *         If a non-NULL progress is provided, the execution of the provided
00128     *         command may report progress to this instance. A given
00129     *         interpreter implementation is permitted to ignore this parameter.
00130     *         An interpreter will only report progress to this progress instance
00131     *         while executing the provided command.
00132     *
00133     *  @return \c False if there was a syntatic problem with the given command,
00134     *          the interpreter is not running, or an exception.
00135     *          was thrown from the interpreter. \c True will be returned otherwise.
00136     */
00137    virtual bool executeScopedCommand(const std::string& command, const Slot& output,
00138       const Slot& error, Progress* pProgress) = 0;
00139 
00140    /**
00141     *  Returns the last value provided to showGlobalOutput(). The default
00142     *  value for a given interpreter implementation may be \c true or \c false.
00143     *
00144     *  @return The last value provided to showGlobalOutput().
00145     */
00146    virtual bool isGlobalOutputShown() const = 0;
00147 
00148    /**
00149     *  Controls whether output from executeScopedCommand() is emitted
00150     *  from SIGNAL_NAME(Interpreter, OutputText) and SIGNAL_NAME(Interpreter, ErrorText).
00151     *
00152     *  @param newValue
00153     *         A value of \c true will cause any ouput or error text
00154     *         generated from calling executeScopedCommand() to also be
00155     *         emitted from SIGNAL_NAME(Interpreter, OutputText) and
00156     *         SIGNAL_NAME(Interpreter, ErrorText).  A value of \c false
00157     *         causes output or error text generated from calling
00158     *         executeScopedCommand() to only be sent to the Slot instances
00159     *         passed to executeScopedCommand().
00160     */
00161    virtual void showGlobalOutput(bool newValue) = 0;
00162 
00163 protected:
00164    /**
00165     * This Interpreter instance is owned by a InterpreterManager instance.
00166     */
00167    virtual ~Interpreter() {}
00168 };
00169 
00170 #endif

Software Development Kit - Opticks 4.9.0 Build 16218