Version: 8.3.0
YACS::ENGINE::ForEachLoopPassedData Class Reference

#include <ForEachLoop.hxx>

Collaboration diagram for YACS::ENGINE::ForEachLoopPassedData:

Public Member Functions

 ForEachLoopPassedData (const std::vector< unsigned int > &passedIds, const std::vector< SequenceAny * > &passedOutputs, const std::vector< std::string > &nameOfOutputs)
 
 ForEachLoopPassedData (const ForEachLoopPassedData &copy)
 
 ~ForEachLoopPassedData ()
 
void init ()
 
void checkCompatibilyWithNb (int nbOfElts) const
 
void checkLevel2 (const std::vector< AnyInputPort * > &ports) const
 
int getNumberOfEltsAlreadyDone () const
 
int toAbsId (int localId) const
 
int toAbsIdNot (int localId) const
 
int getNumberOfElementsToDo () const
 
void assignAlreadyDone (const std::vector< SequenceAny * > &execVals) const
 
const std::vector< unsigned int > & getIds () const
 
const std::vector< SequenceAny * > & getOutputs () const
 
const std::vector< std::string > & getOutputNames () const
 

Private Attributes

std::vector< unsigned int > _passedIds
 
std::vector< SequenceAny * > _passedOutputs
 
std::vector< std::string > _nameOfOutputs
 
std::vector< bool > _flagsIds
 

Detailed Description

Definition at line 126 of file ForEachLoop.hxx.

Constructor & Destructor Documentation

ForEachLoopPassedData::ForEachLoopPassedData ( const std::vector< unsigned int > &  passedIds,
const std::vector< SequenceAny * > &  passedOutputs,
const std::vector< std::string > &  nameOfOutputs 
)

Definition at line 301 of file ForEachLoop.cxx.

References _passedIds, _passedOutputs, YACS::ENGINE::RefCounter::incrRef(), and YACS::ENGINE::SequenceAny::size().

301  :_passedIds(passedIds),_passedOutputs(passedOutputs),_nameOfOutputs(nameOfOutputs)
302 {
303  std::size_t sz(_passedIds.size()),sz1(passedOutputs.size()),sz2(nameOfOutputs.size());
304  if(sz1!=sz2)
305  throw YACS::Exception("ForEachLoopPassedData::ForEachLoopPassedData : nameOfOutputs and passedOutputs must have the same size !");
306  for(std::vector<SequenceAny *>::iterator it=_passedOutputs.begin();it!=_passedOutputs.end();it++)
307  {
308  const SequenceAny *elt(*it);
309  if(elt)
310  if(sz!=(std::size_t)elt->size())
311  throw YACS::Exception("ForEachLoopPassedData::ForEachLoopPassedData : incoherent input of passed data !");
312  }
313  for(std::vector<SequenceAny *>::iterator it=_passedOutputs.begin();it!=_passedOutputs.end();it++)
314  {
315  SequenceAny *elt(*it);
316  if(elt)
317  elt->incrRef();
318  }
319 }
ForEachLoopPassedData::ForEachLoopPassedData ( const ForEachLoopPassedData copy)

Definition at line 321 of file ForEachLoop.cxx.

322 : _passedIds(copy._passedIds),
325  _flagsIds(copy._flagsIds)
326 {
327 }
ForEachLoopPassedData::~ForEachLoopPassedData ( )

Definition at line 329 of file ForEachLoop.cxx.

References _passedOutputs, and YACS::ENGINE::RefCounter::decrRef().

330 {
331  for(std::vector<SequenceAny *>::iterator it=_passedOutputs.begin();it!=_passedOutputs.end();it++)
332  {
333  SequenceAny *elt(*it);
334  if(elt)
335  elt->decrRef();
336  }
337 }

Member Function Documentation

void ForEachLoopPassedData::assignAlreadyDone ( const std::vector< SequenceAny * > &  execVals) const

Definition at line 443 of file ForEachLoop.cxx.

