Salome HOME
Bug correction EDF12462 (2)
[modules/yacs.git] / src / engine / ForEachLoop.hxx
index 7648f89e85aab207d759c30c7775e65e926e9087..efb9888fb4e6bb2df5b175198a7a2f7e4151d039 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2006-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2015  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -123,6 +123,28 @@ namespace YACS
       static const char NAME[];
     };
 
+    class YACSLIBENGINE_EXPORT ForEachLoopPassedData
+    {
+    public:
+      ForEachLoopPassedData(const std::vector<unsigned int>& passedIds, const std::vector<SequenceAny *>& passedOutputs, const std::vector<std::string>& nameOfOutputs);
+      ~ForEachLoopPassedData();
+      void init();
+      void checkCompatibilyWithNb(int nbOfElts) const;
+      void checkLevel2(const std::vector<AnyInputPort *>& ports) const;
+      int getNumberOfEltsAlreadyDone() const { return (int)_passedIds.size(); }
+      int toAbsId(int localId) const;
+      int toAbsIdNot(int localId) const;
+      int getNumberOfElementsToDo() const;
+      void assignAlreadyDone(const std::vector<SequenceAny *>& execVals) const;
+    private:
+      std::vector<unsigned int> _passedIds;
+      std::vector<SequenceAny *> _passedOutputs;
+      std::vector<std::string> _nameOfOutputs;
+      mutable std::vector<bool> _flagsIds;
+    };
+
+    class Executor;
+
     class YACSLIBENGINE_EXPORT ForEachLoop : public DynParaLoop
     {
       friend class SplitterNode;
@@ -142,6 +164,7 @@ namespace YACS
       unsigned _execCurrentId;
       std::vector<SequenceAny *> _execVals;
       std::vector< std::vector<AnyInputPort *> > _execOutGoingPorts;
+      ForEachLoopPassedData *_passedData;
     public:
       ForEachLoop(const std::string& name, TypeCode *typeOfDataSplitted);
       ForEachLoop(const ForEachLoop& other, ComposedNode *father, bool editionOnly);
@@ -169,11 +192,22 @@ namespace YACS
       virtual std::string typeName() {return "YACS__ENGINE__ForEachLoop";}
       virtual void resetState(int level);
       std::string getProgress() const;
+      std::list<ProgressWeight> getProgressWeight() const;
+      int getCurrentIndex() const { return _currentIndex; }
+      int getNbOfElementsToBeProcessed() const;
+#ifndef SWIG
+      std::vector<unsigned int> getPassedResults(Executor *execut, std::vector<SequenceAny *>& outputs, std::vector<std::string>& nameOfOutputs) const;
+      void assignPassedResults(const std::vector<unsigned int>& passedIds, const std::vector<SequenceAny *>& passedOutputs, const std::vector<std::string>& nameOfOutputs);
+#endif
     protected:
       Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
       void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
                                 InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
       YACS::Event updateStateOnFinishedEventFrom(Node *node);
+      YACS::Event updateStateForInitNodeOnFinishedEventFrom(Node *node, unsigned int id);
+      YACS::Event updateStateForWorkNodeOnFinishedEventFrom(Node *node, unsigned int id, bool isNormalFinish);
+      YACS::Event updateStateForFinalizeNodeOnFinishedEventFrom(Node *node, unsigned int id);
+      YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
       void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
       void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
       void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
@@ -184,6 +218,11 @@ namespace YACS
       void prepareSequenceValues(int sizeOfSamples);
       OutPort *getDynOutPortByAbsName(int branchNb, const std::string& name);
       void storeOutValsInSeqForOutOfScopeUse(int rank, int branchNb);
+    private:
+      int getFinishedId();
+    public:
+      static void InterceptorizeNameOfPort(std::string& portName);
+      static const char INTERCEPTOR_STR[];
     };
   }
 }