Version: 8.3.0
InGate.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 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 "InGate.hxx"
21 #include "Node.hxx"
22 
23 //#define _DEVDEBUG_
24 #include "YacsTrace.hxx"
25 
26 #include <algorithm>
27 
28 using namespace YACS::ENGINE;
29 using namespace std;
30 
31 const char InGate::NAME[]="InGate";
32 
33 InGate::InGate(Node *node):Port(node)
34 {
35 }
36 
38 {
39 }
40 
42 {
43  return NAME;
44 }
45 
47 {
48  for(list< std::pair<OutGate *, bool> >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
49  ((*iter).first)->edRemoveInGate(this,false);
50  _backLinks.clear();
51 }
52 
53 class ItemCmp
54 {
55 private:
57 public:
58  ItemCmp(OutGate *itf):_itf(itf) { }
59  bool operator()(const std::pair<OutGate *,bool>& elt) const { return elt.first==_itf; }
60 };
61 
63 
69 {
70  DEBTRACE("InGate::exNotifyFromPrecursor");
71  list< pair<OutGate *, bool> >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from)));
72  if(iter==_backLinks.end())
73  throw YACS::Exception("InGate::exNotifyFromPrecursor : precursor not found !");
74  (*iter).second=true;
75  if(exIsReady())
77 }
78 
80 
84 {
85  if(_node)
87 }
88 
90 
94 {
95  if(_node)
97 }
98 
100 {
101  list< pair<OutGate *, bool> >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from)));
102  if(iter!=_backLinks.end())
103  (*iter).second=false;
104  else
105  _backLinks.push_back(pair<OutGate *, bool>(from,false));
106 }
107 
109 {
110  list< pair<OutGate *, bool> >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from)));
111  if(iter!=_backLinks.end())
112  _backLinks.erase(iter);
113 }
114 
116 {
117  return _backLinks.size();
118 }
119 
121 {
122  for(list< std::pair<OutGate *, bool> >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
123  (*iter).second=false;
124 }
125 
126 bool InGate::exIsReady() const
127 {
128  bool isReady(true);
129  for(list< std::pair<OutGate *, bool> >::const_iterator iter=_backLinks.begin();iter!=_backLinks.end() && isReady;iter++)
130  isReady=(*iter).second;
131  return isReady;
132 }
133 
134 std::list<OutGate *> InGate::getBackLinks()
135 {
136  list<OutGate *> listo;
137  for(list< std::pair<OutGate *, bool> >::const_iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
138  listo.push_back(iter->first);
139  return listo;
140 }
141 
143 {
144  list< std::pair<OutGate *, bool> >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from)));
145  if(iter!=_backLinks.end())
146  (*iter).second=true;
147  else
148  throw YACS::Exception("InGate::setPrecursorDone : precursor not found !");
149 }