summaryrefslogtreecommitdiff
path: root/dnn/Behaviour.h
blob: 55fc8e527eca6a5e7431bb3f85d0ea99bc70f0a6 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 *	DNN - Data News Network
 *
 *	by Stephane Chatty
 *
 *	Copyright 1993-1996
 *	Centre d'Etudes de la Navigation Aerienne (CENA)
 *
 *	Behaviours.
 *
 *	$Id$
 *	$CurLog$
 */

#ifndef IvlBehaviour_H_
#define IvlBehaviour_H_

#include "cplus_bugs.h"
#include "Reaction.h"
#include "ivl/String.h"
#include "ivl/List.h"

class IvlBehaviour;
class IvlTransition;
class IvlEvent;

class IvlToken {
public:
		IvlToken ();
virtual		~IvlToken ();
};

typedef void (IvlActivation) (IvlBaseReaction*, IvlToken*);
typedef void (IvlAction) (IvlToken*, IvlEvent*);

class IvlState {
protected:
	IvlString	Name;
	IvlListOf <IvlTransition>	Transitions;
public:
		IvlState (const char*);
		~IvlState ();
	IvlTransition*	CreateTransition (const char*, IvlState*, IvlActivation*, IvlAction*);
	void	Activate (IvlBehaviour*, IvlToken*);
	
};

class IvlTransition {
protected:
	IvlString	Name;
	IvlState*	From;
	IvlState*	To;
	IvlActivation*	Activation;
	IvlAction*	Action;

public:
		IvlTransition (const char*, IvlState*, IvlState*, IvlActivation*, IvlAction*);
		~IvlTransition ();
inline	IvlState*	GetDestination () const	{ return To;}
inline	IvlState*	GetOrigin () const	{ return From;}
	void	Activate (IvlBaseReaction*, IvlToken*);
	IvlState*	Fire (IvlToken*, IvlEvent*);
};

class IvlBehaviourModel {
protected:
	IvlState*	Initial;
	IvlListOf <IvlState>	States;
public:
		IvlBehaviourModel ();
		~IvlBehaviourModel ();
inline	IvlState*	GetInitial () const	{ return Initial; }
inline	void	SetInitial (IvlState* s)	{ Initial = s; }
	IvlState*	CreateState (const char* = 0);
};

class IvlBehaviour {
friend	class	IvlBehaviourReaction;
protected:
	IvlBehaviourModel*	TheModel;
	IvlState*	CurState;
	IvlListOf <IvlBaseReaction>	CurReactions;
	IvlToken*	CurToken;
	void	Fire (IvlTransition*, IvlEvent*);
public:
		IvlBehaviour (IvlBehaviourModel&, IvlToken*);
		~IvlBehaviour ();
inline	void	AddReaction (IvlBaseReaction* r) { CurReactions.Append (r); }

};

class IvlBehaviourReaction : public IvlBaseReaction {
protected:
	IvlBehaviour*	TheBehaviour;
	IvlTransition*	TheTransition;
public:
		IvlBehaviourReaction (IvlBehaviour*, IvlTransition*);
		~IvlBehaviourReaction ();
	void	Manage (IvlEvent&);
};	

#endif	/* IvlBehaviour_H_ */