2 #include "InputPort.hxx"
3 #include "OutputPort.hxx"
4 #include "ComposedNode.hxx"
5 #include "InputDataStreamPort.hxx"
6 #include "OutputDataStreamPort.hxx"
8 using namespace YACS::ENGINE;
10 Node::Node(const std::string& name):_name(name),_inGate(this),_outGate(this),_father(0),_colour(YACS::White),_state(YACS::INITED)
21 for(std::list<OutputPort *>::iterator iter=_listOfOutputPort.begin();iter!=_listOfOutputPort.end();iter++)
23 for(std::list<InputPort *>::iterator iter2=_listOfInputPort.begin();iter2!=_listOfInputPort.end();iter2++)
25 if(_inGate.exIsReady())
26 _state=YACS::TOACTIVATE;
31 std::list<Node *> Node::getOutNodes() const
33 std::list<Node *> ret;
34 std::list<InGate *> inGates=_outGate.edListInGate();
35 for(std::list<InGate *>::iterator iter=inGates.begin();iter!=inGates.end();iter++)
36 ret.push_back((*iter)->getNode());
41 * @ note : Update the '_state' attribute.
42 * Typically called by 'this->_inGate' when 'this->_inGate' is ready.
44 void Node::exUpdateState()
46 if(_inGate.exIsReady())
47 if(areAllInputPortsValid())
48 _state=YACS::TOACTIVATE;
51 std::string what("Node::exUpdateState : Invalid graph given : Node with name \"");
52 what+=_name; what+="\" ready to run whereas some inputports are not set correctly\nCheck coherence DF/CF";
53 throw Exception(what);
57 int Node::getNumberOfInputPorts() const
59 return _listOfInputPort.size();
62 int Node::getNumberOfOutputPorts() const
64 return _listOfOutputPort.size();
67 InputPort *Node::getInputPort(const std::string& name) const throw(Exception)
69 return getPort<InputPort>(name,_listOfInputPort);
72 OutputPort *Node::getOutputPort(const std::string& name) const throw(Exception)
74 return getPort<OutputPort>(name,_listOfOutputPort);
77 InputDataStreamPort *Node::getInputDataStreamPort(const std::string& name) const throw(Exception)
79 return getPort<InputDataStreamPort>(name,_listOfInputDataStreamPort);
82 OutputDataStreamPort *Node::getOutputDataStreamPort(const std::string& name) const throw(Exception)
84 return getPort<OutputDataStreamPort>(name,_listOfOutputDataStreamPort);
87 std::list<ComposedNode *> Node::getAllAscendanceOf(ComposedNode *levelToStop)
89 std::list<ComposedNode *> ret;
90 for(ComposedNode *iter=_father;iter!=levelToStop && iter!=0; iter=iter->_father)
95 bool Node::areAllInputPortsValid() const
98 for(std::list<InputPort *>::const_iterator iter=_listOfInputPort.begin();iter!=_listOfInputPort.end();iter++)
99 ret=!(*iter)->exGet().empty();
103 ComposedNode *Node::getRootNode() throw(Exception)
106 throw Exception("No root node");
107 ComposedNode *iter=_father;
113 void Node::checkValidityOfPortName(const std::string& name) throw(Exception)
115 if(name.find(SEP_CHAR_IN_PORT, 0 )!=std::string::npos)
117 std::string what("Port name "); what+=name; what+="not valid because it contains character "; what+=SEP_CHAR_IN_PORT;
118 throw Exception(what);
123 * @ note : Check that 'node1' and 'node2' have exactly the same father
124 * @ exception : If 'node1' and 'node2' have NOT exactly the same father
126 ComposedNode *Node::checkHavingCommonFather(Node *node1, Node *node2) throw(Exception)
128 if(node1!=0 && node2!=0)
130 if(node1->_father==node2->_father)
131 return node1->_father;
133 throw Exception("check failed : nodes have not the same father");
136 void Node::initForDFS() const
139 std::list<InGate *> inGates=_outGate.edListInGate();
140 for(std::list<InGate *>::iterator iter=inGates.begin();iter!=inGates.end();iter++)
141 (*iter)->initForDFS();