Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ih.h

Go to the documentation of this file.
00001 #ifndef ih_h
00002 #define ih_h
00003 
00004 #include <string>
00005 #include <list>
00006 #include "script.h"
00007 #include "file.h"
00008 
00010 class Interpreter
00011 {
00012 public:
00013 
00015   class Type
00016   {
00017   public:
00018     enum EType
00019       {
00020         UNKNOWN,    
00021         JAVASCRIPT, 
00022         DEFAULT     
00023       };
00024 
00025   private:
00026     EType type;
00027     std::string name;     
00028     std::string command;  
00029 
00030     bool valid;
00031   public:
00032     Type() : type( UNKNOWN ), valid( false ) {}
00033     Type( std::string type, std::string name = "", std::string command="" );
00034 
00035     std::string get_name() const { return name; }
00036     std::string get_command() const { return command; }
00037     EType get_type() const { return type; }
00038     bool operator!() const { return !valid; }
00039     bool is_valid() const { return valid; }
00040   };
00041   
00043   struct Error
00044   {
00045     std::string what;
00046     Error( std::string what ) : what( what ) {}
00047   };
00048   
00049 protected:
00050   Type type;
00051   bool default_int;
00052   
00053   std::istream* in;
00054   std::ostream* out;
00055   std::ostream* err;
00056   
00057   bool valid;
00058 
00059 public:
00060   Type get_type() const { return type; }
00061   bool is_default() const { return default_int; }
00062   
00063   Interpreter();
00064   Interpreter( Type type, bool default_int,  std::istream& in, std::ostream& out, std::ostream& err );
00065   virtual ~Interpreter();
00066 
00068   virtual bool exec()=0;
00069   virtual bool exec( std::string buffer )=0;
00070 
00071   bool operator!() const { return !valid; }
00072   bool is_valid() const { return valid; }
00073 
00074   void set_io( std::istream& in, std::ostream& out, std::ostream& err );
00075   void set_out( std::ostream& out );
00076   
00077   std::ostream& get_out() const { return *out; }
00078   std::istream& get_in()  const { return *in; }
00079   std::ostream& get_err() const { return *err; }
00080 };
00081 
00082 bool operator==( const Interpreter::Type &t1, const Interpreter::Type &t2 );
00083 
00084 inline bool operator==( const Interpreter::Type &t1, const Interpreter::Type::EType t2 )
00085 {
00086   return t1.get_type() == t2;
00087 }
00088 
00089 class Precompiler;
00090 
00092 class InterpreterHandler
00093 {
00094 private:
00095   typedef std::list<Interpreter*> interpreter_list;
00096   typedef interpreter_list::iterator interpreter_list_it;
00097 
00098   interpreter_list il;
00099 
00100   Precompiler &precompiler;
00101 public:
00102   InterpreterHandler( Precompiler &precompiler ) : precompiler( precompiler ) {}
00103   ~InterpreterHandler();
00104 
00106   bool have_one( Interpreter::Type type );
00107 
00109 
00113   Interpreter* get_default();
00114 
00116 
00117   bool add( Interpreter* ip );
00118 
00119   bool have_default();
00120 
00122 
00126   Interpreter* get_one( Interpreter::Type type );
00127   Interpreter* get_one( std::string name );
00128 
00130 
00131   bool create_one( Interpreter::Type type, std::istream& in, std::ostream& out, std::ostream& err, bool default_int = false );
00132 };
00133 
00134 class Precompiler;
00135 
00137 class ScriptHandler
00138 {
00139 public:
00140   
00141   // handles Script sources
00142   class Script
00143   {
00144   private:
00145     Interpreter::Type type;
00146     File buffer;
00147     ScriptStart start;
00148 
00149     bool valid;
00150   public:
00151     Script( Interpreter::Type type, File buffer, ScriptStart start );
00152 
00153     template <class T> void operator<<( T t ) { buffer << t; }
00154     template <class T> void operator>>( T& t ) { buffer >> t; }
00155 
00156     bool operator!() const { return !valid; }
00157     bool is_valid() const { return valid; }
00158 
00159     File get_buffer() const { return buffer; }
00160 
00161     Interpreter::Type get_type() const { return type; }
00162     ScriptStart get_start() const { return start; }
00163   };
00164 
00165   typedef std::list<Script> script_list;
00166   typedef script_list::iterator script_list_it;
00167 
00168 private:
00169 
00170   script_list sl;
00171 
00172   Precompiler* precompiler;
00173 
00174 public:
00175 
00176   ScriptHandler( Precompiler* precompiler );
00177 
00179   bool add( ScriptStart ss, File buffer );
00180 
00181   script_list get_scripts() const { return sl; }
00182 
00183 private:
00184   ScriptHandler(){}
00185 
00186 };
00187 
00188 #endif

Generated on Tue Nov 20 02:19:52 2001 for Leo<HTML> by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001