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 102 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 108 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 // defined(_WIN32) || defined(CLOCK_MONOTONIC)
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 115 of file timings.h, definition at line 58 of file timings-inlines.h.

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

Reference value_.

timestamp()

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

Defaulted copy constructor.

Definition at line 124 of file timings.h.

Reference timestamp.

timestamp()

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

Defaulted move constructor.

Definition at line 129 of file timings.h.

Reference timestamp.

Public Destructor

~timestamp()

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

Defaulted destructor.

Definition at line 148 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 135 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 142 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 159 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 179 of file timings.h, definition at line 77 of file timings-inlines.h.

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

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 169 of file timings.h, definition at line 67 of file timings-inlines.h.

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

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 185 of file timings.h.

185 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.2 by Doxygen 1.17.0.