Version: 9.15.0
ComposedNode.hxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 CEA, EDF
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 __COMPOSEDNODE_HXX__
21 #define __COMPOSEDNODE_HXX__
22 
23 #include "YACSlibEngineExport.hxx"
24 #include "Node.hxx"
25 #include "Scheduler.hxx"
26 
27 #include <set>
28 #include <string>
29 #include <vector>
30 
31 namespace YACS
32 {
33  namespace ENGINE
34  {
35  class Bloc;
36  class Loop;
37  class InPort;
38  class OutPort;
39  class LinkInfo;
40  class ElementaryNode;
41 
43  {
44  friend class Bloc;
45  friend class Loop;
46  friend class OutPort;
47  friend class ElementaryNode;
48  public:
49  static const char SEP_CHAR_BTW_LEVEL[];
50  protected:
51  ComposedNode(const std::string& name);
52  ComposedNode(const ComposedNode& other, ComposedNode *father);
53  void performDuplicationOfPlacement(const Node& other);
54  void performShallowDuplicationOfPlacement(const Node& other);
55  public:
56  virtual ~ComposedNode();
57  bool isFinished();
58  void init(bool start=true);
59  virtual void shutdown(int level);
60  virtual void resetState(int level);
61  std::string getName() const;
62  std::string getTaskName(Task *task) const;
63  DeploymentTree getDeploymentTree() const;
64  DeploymentTree checkDeploymentTree(bool deep) const ;
65  std::vector<Task *> getNextTasks(bool& isMore);
66  virtual bool isPlacementPredictableB4Run() const = 0;
67  void notifyFrom(const Task *sender, YACS::Event event, const Executor *execInst);
68  bool edAddLink(OutPort *start, InPort *end) ;
69  virtual bool edAddDFLink(OutPort *start, InPort *end) ;
70  //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
71  virtual bool edAddChild(Node *DISOWNnode) ;
72  virtual void edRemoveChild(Node *node) ;
73  bool edAddLink(OutGate *start, InGate *end) ;
74  bool edAddCFLink(Node *nodeS, Node *nodeE) ;
75  void edRemoveCFLink(Node *nodeS, Node *nodeE) ;
76  void edRemoveLink(OutPort *start, InPort *end) ;
77  void edRemoveLink(OutGate *start, InGate *end) ;
78  virtual bool isRepeatedUnpredictablySeveralTimes() const { return false; }
79  virtual bool isLoop() const { return false; }
80  virtual std::list<Node *> edGetDirectDescendants() const = 0;
81  virtual void removeRecursivelyRedundantCL();
82  std::list<ElementaryNode *> getRecursiveConstituents() const;
83  std::list<Node *> getAllRecursiveNodes();
84  virtual std::list<Node *> getAllRecursiveConstituents(); // first implementation
85  std::list<ProgressWeight> getProgressWeight() const;
86  std::string getInPortName(const InPort *) const ;
87  std::string getOutPortName(const OutPort *) const ;
88  //
89  int getNumberOfInputPorts() const;
90  int getNumberOfOutputPorts() const;
91  std::list<InputPort *> getSetOfInputPort() const;
92  std::list<OutputPort *> getSetOfOutputPort() const;
93  std::list<InputPort *> getLocalInputPorts() const;
94  std::list<OutputPort *> getLocalOutputPorts() const;
95  std::set<OutPort *> getAllOutPortsLeavingCurrentScope() const;
96  std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const;
97  std::list<InputDataStreamPort *> getSetOfInputDataStreamPort() const;
98  std::list<OutputDataStreamPort *> getSetOfOutputDataStreamPort() const;
99  OutPort *getOutPort(const std::string& name) const ;
100  InputPort *getInputPort(const std::string& name) const ;
101  OutputPort *getOutputPort(const std::string& name) const ;
102  InputDataStreamPort *getInputDataStreamPort(const std::string& name) const ;
103  OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const ;
104  std::vector< std::pair<OutPort *, InPort *> > getSetOfInternalLinks() const;
105  virtual std::vector< std::pair<OutPort *, InPort *> > getSetOfLinksLeavingCurrentScope() const;
106  void checkConsistency(LinkInfo& info) const ;
107  virtual std::vector< std::pair<InPort *, OutPort *> > getSetOfLinksComingInCurrentScope() const;
108  virtual std::string typeName() {return "YACS__ENGINE__ComposedNode";}
109  virtual void edUpdateState();
110  virtual void checkBasicConsistency() const ;
111  virtual std::string getErrorReport();
112  //
113  ComposedNode *getRootNode() const ;
114  bool isNodeAlreadyAggregated(const Node *node) const;
115  virtual bool isNameAlreadyUsed(const std::string& name) const;
116  Node *isInMyDescendance(Node *nodeToTest) const;
117  std::string getChildName(const Node* node) const ;
118  virtual std::string getMyQualifiedName(const Node *directSon) const;
119  Node *getChildByName(const std::string& name) const ;
120  static ComposedNode *getLowestCommonAncestor(Node *node1, Node *node2) ;
121  static std::string getLowestCommonAncestorStr(const std::string& node1, const std::string& node2);
122  void loaded();
123  void connected();
124  void accept(Visitor *visitor);
125  virtual void cleanNodes();
126  virtual std::string getProgress() const { return "0"; }
127  void setProperty(const std::string& name,const std::string& value)override;
128  std::string getProperty(const std::string& name)override;
129  protected:
130  struct SortHierarc
131  {
132  bool operator()(ComposedNode *n1, ComposedNode *n2) const
133  {
134  return *n1<*n2;
135  }
136  };
137  protected:
138  void edDisconnectAllLinksWithMe();
139  static bool splitNamesBySep(const std::string& globalName, const char separator[],
140  std::string& firstPart, std::string& lastPart, bool priority) ;
141  virtual Node *getChildByShortName(const std::string& name) const = 0;
142  YACS::Event updateStateFrom(Node *node, YACS::Event event, const Executor *execInst);//update the state of this. Precondition : node->_father == this
143  virtual YACS::Event updateStateOnStartEventFrom(Node *node);//transition 3 doc P.R
144  virtual YACS::Event updateStateOnFinishedEventFrom(Node *node) = 0;//transition 9 doc P.R.
145  virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);//transition 9 doc P.R.
146  virtual void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
147  InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) ;
148  virtual void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
149  virtual void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
150  virtual void getDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView) ;
151  virtual void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) ;
152  virtual void releaseDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView) ;
153  virtual void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) ;
154  virtual void checkNoCyclePassingThrough(Node *node) = 0;
155  void checkInMyDescendance(Node *nodeToTest) const ;
156  template <class PORT>
157  std::string getPortName(const PORT * port) const ;
158  //For CF Computations
159  void checkNoCrossHierachyWith(Node *node) const ;
160  virtual void performCFComputations(LinkInfo& info) const;
161  virtual void destructCFComputations(LinkInfo& info) const;
162  Node *getLowestNodeDealingAll(const std::list<OutPort *>& ports) const;
163  void checkLinksCoherenceRegardingControl(const std::vector<OutPort *>& starts,
164  InputPort *end, LinkInfo& info) const ;
165  virtual void checkControlDependancy(OutPort *start, InPort *end, bool cross,
166  std::map < ComposedNode *, std::list < OutPort * >, SortHierarc >& fw,
167  std::vector<OutPort *>& fwCross,
168  std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
169  LinkInfo& info) const = 0;
170  void solveObviousOrDelegateCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
171  virtual void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
172  protected:
173  //For internal calculations.
174  static const unsigned char FED_ST = 2;
175  static const unsigned char FREE_ST = 0;
176  static const unsigned char FED_DS_ST = 1;
177  };
178 
179  template <class PORT>
180  std::string ComposedNode::getPortName(const PORT * port) const
181  {
182  Node *node = port->getNode();
183  std::string portName = port->getName();
184  checkInMyDescendance(node);
185  Node *father = node;
186  while (father != this)
187  {
188  portName = father->getQualifiedName() + Node::SEP_CHAR_IN_PORT + portName;
189  father = father->_father;
190  }
191  return portName;
192  }
193  }
194 }
195 
196 #endif
#define YACSLIBENGINE_EXPORT
Composed node to group elementary and composed nodes.
Definition: Bloc.hxx:36
Base class for all composed nodes.
virtual bool isRepeatedUnpredictablySeveralTimes() const
virtual std::list< Node * > edGetDirectDescendants() const =0
virtual Node * getChildByShortName(const std::string &name) const =0
std::string getPortName(const PORT *port) const
virtual bool isLoop() const
void checkInMyDescendance(Node *nodeToTest) const
Check if a node is in the descendance of this node.
virtual std::string typeName()
virtual void checkNoCyclePassingThrough(Node *node)=0
virtual YACS::Event updateStateOnFinishedEventFrom(Node *node)=0
virtual std::string getProgress() const
virtual void checkControlDependancy(OutPort *start, InPort *end, bool cross, std::map< ComposedNode *, std::list< OutPort * >, SortHierarc > &fw, std::vector< OutPort * > &fwCross, std::map< ComposedNode *, std::list< OutPort * >, SortHierarc > &bw, LinkInfo &info) const =0
virtual bool isPlacementPredictableB4Run() const =0
Base class for all calculation nodes.
Threaded Executor.
Definition: Executor.hxx:63
Base class for Input Ports.
Definition: InputPort.hxx:44
Class that deal with list of semantics links for high level analysis.
Definition: LinkInfo.hxx:83
Base class for loop node.
Definition: Loop.hxx:147
Base class for all nodes.
Definition: Node.hxx:70
ComposedNode * _father
Definition: Node.hxx:90
std::string getQualifiedName() const
same as Node::getName() in most cases, but differs for children of switch
Definition: Node.cxx:632
static const char SEP_CHAR_IN_PORT[]
Definition: Node.hxx:94
const std::string & getName() const
Definition: Node.hxx:125
Event
Definition: define.hxx:56
bool operator()(ComposedNode *n1, ComposedNode *n2) const