References _passedOutputs, CORBAEngineTest::i, YACS::ENGINE::SequenceAny::setEltAtRank(), YACS::ENGINE::SequenceAny::size(), and toAbsIdNot().

Referenced by YACS::ENGINE::ForEachLoop::exUpdateState().

444 {
445  std::size_t sz(execVals.size());
446  if(_passedOutputs.size()!=sz)
447  throw YACS::Exception("ForEachLoopPassedData::assignedAlreadyDone : mismatch of size of vectors !");
448  for(std::size_t i=0;i<sz;i++)
449  {
451  SequenceAny *eltDestination(execVals[i]);
452  if(!elt)
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++)
456  {
457  AnyPtr elt1((*elt)[j]);
458  int jAbs(toAbsIdNot(j));
459  eltDestination->setEltAtRank(jAbs,elt1);
460  }
461  }
462 }
void ForEachLoopPassedData::checkCompatibilyWithNb ( int  nbOfElts) const

Definition at line 344 of file ForEachLoop.cxx.

References _flagsIds, and _passedIds.

Referenced by YACS::ENGINE::ForEachLoop::exUpdateState().

345 {
346  if(nbOfElts<0)
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 !");
351  for(std::vector<unsigned int>::const_iterator it=_passedIds.begin();it!=_passedIds.end();it++)
352  {
353  if((*it)>=nbOfElts2)
354  throw YACS::Exception("ForEachLoopPassedData::checkCompatibilyWithNb : Invalid nb of elemts in input seq regarding passed data set 2 !");
355  }
356  _flagsIds.resize(nbOfElts);
357  std::fill(_flagsIds.begin(),_flagsIds.end(),false);
358  for(std::vector<unsigned int>::const_iterator it=_passedIds.begin();it!=_passedIds.end();it++)
359  {
360  if(*it<nbOfElts)
361  {
362  if(!_flagsIds[*it])
363  _flagsIds[*it]=true;
364  else
365  {
366  std::ostringstream oss; oss << "ForEachLoopPassedData::checkCompatibilyWithNb : id " << *it << " in list of ids appears more than once !";
367  throw YACS::Exception(oss.str());
368  }
369  }
370  else
371  {
372  std::ostringstream oss; oss << "ForEachLoopPassedData::checkCompatibilyWithNb : Presence of id " << *it << " in list of ids ! Must be in [0," << nbOfElts << ") !";
373  throw YACS::Exception(oss.str());
374  }
375  }
376 }
void ForEachLoopPassedData::checkLevel2 ( const std::vector< AnyInputPort * > &  ports) const

Definition at line 378 of file ForEachLoop.cxx.

References _nameOfOutputs, YACS::ENGINE::DataPort::getName(), and CORBAEngineTest::i.

Referenced by YACS::ENGINE::ForEachLoop::exUpdateState().

379 {
380  std::size_t sz(_nameOfOutputs.size());
381  if(sz!=ports.size())
382  throw YACS::Exception("ForEachLoopPassedData::checkLevel2 : mismatch of size of vectors !");
383  for(std::size_t i=0;i<sz;i++)
384  {
385  AnyInputPort *elt(ports[i]);
386  if(!elt)
387  throw YACS::Exception("ForEachLoopPassedData::checkLevel2 : presence of null instance !");
388  if(_nameOfOutputs[i]!=elt->getName())
389  {
390  std::ostringstream oss; oss << "ForEachLoopPassedData::checkLevel2 : At pos #" << i << " the name is not OK !";
391  throw YACS::Exception(oss.str());
392  }
393  }
394 }
const std::vector<unsigned int>& YACS::ENGINE::ForEachLoopPassedData::getIds ( ) const
inline

Definition at line 140 of file ForEachLoop.hxx.

Referenced by YACS::ENGINE::VisitorSalomeSaveState::visitForEachLoop().

140 {return _passedIds;}
int ForEachLoopPassedData::getNumberOfElementsToDo ( ) const

Definition at line 436 of file ForEachLoop.cxx.

