X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingTimeLabel.cxx;h=7a9a60383b2002f55408518b1d44aeb84bfe00ec;hb=51fff402deffba5b8c47ae68f4c26f1924b700bb;hp=a827585315fc5807508bf7a1f89a9846b5139db8;hpb=659f8c67d0348350e12fde38fe8c4de1ff95dffe;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingTimeLabel.cxx b/src/MEDCoupling/MEDCouplingTimeLabel.cxx index a82758531..7a9a60383 100644 --- a/src/MEDCoupling/MEDCouplingTimeLabel.cxx +++ b/src/MEDCoupling/MEDCouplingTimeLabel.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// Copyright (C) 2007-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 @@ -20,7 +20,11 @@ #include "MEDCouplingTimeLabel.hxx" -using namespace ParaMEDMEM; +#include "InterpKernelException.hxx" + +#include + +using namespace MEDCoupling; std::size_t TimeLabel::GLOBAL_TIME=0; @@ -57,3 +61,52 @@ void TimeLabel::forceTimeOfThis(const TimeLabel& other) const { _time=other._time; } + +TimeLabelConstOverseer::TimeLabelConstOverseer(const TimeLabel *tl):_tl(tl),_ref_time(std::numeric_limits::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::max(); + } + return true; +}