Salome HOME
Solve problem of non install of includes of src/engine/.hxx into install/include...
[modules/yacs.git] / src / engine / AnyInputPort.cxx
index 7aa5602ae88fb4f761a6dc6ec3fb5944a4c8d0e2..3db6b63297ba49803acdba02210702e1bf6d2428 100644 (file)
@@ -1,19 +1,50 @@
+// Copyright (C) 2006-2016  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "AnyInputPort.hxx"
 #include "TypeCode.hxx"
-#include <iostream>
-#include <sstream>
+#include "Mutex.hxx"
+#include "AutoLocker.hxx"
 
 //#define _DEVDEBUG_
 #include "YacsTrace.hxx"
 
+#include <iostream>
+#include <iomanip>
+#include <sstream>
+
 using namespace YACS::ENGINE;
 using namespace std;
 
-AnyInputPort::AnyInputPort(const std::string& name, Node *node, TypeCode* type):InputPort(name,node,type),DataPort(name,node,type),Port(node),_value(0)
+AnyInputPort::AnyInputPort(const std::string& name, Node *node, TypeCode* type, bool canBeNull)
+  : InputPort(name, node, type, canBeNull),
+    DataPort(name, node, type),
+    Port(node),
+    _value(0)
 {
 }
 
-AnyInputPort::AnyInputPort(const  AnyInputPort& other, Node *newHelder):InputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),_value(0)
+AnyInputPort::AnyInputPort(const AnyInputPort& other, Node *newHelder)
+  : InputPort(other, newHelder),
+    DataPort(other, newHelder),
+    Port(other, newHelder),
+    _value(0)
 {
   if(other._value)
     _value=other._value->clone();
@@ -55,11 +86,14 @@ void AnyInputPort::exRestoreInit()
 
 void AnyInputPort::put(Any *data)
 {
-   if(_value)
+  YACS::BASES::AutoLocker<YACS::BASES::Mutex> lock(&_mutex);
+  if(_value)
     _value->decrRef();
   _value=data;
-  _value->incrRef();
-  DEBTRACE("value ref count: " << _value->getRefCnt());
+  if (_value) {
+    _value->incrRef();
+    DEBTRACE("value ref count: " << _value->getRefCnt());
+  }
 }
 
 bool AnyInputPort::isEmpty()
@@ -72,6 +106,12 @@ void *AnyInputPort::get() const
   return (void *)_value;
 }
 
+std::string AnyInputPort::getAsString()
+{
+  YACS::BASES::AutoLocker<YACS::BASES::Mutex> lock(&_mutex);
+  return getRuntime()->convertNeutralAsString(edGetType(),_value);
+}
+
 void AnyInputPort::put(const void *data) throw(ConversionException)
 {
   put((Any *)data);
@@ -86,14 +126,14 @@ std::string AnyInputPort::dump()
 {
   if(!_value)
     {
-      std::string what="AnyInputPort::get : no value currently in input whith name \""; what+=_name; what+="\"";
+      std::string what="AnyInputPort::get : no value currently in input port with name \""; what+=_name; what+="\"";
       throw Exception(what);
     }
   stringstream xmldump;
   switch (_value->getType()->kind())
     {
     case Double:
-      xmldump << "<value><double>" << _value->getDoubleValue() << "</double></value>" << endl;
+      xmldump << "<value><double>" << setprecision(16) << _value->getDoubleValue() << "</double></value>" << endl;
       break;
     case Int:
       xmldump << "<value><int>" << _value->getIntValue() << "</int></value>" << endl;