Class representing the time measured by an electronics clock. More...
#include <ElecClock.h>
Public Member Functions | |
ElecClock (double const time, double const frame_period, double const frequency) | |
Constructor: sets all values. More... | |
constexpr ElecClock | WithTime (double const time) const noexcept |
constexpr ElecClock | WithTick (int const tick, int const frame=0) const noexcept |
constexpr ElecClock | AdvanceTimeBy (double const time) const noexcept |
constexpr ElecClock | AdvanceTicksBy (int const ticks) const noexcept |
constexpr double | Time () const noexcept |
Current time (as stored) in microseconds. More... | |
constexpr double | Time (int const sample, int const frame) const noexcept |
Returns the absolute time of the start of the specified sample. More... | |
constexpr double | Time (double const time) const noexcept |
Returns the discretized value of the specified time. More... | |
constexpr double | Time (int const ticks) const noexcept |
Returns the absolute start time of the specified tick. More... | |
constexpr double | Frequency () const |
Frequency in MHz. More... | |
constexpr double | FramePeriod () const noexcept |
A single frame period in microseconds. More... | |
constexpr int | Ticks () const noexcept |
Current clock tick (that is, the number of tick Time() falls in). More... | |
constexpr int | Ticks (double const time) const noexcept |
Returns the number of tick the specified time falls in. More... | |
constexpr int | Ticks (int const sample, int const frame) const noexcept |
Returns the number of tick the specified sample falls in. More... | |
constexpr int | Sample () const noexcept |
Returns number of the sample containing the clock current time. More... | |
constexpr int | Sample (double const time) const noexcept |
Returns the number of the sample containing the specified time. More... | |
constexpr int | Sample (int const tick) const noexcept |
Returns the number of the sample containing the specified tick. More... | |
constexpr int | Frame () const noexcept |
Returns the number of the frame containing the clock current time. More... | |
constexpr int | Frame (double const time) const noexcept |
Returns the number of the frame containing the specified time. More... | |
constexpr int | Frame (int const tick) const noexcept |
Returns the number of the frame containing the specified tick. More... | |
constexpr unsigned int | FrameTicks () const noexcept |
Number ticks in a frame. More... | |
constexpr double | TickPeriod () const noexcept |
A single tick period in microseconds. More... | |
constexpr bool | operator< (const ElecClock &rhs) const noexcept |
constexpr bool | operator> (const ElecClock &rhs) const noexcept |
constexpr bool | operator<= (const ElecClock &rhs) const noexcept |
constexpr bool | operator>= (const ElecClock &rhs) const noexcept |
Private Member Functions | |
constexpr | ElecClock (double const time, double const frame_period, double const frequency, std::nothrow_t) noexcept |
Private Attributes | |
double | fTime {} |
Time in microseconds. More... | |
double | fFramePeriod {kTIME_MAX} |
Frame period in microseconds. More... | |
double | fFrequency {1e9} |
Clock speed in MHz. More... | |
Class representing the time measured by an electronics clock.
This class represents the status of a running electronics clock. As such, it has:
Note that this object is actually able to manage any (continuous) value of time, and the concepts of frame and sample are not used to store the clock state, which is instead defined by its current time.
All these quantities are stored in real time units as opposed to clock tick counts. The nominal units for all times and frequencies are microseconds and megahertz, respectively, but ElecClock
will give consistent results as long as the units of frame period and time are the same, and reciprocal to the frequency unit.
The clock can update its time directly (SetTime()
) or through operators.
The clock started at time 0, with the sample 0 of the frame 0 (that is also tick 0). This implies that all times and ticks returned by the clock implicitly have the same reference as the input time specified by the constructors or by the last call to SetTime()
.
Some usage examples:
double
, in which case it is interpreted as a time, or int
, where it is interpreted as a clock tick. Be especially careful when utilizing data types which are neither int
not double
, because a conversion to one of them will occur, and you need to be in control of which one. Definition at line 91 of file ElecClock.h.
|
inline |
Constructor: sets all values.
time | starting time of the clock [s] |
frame_period | period of the clock [s] |
frequency | clock frequency [MHz] |
Definition at line 100 of file ElecClock.h.
|
inlineprivatenoexcept |
Definition at line 381 of file ElecClock.h.
|
inlinenoexcept |
Definition at line 126 of file ElecClock.h.
|
inlinenoexcept |
Definition at line 120 of file ElecClock.h.
|
inlinenoexcept |
Returns the number of the frame containing the clock current time.
Frame(double)
The returned value is the number of the frame which the current clock time falls in.
Definition at line 304 of file ElecClock.h.
|
inlinenoexcept |
Returns the number of the frame containing the specified time.
time | a clock time [s] |
Sample(double)
The returned value is the number of the frame which the specified time falls in.
The result is not related to the current time of the clock.
Definition at line 321 of file ElecClock.h.
|
inlinenoexcept |
Returns the number of the frame containing the specified tick.
tick | a clock tick number |
Frame(int)
The returned value is the number of the frame the specified tick belongs to.
The result is not related to the current time of the clock.
Definition at line 338 of file ElecClock.h.
|
inlinenoexcept |
A single frame period in microseconds.
Definition at line 198 of file ElecClock.h.
|
inlinenoexcept |
Number ticks in a frame.
Definition at line 345 of file ElecClock.h.
|
inline |
|
inlinenoexcept |
Definition at line 360 of file ElecClock.h.
|
inlinenoexcept |
Definition at line 370 of file ElecClock.h.
|
inlinenoexcept |
Definition at line 365 of file ElecClock.h.
|
inlinenoexcept |
Definition at line 375 of file ElecClock.h.
|
inlinenoexcept |
Returns number of the sample containing the clock current time.
Sample(double)
The returned value is the number of the sample within a frame, which the current clock time falls in. The number of the frame is not returned. To univocally define the sample, the number of the frame must also be obtained, e.g. via Frame()
.
Definition at line 253 of file ElecClock.h.
|
inlinenoexcept |
Returns the number of the sample containing the specified time.
time | a clock time [s] |
Frame(double)
The returned value is the number of the sample within a frame, which the specified time falls in. The number of the frame is not returned. To univocally define the sample, the number of the frame must also be obtained, e.g. via Frame(double)
.
The result is not related to the current time of the clock.
Definition at line 272 of file ElecClock.h.
|
inlinenoexcept |
Returns the number of the sample containing the specified tick.
tick | a clock tick number |
Frame(int)
The returned value is the number of the sample within a frame, of the specified tick. The number of the frame is not returned. To univocally define the sample, the number of the frame must also be obtained, e.g. via Frame(int)
.
The result is not related to the current time of the clock.
Definition at line 291 of file ElecClock.h.
|
inlinenoexcept |
|
inlinenoexcept |
Current clock tick (that is, the number of tick Time()
falls in).
Definition at line 205 of file ElecClock.h.
|
inlinenoexcept |
Returns the number of tick the specified time falls in.
time | time to be converted in ticks [s] |
The tick number 0 starts at time 0.0 s.
int
). Definition at line 221 of file ElecClock.h.
|
inlinenoexcept |
Returns the number of tick the specified sample falls in.
sample | number of sample in the specified frame |
frame | number of frame the specified sample is in |
The sample 0 of frame 0 is the tick number 0.
int
). Definition at line 238 of file ElecClock.h.
|
inlinenoexcept |
Current time (as stored) in microseconds.
Note that this is different than Time(Time())
, which is discretized.
Definition at line 137 of file ElecClock.h.
|
inlinenoexcept |
Returns the absolute time of the start of the specified sample.
sample | sample number within the specified frame |
frame | number of the frame the specified sample is in |
The sample number is not checked to be actually within the specified frame.
The returned time is not related to the current time of the clock.
Definition at line 154 of file ElecClock.h.
|
inlinenoexcept |
Returns the discretized value of the specified time.
time | a clock time [s] |
The returned time is the start time of the sample time
falls in.
It is not related to the current time of the clock.
Definition at line 169 of file ElecClock.h.
|
inlinenoexcept |
Returns the absolute start time of the specified tick.
ticks | a clock time [s] |
The returned time is the start time of the tick which time
falls in.
It is not related to the current time of the clock.
Definition at line 184 of file ElecClock.h.
|
inlinenoexcept |
Definition at line 114 of file ElecClock.h.
|
inlinenoexcept |
Definition at line 108 of file ElecClock.h.
|
private |
Frame period in microseconds.
Definition at line 389 of file ElecClock.h.
|
private |
Clock speed in MHz.
Definition at line 390 of file ElecClock.h.
|
private |
Time in microseconds.
Definition at line 388 of file ElecClock.h.