8 #ifndef __DIADES__AUTOMATA__EXPERIMENTAL__SYNCHRONISATIONEVENT__HH__ 9 #define __DIADES__AUTOMATA__EXPERIMENTAL__SYNCHRONISATIONEVENT__HH__ 22 namespace Experimental
45 template<
typename StateMachine>
53 return "Automata::Experimental::SynchronisationEvent";
72 using Size =
typename ComponentVector::size_type;
118 Size index) : _pVect(pVect), _pEvent(pEvent), _index(index)
134 return *(_pVect->operator[](_index));
142 return(_pVect->operator[](_index));
169 return(_pVect == compIt.
_pVect) && (_pEvent == compIt.
_pEvent)
170 && (_index == compIt.
_index);
178 return !(*
this == compIt);
187 return(*_pEvent)[_index];
281 require(
Exception, !components.empty(),
"constructor: empty set of components");
282 std::set<const Component *> sortedComponents;
283 bool null = components.empty();
285 while((!null) && (index != components.size()))
287 null = (components[index] ==
nullptr);
288 require(
Exception, !null,
"constructor: one pointer in the set of components is null");
291 null = sortedComponents.find(components[index]) != sortedComponents.end();
294 require(
Exception, !null,
"constructor: the set of components contains twice the same component");
295 sortedComponents.insert(components[index]);
302 std::for_each(components.begin(), components.end(),
305 _components.push_back(comp);
306 _events.push_back(comp->nullEvent());
337 null = &(*it1) == &(*it2);
338 require(
Exception, !null,
"merging constructor: sync1 and sync2 contains the same component");
341 if(&(*it1) < &(*it2))
343 _components.push_back(&(*it1));
345 if(_events.back().isValid())
347 _support.push_back(_components.back());
348 _supportEvents.push_back(_events.back());
354 _components.push_back(&(*it2));
356 if(_events.back().isValid())
358 _support.push_back(_components.back());
359 _supportEvents.push_back(_events.back());
371 _components.push_back(&(*it2));
373 if(_events.back().isValid())
375 _support.push_back(_components.back());
376 _supportEvents.push_back(_events.back());
387 _components.push_back(&(*it1));
389 if(_events.back().isValid())
391 _support.push_back(_components.back());
392 _supportEvents.push_back(_events.back());
403 _supportEvents.clear();
406 ensure(
Exception, isValid(),
"merging constructor: it should be valid but it is not.");
425 require(
Exception, !components.empty(),
"constructor: empty set of components");
426 std::set<const Component *> sortedComponents;
427 bool null = components.empty();
429 while((!null) && (index != components.size()))
431 null = (components[index] == 0);
432 require(
Exception, !null,
"constructor: one pointer in the set of components is null");
435 null = sortedComponents.find(components[index]) != sortedComponents.end();
438 require(
Exception, !null,
"constructor: the set of components contains twice the same component");
439 sortedComponents.insert(components[index]);
446 std::for_each(components.begin(), components.end(),
449 _components.push_back(comp);
450 _events.push_back(comp->nullEvent());
479 return !(*
this == evt);
488 return _components.size();
497 return _support.size();
507 bool result = (_components.size() == _events.size())
508 && (_support.size() == _supportEvents.size())
509 && (_support.size() <= _components.size());
513 map<const Component *, Size> theSupport;
515 while(result && index < _components.size())
517 result = _components[index] != 0
518 && _components[index]->isValid();
521 if(_events[index].isValid())
523 result = _components[index]->containsEvent(_events[index]);
524 theSupport[_components[index]] = index;
530 result = _support.size() == theSupport.size();
531 while(result && index < _support.size())
534 result = _support[index] != 0
535 && _support[index]->isValid();
538 map<const Component *, Size>::const_iterator it = theSupport.find(_support[index]);
539 result = (it != theSupport.end())
540 && _supportEvents[index].isValid()
541 && _support[index]->containsEvent(_supportEvents[index])
542 && (_support[index] == _components[it->second])
543 && (_events[it->second] == _supportEvents[index]);
567 require(
Exception, it != endOfComponents(),
"addEvent: the component does not belong to the SynchronisationEvent");
568 if(it != endOfComponents())
570 if(e != getAssociatedEvent(it))
572 if(getAssociatedEvent(it) ==
NullEvent().nullValue())
574 _support.push_back(&component);
575 _supportEvents.push_back(e);
583 _supportEvents[itSupp.
index()] = e;
588 while(index < (_support.size() - 1))
590 _support[index] = _support[index + 1];
591 _supportEvents[index] = _supportEvents[index + 1];
594 _supportEvents.resize(_supportEvents.size() - 1);
595 _support.resize(_support.size() - 1);
598 _events[it.index()] = e;
601 ensure(
Exception, isValid(),
"addEvent: the result should be valid but it is not.");
657 require(
Exception, findComponent(comp) != endOfComponents(),
"getAssociatedEvent: the component does not exist in the synchronisation event");
659 if(it == endOfComponents())
663 return getAssociatedEvent(it);
676 while((!found) && (it != endOfComponents()))
697 while((!found) && (it != endOfSupport()))
717 return _synchronisedEvent;
727 _synchronisedEvent = evt;
734 template<
typename _SyncEvent>
745 _numberOfSynchronisationEventsToEncode(numberOfSynchronisationEventsToEncode)
EventVector _supportEvents
static std::string typeName()
static ConstP get(const T &obj)
std::vector< Event > EventVector
SynchronisationEvent(const SynchronisationEvent &sync1, const SynchronisationEvent &sync2)
const Component & operator*() const
const EventVector * _pEvent
Event getAssociatedEvent() const
ComponentIterator findSupportComponent(const Component &component) const
ComponentIterator(const ComponentVector *pVect, const EventVector *pEvent, Size index)
const ComponentVector * _pVect
typename ComponentVector::size_type Size
void setSynchronisedEvent(Event evt)
typename StateMachine::NullEventPropertyId NullEvent
#define ensure(Exception, expr, message)
bool containsEvent(const EventPropertyId &e) const
bool operator!=(const SynchronisationEvent &evt) const
ComponentVector _components
typename SyncEvent::Event Event
const Component * operator->() const
Event getAssociatedEvent(const ComponentIterator &it) const
bool operator==(const ComponentIterator &compIt) const
SynchronisationEventEncoder(size_t numberOfSynchronisationEventsToEncode)
ComponentIterator beginOfSupport() const
SynchronisationEvent(const SynchronisationEvent &sync, const ComponentVector &components)
ComponentIterator beginOfComponents() const
ComponentIterator & operator++()
DdAutFsm::EventPropertyId Event
std::vector< const Component * > ComponentVector
Event getAssociatedEvent(const Component &comp) const
ComponentIterator findComponent(const Component &component) const
ComponentIterator addEvent(const Component &component, Event e)
SynchronisationEvent(const ComponentVector &components)
#define require(Exception, expr, message)
Event synchronisedEvent() const
Namespace of the Diades project.
_NullEventPropertyId NullEventPropertyId
_EventPropertyId EventPropertyId
typename Component::EventPropertyId Event
size_t _numberOfSynchronisationEventsToEncode
ComponentIterator(const ComponentIterator &it)
std::input_iterator_tag iterator_category
ComponentIterator operator++(int)
ComponentIterator endOfComponents() const
bool operator==(const SynchronisationEvent &evt) const
ComponentIterator endOfSupport() const
typename Ptr< Component >::P pointer
bool operator!=(const ComponentIterator &compIt) const