]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/InputPort.cxx
Salome HOME
4072e7e0149b721ca784abd0dabb5f89e3d854d5
[modules/yacs.git] / src / engine / InputPort.cxx
1 #include "InputPort.hxx"
2 #include "OutPort.hxx"
3 #include "ComposedNode.hxx"
4
5 #include <sstream>
6 #include <iostream>
7 #include <cassert>
8
9 //#define _DEVDEBUG_
10 #include "YacsTrace.hxx"
11
12 using namespace YACS::ENGINE;
13 using namespace std;
14
15 const char InputPort::NAME[]="InputPort";
16
17 InputPort::InputPort(const InputPort& other, Node *newHelder):DataFlowPort(other,newHelder),InPort(other,newHelder),
18                                                               DataPort(other,newHelder),Port(other,newHelder),
19                                                               _initValue(0)
20 {
21   if(other._initValue)
22     _initValue=other._initValue->clone();
23 }
24
25 InputPort::InputPort(const std::string& name, Node *node, TypeCode* type)
26   : DataFlowPort(name,node,type), InPort(name,node,type),DataPort(name,node,type),Port(node), _initValue(0)
27 {
28 }
29
30 string InputPort::getNameOfTypeOfCurrentInstance() const
31 {
32   return NAME;
33 }
34
35 void InputPort::exInit(bool start)
36 {
37   checkBasicConsistency();
38   if(start)
39     exRestoreInit();
40 }
41
42 bool InputPort::isEmpty()
43 {
44   return get()==0;
45 }
46
47 //! Specifies if this port has been \b manually set by the call of InputPort::edInit
48 bool InputPort::edIsManuallyInitialized() const
49 {
50   return _initValue!=0;
51 }
52
53 /*!
54  * Perform a quick and not complete check. Use ComposedNode::CheckConsistency instead.
55  */
56 bool InputPort::edIsInitialized() const
57 {
58   return (edIsManuallyInitialized() or _backLinks.size()!=0 );
59 }
60
61 InputPort::~InputPort()
62 {
63   if(_initValue)
64     _initValue->decrRef();
65 }
66
67 void InputPort::edInit(Any *value)
68 {
69   InputPort *manuallySet=getRuntime()->adapt(this,
70                                              Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME,_type);
71   manuallySet->put((const void *) value);
72   if(manuallySet!=this)
73     delete manuallySet;
74   exSaveInit();
75   modified();
76 }
77
78 void InputPort::edInit(const std::string& impl,const void* value)
79 {
80   InputPort *manuallySet=getRuntime()->adapt(this,impl,_type);
81   manuallySet->put(value);
82   if(manuallySet!=this)
83     delete manuallySet;
84   exSaveInit();
85   modified();
86 }
87
88 //! Removes eventually previous manual initialisation.
89 void InputPort::edRemoveManInit()
90 {
91   if(_initValue)
92     _initValue->decrRef();
93   _initValue=0;
94 }
95
96 //! Check basically that this port has one chance to be specified on time. It's a necessary condition \b not \b sufficient at all.
97 void InputPort::checkBasicConsistency() const throw(Exception)
98 {
99   if(!edIsManuallyInitialized() and _backLinks.size()==0 )
100     {
101       ostringstream stream;
102       stream << "InputPort::checkBasicConsistency : Port " << _name << " of node with name " << _node->getName() << " neither initialized nor linked back";
103       throw Exception(stream.str());
104     }
105 }
106
107 std::string InputPort::dump()
108 {
109   string xmldump = "<value><error> NO_SERIALISATION_AVAILABLE </error></value>";
110   return xmldump;
111 }
112
113 void InputPort::setStringRef(std::string strRef)
114 {
115   _stringRef = strRef;
116 }
117
118 ProxyPort::ProxyPort(InputPort* p):InputPort("Convertor", p->getNode(), p->edGetType()),DataPort("Convertor", p->getNode(), p->edGetType()),
119                                    Port( p->getNode())
120 {
121   _port = p;
122 }
123
124 ProxyPort::~ProxyPort()
125 {
126   //For the moment, there is no case in YACS we have a proxy port in a proxy port
127   //So don't test that. _port may be already deleted. The test is not sure.
128   /*
129   if(_port->isIntermediate())
130     delete _port;
131     */
132 }
133
134 void ProxyPort::edRemoveAllLinksLinkedWithMe() throw(Exception)
135 {
136   _port->edRemoveAllLinksLinkedWithMe();
137 }
138
139 /*!
140  * \note : Should never been called because Node clone process does not duplicate data attributes relative to links.
141  *         This part is done afterwards on relink process.
142  */
143 InputPort *ProxyPort::clone(Node *newHelder) const
144 {
145   throw Exception("ProxyPort::clone : internal error - should never happened");
146 }
147
148 void ProxyPort::edNotifyReferencedBy(OutPort *fromPort)
149 {
150   _port->edNotifyReferencedBy(fromPort);
151 }
152
153 void ProxyPort::edNotifyDereferencedBy(OutPort *fromPort)
154 {
155   _port->edNotifyDereferencedBy(fromPort);
156 }
157
158 std::set<OutPort *> ProxyPort::edSetOutPort() const
159 {
160   return _port->edSetOutPort();
161 }
162
163 int ProxyPort::edGetNumberOfLinks() const
164 {
165   return _port->edGetNumberOfLinks();
166 }
167
168 void ProxyPort::exRestoreInit()
169 {
170   _port->exRestoreInit();
171 }
172
173 void ProxyPort::exSaveInit()
174 {
175   _port->exSaveInit();
176 }
177
178 #ifdef NOCOVARIANT
179 InPort *ProxyPort::getPublicRepresentant()
180 #else
181 InputPort *ProxyPort::getPublicRepresentant()
182 #endif
183
184   return _port->getPublicRepresentant();
185 }
186
187 void *ProxyPort::get() const
188 {
189   return _port->get();
190 }
191
192 void ProxyPort::put(const void *data) throw(ConversionException)
193 {
194   _port->put(data);
195 }
196
197 void ProxyPort::getAllRepresentants(std::set<InPort *>& repr) const
198 {
199   DEBTRACE("ProxyPort::getAllRepresentants");
200   _port->getAllRepresentants(repr);
201 }