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

guard.H

Go to the documentation of this file.
00001 #ifndef GLUE_GUARD_H
00002 #define GLUE_GUARD_H
00003 
00004 #include "event/event.H"
00005 
00006 
00007 //
00008 //  GUARD - abstract interface
00009 //
00010 //
00011 MAKE_PTR_BASEC(GUARD);
00012 typedef const class GUARD cGUARD;
00013 class GUARD: public REFcounter {
00014  public:
00015    virtual     ~GUARD()                      { }
00016    virtual int  exec(cEVENTptr &e)     const = 0;
00017    virtual bool guarded()              const = 0;
00018            int  operator == (cGUARD &) const { return 0; }
00019    virtual void debug(ostream &o)      const = 0;
00020 };
00021 
00022 
00023 //
00024 //  GUARDevent - test if EVENTs match
00025 //
00026 //
00027 MAKE_PTR_SUBC(GUARDevent, GUARD);
00028 class GUARDevent : public GUARD {
00029  protected:
00030    EVENTptr _event;
00031  public:
00032                       GUARDevent(cEVENTptr &e):_event(e) { }
00033 
00034    virtual int        exec(cEVENTptr &e) const  { return _event->test(e); }
00035    virtual bool       guarded()          const  { return false; }
00036    virtual cEVENTptr &event()            const  { return _event; }
00037    virtual void       debug(ostream &o)  const  { _event->debug(o);}
00038 };
00039 
00040 
00041 //
00042 //  GUARDfunc - test EVENTs with a given function
00043 //
00044 //
00045 class GUARDfunc: public GUARD {
00046  public:
00047    typedef bool (*func_t)(cEVENTptr &);
00048 
00049  protected:
00050    func_t  _func;
00051 
00052  public: 
00053                   GUARDfunc(func_t f) : _func(f) {}
00054 
00055    virtual bool   guarded()          const  { return false; }
00056    virtual int    exec(cEVENTptr &e) const  { return (*_func)(e); }
00057    virtual void   debug(ostream &o)  const  { o << "(GUARDfunc)"; }
00058 };
00059 
00060 //
00061 //  GUARDmeth - test EVENTs with a given method on an object
00062 //
00063 //
00064 template <class T, class EVT>
00065 class GUARDmeth: public GUARD {
00066   public:
00067     typedef bool (T::*_meth)(EVT) const;
00068 
00069   protected:
00070     T        *_obj;
00071     _meth     _method;
00072 
00073   public: 
00074                   GUARDmeth(T *o, _meth m): _obj(o),_method(m) {}
00075    virtual       ~GUARDmeth()               { }
00076 
00077    virtual bool   guarded()          const  { return false; }
00078    virtual int    exec(cEVENTptr &e) const  { EVT x((EVT) e);
00079                                               if (!x->cast(e)) {
00080                                                  cerr<< "ERROR: GUARDmeth: event type ";
00081                                                      e->debug(cerr);
00082                                                  cerr<<" doesn't match FSA GUARD method " <<  x->static_name() << endl;
00083                                             return 0;
00084                                           } else
00085                                              return (_obj->*_method)(x->cast(e)); }
00086    virtual void   debug(ostream &o)  const  { o << "(GUARDmeth)"; }
00087 };
00088 
00089 //
00090 //  GUARDand - tests two GUARD's, returns true only if both GUARDS return true
00091 //
00092 //
00093 class DllImpExp GUARDand : public GUARD {
00094    protected:
00095       GUARDptr _g1;
00096       GUARDptr _g2;
00097    public:
00098                 GUARDand(cGUARDptr &g1, cGUARDptr &g2) : _g1(g1), _g2(g2) {}
00099    virtual     ~GUARDand()                { }
00100 
00101    virtual bool guarded()          const  { return true; }
00102    virtual int  exec(cEVENTptr &e) const  { return _g1->exec(e)&&_g2->exec(e); }
00103    virtual void debug(ostream &o)  const  { _g1->debug(o);o<<"&";_g2->debug(o);}
00104 };
00105 
00106 //
00107 //  GUARDnot - returns the logical negation of a GUARD
00108 //
00109 //
00110 class GUARDnot : public GUARD {
00111    protected:
00112       cGUARDptr _g;
00113    public:
00114                   GUARDnot(cGUARDptr &g) : _g(g) { }
00115    virtual       ~GUARDnot()                { }
00116 
00117    virtual bool   guarded()          const  { return true; }
00118    virtual int    exec(cEVENTptr &e) const  { return !_g->exec(e); }
00119    virtual void   debug(ostream &o)  const  { o << "!"; _g->debug(o); }
00120 };
00121 #endif

Generated on Mon Sep 15 16:25:56 2003 for gluebase by doxygen1.2.18