Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / engine / DynParaLoop.hxx
1 #ifndef __DYNPARALOOP_HXX__
2 #define __DYNPARALOOP_HXX__
3
4 #include "ComposedNode.hxx"
5 #include "AnyInputPort.hxx"
6 #include "OutputPort.hxx"
7
8 namespace YACS
9 {
10   namespace ENGINE
11   { 
12     class DynParaLoop;
13
14     class AnyOutputPort : public OutputPort
15     {
16       friend class DynParaLoop;
17     public:
18       //! store the current dispatched value
19       virtual void setValue(Any *data);
20       //! get the current dispatched value for update port value 
21       Any* getValue() const { return _data; }
22     private:
23       Any* _data; // the data dispatched from port on the current moment
24     private:
25       AnyOutputPort(const std::string& name, Node *node, TypeCode *type);
26       AnyOutputPort(const AnyOutputPort& other, Node *newHelder);
27       virtual ~AnyOutputPort();
28       OutputPort *clone(Node *newHelder) const;
29     };
30
31     /*!
32      * \brief Base class for dynamically (fully or semifully) built graphs.
33      */
34     class DynParaLoop : public ComposedNode
35     {
36     protected:
37       typedef enum
38         {
39           INIT_NODE = 5,
40           WORK_NODE = 6
41       } TypeOfNode;
42     protected:
43       Node *_node;
44       Node *_initNode;
45       unsigned _nbOfEltConsumed;
46       std::vector<int> _execIds;
47       AnyInputPort _nbOfBranches;
48       AnyOutputPort _splittedPort;
49       std::vector<Node *> _execNodes;
50       std::vector<Node *> _execInitNodes;
51     protected:
52       static const char NAME_OF_SPLITTED_SEQ_OUT[];
53       static const char NAME_OF_NUMBER_OF_BRANCHES[];
54     protected:
55       DynParaLoop(const std::string& name, TypeCode *typeOfDataSplitted);
56       virtual ~DynParaLoop();
57       DynParaLoop(const DynParaLoop& other, ComposedNode *father, bool editionOnly);
58     public:
59       Node *edRemoveNode();
60       Node *edRemoveInitNode();
61       //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
62       Node *edSetNode(Node *DISOWNnode);
63       Node *edSetInitNode(Node *DISOWNnode);
64       void init(bool start=true);
65       InputPort *edGetNbOfBranchesPort() { return &_nbOfBranches; }
66       int getNumberOfInputPorts() const;
67       int getNumberOfOutputPorts() const;
68       unsigned getNumberOfEltsConsumed() const { return _nbOfEltConsumed; }
69       std::list<OutputPort *> getSetOfOutputPort() const;
70       OutputPort *edGetSamplePort() { return &_splittedPort; }
71       OutPort *getOutPort(const std::string& name) const throw(Exception);
72       InputPort *getInputPort(const std::string& name) const throw(Exception);
73       OutputPort *getOutputPort(const std::string& name) const throw(Exception);
74       //! For the moment false is returned : impovement about it coming soon.
75       bool isPlacementPredictableB4Run() const;
76       void edRemoveChild(Node *node) throw(Exception);
77       std::list<Node *> edGetDirectDescendants() const;
78       std::list<InputPort *> getSetOfInputPort() const;
79       std::list<InputPort *> getLocalInputPorts() const;
80       unsigned getNumberOfBranchesCreatedDyn() const throw(Exception);
81       Node *getChildByShortName(const std::string& name) const throw(Exception);
82       Node *getChildByNameExec(const std::string& name, unsigned id) const throw(Exception);
83       std::vector<Node *> getNodes() const { return _execNodes; } // need to use in GUI part for adding observers for clone nodes
84       bool isMultiplicitySpecified(unsigned& value) const;
85       void forceMultiplicity(unsigned value);
86     protected:
87       void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
88       void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
89       void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
90       void checkControlDependancy(OutPort *start, InPort *end, bool cross,
91                                   std::map < ComposedNode *,  std::list < OutPort * >, SortHierarc >& fw,
92                                   std::vector<OutPort *>& fwCross,
93                                   std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
94                                   LinkInfo& info) const;
95     protected:
96       void cleanDynGraph();
97       void prepareInputsFromOutOfScope(int branchNb);
98       void putValueOnBranch(Any *val, unsigned branchId, bool first);
99       TypeOfNode getIdentityOfNotifyerNode(const Node *node, unsigned& id);
100       InputPort *getDynInputPortByAbsName(int branchNb, const std::string& name, bool initNodeAdmitted);
101     };
102   }
103 }
104
105 #endif