micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::detail::timestamp Class Reference

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

#include <micro-os-plus/micro-test-plus.h>

Public Member Functions

 timestamp () noexcept
 Default constructor. Zero-initialises the internal timespec.
 timestamp (const timespec &ts) noexcept
 Constructs a timestamp from an existing timespec value.
 timestamp (const timestamp &)=default
 Defaulted copy constructor.
 timestamp (timestamp &&)=default
 Defaulted move constructor.
 ~timestamp ()=default
 Defaulted destructor.
bool has_clock (void) const noexcept
 Returns true if a monotonic clock is available on this target.
timestampoperator= (const timestamp &)=default
 Defaulted copy assignment operator.
timestampoperator= (timestamp &&)=default
 Defaulted move assignment operator.
const timespec & value () const noexcept
 Returns a const reference to the underlying timespec value.
timespec & value () noexcept
 Returns a mutable reference to the underlying timespec value.

Protected Attributes

timespec value_ {}
 The underlying timespec value.

Detailed Description

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.

Constructor & Destructor Documentation

◆ timestamp() [1/4]

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

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.

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 }
timespec value_
The underlying timespec value.
Definition timings.h:176

References value_.

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

◆ timestamp() [2/4]

micro_os_plus::micro_test_plus::detail::timestamp::timestamp ( const timespec & ts)
inlinenoexcept
Parameters
tsThe timespec value to store.

Stores the supplied timespec value in the value_ member.

Definition at line 57 of file timings-inlines.h.

57 : value_{ ts }
58 {
59 }

References value_.

◆ timestamp() [3/4]

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

References timestamp().

◆ timestamp() [4/4]

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

References timestamp().

◆ ~timestamp()

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

References value().

Member Function Documentation

◆ has_clock()

bool micro_os_plus::micro_test_plus::detail::timestamp::has_clock ( void ) const
noexcept
Parameters
None.
Return values
trueA real-time clock is available and timestamps are valid.
falseNo 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.

Definition at line 87 of file timings.cpp.

88 {
89 return value_.tv_sec != 0 || value_.tv_nsec != 0;
90 }

References value_.

◆ operator=() [1/2]

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

References timestamp().

◆ operator=() [2/2]

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

References timestamp().

◆ value() [1/2]

const timespec & micro_os_plus::micro_test_plus::detail::timestamp::value ( ) const
inlinenodiscardnoexcept
Parameters
None.
Returns
A const reference to the stored timespec.

Returns a const reference to the value_ member.

Definition at line 76 of file timings-inlines.h.

77 {
78 return value_;
79 }

References value_.

◆ value() [2/2]

timespec & micro_os_plus::micro_test_plus::detail::timestamp::value ( )
inlinenodiscardnoexcept
Parameters
None.
Returns
A reference to the stored timespec.

Returns a mutable reference to the value_ member.

Definition at line 66 of file timings-inlines.h.

67 {
68 return value_;
69 }

References value_.

Referenced by ~timestamp().

Member Data Documentation

◆ value_

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

Definition at line 176 of file timings.h.

176{};

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


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