1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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_ */
|