diff options
author | chatty | 2000-11-28 14:19:34 +0000 |
---|---|---|
committer | chatty | 2000-11-28 14:19:34 +0000 |
commit | 09f57c8dffd9a8ba0983cce13381aef716f43801 (patch) | |
tree | 49c5faa7cd1b76eea36169b5ecce09411b2802c2 /utils/Automaton.h | |
parent | 2575756ec6f41bd05bf4505ccc0253fad0ed77c4 (diff) | |
download | ivy-league-09f57c8dffd9a8ba0983cce13381aef716f43801.zip ivy-league-09f57c8dffd9a8ba0983cce13381aef716f43801.tar.gz ivy-league-09f57c8dffd9a8ba0983cce13381aef716f43801.tar.bz2 ivy-league-09f57c8dffd9a8ba0983cce13381aef716f43801.tar.xz |
*** empty log message ***
Diffstat (limited to 'utils/Automaton.h')
-rw-r--r-- | utils/Automaton.h | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/utils/Automaton.h b/utils/Automaton.h new file mode 100644 index 0000000..a85d911 --- /dev/null +++ b/utils/Automaton.h @@ -0,0 +1,137 @@ +/* + * CENA C++ Utilities + * + * by Stephane Chatty + * + * Copyright 1992-1995 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Automata. + * + * $Id$ + * $CurLog$ + */ + +#ifndef CcuAutomaton_H_ +#define CcuAutomaton_H_ + +#include "cplus_bugs.h" +#include "List.h" +#include "HashTable.h" +#include "String.h" +#include "bool.h" + +typedef void CcuToken; +typedef void CcuKey; +class CcuBaseState; +class CcuBaseAutomaton; + +class CcuBaseLink { +protected: + CcuBaseState* To; +public: + CcuBaseLink (CcuBaseState*); +virtual ~CcuBaseLink (); +virtual void Fire (CcuBaseState*, CcuBaseState*, CcuToken*) = 0; +inline CcuBaseState* GetDestination () const { return To;} +}; + +class CcuBaseState { +protected: + CcuString Name; + CcuHashTableOf <CcuBaseLink> Links; + CcuBaseAutomaton* TheAutomaton; + +virtual void In () = 0; +virtual void Out () = 0; + +public: + CcuBaseState (const char*, CcuBaseAutomaton&); +virtual ~CcuBaseState (); + void Add (CcuBaseLink*); + void CreateLink (CcuBaseState*, CcuKey*); + void RemoveLink (CcuBaseLink*); + CcuBaseState* Next (CcuToken*, bool = false); +}; + + +#if 0 +typedef unsigned int (*HASH_F) (const CcuKey*, int); +typedef int (*HCMP_F) (const CcuKey*, const CcuKey*); +typedef CcuKey* (*HCP_F) (const CcuKey*); +typedef void (*HDEL_F) (const CcuKey*); +#endif +typedef CcuKey* (*AKEY_F) (CcuToken*); + + +class CcuBaseAutomaton { +friend class CcuBaseState; +friend class CcuAutomIter; +protected: + int Size; + HASH_F Hash; + HCP_F Copy; + HDEL_F Delete; + HCMP_F Compare; + AKEY_F GetKey; + CcuBaseState* Initial; + CcuListOf <CcuBaseState> AllStates; +public: + CcuBaseAutomaton (AKEY_F = 0, HASH_F = 0, HCP_F = 0, HDEL_F = 0, HCMP_F = 0, int sz = 4); + ~CcuBaseAutomaton (); +inline CcuBaseState* GetInitial () { return Initial; } +inline void SetInitial (CcuBaseState* s) { Initial = s; } + CcuBaseState* CreateState (const char* = 0); +}; + + +class CcuState; +typedef void (CcuLinkFun) (CcuState*, CcuState*, CcuToken*); + +class CcuLink : public CcuBaseLink { +protected: + CcuLinkFun* Fun; +public: + CcuLink (CcuState*, CcuLinkFun*); + ~CcuLink (); + void Fire (CcuBaseState*, CcuBaseState*, CcuToken*); +}; + +typedef void (CcuStateFun) (CcuState*); +class CcuAutomaton; + +class CcuState : public CcuBaseState { +protected: + CcuStateFun* InFun; + CcuStateFun* OutFun; + + void In (); + void Out (); + +public: + CcuState (const char*, CcuAutomaton&, CcuStateFun* = 0, CcuStateFun* = 0); + ~CcuState (); + void CreateLink (CcuState*, CcuKey*, CcuLinkFun); +}; + + +class CcuAutomaton : public CcuBaseAutomaton { +public: +inline CcuAutomaton () : CcuBaseAutomaton () {} +inline ~CcuAutomaton () {} + CcuState* CreateState (const char* = 0, CcuStateFun = 0, CcuStateFun = 0); +}; + +class CcuAutomIter { +protected: + CcuBaseAutomaton* TheAutomaton; + CcuBaseState* CurState; +public: + CcuAutomIter (CcuBaseAutomaton&); + ~CcuAutomIter (); + bool Step (CcuToken*); +}; + + + +#endif /* CcuAutomaton_H_ */ |