1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 #include "YacsTrace.hxx"
28 using namespace YACS::ENGINE;
31 const char InGate::NAME[]="InGate";
33 InGate::InGate(Node *node):Port(node)
41 string InGate::getNameOfTypeOfCurrentInstance() const
46 void InGate::edDisconnectAllLinksToMe()
48 for(list< std::pair<OutGate *, bool> >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
49 ((*iter).first)->edRemoveInGate(this,false);
58 ItemCmp(OutGate *itf):_itf(itf) { }
59 bool operator()(const std::pair<OutGate *,bool>& elt) const { return elt.first==_itf; }
62 //! Notify this port that an upstream node connected by a control flow link is finished
64 * Calls the node's gate method : Node::exUpdateState
66 * Called by OutGate::exNotifyDone
68 void InGate::exNotifyFromPrecursor(OutGate *from)
70 DEBTRACE("InGate::exNotifyFromPrecursor");
71 list< pair<OutGate *, bool> >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from)));
72 if(iter==_backLinks.end())
73 throw YACS::Exception("InGate::exNotifyFromPrecursor : precursor not found !");
76 _node->exUpdateState();
79 //! Notify this port that an upstream node connected by a control flow link has failed
83 void InGate::exNotifyFailed()
86 _node->exFailedState();
89 //! Notify this port that an upstream node connected by a control flow link has been disabled
93 void InGate::exNotifyDisabled()
96 _node->exDisabledState();
99 void InGate::edAppendPrecursor(OutGate *from)
101 list< pair<OutGate *, bool> >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from)));
102 if(iter!=_backLinks.end())
103 (*iter).second=false;
105 _backLinks.push_back(pair<OutGate *, bool>(from,false));
108 void InGate::edRemovePrecursor(OutGate *from)
110 list< pair<OutGate *, bool> >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from)));
111 if(iter!=_backLinks.end())
112 _backLinks.erase(iter);
115 int InGate::getNumberOfBackLinks() const
117 return _backLinks.size();
120 void InGate::exReset()
122 for(list< std::pair<OutGate *, bool> >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
123 (*iter).second=false;
126 bool InGate::exIsReady() const
129 for(list< std::pair<OutGate *, bool> >::const_iterator iter=_backLinks.begin();iter!=_backLinks.end() && isReady;iter++)
130 isReady=(*iter).second;
134 std::list<OutGate *> InGate::getBackLinks()
136 list<OutGate *> listo;
137 for(list< std::pair<OutGate *, bool> >::const_iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
138 listo.push_back(iter->first);
142 void InGate::setPrecursorDone(OutGate *from)
144 list< std::pair<OutGate *, bool> >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from)));
145 if(iter!=_backLinks.end())
148 throw YACS::Exception("InGate::setPrecursorDone : precursor not found !");