Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Realtime.h File Reference
#include "Stroika/Foundation/StroikaPreComp.h"
#include <chrono>
#include "Stroika/Foundation/Common/TypeHints.h"
#include "Stroika/Foundation/Time/Clock.h"
#include "Stroika/Foundation/Traversal/Common.h"
#include "Realtime.inl"

Go to the source code of this file.

Namespaces

namespace  Stroika::Foundation
 
namespace  Stroika::Foundation::Traversal::RangeTraits
 

Typedefs

using Stroika::Foundation::Time::DurationSeconds = chrono::duration< double >
 chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
 
using Stroika::Foundation::Time::RealtimeClock = chrono::steady_clock
 this is an alias for steady_clock; this is the clock used for GetTickCount () results.
 
using Stroika::Foundation::Time::TimePointSeconds = time_point< RealtimeClock, DurationSeconds >
 TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates everywhere.
 
using Stroika::Foundation::Time::DisplayedRealtimeClock = AppStartZeroedClock< RealtimeClock, DurationSeconds >
 

Functions

TimePointSeconds Stroika::Foundation::Time::GetTickCount () noexcept
 get the current (monotonically increasing) time - from RealtimeClock
 

Variables

constexpr DurationSeconds Stroika::Foundation::Time::kInfinity = DurationSeconds{numeric_limits<DurationSeconds::rep>::infinity ()}
 

Detailed Description

Note
Code-Status: Beta

Definition in file Realtime.h.

Typedef Documentation

◆ DurationSeconds

using Stroika::Foundation::Time::DurationSeconds = typedef chrono::duration<double>

chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.

DurationSeconds is just a choice of what chrono::duration template parameters to use to make use much simpler. Converting to a common sensible base format greatly simplifies a number of Stroika APIs, so rather than having to template all your 'duration' arguments, just use this DurationSeconds for simplicity, clarity, and at only a small cost.

Note
this is one of two types which replaces the Stroika v2.1 DurationSecondsType (DurationSeconds and TimePointSeconds)
Because chrono::duration supports automatic conversion from other 'base units' etc, you can maintain your code/data structures with any chrono::duration<> and seamlessly use Stroika APIs which expect DurationSeconds.
Use double instead of long double (as the rep) because we don't have time to test performance impact, and only some (gcc/unix) systems make a difference anyhow (not on ppc). Everything else in Stroika should key off this choice, so this is the place to change the basic rep used throughout Stroika if I need to experiment (float/long double).
DurationSeconds is a 'floating point version of chrono::seconds'
- WHY is it so important Stroika uses a 'floating point' version of duration. Consider this code: TimeOutAt t = now + REALLY_BIG_TIMOUT; say we define REALLY_BIG_TIMEOUT = DURUATION::max(); if we used fixed point numbers, REALLY_BIG_TIMOUT + tiny number wraps - basically back to zero. with floating point numbers, max + small number remains max. That's a HUGE, and USEFUL simplification of wildly common code.
See also
See Also Duration - which can be easily interoperate with DurationSeconds - which provides additional functionality.

Definition at line 57 of file Realtime.h.

◆ RealtimeClock

using Stroika::Foundation::Time::RealtimeClock = typedef chrono::steady_clock

this is an alias for steady_clock; this is the clock used for GetTickCount () results.

The clock it uses IS guaranteed to be a 'steady' clock, though not necessarily THE 'steady_clock' class.

Note
- could use AppStartZeroedClock to get zero-based results, or clock_cast to map from regular tick-counts to zero based.

Definition at line 70 of file Realtime.h.

◆ TimePointSeconds

using Stroika::Foundation::Time::TimePointSeconds = typedef time_point<RealtimeClock, DurationSeconds>

TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates everywhere.

But - TimePointSeconds - since it uses chrono::time_point - is mostly (see Pin2SafeSeconds()) interoperable with the other time_point etc objects.

Note
- CARE is required passing this value to STD C++ APIs!; see and consider using Pin2SafeSeconds() in calling those APIs.
See also
RealtimeClock for details of how time is measured.

Definition at line 82 of file Realtime.h.

◆ DisplayedRealtimeClock

using Stroika::Foundation::Time::DisplayedRealtimeClock = typedef AppStartZeroedClock<RealtimeClock, DurationSeconds>

If you want to convert tick-count times to be zero based (often helpful for display purposes), you can use:

clock_cast<DisplayedRealtimeClock> (GetTickCount ())

Definition at line 112 of file Realtime.h.

Function Documentation

◆ GetTickCount()

TimePointSeconds Stroika::Foundation::Time::GetTickCount ( )
noexcept

get the current (monotonically increasing) time - from RealtimeClock

Note
no longer true, but in Stroika v2.1: this always started at offset zero for start of app. this always used steady_clock (now see TimePointSeconds). it used to return a 'float' type and now returns a chrono::time_point<> type (for better type safety).

Since Stroika v3.0d5 - defined to be based on RealtimeClock (which is same - steady_clock), and uses double internally (using DurationSeconds = chrono::duration<double>). And to get it to be zero based,

Time::clock_cast<Time::AppStartZeroedClock<Time::RealtimeClock>> (Time::GetTickCount ());

Definition at line 16 of file Realtime.inl.

Variable Documentation

◆ kInfinity

constexpr DurationSeconds Stroika::Foundation::Time::kInfinity = DurationSeconds{numeric_limits<DurationSeconds::rep>::infinity ()}
constexpr

@See http://stroika-bugs.sophists.com/browse/STK-619 CONSIDER LOSING THIS - AND USE special TYPE and overloading, and handle kInfinity differently - no arithmatic, just no timeout

Definition at line 104 of file Realtime.h.