7 #include "Exception.hxx"
22 class InputDataStreamPort;
23 class OutputDataStreamPort;
28 friend class ComposedNode;
29 friend class ElementaryNode;
34 ComposedNode *_father;
35 YACS::StatesForNode _state;
36 std::list<InputPort *> _listOfInputPort;
37 std::list<OutputPort *> _listOfOutputPort;
38 std::list<InputDataStreamPort *> _listOfInputDataStreamPort;
39 std::list<OutputDataStreamPort *> _listOfOutputDataStreamPort;
40 static const char SEP_CHAR_IN_PORT='?';
42 //for graphs algorithms
43 mutable YACS::Colour _colour;
45 Node(const std::string& name);
49 InGate *getInGate() { return &_inGate; }
50 OutGate *getOutGate() { return &_outGate; }
51 const std::string& getName() const { return _name; }
52 std::list<Node *> getOutNodes() const;
53 virtual void exUpdateState();
54 virtual void getReadyTasks(std::vector<Task *>& tasks) = 0;
55 virtual std::list<ElementaryNode *> getRecursiveConstituents() = 0;
56 virtual int getNumberOfInputPorts() const;
57 virtual int getNumberOfOutputPorts() const;
58 virtual std::list<InputPort *> getListOfInputPort() const { return _listOfInputPort; }
59 virtual std::list<OutputPort *> getListOfOutputPort() const { return _listOfOutputPort; }
60 virtual InputPort *getInputPort(const std::string& name) const throw(Exception);
61 virtual OutputPort *getOutputPort(const std::string& name) const throw(Exception);
62 virtual std::list<InputDataStreamPort *> getListOfInputDataStreamPort() const { return _listOfInputDataStreamPort; }
63 virtual std::list<OutputDataStreamPort *> getListOfOutputDataStreamPort() const { return _listOfOutputDataStreamPort; }
64 virtual InputDataStreamPort *getInputDataStreamPort(const std::string& name) const throw(Exception);
65 virtual OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const throw(Exception);
66 std::list<ComposedNode *> getAllAscendanceOf(ComposedNode *levelToStop = 0);
68 bool areAllInputPortsValid() const;
69 virtual ComposedNode *getRootNode() throw(Exception);
70 virtual void disconnectAllLinksConnectedTo(Node *node) = 0;
71 static void checkValidityOfPortName(const std::string& name) throw(Exception);
72 static ComposedNode *checkHavingCommonFather(Node *node1, Node *node2) throw(Exception);
74 PORT *getPort(const std::string& name, const std::list<PORT *>& listOfPorts) const throw(Exception);
75 template<class PORT, class ENUMTYPE>
76 PORT *edAddPort(const std::string& portName, std::list<PORT *>& listOfPorts, ENUMTYPE type) throw(Exception);
78 static void edRemovePortTypedFromList(PORT *port, std::list<PORT *>& listOfPorts) throw(Exception);
80 static bool isPortNameAlreadyExist(const std::string& portName, const std::list<PORT *>& listOfPorts);
82 void initForDFS() const;
86 PORT *Node::getPort(const std::string& name, const std::list<PORT *>& listOfPorts) const throw(Exception)
88 for(typename std::list<PORT *>::const_iterator iter=listOfPorts.begin();iter!=listOfPorts.end();iter++)
90 if((*iter)->getName()==name)
93 std::string what="Node::getPort : unexisting "; what+=PORT::NAME;
96 throw Exception(what);
99 template<class PORT, class ENUMTYPE>
100 PORT *Node::edAddPort(const std::string& portName, std::list<PORT *>& listOfPorts, ENUMTYPE type) throw(Exception)
102 checkValidityOfPortName(portName);
103 if(isPortNameAlreadyExist<PORT>(portName, listOfPorts))
105 std::string what="Port of type "; what+=PORT::NAME; what += " with name : "; what+=portName; what+=" already exists";
106 throw Exception(what);
108 PORT *ret=new PORT(portName,this,type);
109 listOfPorts.push_back(ret);
114 void Node::edRemovePortTypedFromList(PORT *port, std::list<PORT *>& listOfPorts) throw(Exception)
116 if(!isPortNameAlreadyExist<PORT>(port->getName(), listOfPorts))
117 throw Exception("Port is not part of the list : unable to remove it");
118 listOfPorts.remove(port);
122 bool Node::isPortNameAlreadyExist(const std::string& portName, const std::list<PORT *>& listOfPorts)
124 for(typename std::list<PORT *>::const_iterator iter=listOfPorts.begin();iter!=listOfPorts.end();iter++)
126 if((*iter)->getName()==portName)