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_FSA_H
00024 #define GLUE_FSA_H
00025
00026 #include "std/strings.H"
00027 #include "fsa/guard.H"
00028 #include "fsa/arc.H"
00029 #include "fsa/state.H"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 template <class T>
00041 class Interactor {
00042 protected :
00043 str_ptr _name;
00044 STATE _entry;
00045 public :
00046 virtual ~Interactor() { }
00047 Interactor(Cstr_ptr &n):_name(n),_entry(n) { }
00048
00049 STATE *entry() { return &_entry; }
00050 cSTATE *entry() const { return &_entry; }
00051 Cstr_ptr &name() const { return _name; }
00052 };
00053
00054 inline GUARD *Gd(cEVENTptr &e) { return new GUARDevent(e); }
00055 inline GUARD *GDand(cGUARDptr &a, cGUARDptr &b) { return new GUARDand(a, b); }
00056 inline GUARD *GDnot(cGUARDptr &a) { return new GUARDnot(a); }
00057
00058 template <class T, class EVT>
00059 inline GUARD *
00060 GdMeth(T *THIS_PTR, bool (T::*m)(EVT) const)
00061 { return new GUARDmeth<T,EVT>(THIS_PTR, m); }
00062
00063 #ifdef _AIX
00064 template <class T, class EVT>
00065 inline ARC *
00066 Arc(T *THIS_PTR, cGUARDptr &g, void (T::*m)(EVT, STATE *&), STATE *s)
00067 { return new ARC(((Interactor<T> *)THIS_PTR)->name(), g, new TRIGGERmeth<T,EVT>(THIS_PTR,m),s);}
00068 template <class T, class EVT>
00069 inline ARC *
00070 Arc(T *THIS_PTR, GUARD *g, void (T::*m)(EVT, STATE *&), STATE *s)
00071 { return new ARC(((Interactor<T> *)THIS_PTR)->name(), g, new TRIGGERmeth<T,EVT>(THIS_PTR,m),s);}
00072 template <class T, class EVT>
00073 inline ARC *
00074 Arc(T *THIS_PTR, cGUARDptr &g, void (T::*m)(EVT, STATE *&))
00075 { return new ARC(((Interactor<T> *)THIS_PTR)->name(), g, new TRIGGERmeth<T,EVT>(THIS_PTR,m),0);}
00076 template <class T, class EVT>
00077 inline ARC *
00078 Arc(T *THIS_PTR, GUARD *g, void (T::*m)(EVT, STATE *&))
00079 { return new ARC(((Interactor<T> *)THIS_PTR)->name(), g, new TRIGGERmeth<T,EVT>(THIS_PTR,m),0);}
00080 #else
00081 template <class T, class EVT>
00082 inline ARC *
00083 Arc(T *THIS_PTR, cGUARDptr &g, void (T::*m)(EVT, STATE *&), STATE *s=0)
00084 { return new ARC(((Interactor<T> *)THIS_PTR)->name(), g, new TRIGGERmeth<T,EVT>(THIS_PTR,m),s);}
00085 template <class T, class EVT>
00086 inline ARC *
00087 Arc(T *THIS_PTR, GUARD *g, void (T::*m)(EVT, STATE *&), STATE *s=0)
00088 { return new ARC(((Interactor<T> *)THIS_PTR)->name(), g, new TRIGGERmeth<T,EVT>(THIS_PTR,m),s);}
00089 #endif
00090
00091
00092
00093
00094 class FSA : public EVENThandler {
00095 protected:
00096 STATE *_cur;
00097 STATE *_start;
00098
00099 public:
00100 FSA():_cur(0), _start(0) { }
00101 FSA(STATE *x):_cur(x), _start(x) { }
00102
00103 STATE *cur() { return _cur; }
00104 STATE *start() { return _start; }
00105 void set_cur(STATE *x) { _cur = x; }
00106 void handle_event(cEVENTptr &e) { _cur->event(_cur,e,_start); }
00107 void reset() { _cur = _start; }
00108 bool is_reset() const { return _cur == _start; }
00109 };
00110
00111 #endif