1 // Copyright (C) 2006-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "Visitor.hxx"
22 #include "LinkInfo.hxx"
29 #include "YacsTrace.hxx"
31 using namespace YACS::ENGINE;
34 const char Switch::DEFAULT_NODE_NAME[]="default";
35 const int Switch::ID_FOR_DEFAULT_NODE=-1973012217;
36 const char Switch::SELECTOR_INPUTPORT_NAME[]="select";
38 int CollectorSwOutPort::edGetNumberOfOutLinks() const
43 std::set<InPort *> CollectorSwOutPort::edSetInPort() const
47 ret.insert(_consumer);
51 bool CollectorSwOutPort::isAlreadyLinkedWith(InPort *with) const
54 with->getAllRepresentants(s);
55 return s.find(_consumer)!=s.end();
58 std::string CollectorSwOutPort::getNameOfTypeOfCurrentInstance() const
63 void CollectorSwOutPort::edRemoveAllLinksLinkedWithMe() throw(YACS::Exception)
65 map<int, OutPort *>::iterator pt;
67 for(pt=_potentialProducers.begin();pt!=_potentialProducers.end();pt++)
68 ((*pt).second)->removeInPort(_consumer,true);
71 TypeOfChannel CollectorSwOutPort::getTypeOfChannel() const
73 return (*(_potentialProducers.begin())).second->getTypeOfChannel();
76 void CollectorSwOutPort::getAllRepresented(std::set<OutPort *>& represented) const
78 map<int, OutPort *>::const_iterator pt;
79 for(pt=_potentialProducers.begin();pt!=_potentialProducers.end();pt++)
80 ((*pt).second)->getAllRepresented(represented);
83 bool CollectorSwOutPort::addInPort(InPort *inPort) throw(YACS::Exception)
86 {//a specific link is beeing done
87 bool ret=_currentProducer->addInPort(inPort);
91 else//global links asked
92 for(map<int, OutPort *>::iterator iter=_potentialProducers.begin();iter!=_potentialProducers.end();iter++)
93 (*iter).second->addInPort(inPort);
96 int CollectorSwOutPort::removeInPort(InPort *inPort, bool forward) throw(YACS::Exception)
100 return _currentProducer->removeInPort(inPort,forward);
103 throw Exception("CollectorSwOutputPort::edRemoveInputPort : internal error on link removal.");
108 * \note : 'master' specifies the instance of Switch of which 'this' collects all of these direct
109 * or indirect outports going to the same port 'port' (which is out of scope of 'master').
111 CollectorSwOutPort::CollectorSwOutPort(Switch *master, InPort *port):OutPort("",master,port->edGetType()),
112 DataPort("",master,port->edGetType()),
114 _consumer(port),_currentProducer(0)
116 _name="Representant_of_"; _name+=master->getName(); _name+="_for_inport_"; _name+=master->getRootNode()->getInPortName(_consumer);
119 CollectorSwOutPort::CollectorSwOutPort(const CollectorSwOutPort& other, Switch *master):OutPort("",master,other.edGetType()),
120 DataPort("",master,other.edGetType()),
122 _consumer(0),_currentProducer(0)
125 Switch *othSw=(Switch *)other._node;
126 for(map<int, OutPort *>::const_iterator iter=other._potentialProducers.begin();iter!=other._potentialProducers.end();iter++)
128 string name=othSw->getOutPortName((*iter).second);
129 _potentialProducers[(*iter).first]=master->getOutPort(name);
133 void CollectorSwOutPort::addPotentialProducerForMaster(OutPort *port)
135 int i=((Switch *)_node)->getRankOfNode(port->getNode());
136 map<int, OutPort *>::iterator pt=_potentialProducers.find(i);
137 if(pt==_potentialProducers.end())
139 _potentialProducers[i]=port;
140 _currentProducer=port;
144 _currentProducer=(*pt).second;
145 if(_currentProducer!=port)
147 string what("CollectorSwOutPort::addPotentialProducerForMaster : In switch node "); what+=_node->getName();
148 what+=" for input named \'"; what+=_consumer->getName(); what+="\' the output "; what+=_currentProducer->getName();
149 what+=" already got out for case of label ";
150 what+=Switch::getRepresentationOfCase((*pt).first);
151 throw Exception(what);
154 _className=port->getNameOfTypeOfCurrentInstance();
157 bool CollectorSwOutPort::removePotentialProducerForMaster()
160 map<int, OutPort *>::iterator result;
161 for(result=_potentialProducers.begin();result!=_potentialProducers.end();result++)
162 if((*result).second==_currentProducer)
167 if(result==_potentialProducers.end())
169 ostringstream stream; stream << "CollectorSwOutPort::removePotentialProducerForMaster : link from the branch whith id ";
170 stream << i << " not defined";
171 throw Exception(stream.str());
173 if((*result).second!=_currentProducer)
175 ostringstream stream; stream << "CollectorSwOutPort::removePotentialProducerForMaster : link from the branch whith id ";
176 stream << i << " defined but the output specified is not compatible";
177 throw Exception(stream.str());
179 _potentialProducers.erase(result);
180 return _potentialProducers.empty();
183 bool CollectorSwOutPort::checkManagementOfPort(OutPort *port) throw(YACS::Exception)
185 for(map<int, OutPort *>::iterator iter=_potentialProducers.begin();iter!=_potentialProducers.end();iter++)
186 if((*iter).second==port)
188 _currentProducer=port;
189 return _potentialProducers.size()==1;
191 throw Exception("CollectorSwOutPort::checkManagementOfPort : unexported port");
195 * Called by Switch::checkCFLinks.
197 void CollectorSwOutPort::checkConsistency(LinkInfo& info) const
199 if(((Switch *)_node)->getNbOfCases()!=_potentialProducers.size())
200 info.pushErrSwitch((CollectorSwOutPort *)this);
201 for(map<int, OutPort *>::const_iterator iter=_potentialProducers.begin();iter!=_potentialProducers.end();iter++)
202 (*iter).second->checkConsistency(info);
206 * Called by LinkInfo::getErrRepr to have a comprehensible message on throw.
207 * When called, typically checkCompletenessOfCases has detected that some potential producers were laking...
209 void CollectorSwOutPort::getHumanReprOfIncompleteCases(std::ostream& stream) const
211 set<int> lackingCases;
212 for(map< int ,Node * >::const_iterator iter=((Switch *)_node)->_mapOfNode.begin();iter!=((Switch *)_node)->_mapOfNode.end();iter++)
214 if(_potentialProducers.find((*iter).first)==_potentialProducers.end())
215 lackingCases.insert((*iter).first);
217 ostringstream streamForExc;
218 stream << "For link to " << _consumer->getName() << " of node " << _consumer->getNode()->getName()
219 << " the cases of switch node named " << _node->getName()
220 << " do not define links for following cases ids :";
221 for(set<int>::iterator iter=lackingCases.begin();iter!=lackingCases.end();iter++)
222 stream << Switch::getRepresentationOfCase(*iter) << " ";
226 FakeNodeForSwitch::FakeNodeForSwitch(Switch *sw, bool normalFinish, bool internalError):ElementaryNode("thisIsAFakeNode"),
228 _normalFinish(normalFinish),
229 _internalError(internalError)
231 _state=YACS::TOACTIVATE;
232 _father=_sw->getFather();
235 FakeNodeForSwitch::FakeNodeForSwitch(const FakeNodeForSwitch& other):ElementaryNode(other),_sw(0),
236 _normalFinish(false),
241 Node *FakeNodeForSwitch::simpleClone(ComposedNode *father, bool editionOnly) const
243 return new FakeNodeForSwitch(*this);
246 void FakeNodeForSwitch::exForwardFailed()
248 _sw->exForwardFailed();
251 void FakeNodeForSwitch::exForwardFinished()
253 _sw->exForwardFinished();
256 void FakeNodeForSwitch::execute()
259 throw Exception("");//only to trigger ABORT on Executor
262 void FakeNodeForSwitch::aborted()
265 _sw->_state!=YACS::INTERNALERR;
267 _sw->setState(YACS::ERROR);
270 void FakeNodeForSwitch::finished()
272 _sw->setState(YACS::DONE);
275 /*! \class YACS::ENGINE::Switch
276 * \brief Control node that emulates the C switch
281 Switch::Switch(const Switch& other, ComposedNode *father, bool editionOnly):StaticDefinedComposedNode(other,father),_condition(other._condition,this),
282 _undispatchableNotificationNode(0)
284 for(map<int,Node *>::const_iterator iter=other._mapOfNode.begin();iter!=other._mapOfNode.end();iter++)
285 _mapOfNode[(*iter).first]=(*iter).second->clone(this,editionOnly);
287 for(map<InPort *, CollectorSwOutPort * >::const_iterator iter2=other._outPortsCollector.begin();iter2!=other._outPortsCollector.end();iter2++)
289 CollectorSwOutPort *newCol=new CollectorSwOutPort(*((*iter2).second),this);
290 _alreadyExistingCollectors.push_back(newCol);
294 Switch::Switch(const std::string& name):StaticDefinedComposedNode(name),_condition(SELECTOR_INPUTPORT_NAME,this,Runtime::_tc_int),_undispatchableNotificationNode(0)
300 if(_undispatchableNotificationNode)delete _undispatchableNotificationNode;
302 for(map< int , Node * >::iterator iter=_mapOfNode.begin();iter!=_mapOfNode.end();iter++)
303 delete (*iter).second;
304 for(map<InPort *, CollectorSwOutPort * >::iterator iter2=_outPortsCollector.begin();iter2!=_outPortsCollector.end();iter2++)
305 delete (*iter2).second;
306 for(vector<CollectorSwOutPort *>::iterator iter3=_alreadyExistingCollectors.begin();iter3!=_alreadyExistingCollectors.end();iter3++)
310 Node *Switch::simpleClone(ComposedNode *father, bool editionOnly) const
312 return new Switch(*this,father,editionOnly);
315 void Switch::exUpdateState()
317 DEBTRACE("Switch::exUpdateState " << _state);
318 if(_state == YACS::DISABLED)
320 if(_inGate.exIsReady())
322 setState(YACS::ACTIVATED);
323 if(_condition.isEmpty())
324 _undispatchableNotificationNode=new FakeNodeForSwitch(this,false,true);
327 map< int , Node * >::iterator iter=_mapOfNode.find(_condition.getIntValue());
328 if(iter==_mapOfNode.end())
330 iter=_mapOfNode.find(ID_FOR_DEFAULT_NODE);
331 if(iter==_mapOfNode.end())
333 bool normalFinish=getAllOutPortsLeavingCurrentScope().empty();
334 delete _undispatchableNotificationNode;
335 _undispatchableNotificationNode=new FakeNodeForSwitch(this,normalFinish);
338 ((*iter).second)->exUpdateState();
341 ((*iter).second)->exUpdateState();
346 void Switch::init(bool start)
348 DEBTRACE("Switch::init " << start);
349 StaticDefinedComposedNode::init(start);
351 for(map< int , Node * >::iterator iter=_mapOfNode.begin();iter!=_mapOfNode.end();iter++, i++)
355 ostringstream stream;
356 stream << "Switch::init : initialization failed due to unitialized branch of id " << (*iter).first;
357 throw Exception(stream.str());
359 ((*iter).second)->init(start);
363 void Switch::getReadyTasks(std::vector<Task *>& tasks)
366 * To change the way ComposedNode state is handled, uncomment the following line
367 * see Bloc::getReadyTasks
369 if(_state==YACS::TOACTIVATE) setState(YACS::ACTIVATED);
370 if(_state==YACS::TOACTIVATE || _state==YACS::ACTIVATED)
372 map< int , Node * >::iterator iter=_mapOfNode.find(_condition.getIntValue());
373 if(iter!=_mapOfNode.end())
374 ((*iter).second)->getReadyTasks(tasks);
377 iter=_mapOfNode.find(ID_FOR_DEFAULT_NODE);
378 if(iter!=_mapOfNode.end())
379 (*iter).second->getReadyTasks(tasks);//Default Node is returned
381 if(_undispatchableNotificationNode)
382 _undispatchableNotificationNode->getReadyTasks(tasks);
384 throw Exception("Switch::getReadyTasks : internal error");
389 list<Node *> Switch::edGetDirectDescendants() const
392 for(map< int , Node * >::const_iterator iter=_mapOfNode.begin();iter!=_mapOfNode.end();iter++)
394 ret.push_back((*iter).second);
398 int Switch::getNumberOfInputPorts() const
400 return StaticDefinedComposedNode::getNumberOfInputPorts()+1;
403 int Switch::getMaxLevelOfParallelism() const
406 for(std::map< int , Node * >::const_iterator it=_mapOfNode.begin();it!=_mapOfNode.end();it++)
407 ret=std::max(ret,((*it).second)->getMaxLevelOfParallelism());
411 void Switch::edRemoveChild(Node *node) throw(YACS::Exception)
413 map< int , Node * >::iterator iter=_mapOfNode.begin();
414 for(;iter!=_mapOfNode.end();iter++)
415 if(node==(*iter).second)
417 edReleaseCase((*iter).first);
420 ostringstream what; what << "Switch::edRemoveChild : node with name " << node->getName() << " is not a direct child of Switch node " << _name;
421 throw Exception(what.str());
424 std::list<InputPort *> Switch::getSetOfInputPort() const
426 list<InputPort *> ret=StaticDefinedComposedNode::getSetOfInputPort();
427 ret.push_back((InputPort *)&_condition);
432 std::list<InputPort *> Switch::getLocalInputPorts() const
434 list<InputPort *> ret=StaticDefinedComposedNode::getLocalInputPorts();
435 ret.push_back((InputPort *)&_condition);
438 OutPort *Switch::getOutPort(const std::string& name) const throw(YACS::Exception)
440 for(map<InPort *, CollectorSwOutPort * >::const_iterator iter=_outPortsCollector.begin();iter!=_outPortsCollector.end();iter++)
441 if(name==(*iter).second->getName())
442 return (*iter).second;
443 for(vector<CollectorSwOutPort *>::const_iterator iter2=_alreadyExistingCollectors.begin();iter2!=_alreadyExistingCollectors.end();iter2++)
444 if(name==(*iter2)->getName())
446 return StaticDefinedComposedNode::getOutPort(name);
449 InputPort *Switch::getInputPort(const std::string& name) const throw(YACS::Exception)
451 if(name==SELECTOR_INPUTPORT_NAME)
452 return (InputPort *)&_condition;
453 return StaticDefinedComposedNode::getInputPort(name);
456 Node *Switch::getChildByShortName(const std::string& name) const throw(YACS::Exception)
458 if(name==DEFAULT_NODE_NAME)
460 map< int , Node * >::const_iterator iter=_mapOfNode.find(ID_FOR_DEFAULT_NODE);
461 if(iter!=_mapOfNode.end())
462 return (Node *)((*iter).second);
465 string what("Switch::getChildByShortName : no default node defined for switch of name "); what+=getName();
466 throw Exception(what);
469 for(map< int , Node * >::const_iterator iter=_mapOfNode.begin();iter!=_mapOfNode.end();iter++)
471 if(name==((*iter).second)->getQualifiedName())
472 return (*iter).second;
474 string what("node "); what+= name ; what+=" is not a child of node switch "; what += getName();
475 throw Exception(what);
478 Node *Switch::edSetDefaultNode(Node *node)
480 return edSetNode(ID_FOR_DEFAULT_NODE,node);
483 Node *Switch::edReleaseDefaultNode() throw(YACS::Exception)
485 return edReleaseCase(ID_FOR_DEFAULT_NODE);
488 Node *Switch::edReleaseCase(int caseId) throw(YACS::Exception)
490 map< int , Node * >::iterator iter=_mapOfNode.find(caseId);
491 if(iter==_mapOfNode.end())
493 string what("Switch::edReleaseCase : the case # "); what+=getRepresentationOfCase(caseId); what+=" is not set yet.";
494 throw Exception(what);
498 Node *ret=(*iter).second;
499 StaticDefinedComposedNode::edRemoveChild(ret);
500 _mapOfNode.erase(iter);
506 Node *Switch::edGetNode(int caseId)
508 if (!_mapOfNode.count(caseId)) return 0;
509 return _mapOfNode[caseId];
514 * \param caseId : the case ID chosen to place 'node'
515 * \param node : the node for the specified 'caseId'
516 * \return : If an old node with id equal to 'caseId' exists before, this old node is returned so that to be deallocated.
517 * 0 is returned if caseId is a new ID.
518 * \b WARNING : 'node' is held by 'this' after call, whereas returned node is no more held.
520 Node *Switch::edSetNode(int caseId, Node *node) throw(YACS::Exception)
523 throw Exception("Switch::edSetNode : null node cannot be set as a case in switch node");
525 throw Exception("Switch::edSetNode : node already held by another father");
526 checkNoCrossHierachyWith(node);
528 map< int , Node * >::iterator iter=_mapOfNode.find(caseId);
529 if(iter==_mapOfNode.end())
531 _mapOfNode[caseId]=node;
537 if(node!=(*iter).second)
539 Node *ret=(*iter).second;
547 //! Change the case of a node
549 * \param oldCase : the case value to change
550 * \param newCase : the new value to set
551 * raise an exception if the old case does not exist or if the new case already exists
553 void Switch::edChangeCase(int oldCase, int newCase)
555 std::map< int , Node * >::iterator iter=_mapOfNode.find(oldCase);
556 if(iter==_mapOfNode.end())
558 //the case does not exists
559 throw Exception("Switch::edChangeCase : case does not exist");
561 iter=_mapOfNode.find(newCase);
562 if(iter != _mapOfNode.end())
564 //the new case exists
565 throw Exception("Switch::edChangeCase : new case exists");
567 Node* node=_mapOfNode[oldCase];
568 _mapOfNode.erase(oldCase);
569 _mapOfNode[newCase]=node;
573 int Switch::getMaxCase()
576 map<int, Node*>::const_iterator it = _mapOfNode.begin();
577 for(; it != _mapOfNode.end(); ++it)
578 if ((*it).first > aCase)
583 //! Get the progress weight of the graph
585 * Only elementary nodes have weight. If the switch node is not done, we add the weight of all his descendants,
586 * otherwise only the weight of the used case count.
588 list<ProgressWeight> Switch::getProgressWeight() const
590 list<ProgressWeight> ret;
591 list<Node *> setOfNode=edGetDirectDescendants();
592 if (getState() == YACS::DONE)
594 for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
596 if (getEffectiveState(*iter) == YACS::DONE)
597 ret=(*iter)->getProgressWeight();
602 for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
604 list<ProgressWeight> myCurrentSet=(*iter)->getProgressWeight();
605 ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
611 bool Switch::edAddChild(Node *node) throw(YACS::Exception)
613 int aCase = getMaxCase() + 1;
615 bool ret = edSetNode(aCase, node);
620 YACS::Event Switch::updateStateOnFinishedEventFrom(Node *node)
622 setState(YACS::DONE);
623 return YACS::FINISH;//notify to father node that 'this' has becomed finished.
626 std::set<InPort *> Switch::getAllInPortsComingFromOutsideOfCurrentScope() const
628 set<InPort *> ret=StaticDefinedComposedNode::getAllInPortsComingFromOutsideOfCurrentScope();
629 set<OutPort *> temp2=_condition.edSetOutPort();
630 for(set<OutPort *>::iterator iter3=temp2.begin();iter3!=temp2.end();iter3++)
631 if(!isInMyDescendance((*iter3)->getNode()))
633 ret.insert((InPort *)&_condition);
639 void Switch::checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const
641 map<InPort *, CollectorSwOutPort * >::const_iterator iter=_outPortsCollector.find(end);
642 if(iter!=_outPortsCollector.end())
644 set<OutPort *> represented;
645 (*iter).second->getAllRepresented(represented);
646 list<OutPort *> others;
647 for(list<OutPort *>::const_iterator iter2=starts.begin();iter2!=starts.end();iter2++)
648 if(represented.find(*iter2)==represented.end())
649 others.push_back(*iter2);
653 StaticDefinedComposedNode::checkCFLinks(others,end,alreadyFed,direction,info);//should never happend;
656 StaticDefinedComposedNode::checkCFLinks(starts,end,alreadyFed,direction,info);
659 void Switch::checkControlDependancy(OutPort *start, InPort *end, bool cross,
660 std::map < ComposedNode *, std::list < OutPort * > >& fw,
661 std::vector<OutPort *>& fwCross,
662 std::map< ComposedNode *, std::list < OutPort *> >& bw,
663 LinkInfo& info) const
665 throw Exception("Switch::checkControlDependancy : a link was dectected between 2 cases of a switch. Impossible !");
668 void Switch::checkNoCyclePassingThrough(Node *node) throw(YACS::Exception)
670 throw Exception("Switch::checkNoCyclePassingThrough : uncorrect control flow link relative to switch");
673 void Switch::checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
674 InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(YACS::Exception)
676 throw Exception("Switch::checkLinkPossibility : A link between 2 different cases of a same Switch requested -> Impossible");
679 void Switch::buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView)
681 map<InPort *, CollectorSwOutPort * >::iterator result=_outPortsCollector.find(finalTarget);
682 CollectorSwOutPort *newCollector;
683 if(result!=_outPortsCollector.end())
684 newCollector=(*result).second;
687 newCollector=new CollectorSwOutPort(this,finalTarget);
688 newCollector->edSetType((port.first)->edGetType());
689 _outPortsCollector[finalTarget]=newCollector;
691 newCollector->addPotentialProducerForMaster(port.first);
692 port.second=newCollector;
693 port.first=newCollector;
696 void Switch::getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(YACS::Exception)
698 map<InPort *, CollectorSwOutPort * >::iterator iter=_outPortsCollector.find(finalTarget);
699 if(iter==_outPortsCollector.end())
701 string what("Switch::getDelegateOf : not exported OuputPort with name "); what+=(port.first)->getName(); what+=" for target inport of name ";
702 what+=finalTarget->getName();
703 throw Exception(what);
705 ((*iter).second)->checkManagementOfPort(port.first);
706 port.second=(*iter).second;
707 port.first=(*iter).second;
710 void Switch::releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(YACS::Exception)
713 portDwn->getAllRepresented(repr);
716 CollectorSwOutPort *portCasted=dynamic_cast<CollectorSwOutPort *>(portUp);
717 if(portCasted->removePotentialProducerForMaster())//normally always true
720 _outPortsCollector.erase(finalTarget);
725 int Switch::getNbOfCases() const
727 return _mapOfNode.size();
730 int Switch::getRankOfNode(Node *node) const
732 Node *directSon=isInMyDescendance(node);
733 for(map< int , Node * >::const_iterator iter=_mapOfNode.begin();iter!=_mapOfNode.end();iter++)
734 if((*iter).second==directSon)
735 return (*iter).first;
736 throw Exception("Switch::getRankOfNode : node not in switch");
739 string Switch::getRepresentationOfCase(int i)
741 if(i!=ID_FOR_DEFAULT_NODE)
743 ostringstream stream;
748 return DEFAULT_NODE_NAME;
751 //! Return the effective state of a node in the context of this switch (its father)
753 * \param node: the node which effective state is queried
754 * \return the effective node state
756 YACS::StatesForNode Switch::getEffectiveState(const Node* node) const
758 YACS::StatesForNode effectiveState=Node::getEffectiveState();
759 if(effectiveState==YACS::READY)
761 if(effectiveState==YACS::TOACTIVATE)
763 if(effectiveState==YACS::DISABLED)
764 return YACS::DISABLED;
766 return node->getState();
768 YACS::StatesForNode Switch::getEffectiveState() const
770 return Node::getEffectiveState();
773 void Switch::writeDot(std::ostream &os) const
775 os << " subgraph cluster_" << getId() << " {\n" ;
776 for(map<int,Node*>::const_iterator iter=_mapOfNode.begin();iter!=_mapOfNode.end();iter++)
778 Node* n=(*iter).second;
780 os << getId() << " -> " << n->getId() << ";\n";
783 os << getId() << "[fillcolor=\"" ;
784 YACS::StatesForNode state=Node::getEffectiveState();
785 os << getColorState(state);
786 os << "\" label=\"" << "Switch:" ;
787 os << getQualifiedName() <<"\"];\n";
790 std::string Switch::getMyQualifiedName(const Node *directSon) const
792 string id=getCaseId(directSon);
793 id+=directSon->getName();
797 std::string Switch::getCaseId(const Node *node) const throw(YACS::Exception)
800 map<int, Node*>::const_iterator iter;
801 for (iter = _mapOfNode.begin(); iter != _mapOfNode.end(); iter++)
802 if (iter->second == node)
805 if (iter->first == Switch::ID_FOR_DEFAULT_NODE)
806 a << DEFAULT_NODE_NAME << sep;
807 else if (iter->first <0)
808 a << "m" << -iter->first << sep;
809 else a << "p" << iter->first << sep;
812 string what("node "); what+= node->getName() ; what+=" is not a child of node "; what += getName();
813 throw Exception(what);
816 void Switch::accept(Visitor *visitor)
818 visitor->visitSwitch(this);