]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/AnyInputPort.cxx
Salome HOME
3a0e898c44061be0726df723b7bbe74996e1a897
[modules/yacs.git] / src / engine / AnyInputPort.cxx
1 #include "AnyInputPort.hxx"
2 #include <iostream>
3 #include <sstream>
4
5 //#define _DEVDEBUG_
6 #include "YacsTrace.hxx"
7
8 using namespace YACS::ENGINE;
9 using namespace std;
10
11 AnyInputPort::AnyInputPort(const std::string& name, Node *node, TypeCode* type):InputPort(name,node,type),DataPort(name,node,type),Port(node),_value(0)
12 {
13 }
14
15 AnyInputPort::AnyInputPort(const  AnyInputPort& other, Node *newHelder):InputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),_value(0)
16 {
17   if(other._value)
18     _value=other._value->clone();
19 }
20
21 AnyInputPort::~AnyInputPort()
22 {
23   if(_value)
24     {
25       DEBTRACE("_value ref count: " << _value->getRefCnt());
26       _value->decrRef();
27     }
28 }
29
30 //! Save the current data value for further reinitialization of the port
31 /*!
32  *
33  */
34 void AnyInputPort::exSaveInit()
35 {
36   if(_initValue) _initValue->decrRef();
37   _initValue=_value;
38   _initValue->incrRef();
39 }
40
41 //! Restore the saved data value to current data value
42 /*!
43  * If no data has been saved (_initValue == 0) don't restore
44  */
45 void AnyInputPort::exRestoreInit()
46 {
47   if(!_initValue)
48     return;
49   if(_value)
50     _value->decrRef();
51   _value=_initValue;
52   _value->incrRef();
53 }
54
55 void AnyInputPort::put(Any *data)
56 {
57    if(_value)
58     _value->decrRef();
59   _value=data;
60   _value->incrRef();
61   DEBTRACE("value ref count: " << _value->getRefCnt());
62 }
63
64 bool AnyInputPort::isEmpty()
65 {
66   return !_value;
67 }
68
69 void *AnyInputPort::get() const throw(Exception)
70 {
71   if(!_value)
72     {
73       std::string what="AnyInputPort::get : no value currently in input whith name \""; what+=_name; what+="\"";
74       throw Exception(what);
75     }
76   return (void *)_value;
77 }
78
79 void AnyInputPort::put(const void *data) throw(ConversionException)
80 {
81   put((Any *)data);
82 }
83
84 InputPort *AnyInputPort::clone(Node *newHelder) const
85 {
86   return new AnyInputPort(*this,newHelder);
87 }
88
89 std::string AnyInputPort::dump()
90 {
91   if(!_value)
92     {
93       std::string what="AnyInputPort::get : no value currently in input whith name \""; what+=_name; what+="\"";
94       throw Exception(what);
95     }
96   stringstream xmldump;
97   switch (_value->getType()->kind())
98     {
99     case Double:
100       xmldump << "<value><double>" << _value->getDoubleValue() << "</double></value>" << endl;
101       break;
102     case Int:
103       xmldump << "<value><int>" << _value->getIntValue() << "</int></value>" << endl;
104       break;
105     case Bool:
106       xmldump << "<value><boolean>" << _value->getBoolValue() << "</boolean></value>" << endl;
107       break;
108     case String:
109       xmldump << "<value><string>" << _value->getStringValue() << "</string></value>" << endl;
110       break;
111     default:
112       xmldump << "<value><error> NO_SERIALISATION_AVAILABLE </error></value>" << endl;
113       break;
114     }
115   return xmldump.str();
116 }