NanoTime.h
Go to the documentation of this file.
13 * - Only uses 64-bit calculations. NanoTime can use any integral type, although uint32_t is the most useful.
137 template <typename ClockDef, uint32_t frequency_, typename TickType_, TickType_ maxTicks_> struct Clock {
141 template <Unit unit> using TicksPerUnit = std::ratio_divide<std::ratio<frequency_>, UnitTickRatio<unit>>;
202 template <Unit unit, typename TimeType> static constexpr TimeSource<unit, TimeType> timeSource()
262 template <typename TimeType> __forceinline TimeType convert(const TimeType& time, Unit unitsFrom, Unit unitsTo)
317 uint32_t days = 0;
318 uint8_t hours = 0;
319 uint8_t minutes = 0;
320 uint8_t seconds = 0;
322 uint32_t microseconds = 0;
323 uint32_t nanoseconds = 0;
423 T time = 0;
593 Clock::template TicksPerUnit<unit>::num))>;
619 template <Unit unitsFrom, Unit unitsTo, typename TimeType> __forceinline TimeType convert(const TimeType& time)
697 return Time<TimeType_>(unit_, MuldivLimits<TicksPerUnit::num, TicksPerUnit::den, TimeType>::maxValue());
typename MaxTicks::template TimeConst< unit > MaxTime
Definition: NanoTime.h:161
static Ticks< TimeType > timeToTicks(TimeType time)
Get the number of ticks for a given time.
Definition: NanoTime.h:212
static constexpr BasicRatio32 ticksPerUnit()
Number of clock ticks per unit of time.
Definition: NanoTime.h:652
static constexpr uint64_t as()
Obtain the time in a different set of units.
Definition: NanoTime.h:539
static Ratio32 ticksPerUnit()
Get ticks per unit as a Ratio object.
Definition: NanoTime.h:502
typename Clock::template TicksPerUnit< unit_ > TicksPerUnit
Definition: NanoTime.h:639
typename Clock::template TicksPerUnit< unit_ > TicksPerUnit
Definition: NanoTime.h:476
Definition: NanoTime.h:50
uint32_t TickType
Definition: NanoTime.h:138
Class template representing a physical Clock with fixed timing characteristics.
Definition: NanoTime.h:137
static constexpr TicksConst< ticks > ticksConst()
Class template defining a fixed tick quantity.
Definition: NanoTime.h:192
static constexpr uint64_t ticks()
Return the corresponding tick value for the time interval.
Definition: NanoTime.h:511
Definition: NanoTime.h:53
friend Time & operator+(Time lhs, const Time &rhs)
Definition: NanoTime.h:395
Definition: NanoTime.h:48
static constexpr void check()
Use this function to perform a static (compile-time) range check against Clock maxTicks.
Definition: NanoTime.h:520
static constexpr TimeConst< unit > as()
Get the time for the tick count in a specific time unit.
Definition: NanoTime.h:600
TimeConst< Clock, unit, time > TimeConst
Definition: NanoTime.h:140
const char * unitToString(Unit unit)
Get a string identifying the given time units, e.g. "ns".
uint32_t getNanoseconds() const
Get sub-second time entirely in nanoseconds.
Definition: NanoTime.h:303
Class template to represent a fixed time value for a specific Clock.
Definition: NanoTime.h:120
static constexpr ValType maxValue()
Get the maximum value which can be used for a muldiv calcuation without overflowing.
Definition: muldiv.h:75
Class template for accessing a Clock in specific time units.
Definition: NanoTime.h:122
uint32_t getMicroseconds() const
Get sub-second time entirely in microseconds.
Definition: NanoTime.h:295
Time< T > time(Unit unit, T value)
Helper function to create a Time and deduce the type.
Definition: NanoTime.h:429
TicksConst< Clock, ticks > TicksConst
Definition: NanoTime.h:139
NanoTime::Nanoseconds Clock
Definition: NanoTime.h:637
Definition: NanoTime.h:49
constexpr BasicRatio32 unitTicks[UnitMax+1]
List of clock ticks for each supported unit of time.
Definition: NanoTime.h:96
TimeType TimeType
Definition: NanoTime.h:638
static constexpr TicksConst< ticks > ticksConst()
Class template defining a fixed tick quantity.
Definition: NanoTime.h:686
static constexpr Time< TimeType_ > maxCalcTime()
The maximum time value supported by timeToTicks without overflowing.
Definition: NanoTime.h:695
static constexpr uint64_t ticksToTime()
Get the time for a given number of clock ticks.
Definition: NanoTime.h:734
TimeConst< Clock, unit_, time > TimeConst
Definition: NanoTime.h:640
TimeValue(Unit unit, TimeType time)
Resolve a time value into constituent components.
Definition: NanoTime.h:285
const char * unitToLongString(Unit unit)
Get a long string identifying the given time units, e.g. "seconds".
static constexpr MaxClockTime maxClockTime()
Definition: NanoTime.h:661
Definition: NanoTime.h:52
static constexpr uint64_t timeToTicks()
Get the number of ticks for a given time.
Definition: NanoTime.h:724
static constexpr TimeSource< unit, TimeType > timeSource()
Create a Time Source for this Clock.
Definition: NanoTime.h:202
static constexpr TimeConst< time > timeConst()
Obtain a TimeConst type representing the given time quantity.
Definition: NanoTime.h:675
TicksConst< Clock, ticks > TicksConst
Definition: NanoTime.h:641
static constexpr TimeConst< unit, time > timeConst()
Class template defining a fixed time quantity.
Definition: NanoTime.h:182
TicksConst< maxTicks_ > MaxTicks
Definition: NanoTime.h:155
static Ratio32 ticksPerUnit(Unit unit)
Get ticks per unit as a Ratio object.
Definition: NanoTime.h:171
constexpr uint64_t convert()
Function template to convert a constant time quantity from one unit to another.
Definition: NanoTime.h:249
Class template representing a fixed clock tick count.
Definition: NanoTime.h:121
TimeSource< Clock, unit, TimeType > TimeSource
Definition: NanoTime.h:142
static Ticks< Clock_, TimeType_ > timeToTicks(TimeType time)
Get the number of ticks for a given time.
Definition: NanoTime.h:714
std::ratio_divide< std::ratio< frequency_ >, UnitTickRatio< unit > > TicksPerUnit
Definition: NanoTime.h:141
Definition: NanoTime.h:46
typename Clock::template MaxTime< unit_ > MaxClockTime
Get the time corresponding to the maximum clock tick value.
Definition: NanoTime.h:660
Definition: NanoTime.h:47
static Time< TimeType_ > ticksToTime(TimeType ticks)
Get the time for a given number of clock ticks.
Definition: NanoTime.h:744
NanoTime::Clock< CpuCycleClock< cpuFreq >, uint32_t(cpuFreq) *1000000, uint32_t, 0xFFFFFFFF >::Ticks
Ticks< Clock, T > Ticks
Definition: NanoTime.h:143
static constexpr uint64_t clockTime()
Obtain the actual Clock time by converting tick value.
Definition: NanoTime.h:529
Definition: NanoTime.h:39
static Time< TimeType > ticksToTime(TimeType ticks)
Get the time for a given number of clock ticks.
Definition: NanoTime.h:222
Definition: NanoTime.h:51
static constexpr void check()
Obtain the tick count with a static range check against Clock maxTicks.
Definition: NanoTime.h:585
TimeConst< Clock, unit, TimeType(round(double(ticks_) *Clock::template TicksPerUnit< unit >::den/Clock::template TicksPerUnit< unit >::num))> TimeConst
Definition: NanoTime.h:593
static constexpr Ticks< Clock_, TimeType_ > maxCalcTicks()
The maximum tick value supported by ticksToTime without overflowing.
Definition: NanoTime.h:704