NanoTime Namespace Reference

Classes

struct  Frequency
 Class to represent a frequency. More...
 
struct  TimeConst
 Class template to represent a fixed time value for a specific Clock. More...
 
struct  TicksConst
 Class template representing a fixed clock tick count. More...
 
struct  TimeSource
 Class template for accessing a Clock in specific time units. More...
 
struct  Time
 Class to handle a simple time value with associated unit. More...
 
struct  Ticks
 Class to handle a tick value associated with a clock. More...
 
struct  Clock
 Class template representing a physical Clock with fixed timing characteristics. More...
 
struct  TimeValue
 A time time broken into its constituent elements. More...
 

Typedefs

template<Unit unit>
using UnitTickRatio = std::ratio< unitTicks[unit].num, unitTicks[unit].den >
 Class template to define tick std::ratio type. More...
 

Enumerations

enum  Unit {
  Nanoseconds , Microseconds , Milliseconds , Seconds ,
  Minutes , Hours , Days , UnitMax = Days
}
 Identify units for a scalar quantity of time. More...
 

Functions

constexpr uint64_t round_ce (double v)
 
const char * unitToString (Unit unit)
 Get a string identifying the given time units, e.g. "ns". More...
 
const char * unitToLongString (Unit unit)
 Get a long string identifying the given time units, e.g. "seconds". More...
 
template<uint64_t time, Unit unitsFrom, Unit unitsTo, typename R = std::ratio_divide<UnitTickRatio<unitsTo>, UnitTickRatio<unitsFrom>>>
constexpr uint64_t convert ()
 Function template to convert a constant time quantity from one unit to another. More...
 
template<typename TimeType >
TimeType convert (const TimeType &time, Unit unitsFrom, Unit unitsTo)
 Function template to convert a time quantity from one unit to another. More...
 
template<typename T >
Time< T > time (Unit unit, T value)
 Helper function to create a Time and deduce the type. More...
 
template<Unit unitsFrom, Unit unitsTo, typename TimeType >
TimeType convert (const TimeType &time)
 Function template to convert a time quantity from one unit to another. More...
 

Variables

constexpr BasicRatio32 unitTicks [UnitMax+1]
 List of clock ticks for each supported unit of time. More...
 

Typedef Documentation

◆ UnitTickRatio

template<Unit unit>
using NanoTime::UnitTickRatio = typedef std::ratio<unitTicks[unit].num, unitTicks[unit].den>

Class template to define tick std::ratio type.

Template Parameters
unit
Return values
std::ratioTicks per second

Enumeration Type Documentation

◆ Unit

Identify units for a scalar quantity of time.

Note
Ordered in increasing unit size, e.g. days > seconds
Enumerator
Nanoseconds 
Microseconds 
Milliseconds 
Seconds 
Minutes 
Hours 
Days 
UnitMax 

Function Documentation

◆ convert() [1/3]

template<uint64_t time, Unit unitsFrom, Unit unitsTo, typename R = std::ratio_divide<UnitTickRatio<unitsTo>, UnitTickRatio<unitsFrom>>>
constexpr uint64_t NanoTime::convert ( )
constexpr

Function template to convert a constant time quantity from one unit to another.

Template Parameters
timeThe time to convert
unitsFromUnits for time parameter
unitsToUnits for return value
Return values
TimeTypeConverted time
Note
example:
uint32_t micros = convert<50, Milliseconds, Microseconds>();

◆ convert() [2/3]

template<Unit unitsFrom, Unit unitsTo, typename TimeType >
TimeType NanoTime::convert ( const TimeType &  time)

Function template to convert a time quantity from one unit to another.

Template Parameters
unitsFromUnits for time parameter
unitsToUnits for return value
TimeTypeVariable type to use for calculation
Parameters
timeThe time to convert
Return values
TimeTypeConverted time, returns TimeType(-1) if calculation overflowed

◆ convert() [3/3]

template<typename TimeType >
TimeType NanoTime::convert ( const TimeType &  time,
Unit  unitsFrom,
Unit  unitsTo 
)

Function template to convert a time quantity from one unit to another.

Template Parameters
TimeTypeVariable type to use for calculation
Parameters
timeThe time to convert
unitsFromUnits for time parameter
unitsToUnits for return value
Return values
TimeTypeConverted time, returns TimeType(-1) if calculation overflowed

◆ round_ce()

constexpr uint64_t NanoTime::round_ce ( double  v)
constexpr

◆ time()

template<typename T >
Time<T> NanoTime::time ( Unit  unit,
value 
)

Helper function to create a Time and deduce the type.

◆ unitToLongString()

const char* NanoTime::unitToLongString ( Unit  unit)

Get a long string identifying the given time units, e.g. "seconds".

◆ unitToString()

const char* NanoTime::unitToString ( Unit  unit)

Get a string identifying the given time units, e.g. "ns".

Variable Documentation

◆ unitTicks

constexpr BasicRatio32 NanoTime::unitTicks[UnitMax+1]
constexpr
Initial value:
= {
{1000000000, 1},
{1000000, 1},
{1000, 1},
{1, 1},
{1, 60},
{1, 60 * 60},
{1, 24 * 60 * 60},
}

List of clock ticks for each supported unit of time.