]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/ConditionInputPort.cxx
Salome HOME
8cc4f3e95ae40dada169eb69ed16f195a06faf51
[modules/yacs.git] / src / engine / ConditionInputPort.cxx
1 #include "ConditionInputPort.hxx"
2 #include "WhileLoop.hxx"
3 #include "OutputPort.hxx"
4 #include <iostream>
5 #include <string>
6
7 using namespace YACS::ENGINE;
8 using namespace std;
9
10 ConditionInputPort::ConditionInputPort(const std::string& name, WhileLoop *node):InputPort(name,node,Runtime::_tc_bool),
11                                                                                  DataPort(name,node,Runtime::_tc_bool),
12                                                                                  Port(node),_outOfScopeBackLink(0),_value(0)
13 {
14 }
15
16 ConditionInputPort::ConditionInputPort(const ConditionInputPort& other, Node *newHelder):InputPort(other,newHelder),
17                                                                                          DataPort(other,newHelder),Port(other,newHelder),
18                                                                                          _outOfScopeBackLink(0),_value(0)
19 {
20   if(other._value)
21     _value=other._value->clone();
22 }
23
24 ConditionInputPort::~ConditionInputPort()
25 {
26   if(_value)
27     _value->decrRef();
28 }
29
30 void ConditionInputPort::exSaveInit()
31 {
32   if(_initValue) _initValue->decrRef();
33   _initValue=_value;
34   _initValue->incrRef();
35 }
36
37 void ConditionInputPort::exRestoreInit()
38 {
39   if(!_initValue)
40     return;
41   if(_value)
42     _value->decrRef();
43   _value=_initValue;
44   _value->incrRef();
45 }
46
47 InputPort *ConditionInputPort::clone(Node *newHelder) const
48 {
49   return new ConditionInputPort(*this,newHelder);
50 }
51
52 bool ConditionInputPort::isLinkedOutOfScope() const
53 {
54   return _outOfScopeBackLink!=0;
55 }
56
57 void ConditionInputPort::edNotifyReferencedBy(OutPort *fromPort)
58 {
59   if(!((ComposedNode*)(_node))->isInMyDescendance(fromPort->getNode()))
60     {
61       if(_outOfScopeBackLink)
62         throw Exception("ConditionInputPort::edNotifyReferenced : already linked from outside");
63       _outOfScopeBackLink=fromPort;
64       return ;
65     }
66   InputPort::edNotifyReferencedBy(fromPort);
67 }
68
69 void ConditionInputPort::edNotifyDereferencedBy(OutPort *fromPort)
70 {
71   if(fromPort==_outOfScopeBackLink)
72     _outOfScopeBackLink=0;
73   else
74     if(!((ComposedNode*)(_node))->isInMyDescendance(fromPort->getNode()))
75       throw Exception("ConditionInputPort::edNotifyDereferencedBy link does not exists");
76   InputPort::edNotifyDereferencedBy(fromPort);
77 }
78
79 void *ConditionInputPort::get() const
80 {
81   return (void *)_value;
82 }
83
84 void ConditionInputPort::put(const void *data) throw(ConversionException)
85 {
86   Any *dataCst=(Any *)data;
87   if(_value)
88     _value->decrRef();
89   _value=dataCst;
90   _value->incrRef();
91 }    
92
93 std::string ConditionInputPort::dump()
94 {
95   string xmldump;
96   if (_value->getBoolValue())
97     xmldump="<value><boolean>true</boolean></value>\n";
98   else
99     xmldump="<value><boolean>false</boolean></value>\n";
100   return xmldump;
101 }