libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
TimeStamp Class Reference

A monotonic timestamp based on std::chrono::steady_clock. More...

#include <timestamp.h>

Public Types

using Clock = std::chrono::steady_clock
 Underlying clock type.
 
using Value = std::chrono::time_point< Clock >
 Time point value type.
 
using Duration = Clock::duration
 Duration type derived from the clock.
 

Public Member Functions

 TimeStamp ()
 Constructs a default (epoch) TimeStamp.
 
 TimeStamp (const Value &v)
 Constructs a TimeStamp from the given time point value.
 
 operator Value () const
 Converts the TimeStamp to its underlying Value type.
 
TimeStampoperator+= (const Duration &duration)
 Advances the timestamp by the given duration.
 
TimeStampoperator-= (const Duration &duration)
 Moves the timestamp back by the given duration.
 
void setValue (const Value &v)
 Sets the underlying time point value.
 
Value value () const
 Returns the underlying time point value.
 
void update ()
 Updates the timestamp to the current time.
 
void sleepUntil () const
 Sleeps the current thread until this timestamp is reached.
 
Duration timeSinceEpoch () const
 Returns the duration since the clock's epoch.
 
double seconds () const
 Returns the time since epoch in seconds as a double.
 
int64_t milliseconds () const
 Returns the time since epoch in milliseconds.
 
int64_t microseconds () const
 Returns the time since epoch in microseconds.
 
int64_t nanoseconds () const
 Returns the time since epoch in nanoseconds.
 
double elapsedSeconds () const
 Returns the elapsed time since this timestamp in seconds.
 
int64_t elapsedMilliseconds () const
 Returns the elapsed time since this timestamp in milliseconds.
 
int64_t elapsedMicroseconds () const
 Returns the elapsed time since this timestamp in microseconds.
 
int64_t elapsedNanoseconds () const
 Returns the elapsed time since this timestamp in nanoseconds.
 
String toString () const
 Returns a string representation of the timestamp in seconds.
 
 operator String () const
 Converts the TimeStamp to a String.
 

Static Public Member Functions

static Duration secondsToDuration (double val)
 Converts a floating-point number of seconds to a Duration.
 
static void sleep (const Duration &d)
 Sleeps the current thread for the given duration.
 
static TimeStamp now ()
 Returns a TimeStamp representing the current time.
 

Detailed Description

A monotonic timestamp based on std::chrono::steady_clock.

Provides high-resolution time measurement, elapsed time queries, and thread sleep utilities. Uses steady_clock to guarantee monotonic

Example
// ... do work ...
double elapsed = start.elapsedSeconds();
A monotonic timestamp based on std::chrono::steady_clock.
Definition timestamp.h:32
static TimeStamp now()
Returns a TimeStamp representing the current time.
Definition timestamp.h:64
double elapsedSeconds() const
Returns the elapsed time since this timestamp in seconds.
Definition timestamp.h:173
progression regardless of system clock adjustments.

Constructor & Destructor Documentation

◆ TimeStamp()

TimeStamp::TimeStamp ( const Value v)
inline

Constructs a TimeStamp from the given time point value.

Parameters
vThe time point value.

Member Function Documentation

◆ elapsedMicroseconds()

int64_t TimeStamp::elapsedMicroseconds ( ) const
inline

Returns the elapsed time since this timestamp in microseconds.

Returns
Elapsed microseconds.

◆ elapsedMilliseconds()

int64_t TimeStamp::elapsedMilliseconds ( ) const
inline

Returns the elapsed time since this timestamp in milliseconds.

Returns
Elapsed milliseconds.

◆ elapsedNanoseconds()

int64_t TimeStamp::elapsedNanoseconds ( ) const
inline

Returns the elapsed time since this timestamp in nanoseconds.

Returns
Elapsed nanoseconds.

◆ elapsedSeconds()

double TimeStamp::elapsedSeconds ( ) const
inline

Returns the elapsed time since this timestamp in seconds.

Returns
Elapsed seconds as a double.

◆ microseconds()

int64_t TimeStamp::microseconds ( ) const
inline

Returns the time since epoch in microseconds.

Returns
Microseconds since the clock's epoch.

◆ milliseconds()

int64_t TimeStamp::milliseconds ( ) const
inline

Returns the time since epoch in milliseconds.

Returns
Milliseconds since the clock's epoch.

◆ nanoseconds()

int64_t TimeStamp::nanoseconds ( ) const
inline

Returns the time since epoch in nanoseconds.

Returns
Nanoseconds since the clock's epoch.

◆ now()

static TimeStamp TimeStamp::now ( )
inlinestatic

Returns a TimeStamp representing the current time.

Returns
A TimeStamp initialized to the current steady_clock time.

◆ operator+=()

TimeStamp & TimeStamp::operator+= ( const Duration duration)
inline

Advances the timestamp by the given duration.

Parameters
durationThe duration to add.
Returns
Reference to this TimeStamp.

◆ operator-=()

TimeStamp & TimeStamp::operator-= ( const Duration duration)
inline

Moves the timestamp back by the given duration.

Parameters
durationThe duration to subtract.
Returns
Reference to this TimeStamp.

◆ seconds()

double TimeStamp::seconds ( ) const
inline

Returns the time since epoch in seconds as a double.

Returns
Seconds since the clock's epoch.

◆ secondsToDuration()

static Duration TimeStamp::secondsToDuration ( double  val)
inlinestatic

Converts a floating-point number of seconds to a Duration.

Parameters
valThe time in seconds.
Returns
The equivalent Duration value.

◆ setValue()

void TimeStamp::setValue ( const Value v)
inline

Sets the underlying time point value.

Parameters
vThe new time point value.

◆ sleep()

static void TimeStamp::sleep ( const Duration d)
inlinestatic

Sleeps the current thread for the given duration.

Parameters
dThe duration to sleep.

◆ timeSinceEpoch()

Duration TimeStamp::timeSinceEpoch ( ) const
inline

Returns the duration since the clock's epoch.

Returns
The duration from epoch to this timestamp.

◆ toString()

String TimeStamp::toString ( ) const
inline

Returns a string representation of the timestamp in seconds.

Returns
A String containing the seconds value.

◆ value()

Value TimeStamp::value ( ) const
inline

Returns the underlying time point value.

Returns
The stored time point.

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