DiaDes  0.1
DIAgnosis of Discrete-Event System
EventInserter.hh
Go to the documentation of this file.
1 
9 #ifndef __DIADES__AUTOMATA__EXPERIMENTAL__EVENTINSERTER__HH__
10 #define __DIADES__AUTOMATA__EXPERIMENTAL__EVENTINSERTER__HH__
11 
12 namespace Diades
13 {
14  namespace Automata
15  {
16  namespace Experimental
17  {
18 
19 
20 
30  template<typename Fsm>
32  {
33  public:
34 
35  using EventId = typename Fsm::EventPropertyId;
36  using EventMap = std::unordered_map<EventId, EventId>;
39 
40  protected:
44 
45  public:
49  EventInserter() = default;
50 
51 
56  EventInserter(EventInserter const& other) = default;
62  EventInserter& operator=(EventInserter const& other) = default;
67  EventInserter(EventInserter&& other) = default;
73  EventInserter& operator=(EventInserter&& other) = default;
77  ~EventInserter() = default;
78 
86  EventInserter(const Fsm & source, Fsm & target) :
87  _source(Diades::Utils::Ptr<Fsm>::get(source)),
88  _target(Diades::Utils::Ptr<Fsm>::get(target)),
89  _eventOf()
90  {
91  }
92 
99  EventId
101  {
102  auto it = _eventOf.find(evt);
103  if(it == _eventOf.end())
104  {
105  it = generateEvent(evt);
106  _target->insertEventPropertyId(it->second);
107  }
108 
109  return it->second;
110  }
111 
112  protected:
113 
122  virtual typename EventMap::iterator
124  {
125  // in case of unmanaged events, no problem, the eventPropertyId is unique
126  return _eventOf.emplace(evt, evt).first;
127  }
128  };
129 
140  template<typename _Fsm, typename _EventManager>
141  class ManagedEventInserter : public EventInserter<_Fsm>
142  {
143  public:
144  using Fsm = _Fsm;
146  using EM = _EventManager;
147  private:
150 
151  public:
155  ManagedEventInserter() = default;
156 
157 
162  ManagedEventInserter(ManagedEventInserter const& other) = default;
168  ManagedEventInserter& operator=(ManagedEventInserter const& other) = default;
173  ManagedEventInserter(ManagedEventInserter&& other) = default;
183  ~ManagedEventInserter() = default;
184 
194  ManagedEventInserter(const Fsm & source, Fsm & target,
195  const EM& sourceManager,
196  EM & targetManager) : EI(source, target),
197  _sourceManager(Diades::Utils::Ptr<EM>::get(sourceManager)),
198  _targetManager(Diades::Utils::Ptr<EM>::get(targetManager))
199  {
200  }
201 
202 
203  protected:
204 
213  virtual typename EI::EventMap::iterator
215  {
216 
217  // if evt is not associated with anything in the source manager,
218  // it means that it is associated with the _sourceManager->nullEvent()
219  // In this case generateEvent returns the _targetManager->nullEventId()
220  // so the property is kept: sourceManager.getEvent(evt) == targetManager.getEvent(evtTarget)
221  return EI::_eventOf.emplace(evt, _targetManager->eventId(_sourceManager->getEvent(evt))).first;
222  }
223  };
224 
225 
226  }
227  }
228 
229 }
230 
231 #endif /* __DIADES__AUTOMATA__EXPERIMENTAL__EVENTINSERTER__HH__ */
232 
Diades::Utils::Ptr< EM >::ConstP _sourceManager
const T * ConstP
Definition: Pointer.hh:31
FaultyEventStateMachine< CandidateId, EventInfoId > Fsm
typename Diades::Utils::Ptr< _Fsm >::P TargetPtr
EventInserter(const Fsm &source, Fsm &target)
typename Diades::Utils::Ptr< _Fsm >::ConstP SourcePtr
virtual EI::EventMap::iterator generateEvent(typename EI::EventId evt)
std::unordered_map< EventId, EventId > EventMap
Namespace of the Diades project.
ManagedEventInserter(const Fsm &source, Fsm &target, const EM &sourceManager, EM &targetManager)
virtual EventMap::iterator generateEvent(EventId evt)
EventInserter & operator=(EventInserter const &other)=default