1 // Copyright (C) 2006-2013 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.
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 put(const void *data) throw(ConversionException);
47 InputPort *clone(Node *newHelder) const;
48 void *get() const throw(Exception);
57 class DFToDSForLoop : public ElementaryNode
62 Loop *_loopArtificiallyBuiltMe;
64 DFToDSForLoop(Loop *loop, const std::string& name, TypeCode* type);
65 void loopHasOneMoreRef() { _nbOfTimeUsed++; }
66 bool loopHasOneLessRef() { return --_nbOfTimeUsed==0; }
67 void getReadyTasks(std::vector<Task *>& tasks);
68 InputPort *getInputPort(const std::string& name) const throw(Exception);
69 OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const throw(Exception);
70 Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
78 class YACSLIBENGINE_EXPORT OutputPort4DS2DF : public OutputPort
81 OutputPort4DS2DF(DSToDFForLoop *node, TypeCode *type);
82 void getAllRepresented(std::set<OutPort *>& represented) const;
83 void put(const void *data) throw(ConversionException);
84 OutputPort *clone(Node *newHelder) const;
91 class YACSLIBENGINE_EXPORT InputDataStreamPort4DS2DF : public InputDataStreamPort
94 InputDataStreamPort4DS2DF(DSToDFForLoop *node, TypeCode* type);
95 void getAllRepresentants(std::set<InPort *>& repr) const;
98 class DSToDFForLoop : public ElementaryNode
103 Loop *_loopArtificiallyBuiltMe;
105 DSToDFForLoop(Loop *loop, const std::string& name, TypeCode* type);
106 Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
107 void loopHasOneMoreRef() { _nbOfTimeUsed++; }
108 bool loopHasOneLessRef() { return --_nbOfTimeUsed==0; }
109 void getReadyTasks(std::vector<Task *>& tasks);
110 OutputPort *getOutputPort(const std::string& name) const throw(Exception);
111 InputDataStreamPort *getInputDataStreamPort(const std::string& name) const throw(Exception);
119 class FakeNodeForLoop : public ElementaryNode
121 friend class ForLoop;
122 friend class WhileLoop;
128 FakeNodeForLoop(Loop *loop, bool normalFinish, bool internalError=false);
129 FakeNodeForLoop(const FakeNodeForLoop& other);
130 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
131 void exForwardFailed();
132 void exForwardFinished();
138 /*! \brief Base class for loop node
145 class YACSLIBENGINE_EXPORT Loop : public StaticDefinedComposedNode
147 friend class DSToDFForLoop;
148 friend class FakeNodeForLoop;
149 friend void NbDoneLoader(Loop* node, int val);
153 FakeNodeForLoop *_nodeForNullTurnOfLoops;
154 std::set<DSToDFForLoop *> _inputsTraducer;
155 std::set<DFToDSForLoop *> _outputsTraducer;
157 Loop(const Loop& other, ComposedNode *father, bool editionOnly);
158 Loop(const std::string& name);
160 void init(bool start=true);
161 int getNbOfTurns() const { return _nbOfTurns; }
162 //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
163 Node *edSetNode(Node *DISOWNnode);
164 virtual bool edAddChild(Node *DISOWNnode) throw(Exception);
165 Node *edRemoveNode();
166 virtual void checkBasicConsistency() const throw(Exception);
167 //! Returns the port which value is used to take decision about the continuation of the loop.
168 virtual InputPort *getDecisionPort() const = 0;
169 void getReadyTasks(std::vector<Task *>& tasks);
170 void edRemoveChild(Node *node) throw(Exception);
171 bool isRepeatedUnpredictablySeveralTimes() const { return true; }
172 void selectRunnableTasks(std::vector<Task *>& tasks);
173 std::list<Node *> edGetDirectDescendants() const;
174 std::list<InputPort *> getSetOfInputPort() const;
175 int getNumberOfInputPorts() const;
176 Node *getChildByShortName(const std::string& name) const throw(Exception);
177 static TypeCode* MappingDF2DS(TypeCode* type) throw(Exception);
178 static TypeCode* MappingDS2DF(TypeCode* type) throw(Exception);
179 virtual bool edAddDFLink(OutPort *start, InPort *end) throw(Exception);
180 void writeDot(std::ostream &os) const;
181 virtual void accept(Visitor *visitor);
182 virtual std::string typeName() {return "YACS__ENGINE__Loop";}
184 void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
185 void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
186 void getDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
187 void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
188 void releaseDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
189 void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
190 void checkNoCyclePassingThrough(Node *node) throw(Exception);
191 void checkControlDependancy(OutPort *start, InPort *end, bool cross,
192 std::map < ComposedNode *, std::list < OutPort * >, SortHierarc >& fw,
193 std::vector<OutPort *>& fwCross,
194 std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
195 LinkInfo& info) const;
196 void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
197 static bool isNecessaryToBuildSpecificDelegateDF2DS(const std::list<ComposedNode *>& pointsOfView);