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

#ifndef DnnBehaviour_H_
#define DnnBehaviour_H_

#include "cplus_bugs.h"
#include "ccu/Automaton.h"
class DnnEvent;

// en cours de developpement.

template <class T> class DnnStateOf;

template <class T> class DnnActionOf : public CcuBaseLink {
protected:
	T&	Object;
	void	(T::*Action)	(DnnStateOf<T>*, DnnStateOf<T>*, DnnEvent*);

	void	Fire (CcuBaseState* f, CcuBaseState* t, CcuToken* k)	{ if (Action) (Object.*Action) ((DnnStateOf<T>*) f, (DnnStateOf<T>*) t, (DnnEvent*) k);}

public:
		DnnActionOf (DnnStateOf<T>* s, DnnEventType* k, T& o, void (T::*a) (DnnStateOf<T>*, DnnStateOf<T>*, DnnEvent*)) : CcuBaseLink (s), Object (o), Action (a)	{}
		~DnnActionOf ()	{}

};

#if 0
/* future version of States: they create reactions associated to their links when entered. */

class DnnSuperState : public CcuBaseState {
protected:
	CcuListOf<DnnCriterion>	Criteria;
	void	In ();
	void	Out ();
public:
		DnnSuperState (const char* n, CcuAutomaton& b) : CcuBaseState (n, b)	{}
		~DnnSuperState ();
	void	CreateLink (DnnSuperState*, DnnCriterion*);
};

template <class T> class DnnStateOf : public CcuBaseState {
protected:
	void	In ()	{}
	void	Out ()	{}
public:
		DnnStateOf (const char* n, DnnBehaviourOf<T>& b) : CcuBaseState (n, b)	{}
		~DnnStateOf ()	{}
	void	CreateLink (DnnStateOf<T>* to, DnnEventType* k, T& o, void (T::*a) (DnnStateOf<T>*, DnnStateOf<T>*, DnnEvent*)) { CcuHashCellOf <CcuBaseLink>* c = Links.Add (k); c->SetInfo (new DnnActionOf<T> (to, k, o, a)); }
};

template <class T> class DnnBehaviourOf : public CcuBaseAutomaton {
protected:
static	CcuKey*	GetEventType (CcuToken*);
public:
		DnnBehaviourOf () : CcuBaseAutomaton (&GetEventType)	{}
		~DnnBehaviourOf ()	{}
	DnnStateOf<T>*	CreateState (const char* n) { DnnStateOf<T>* s = new DnnStateOf<T> (n, *this); AllStates.Append (s); return s; }
};

template <class T>
CcuKey*
DnnBehaviourOf<T> :: GetEventType (CcuToken* t)
{
	DnnEvent* e = (DnnEvent*) t;
	return (CcuKey*) e->GetType ();
}


// tentative du 20/11/95
template <class T> class DnnInteractionOf : public CcuAutomIter {
		DnnInteractionOf (DnnBehaviourOf<T>& b) : CcuAutomIter (b)	{}
};
#endif
#endif	/* DnnBehaviour_H_ */