3 #include "OutputPort.hxx"
7 using namespace YACS::ENGINE;
10 const char ForLoop::NAME_OF_NSTEPS_NUMBER[]="nsteps";
12 ForLoop::ForLoop(const std::string& name):Loop(name),_nbOfTimesPort(NAME_OF_NSTEPS_NUMBER,this,Runtime::_tc_int)
16 ForLoop::ForLoop(const ForLoop& other, ComposedNode *father, bool editionOnly):Loop(other,father,editionOnly),
17 _nbOfTimesPort(other._nbOfTimesPort,this)
21 Node *ForLoop::simpleClone(ComposedNode *father, bool editionOnly) const
23 return new ForLoop(*this,father,editionOnly);
26 int ForLoop::getNumberOfInputPorts() const
28 return StaticDefinedComposedNode::getNumberOfInputPorts()+1;
31 std::list<InputPort *> ForLoop::getSetOfInputPort() const
33 list<InputPort *> ret=StaticDefinedComposedNode::getSetOfInputPort();
34 ret.push_back((InputPort *)&_nbOfTimesPort);
38 InputPort* ForLoop::getInputPort(const std::string& name) const throw(Exception)
40 if(name == NAME_OF_NSTEPS_NUMBER)return (InputPort*)&_nbOfTimesPort;
41 return Loop::getInputPort(name);
45 //! Initialize the node
47 * \param start: a boolean flag to indicate the initialization mode
49 * If start is true, it's a complete initialization (with port values initialization)
50 * If start is false, there is no port values initialization
53 void ForLoop::init(bool start)
56 _nbOfTimesPort.exInit(start);
59 //! Update the state of the for loop
61 * If the inGate port is ready goes to YACS::TOACTIVATE state
62 * If the steps number is 0, create an special internal node
65 void ForLoop::exUpdateState()
67 if(_state == YACS::DISABLED)
69 if(_inGate.exIsReady())
71 setState(YACS::TOACTIVATE);
72 _node->exUpdateState();
73 if(_nbOfTimesPort.isEmpty())
75 delete _nodeForNullTurnOfLoops;
76 _nodeForNullTurnOfLoops=new FakeNodeForLoop(this,false,true);
80 if(_nbOfTimesPort.getIntValue()==0)
82 bool normalFinish=getAllOutPortsLeavingCurrentScope().empty();
83 delete _nodeForNullTurnOfLoops;
84 _nodeForNullTurnOfLoops=new FakeNodeForLoop(this,normalFinish);
86 else if(_nbOfTimesPort.getIntValue()<0)
88 delete _nodeForNullTurnOfLoops;
89 _nodeForNullTurnOfLoops=new FakeNodeForLoop(this,false);
93 delete _nodeForNullTurnOfLoops;
94 _nodeForNullTurnOfLoops=0;
100 //! Method used to notify the node that a child node has ended
102 * Update the loop state and return the loop change state
104 * \param node : the child node that has ended
105 * \return the loop state change
107 YACS::Event ForLoop::updateStateOnFinishedEventFrom(Node *node)
109 if((++_nbOfTurns)>=_nbOfTimesPort.getIntValue())
111 setState(YACS::DONE);
117 node->exUpdateState();
119 return YACS::NOEVENT;
122 void ForLoop::accept(Visitor *visitor)
124 visitor->visitForLoop(this);
127 std::list<InputPort *> ForLoop::getLocalInputPorts() const
129 list<InputPort *> ret;
130 ret.push_back((InputPort *)&_nbOfTimesPort);