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