Version: 9.16.0
OutGate.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
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#include <algorithm>
27
28using namespace YACS::ENGINE;
29using namespace std;
30
31const char OutGate::NAME[]="OutGate";
32
33OutGate::OutGate(Node *node):Port(node)
34{
35}
36
38{
39 return NAME;
40}
41
43{
44 for(list< pair< InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
45 (*iter).second=false;
46}
47
49
56{
57 DEBTRACE("OutGate::exNotifyDone");
58 for(list< pair<InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
59 (*iter).first->exNotifyFromPrecursor(this);
60}
61
63
67{
68 for(list< pair<InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
69 (*iter).first->exNotifyFailed();
70}
71
73
77{
78 for(list< pair<InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
79 (*iter).first->exNotifyDisabled();
80}
81
83{
84 for(list< pair<InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
85 (*iter).first->edRemovePrecursor(this);
86 _setOfInGate.clear();
87}
88
89class ItemCmp
90{
91private:
93public:
94 ItemCmp(InGate *itf):_itf(itf) { }
95 bool operator()(const std::pair<InGate *,bool>& elt) const { return elt.first==_itf; }
96};
97
99{
100 if(!isAlreadyInSet(inGate))
101 {
102 inGate->edAppendPrecursor(this);
103 _setOfInGate.push_back(std::pair<InGate *,bool>(inGate,false));
104 modified();
105 inGate->modified();
106 return true;
107 }
108 else
109 return false;
110}
111
112std::list<InGate *> OutGate::edSetInGate() const
113{
114 list<InGate *> ret;
115 for(list< pair<InGate *, bool> >::const_iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end();iter++)
116 ret.push_back((*iter).first);
117 return ret;
118}
119
120void OutGate::edRemoveInGate(InGate *inGate, bool coherenceWithInGate)
121{
122 std::list< pair<InGate* , bool> >::iterator iter(std::find_if(_setOfInGate.begin(),_setOfInGate.end(),ItemCmp(inGate)));
123 if(iter==_setOfInGate.end())
124 throw Exception("InGate not already connected to OutGate");
125 else
126 {
127 if(coherenceWithInGate)
128 inGate->edRemovePrecursor(this);
129 _setOfInGate.erase(iter);
130 inGate->modified();
131 modified();
132 }
133}
134
135//Idem OutGate::edRemoveInGate except that no exception thrown if CF not exists
137{
138 bool found=false;
139 for(list< pair<InGate *, bool> >::iterator iter=_setOfInGate.begin();iter!=_setOfInGate.end() && !found;iter++)
140 if((*iter).first==inGate)
141 {
142 _setOfInGate.erase(iter);
143 inGate->edRemovePrecursor(this);
144 found=true;
145 modified();
146 inGate->modified();
147 }
148}
149
151{
152 return find_if(_setOfInGate.begin(),_setOfInGate.end(),ItemCmp(inGate))!=_setOfInGate.end();
153}
154
156{
157 return _setOfInGate.size();
158}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
bool operator()(const std::pair< InGate *, bool > &elt) const
Definition: OutGate.cxx:95
InGate * _itf
Definition: OutGate.cxx:92
ItemCmp(InGate *itf)
Definition: OutGate.cxx:94
void edRemovePrecursor(OutGate *fromgate)
Definition: InGate.cxx:108
void edAppendPrecursor(OutGate *fromgate)
Definition: InGate.cxx:99
Base class for all nodes.
Definition: Node.hxx:70
bool isAlreadyInSet(InGate *inGate) const
Definition: OutGate.cxx:150
void edRemoveInGateOneWay(InGate *inGate)
Definition: OutGate.cxx:136
void edDisconnectAllLinksFromMe()
Definition: OutGate.cxx:82
static const char NAME[]
Definition: OutGate.hxx:42
std::list< InGate * > edSetInGate() const
Definition: OutGate.cxx:112
void edRemoveInGate(InGate *inGate, bool coherenceWithInGate=true)
Definition: OutGate.cxx:120
bool edAddInGate(InGate *inGate)
Definition: OutGate.cxx:98
void exNotifyDone()
Notify this port that its node is finished.
Definition: OutGate.cxx:55
int getNbOfInGatesConnected() const
Definition: OutGate.cxx:155
void exNotifyFailed()
Notify this port that its node has failed.
Definition: OutGate.cxx:66
void exNotifyDisabled()
Notify this port that its node has been disabled.
Definition: OutGate.cxx:76
std::list< std::pair< InGate *, bool > > _setOfInGate
Definition: OutGate.hxx:40
std::string getNameOfTypeOfCurrentInstance() const
Definition: OutGate.cxx:37
Base class for all ports.
Definition: Port.hxx:43
void modified()
Definition: Port.cxx:53