Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[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 }
76
77 void InputPort::edInit(const std::string& impl,const void* value)
78 {
79   InputPort *manuallySet=getRuntime()->adapt(this,impl,_type);
80   manuallySet->put(value);
81   if(manuallySet!=this)
82     delete manuallySet;
83   exSaveInit();
84 }
85
86 //! Removes eventually previous manual initialisation.
87 void InputPort::edRemoveManInit()
88 {
89   if(_initValue)
90     _initValue->decrRef();
91   _initValue=0;
92 }
93
94 //! Check basisically that this port has one chance to be specified on time. It's a necessary condition \b not \b sufficient at all.
95 void InputPort::checkBasicConsistency() const throw(Exception)
96 {
97   if(!edIsManuallyInitialized() and _backLinks.size()==0 )
98     {
99       ostringstream stream;
100       stream << "InputPort::checkBasicConsistency : Port " << _name << " of node with name " << _node->getName() << " neither initialized nor linked back";
101       throw Exception(stream.str());
102     }
103 }
104
105 std::string InputPort::dump()
106 {
107   string xmldump = "<value><error> NO_SERIALISATION_AVAILABLE </error></value>";
108   return xmldump;
109 }
110
111 void InputPort::setStringRef(std::string strRef)
112 {
113   _stringRef = strRef;
114 }
115
116 ProxyPort::ProxyPort(InputPort* p):InputPort("Convertor", p->getNode(), p->edGetType()),DataPort("Convertor", p->getNode(), p->edGetType()),
117                                    Port( p->getNode())
118 {
119   _port = p;
120 }
121
122 ProxyPort::~ProxyPort()
123 {
124   //For the moment, there is no case in YACS we have a proxy port in a proxy port
125   //So don't test that. _port may be already deleted. The test is not sure.
126   /*
127   if(_port->isIntermediate())
128     delete _port;
129     */
130 }
131
132 void ProxyPort::edRemoveAllLinksLinkedWithMe() throw(Exception)
133 {
134   _port->edRemoveAllLinksLinkedWithMe();
135 }
136
137 /*!
138  * \note : Should never been called because Node clone process does not duplicate data attributes relative to links.
139  *         This part is done afterwards on relink process.
140  */
141 InputPort *ProxyPort::clone(Node *newHelder) const
142 {
143   throw Exception("ProxyPort::clone : internal error - should never happened");
144 }
145
146 void ProxyPort::edNotifyReferencedBy(OutPort *fromPort)
147 {
148   _port->edNotifyReferencedBy(fromPort);
149 }
150
151 void ProxyPort::edNotifyDereferencedBy(OutPort *fromPort)
152 {
153   _port->edNotifyDereferencedBy(fromPort);
154 }
155
156 std::set<OutPort *> ProxyPort::edSetOutPort() const
157 {
158   return _port->edSetOutPort();
159 }
160
161 int ProxyPort::edGetNumberOfLinks() const
162 {
163   return _port->edGetNumberOfLinks();
164 }
165
166 void ProxyPort::exRestoreInit()
167 {
168   _port->exRestoreInit();
169 }
170
171 void ProxyPort::exSaveInit()
172 {
173   _port->exSaveInit();
174 }
175
176 InputPort *ProxyPort::getPublicRepresentant()
177
178   return _port->getPublicRepresentant();
179 }
180
181 void *ProxyPort::get() const throw(Exception)
182 {
183   return _port->get();
184 }
185
186 void ProxyPort::put(const void *data) throw(ConversionException)
187 {
188   _port->put(data);
189 }
190
191 void ProxyPort::getAllRepresentants(std::set<InPort *>& repr) const
192 {
193   _port->getAllRepresentants(repr);
194 }