Version: 9.16.0
AnyInputPort.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 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 "AnyInputPort.hxx"
21#include "TypeCode.hxx"
22#include "Mutex.hxx"
23#include "AutoLocker.hxx"
24
25//#define _DEVDEBUG_
26#include "YacsTrace.hxx"
27
28#include <iostream>
29#include <iomanip>
30#include <sstream>
31
32using namespace YACS::ENGINE;
33using namespace std;
34
35AnyInputPort::AnyInputPort(const std::string& name, Node *node, TypeCode* type, bool canBeNull)
36 : InputPort(name, node, type, canBeNull),
37 DataPort(name, node, type),
38 Port(node),
39 _value(0)
40{
41}
42
44 : InputPort(other, newHelder),
45 DataPort(other, newHelder),
46 Port(other, newHelder),
47 _value(0)
48{
49 if(other._value)
50 _value=other._value->clone();
51}
52
54{
55 if(_value)
56 {
57 DEBTRACE("_value ref count: " << _value->getRefCnt());
58 _value->decrRef();
59 }
60}
61
63
67{
71}
72
74
78{
79 if(!_initValue)
80 return;
81 if(_value)
82 _value->decrRef();
84 _value->incrRef();
85}
86
88{
89 if(_value)
90 _value->decrRef();
91 _value = nullptr;
92}
93
95{
98}
99
101{
104 _value=data;
105 if (_value)
106 {
107 _value->incrRef();
108 DEBTRACE("value ref count: " << _value->getRefCnt());
109 }
110}
111
113{
114 return !_value;
115}
116
117void *AnyInputPort::get() const
118{
119 return (void *)_value;
120}
121
123{
126}
127
128void AnyInputPort::put(const void *data)
129{
130 put((Any *)data);
131}
132
134{
135 return new AnyInputPort(*this,newHelder);
136}
137
139{
140 if(!_value)
141 {
142 std::string what="AnyInputPort::get : no value currently in input port with name \""; what+=_name; what+="\"";
143 throw Exception(what);
144 }
145 stringstream xmldump;
146 switch (_value->getType()->kind())
147 {
148 case Double:
149 xmldump << "<value><double>" << setprecision(16) << _value->getDoubleValue() << "</double></value>" << endl;
150 break;
151 case Int:
152 xmldump << "<value><int>" << _value->getIntValue() << "</int></value>" << endl;
153 break;
154 case Bool:
155 xmldump << "<value><boolean>" << _value->getBoolValue() << "</boolean></value>" << endl;
156 break;
157 case String:
158 xmldump << "<value><string>" << _value->getStringValue() << "</string></value>" << endl;
159 break;
160 default:
161 xmldump << "<value><error> NO_SERIALISATION_AVAILABLE </error></value>" << endl;
162 break;
163 }
164 return xmldump.str();
165}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
void exRestoreInit()
Restore the saved data value to current data value.
virtual std::string getAsString()
returns port value as a string that can be used in a GUI for example
YACS::BASES::Mutex _mutex
AnyInputPort(const std::string &name, Node *node, TypeCode *type, bool canBeNull=false)
InputPort * clone(Node *newHelder) const
void releaseData() override
void exSaveInit()
Save the current data value for further reinitialization of the port.
: Interface for management of storage of data formated dynamically in its TypeCode....
Definition: Any.hxx:79
virtual std::string getStringValue() const =0
virtual int getIntValue() const =0
virtual double getDoubleValue() const =0
virtual bool getBoolValue() const =0
const TypeCode * getType() const
Definition: Any.hxx:85
virtual Any * clone() const =0
TypeCode * edGetType() const
Definition: DataPort.hxx:53
Base class for Input Ports.
Definition: InputPort.hxx:44
Base class for all nodes.
Definition: Node.hxx:70
Base class for all ports.
Definition: Port.hxx:43
unsigned int getRefCnt() const
Definition: RefCounter.hxx:32
virtual std::string convertNeutralAsString(TypeCode *type, Any *data)
Convert a YACS::ENGINE::Any object to a string to be used in GUI for example.
Definition: Runtime.cxx:369
Base class for all type objects.
Definition: TypeCode.hxx:68
DynType kind() const
Definition: TypeCode.cxx:47
YACSLIBENGINE_EXPORT Runtime * getRuntime()
Definition: Runtime.cxx:61