1 #include "WhileLoop.hxx"
3 #include "OutputPort.hxx"
8 #include "YacsTrace.hxx"
10 using namespace YACS::ENGINE;
13 const char WhileLoop::NAME_OF_INPUT_CONDITION[]="condition";
15 WhileLoop::WhileLoop(const std::string& name):Loop(name),_conditionPort(NAME_OF_INPUT_CONDITION,this)
19 WhileLoop::WhileLoop(const WhileLoop& other, ComposedNode *father, bool editionOnly):Loop(other,father,editionOnly),
20 _conditionPort(other._conditionPort,this)
24 void WhileLoop::init(bool start)
27 _conditionPort.exInit(start);
30 void WhileLoop::exUpdateState()
32 if(_state == YACS::DISABLED)
34 if(_inGate.exIsReady())
36 setState(YACS::TOACTIVATE);
37 _node->exUpdateState();
38 if(_conditionPort.isLinkedOutOfScope())
39 if(_conditionPort.isEmpty())
41 delete _nodeForNullTurnOfLoops;
42 _nodeForNullTurnOfLoops=new FakeNodeForLoop(this,false,true);
45 if(!_conditionPort.getValue())
47 bool normalFinish=getAllOutPortsLeavingCurrentScope().empty();
48 delete _nodeForNullTurnOfLoops;
49 _nodeForNullTurnOfLoops=new FakeNodeForLoop(this,normalFinish);
53 delete _nodeForNullTurnOfLoops;
54 _nodeForNullTurnOfLoops=0;
59 int WhileLoop::getNumberOfInputPorts() const
61 return StaticDefinedComposedNode::getNumberOfInputPorts()+1;
64 Node *WhileLoop::simpleClone(ComposedNode *father, bool editionOnly) const
66 return new WhileLoop(*this,father,editionOnly);
69 std::list<InputPort *> WhileLoop::getSetOfInputPort() const
71 list<InputPort *> ret=StaticDefinedComposedNode::getSetOfInputPort();
72 ret.push_back((InputPort *)&_conditionPort);
76 InputPort *WhileLoop::getInputPort(const std::string& name) const throw(Exception)
78 if(name==NAME_OF_INPUT_CONDITION)
79 return (InputPort*)&_conditionPort;
80 return Loop::getInputPort(name);
83 //! Method used to notify the node that a child node has ended
85 * Update the loop state and return the loop change state
87 * \param node : the child node that has ended
88 * \return the loop state change
90 YACS::Event WhileLoop::updateStateOnFinishedEventFrom(Node *node)
93 if(!_conditionPort.getValue())
101 node->exUpdateState();
103 return YACS::NOEVENT;
106 void WhileLoop::checkLinkPossibility(OutPort *start,
107 const std::set<ComposedNode *>& pointsOfViewStart,
109 const std::set<ComposedNode *>& pointsOfViewEnd) throw(Exception)
111 DEBTRACE("WhileLoop::checkLinkPossibility");
114 void WhileLoop::accept(Visitor *visitor)
116 visitor->visitWhileLoop(this);
119 std::list<InputPort *> WhileLoop::getLocalInputPorts() const
121 list<InputPort *> ret;
122 ret.push_back((InputPort *)&_conditionPort);