Skip to main content

timestamp Class

A single point-in-time measurement, wrapping a timespec value. More...

Declaration

class micro_os_plus::micro_test_plus::detail::timestamp { ... }

Included Headers

Public Constructors Index

timestamp () noexcept

Default constructor. Zero-initialises the internal timespec. More...

timestamp (const timespec &ts) noexcept

Constructs a timestamp from an existing timespec value. More...

timestamp (const timestamp &)=default

Defaulted copy constructor. More...

timestamp (timestamp &&)=default

Defaulted move constructor. More...

Public Destructor Index

~timestamp ()=default

Defaulted destructor. More...

Public Operators Index

timestamp &operator= (const timestamp &)=default

Defaulted copy assignment operator. More...

timestamp &operator= (timestamp &&)=default

Defaulted move assignment operator. More...

Public Member Functions Index

boolhas_clock (void) const noexcept

Returns true if a monotonic clock is available on this target. More...

const timespec &value () const noexcept

Returns a const reference to the underlying timespec value. More...

timespec &value () noexcept

Returns a mutable reference to the underlying timespec value. More...

Protected Member Attributes Index

timespecvalue_ {}

The underlying timespec value. More...

Description

A single point-in-time measurement, wrapping a timespec value.

timestamp stores one timespec sample obtained from the system clock. It is default-constructible (zero-initialises the timespec), copy-constructible, and move-constructible, so that it can be used efficiently in std::optional<timestamp> containers.

The has_clock() predicate allows callers to determine whether a real-time clock is available on the target platform before relying on the stored value.

Definition at line 93 of file timings.h.

Public Constructors

timestamp()

micro_os_plus::micro_test_plus::detail::timestamp::timestamp ()
noexcept

Default constructor. Zero-initialises the internal timespec.

On Windows, the current time is captured via timespec_get() with TIME_UTC. On POSIX platforms with CLOCK_MONOTONIC defined, clock_gettime(CLOCK_MONOTONIC) is used to obtain a monotonic timestamp. On platforms where neither macro is defined, value_ remains zero-initialised.

Declaration at line 99 of file timings.h, definition at line 71 of file timings.cpp.

72 {
73#if defined(_WIN32)
74 timespec_get (&value_, TIME_UTC);
75#elif defined(CLOCK_MONOTONIC)
76 clock_gettime (CLOCK_MONOTONIC, &value_);
77#endif
78 }

Reference value_.

Referenced by timestamp, timestamp, operator= and operator=.

timestamp()

micro_os_plus::micro_test_plus::detail::timestamp::timestamp (const timespec & ts)
inline noexcept

Constructs a timestamp from an existing timespec value.

Parameters
ts

The timespec value to store.

Stores the supplied timespec value in the value_ member.

Declaration at line 106 of file timings.h, definition at line 57 of file timings-inlines.h.

57 inline timestamp::timestamp (const timespec& ts) noexcept : value_{ ts }
58 {
59 }

Reference value_.

timestamp()

micro_os_plus::micro_test_plus::detail::timestamp::timestamp (const timestamp &)
default

Defaulted copy constructor.

Definition at line 115 of file timings.h.

Reference timestamp.

timestamp()

micro_os_plus::micro_test_plus::detail::timestamp::timestamp (timestamp &&)
default

Defaulted move constructor.

Definition at line 120 of file timings.h.

Reference timestamp.

Public Destructor

~timestamp()

micro_os_plus::micro_test_plus::detail::timestamp::~timestamp ()
default

Defaulted destructor.

Definition at line 139 of file timings.h.

Reference value.

Public Operators

operator=()

timestamp & micro_os_plus::micro_test_plus::detail::timestamp::operator= (const timestamp &)
default

Defaulted copy assignment operator.

Definition at line 126 of file timings.h.

Reference timestamp.

operator=()

timestamp & micro_os_plus::micro_test_plus::detail::timestamp::operator= (timestamp &&)
default

Defaulted move assignment operator.

Definition at line 133 of file timings.h.

Reference timestamp.

Public Member Functions

has_clock()

bool micro_os_plus::micro_test_plus::detail::timestamp::has_clock (void)
noexcept

Returns true if a monotonic clock is available on this target.

Parameters

None.

Return Values
true

A real-time clock is available and timestamps are valid.

false

No clock is available; timing data should be ignored.

Returns true if at least one of the tv_sec or tv_nsec fields of the underlying timespec is non-zero, indicating that a valid clock reading was successfully captured.

Declaration at line 150 of file timings.h, definition at line 87 of file timings.cpp.

87 timestamp::has_clock (void) const noexcept
88 {
89 return value_.tv_sec != 0 || value_.tv_nsec != 0;
90 }

Reference value_.

value()

const timespec & micro_os_plus::micro_test_plus::detail::timestamp::value ()
inline nodiscard noexcept

Returns a const reference to the underlying timespec value.

Parameters

None.

Returns

A const reference to the stored timespec.

Returns a const reference to the value_ member.

Declaration at line 170 of file timings.h, definition at line 76 of file timings-inlines.h.

76 timestamp::value () const noexcept
77 {
78 return value_;
79 }

Reference value_.

value()

timespec & micro_os_plus::micro_test_plus::detail::timestamp::value ()
inline nodiscard noexcept

Returns a mutable reference to the underlying timespec value.

Parameters

None.

Returns

A reference to the stored timespec.

Returns a mutable reference to the value_ member.

Declaration at line 160 of file timings.h, definition at line 66 of file timings-inlines.h.

66 timestamp::value () noexcept
67 {
68 return value_;
69 }

Reference value_.

Referenced by ~timestamp.

Protected Member Attributes

value_

timespec micro_os_plus::micro_test_plus::detail::timestamp::value_ {}
protected

The underlying timespec value.

Definition at line 176 of file timings.h.

176 timespec value_{};

Referenced by timestamp, timestamp, has_clock, value and value.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.