Version: 8.3.0
CppPorts.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #include "TypeConversions.hxx"
21 #include "CppPorts.hxx"
22 #include "Node.hxx"
23 #include "TypeCode.hxx"
24 
25 #include <iostream>
26 #include <sstream>
27 
28 //#define _DEVDEBUG_
29 #include "YacsTrace.hxx"
30 
31 using namespace YACS::ENGINE;
32 using namespace std;
33 
34 InputCppPort::InputCppPort(const std::string& name, Node *node, TypeCode * type)
35  : InputPort(name, node, type), DataPort(name, node, type), Port(node), _data(NULL),_initData(NULL)
36 {
37 }
38 
40 {
41  if(_data)
42  {
43  DEBTRACE("_data ref count: " << _data->getRefCnt());
44  _data->decrRef();
45  }
46 }
47 
48 InputCppPort::InputCppPort(const InputCppPort& other, Node *newHelder):InputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder)
49 {
50  _initData=other._initData;
51  _data=other._data;
52 }
53 
55 {
56  return _initData!= NULL;
57 }
58 
60 {
61  _initData=NULL;
63 }
64 
65 void InputCppPort::put(const void *data) throw(ConversionException)
66 {
67  put((YACS::ENGINE::Any *)data);
68 }
69 
71 {
72  if(_data)
73  _data->decrRef();
74  _data=data;
75  _data->incrRef();
76  DEBTRACE("value ref count: " << _data->getRefCnt());
77 }
78 
80 {
81  return new InputCppPort(*this,newHelder);
82 }
83 
85 {
86  return _data;
87 }
88 
89 void *InputCppPort::get() const throw(YACS::Exception)
90 {
91  return (void*) _data;
92 }
93 
95 {
96  return _data == NULL;
97 }
98 
100 
104 {
106  //DEBTRACE("_initData.ob refcnt: " << _initData->ob_refcnt);
107  //DEBTRACE("_data.ob refcnt: " << _data->ob_refcnt);
108 }
109 
111 
115 {
116  if(!_initData)return;
118  //DEBTRACE("_initData.ob refcnt: " << _initData->ob_refcnt);
119  //DEBTRACE("_data.ob refcnt: " << _data->ob_refcnt);
120 }
121 
122 std::string InputCppPort::dump()
123 {
124  if( _data == NULL)
125  return "<value>None</value>";
126 
127  if (edGetType()->kind() != YACS::ENGINE::Objref)
128  return convertNeutralXml(edGetType(), _data);
129  //return convertCppXml(edGetType(), _data);
130  if (! _stringRef.empty())
131  return _stringRef;
132  else
133  return convertNeutralXml(edGetType(), _data);
134 // {
135 // stringstream msg;
136 // msg << "Cannot retreive init reference string for port " << _name
137 // << " on node " << _node->getName();
138 // throw Exception(msg.str());
139 // }
140 }
141 
142 
143 OutputCppPort::OutputCppPort(const std::string& name, Node *node, TypeCode * type)
144  : OutputPort(name, node, type), DataPort(name, node, type), Port(node)
145 {
146  _data = NULL;
147 }
148 
150 {
151  if(_data)
152  {
153  DEBTRACE("_data ref count: " << _data->getRefCnt());
154  _data->decrRef();
155  }
156 }
157 
158 OutputCppPort::OutputCppPort(const OutputCppPort& other, Node *newHelder):OutputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),
159  _data(NULL)
160 {
161 }
162 
163 void OutputCppPort::put(const void *data) throw(ConversionException)
164 {
165  put((YACS::ENGINE::Any *)data);
166 }
167 
169 {
170  InputPort *p;
171  if(_data)
172  _data->decrRef();
173  _data = data;
174  if(_data)
175  _data->incrRef();
176  OutputPort::put(data);
177 }
178 
180 {
181  return new OutputCppPort(*this,newHelder);
182 }
183 
185 {
186  return _data;
187 }
188 
189 std::string OutputCppPort::dump()
190 {
191  if( _data == NULL)
192  return "<value>None</value>";
193  string xmldump = convertNeutralXml(edGetType(), _data);
194  return xmldump;
195 }
196