Salome HOME
5338987f4083033d03dd7658f9b734870ec4c083
[modules/yacs.git] / src / engine / OutGate.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "OutGate.hxx"
20 #include "InGate.hxx"
21
22 //#define _DEVDEBUG_
23 #include "YacsTrace.hxx"
24
25 using namespace YACS::ENGINE;
26 using namespace std;
27
28 const char OutGate::NAME[]="OutGate";
29
30 OutGate::OutGate(Node *node):Port(node)
31 {
32 }
33
34 string OutGate::getNameOfTypeOfCurrentInstance() const
35 {
36   return NAME;
37 }
38
39 void OutGate::exReset()
40 {
41   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
42     (*iter).second=false;
43 }
44
45 //! Notify this port that its node is finished
46 /*!
47  *  Calls (notify) all the connected ingates : InGate::exNotifyFromPrecursor
48  *
49  *  Called by Bloc::updateStateOnFinishedEventFrom
50  */
51
52 void OutGate::exNotifyDone()
53 {
54   DEBTRACE("OutGate::exNotifyDone");
55   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
56     (*iter).first->exNotifyFromPrecursor(this);
57 }
58
59 //! Notify this port that its node has failed
60 /*!
61  *
62  */
63 void OutGate::exNotifyFailed()
64 {
65   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
66     (*iter).first->exNotifyFailed();
67 }
68
69 //! Notify this port that its node has been disabled
70 /*!
71  *
72  */
73 void OutGate::exNotifyDisabled()
74 {
75   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
76     (*iter).first->exNotifyDisabled();
77 }
78
79 void OutGate::edDisconnectAllLinksFromMe()
80 {
81   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
82     (*iter).first->edRemovePrecursor(this);
83   _setOfInGate.clear();
84 }
85
86 bool OutGate::edAddInGate(InGate *inGate)
87 {
88   if(!isAlreadyInSet(inGate))
89     {
90       inGate->edAppendPrecursor(this);
91       _setOfInGate[inGate]=false;
92       modified();
93       inGate->modified();
94       return true;
95     }
96   else
97     return false;
98 }
99
100 std::set<InGate *> OutGate::edSetInGate() const
101 {
102   set<InGate *> ret;
103   for(map<InGate *, bool>::const_iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
104     ret.insert((*iter).first);
105   return ret;
106 }
107
108 void OutGate::edRemoveInGate(InGate *inGate, bool coherenceWithInGate) throw(Exception)
109 {
110   map<InGate *, bool>::iterator iter;
111   for(iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
112     if((*iter).first==inGate)
113       {
114         _setOfInGate.erase(iter);
115         if(coherenceWithInGate)
116           inGate->edRemovePrecursor(this);
117         modified();
118         inGate->modified();
119         break;
120       }
121   if(iter==_setOfInGate.end())
122     throw Exception("InGate not already connected to OutGate");
123 }
124
125 //Idem OutGate::edRemoveInGateOneWay except that no exception thrown if CF not exists
126 void OutGate::edRemoveInGateOneWay(InGate *inGate)
127 {
128   bool found=false;
129   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end() && !found;iter++)
130     if((*iter).first==inGate)
131       {
132         _setOfInGate.erase(iter);
133         inGate->edRemovePrecursor(this);
134         found=true;
135         modified();
136         inGate->modified();
137       }
138 }
139
140 bool OutGate::isAlreadyInSet(InGate *inGate) const
141 {
142   return _setOfInGate.find(inGate)!=_setOfInGate.end();
143 }
144
145 int OutGate::getNbOfInGatesConnected() const
146 {
147   return _setOfInGate.size();
148 }