MADARA  3.2.3
madara::utility::EpochEnforcer< CLOCK > Class Template Reference

Enforces a periodic epoch. More...

#include <EpochEnforcer.h>

Public Member Functions

 EpochEnforcer (double period, double max_duration)
 Constructor. More...
 
void advance_next (void)
 Advance next. More...
 
template<typename PERIOD = std::chrono::nanoseconds>
uint64_t duration (void) const
 Returns a duration in user-specified period. More...
 
double duration_ds (void) const
 Returns a duration in seconds (double format) More...
 
uint64_t duration_ns (void) const
 Returns a duration in nanoseconds. More...
 
uint64_t duration_s (void) const
 Returns a duration in seconds. More...
 
bool has_reached_next (void) const
 Checks if current time is at or past next. More...
 
bool is_done (void) const
 Checks to see if max duration is finished. More...
 
void set_duration (double duration)
 Sets the maximum duration for the enforcer. More...
 
void set_period (double period)
 Sets the period for the enforcer. More...
 
void sleep_until_next (void)
 Sleeps until the next epoch. More...
 
void start (void)
 Starts the timer. More...
 

Private Attributes

std::chrono::time_point< CLOCK > max_
 the end of the timer duration More...
 
std::chrono::time_point< CLOCK > next_
 the next epoch to sleep to More...
 
std::chrono::nanoseconds period_
 the period of the epochs More...
 
std::chrono::time_point< CLOCK > start_
 the start of the timer duration More...
 

Detailed Description

template<typename CLOCK = std::chrono::steady_clock>
class madara::utility::EpochEnforcer< CLOCK >

Enforces a periodic epoch.

Definition at line 17 of file EpochEnforcer.h.

Constructor & Destructor Documentation

template<typename CLOCK = std::chrono::steady_clock>
madara::utility::EpochEnforcer< CLOCK >::EpochEnforcer ( double  period,
double  max_duration 
)
inline

Constructor.

Parameters
periodthe period between epochs in seconds
max_durationthe maximum duration in seconds

Definition at line 25 of file EpochEnforcer.h.

Member Function Documentation

template<typename CLOCK = std::chrono::steady_clock>
void madara::utility::EpochEnforcer< CLOCK >::advance_next ( void  )
inline

Advance next.

Definition at line 70 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
template<typename PERIOD = std::chrono::nanoseconds>
uint64_t madara::utility::EpochEnforcer< CLOCK >::duration ( void  ) const
inline

Returns a duration in user-specified period.

Returns
the duration of the timer in period

Definition at line 149 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
double madara::utility::EpochEnforcer< CLOCK >::duration_ds ( void  ) const
inline

Returns a duration in seconds (double format)

Returns
the duration of the timer in seconds

Definition at line 136 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
uint64_t madara::utility::EpochEnforcer< CLOCK >::duration_ns ( void  ) const
inline

Returns a duration in nanoseconds.

Returns
the duration of the timer in nanoseconds

Definition at line 112 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
uint64_t madara::utility::EpochEnforcer< CLOCK >::duration_s ( void  ) const
inline

Returns a duration in seconds.

Returns
the duration of the timer in seconds

Definition at line 124 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
bool madara::utility::EpochEnforcer< CLOCK >::has_reached_next ( void  ) const
inline

Checks if current time is at or past next.

Returns
true if current time is greater than or equal to next epoch

Definition at line 82 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
bool madara::utility::EpochEnforcer< CLOCK >::is_done ( void  ) const
inline

Checks to see if max duration is finished.

Returns
true if max duration is exceeded, false otherwise

Definition at line 103 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
void madara::utility::EpochEnforcer< CLOCK >::set_duration ( double  duration)
inline

Sets the maximum duration for the enforcer.

Parameters
durationthe maximum duration of the period epochs

Definition at line 45 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
void madara::utility::EpochEnforcer< CLOCK >::set_period ( double  period)
inline

Sets the period for the enforcer.

Parameters
periodthe period of the epochs

Definition at line 58 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
void madara::utility::EpochEnforcer< CLOCK >::sleep_until_next ( void  )
inline

Sleeps until the next epoch.

Definition at line 92 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
void madara::utility::EpochEnforcer< CLOCK >::start ( void  )
inline

Starts the timer.

Affects future duration calls.

Definition at line 35 of file EpochEnforcer.h.

Member Data Documentation

template<typename CLOCK = std::chrono::steady_clock>
std::chrono::time_point<CLOCK> madara::utility::EpochEnforcer< CLOCK >::max_
private

the end of the timer duration

Definition at line 162 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
std::chrono::time_point<CLOCK> madara::utility::EpochEnforcer< CLOCK >::next_
private

the next epoch to sleep to

Definition at line 165 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
std::chrono::nanoseconds madara::utility::EpochEnforcer< CLOCK >::period_
private

the period of the epochs

Definition at line 168 of file EpochEnforcer.h.

template<typename CLOCK = std::chrono::steady_clock>
std::chrono::time_point<CLOCK> madara::utility::EpochEnforcer< CLOCK >::start_
private

the start of the timer duration

Definition at line 159 of file EpochEnforcer.h.


The documentation for this class was generated from the following file: