1 // Copyright (C) 2006-2021 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
23 #include "YACSlibEngineExport.hxx"
24 #include "StaticDefinedComposedNode.hxx"
25 #include "InputDataStreamPort.hxx"
26 #include "ElementaryNode.hxx"
27 #include "OutputPort.hxx"
28 #include "InputPort.hxx"
34 void YACSLIBENGINE_EXPORT NbDoneLoader(Loop* node, int val);
41 class YACSLIBENGINE_EXPORT InputPort4DF2DS : public InputPort
44 InputPort4DF2DS(DFToDSForLoop *node, TypeCode* type);
45 void getAllRepresentants(std::set<InPort *>& repr) const;
46 void releaseData() override;
47 void put(const void *data);
48 InputPort *clone(Node *newHelder) const;
58 class DFToDSForLoop : public ElementaryNode
63 Loop *_loopArtificiallyBuiltMe;
65 DFToDSForLoop(Loop *loop, const std::string& name, TypeCode* type);
66 void loopHasOneMoreRef() { _nbOfTimeUsed++; }
67 bool loopHasOneLessRef() { return --_nbOfTimeUsed==0; }
68 void getReadyTasks(std::vector<Task *>& tasks);
69 InputPort *getInputPort(const std::string& name) const ;
70 OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const ;
71 Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
79 class YACSLIBENGINE_EXPORT OutputPort4DS2DF : public OutputPort
82 OutputPort4DS2DF(DSToDFForLoop *node, TypeCode *type);
83 void getAllRepresented(std::set<OutPort *>& represented) const;
84 void put(const void *data);
85 OutputPort *clone(Node *newHelder) const;
92 class YACSLIBENGINE_EXPORT InputDataStreamPort4DS2DF : public InputDataStreamPort
95 InputDataStreamPort4DS2DF(DSToDFForLoop *node, TypeCode* type);
96 void getAllRepresentants(std::set<InPort *>& repr) const;
99 class DSToDFForLoop : public ElementaryNode
104 Loop *_loopArtificiallyBuiltMe;
106 DSToDFForLoop(Loop *loop, const std::string& name, TypeCode* type);
107 Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
108 void loopHasOneMoreRef() { _nbOfTimeUsed++; }
109 bool loopHasOneLessRef() { return --_nbOfTimeUsed==0; }
110 void getReadyTasks(std::vector<Task *>& tasks);
111 OutputPort *getOutputPort(const std::string& name) const ;
112 InputDataStreamPort *getInputDataStreamPort(const std::string& name) const ;
120 class FakeNodeForLoop : public ElementaryNode
122 friend class ForLoop;
123 friend class WhileLoop;
129 FakeNodeForLoop(Loop *loop, bool normalFinish, bool internalError=false);
130 FakeNodeForLoop(const FakeNodeForLoop& other);
131 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
132 void exForwardFailed();
133 void exForwardFinished();
139 /*! \brief Base class for loop node
146 class YACSLIBENGINE_EXPORT Loop : public StaticDefinedComposedNode
148 friend class DSToDFForLoop;
149 friend class FakeNodeForLoop;
150 friend void NbDoneLoader(Loop* node, int val);
154 FakeNodeForLoop *_nodeForNullTurnOfLoops;
155 std::set<DSToDFForLoop *> _inputsTraducer;
156 std::set<DFToDSForLoop *> _outputsTraducer;
158 Loop(const Loop& other, ComposedNode *father, bool editionOnly);
159 Loop(const std::string& name);
161 void init(bool start=true);
162 int getNbOfTurns() const { return _nbOfTurns; }
163 //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
164 Node *edSetNode(Node *DISOWNnode);
165 virtual bool edAddChild(Node *DISOWNnode) ;
166 bool isLoop() const override { return true; }
167 Node *edRemoveNode();
168 virtual void checkBasicConsistency() const ;
169 //! Returns the port which value is used to take decision about the continuation of the loop.
170 virtual InputPort *getDecisionPort() const = 0;
171 void getReadyTasks(std::vector<Task *>& tasks);
172 void edRemoveChild(Node *node) ;
173 bool isRepeatedUnpredictablySeveralTimes() const { return true; }
174 std::list<Node *> edGetDirectDescendants() const;
175 std::list<InputPort *> getSetOfInputPort() const;
176 int getNumberOfInputPorts() const;
177 int getMaxLevelOfParallelism() const;
178 void getWeightRegardingDPL(ComplexWeight *weight);
179 void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap);
180 Node *getChildByShortName(const std::string& name) const ;
181 static TypeCode* MappingDF2DS(TypeCode* type) ;
182 static TypeCode* MappingDS2DF(TypeCode* type) ;
183 virtual bool edAddDFLink(OutPort *start, InPort *end) ;
184 void writeDot(std::ostream &os) const;
185 virtual void accept(Visitor *visitor);
186 virtual std::string typeName() {return "YACS__ENGINE__Loop";}
188 void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
189 void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
190 void getDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView) ;
191 void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) ;
192 void releaseDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView) ;
193 void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) ;
194 void checkNoCyclePassingThrough(Node *node) ;
195 void checkControlDependancy(OutPort *start, InPort *end, bool cross,
196 std::map < ComposedNode *, std::list < OutPort * >, SortHierarc >& fw,
197 std::vector<OutPort *>& fwCross,
198 std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
199 LinkInfo& info) const;
200 void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
201 static bool isNecessaryToBuildSpecificDelegateDF2DS(const std::list<ComposedNode *>& pointsOfView);