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
20 #include "OutGate.hxx"
24 #include "YacsTrace.hxx"
28 using namespace YACS::ENGINE;
31 const char OutGate::NAME[]="OutGate";
33 OutGate::OutGate(Node *node):Port(node)
37 string OutGate::getNameOfTypeOfCurrentInstance() const
42 void OutGate::exReset()
44 for(list< pair< InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
48 //! Notify this port that its node is finished
50 * Calls (notify) all the connected ingates : InGate::exNotifyFromPrecursor
52 * Called by Bloc::updateStateOnFinishedEventFrom
55 void OutGate::exNotifyDone()
57 DEBTRACE("OutGate::exNotifyDone");
58 for(list< pair<InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
59 (*iter).first->exNotifyFromPrecursor(this);
62 //! Notify this port that its node has failed
66 void OutGate::exNotifyFailed()
68 for(list< pair<InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
69 (*iter).first->exNotifyFailed();
72 //! Notify this port that its node has been disabled
76 void OutGate::exNotifyDisabled()
78 for(list< pair<InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
79 (*iter).first->exNotifyDisabled();
82 void OutGate::edDisconnectAllLinksFromMe()
84 for(list< pair<InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
85 (*iter).first->edRemovePrecursor(this);
94 ItemCmp(InGate *itf):_itf(itf) { }
95 bool operator()(const std::pair<InGate *,bool>& elt) const { return elt.first==_itf; }
98 bool OutGate::edAddInGate(InGate *inGate)
100 if(!isAlreadyInSet(inGate))
102 inGate->edAppendPrecursor(this);
103 _setOfInGate.push_back(std::pair<InGate *,bool>(inGate,false));
112 std::list<InGate *> OutGate::edSetInGate() const
115 for(list< pair<InGate *, bool> >::const_iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
116 ret.push_back((*iter).first);
120 void OutGate::edRemoveInGate(InGate *inGate, bool coherenceWithInGate) throw(YACS::Exception)
122 std::list< pair<InGate* , bool> >::iterator iter(std::find_if(_setOfInGate.begin(),_setOfInGate.end(),ItemCmp(inGate)));
123 if(iter==_setOfInGate.end())
124 throw Exception("InGate not already connected to OutGate");
127 if(coherenceWithInGate)
128 inGate->edRemovePrecursor(this);
129 _setOfInGate.erase(iter);
135 //Idem OutGate::edRemoveInGate except that no exception thrown if CF not exists
136 void OutGate::edRemoveInGateOneWay(InGate *inGate)
139 for(list< pair<InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end() && !found;iter++)
140 if((*iter).first==inGate)
142 _setOfInGate.erase(iter);
143 inGate->edRemovePrecursor(this);
150 bool OutGate::isAlreadyInSet(InGate *inGate) const
152 return find_if(_setOfInGate.begin(),_setOfInGate.end(),ItemCmp(inGate))!=_setOfInGate.end();
155 int OutGate::getNbOfInGatesConnected() const
157 return _setOfInGate.size();