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)
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());
Class template for accessing a Clock in specific time units.
Definition: NanoTime.h:122
static Ratio32 ticksPerUnit(Unit unit)
Get ticks per unit as a Ratio object.
Definition: NanoTime.h:171
TimeValue()=default
Time< T > time(Unit unit, T value)
Helper function to create a Time and deduce the type.
Definition: NanoTime.h:429
static constexpr void check()
Obtain the tick count with a static range check against Clock maxTicks.
Definition: NanoTime.h:585
static constexpr BasicRatio32 ticksPerUnit()
Number of clock ticks per unit of time.
Definition: NanoTime.h:652
uint32_t getMicroseconds() const
Get sub-second time entirely in microseconds.
Definition: NanoTime.h:295
const char * unitToString(Unit unit)
Get a string identifying the given time units, e.g. "ns".
constexpr uint64_t convert()
Function template to convert a constant time quantity from one unit to another.
Definition: NanoTime.h:249
typename Clock::template TicksPerUnit< unit_ > TicksPerUnit
Definition: NanoTime.h:639
TimeConst< Clock, unit, TimeType(round(double(ticks_) *Clock::template TicksPerUnit< unit >::den/Clock::template TicksPerUnit< unit >::num))> TimeConst
Definition: NanoTime.h:593
typename MaxTicks::template TimeConst< unit > MaxTime
Definition: NanoTime.h:161
static constexpr uint64_t as()
Obtain the time in a different set of units.
Definition: NanoTime.h:539
static constexpr TimeConst< unit, time > timeConst()
Class template defining a fixed time quantity.
Definition: NanoTime.h:182
friend Time & operator+(Time lhs, const Time &rhs)
Definition: NanoTime.h:395
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 ValType maxValue()
Get the maximum value which can be used for a muldiv calculation without overflowing.
Definition: muldiv.h:119
static constexpr TicksConst< ticks > ticksConst()
Class template defining a fixed tick quantity.
Definition: NanoTime.h:192
uint32_t getNanoseconds() const
Get sub-second time entirely in nanoseconds.
Definition: NanoTime.h:303
static constexpr MaxClockTime maxClockTime()
Definition: NanoTime.h:661
Class template to represent a fixed time value for a specific Clock.
Definition: NanoTime.h:120
static constexpr TimeSource< unit, TimeType > timeSource()
Create a Time Source for this Clock.
Definition: NanoTime.h:202
Class template representing a physical Clock with fixed timing characteristics.
Definition: NanoTime.h:137
TimeConst< Clock, unit, time > TimeConst
Definition: NanoTime.h:140
NanoTime::Milliseconds Clock
Definition: NanoTime.h:637
Definition: NanoTime.h:39
TimeType TimeType
Definition: NanoTime.h:638
TimeSource< Clock, unit, TimeType > TimeSource
Definition: NanoTime.h:142
static Ratio32 ticksPerUnit()
Get ticks per unit as a Ratio object.
Definition: NanoTime.h:502
TimeConst< Clock, unit_, time > TimeConst
Definition: NanoTime.h:640
static constexpr uint64_t ticks()
Return the corresponding tick value for the time interval.
Definition: NanoTime.h:511
static constexpr uint64_t ticksToTime()
Get the time for a given number of clock ticks.
Definition: NanoTime.h:734
NanoTime::Clock< CpuCycleClock< cpuFreq >, uint32_t(cpuFreq) *1000000, uint32_t, 0xFFFFFFFF >::Ticks
Ticks< Clock, T > Ticks
Definition: NanoTime.h:143
typename Clock::template TicksPerUnit< unit_ > TicksPerUnit
Definition: NanoTime.h:476
static Time< TimeType > ticksToTime(TimeType ticks)
Get the time for a given number of clock ticks.
Definition: NanoTime.h:222
static constexpr uint64_t timeToTicks()
Get the number of ticks for a given time.
Definition: NanoTime.h:724
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
uint32_t TickType
Definition: NanoTime.h:138
constexpr BasicRatio32 unitTicks[UnitMax+1]
List of clock ticks for each supported unit of time.
Definition: NanoTime.h:96
TimeValue(Unit unit, TimeType time)
Resolve a time value into constituent components.
Definition: NanoTime.h:285
static constexpr uint64_t clockTime()
Obtain the actual Clock time by converting tick value.
Definition: NanoTime.h:529
typename Clock::template MaxTime< unit_ > MaxClockTime
Get the time corresponding to the maximum clock tick value.
Definition: NanoTime.h:660
TicksConst< maxTicks_ > MaxTicks
Definition: NanoTime.h:155
String toString() const
static Time< TimeType_ > ticksToTime(TimeType ticks)
Get the time for a given number of clock ticks.
Definition: NanoTime.h:744
const char * unitToLongString(Unit unit)
Get a long string identifying the given time units, e.g. "seconds".
TicksConst< Clock, ticks > TicksConst
Definition: NanoTime.h:139
std::ratio_divide< std::ratio< frequency_ >, UnitTickRatio< unit > > TicksPerUnit
Definition: NanoTime.h:141
static constexpr Ticks< Clock_, TimeType_ > maxCalcTicks()
The maximum tick value supported by ticksToTime without overflowing.
Definition: NanoTime.h:704
static Ticks< TimeType > timeToTicks(TimeType time)
Get the number of ticks for a given time.
Definition: NanoTime.h:212
static Ticks< Clock_, TimeType_ > timeToTicks(TimeType time)
Get the number of ticks for a given time.
Definition: NanoTime.h:714
Time()=default
static constexpr TimeConst< unit > as()
Get the time for the tick count in a specific time unit.
Definition: NanoTime.h:600
static constexpr void check()
Use this function to perform a static (compile-time) range check against Clock maxTicks.
Definition: NanoTime.h:520