+const char Switch::DEFAULT_NODE_NAME[]="default";
+const int Switch::ID_FOR_DEFAULT_NODE=-1973012217;
+const char Switch::SELECTOR_INPUTPORT_NAME[]="select";
+
+int CollectorSwOutPort::edGetNumberOfOutLinks() const
+{
+ return 1;
+}
+
+std::set<InPort *> CollectorSwOutPort::edSetInPort() const
+{
+ set<InPort *> ret;
+ if(_consumer)
+ ret.insert(_consumer);
+ return ret;
+}
+
+bool CollectorSwOutPort::isAlreadyLinkedWith(InPort *with) const
+{
+ set<InPort *> s;
+ with->getAllRepresentants(s);
+ return s.find(_consumer)!=s.end();
+}
+
+std::string CollectorSwOutPort::getNameOfTypeOfCurrentInstance() const
+{
+ return _className;
+}
+
+void CollectorSwOutPort::edRemoveAllLinksLinkedWithMe()
+{
+ map<int, OutPort *>::iterator pt;
+ if(_consumer)
+ for(pt=_potentialProducers.begin();pt!=_potentialProducers.end();pt++)
+ ((*pt).second)->removeInPort(_consumer,true);
+}
+
+TypeOfChannel CollectorSwOutPort::getTypeOfChannel() const
+{
+ return (*(_potentialProducers.begin())).second->getTypeOfChannel();
+}
+
+void CollectorSwOutPort::getAllRepresented(std::set<OutPort *>& represented) const
+{
+ map<int, OutPort *>::const_iterator pt;
+ for(pt=_potentialProducers.begin();pt!=_potentialProducers.end();pt++)
+ ((*pt).second)->getAllRepresented(represented);
+}
+
+bool CollectorSwOutPort::addInPort(InPort *inPort)
+{
+ bool ret = false;
+ if(_currentProducer)
+ {//a specific link is beeing done
+ ret=_currentProducer->addInPort(inPort);
+ _currentProducer=0;
+ }
+ else//global links asked
+ for(map<int, OutPort *>::iterator iter=_potentialProducers.begin();iter!=_potentialProducers.end();iter++)
+ ret |= (*iter).second->addInPort(inPort);
+ return ret;
+}
+
+int CollectorSwOutPort::removeInPort(InPort *inPort, bool forward)
+{
+ if(_currentProducer)
+ {
+ return _currentProducer->removeInPort(inPort,forward);
+ }
+ else
+ throw Exception("CollectorSwOutputPort::edRemoveInputPort : internal error on link removal.");
+ _currentProducer=0;
+}
+
+/*!
+ * \note : 'master' specifies the instance of Switch of which 'this' collects all of these direct
+ * or indirect outports going to the same port 'port' (which is out of scope of 'master').
+ */
+CollectorSwOutPort::CollectorSwOutPort(Switch *master, InPort *port):OutPort("",master,port->edGetType()),
+ DataPort("",master,port->edGetType()),
+ Port(master),
+ _consumer(port),_currentProducer(0)
+{
+ _name="Representant_of_";
+ _name+=master->getName();
+ _name+="_for_inport_";
+ _name+=port->getName();
+}
+
+CollectorSwOutPort::CollectorSwOutPort(const CollectorSwOutPort& other, Switch *master):OutPort("",master,other.edGetType()),
+ DataPort("",master,other.edGetType()),
+ Port(master),
+ _consumer(0),_currentProducer(0)
+{
+ _name=other._name;
+ Switch *othSw=(Switch *)other._node;
+ for(map<int, OutPort *>::const_iterator iter=other._potentialProducers.begin();iter!=other._potentialProducers.end();iter++)
+ {
+ string name=othSw->getOutPortName((*iter).second);
+ _potentialProducers[(*iter).first]=master->getOutPort(name);
+ }
+}
+
+void CollectorSwOutPort::addPotentialProducerForMaster(OutPort *port)
+{
+ int i=((Switch *)_node)->getRankOfNode(port->getNode());
+ map<int, OutPort *>::iterator pt=_potentialProducers.find(i);
+ if(pt==_potentialProducers.end())
+ {
+ _potentialProducers[i]=port;
+ _currentProducer=port;
+ }
+ else
+ {
+ _currentProducer=(*pt).second;
+ if(_currentProducer!=port)
+ {
+ string what("CollectorSwOutPort::addPotentialProducerForMaster : In switch node "); what+=_node->getName();
+ what+=" for input named \'"; what+=_consumer->getName(); what+="\' the output "; what+=_currentProducer->getName();
+ what+=" already got out for case of label ";
+ what+=Switch::getRepresentationOfCase((*pt).first);
+ throw Exception(what);
+ }
+ }
+ _className=port->getNameOfTypeOfCurrentInstance();
+}
+
+bool CollectorSwOutPort::removePotentialProducerForMaster()
+{
+ int i;
+ map<int, OutPort *>::iterator result;
+ for(result=_potentialProducers.begin();result!=_potentialProducers.end();result++)
+ if((*result).second==_currentProducer)
+ {
+ i=(*result).first;
+ break;
+ }
+ if(result==_potentialProducers.end())
+ {
+ ostringstream stream; stream << "CollectorSwOutPort::removePotentialProducerForMaster : link from the branch whith id ";
+ stream << i << " not defined";
+ throw Exception(stream.str());
+ }
+ if((*result).second!=_currentProducer)
+ {
+ ostringstream stream; stream << "CollectorSwOutPort::removePotentialProducerForMaster : link from the branch whith id ";
+ stream << i << " defined but the output specified is not compatible";
+ throw Exception(stream.str());
+ }
+ _potentialProducers.erase(result);
+ return _potentialProducers.empty();
+}
+
+bool CollectorSwOutPort::checkManagementOfPort(OutPort *port)
+{
+ for(map<int, OutPort *>::iterator iter=_potentialProducers.begin();iter!=_potentialProducers.end();iter++)
+ if((*iter).second==port)
+ {
+ _currentProducer=port;
+ return _potentialProducers.size()==1;
+ }
+ throw Exception("CollectorSwOutPort::checkManagementOfPort : unexported port");
+}
+
+/*!
+ * Called by Switch::checkCFLinks.
+ */
+void CollectorSwOutPort::checkConsistency(LinkInfo& info) const
+{
+ if(((Switch *)_node)->getNbOfCases()!=_potentialProducers.size())
+ info.pushErrSwitch((CollectorSwOutPort *)this);
+ for(map<int, OutPort *>::const_iterator iter=_potentialProducers.begin();iter!=_potentialProducers.end();iter++)
+ (*iter).second->checkConsistency(info);
+}
+
+/*!
+ * Called by LinkInfo::getErrRepr to have a comprehensible message on throw.
+ * When called, typically checkCompletenessOfCases has detected that some potential producers were laking...
+ */
+void CollectorSwOutPort::getHumanReprOfIncompleteCases(std::ostream& stream) const
+{
+ set<int> lackingCases;
+ for(map< int ,Node * >::const_iterator iter=((Switch *)_node)->_mapOfNode.begin();iter!=((Switch *)_node)->_mapOfNode.end();iter++)
+ {
+ if(_potentialProducers.find((*iter).first)==_potentialProducers.end())
+ lackingCases.insert((*iter).first);
+ }
+ ostringstream streamForExc;
+ stream << "For link to " << _consumer->getName() << " of node " << _consumer->getNode()->getName()
+ << " the cases of switch node named " << _node->getName()
+ << " do not define links for following cases ids :";
+ for(set<int>::iterator iter=lackingCases.begin();iter!=lackingCases.end();iter++)
+ stream << Switch::getRepresentationOfCase(*iter) << " ";
+ stream << endl;
+}
+
+FakeNodeForSwitch::FakeNodeForSwitch(Switch *sw, bool normalFinish, bool internalError):ElementaryNode("thisIsAFakeNode"),
+ _sw(sw),
+ _normalFinish(normalFinish),
+ _internalError(internalError)
+{
+ _state=YACS::TOACTIVATE;
+ _father=_sw->getFather();
+}
+
+FakeNodeForSwitch::FakeNodeForSwitch(const FakeNodeForSwitch& other):ElementaryNode(other),_sw(0),
+ _normalFinish(false),
+ _internalError(true)
+{
+}
+
+Node *FakeNodeForSwitch::simpleClone(ComposedNode *father, bool editionOnly) const
+{
+ return new FakeNodeForSwitch(*this);
+}
+
+void FakeNodeForSwitch::exForwardFailed()
+{
+ _sw->exForwardFailed();
+}
+
+void FakeNodeForSwitch::exForwardFinished()
+{
+ _sw->exForwardFinished();
+}
+
+void FakeNodeForSwitch::execute()
+{
+ if(!_normalFinish)
+ throw Exception("");//only to trigger ABORT on Executor
+}
+
+void FakeNodeForSwitch::aborted()
+{
+ if(_internalError)
+ _sw->_state!=YACS::INTERNALERR;
+ else
+ _sw->setState(YACS::ERROR);
+}
+
+void FakeNodeForSwitch::finished()
+{
+ _sw->setState(YACS::DONE);
+}
+
+/*! \class YACS::ENGINE::Switch
+ * \brief Control node that emulates the C switch
+ *
+ * \ingroup Nodes
+ */
+
+Switch::Switch(const Switch& other, ComposedNode *father, bool editionOnly):StaticDefinedComposedNode(other,father),_condition(other._condition,this),
+ _undispatchableNotificationNode(0)
+{
+ for(map<int,Node *>::const_iterator iter=other._mapOfNode.begin();iter!=other._mapOfNode.end();iter++)
+ _mapOfNode[(*iter).first]=(*iter).second->clone(this,editionOnly);
+ if(!editionOnly)
+ for(map<InPort *, CollectorSwOutPort * >::const_iterator iter2=other._outPortsCollector.begin();iter2!=other._outPortsCollector.end();iter2++)
+ {
+ CollectorSwOutPort *newCol=new CollectorSwOutPort(*((*iter2).second),this);
+ _alreadyExistingCollectors.push_back(newCol);
+ }
+}
+
+Switch::Switch(const std::string& name):StaticDefinedComposedNode(name),_condition(SELECTOR_INPUTPORT_NAME,this,Runtime::_tc_int),_undispatchableNotificationNode(0)