]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/OutGate.cxx
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / engine / OutGate.cxx
1 #include "OutGate.hxx"
2 #include "InGate.hxx"
3
4 using namespace YACS::ENGINE;
5 using namespace std;
6
7 const char OutGate::NAME[]="OutGate";
8
9 OutGate::OutGate(Node *node):Port(node)
10 {
11 }
12
13 string OutGate::getNameOfTypeOfCurrentInstance() const
14 {
15   return NAME;
16 }
17
18 void OutGate::exReset()
19 {
20   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
21     (*iter).second=false;
22 }
23
24 //! Notify this port that its node is finished
25 /*!
26  *  Calls (notify) all the connected ingates : InGate::exNotifyFromPrecursor
27  *
28  *  Called by Bloc::updateStateOnFinishedEventFrom
29  */
30
31 void OutGate::exNotifyDone()
32 {
33   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
34     (*iter).first->exNotifyFromPrecursor(this);
35 }
36
37 //! Notify this port that its node has failed
38 /*!
39  *
40  */
41 void OutGate::exNotifyFailed()
42 {
43   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
44     (*iter).first->exNotifyFailed();
45 }
46
47 //! Notify this port that its node has been disabled
48 /*!
49  *
50  */
51 void OutGate::exNotifyDisabled()
52 {
53   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
54     (*iter).first->exNotifyDisabled();
55 }
56
57 void OutGate::edDisconnectAllLinksFromMe()
58 {
59   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
60     (*iter).first->edRemovePrecursor(this);
61   _setOfInGate.clear();
62 }
63
64 bool OutGate::edAddInGate(InGate *inGate)
65 {
66   if(!isAlreadyInSet(inGate))
67     {
68       inGate->edAppendPrecursor(this);
69       _setOfInGate[inGate]=false;
70       return true;
71     }
72   else
73     return false;
74 }
75
76 std::set<InGate *> OutGate::edSetInGate() const
77 {
78   set<InGate *> ret;
79   for(map<InGate *, bool>::const_iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
80     ret.insert((*iter).first);
81   return ret;
82 }
83
84 void OutGate::edRemoveInGate(InGate *inGate, bool coherenceWithInGate) throw(Exception)
85 {
86   map<InGate *, bool>::iterator iter;
87   for(iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
88     if((*iter).first==inGate)
89       {
90         _setOfInGate.erase(iter);
91         if(coherenceWithInGate)
92           inGate->edRemovePrecursor(this);
93         break;
94       }
95   if(iter==_setOfInGate.end())
96     throw Exception("InGate not already connected to OutGate");
97 }
98
99 //Idem OutGate::edRemoveInGateOneWay except that no exception thrown if CF not exists
100 void OutGate::edRemoveInGateOneWay(InGate *inGate)
101 {
102   bool found=false;
103   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end() && !found;iter++)
104     if((*iter).first==inGate)
105       {
106         _setOfInGate.erase(iter);
107         inGate->edRemovePrecursor(this);
108         found=true;
109       }
110 }
111
112 bool OutGate::isAlreadyInSet(InGate *inGate) const
113 {
114   return _setOfInGate.find(inGate)!=_setOfInGate.end();
115 }
116
117 int OutGate::getNbOfInGatesConnected() const
118 {
119   return _setOfInGate.size();
120 }