Version: 8.3.0
OutputDataStreamPort.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 "OutputDataStreamPort.hxx"
21 #include "InputDataStreamPort.hxx"
22 #include "ComposedNode.hxx"
23 #include "InPort.hxx"
24 #include "TypeCode.hxx"
25 #include <iostream>
26 
27 //#define _DEVDEBUG_
28 #include "YacsTrace.hxx"
29 
30 using namespace YACS::ENGINE;
31 using namespace std;
32 
33 const char OutputDataStreamPort::NAME[]="OutputDataStreamPort";
34 
36  OutPort(other,newHelder),
37  DataPort(other,newHelder),
38  Port(other,newHelder)
39 {
40 }
41 
42 OutputDataStreamPort::OutputDataStreamPort(const std::string& name, Node *node, TypeCode* type):DataStreamPort(name,node,type),
43 OutPort(name,node,type),
44 DataPort(name,node,type),
45 Port(node)
46 {
47 }
48 
50 {
51 }
52 
54 {
55  return new OutputDataStreamPort(*this,newHelder);
56 }
57 
58 std::set<InPort *> OutputDataStreamPort::edSetInPort() const
59 {
60  set<InPort *> s;
61  for(set<InputDataStreamPort *>::const_iterator iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
62  (*iter)->getAllRepresentants(s);
63  return s;
64 }
65 
67 {
68  set<InPort *> s;
69  set<InputDataStreamPort *>::const_iterator iter;
70  for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
71  if(*iter==with)
72  return true;
73  for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
74  (*iter)->getAllRepresentants(s);
75  for(set<InPort *>::iterator iter2=s.begin();iter2!=s.end();iter2++)
76  if((*iter2)==with)
77  return true;
78  return false;
79 }
80 
82 {
83  return NAME;
84 }
85 
87  throw(ConversionException)
88 {
89  DEBTRACE("OutputDataStreamPort::edAddInputDataStreamPort");
90  if(!isAlreadyInSet(port))
91  {
92  if(!port->edGetType()->isAdaptable(edGetType()))
93  {
94  string what="Can not connect 2 ports with incompatible types : ";
95  what=what+ port->edGetType()->id();
96  what=what+" is not a ";
97  what=what+ edGetType()->id();
98  throw ConversionException(what);
99  }
100  _setOfInputDataStreamPort.insert(port);
101  port->edAddOutputDataStreamPort(this);
102  return true;
103  }
104  else
105  return false;
106 }
107 
109 {
110  if(forward)
111  {
112  set<InPort *> s;
113  inPort->getAllRepresentants(s);
114  for(set<InPort *>::iterator iter=s.begin();iter!=s.end();iter++)
115  _node->getRootNode()->edRemoveLink(this,*iter);
116  return -1;
117  }
118  else
119  {
120  set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.find(inPort);
121  if(iter!=_setOfInputDataStreamPort.end())
122  {
123  (*iter)->modified();
124  _setOfInputDataStreamPort.erase(iter);
125  modified();
126  return edGetNumberOfOutLinks();
127  }
128  else
129  throw Exception("OutputDataStreamPort::edRemoveInputPort : link does not exist, unable to remove it");
130  }
131 }
132 
134 {
135  DEBTRACE("OutputDataStreamPort::addInPort");
136  if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME)
137  {
138  string what="not compatible type of port requested during building of link FROM ";
139  what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
140  throw Exception(what);
141  }
142  return edAddInputDataStreamPort(static_cast<InputDataStreamPort*>(inPort));
143 }
144 
146 {
147  set<InputDataStreamPort *>::iterator iter;
148  set<InputDataStreamPort *> vec(_setOfInputDataStreamPort);
149  for( set<InputDataStreamPort *>::iterator iter2=vec.begin();iter2!=vec.end();iter2++)
150  edRemoveInputDataStreamPort(*iter2,true);
152 }
153 
155 {
156  DEBTRACE("OutputDataStreamPort::removeInPort");
157  if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME && !forward)
158  {
159  string what="not compatible type of port requested during destruction of for link FROM ";
160  what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
161  throw Exception(what);
162  }
163  return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);
164 }
165 
167 {
168  return _setOfInputDataStreamPort.find(inPort)!=_setOfInputDataStreamPort.end();
169 }