ESLA

Embeddable Scriting LAnguage

frantz@pangea.stanford.edu

Stanford University, Rock Fracture Project research group

© 2003

if_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 IF_ACTION
00028 #define IF_ACTION
00029 
00030 #include "../esla_namespace.h"
00031 #include "common.h"
00032 #include "gen_action.h"
00033 #include "local_string_var_registry.h"
00034 #include "local_fct_registry.h"
00035 #include <string>
00036 
00037 BEGIN_LIB_NAMESPACE 
00038 
00039 // ==============================================
00040 
00041 class IfBase: public GenAction {
00042 public:
00043   IfBase() ;
00044   virtual std::string args() const ;
00045 protected:
00046   virtual bool bind(const std::string& expression) ;
00047   virtual bool rebind(const std::string& name, const std::string& new_value) ;
00048   virtual std::string resolve(const std::string& name) ;
00049   virtual bool parse(const std::string& expr, std::string& res) ;
00050 
00051   Tokens vars_ ;
00052   LocalStringVarRegistry var_registry_if_ ;
00053   LocalStringVarRegistry var_registry_else_ ;
00054 
00055   RET_TYPE  eval(const std::string& var, bool&) ;
00056   void      set_true_expr(bool) ;
00057   void      set_has_else(bool) ;
00058   bool      has_else() const ;
00059   RET_TYPE  pre_execute(bool& result) ;
00060 
00061 private:
00062   bool has_else_ ;
00063   bool is_true_ ;
00064 } ;
00065 inline bool IfBase::has_else() const { return has_else_ ;}
00066 
00067 // ==============================================
00068 
00069 class IfAction: public IfBase {
00070 public:
00071   // --------------------------------------
00072   enum REACH_T {
00073     REACH_NONE,
00074     REACH_END,
00075     REACH_ELSE,
00076     REACH_ELSEIF
00077   } ;
00078 
00079 private:
00080   class ElseIfAction: public IfBase {
00081   public:
00082     ElseIfAction(IfAction* p) ;
00083     virtual RET_TYPE set_parameters(IfStream*, const std::string& params) ;
00084     virtual RET_TYPE execute() ;
00085     virtual std::string command_name() const ;
00086     REACH_T reach_type() const ;
00087     const std::string& last_line() const ;
00088   private:
00089     ListActions list_ ;  
00090     REACH_T reach_ ;
00091     std::string last_line_ ;
00092     SmartPointer<IfAction> super_ ;
00093   } ;
00094   // --------------------------------------
00095   class ElseAction: public IfBase {
00096   public:
00097     ElseAction() ;
00098     virtual RET_TYPE set_parameters(IfStream*, const std::string& params) ;
00099     virtual RET_TYPE execute() ;
00100     virtual std::string command_name() const ;
00101     REACH_T reach_type() const ;
00102   private:
00103     ListActions list_ ;  
00104     REACH_T reach_ ;
00105   } ;
00106   friend class ElseIfAction ;
00107 public:
00108   IfAction() ;
00109   virtual RET_TYPE set_parameters(IfStream*, const std::string& params) ;
00110   virtual RET_TYPE execute() ;
00111   virtual std::string command_name() const ;
00112 
00113 protected:
00114   void set_result(bool) ;
00115 
00116 private:
00117   bool result_ ;
00118   ListActions list_if_ ;
00119   ListActions list_else_ ;
00120   ListActions list_elseif_ ;
00121 } ;
00122 //----------------------------------
00123 DECLARE_SMART_OBJECT(IfAction) ;
00124 //----------------------------------
00125 
00126 inline IfAction::REACH_T IfAction::ElseIfAction::reach_type() const {
00127   return reach_ ;
00128 }
00129 inline const std::string& IfAction::ElseIfAction::last_line() const {
00130   return last_line_ ;
00131 }
00132 
00133 inline IfAction::REACH_T IfAction::ElseAction::reach_type() const {
00134   return reach_ ;
00135 }
00136 
00137 
00138 END_LIB_NAMESPACE
00139 
00140 #endif

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