Salome HOME
Merge branch 'V9_9_BR'
[modules/yacs.git] / src / engine / AnyInputPort.cxx
index f86ba5e217b15f5aba94611e25498df507744bd3..f4df76fbed879b9ad68990429eda9ca00fe91519 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2006-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2022  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.
+// 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
 
 #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;
 
@@ -81,16 +84,29 @@ void AnyInputPort::exRestoreInit()
   _value->incrRef();
 }
 
-void AnyInputPort::put(Any *data)
+void AnyInputPort::releaseDataUnsafe()
 {
-  YACS::BASES::Lock lock(&_mutex);
   if(_value)
     _value->decrRef();
+  _value = nullptr;
+}
+
+void AnyInputPort::releaseData()
+{
+  YACS::BASES::AutoLocker<YACS::BASES::Mutex> lock(&_mutex);
+  releaseDataUnsafe();
+}
+
+void AnyInputPort::put(Any *data)
+{
+  YACS::BASES::AutoLocker<YACS::BASES::Mutex> lock(&_mutex);
+  releaseDataUnsafe();
   _value=data;
-  if (_value) {
-    _value->incrRef();
-    DEBTRACE("value ref count: " << _value->getRefCnt());
-  }
+  if (_value)
+    {
+      _value->incrRef();
+      DEBTRACE("value ref count: " << _value->getRefCnt());
+    }
 }
 
 bool AnyInputPort::isEmpty()
@@ -105,11 +121,11 @@ void *AnyInputPort::get() const
 
 std::string AnyInputPort::getAsString()
 {
-  YACS::BASES::Lock lock(&_mutex);
+  YACS::BASES::AutoLocker<YACS::BASES::Mutex> lock(&_mutex);
   return getRuntime()->convertNeutralAsString(edGetType(),_value);
 }
 
-void AnyInputPort::put(const void *data) throw(ConversionException)
+void AnyInputPort::put(const void *data)
 {
   put((Any *)data);
 }
@@ -130,7 +146,7 @@ std::string AnyInputPort::dump()
   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;