qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::TscTimePoint Class Reference

Represents a time point based on CPU's timestamp counter. More...

#include <timestamp.h>

Inheritance diagram for qb::TscTimePoint:
Collaboration diagram for qb::TscTimePoint:

Public Member Functions

 TscTimePoint ()
 Default constructor, initializes to current TSC time.
constexpr TimePoint () noexcept=default
 Default constructor, initializes to epoch.
constexpr TimePoint (rep nanoseconds) noexcept
 Constructs a time point with specified time since epoch.
template<typename Clock, typename ChronoDuration>
 TimePoint (const std::chrono::time_point< Clock, ChronoDuration > &time_point) noexcept
 Constructs a time point from std::chrono::time_point.
constexpr TimePoint (const TimePoint &) noexcept=default
constexpr TimePoint (TimePoint &&) noexcept=default
Public Member Functions inherited from qb::TimePoint
constexpr TimePoint () noexcept=default
 Default constructor, initializes to epoch.
constexpr TimePoint (rep nanoseconds) noexcept
 Constructs a time point with specified time since epoch.
template<typename Clock, typename ChronoDuration>
 TimePoint (const std::chrono::time_point< Clock, ChronoDuration > &time_point) noexcept
 Constructs a time point from std::chrono::time_point.
constexpr TimePoint (const TimePoint &) noexcept=default
constexpr TimePoint (TimePoint &&) noexcept=default
constexpr TimePointoperator= (const TimePoint &) noexcept=default
constexpr TimePointoperator= (TimePoint &&) noexcept=default
chrono_time_point to_chrono () const noexcept
 Converts to std::chrono::time_point.
template<typename Clock, typename ChronoDuration = typename Clock::duration>
std::chrono::time_point< Clock, ChronoDuration > to () const noexcept
 Converts to any std::chrono::time_point.
constexpr rep days () const noexcept
 Gets the time in days since epoch.
constexpr double days_float () const noexcept
 Gets the time in days since epoch with fractional precision.
constexpr rep hours () const noexcept
 Gets the time in hours since epoch.
constexpr double hours_float () const noexcept
 Gets the time in hours since epoch with fractional precision.
constexpr rep minutes () const noexcept
 Gets the time in minutes since epoch.
constexpr double minutes_float () const noexcept
 Gets the time in minutes since epoch with fractional precision.
constexpr rep seconds () const noexcept
 Gets the time in seconds since epoch.
constexpr double seconds_float () const noexcept
 Gets the time in seconds since epoch with fractional precision.
constexpr rep milliseconds () const noexcept
 Gets the time in milliseconds since epoch.
constexpr double milliseconds_float () const noexcept
 Gets the time in milliseconds since epoch with fractional precision.
constexpr rep microseconds () const noexcept
 Gets the time in microseconds since epoch.
constexpr double microseconds_float () const noexcept
 Gets the time in microseconds since epoch with fractional precision.
constexpr rep nanoseconds () const noexcept
 Gets the time in nanoseconds since epoch.
constexpr double nanoseconds_float () const noexcept
 Gets the time in nanoseconds since epoch with double precision.
Duration time_since_epoch () const noexcept
 Gets the duration since epoch.
constexpr rep count () const noexcept
 Gets the total time in nanoseconds since epoch.
std::string format (std::string_view format) const
 Formats the time point as a string.
std::string to_iso8601 () const
 Converts to ISO8601 string.
TimePointoperator+= (const Duration &duration) noexcept
 Adds a duration to this time point.
TimePointoperator-= (const Duration &duration) noexcept
 Subtracts a duration from this time point.

Static Public Member Functions

static TscTimePoint now () noexcept
 Gets current TSC time calibrated to system time.
Static Public Member Functions inherited from qb::TimePoint
static constexpr TimePoint epoch () noexcept
 Represents the epoch (1970-01-01 00:00:00 UTC)
static TimePoint now () noexcept
 Gets current system time.
static constexpr TimePoint from_days (int64_t days) noexcept
 Factory method to create a TimePoint from days since epoch.
static constexpr TimePoint from_hours (int64_t hours) noexcept
 Factory method to create a TimePoint from hours since epoch.
static constexpr TimePoint from_minutes (int64_t minutes) noexcept
 Factory method to create a TimePoint from minutes since epoch.
static constexpr TimePoint from_seconds (int64_t seconds) noexcept
 Factory method to create a TimePoint from seconds since epoch.
static constexpr TimePoint from_milliseconds (int64_t ms) noexcept
 Factory method to create a TimePoint from milliseconds since epoch.
static constexpr TimePoint from_microseconds (int64_t us) noexcept
 Factory method to create a TimePoint from microseconds since epoch.
static constexpr TimePoint from_nanoseconds (int64_t ns) noexcept
 Factory method to create a TimePoint from nanoseconds since epoch.
static std::optional< TimePointfrom_iso8601 (std::string_view iso8601) noexcept
 Creates a TimePoint from ISO8601 string.
static std::optional< TimePointparse (std::string_view time_string, std::string_view format) noexcept
 Factory method to parse a string into a TimePoint.
static uint64_t read_tsc () noexcept
 Reads CPU timestamp counter.
static uint64_t nano () noexcept
 Gets the current time in nanoseconds since epoch.

Additional Inherited Members

Public Types inherited from qb::TimePoint
using rep = uint64_t
 Type used for nanosecond representation.
using chrono_time_point
 Underlying std::chrono time point type.
Protected Attributes inherited from qb::TimePoint
rep _time_since_epoch {0}
 Time in nanoseconds since epoch.

Detailed Description

Represents a time point based on CPU's timestamp counter.

Extends TimePoint to specifically represent times based on the CPU's timestamp counter, which provides very high precision but may vary between CPU cores.

Member Function Documentation

◆ now()

TscTimePoint qb::TscTimePoint::now ( )
inlinestaticnoexcept

Gets current TSC time calibrated to system time.

Returns
TscTimePoint based on CPU timestamp counter but aligned with system time

◆ TimePoint() [1/2]

qb::TimePoint::TimePoint ( rep nanoseconds)
inlineexplicitconstexprnoexcept

Constructs a time point with specified time since epoch.

Parameters
nanosecondsTime in nanoseconds since epoch

◆ TimePoint() [2/2]

template<typename Clock, typename ChronoDuration>
qb::TimePoint::TimePoint ( const std::chrono::time_point< Clock, ChronoDuration > & time_point)
inlineexplicitnoexcept

Constructs a time point from std::chrono::time_point.

Template Parameters
ClockThe clock type
DurationThe duration type
Parameters
time_pointA std::chrono time point