Version: 8.3.0
Loop.hxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef __LOOP_HXX__
21 #define __LOOP_HXX__
22 
23 #include "YACSlibEngineExport.hxx"
25 #include "InputDataStreamPort.hxx"
26 #include "ElementaryNode.hxx"
27 #include "OutputPort.hxx"
28 #include "InputPort.hxx"
29 
30 namespace YACS
31 {
32  namespace ENGINE
33  {
34  void YACSLIBENGINE_EXPORT NbDoneLoader(Loop* node, int val);
35  class Loop;
36  class ForLoop;
37  class WhileLoop;
38  class DFToDSForLoop;
39  class DSToDFForLoop;
40 
42  {
43  public:
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);
49  void exRestoreInit();
50  void exSaveInit();
51  void put(Any *data);
52  ~InputPort4DF2DS();
53  protected:
55  };
56 
58  {
59  friend class Loop;
60  private:
63  private:
64  DFToDSForLoop(Loop *loop, const std::string& name, TypeCode* type);
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;
71  //run part
72  void execute();
73  void load();
74  public:
76  };
77 
79  {
80  public:
82  void getAllRepresented(std::set<OutPort *>& represented) const;
83  void put(const void *data) throw(ConversionException);
84  OutputPort *clone(Node *newHelder) const;
85  void put(Any *data);
87  protected:
89  };
90 
92  {
93  public:
95  void getAllRepresentants(std::set<InPort *>& repr) const;
96  };
97 
99  {
100  friend class Loop;
101  private:
104  private:
105  DSToDFForLoop(Loop *loop, const std::string& name, TypeCode* type);
106  Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
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);
112  //run part
113  void execute();
114  void load();
115  public:
116  ~DSToDFForLoop();
117  };
118 
120  {
121  friend class ForLoop;
122  friend class WhileLoop;
123  private:
127  private:
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();
133  void execute();
134  void aborted();
135  void finished();
136  };
137 
146  {
147  friend class DSToDFForLoop;
148  friend class FakeNodeForLoop;
149  friend void NbDoneLoader(Loop* node, int val);
150  protected:
154  std::set<DSToDFForLoop *> _inputsTraducer;
155  std::set<DFToDSForLoop *> _outputsTraducer;
156  public:
157  Loop(const Loop& other, ComposedNode *father, bool editionOnly);
158  Loop(const std::string& name);
159  ~Loop();
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);
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  std::list<Node *> edGetDirectDescendants() const;
173  std::list<InputPort *> getSetOfInputPort() const;
174  int getNumberOfInputPorts() const;
175  int getMaxLevelOfParallelism() 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";}
183  protected:
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);
198  };
199 
200  }
201 }
202 
203 #endif