1 // Copyright (C) 2006-2014 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, or (at your option) any later version.
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
20 #include "OutputPort.hxx"
21 #include "ComposedNode.hxx"
22 #include "InputPort.hxx"
23 #include "InPropertyPort.hxx"
24 #include "Runtime.hxx"
31 #include "YacsTrace.hxx"
33 using namespace YACS::ENGINE;
36 const char OutputPort::NAME[]="OutputPort";
38 OutputPort::OutputPort(const OutputPort& other, Node *newHelder):DataFlowPort(other,newHelder),OutPort(other,newHelder),
39 DataPort(other,newHelder),Port(other,newHelder)
43 OutputPort::OutputPort(const std::string& name, Node *node, TypeCode* type):DataFlowPort(name,node,type),OutPort(name,node,type),
44 DataPort(name,node,type),Port(node)
48 string OutputPort::getNameOfTypeOfCurrentInstance() const
53 void OutputPort::edRemoveAllLinksLinkedWithMe() throw(YACS::Exception)
55 set<InputPort *>::iterator iter;
56 set<InputPort *> vec(_setOfInputPort);
57 for( set<InputPort *>::iterator iter2=vec.begin();iter2!=vec.end();iter2++)
58 edRemoveInputPort(*iter2,true);
59 _setOfInputPort.clear();
62 void OutputPort::exInit()
66 void OutputPort::put(const void *data) throw(ConversionException)
68 for(set<InputPort *>::iterator iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
73 * check if output type is an input type and if a data converter exists before link
75 bool OutputPort::edAddInputPort(InputPort *phyPort) throw(YACS::Exception)
77 DEBTRACE("OutputPort::edAddInputPort");
78 if(!isAlreadyInSet(phyPort))
80 InputPort *pwrap = getRuntime()->adapt(phyPort,
81 _node->getImplementation(),
83 _setOfInputPort.insert(pwrap);
92 bool OutputPort::edAddInPropertyPort(InPropertyPort *phyPort) throw(YACS::Exception)
94 DEBTRACE("OutputPort::edAddInPropertyPort");
95 if(!isAlreadyInSet(phyPort))
97 InputPort *pwrap = getRuntime()->adapt(phyPort,
98 _node->getImplementation(),
100 _setOfInputPort.insert(pwrap);
110 * Remove a link by performing not only the deletion in _setOfInputPort but also dereference to the target inputPort.
111 * If 'forward' == true the forward deletion
112 * If 'forward' == false no forward deletion performed, oneway deletion without update 'inputPort' side.
114 int OutputPort::edRemoveInputPort(InputPort *inputPort, bool forward) throw(YACS::Exception)
119 inputPort->getAllRepresentants(s);
121 for(set<InPort *>::iterator iter=s.begin();iter!=s.end();iter++)
124 _node->getRootNode()->edRemoveLink(this,*iter);
131 InPort *publicRepr=inputPort->getPublicRepresentant();
133 InputPort *publicRepr=inputPort->getPublicRepresentant();
135 set<InputPort *>::iterator iter;
136 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
137 if((*iter)->getPublicRepresentant()==publicRepr)
139 if(iter!=_setOfInputPort.end())
142 if((*iter)->isIntermediate())
144 _setOfInputPort.erase(iter);
146 return edGetNumberOfOutLinks();
149 throw Exception("OutputPort::edRemoveInputPort : link does not exist, unable to remove it");
153 OutputPort::~OutputPort()
155 set<InputPort *>::iterator iter;
156 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
162 bool OutputPort::isAlreadyLinkedWith(InPort *with) const
164 InPort *publicRepr=with->getPublicRepresentant();
166 set<InputPort *>::const_iterator iter;
167 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
169 if((*iter)->getPublicRepresentant() == publicRepr)
172 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
173 (*iter)->getAllRepresentants(s);
174 for(set<InPort *>::iterator iter2=s.begin();iter2!=s.end();iter2++)
176 if((*iter2)->getPublicRepresentant() == publicRepr)
182 bool OutputPort::isAlreadyInSet(InputPort *inputPort) const
185 InPort *publicRepr=inputPort->getPublicRepresentant();
187 InputPort *publicRepr=inputPort->getPublicRepresentant();
189 for(set<InputPort *>::const_iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
190 if((*iter)->getPublicRepresentant()==publicRepr)
196 OutputPort::isConnected() const
198 return !_setOfInputPort.empty();
203 * check compatibility of port class ( an inputPort ) before trying to create the link.
205 bool OutputPort::addInPort(InPort *inPort) throw(YACS::Exception)
207 DEBTRACE("OutputPort::addInPort");
208 if(inPort->getNameOfTypeOfCurrentInstance()!=InputPort::NAME &&
209 inPort->getNameOfTypeOfCurrentInstance()!=InPropertyPort::NAME)
211 string what="not compatible type of port requested during building of link FROM ";
212 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
213 throw Exception(what);
215 if (inPort->getNameOfTypeOfCurrentInstance() == InputPort::NAME)
217 return edAddInputPort(static_cast<InputPort*>(inPort));
221 return edAddInPropertyPort(static_cast<InPropertyPort*>(inPort));
226 * check compatibility of port class ( an inputPort ) before trying to remove link WITHOUT forward.
228 int OutputPort::removeInPort(InPort *inPort, bool forward) throw(YACS::Exception)
230 if(inPort->getNameOfTypeOfCurrentInstance()!=InputPort::NAME && !forward)
232 string what="not compatible type of port requested during destruction of for link FROM ";
233 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
234 throw Exception(what);
236 return edRemoveInputPort(static_cast<InputPort*>(inPort),forward);
239 std::set<InPort *> OutputPort::edSetInPort() const
242 for(set<InputPort *>::const_iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
243 (*iter)->getAllRepresentants(s);
247 std::string OutputPort::dump()
249 string xmldump = "<value><error> NO_SERIALISATION_AVAILABLE </error></value>";
254 //! Returns physical links linked to this. Contrary to edSetInPort that returns semantic links.
255 const std::set<InputPort *>& OutputPort::getSetOfPhyLinks() const
257 return _setOfInputPort;
260 //! Check validity of output port. Nothing on base class
261 void OutputPort::checkBasicConsistency() const throw(YACS::Exception)