DiaDes  0.1
DIAgnosis of Discrete-Event System
FaultyEventStateMachine.hh
Go to the documentation of this file.
1 
7 #ifndef __DIADES__AUTOMATA__EXPERIMENTAL__FAULTYEVENTSTATEMACHINE__HH__
8 #define __DIADES__AUTOMATA__EXPERIMENTAL__FAULTYEVENTSTATEMACHINE__HH__
9 
10 
13 
14 namespace Diades {
15  namespace Automata {
16  namespace Experimental {
17  using Diades::Utils::Msg;
18  using std::unordered_set;
19  using std::unordered_map;
20  using std::set;
21 
28  template<typename _StatePropertyId,
29  typename _EventPropertyId,
30  typename _NullStatePropertyId = NullValue<_StatePropertyId>,
31  typename _NullEventPropertyId = NullValue<_EventPropertyId>
32 
33  >
34  class FaultyEventStateMachine : public StateMachine<_StatePropertyId, _EventPropertyId, _NullStatePropertyId,_NullEventPropertyId> {
35  public:
36  using StatePropertyId = _StatePropertyId;
37  using EventPropertyId = _EventPropertyId;
38  using NullStatePropertyId = _NullStatePropertyId;
40  typedef typename unordered_set<EventPropertyId>::const_iterator NormalEventPropertyIdIterator;
41  typedef typename unordered_set<EventPropertyId>::const_iterator FaultyEventPropertyIdIterator;
42 
43  private:
44 
46 
47 
48 
49  private:
50  unordered_set<EventPropertyId> _faultyEventPropertyIds;
51  unordered_set<EventPropertyId> _normalEventPropertyIds;
52 
53 
54 
55 
56  public:
57 
58  /*********************************************************************/
59  /* GENERAL MANAGEMENT */
60  /*********************************************************************/
61 
66  _faultyEventPropertyIds(),
67  _normalEventPropertyIds() {
68  }
69 
75  SM(machine),
76  _faultyEventPropertyIds(machine._faultyEventPropertyIds),
77  _normalEventPropertyIds(machine._normalEventPropertyIds) {
78  }
79 
86  if (this != &machine) {
87  SM::operator=(machine);
88  _faultyEventPropertyIds = machine._faultyEventPropertyIds;
89  _normalEventPropertyIds = machine._normalEventPropertyIds;
90 
91  }
92  return *this;
93  }
94 
98  virtual
100  clear();
101  }
102 
106  virtual void
107  clear() {
108 
109  _faultyEventPropertyIds.clear();
110  _normalEventPropertyIds.clear();
111  SM::clear();
112 
113  }
114 
115 
116  /********************************************************************/
117 
118 
119  /*********************************************************************/
120  /* EVENT MANAGEMENT */
121  /*********************************************************************/
131  insertEventPropertyId(event);
132  if(m.isFaulty(event))
133  {
134  setFaulty(event);
135  }
136  }
137 
146  std::for_each(m.eventBegin(), m.eventEnd(),
147  [&](EventPropertyId event) {
148  copyEventPropertyId(m,event);
149  }
150  );
151  }
152 // /**
153 // * Copy the EventPropertyId of a machine into the current one
154 // * @param m a StateMachine
155 // * @param event an EventPropertyId
156 // * @p this method is used especially in Determine, Abstract, ...
157 // * As it is virtual, it ensures that events and their properties
158 // * are properly copied whatever the derived class calls it.
159 // */
160 // virtual
161 // void copyEventPropertyId(const FaultyEventStateMachine & m, const EventPropertyId & event) {
162 // this->insertEventPropertyId(event);
163 // if(m.isFaulty(event))
164 // {
165 // setFaulty(event);
166 // }
167 // }
168 
176  virtual
177  void
179  if (!SM::containsEvent(event)) {
181  _normalEventPropertyIds.insert(event);
182  }
183  }
184 
190  void
192  require(Exception, SM::containsEvent(e), "setFaulty: the event does not exist in the machine");
193  _normalEventPropertyIds.erase(e);
194  _faultyEventPropertyIds.insert(e);
195  }
196 
201  bool
202  isFaulty(const EventPropertyId & e) const {
203  return _faultyEventPropertyIds.find(e) != _faultyEventPropertyIds.end();
204  }
205 
213  const std::unordered_set<EventPropertyId> &
214  faultyEvents() const {
216  }
217 
222  FaultyEventPropertyIdIterator
224  return _faultyEventPropertyIds.begin();
225  }
226 
231  FaultyEventPropertyIdIterator
232  faultyEventEnd() const {
233  return _faultyEventPropertyIds.end();
234  }
235 
241  void
243  require(Exception, SM::containsEvent(e), "setNormal: the event does not exist in the machine");
244  _normalEventPropertyIds.insert(e);
245  _faultyEventPropertyIds.erase(e);
246  }
247 
252  bool
253  isNormal(const EventPropertyId & e) const {
254  return _normalEventPropertyIds.find(e) != _normalEventPropertyIds.end();
255  }
256 
264  const unordered_set<EventPropertyId> &
265  normalEvents() const {
267  }
268 
273  NormalEventPropertyIdIterator
275  return _normalEventPropertyIds.begin();
276  }
277 
282  NormalEventPropertyIdIterator
283  normalEventEnd() const {
284  return _normalEventPropertyIds.end();
285  }
286 
287 
288 
289 
290 
291  private:
292 
299  virtual
300  void
301  eraseEventPropertyId(size_t eventIndex) {
302  _normalEventPropertyIds.erase(SM::getEventFromIndex(eventIndex));
303  _faultyEventPropertyIds.erase(SM::getEventFromIndex(eventIndex));
304  SM::eraseEventPropertyId(eventIndex);
305 
306  }
307 
308 
309  };
310 
311 
312  }
313  }
314 
315 }
316 
317 
318 //
319 //
320 //namespace std
321 //{
322 //
323 // template <typename StateProperty, typename EventProperty>
324 // struct iterator_traits<Diades::Automata::Experimental::StateMachine<StateProperty, EventProperty>>
325 // {
326 // using iterator_category = std::forward_iterator_tag;
327 // using value_type = StateProperty;
328 // };
329 //
330 //}
331 //
332 
333 
334 
335 #endif /* FAULTYEVENTSTATEMACHINE_HH */
336 
unordered_set< EventPropertyId >::const_iterator FaultyEventPropertyIdIterator
EventPropertyIdIterator eventEnd() const
virtual FaultyEventStateMachine & operator=(const FaultyEventStateMachine &machine)
const std::unordered_set< EventPropertyId > & faultyEvents() const
StateMachine & operator=(const StateMachine &machine)
EventPropertyId getEventFromIndex(size_t index) const
virtual void eraseEventPropertyId(size_t eventIndex)
bool containsEvent(const EventPropertyId &e) const
virtual void insertEventPropertyId(const EventPropertyId &event)
#define require(Exception, expr, message)
Definition: Assertion.hh:90
Namespace of the Diades project.
void copyEventPropertyId(const FaultyEventStateMachine &m, const EventPropertyId &event)
virtual void insertEventPropertyId(const EventPropertyId &event)
EventPropertyIdIterator eventBegin() const
unordered_set< EventPropertyId >::const_iterator NormalEventPropertyIdIterator
FaultyEventStateMachine(const FaultyEventStateMachine &machine)
const unordered_set< EventPropertyId > & normalEvents() const
boost::format Msg
Definition: Verbose.hh:42