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

fsa.H

Go to the documentation of this file.
00001 /*
00002  * Copyright 1997, Brown University, Providence, RI.
00003  * 
00004  *                         All Rights Reserved
00005  * 
00006  * Permission to use, copy, modify, and distribute this software and its
00007  * documentation for any purpose other than its incorporation into a
00008  * commercial product is hereby granted without fee, provided that the
00009  * above copyright notice appear in all copies and that both that
00010  * copyright notice and this permission notice appear in supporting
00011  * documentation, and that the name of Brown University not be used in
00012  * advertising or publicity pertaining to distribution of the software
00013  * without specific, written prior permission.
00014  * 
00015  * BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00016  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00017  * PARTICULAR PURPOSE.  IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
00018  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00019  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00020  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00021  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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 //  Interactor
00035 //     is a convenience class that makes it easy for an
00036 //  object to define ARC and GUARD methods and ultimately
00037 //  encapsulate an FSA.
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 // FSA 
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

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