ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
TimePointBase< TClock, TDerived > Class Template Reference

Description:

template<typename TClock, typename TDerived>
class alib::time::TimePointBase< TClock, TDerived >

As explained in detail in the documentation of module ALib Time , a steady time model is supported with class Ticks and a non-steady one representing the system clock with class DateTime . Both types share this template class as their generic base.

The common features that this class provides to its descendants are:

  • Type definition TTimePoint used to store a point in time.
  • Method Export, which returns the internal value of type TTimePoint which is of C++ standard type std::chrono::time_point.
  • Inner class Duration that represents the difference type of this class.
  • Static method Now which creates an instance representing the current point in time.
  • Methods Age and Since.
  • Various overloaded arithmetic and comparison operators.
Note
The resolution and accuracy of the values is platform dependent. Especially nanoseconds are deemed to be inaccurate if below several hundreds (this was written and fact in 2013, reviewed 2019).
Attention
The dates storable in objects of this class are limited to a certain time range. In the current GNU/Linux and Windows implementations the range is roughly +-292.27 years before and after the point in time that the system that the software is running on was initialized (bootstrapped). This value results from the following facts for these implementations:
  • the storage resolution is one nanosecond.
  • the storage size is 64 bits (63 plus the sign bit).
  • system dependent ticks counters are reset to 0 with the boot of a system.

Now, dividing 2^63 by the number of nanoseconds of one year which consists of roughly 365.25 days, this results in 292.27 years.

Template Parameters
TClockThe type of clock to use. This will be
  • std::chrono::system_clock with descendant class DateTime and
  • std::chrono::steady_clock with descendant class Ticks .
TDerivedThe derived type itself, hence either DateTime or Ticks . This template parameter is needed to define the result type of various methods and operators.

Definition at line 88 of file timepointbase.hpp.

#include <timepointbase.hpp>

Inner Type Index:

class  Duration
 

Public Type Index:

using TRaw = typename TTimePoint::rep
 
using TTimePoint = typename TClock::time_point
 

Public Static Method Index:

static TDerived FromRaw (TRaw raw)
 
static TDerived Now ()
 

Public Method Index:

constexpr TimePointBase (lang::Initialization init=lang::Initialization::Perform)
 
constexpr TimePointBase (TTimePoint internalValue)
 
Duration Age () const
 
TTimePoint Export () const
 
void Import (TTimePoint timePoint)
 
bool IsOlderThan (Duration timeSpan) const
 
bool IsSet ()
 
TDerived operator+ (const Duration &timeSpan) const
 
TDerived operator+= (const Duration &timeSpan)
 
TDerived operator- (const Duration &timeSpan) const
 
Duration operator- (const TDerived &other) const
 
TDerived operator-= (const Duration &timeSpan)
 
TDerived & Reset ()
 
void SetAs (const TDerived &other)
 
void SetFromRaw (TRaw raw)
 
Duration Since (const TDerived &other) const
 
TRaw ToRaw () const
 
void Unset ()
 

Type Definition Details:

◆ TRaw

template<typename TClock , typename TDerived >
using TRaw = typename TTimePoint::rep

Integral type used for exporting and importing values in raw units.

Definition at line 95 of file timepointbase.hpp.

◆ TTimePoint

template<typename TClock , typename TDerived >
using TTimePoint = typename TClock::time_point

The internal c++ type for time points.

Definition at line 92 of file timepointbase.hpp.

Field Details:

◆ stamp

template<typename TClock , typename TDerived >
TTimePoint stamp
protected

The internal timer value. This value can be accessed using methods Export and Import.

Definition at line 673 of file timepointbase.hpp.

Constructor(s) / Destructor Details::

◆ TimePointBase() [1/2]

template<typename TClock , typename TDerived >
constexpr TimePointBase ( lang::Initialization init = lang::Initialization::Perform)
inlineconstexpr

Creates an instance representing the point in time when this constructor was invoked.

The default invocation measures the current point in time, which introduces some effort. To avoid this in situations where an instance is overwritten by the result of static method Now at a later point in time, parameter init can be used to suppress the initial measurement.

Parameters
initIf Initialization::Perform, the current time is measured and set. If Initialization::Suppress, the time stamp will be initialized to represent the start of the epoch.
Defaults to Initialization::Perform.

Definition at line 695 of file timepointbase.hpp.

◆ TimePointBase() [2/2]

template<typename TClock , typename TDerived >
constexpr TimePointBase ( TTimePoint internalValue)
inlineconstexpr

Constructor using native C++ library values.

See also
Methods Import and Export.
Parameters
internalValueThe value to copy into this.

Definition at line 730 of file timepointbase.hpp.

Method Details:

◆ Age()

template<typename TClock , typename TDerived >
Duration Age ( ) const
inline

Returns the time span between value represented by this instance and the current system time. If the internal value represents a historic point in time, the result is positive.

Returns
The age of this instance stored in a new Duration.

Definition at line 883 of file timepointbase.hpp.

◆ Export()

