Version: 8.3.0
InputPort.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 "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 
210 {
211  _port->edNotifyReferencedBy(fromPort);
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 
253 void ProxyPort::put(const void *data) throw(ConversionException)
254 {
255  _port->put(data);
256 }
257 
258 void ProxyPort::getAllRepresentants(std::set<InPort *>& repr) const
259 {
260  DEBTRACE("ProxyPort::getAllRepresentants");
261  _port->getAllRepresentants(repr);
262 }