]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/Node.hxx
Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / engine / Node.hxx
1 #ifndef __NODE_HXX__
2 #define __NODE_HXX__
3
4 #include "InGate.hxx"
5 #include "OutGate.hxx"
6 #include "Exception.hxx"
7 #include "define.hxx"
8
9 #include <set>
10 #include <string>
11 #include <vector>
12 #include <map>
13
14 namespace YACS
15 {
16   namespace ENGINE
17   {
18     void StateLoader(Node* node, YACS::StatesForNode state);
19     class Task;
20     class InPort;
21     class OutPort;
22     class InputPort;
23     class OutputPort;
24     class DynParaLoop;
25     class ForEachLoop;
26     class ComposedNode;
27     class ElementaryNode;
28     class Switch;
29     class InputDataStreamPort;
30     class OutputDataStreamPort;
31     class Visitor;
32     
33 /*! \brief Base class for all nodes
34  *
35  * \ingroup Nodes
36  *
37  *
38  */
39     class Node
40     {
41       friend class Bloc;
42       friend class Loop;
43       friend class Switch;
44       friend class InputPort;
45       friend class OutputPort;
46       friend class DynParaLoop;
47       friend class ForEachLoop;
48       friend class ComposedNode;
49       friend class ElementaryNode;
50       friend class Visitor;
51       friend void StateLoader(Node* node, YACS::StatesForNode state);
52     public:
53       mutable YACS::Colour _colour;
54     protected:
55       InGate _inGate;
56       OutGate _outGate;
57       std::string _name;
58       ComposedNode *_father;
59       YACS::StatesForNode _state;
60       int _modified;
61       std::string _errorDetails;
62       static const char SEP_CHAR_IN_PORT[];
63       static int _total;
64       int _numId;
65       std::string _implementation;
66       std::map<std::string,std::string> _propertyMap;
67     protected:
68       Node(const std::string& name);
69       Node(const Node& other, ComposedNode *father);
70       virtual void performDuplicationOfPlacement(const Node& other) = 0;
71       virtual Node *simpleClone(ComposedNode *father, bool editionOnly=true) const = 0;
72     public:
73       virtual ~Node();
74       virtual void init(bool start=true);
75       //! \b This method \b MUST \b NEVER \b BE \b VIRTUAL
76       Node *clone(ComposedNode *father, bool editionOnly=true) const;
77       void setState(YACS::StatesForNode theState); // To centralize state changes
78       virtual YACS::StatesForNode getState() const { return _state; }
79       virtual YACS::StatesForNode getEffectiveState() const;
80       virtual YACS::StatesForNode getEffectiveState(const Node*) const;
81       std::string getColorState(YACS::StatesForNode state) const;
82       InGate *getInGate() { return &_inGate; }
83       OutGate *getOutGate() { return &_outGate; }
84       const std::string& getName() const { return _name; }
85       void setName(const std::string& name);
86       ComposedNode * getFather() const { return _father; }
87       const std::string getId() const;
88       bool exIsControlReady() const;
89       std::set<Node *> getOutNodes() const;
90       virtual void writeDot(std::ostream &os) const;
91       virtual void exUpdateState();
92       virtual void exFailedState();
93       virtual void exDisabledState();
94       virtual void getReadyTasks(std::vector<Task *>& tasks) = 0;
95       virtual std::list<ElementaryNode *> getRecursiveConstituents() const = 0;
96       virtual int getNumberOfInputPorts() const = 0;
97       virtual int getNumberOfOutputPorts() const = 0;
98       std::list<InPort *> getSetOfInPort() const;
99       std::list<OutPort *> getSetOfOutPort() const;
100       virtual std::list<InputPort *> getSetOfInputPort() const = 0;
101       virtual std::list<OutputPort *> getSetOfOutputPort() const = 0;
102       virtual std::list<InputPort *> getLocalInputPorts() const = 0;
103       virtual std::list<OutputPort *> getLocalOutputPorts() const = 0;
104       virtual std::set<InputPort *> edGetSetOfUnitializedInputPort() const;
105       virtual bool edAreAllInputPortInitialized() const;
106       virtual std::string getInPortName(const InPort *) const throw (Exception) = 0;
107       virtual std::string getOutPortName(const OutPort *) const throw (Exception) = 0;
108       virtual std::list<InputDataStreamPort *> getSetOfInputDataStreamPort() const = 0;
109       virtual std::list<OutputDataStreamPort *> getSetOfOutputDataStreamPort() const = 0;
110       InPort *getInPort(const std::string& name) const throw(Exception);
111       virtual OutPort *getOutPort(const std::string& name) const throw(Exception);
112       virtual std::set<OutPort *> getAllOutPortsLeavingCurrentScope() const = 0;
113       virtual std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const = 0;
114       virtual std::vector< std::pair<OutPort *, InPort *> > getSetOfLinksLeavingCurrentScope() const = 0;
115       virtual std::vector< std::pair<InPort *, OutPort *> > getSetOfLinksComingInCurrentScope() const =0;
116       virtual InputPort *getInputPort(const std::string& name) const throw(Exception) = 0;
117       virtual OutputPort *getOutputPort(const std::string& name) const throw(Exception) = 0;
118       virtual InputDataStreamPort *getInputDataStreamPort(const std::string& name) const throw(Exception) = 0;
119       virtual OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const throw(Exception) = 0;
120       std::list<ComposedNode *> getAllAscendanceOf(ComposedNode *levelToStop = 0) const;
121       bool operator>(const Node& other) const;
122       bool operator<(const Node& other) const;
123       std::string getImplementation() const;
124       virtual ComposedNode *getRootNode() const throw(Exception);
125       virtual void setProperty(const std::string& name,const std::string& value);
126       virtual Node *getChildByName(const std::string& name) const throw(Exception) = 0;
127       virtual void accept(Visitor *visitor) = 0;
128       std::string getQualifiedName() const;
129       int getNumId();
130       virtual void sendEvent(const std::string& event);
131       static std::map<int,Node *> idMap;
132       virtual std::string typeName() {return "YACS__ENGINE__Node";}
133       virtual std::string getErrorDetails(){return _errorDetails;};
134       virtual void setErrorDetails(const std::string& error){_errorDetails=error;};
135       virtual void modified();
136       virtual int isModified(){return _modified;}
137       virtual int isValid();
138       virtual void edUpdateState();
139       virtual std::string getErrorReport();
140       virtual std::string getContainerLog();
141       virtual void ensureLoading();
142     protected:
143       virtual void exForwardFailed();
144       virtual void exForwardFinished();
145       virtual void edDisconnectAllLinksWithMe();
146       static void checkValidityOfPortName(const std::string& name) throw(Exception);
147       static ComposedNode *checkHavingCommonFather(Node *node1, Node *node2) throw(Exception);
148     };
149
150   }
151 }
152
153 #endif