1 // Copyright (C) 2006-2008 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "OutputPort.hxx"
20 #include "ComposedNode.hxx"
21 #include "InputPort.hxx"
22 #include "Runtime.hxx"
29 #include "YacsTrace.hxx"
31 using namespace YACS::ENGINE;
34 const char OutputPort::NAME[]="OutputPort";
36 OutputPort::OutputPort(const OutputPort& other, Node *newHelder):DataFlowPort(other,newHelder),OutPort(other,newHelder),
37 DataPort(other,newHelder),Port(other,newHelder)
41 OutputPort::OutputPort(const std::string& name, Node *node, TypeCode* type):DataFlowPort(name,node,type),OutPort(name,node,type),
42 DataPort(name,node,type),Port(node)
46 string OutputPort::getNameOfTypeOfCurrentInstance() const
51 void OutputPort::edRemoveAllLinksLinkedWithMe() throw(Exception)
53 set<InputPort *>::iterator iter;
54 set<InputPort *> vec(_setOfInputPort);
55 for( set<InputPort *>::iterator iter2=vec.begin();iter2!=vec.end();iter2++)
56 edRemoveInputPort(*iter2,true);
57 _setOfInputPort.clear();
60 void OutputPort::exInit()
64 void OutputPort::put(const void *data) throw(ConversionException)
66 for(set<InputPort *>::iterator iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
71 * check if output type is an input type and if a data converter exists before link
73 bool OutputPort::edAddInputPort(InputPort *phyPort) throw(Exception)
75 DEBTRACE("OutputPort::edAddInputPort");
76 if(!isAlreadyInSet(phyPort))
78 InputPort *pwrap = getRuntime()->adapt(phyPort,
79 _node->getImplementation(),
81 _setOfInputPort.insert(pwrap);
91 * Remove a link by performing not only the deletion in _setOfInputPort but also dereference to the target inputPort.
92 * If 'forward' == true the forward deletion
93 * If 'forward' == false no forward deletion performed, oneway deletion without update 'inputPort' side.
95 int OutputPort::edRemoveInputPort(InputPort *inputPort, bool forward) throw(Exception)
100 inputPort->getAllRepresentants(s);
102 for(set<InPort *>::iterator iter=s.begin();iter!=s.end();iter++)
105 _node->getRootNode()->edRemoveLink(this,*iter);
112 InPort *publicRepr=inputPort->getPublicRepresentant();
114 InputPort *publicRepr=inputPort->getPublicRepresentant();
116 set<InputPort *>::iterator iter;
117 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
118 if((*iter)->getPublicRepresentant()==publicRepr)
120 if(iter!=_setOfInputPort.end())
123 if((*iter)->isIntermediate())
125 _setOfInputPort.erase(iter);
127 return edGetNumberOfOutLinks();
130 throw Exception("OutputPort::edRemoveInputPort : link does not exist, unable to remove it");
134 OutputPort::~OutputPort()
136 set<InputPort *>::iterator iter;
137 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
143 bool OutputPort::isAlreadyLinkedWith(InPort *with) const
145 InPort *publicRepr=with->getPublicRepresentant();
147 set<InputPort *>::iterator iter;
148 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
150 if((*iter)->getPublicRepresentant() == publicRepr)
153 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
154 (*iter)->getAllRepresentants(s);
155 for(set<InPort *>::iterator iter2=s.begin();iter2!=s.end();iter2++)
157 if((*iter2)->getPublicRepresentant() == publicRepr)
163 bool OutputPort::isAlreadyInSet(InputPort *inputPort) const
166 InPort *publicRepr=inputPort->getPublicRepresentant();
168 InputPort *publicRepr=inputPort->getPublicRepresentant();
170 for(set<InputPort *>::const_iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
171 if((*iter)->getPublicRepresentant()==publicRepr)
177 * check compatibility of port class ( an inputPort ) before trying to create the link.
179 bool OutputPort::addInPort(InPort *inPort) throw(Exception)
181 DEBTRACE("OutputPort::addInPort");
182 if(inPort->getNameOfTypeOfCurrentInstance()!=InputPort::NAME)
184 string what="not compatible type of port requested during building of link FROM ";
185 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
186 throw Exception(what);
188 return edAddInputPort(static_cast<InputPort*>(inPort));
192 * check compatibility of port class ( an inputPort ) before trying to remove link WITHOUT forward.
194 int OutputPort::removeInPort(InPort *inPort, bool forward) throw(Exception)
196 if(inPort->getNameOfTypeOfCurrentInstance()!=InputPort::NAME && !forward)
198 string what="not compatible type of port requested during destruction of for link FROM ";
199 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
200 throw Exception(what);
202 return edRemoveInputPort(static_cast<InputPort*>(inPort),forward);
205 std::set<InPort *> OutputPort::edSetInPort() const
208 for(set<InputPort *>::iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
209 (*iter)->getAllRepresentants(s);
213 std::string OutputPort::dump()
215 string xmldump = "<value><error> NO_SERIALISATION_AVAILABLE </error></value>";
220 //! Returns physical links linked to this. Contrary to edSetInPort that returns semantic links.
221 const std::set<InputPort *>& OutputPort::getSetOfPhyLinks() const
223 return _setOfInputPort;
226 //! Check validity of output port. Nothing on base class
227 void OutputPort::checkBasicConsistency() const throw(Exception)