summaryrefslogtreecommitdiff
path: root/dnn/Automaton.h
blob: 3cb78ba4c4eb889f2a609ce78f3134cad4a3dd18 (plain)
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
/*
 *	DNN - Data News Network
 *
 *	by Stephane Chatty
 *
 *	Copyright 1993-1995
 *	Centre d'Etudes de la Navigation Aerienne (CENA)
 *
 *	Automata.
 *
 *	$Id$
 *	$CurLog$
 */

#ifndef DnnAutomaton_H_
#define DnnAutomaton_H_

#include "cplus_bugs.h"
#include "ccu/List.h"
#include "ccu/HashTable.h"
#include "ccu/String.h"
#include "ccu/bool.h"

class DnnState;

typedef void (DnnStateFun) (DnnState*);
typedef void (DnnLinkFun) (DnnState*, DnnState*, void*);

class DnnLink {
public:
	DnnState*	To;
	DnnLinkFun*	Fun;
inline		DnnLink (DnnState* to, DnnLinkFun* fn) : To (to), Fun (fn)	{}
inline		~DnnLink ()	{}
};


class DnnState {
protected:
	CcuString	Name;
	DnnStateFun*	InFun;
	DnnStateFun*	OutFun;
	CcuHashTableOf <DnnLink>	Links; 

inline	void	In ()	{ if (InFun) (*InFun) (this); }
inline	void	Out ()	{ if (OutFun) (*OutFun) (this); }

public:
		DnnState (const char*, int sz, DnnStateFun* = 0, DnnStateFun* = 0);
		~DnnState ();
	void	CreateLink (DnnState*, void*, DnnLinkFun);
	DnnState*	Next (void*, bool = false);
};

class DnnAutomaton {
protected:
	int	Size;
	DnnState*	Initial;
	CcuListOf <DnnState>	AllStates;
public:
		DnnAutomaton (int sz = 16);
		~DnnAutomaton ();
inline	DnnState*	GetInitial ()	{ return Initial; }
inline	void	SetInitial (DnnState* s)	{ Initial = s; }
	DnnState*	CreateState (const char* = 0, DnnStateFun = 0, DnnStateFun = 0);
	void	CreateLink (DnnState*, DnnState*, void*, DnnLinkFun);
};

class DnnAutomIter {
protected:
	DnnAutomaton*	TheAutomaton;
	DnnState*	CurState;
public:
		DnnAutomIter (DnnAutomaton&);
		~DnnAutomIter ();
	bool	Step (void*);
};



#endif	/* DnnAutomaton_H_ */