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
 Converts to a Relative struct. More...
 
Nanoseconds toNanoseconds () const
 Converts to Nanoseconds. More...
 
Milliseconds toMilliseconds () const
 Converts to Milliseconds. More...
 
Seconds toSeconds () const
 Converts to Seconds. More...
 

Detailed Description

An high resolution time counter.

Member Function Documentation

◆ getRelative()

Relative SC::Time::HighResolutionCounter::getRelative ( ) const

Converts to a Relative struct.

◆ 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(123_ms);
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::Milliseconds elapsed = end.subtractExact(start).toMilliseconds();
SC_TEST_EXPECT(elapsed == 321_ms);

◆ snap()

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

Sets HighResolutionCounter to current instant
Example:

Time::HighResolutionCounter start, end;
start.snap();
end.snap();
Time::Milliseconds elapsed = end.subtractExact(start).toMilliseconds();
SC_TEST_EXPECT(elapsed < 300_ms and elapsed > 0_ms);
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::Milliseconds elapsed = end.subtractExact(start).toMilliseconds();
SC_TEST_EXPECT(elapsed == 321_ms);

◆ 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

◆ toMilliseconds()

Milliseconds SC::Time::HighResolutionCounter::toMilliseconds ( ) const

Converts to Milliseconds.

◆ toNanoseconds()

Nanoseconds SC::Time::HighResolutionCounter::toNanoseconds ( ) const

Converts to Nanoseconds.

◆ toSeconds()

Seconds SC::Time::HighResolutionCounter::toSeconds ( ) const

Converts to Seconds.


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