Barst  2.0
A server that controls lab hardware.
Public Member Functions | List of all members
CTimer Class Reference

#include <misc tools.h>

Public Member Functions

 CTimer ()
 
double Seconds () const
 
double Seconds (LARGE_INTEGER llStart) const
 
double TimeOf (LARGE_INTEGER llTime) const
 
LARGE_INTEGER GetStart () const
 
void ResetTimer ()
 

Detailed Description

Defines a high precision timer. Because of overflow, we allow the timer to be reset so that we count time relative to when it was last reset as opposed to when the computer was last started etc. The time it takes to overflow in this case can vary depending on the precision of the timer, which according to windows is no less than 100 years. Since we return time relative to some other time, we can use the time of that starting point in other instances of this class to calculate time relative to that offset.

This class can uses the QueryPerformanceCounter() and therefore assumes at least XP. The assumption implicit in the Seconds(LARGE_INTEGER llStart) and TimeOf(LARGE_INTEGER llTime) functions is that the instance used to generate the llStart or llTime value used the same time function as this instance otherwise they would be incompatible. The reason this should work is that if the performance counter isn't availible in one instance it shouldn't be availible for the other as well.

Definition at line 48 of file misc tools.h.

Constructor & Destructor Documentation

◆ CTimer()

CTimer::CTimer ( )

Initializes timer and calls ResetTimer().

Definition at line 54 of file misc tools.cpp.

Member Function Documentation

◆ GetStart()

LARGE_INTEGER CTimer::GetStart ( ) const
inline

Returns the offset, i.e. the internal time when reset was last called.

Definition at line 69 of file misc tools.h.

◆ ResetTimer()

void CTimer::ResetTimer ( )

Resets the elpased time count to the current time. I.e. Seconds() returns the elapsed time since this function was last called.

Definition at line 99 of file misc tools.cpp.

◆ Seconds() [1/2]

double CTimer::Seconds ( ) const

Returns the current time in seconds as elapsed from the last time ResetTimer() was called on this object. This is only accurate until overflow.

Definition at line 63 of file misc tools.cpp.

◆ Seconds() [2/2]

double CTimer::Seconds ( LARGE_INTEGER  llStart) const

Returns the currect time relative to an offset of some other clock. That is, You get the time when RestTimer() was calles on another instance of the timer using the GetStart() function and when you pass in that large integer to this function, the function will return the time relative to that offset.

Definition at line 76 of file misc tools.cpp.

◆ TimeOf()

double CTimer::TimeOf ( LARGE_INTEGER  llTime) const

Returns the time difference between llTime and the time that the timer was last reset. llTime would typically be the offset time when another timer instance was reset. You can use this to calculate the time difference between two timers so as to find a consistent time.

Definition at line 89 of file misc tools.cpp.