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 Node *WhileLoop::simpleClone(ComposedNode *father, bool editionOnly) const
61 return new WhileLoop(*this,father,editionOnly);
64 InputPort *WhileLoop::getInputPort(const std::string& name) const throw(Exception)
66 if(name==NAME_OF_INPUT_CONDITION)
67 return (InputPort*)&_conditionPort;
68 return Loop::getInputPort(name);
71 //! Method used to notify the node that a child node has ended
73 * Update the loop state and return the loop change state
75 * \param node : the child node that has ended
76 * \return the loop state change
78 YACS::Event WhileLoop::updateStateOnFinishedEventFrom(Node *node)
81 if(!_conditionPort.getValue())
89 node->exUpdateState();
94 void WhileLoop::checkLinkPossibility(OutPort *start,
95 const std::list<ComposedNode *>& pointsOfViewStart,
97 const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception)
99 DEBTRACE("WhileLoop::checkLinkPossibility");
102 void WhileLoop::accept(Visitor *visitor)
104 visitor->visitWhileLoop(this);
107 std::list<InputPort *> WhileLoop::getLocalInputPorts() const
109 list<InputPort *> ret;
110 ret.push_back((InputPort *)&_conditionPort);