ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
TickConverter Class Reference

Description:


As explained in detail in the documentation of module ALib Time , a steady time model is supported with class Ticks and a non-steady one representing the system clock with class DateTime . Only values of the latter type can be converted to human readable (calendar) date and time values.

In some situations however, a software that requires steady, monotonic time points, may also be required to present these time points in human readable format. It is of-course possible to do some sort of conversion. For that, simply both clocks need to be probed at the same point in time and then time points of both notions can be put in relation to these two probes.

The effect however is that the conversion results will change for all values as soon as the system clock is changed and the probe values of the two clocks are updated. This is true also for values that are "older" than the point in time that the clock change happened. The reason is quickly understood: The system clock's counter changes, while the steady clock's counter does not.

To give the user of ALib full control about how system clock changes are reflected, the conversion of time points is encapsulated by this class together with one pair of clock probe data. A software can use one ore more instances of this class and update (synchronize) these instances independently.

Definition at line 43 of file tickconverter.hpp.

#include <tickconverter.hpp>

Public Method Index:

 TickConverter ()
 
void SetAs (const TickConverter &other)
 
ALIB_API void SyncClocks (int qtyRepeats=5)
 
DateTime ToDateTime (Ticks ticks)
 
Ticks ToTicks (DateTime dateTime)
 

Field Details:

◆ steadyClockSyncTime

Ticks::TTimePoint steadyClockSyncTime
protected

Time point of steady clock of last invocation of SyncClocks.

Definition at line 47 of file tickconverter.hpp.

◆ systemClockSyncTime

DateTime::TTimePoint systemClockSyncTime
protected

Time point of system clock of last invocation of SyncClocks.

Definition at line 50 of file tickconverter.hpp.

Constructor(s) / Destructor Details::

◆ TickConverter()

TickConverter ( )
inline

Constructor. Invokes SyncClocks.

Definition at line 56 of file tickconverter.hpp.

Here is the call graph for this function:

Method Details:

◆ SetAs()

void SetAs ( const TickConverter & other)
inline

Sets the pair of conversion times to equal the other converter object. This is useful to avoid differences in conversion across converter instances used in a software.

Parameters
otherAnother converter object to copy the synchronization information from.

Definition at line 91 of file tickconverter.hpp.

◆ SyncClocks()

void SyncClocks ( int qtyRepeats = 5)

Generates a set of "probes" of the steady, monotonic clock and the system clock. The measurement of both clocks is repeated the given number of times and the pair with the smallest difference between both is chosen. This approach mitigates the risk of using a pair for which thread execution had been interrupted during the two measurements.

Note that after a call to this method, the conversion methods may return slightly different values than before the call, even if the system clock was not changed.

If this method is not invoked after a change of the system clock, such change of the system clock is not reflected by the conversion methods. In other words, the conversion methods always work just as if the system clock had not changed since the last invocation of this method.

Note
On a GNU/Linux workstation (without workload), the error observed when doing only one measurement was in the magnitude of several microseconds.
Parameters
qtyRepeatsThe number of measurements to perform. Defaults to 5.

Definition at line 81 of file time.cpp.

◆ ToDateTime()

DateTime ToDateTime ( Ticks ticks)
inline

Converts a Ticks object to a DateTime object.

Parameters
ticksThe ticks object to convert.
Returns
The date time object.

Definition at line 102 of file tickconverter.hpp.

Here is the call graph for this function:

◆ ToTicks()

Ticks ToTicks ( DateTime dateTime)
inline

Converts a DateTime object to a Ticks object.

Parameters
dateTimeThe date/time object to convert.
Returns
The date time object.

Definition at line 114 of file tickconverter.hpp.

Here is the call graph for this function:

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