Salome HOME
Deal with 2D/0D pointlocator into Remapper
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingTimeLabel.cxx
index a827585315fc5807508bf7a1f89a9846b5139db8..1b1a72b6da85d9ae1a9376cdfd56310c9385f86d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2019  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
 
 #include "MEDCouplingTimeLabel.hxx"
 
-using namespace ParaMEDMEM;
+#include "InterpKernelException.hxx"
 
-std::size_t TimeLabel::GLOBAL_TIME=0;
+#include <limits>
+
+using namespace MEDCoupling;
+
+std::atomic<std::size_t> TimeLabel::GLOBAL_TIME(0);
 
 TimeLabel::TimeLabel():_time(GLOBAL_TIME++)
 {
@@ -50,10 +54,59 @@ void TimeLabel::updateTimeWith(const TimeLabel& other) const
 }
 
 /*!
- * This method has to be called with a lot of care. It set agressively the time in this with the
+ * This method has to be called with a lot of care. It set aggressively the time in this with the
  * time in \a other.
  */
 void TimeLabel::forceTimeOfThis(const TimeLabel& other) const
 {
   _time=other._time;
 }
+
+TimeLabelConstOverseer::TimeLabelConstOverseer(const TimeLabel *tl):_tl(tl),_ref_time(std::numeric_limits<std::size_t>::max())
+{
+  if(!_tl)
+    throw INTERP_KERNEL::Exception("TimeLabelConstOverseer constructor : input instance must be not NULL !");
+  _tl->updateTime();
+  _ref_time=tl->getTimeOfThis();
+}
+
+/*!
+ * This method checks that the tracked instance is not NULL and if not NULL that its internal state has not changed.
+ */
+void TimeLabelConstOverseer::checkConst() const
+{
+  if(!_tl)
+    throw INTERP_KERNEL::Exception("TimeLabelConstOverseer::checkConst : NULL tracked instance !");
+  _tl->updateTime();
+  if(_ref_time!=_tl->getTimeOfThis())
+    throw INTERP_KERNEL::Exception("TimeLabelConstOverseer::checkConst : the state of the controlled instance of TimeLable has changed !");
+}
+
+bool TimeLabelConstOverseer::resetState()
+{
+  if(_tl)
+    {
+      _tl->updateTime();
+      _ref_time=_tl->getTimeOfThis();
+      return true;
+    }
+  else
+    return false;
+}
+
+bool TimeLabelConstOverseer::keepTrackOfNewTL(const TimeLabel *tl)
+{
+  if(_tl==tl)
+    return false;
+  _tl=tl;
+  if(_tl)
+    {
+      _tl->updateTime();
+      _ref_time=_tl->getTimeOfThis();
+    }
+  else
+    {
+      _ref_time=std::numeric_limits<std::size_t>::max();
+    }
+  return true;
+}