00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef GLUE_ARC_H
00024 #define GLUE_ARC_H
00025
00026 #include "std/ref.H"
00027 #include "std/strings.H"
00028 #include "fsa/guard.H"
00029
00030 typedef const class STATE cSTATE;
00031 class STATE;
00032 #define STATEstart ((STATE *)-1)
00033
00034
00035
00036
00037
00038
00039 MAKE_PTR_BASEC(TRIGGER);
00040 class TRIGGER : public REFcounter {
00041 public:
00042 virtual ~TRIGGER() { }
00043 virtual void exec(STATE *&, cEVENTptr &) = 0;
00044 };
00045
00046
00047
00048
00049
00050 class TRIGGERfunc : public TRIGGER {
00051 public :
00052 typedef void (*_functor)(cEVENTptr &, STATE *&);
00053
00054 protected :
00055 _functor _func;
00056
00057 public:
00058 virtual ~TRIGGERfunc() { }
00059 TRIGGERfunc(_functor f): _func(f) { }
00060
00061 void exec(STATE *&s, cEVENTptr &e) { _func(e,s); }
00062 };
00063
00064
00065
00066
00067
00068 template <class T, class EVT>
00069 class TRIGGERmeth : public TRIGGER {
00070 public:
00071 typedef void (T::*_meth)(EVT, STATE *&);
00072
00073 protected:
00074 T *_obj;
00075 _meth _method;
00076
00077 public:
00078 virtual ~TRIGGERmeth() { }
00079 TRIGGERmeth(T *obj, _meth meth): _obj(obj), _method(meth) { }
00080
00081 void exec(STATE *&s, cEVENTptr &e) { EVT x((EVT) e);
00082 if (!x->cast(e)) {
00083 cerr<< "ERROR: TRIGGERmeth: event type ";
00084 e->debug(cerr);
00085 cerr<<" doesn't match FSA Arc method " << x->static_name() << endl;
00086 } else
00087 (_obj->*_method)(x->cast(e),s); }
00088 };
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 typedef const class ARC cARC;
00102 class ARC {
00103 protected :
00104
00105 str_ptr _name;
00106 STATE *_next;
00107 GUARDptr _guard;
00108 TRIGGERptr _trigger;
00109
00110 public :
00111
00112 ARC(Cstr_ptr &n, cEVENTptr &e, cTRIGGERptr &t,STATE *s=0):_name(n),
00113 _next(s),_guard(new GUARDevent(e)),_trigger(t) {}
00114 ARC(Cstr_ptr &n, cGUARDptr &g, cTRIGGERptr &t,STATE *s=0):_name(n),
00115 _next(s),_guard(g),_trigger(t) { }
00116 virtual ~ARC() {}
00117
00118 int match(cEVENTptr &e) const { return _guard->exec(e); }
00119 bool guarded() const { return _guard->guarded(); }
00120 cGUARDptr &guard() const { return _guard; }
00121 int operator==(cARC &a) const { return *_guard == *a._guard; }
00122 void debug(ostream &o) const { if (_name) o << _name << ":";
00123 if (_guard)_guard->debug(o); }
00124 void exec(STATE *&s, cEVENTptr &e, STATE *start) {
00125 if (_next)
00126 s = _next==STATEstart ? start:_next;
00127 _trigger->exec(s,e);
00128 if (s == STATEstart) s = start; }
00129 };
00130
00131 #endif