This repository has been archived on 2026-03-28. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
eodev/eo/src/utils/eoUpdater.cpp
evomarc 0e62de2d14 Added the lastCall construct: if the stopping condition becomes true in eoCheckPoint,
a method called lastCall is called for everything contained in that checkpoint
      (stats, updaters and monitors). This can be extremely useful
      - for stateSavers (see below)
      - for monitoring things like rates of success of operators, where what you
        are interested in is the final result only.
Added of course a virtual method lastCall that does nothing by default in classes
      eoBaseStat, eoBaseSortedStat, eoUpdater and eoMonitor
Added a boolean to control the save of the state in method eoCountedStateSaver::lastCall
      so you can ask that the state is saved at final population, whatever happens.
      I also added the corresponding constructor to take this into account.
2000-12-04 06:58:43 +00:00

46 lines
758 B
C++

#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include <strstream>
#include <utils/eoState.h>
#include <utils/eoUpdater.h>
using namespace std;
void eoTimedStateSaver::operator()(void)
{
time_t now = time(0);
if (now >= last_time + interval)
{
last_time = now;
ostrstream os;
os << prefix << (now - first_time) << '.' << extension << ends;
state.save(os.str());
}
}
void eoCountedStateSaver::doItNow(void)
{
ostrstream os;
os << prefix << counter << '.' << extension << ends;
state.save(os.str());
}
void eoCountedStateSaver::operator()(void)
{
if (++counter % interval == 0)
doItNow();
}
void eoCountedStateSaver::lastCall(void)
{
if (saveOnLastCall)
doItNow();
}