template<typename TClock , typename TDerived >
TTimePoint Export ( ) const
inline

Returns the internal time value in the C++ standard library type.

Returns
The internal value.

Definition at line 773 of file timepointbase.hpp.

◆ FromRaw()

template<typename TClock , typename TDerived >
static TDerived FromRaw ( TRaw raw)
inlinestatic

Creates an instance from a value of C++ standard library's tick unit type.

Parameters
rawThe time span to create in raw units.
Returns
The internal value.

Definition at line 814 of file timepointbase.hpp.

◆ Import()

template<typename TClock , typename TDerived >
void Import ( TTimePoint timePoint)
inline

Sets the internal time value given by a value of C++ standard library type.

Parameters
timePointThe value to set.

Definition at line 782 of file timepointbase.hpp.

◆ IsOlderThan()

template<typename TClock , typename TDerived >
bool IsOlderThan ( Duration timeSpan) const
inline

Determines if this object's age is higher than a given time span.

Parameters
timeSpanA time span to compare.
Returns
true if the given time span is smaller equal than the age of this object, hence to the time span passed since the point in time this object represents. false otherwise.

Definition at line 910 of file timepointbase.hpp.

Here is the call graph for this function:

◆ IsSet()

template<typename TClock , typename TDerived >
bool IsSet ( )
inline

Returns true if this object is not representing the start of the epoch. An uninitialized object that returns false can be created with provision of Initialization::Suppress on construction.

Returns
true if this object is initialized, false otherwise.

Definition at line 746 of file timepointbase.hpp.

◆ Now()

template<typename TClock , typename TDerived >
static TDerived Now ( )
inlinestatic

Returns an instance representing the actual point in time.

Returns
A value type of TDerived . Usually this is assigned to a value variable which might have been constructed with measurement suppression.

Definition at line 707 of file timepointbase.hpp.

◆ operator+()

template<typename TClock , typename TDerived >
TDerived operator+ ( const Duration & timeSpan) const
inline

Addition operator.

Parameters
timeSpanThe time span to add.
Returns
A time stamp object containing the sum.

Definition at line 824 of file timepointbase.hpp.

◆ operator+=()

template<typename TClock , typename TDerived >
TDerived operator+= ( const Duration & timeSpan)
inline

Assignment by sum operator.

Parameters
timeSpanThe time span to add.
Returns
A reference to this object.

Definition at line 834 of file timepointbase.hpp.

◆ operator-() [1/2]

template<typename TClock , typename TDerived >
TDerived operator- ( const Duration & timeSpan) const
inline

Subtraction operator.

Parameters
timeSpanThe time span to subtract.
Returns
A time stamp object containing the sum.

Definition at line 845 of file timepointbase.hpp.

◆ operator-() [2/2]

template<typename TClock , typename TDerived >
Duration operator- ( const TDerived & other) const
inline

Subtraction operator with other time span argument. If the given time stamp represents a point in type earlier than the one this object represents, the result is positive.

Parameters
otherThe time stamp to subtract.
Returns
A time span object containing the difference.

Definition at line 867 of file timepointbase.hpp.

◆ operator-=()

template<typename TClock , typename TDerived >
TDerived operator-= ( const Duration & timeSpan)
inline

Assignment by difference operator.

Parameters
timeSpanThe time span to subtract.
Returns
A reference to this object.

Definition at line 855 of file timepointbase.hpp.

◆ Reset()

template<typename TClock , typename TDerived >
TDerived & Reset ( )
inline

Resets this instance to the current point in time.

Returns
A reference to this, (casted to the derived type) to allow concatenated operations.

Definition at line 717 of file timepointbase.hpp.

◆ SetAs()

template<typename TClock , typename TDerived >
void SetAs ( const TDerived & other)
inline

Copies the value from the given object.

Parameters
otherThe point in time to copy from.

Definition at line 764 of file timepointbase.hpp.

◆ SetFromRaw()

template<typename TClock , typename TDerived >
void SetFromRaw ( TRaw raw)
inline

Sets the value from a value of C++ standard library's tick unit type.

Parameters
rawThe time span to create in raw units.

Definition at line 802 of file timepointbase.hpp.

◆ Since()

template<typename TClock , typename TDerived >
Duration Since ( const TDerived & other) const
inline

Returns the time span between the value represented by this instance and the given other time stamp. If the given time stamp represents an earlier point in time, the result is positive.

Parameters
otherThe value to compare this instance with
Returns
The age of this instance stored in the given or created object.

Definition at line 897 of file timepointbase.hpp.

◆ ToRaw()

template<typename TClock , typename TDerived >
TRaw ToRaw ( ) const
inline

Returns the internal time value in the C++ standard library's tick unit.

Returns
The internal value.

Definition at line 793 of file timepointbase.hpp.

◆ Unset()

template<typename TClock , typename TDerived >
void Unset ( )
inline

Unsets this object, hence makes this object representing the start of the epoch, as if it was constructed with parameter value Initialization::Suppress.

Definition at line 755 of file timepointbase.hpp.


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