Version: 9.15.0
CppPorts.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 CEA, EDF
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)
66 {
67  put((YACS::ENGINE::Any *)data);
68 }
69 
71 {
72  if(_data)
73  _data->decrRef();
74  _data=nullptr;
75 }
76 
78 {
79  releaseData();
80  _data=data;
81  _data->incrRef();
82  DEBTRACE("value ref count: " << _data->getRefCnt());
83 }
84 
86 {
87  return new InputCppPort(*this,newHelder);
88 }
89 
91 {
92  return _data;
93 }
94 
95 void *InputCppPort::get() const
96 {
97  return (void*) _data;
98 }
99 
101 {
102  return _data == NULL;
103 }
104 
106 
110 {
112  //DEBTRACE("_initData.ob refcnt: " << _initData->ob_refcnt);
113  //DEBTRACE("_data.ob refcnt: " << _data->ob_refcnt);
114 }
115 
117 
121 {
122  if(!_initData)return;
124  //DEBTRACE("_initData.ob refcnt: " << _initData->ob_refcnt);
125  //DEBTRACE("_data.ob refcnt: " << _data->ob_refcnt);
126 }
127 
128 std::string InputCppPort::dump()
129 {
130  if( _data == NULL)
131  return "<value>None</value>";
132 
133  if (edGetType()->kind() != YACS::ENGINE::Objref)
134  return convertNeutralXml(edGetType(), _data);
135  //return convertCppXml(edGetType(), _data);
136  if (! _stringRef.empty())
137  return _stringRef;
138  else
139  return convertNeutralXml(edGetType(), _data);
140 // {
141 // stringstream msg;
142 // msg << "Cannot retreive init reference string for port " << _name
143 // << " on node " << _node->getName();
144 // throw Exception(msg.str());
145 // }
146 }
147 
148 
149 OutputCppPort::OutputCppPort(const std::string& name, Node *node, TypeCode * type)
150  : OutputPort(name, node, type), DataPort(name, node, type), Port(node)
151 {
152  _data = NULL;
153 }
154 
156 {
157  if(_data)
158  {
159  DEBTRACE("_data ref count: " << _data->getRefCnt());
160  _data->decrRef();
161  }
162 }
163 
164 OutputCppPort::OutputCppPort(const OutputCppPort& other, Node *newHelder):OutputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),
165  _data(NULL)
166 {
167 }
168 
169 void OutputCppPort::put(const void *data)
170 {
171  put((YACS::ENGINE::Any *)data);
172 }
173 
175 {
176  InputPort *p;
177  if(_data)
178  _data->decrRef();
179  _data = data;
180  if(_data)
181  _data->incrRef();
182  OutputPort::put(data);
183 }
184 
186 {
187  return new OutputCppPort(*this,newHelder);
188 }
189 
191 {
192  return _data;
193 }
194 
195 std::string OutputCppPort::dump()
196 {
197  if( _data == NULL)
198  return "<value>None</value>";
199  string xmldump = convertNeutralXml(edGetType(), _data);
200  return xmldump;
201 }
202 
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
: Interface for management of storage of data formated dynamically in its TypeCode....
Definition: Any.hxx:79
TypeCode * edGetType() const
Definition: DataPort.hxx:53
Class for C++ Ports.
Definition: CppPorts.hxx:40
virtual YACS::ENGINE::Any * getCppObj() const
Definition: CppPorts.cxx:90
InputPort * clone(Node *newHelder) const
Definition: CppPorts.cxx:85
InputCppPort(const std::string &name, Node *node, TypeCode *type)
Definition: CppPorts.cxx:34
bool edIsManuallyInitialized() const
Specifies if this port has been manually set by the call of InputPort::edInit.
Definition: CppPorts.cxx:54
virtual void exRestoreInit()
Restore the saved data value to current data value.
Definition: CppPorts.cxx:120
void edRemoveManInit()
Removes eventually previous manual initialisation.
Definition: CppPorts.cxx:59
virtual bool isEmpty()
Definition: CppPorts.cxx:100
virtual void exSaveInit()
Save the current data value for further reinitialization of the port.
Definition: CppPorts.cxx:109
YACS::ENGINE::Any * _initData
Definition: CppPorts.hxx:59
void releaseData() override
Definition: CppPorts.cxx:70
virtual std::string dump()
Definition: CppPorts.cxx:128
virtual void put(const void *data)
Definition: CppPorts.cxx:65
YACS::ENGINE::Any * _data
Definition: CppPorts.hxx:58
Base class for Input Ports.
Definition: InputPort.hxx:44
virtual void edRemoveManInit()
Removes eventually previous manual initialisation.
Definition: InputPort.cxx:140
std::string _stringRef
Definition: InputPort.hxx:90
Base class for all nodes.
Definition: Node.hxx:70
OutputPort * clone(Node *newHelder) const
Definition: CppPorts.cxx:185
virtual std::string dump()
Definition: CppPorts.cxx:195
virtual YACS::ENGINE::Any * get() const
Definition: CppPorts.cxx:190
YACS::ENGINE::Any * _data
Definition: CppPorts.hxx:74
virtual void put(const void *data)
Definition: CppPorts.cxx:169
OutputCppPort(const std::string &name, Node *node, TypeCode *type)
Definition: CppPorts.cxx:149
virtual void put(const void *data)
Definition: OutputPort.cxx:66
Base class for all ports.
Definition: Port.hxx:43
unsigned int getRefCnt() const
Definition: RefCounter.hxx:32
Base class for all type objects.
Definition: TypeCode.hxx:68
Proc * p
Definition: driver.cxx:216
std::string convertNeutralXml(const TypeCode *t, YACS::ENGINE::Any *data)