-
Notifications
You must be signed in to change notification settings - Fork 2
TimeFilter
nphtan edited this page May 19, 2021
·
2 revisions
Filter for checkpointing periodically.
Header File: CheckpointFilter.hpp
struct TimeFilter
{
using clock_type = std::chrono::steady_clock;
using duration_type = std::chrono::steady_clock::duration;
using time_point_type = std::chrono::steady_clock::time_point;
template< typename Rep, typename Period >
explicit TimeFilter( std::chrono::duration< Rep, Period > duration )
: checkpoint_interval( std::chrono::duration_cast< duration_type >( duration ) ),
start( clock_type::now() )
{
}
bool operator()( int ) const
{
auto now = clock_type::now();
bool ret = ( now - start ) > checkpoint_interval;
if ( ret )
start = now;
return ret;
}
mutable time_point_type start;
duration_type checkpoint_interval;
};
-
clock_type
: Identify what kind of underlying clock to use. -
duration_type
: Identify what kind of type to use to express time differences -
time_point_type
: Identify the type to use for a time point.
-
Construct the
template< typename Rep, typename Period > explicit TimeFilter( std::chrono::duration< Rep, Period > duration ) : checkpoint_interval( std::chrono::duration_cast< duration_type >( duration ) ), start( clock_type::now() )
TimeFilter
with the supplied time period between checkpoints.
-
Get whether it is time to checkpoint.
bool operator()( int ) const