DiaDes  0.1
DIAgnosis of Discrete-Event System
StateNode.hh
Go to the documentation of this file.
1 
2 
3 
4 class StateNode
5 {
6 public:
10  StateNode():next(0),down(0),state() {}
11 };
12 
13 
15 {
16 private:
18 public:
19  StateTable():root(0){}
20  void insert(const vector<State> & states, State synchronisedState);
21  State getSynchronisedState(const vector<State> & states) const;
22 };
23 
24 
25 
26 void StateTable::insert(const vector<State> & states, State synchronisedState)
27 {
29  vector<State>::size_type index = 0;
30  if(root == 0)
31  {
32  current = new StateNode();
33  current->state = states[index];
34  }
35 
36  while(index != states.size()-1)
37  {
38  if(current->state == states[index])
39  {
40  if(current->down == 0)
41  {
42  current->down = new StateNode();
43  current->down->state = states[index+1];
44  }
45  current = current->down;
46  ++index;
47  }
48  else
49  {
50  if(current->state.id() < states[index].id())
51  {
52  if(current->next == 0)
53  {
54  current->next = new StateNode();
55  current->next->state = states[index];
56  }
57  current = current->next;
58  }
59  else
60  {
61  // current->state.id() > states[index].id()
62  StateNode * newNode = new StateNode();
63  newNode->state = current->state;
64  newNode->next = current->next;
65  newNode->down = current->down;
66  current->state = states[index];
67  }
68  }
69  }
70  if(current->down == 0)
71  {
72  current->down = new StateNode();
73  current->down->state = synchronisedState;
74  }
75 }
76 
77 
78 
79 State StateTable::getSynchronisedState(const vector<State> & states)
80 {
81  State result;
82  if(root != 0)
83  {
84  StateNode * current = root;
85  vector<State>::size_type index = 0;
86  bool exit = false;
87  while(!exit && (index != states.size()))
88  {
89  if(current->state == states[index])
90  {
91  if(current->down != 0)
92  {
93  current = current->down;
94  ++index;
95  }
96  else
97  {
98  assertion(StateNodeInvalid, index != states.size(), "getSynchronisedState: the synchronised state of the visited state is not there");
99  exit = true;
100  }
101  }
102  else
103  {
104  if(current->state.id() < states[index].id())
105  {
106  if(current->next != 0)
107  {
108  current = current->next;
109  }
110  else
111  {
112  exit =true;
113  }
114  }
115  else
116  {
117  // current->state.id() > states[index].id()
118  exit = true;
119  }
120  }
121  }
122  if(index = states.size() )
123  {
124  result = current->state;
125  }
126  }
127  return result;
128 }
StateNode * down
Definition: StateNode.hh:8
StIndexes states
Definition: Run.cc:266
AutFsm::State State
Definition: Run.cc:72
Definition: Run.cc:83
StateNode * next
Definition: StateNode.hh:7
State state
Definition: StateNode.hh:9
State getSynchronisedState(const vector< State > &states) const
void insert(const vector< State > &states, State synchronisedState)
Definition: StateNode.hh:26
StateNode * root
Definition: StateNode.hh:17
#define assertion(Exception, expr, message)
Definition: Assertion.hh:106