]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/CppPorts.cxx
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / runtime / CppPorts.cxx
1
2 #include "TypeConversions.hxx"
3 #include "CppPorts.hxx"
4 #include "Node.hxx"
5
6 #include <iostream>
7 #include <sstream>
8
9 //#define _DEVDEBUG_
10 #include "YacsTrace.hxx"
11
12 using namespace YACS::ENGINE;
13 using namespace std;
14
15 InputCppPort::InputCppPort(const std::string& name, Node *node, TypeCode * type)
16   : InputPort(name, node, type), DataPort(name, node, type), Port(node), _data(NULL),_initData(NULL)
17 {
18 }
19
20 InputCppPort::~InputCppPort()
21 {
22   if(_data)
23     {
24       DEBTRACE("_data ref count: " << _data->getRefCnt());
25       _data->decrRef();
26     }
27 }
28
29 InputCppPort::InputCppPort(const InputCppPort& other, Node *newHelder):InputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder)
30 {
31   _initData=other._initData;
32   _data=other._data;
33 }
34
35 bool InputCppPort::edIsManuallyInitialized() const
36 {
37   return _initData!= NULL;
38 }
39
40 void InputCppPort::edRemoveManInit()
41 {
42   _initData=NULL;
43   InputPort::edRemoveManInit();
44 }
45
46 void InputCppPort::put(const void *data) throw(ConversionException)
47 {
48   put((YACS::ENGINE::Any *)data);
49 }
50
51 void InputCppPort::put(YACS::ENGINE::Any *data) throw(ConversionException)
52 {
53   if(_data)
54     _data->decrRef();
55   _data=data;
56   _data->incrRef();
57   DEBTRACE("value ref count: " << _data->getRefCnt());
58 }
59
60 InputPort *InputCppPort::clone(Node *newHelder) const
61 {
62   return new InputCppPort(*this,newHelder);
63 }
64
65 YACS::ENGINE::Any * InputCppPort::getCppObj() const
66 {
67   return _data;
68 }
69
70 void *InputCppPort::get() const throw(Exception)
71 {
72   return (void*) _data;
73 }
74
75 bool InputCppPort::isEmpty()
76 {
77   return _data == NULL;
78 }
79
80 //! Save the current data value for further reinitialization of the port
81 /*!
82  *
83  */
84 void InputCppPort::exSaveInit()
85 {
86   _initData=_data;
87   //DEBTRACE("_initData.ob refcnt: " << _initData->ob_refcnt);
88   //DEBTRACE("_data.ob refcnt: " << _data->ob_refcnt);
89 }
90
91 //! Restore the saved data value to current data value
92 /*!
93  * If no data has been saved (_initData == 0) don't restore
94  */
95 void InputCppPort::exRestoreInit()
96 {
97   if(!_initData)return;
98   _data=_initData;
99   //DEBTRACE("_initData.ob refcnt: " << _initData->ob_refcnt);
100   //DEBTRACE("_data.ob refcnt: " << _data->ob_refcnt);
101 }
102
103 std::string InputCppPort::dump()
104 {
105   if( _data == NULL)
106     return "<value>None</value>";
107
108   if (edGetType()->kind() != YACS::ENGINE::Objref)
109     return convertNeutralXml(edGetType(), _data);
110     //return convertCppXml(edGetType(), _data);
111   if (! _stringRef.empty())
112     return _stringRef;
113   else 
114     return convertNeutralXml(edGetType(), _data);
115 //     {
116 //       stringstream msg;
117 //       msg << "Cannot retreive init reference string for port " << _name
118 //           << " on node " << _node->getName();
119 //       throw Exception(msg.str());      
120 //     }
121 }
122
123
124 OutputCppPort::OutputCppPort(const std::string& name, Node *node, TypeCode * type)
125   : OutputPort(name, node, type), DataPort(name, node, type), Port(node)
126 {
127   _data = NULL;
128 }
129
130 OutputCppPort::~OutputCppPort()
131 {
132   if(_data)
133     {
134       DEBTRACE("_data ref count: " << _data->getRefCnt());
135       _data->decrRef();
136     }
137 }
138
139 OutputCppPort::OutputCppPort(const OutputCppPort& other, Node *newHelder):OutputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),
140                                                                        _data(NULL)
141 {
142 }
143
144 void OutputCppPort::put(const void *data) throw(ConversionException)
145 {
146   put((YACS::ENGINE::Any *)data);
147 }
148
149 void OutputCppPort::put(YACS::ENGINE::Any *data) throw(ConversionException)
150 {
151   InputPort *p;
152   if(_data)
153     _data->decrRef();
154   _data = data;
155   if(_data)
156     _data->incrRef();
157   OutputPort::put(data);
158 }
159
160 OutputPort *OutputCppPort::clone(Node *newHelder) const
161 {
162   return new OutputCppPort(*this,newHelder);
163 }
164
165 YACS::ENGINE::Any * OutputCppPort::get() const
166 {
167   return _data;
168 }
169
170 std::string OutputCppPort::dump()
171 {
172   if( _data == NULL)
173     return "<value>None</value>";
174   string xmldump = convertNeutralXml(edGetType(), _data);
175   return xmldump;
176 }
177