Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::Time::HighResolutionCounter Struct Reference

An high resolution time counter. More...

#include <Time.h>

Public Member Functions

HighResolutionCountersnap ()
 Sets HighResolutionCounter to current instant
Example: More...
 
HighResolutionCounter offsetBy (Milliseconds ms) const
 Returns a HighResolutionCounter offset by a given number of Milliseconds. More...
 
bool isLaterThanOrEqualTo (HighResolutionCounter other) const
 Check if this HighResolutionCounter is later or equal to another HighResolutionCounter. More...
 
Relative subtractApproximate (HighResolutionCounter other) const
 Subtracts another HighResolutionCounter from this one, returning an approximate Relative. More...
 
HighResolutionCounter subtractExact (HighResolutionCounter other) const
 Subtracts another HighResolutionCounter from this one, returning a precise HighResolutionCounter. More...
 
Relative getRelative () const
 

Public Attributes

int64_t part1
 
int64_t part2
 

Detailed Description

An high resolution time counter.

Member Function Documentation

◆ isLaterThanOrEqualTo()

bool SC::Time::HighResolutionCounter::isLaterThanOrEqualTo ( HighResolutionCounter  other) const

Check if this HighResolutionCounter is later or equal to another HighResolutionCounter.

Parameters
otherThe HighResolutionCounter to be used in the comparison
Returns
true if this HighResolutionCounter is later or equal to another HighResolutionCounter
Example:
Time::HighResolutionCounter start;
start.snap();
const Time::HighResolutionCounter end = start.offsetBy(Time::Milliseconds(123));
SC_TEST_EXPECT(end.isLaterThanOrEqualTo(start));
SC_TEST_EXPECT(not start.isLaterThanOrEqualTo(end));
#define SC_TEST_EXPECT(e)
Records a test expectation (eventually aborting or breaking o n failed test)
Definition: Testing.h:113

◆ offsetBy()

HighResolutionCounter SC::Time::HighResolutionCounter::offsetBy ( Milliseconds  ms) const

Returns a HighResolutionCounter offset by a given number of Milliseconds.

Parameters
msHow many Milliseconds the returned HighResolutionCounter must be offset of
Returns
A HighResolutionCounter that is offset by ms
Example:
Time::HighResolutionCounter start, end;
start.snap();
end = start.offsetBy(Time::Milliseconds(321));
Time::Relative elapsed = end.subtractApproximate(start);
SC_TEST_EXPECT(elapsed.inRoundedUpperMilliseconds().ms == 321);

◆ snap()

HighResolutionCounter & SC::Time::HighResolutionCounter::snap ( )

Sets HighResolutionCounter to current instant
Example:

Time::HighResolutionCounter start, end;
start.snap();
end.snap();
Time::Relative elapsed = end.subtractApproximate(start);
SC_TEST_EXPECT(elapsed.inRoundedUpperMilliseconds().ms < 300 and elapsed.inRoundedUpperMilliseconds().ms > 0);
static void Sleep(uint32_t milliseconds)
Puts current thread to sleep.

◆ subtractApproximate()

Relative SC::Time::HighResolutionCounter::subtractApproximate ( HighResolutionCounter  other) const

Subtracts another HighResolutionCounter from this one, returning an approximate Relative.

Parameters
otherThe HighResolutionCounter to be subtracted
Returns
A Relative holding the time interval between the two HighResolutionCounter
Example:
Time::HighResolutionCounter start, end;
start.snap();
end = start.offsetBy(Time::Milliseconds(321));
Time::Relative elapsed = end.subtractApproximate(start);
SC_TEST_EXPECT(elapsed.inRoundedUpperMilliseconds().ms == 321);

◆ subtractExact()

HighResolutionCounter SC::Time::HighResolutionCounter::subtractExact ( HighResolutionCounter  other) const

Subtracts another HighResolutionCounter from this one, returning a precise HighResolutionCounter.

Parameters
otherThe HighResolutionCounter to be subtracted
Returns
A HighResolutionCounter holding the time interval between the two HighResolutionCounter

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