ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
Public Types | Inner Classes | Public Static Methods | Public Methods | Protected Fields | List of all members
TimePointBase< TClock, TDerived > Class Template Reference

#include <timepointbase.hpp>

Class Description

template<typename TClock, typename TDerived>
class aworx::lib::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:

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.

Public Types

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

Inner Classes

class  Duration
 

Public Static Methods

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

Public Methods

ALIB_CPP14_CONSTEXPR TimePointBase (Initialization init=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)
 
void SetAs (const TDerived &other)
 
void SetFromRaw (TRaw raw)
 
Duration Since (const TDerived &other) const
 
TRaw ToRaw () const
 
void Unset ()
 

Protected Fields

TTimePoint stamp
 

Member Typedef Documentation

◆ TRaw

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

using TTimePoint = typename TClock::time_point

The internal c++ type for time points.

Definition at line 92 of file timepointbase.hpp.

Constructor & Destructor Documentation

◆ TimePointBase() [1/2]


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]

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 719 of file timepointbase.hpp.

Member Function Documentation

◆ Age()

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 872 of file timepointbase.hpp.

◆ Export()

TTimePoint Export ( ) const
inline

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

Returns
The internal value.

Definition at line 762 of file timepointbase.hpp.

◆ FromRaw()

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 803 of file timepointbase.hpp.

◆ Import()

void Import ( TTimePoint  timePoint)
inline

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

Parameters
timePointThe value to set.

Definition at line 771 of file timepointbase.hpp.

◆ IsOlderThan()

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 899 of file timepointbase.hpp.

◆ IsSet()

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 735 of file timepointbase.hpp.

◆ Now()

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+()

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 813 of file timepointbase.hpp.

◆ operator+=()

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 823 of file timepointbase.hpp.

◆ operator-() [1/2]

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 834 of file timepointbase.hpp.

◆ operator-() [2/2]

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 856 of file timepointbase.hpp.

◆ operator-=()

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 844 of file timepointbase.hpp.

◆ SetAs()

void SetAs ( const TDerived &  other)
inline

Copies the value from the given object.

Parameters
otherThe point in time to copy from.

Definition at line 753 of file timepointbase.hpp.

◆ SetFromRaw()

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 791 of file timepointbase.hpp.

◆ Since()

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 886 of file timepointbase.hpp.

◆ ToRaw()

TRaw ToRaw ( ) const
inline

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

Returns
The internal value.

Definition at line 782 of file timepointbase.hpp.

◆ Unset()

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 744 of file timepointbase.hpp.

Member Data Documentation

◆ stamp

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.


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