1 // Copyright (C) 2006-2014 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "AnyInputPort.hxx"
21 #include "TypeCode.hxx"
23 #include "AutoLocker.hxx"
26 #include "YacsTrace.hxx"
31 using namespace YACS::ENGINE;
34 AnyInputPort::AnyInputPort(const std::string& name, Node *node, TypeCode* type, bool canBeNull)
35 : InputPort(name, node, type, canBeNull),
36 DataPort(name, node, type),
42 AnyInputPort::AnyInputPort(const AnyInputPort& other, Node *newHelder)
43 : InputPort(other, newHelder),
44 DataPort(other, newHelder),
45 Port(other, newHelder),
49 _value=other._value->clone();
52 AnyInputPort::~AnyInputPort()
56 DEBTRACE("_value ref count: " << _value->getRefCnt());
61 //! Save the current data value for further reinitialization of the port
65 void AnyInputPort::exSaveInit()
67 if(_initValue) _initValue->decrRef();
69 _initValue->incrRef();
72 //! Restore the saved data value to current data value
74 * If no data has been saved (_initValue == 0) don't restore
76 void AnyInputPort::exRestoreInit()
86 void AnyInputPort::put(Any *data)
88 YACS::BASES::AutoLocker<YACS::BASES::Mutex> lock(&_mutex);
94 DEBTRACE("value ref count: " << _value->getRefCnt());
98 bool AnyInputPort::isEmpty()
103 void *AnyInputPort::get() const
105 return (void *)_value;
108 std::string AnyInputPort::getAsString()
110 YACS::BASES::AutoLocker<YACS::BASES::Mutex> lock(&_mutex);
111 return getRuntime()->convertNeutralAsString(edGetType(),_value);
114 void AnyInputPort::put(const void *data) throw(ConversionException)
119 InputPort *AnyInputPort::clone(Node *newHelder) const
121 return new AnyInputPort(*this,newHelder);
124 std::string AnyInputPort::dump()
128 std::string what="AnyInputPort::get : no value currently in input port with name \""; what+=_name; what+="\"";
129 throw Exception(what);
131 stringstream xmldump;
132 switch (_value->getType()->kind())
135 xmldump << "<value><double>" << _value->getDoubleValue() << "</double></value>" << endl;
138 xmldump << "<value><int>" << _value->getIntValue() << "</int></value>" << endl;
141 xmldump << "<value><boolean>" << _value->getBoolValue() << "</boolean></value>" << endl;
144 xmldump << "<value><string>" << _value->getStringValue() << "</string></value>" << endl;
147 xmldump << "<value><error> NO_SERIALISATION_AVAILABLE </error></value>" << endl;
150 return xmldump.str();