X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fengine%2FInputPort.cxx;h=a1680c9c87d83f13860689406011d1d0752dcedb;hb=bc24bc779f747eda6d9c49b4ee4d390b34b0bb41;hp=37af33bfef396d8d1cdcff594f70cbbac61edbe4;hpb=a84e60a749da66dffb73297fa5082b70b9d62f7d;p=modules%2Fyacs.git diff --git a/src/engine/InputPort.cxx b/src/engine/InputPort.cxx index 37af33bfe..a1680c9c8 100644 --- a/src/engine/InputPort.cxx +++ b/src/engine/InputPort.cxx @@ -1,3 +1,22 @@ +// Copyright (C) 2006-2013 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + #include "InputPort.hxx" #include "OutPort.hxx" #include "ComposedNode.hxx" @@ -14,16 +33,25 @@ using namespace std; const char InputPort::NAME[]="InputPort"; -InputPort::InputPort(const InputPort& other, Node *newHelder):DataFlowPort(other,newHelder),InPort(other,newHelder), - DataPort(other,newHelder),Port(other,newHelder), - _initValue(0) +InputPort::InputPort(const InputPort& other, Node *newHelder) + : DataFlowPort(other, newHelder), + InPort(other, newHelder), + DataPort(other, newHelder), + Port(other, newHelder), + _initValue(0), + _canBeNull(other._canBeNull) { if(other._initValue) _initValue=other._initValue->clone(); } -InputPort::InputPort(const std::string& name, Node *node, TypeCode* type) - : DataFlowPort(name,node,type), InPort(name,node,type),DataPort(name,node,type),Port(node), _initValue(0) +InputPort::InputPort(const std::string& name, Node *node, TypeCode* type, bool canBeNull) + : DataFlowPort(name, node, type), + InPort(name, node, type), + DataPort(name, node, type), + Port(node), + _initValue(0), + _canBeNull(canBeNull) { } @@ -55,7 +83,7 @@ bool InputPort::edIsManuallyInitialized() const */ bool InputPort::edIsInitialized() const { - return (edIsManuallyInitialized() or _backLinks.size()!=0 ); + return (edIsManuallyInitialized() || _backLinks.size()!=0 ); } InputPort::~InputPort() @@ -67,20 +95,45 @@ InputPort::~InputPort() void InputPort::edInit(Any *value) { InputPort *manuallySet=getRuntime()->adapt(this, - Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME,_type); - manuallySet->put((const void *) value); - if(manuallySet!=this) - delete manuallySet; + Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME,_type,true); + try + { + manuallySet->put((const void *) value); + if(manuallySet!=this) + delete manuallySet; + } + catch(ConversionException&) + { + if(manuallySet!=this) + delete manuallySet; + throw; + } exSaveInit(); + modified(); } +//! Initialize the port with an object (value) coming from a world with implementation impl +/*! + * You should be careful when using this method : the caller must set the context according to implementation + * For instance, if implementation is Python, the caller must hold the Global Interpreter Lock (also known as GIL). + */ void InputPort::edInit(const std::string& impl,const void* value) { - InputPort *manuallySet=getRuntime()->adapt(this,impl,_type); - manuallySet->put(value); - if(manuallySet!=this) - delete manuallySet; + InputPort *manuallySet=getRuntime()->adapt(this,impl,_type,true); + try + { + manuallySet->put(value); + if(manuallySet!=this) + delete manuallySet; + } + catch(ConversionException&) + { + if(manuallySet!=this) + delete manuallySet; + throw; + } exSaveInit(); + modified(); } //! Removes eventually previous manual initialisation. @@ -91,10 +144,10 @@ void InputPort::edRemoveManInit() _initValue=0; } -//! Check basisically that this port has one chance to be specified on time. It's a necessary condition \b not \b sufficient at all. -void InputPort::checkBasicConsistency() const throw(Exception) +//! Check basically that this port has one chance to be specified on time. It's a necessary condition \b not \b sufficient at all. +void InputPort::checkBasicConsistency() const throw(YACS::Exception) { - if(!edIsManuallyInitialized() and _backLinks.size()==0 ) + if(!_canBeNull && !edIsManuallyInitialized() && _backLinks.size()==0 ) { ostringstream stream; stream << "InputPort::checkBasicConsistency : Port " << _name << " of node with name " << _node->getName() << " neither initialized nor linked back"; @@ -113,6 +166,11 @@ void InputPort::setStringRef(std::string strRef) _stringRef = strRef; } +bool InputPort::canBeNull() const +{ + return _canBeNull; +} + ProxyPort::ProxyPort(InputPort* p):InputPort("Convertor", p->getNode(), p->edGetType()),DataPort("Convertor", p->getNode(), p->edGetType()), Port( p->getNode()) { @@ -129,7 +187,7 @@ ProxyPort::~ProxyPort() */ } -void ProxyPort::edRemoveAllLinksLinkedWithMe() throw(Exception) +void ProxyPort::edRemoveAllLinksLinkedWithMe() throw(YACS::Exception) { _port->edRemoveAllLinksLinkedWithMe(); } @@ -173,12 +231,16 @@ void ProxyPort::exSaveInit() _port->exSaveInit(); } +#ifdef NOCOVARIANT +InPort *ProxyPort::getPublicRepresentant() +#else InputPort *ProxyPort::getPublicRepresentant() +#endif { return _port->getPublicRepresentant(); } -void *ProxyPort::get() const throw(Exception) +void *ProxyPort::get() const { return _port->get(); } @@ -190,5 +252,6 @@ void ProxyPort::put(const void *data) throw(ConversionException) void ProxyPort::getAllRepresentants(std::set& repr) const { + DEBTRACE("ProxyPort::getAllRepresentants"); _port->getAllRepresentants(repr); }