Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[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       modified();
71       inGate->modified();
72       return true;
73     }
74   else
75     return false;
76 }
77
78 std::set<InGate *> OutGate::edSetInGate() const
79 {
80   set<InGate *> ret;
81   for(map<InGate *, bool>::const_iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
82     ret.insert((*iter).first);
83   return ret;
84 }
85
86 void OutGate::edRemoveInGate(InGate *inGate, bool coherenceWithInGate) throw(Exception)
87 {
88   map<InGate *, bool>::iterator iter;
89   for(iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
90     if((*iter).first==inGate)
91       {
92         _setOfInGate.erase(iter);
93         if(coherenceWithInGate)
94           inGate->edRemovePrecursor(this);
95         modified();
96         inGate->modified();
97         break;
98       }
99   if(iter==_setOfInGate.end())
100     throw Exception("InGate not already connected to OutGate");
101 }
102
103 //Idem OutGate::edRemoveInGateOneWay except that no exception thrown if CF not exists
104 void OutGate::edRemoveInGateOneWay(InGate *inGate)
105 {
106   bool found=false;
107   for(map<InGate *, bool>::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end() && !found;iter++)
108     if((*iter).first==inGate)
109       {
110         _setOfInGate.erase(iter);
111         inGate->edRemovePrecursor(this);
112         found=true;
113         modified();
114         inGate->modified();
115       }
116 }
117
118 bool OutGate::isAlreadyInSet(InGate *inGate) const
119 {
120   return _setOfInGate.find(inGate)!=_setOfInGate.end();
121 }
122
123 int OutGate::getNbOfInGatesConnected() const
124 {
125   return _setOfInGate.size();
126 }