1 // Copyright (C) 2006-2008 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
19 #ifndef __FOREACHLOOP_HXX__
20 #define __FOREACHLOOP_HXX__
22 #include "ElementaryNode.hxx"
23 #include "DynParaLoop.hxx"
24 #include "OutputPort.hxx"
25 #include "InputPort.hxx"
26 #include "AnyInputPort.hxx"
34 class AnySplitOutputPort;
38 class InterceptorInputPort : public AnyInputPort
40 friend class ForEachLoop;
41 friend class SplitterNode;
43 AnySplitOutputPort *_repr;
45 InterceptorInputPort(const std::string& name, Node *node, TypeCode* type);
46 InterceptorInputPort(const InterceptorInputPort& other, Node *newHelder);
47 void getAllRepresentants(std::set<InPort *>& repr) const;
48 InputPort *clone(Node *newHelder) const;
49 void setRepr(AnySplitOutputPort *repr);
52 class AnySplitOutputPort : public OutputPort
54 friend class ForEachLoop;
55 friend class SplitterNode;
58 InterceptorInputPort *_intercptr;
59 mutable unsigned int _cnt;
63 AnySplitOutputPort(const std::string& name, Node *node, TypeCode *type);
64 AnySplitOutputPort(const AnySplitOutputPort& other, Node *newHelder);
65 bool addInPort(InPort *inPort) throw(Exception);
66 void getAllRepresented(std::set<OutPort *>& represented) const;
67 int removeInPort(InPort *inPort, bool forward) throw(Exception);
68 void addRepr(OutPort *repr, InterceptorInputPort *intercptr);
69 OutPort *getRepr() const { return _repr; }
70 OutputPort *clone(Node *newHelder) const;
73 class SeqAnyInputPort : public AnyInputPort
75 friend class ForEachLoop;
76 friend class SplitterNode;
78 unsigned getNumberOfElements() const;
79 virtual std::string dump();
81 SeqAnyInputPort(const std::string& name, Node *node, TypeCodeSeq* type);
82 SeqAnyInputPort(const SeqAnyInputPort& other, Node *newHelder);
83 InputPort *clone(Node *newHelder) const;
84 Any *getValueAtRank(int i) const;
87 class SplitterNode : public ElementaryNode
89 friend class ForEachLoop;
91 static const char NAME_OF_SEQUENCE_INPUT[];
93 SplitterNode(const std::string& name, TypeCode *typeOfData, ForEachLoop *father);
94 SplitterNode(const SplitterNode& other, ForEachLoop *father);
95 InputPort *getInputPort(const std::string& name) const throw(Exception);
96 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
97 unsigned getNumberOfElements() const;
99 void init(bool start=true);
100 void putSplittedValueOnRankTo(int rankInSeq, int branch, bool first);
102 SeqAnyInputPort _dataPortToDispatch;
105 class FakeNodeForForEachLoop : public ElementaryNode
107 friend class ForEachLoop;
112 FakeNodeForForEachLoop(ForEachLoop *loop, bool normalFinish);
113 FakeNodeForForEachLoop(const FakeNodeForForEachLoop& other);
114 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
115 void exForwardFailed();
116 void exForwardFinished();
121 static const char NAME[];
124 class ForEachLoop : public DynParaLoop
126 friend class SplitterNode;
127 friend class FakeNodeForForEachLoop;
130 static const char NAME_OF_SPLITTERNODE[];
132 static const int NOT_RUNNING_BRANCH_ID;
134 SplitterNode _splitterNode;
135 FakeNodeForForEachLoop *_nodeForSpecialCases;
136 std::vector<AnySplitOutputPort *> _outGoingPorts;//! ports linked to node outside the current scope
137 std::vector<InterceptorInputPort *> _intecptrsForOutGoingPorts;//!ports created for TypeCodes correctness
138 //part of attributes defining graph dynamically built on control notification
139 unsigned _execCurrentId;
140 std::vector<SequenceAny *> _execVals;
141 std::vector< std::vector<AnyInputPort *> > _execOutGoingPorts;
143 ForEachLoop(const std::string& name, TypeCode *typeOfDataSplitted);
144 ForEachLoop(const ForEachLoop& other, ComposedNode *father, bool editionOnly);
146 void init(bool start=true);
147 void exUpdateState();
148 void getReadyTasks(std::vector<Task *>& tasks);
149 int getNumberOfInputPorts() const;
151 void checkNoCyclePassingThrough(Node *node) throw(Exception);
152 void selectRunnableTasks(std::vector<Task *>& tasks);
154 unsigned getExecCurrentId() const { return _execCurrentId; } // for update progress bar on GUI part
155 std::list<InputPort *> getSetOfInputPort() const;
156 std::list<InputPort *> getLocalInputPorts() const;
157 InputPort *edGetSeqOfSamplesPort() { return &_splitterNode._dataPortToDispatch; }
158 InputPort *getInputPort(const std::string& name) const throw(Exception);
159 OutPort *getOutPort(const std::string& name) const throw(Exception);
160 OutputPort *getOutputPort(const std::string& name) const throw(Exception);
161 Node *getChildByShortName(const std::string& name) const throw(Exception);
162 std::list<OutputPort *> getLocalOutputPorts() const;
163 void accept(Visitor *visitor);
164 void writeDot(std::ostream &os) const;
165 virtual std::string typeName() {return "YACS__ENGINE__ForEachLoop";}
167 Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
168 void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
169 InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
170 YACS::Event updateStateOnFinishedEventFrom(Node *node);
171 void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
172 void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
173 void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
174 void forwardExecStateToOriginalBody(Node *execNode);
176 void cleanDynGraph();
177 void pushAllSequenceValues();
178 void createOutputOutOfScopeInterceptors(int branchNb);
179 void prepareSequenceValues(int sizeOfSamples);
180 OutPort *getDynOutPortByAbsName(int branchNb, const std::string& name);
181 void storeOutValsInSeqForOutOfScopeUse(int rank, int branchNb);