35 using namespace YACS::ENGINE;
61 Port(other,newHelder),
69 for(set<InPort *>::iterator iter=ports.begin();iter!=ports.end();iter++)
70 (*iter)->getAllRepresentants(repr);
95 _repr(0),_intercptr(0),_cnt(1)
101 Port(other,newHelder),
102 _repr(0),_intercptr(0),_cnt(1)
110 _repr->addInPort(_intercptr);
126 if(_setOfInputPort.empty())
127 _repr->removeInPort(_intercptr,forward);
159 if (valCsted)
return valCsted->
size();
173 stringstream xmldump;
175 xmldump <<
"<value><array><data>" << endl;
176 for (
int i = 0;
i < nbElem;
i++)
182 xmldump <<
"<value><double>" << setprecision(16) << val->
getDoubleValue() <<
"</double></value>" << endl;
185 xmldump <<
"<value><int>" << val->
getIntValue() <<
"</int></value>" << endl;
188 xmldump <<
"<value><boolean>" << val->
getBoolValue() <<
"</boolean></value>" << endl;
191 xmldump <<
"<value><string>" << val->
getStringValue() <<
"</string></value>" << endl;
194 xmldump <<
"<value><objref>" << val->
getStringValue() <<
"</objref></value>" << endl;
197 xmldump <<
"<value><error> NO_SERIALISATION_AVAILABLE </error></value>" << endl;
201 xmldump <<
"</data></array></value>" << endl;
202 return xmldump.str();
207 _dataPortToDispatch(NAME_OF_SEQUENCE_INPUT,
214 _dataPortToDispatch(other._dataPortToDispatch,this)
220 if(name==NAME_OF_SEQUENCE_INPUT)
221 return (
InputPort *)&_dataPortToDispatch;
257 _normalFinish(normalFinish)
301 ForEachLoopPassedData::ForEachLoopPassedData(
const std::vector<unsigned int>& passedIds,
const std::vector<SequenceAny *>& passedOutputs,
const std::vector<std::string>& nameOfOutputs):_passedIds(passedIds),_passedOutputs(passedOutputs),_nameOfOutputs(nameOfOutputs)
303 std::size_t sz(
_passedIds.size()),sz1(passedOutputs.size()),sz2(nameOfOutputs.size());
305 throw YACS::Exception(
"ForEachLoopPassedData::ForEachLoopPassedData : nameOfOutputs and passedOutputs must have the same size !");
310 if(sz!=(std::size_t)elt->
size())
311 throw YACS::Exception(
"ForEachLoopPassedData::ForEachLoopPassedData : incoherent input of passed data !");
322 : _passedIds(copy._passedIds),
323 _passedOutputs(copy._passedOutputs),
324 _nameOfOutputs(copy._nameOfOutputs),
325 _flagsIds(copy._flagsIds)
347 throw YACS::Exception(
"ForEachLoopPassedData::checkCompatibilyWithNb : nb of elts is expected to be > 0 !");
348 std::size_t sizeExp(
_passedIds.size()),nbOfElts2(nbOfElts);
349 if(nbOfElts2<sizeExp)
350 throw YACS::Exception(
"ForEachLoopPassedData::checkCompatibilyWithNb : Invalid nb of elemts in input seq regarding passed data set !");
354 throw YACS::Exception(
"ForEachLoopPassedData::checkCompatibilyWithNb : Invalid nb of elemts in input seq regarding passed data set 2 !");
366 std::ostringstream oss; oss <<
"ForEachLoopPassedData::checkCompatibilyWithNb : id " << *it <<
" in list of ids appears more than once !";
372 std::ostringstream oss; oss <<
"ForEachLoopPassedData::checkCompatibilyWithNb : Presence of id " << *it <<
" in list of ids ! Must be in [0," << nbOfElts <<
") !";
382 throw YACS::Exception(
"ForEachLoopPassedData::checkLevel2 : mismatch of size of vectors !");
383 for(std::size_t
i=0;
i<sz;
i++)
387 throw YACS::Exception(
"ForEachLoopPassedData::checkLevel2 : presence of null instance !");
390 std::ostringstream oss; oss <<
"ForEachLoopPassedData::checkLevel2 : At pos #" << i <<
" the name is not OK !";
402 throw YACS::Exception(
"ForEachLoopPassedData::toAbsId : local pos must be >= 0 !");
403 int ret(0),curLocId(0);
408 if(localId==curLocId)
413 throw YACS::Exception(
"ForEachLoopPassedData::toAbsId : not referenced Id !");
422 throw YACS::Exception(
"ForEachLoopPassedData::toAbsIdNot : local pos must be >= 0 !");
423 int ret(0),curLocId(0);
428 if(localId==curLocId)
433 throw YACS::Exception(
"ForEachLoopPassedData::toAbsIdNot : not referenced Id !");
445 std::size_t sz(execVals.size());
447 throw YACS::Exception(
"ForEachLoopPassedData::assignedAlreadyDone : mismatch of size of vectors !");
448 for(std::size_t
i=0;
i<sz;
i++)
453 throw YACS::Exception(
"ForEachLoopPassedData::assignedAlreadyDone : presence of null elt !");
454 unsigned int szOfElt(elt->
size());
455 for(
unsigned int j=0;j<szOfElt;j++)
465 _splitterNode(NAME_OF_SPLITTERNODE,typeOfDataSplitted,this),
466 _execCurrentId(0),_nodeForSpecialCases(0),_currentIndex(0),_passedData(0)
471 _splitterNode(other._splitterNode,this),
472 _execCurrentId(0),_nodeForSpecialCases(0),_currentIndex(0),_passedData(0)
516 DEBTRACE(
"ForEachLoop::exUpdateState");
531 int nbOfEltsToDo(nbOfElts-nbOfEltsDone);
551 if(nbOfBr>nbOfEltsToDo)
563 vector<Node *> origNodes;
565 origNodes.push_back(
_node);
572 for(i=0;i<nbOfBr;i++)
587 for(i=0;i<nbOfBr;i++)
607 DEBTRACE(
"ForEachLoop::exUpdateState: " << ex.
what() );
616 for(i=0;i<nbOfBr;i++)
650 vector<Node *>::iterator iter;
652 (*iter)->getReadyTasks(tasks);
654 (*iter)->getReadyTasks(tasks);
656 (*iter)->getReadyTasks(tasks);
691 return (
InputPort *)&_splitterNode._dataPortToDispatch;
698 for(vector<AnySplitOutputPort *>::const_iterator iter=_outGoingPorts.begin();iter!=_outGoingPorts.end();iter++)
700 if(name==(*iter)->getName())
708 for(vector<AnySplitOutputPort *>::const_iterator iter=_outGoingPorts.begin();iter!=_outGoingPorts.end();iter++)
710 if(name==(*iter)->getName())
718 if(name==NAME_OF_SPLITTERNODE)
719 return (
Node *)&_splitterNode;
796 std::ostringstream oss; oss <<
"Keep Going mode activated and some errors (" <<
_failedCounter <<
")reported !";
797 DEBTRACE(
"ForEachLoop::updateStateOnFinishedEventFrom : "<< oss.str());
811 std::list<Node *>::iterator iter=aChldn.begin();
812 for(;iter!=aChldn.end();iter++)
830 DEBTRACE(
"Launching finalize node for branch " <<
i);
839 DEBTRACE(
"ForEachLoop::updateStateOnFinishedEventFrom: "<<ex.
what());
870 DEBTRACE(
"Finalize node finished on branch " <<
id);
901 std::replace_if(portName.begin(), portName.end(), std::bind1st(std::equal_to<char>(),
'.'),
'_');
908 string typeOfPortInstance=(port.first)->getNameOfTypeOfCurrentInstance();
911 vector<AnySplitOutputPort *>::iterator iter=
_outGoingPorts.begin();
914 if((*iter)->getRepr()==port.first || *iter==port.first)
918 if(*iter!=port.first)
933 std::string outputPortName(
getPortName(port.first));
939 newPort->
addRepr(port.first,intercptor);
946 throw Exception(
"ForEachLoop::buildDelegateOf : not implemented for DS because not specified");
951 string typeOfPortInstance=(port.first)->getNameOfTypeOfCurrentInstance();
954 vector<AnySplitOutputPort *>::iterator iter=_outGoingPorts.begin();
955 for(;iter!=_outGoingPorts.end();iter++)
956 if((*iter)->getRepr()==port.first)
958 if(iter==_outGoingPorts.end())
960 string what(
"ForEachLoop::getDelegateOf : Port with name "); what+=port.first->getName(); what+=
" not exported by ForEachLoop "; what+=_name;
967 throw Exception(
"ForEachLoop::getDelegateOf : not implemented because not specified");
972 string typeOfPortInstance=portDwn->getNameOfTypeOfCurrentInstance();
975 vector<AnySplitOutputPort *>::iterator iter=_outGoingPorts.begin();
976 vector<InterceptorInputPort *>::iterator iter2=_intecptrsForOutGoingPorts.begin();
977 for(;iter!=_outGoingPorts.end();iter++,iter2++)
978 if((*iter)->getRepr()==portDwn)
981 if((*iter)->decrRef())
984 _outGoingPorts.erase(iter);
987 _intecptrsForOutGoingPorts.erase(iter2);
995 string portName, nodeName;
998 return _execNodes[branchNb]->getOutPort(portName);
1005 for(vector< SequenceAny *>::iterator iter3=
_execVals.begin();iter3!=
_execVals.end();iter3++)
1006 (*iter3)->decrRef();
1009 for(vector<AnyInputPort *>::iterator iter5=(*iter4).begin();iter5!=(*iter4).end();iter5++)
1016 vector<AnyInputPort *>::iterator iter;
1020 Any *val=(
Any *)(*iter)->getValue();
1036 vector<AnySplitOutputPort *>::iterator iter=
_outGoingPorts.begin();
1043 vector<AnySplitOutputPort *>::iterator iter=
_outGoingPorts.begin();
1046 (*iter)->put((
const void *)
_execVals[i]);
1051 vector<AnySplitOutputPort *>::iterator iter=
_outGoingPorts.begin();
1055 DEBTRACE( (*iter)->getName() <<
" " << (*iter)->edGetType()->kind() );
1061 portOut->addInPort(interceptor);
1070 if(end->getNode() == &_splitterNode)
1071 throw Exception(
"Illegal link within a foreach loop: \
1072 the 'SmplsCollection' port cannot be linked within the scope of the loop.");
1073 if(end == &_nbOfBranches)
1074 throw Exception(
"Illegal link within a foreach loop: \
1075 the 'nbBranches' port cannot be linked within the scope of the loop.");
1080 list<OutputPort *>
ret;
1096 os <<
" subgraph cluster_" <<
getId() <<
" {\n" ;
1104 os <<
getId() <<
"[fillcolor=\"" ;
1107 os <<
"\" label=\"" <<
"Loop:" ;
1124 std::stringstream aProgress;
1129 return aProgress.str();
1139 list<ProgressWeight>
ret;
1143 for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
1145 list<ProgressWeight> myCurrentSet=(*iter)->getProgressWeight();
1146 for(list<ProgressWeight>::iterator iter=myCurrentSet.begin();iter!=myCurrentSet.end();iter++)
1148 (*iter).weightDone=((*iter).weightTotal) * elemDone;
1149 (*iter).weightTotal*=elemTotal;
1151 ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
1182 return std::vector<unsigned int>();
1184 return std::vector<unsigned int>();
1187 nameOfOutputs.resize(sz);
1189 for(std::size_t
i=0;
i<sz;
i++)
1191 outputs[
i]=
_execVals[
i]->removeUnsetItemsFromThis();
1192 nameOfOutputs[
i]=ports[
i]->getName();
1201 void ForEachLoop::assignPassedResults(
const std::vector<unsigned int>& passedIds,
const std::vector<SequenceAny *>& passedOutputs,
const std::vector<std::string>& nameOfOutputs)
1216 ForEachLoop *isFE(dynamic_cast<ForEachLoop *>(work));
1221 if(dynamic_cast<AnySplitOutputPort *>(start))
1232 std::vector<SequenceAny *> outputs;
1233 std::vector<std::string> nameOfOutputs;
1238 nameOfOutputs.resize(sz);
1240 for(std::size_t
i=0;
i<sz;
i++)
1242 outputs[
i]=
_execVals[
i]->removeUnsetItemsFromThis();
1243 nameOfOutputs[
i]=ports[
i]->getName();
1261 vector<AnySplitOutputPort *>::const_iterator it;
1266 DEBTRACE(
"ForEachLoop::getOutputPortType compare " << portName <<
" == " << originalPortName);
1267 if(originalPortName == portName)