References _flagsIds, _passedIds, and PMMLBasicsTestLauncher::ret.

Referenced by YACS::ENGINE::ForEachLoop::getFinishedId().

437 {
438  std::size_t nbAllElts(_flagsIds.size());
439  std::size_t ret(nbAllElts-_passedIds.size());
440  return ret;
441 }
int YACS::ENGINE::ForEachLoopPassedData::getNumberOfEltsAlreadyDone ( ) const
inline

Definition at line 135 of file ForEachLoop.hxx.

Referenced by YACS::ENGINE::ForEachLoop::exUpdateState().

135 { return (int)_passedIds.size(); }
const std::vector<std::string>& YACS::ENGINE::ForEachLoopPassedData::getOutputNames ( ) const
inline

Definition at line 142 of file ForEachLoop.hxx.

Referenced by YACS::ENGINE::VisitorSalomeSaveState::visitForEachLoop().

142 {return _nameOfOutputs;}
const std::vector<SequenceAny *>& YACS::ENGINE::ForEachLoopPassedData::getOutputs ( ) const
inline

Definition at line 141 of file ForEachLoop.hxx.

Referenced by YACS::ENGINE::VisitorSalomeSaveState::visitForEachLoop().

141 {return _passedOutputs;}
void ForEachLoopPassedData::init ( )

Definition at line 339 of file ForEachLoop.cxx.

References _flagsIds.

Referenced by YACS::ENGINE::ForEachLoop::init().

340 {
341  _flagsIds.clear();
342 }
int ForEachLoopPassedData::toAbsId ( int  localId) const

performs local to abs id. Input localId refers to an id in all jobs to perform. Returned id refers to pos in whole output sequences.

Definition at line 399 of file ForEachLoop.cxx.

References _flagsIds, and PMMLBasicsTestLauncher::ret.

Referenced by YACS::ENGINE::ForEachLoop::exUpdateState(), and YACS::ENGINE::ForEachLoop::updateStateForWorkNodeOnFinishedEventFrom().

400 {
401  if(localId<0)
402  throw YACS::Exception("ForEachLoopPassedData::toAbsId : local pos must be >= 0 !");
403  int ret(0),curLocId(0);
404  for(std::vector<bool>::const_iterator it=_flagsIds.begin();it!=_flagsIds.end();it++,ret++)
405  {
406  if(!*it)
407  {
408  if(localId==curLocId)
409  return ret;
410  curLocId++;
411  }
412  }
413  throw YACS::Exception("ForEachLoopPassedData::toAbsId : not referenced Id !");
414 }
int ForEachLoopPassedData::toAbsIdNot ( int  localId) const

Equivalent to toAbsId except that only ON are considered here.

Definition at line 419 of file ForEachLoop.cxx.

References _flagsIds, and PMMLBasicsTestLauncher::ret.

Referenced by assignAlreadyDone().

420 {
421  if(localId<0)
422  throw YACS::Exception("ForEachLoopPassedData::toAbsIdNot : local pos must be >= 0 !");
423  int ret(0),curLocId(0);
424  for(std::vector<bool>::const_iterator it=_flagsIds.begin();it!=_flagsIds.end();it++,ret++)
425  {
426  if(*it)//<- diff is here !
427  {
428  if(localId==curLocId)
429  return ret;
430  curLocId++;
431  }
432  }
433  throw YACS::Exception("ForEachLoopPassedData::toAbsIdNot : not referenced Id !");
434 }

Member Data Documentation

std::vector<bool> YACS::ENGINE::ForEachLoopPassedData::_flagsIds
mutableprivate
std::vector<std::string> YACS::ENGINE::ForEachLoopPassedData::_nameOfOutputs
private

Definition at line 147 of file ForEachLoop.hxx.

Referenced by checkLevel2().

std::vector<unsigned int> YACS::ENGINE::ForEachLoopPassedData::_passedIds
private
std::vector<SequenceAny *> YACS::ENGINE::ForEachLoopPassedData::_passedOutputs
private

The documentation for this class was generated from the following files: