ESLA

Embeddable Scriting LAnguage

frantz@pangea.stanford.edu

Stanford University, Rock Fracture Project research group

© 2003

gen_action.h

Go to the documentation of this file.
00001 /*************************************************************************
00002  *              ESLA: Embeddable Scripting LAnguage
00003  *                  Copyright (C) 2003 Frantz Maerten
00004  *
00005  *   This  program  is  free  software;  you  can  redistribute it and/or
00006  *   modify  it  under  the  terms  of  the GNU General Public License as
00007  *   published  by  the Free Software Foundation; either version 2 of the
00008  *   License, or (at your option) any later version.
00009  *
00010  *   If  you modify this software, you should contact the author, include
00011  *   a  notice giving the name of the person performing the modification,
00012  *   the date of modification, and the reason for such modification.
00013  *
00014  *   Note   that   the   GNU  General  Public  License  does  not  permit
00015  *   incorporating the Software into proprietary programs.
00016  *
00017  *  Contact: Frantz Maerten
00018  *     frantz@pangea.stanford.edu
00019  *
00020  *     Dept. of Geological & Environmental Sciences
00021  *     Stanford University 
00022  *     Stanford, CA 94305-2115
00023  *     USA
00024  *************************************************************************/
00025 
00026 
00027 #ifndef GEN_ACTION
00028 #define GEN_ACTION
00029 
00030 #include "../esla_namespace.h"
00031 #include "if_stream.h"
00032 #include "../utils/gen_object.h"
00033 #include "../utils/logger.h"
00034 #include "../utils/gen_static_repository.h"
00035 #include "../utils/help_display.h"
00036 #include "../utils/tokenizer.h"
00037 #include <iostream>
00038 #include <string>
00039 
00040 
00041 BEGIN_LIB_NAMESPACE 
00042 
00043 enum RET_TYPE {
00044   RT_OK,
00045   RT_FAIL,
00046   RT_BREAK,
00047   RT_CONTINUE,
00048   RT_RETURN,
00049   RT_NEUTRAL
00050 } ;
00051 
00052 class GenAction: public virtual GenObject {
00053 public:   
00054   typedef Tokenizer::ListTokens Tokens ;
00055    
00056   GenAction() ;
00057   virtual ~GenAction() ;
00058   virtual RET_TYPE    set_parameters(IfStream*, const std::string& params) = 0 ;
00059   virtual RET_TYPE    execute() = 0 ;
00060   virtual RET_TYPE    execute(const std::string&, std::string& ret) ;
00061   virtual std::string args() const = 0 ;
00062   virtual std::string name_space() const ;
00063   virtual std::string command_name() const = 0 ;
00064   virtual GenAction*  get_function(const std::string& name) ;
00065   virtual void        add_function(GenAction*, const std::string& name) ;
00066   void                set_parent(GenAction*) ;
00067   virtual bool        has_return() const ;
00068   virtual RET_TYPE    get_return(std::string&) const ;
00069 
00070   // Use to evaluate an expression
00071   RET_TYPE eval_expression(const std::string& expr, std::string& value) ;
00072   // Use to evaluate arguments
00073   RET_TYPE eval_args(const Tokens& params, unsigned int& start_index, std::string& value) ;
00074 
00075 protected:
00076   std::string linearize(const Tokens& args, unsigned int start_index = 0) ;
00077 
00078   RET_TYPE tokenize(
00079     const std::string&,
00080     Tokens& tokens,
00081     const std::string seps=" \t", 
00082     bool includeSeparators = false) ;
00083 
00084   static std::string extract_name(
00085     const std::string& name) ;
00086 
00087   void                set_ifstream(IfStream* is) ;
00088   const IfStream&     ifstream() const ;
00089   RET_TYPE            send_error(const std::string& message="") ;
00090   void                message(const std::string& message) ;
00091   virtual bool        bind(const std::string& expression) ;
00092   virtual bool        rebind(const std::string& name, const std::string& new_value) ;
00093   virtual std::string resolve(const std::string& name) ;
00094   virtual bool        parse(const std::string& expr, std::string& res) ;
00095   GenAction*          parent() const ;
00096   GenAction*          parent(GenAction* a) const ;
00097   std::string         last_error() ;
00098 
00099   void set_activate_error(bool) ;
00100   bool is_error_activated() const ;
00101   
00102 
00103 private:
00104   GenAction* parent_ ;
00105   IfStream is_ ;
00106   bool error_displ_activated_ ;
00107   std::string last_error_ ;
00108 } ;
00109 //----------------------------------
00110 DECLARE_SMART_OBJECT(GenAction) ;
00111 //----------------------------------
00112 
00113 
00114 class ListActions: public GenAction {
00115   typedef std::vector<SmartPointer<GenAction> > List ;
00116 public:
00117   typedef List::iterator iterator ;
00118   ListActions() ;
00119   ListActions(ListActions*) ;
00120   virtual RET_TYPE set_parameters(IfStream*, const std::string& params) ;
00121   virtual RET_TYPE execute() ;
00122   virtual std::string args() const ;
00123   virtual std::string command_name() const ;
00124 
00125   void add_action(GenAction* a) ;
00126 
00127 private:
00128   List list_ ;
00129 } ;
00130 
00131 //----------------------------------
00132 DECLARE_SMART_OBJECT(ListActions) ;
00133 //----------------------------------
00134 
00135 
00136 inline const IfStream& GenAction::ifstream() const {
00137   return is_ ;
00138 }
00139 
00140 inline bool GenAction::is_error_activated() const {
00141   return error_displ_activated_ ;
00142 }
00143 
00144 inline GenAction* GenAction::parent() const {
00145   return parent_;
00146 }
00147 
00148 inline GenAction* GenAction::parent(GenAction* a) const {
00149   if(a)
00150     return a->parent() ;
00151   return NULL ;
00152 }
00153 
00154 END_LIB_NAMESPACE
00155 
00156 #endif
00157 

Generated on Wed May 14 11:42:31 2003 for Esla-lib by doxygen1.3-rc1