1 #ifndef __FOREACHLOOP_HXX__
2 #define __FOREACHLOOP_HXX__
4 #include "ElementaryNode.hxx"
5 #include "DynParaLoop.hxx"
6 #include "OutputPort.hxx"
7 #include "InputPort.hxx"
8 #include "TypeCode.hxx"
9 #include "AnyInputPort.hxx"
17 class AnySplitOutputPort;
19 class InterceptorInputPort : public AnyInputPort
21 friend class ForEachLoop;
22 friend class SplitterNode;
24 AnySplitOutputPort *_repr;
26 InterceptorInputPort(const std::string& name, Node *node, TypeCode* type);
27 InterceptorInputPort(const InterceptorInputPort& other, Node *newHelder);
28 void getAllRepresentants(std::set<InPort *>& repr) const;
29 InputPort *clone(Node *newHelder) const;
30 void setRepr(AnySplitOutputPort *repr);
33 class AnySplitOutputPort : public OutputPort
35 friend class ForEachLoop;
36 friend class SplitterNode;
39 InterceptorInputPort *_intercptr;
40 mutable unsigned int _cnt;
44 AnySplitOutputPort(const std::string& name, Node *node, TypeCode *type);
45 AnySplitOutputPort(const AnySplitOutputPort& other, Node *newHelder);
46 bool addInPort(InPort *inPort) throw(Exception);
47 void getAllRepresented(std::set<OutPort *>& represented) const;
48 int removeInPort(InPort *inPort, bool forward) throw(Exception);
49 void addRepr(OutPort *repr, InterceptorInputPort *intercptr);
50 OutPort *getRepr() const { return _repr; }
51 OutputPort *clone(Node *newHelder) const;
54 class SeqAnyInputPort : public AnyInputPort
56 friend class ForEachLoop;
57 friend class SplitterNode;
59 unsigned getNumberOfElements() const;
60 virtual std::string dump();
62 SeqAnyInputPort(const std::string& name, Node *node, TypeCodeSeq* type);
63 SeqAnyInputPort(const SeqAnyInputPort& other, Node *newHelder);
64 InputPort *clone(Node *newHelder) const;
65 Any *getValueAtRank(int i) const;
68 class SplitterNode : public ElementaryNode
70 friend class ForEachLoop;
72 static const char NAME_OF_SEQUENCE_INPUT[];
74 SplitterNode(const std::string& name, TypeCode *typeOfData, ForEachLoop *father);
75 SplitterNode(const SplitterNode& other, ForEachLoop *father);
76 InputPort *getInputPort(const std::string& name) const throw(Exception);
77 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
78 unsigned getNumberOfElements() const;
80 void init(bool start=true);
81 void putSplittedValueOnRankTo(int rankInSeq, int branch, bool first);
83 SeqAnyInputPort _dataPortToDispatch;
86 class FakeNodeForForEachLoop : public ElementaryNode
88 friend class ForEachLoop;
93 FakeNodeForForEachLoop(ForEachLoop *loop, bool normalFinish);
94 FakeNodeForForEachLoop(const FakeNodeForForEachLoop& other);
95 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
96 void exForwardFailed();
97 void exForwardFinished();
102 static const char NAME[];
105 class ForEachLoop : public DynParaLoop
107 friend class SplitterNode;
108 friend class FakeNodeForForEachLoop;
111 static const char NAME_OF_SPLITTERNODE[];
113 static const int NOT_RUNNING_BRANCH_ID;
115 SplitterNode _splitterNode;
116 FakeNodeForForEachLoop *_nodeForSpecialCases;
117 std::vector<AnySplitOutputPort *> _outGoingPorts;//! ports linked to node outside the current scope
118 std::vector<InterceptorInputPort *> _intecptrsForOutGoingPorts;//!ports created for TypeCodes correctness
119 //part of attributes defining graph dynamically built on control notification
120 unsigned _execCurrentId;
121 std::vector<SequenceAny *> _execVals;
122 std::vector< std::vector<AnyInputPort *> > _execOutGoingPorts;
124 ForEachLoop(const std::string& name, TypeCode *typeOfDataSplitted);
125 ForEachLoop(const ForEachLoop& other, ComposedNode *father, bool editionOnly);
127 void init(bool start=true);
128 void exUpdateState();
129 void getReadyTasks(std::vector<Task *>& tasks);
130 int getNumberOfInputPorts() const;
132 void checkConsistency(ComposedNode *pointOfView) const throw(Exception);
133 void checkNoCyclePassingThrough(Node *node) throw(Exception);
134 void selectRunnableTasks(std::vector<Task *>& tasks);
136 unsigned getExecCurrentId() const { return _execCurrentId; } // for update progress bar on GUI part
137 std::list<InputPort *> getSetOfInputPort() const;
138 InputPort *edGetSeqOfSamplesPort() { return &_splitterNode._dataPortToDispatch; }
139 InputPort *getInputPort(const std::string& name) const throw(Exception);
140 OutPort *getOutPort(const std::string& name) const throw(Exception);
141 OutputPort *getOutputPort(const std::string& name) const throw(Exception);
142 Node *getChildByShortName(const std::string& name) const throw(Exception);
143 std::list<OutputPort *> getLocalOutputPorts() const;
144 void accept(Visitor *visitor);
145 void writeDot(std::ostream &os);
147 Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
148 void checkLinkPossibility(OutPort *start, const std::set<ComposedNode *>& pointsOfViewStart,
149 InPort *end, const std::set<ComposedNode *>& pointsOfViewEnd) throw(Exception);
150 YACS::Event updateStateOnFinishedEventFrom(Node *node);
151 void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::set<ComposedNode *>& pointsOfView);
152 void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::set<ComposedNode *>& pointsOfView) throw(Exception);
153 void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::set<ComposedNode *>& pointsOfView) throw(Exception);
155 void cleanDynGraph();
156 void pushAllSequenceValues();
157 void createOutputOutOfScopeInterceptors(int branchNb);
158 void prepareSequenceValues(int sizeOfSamples);
159 OutPort *getDynOutPortByAbsName(int branchNb, const std::string& name);
160 void storeOutValsInSeqForOutOfScopeUse(int rank, int branchNb);