Version: 9.15.0
InputPort.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 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 "InputPort.hxx"
21 #include "OutPort.hxx"
22 #include "ComposedNode.hxx"
23 
24 #include <sstream>
25 #include <iostream>
26 #include <cassert>
27 
28 //#define _DEVDEBUG_
29 #include "YacsTrace.hxx"
30 
31 using namespace YACS::ENGINE;
32 using namespace std;
33 
34 const char InputPort::NAME[]="InputPort";
35 
36 InputPort::InputPort(const InputPort& other, Node *newHelder)
37  : DataFlowPort(other, newHelder),
38  InPort(other, newHelder),
39  DataPort(other, newHelder),
40  Port(other, newHelder),
41  _initValue(0),
42  _canBeNull(other._canBeNull)
43 {
44  if(other._initValue)
45  _initValue=other._initValue->clone();
46 }
47 
48 InputPort::InputPort(const std::string& name, Node *node, TypeCode* type, bool canBeNull)
49  : DataFlowPort(name, node, type),
50  InPort(name, node, type),
51  DataPort(name, node, type),
52  Port(node),
53  _initValue(0),
54  _canBeNull(canBeNull)
55 {
56 }
57 
59 {
60  return NAME;
61 }
62 
63 void InputPort::exInit(bool start)
64 {
66  if(start)
67  exRestoreInit();
68 }
69 
71 {
72  return get()==0;
73 }
74 
77 {
78  return _initValue!=0;
79 }
80 
85 {
86  return (edIsManuallyInitialized() || _backLinks.size()!=0 );
87 }
88 
90 {
91  if(_initValue)
93 }
94 
95 void InputPort::edInit(Any *value)
96 {
97  InputPort *manuallySet=getRuntime()->adapt(this,
99  try
100  {
101  manuallySet->put((const void *) value);
102  if(manuallySet!=this)
103  delete manuallySet;
104  }
105  catch(ConversionException&)
106  {
107  if(manuallySet!=this)
108  delete manuallySet;
109  throw;
110  }
111  exSaveInit();
112  modified();
113 }
114 
116 
120 void InputPort::edInit(const std::string& impl,const void* value)
121 {
122  InputPort *manuallySet=getRuntime()->adapt(this,impl,_type,true);
123  try
124  {
125  manuallySet->put(value);
126  if(manuallySet!=this)
127  delete manuallySet;
128  }
129  catch(ConversionException&)
130  {
131  if(manuallySet!=this)
132  delete manuallySet;
133  throw;
134  }
135  exSaveInit();
136  modified();
137 }
138 
141 {
142  if(_initValue)
143  _initValue->decrRef();
144  _initValue=0;
145 }
146 
149 {
150  if(!_canBeNull && !edIsManuallyInitialized() && _backLinks.size()==0 )
151  {
152  ostringstream stream;
153  stream << "InputPort::checkBasicConsistency : Port " << _name << " of node with name " << _node->getName() << " neither initialized nor linked back";
154  throw Exception(stream.str());
155  }
156 }
157 
158 std::string InputPort::dump()
159 {
160  string xmldump = "<value><error> NO_SERIALISATION_AVAILABLE </error></value>";
161  return xmldump;
162 }
163 
165 {
166  return dump();
167 }
168 
169 void InputPort::setStringRef(std::string strRef)
170 {
171  _stringRef = strRef;
172 }
173 
175 {
176  return _canBeNull;
177 }
178 
179 ProxyPort::ProxyPort(InputPort* p):InputPort("Convertor", p->getNode(), p->edGetType()),DataPort("Convertor", p->getNode(), p->edGetType()),
180  Port( p->getNode())
181 {
182  _port = p;
183 }
184 
186 {
187  //For the moment, there is no case in YACS we have a proxy port in a proxy port
188  //So don't test that. _port may be already deleted. The test is not sure.
189  /*
190  if(_port->isIntermediate())
191  delete _port;
192  */
193 }
194 
196 {
198 }
199 
204 InputPort *ProxyPort::clone(Node *newHelder) const
205 {
206  throw Exception("ProxyPort::clone : internal error - should never happened");
207 }
208 
209 void ProxyPort::edNotifyReferencedBy(OutPort *fromPort, bool isLoopProof)
210 {
211  _port->edNotifyReferencedBy(fromPort,isLoopProof);
212 }
213 
215 {
216  _port->edNotifyDereferencedBy(fromPort);
217 }
218 
219 std::set<OutPort *> ProxyPort::edSetOutPort() const
220 {
221  return _port->edSetOutPort();
222 }
223 
225 {
226  return _port->edGetNumberOfLinks();
227 }
228 
230 {
231  _port->exRestoreInit();
232 }
233 
235 {
236  _port->exSaveInit();
237 }
238 
239 #ifdef NOCOVARIANT
241 #else
243 #endif
244 {
245  return _port->getPublicRepresentant();
246 }
247 
248 void *ProxyPort::get() const
249 {
250  return _port->get();
251 }
252 
254 {
255  _port->releaseData();
256 }
257 
258 void ProxyPort::put(const void *data)
259 {
260  _port->put(data);
261 }
262 
263 void ProxyPort::getAllRepresentants(std::set<InPort *>& repr) const
264 {
265  DEBTRACE("ProxyPort::getAllRepresentants");
266  _port->getAllRepresentants(repr);
267 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
: Interface for management of storage of data formated dynamically in its TypeCode....
Definition: Any.hxx:79
virtual Any * clone() const =0
virtual std::set< OutPort * > edSetOutPort() const
Returns physical backlinks NOT user backlinks.
Definition: InPort.cxx:65
virtual void edNotifyDereferencedBy(OutPort *fromPort)
Definition: InPort.cxx:102
virtual int edGetNumberOfLinks() const
Returns number of physical backlinks NOT number of user backlinks.
Definition: InPort.cxx:45
void edRemoveAllLinksLinkedWithMe()
Definition: InPort.cxx:50
friend class ProxyPort
Definition: InPort.hxx:50
std::set< std::pair< OutPort *, bool > > _backLinks
Definition: InPort.hxx:78
virtual void getAllRepresentants(std::set< InPort * > &repr) const
Definition: InPort.cxx:110
virtual void edNotifyReferencedBy(OutPort *fromPort, bool isLoopProof=true)
Definition: InPort.cxx:93
Base class for Input Ports.
Definition: InputPort.hxx:44
std::string getNameOfTypeOfCurrentInstance() const
Definition: InputPort.cxx:58
virtual void put(const void *data)=0
virtual std::string dump()
Definition: InputPort.cxx:158
virtual void exInit(bool start)
Definition: InputPort.cxx:63
virtual void edRemoveManInit()
Removes eventually previous manual initialisation.
Definition: InputPort.cxx:140
bool canBeNull() const
Definition: InputPort.cxx:174
std::string _stringRef
Definition: InputPort.hxx:90
virtual InputPort * getPublicRepresentant()
returns the final physical port behind 'this'.
Definition: InputPort.hxx:57
static const char NAME[]
Definition: InputPort.hxx:48
virtual void setStringRef(std::string strRef)
Definition: InputPort.cxx:169
bool edIsInitialized() const
soon deprecated
Definition: InputPort.cxx:84
virtual bool edIsManuallyInitialized() const
Specifies if this port has been manually set by the call of InputPort::edInit.
Definition: InputPort.cxx:76
virtual bool isEmpty()
Definition: InputPort.cxx:70
virtual void * get() const =0
virtual void exRestoreInit()=0
InputPort(const InputPort &other, Node *newHelder)
Definition: InputPort.cxx:36
virtual void exSaveInit()=0
void edInit(T value)
Definition: InputPort.hxx:129
virtual void releaseData()=0
virtual std::string getHumanRepr()
Definition: InputPort.cxx:164
virtual void checkBasicConsistency() const
Check basically that this port has one chance to be specified on time. It's a necessary condition not...
Definition: InputPort.cxx:148
Base class for all nodes.
Definition: Node.hxx:70
const std::string & getName() const
Definition: Node.hxx:125
Base class for all ports.
Definition: Port.hxx:43
void modified()
Definition: Port.cxx:53
Node * _node
Definition: Port.hxx:55
void releaseData() override
Definition: InputPort.cxx:253
void * get() const
Definition: InputPort.cxx:248
void edNotifyDereferencedBy(OutPort *fromPort)
Definition: InputPort.cxx:214
InputPort * clone(Node *newHelder) const
Definition: InputPort.cxx:204
void edRemoveAllLinksLinkedWithMe()
Definition: InputPort.cxx:195
void getAllRepresentants(std::set< InPort * > &repr) const
Definition: InputPort.cxx:263
InputPort * getPublicRepresentant()
returns the final physical port behind 'this'.
Definition: InputPort.cxx:242
int edGetNumberOfLinks() const
Returns number of physical backlinks NOT number of user backlinks.
Definition: InputPort.cxx:224
std::set< OutPort * > edSetOutPort() const
Returns physical backlinks NOT user backlinks.
Definition: InputPort.cxx:219
virtual void put(const void *data)
Definition: InputPort.cxx:258
void edNotifyReferencedBy(OutPort *fromPort, bool isLoopProof=true) override
Definition: InputPort.cxx:209
static const char RUNTIME_ENGINE_INTERACTION_IMPL_NAME[]
Definition: Runtime.hxx:135
virtual InputPort * adapt(InputPort *source, const std::string &impl, TypeCode *type, bool init=false)=0
Base class for all type objects.
Definition: TypeCode.hxx:68
Proc * p
Definition: driver.cxx:216
YACSLIBENGINE_EXPORT Runtime * getRuntime()
Definition: Runtime.cxx:61