ALib C++ Library
Library Version: 2412 R0
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 74 of file timepointbase.hpp.

#include <timepointbase.hpp>

Inner Type Index:

class  Duration
 

Public Type Index:

using TRaw = typename TTimePoint::rep
 Integral type used for exporting and importing values in raw units.
 
using TTimePoint = typename TClock::time_point
 The internal c++ type for time points.
 

Public Static Method Index:

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

Public Method Index:

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

Protected Field Index:

TTimePoint stamp
 

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 81 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 78 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 684 of file timepointbase.hpp.

Constructor(s) / Destructor Details:

◆ TimePointBase() [1/2]

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

Constructor. With parameter init being defaulted, this constructor acts as the default constructor, which creates an instance representing the point in time when this constructor was invoked. This measures the current point in time, which introduces some effort.

To avoid this in situations where an instance is overwritten after construction (i.e., before it is read), parameter init can be passed to either Suppress or Nulled. Both values set this instance to a nulled state, as complete suppression is not available. Inn many situations the compiler will optimize out a nulled construction.

If not initialized, the method IsSet will return false.

Parameters
initIf Initialization::Default, the current time is measured and set. Defaults to Initialization::Default.

Definition at line 707 of file timepointbase.hpp.

◆ TimePointBase() [2/2]

template<typename TClock , typename TDerived >
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 750 of file timepointbase.hpp.

Method Details:

◆ Age()

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

Returns the time span between the 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 923 of file timepointbase.hpp.

◆ BeginningOfEpoch()

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

Returns an instance representing the beginning of the epoch. No time point represented by this type can be further in the past.

Returns
The earliest point in time.

Definition at line 724 of file timepointbase.hpp.

◆ EndOfEpoch()

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

Returns an instance representing the end of the epoch. No time point represented by this type can be further in the future.

Returns
A maximum point in time.

Definition at line 730 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 793 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 830 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 802 of file timepointbase.hpp.

◆ IsOlderThan()

template<typename TClock , typename TDerived >
bool IsOlderThan ( const 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 946 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 766 of file timepointbase.hpp.

◆ Now()

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

Returns an instance representing the actual point in time.

Returns
The current point in time time.

Definition at line 718 of file timepointbase.hpp.

◆ operator+() [1/2]

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

◆ operator+() [2/2]

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

Addition operator.

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

Definition at line 846 of file timepointbase.hpp.

◆ operator+=() [1/2]

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

◆ operator+=() [2/2]

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

Assignment by sum operator.

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

Definition at line 865 of file timepointbase.hpp.

◆ operator-() [1/3]

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

◆ operator-() [2/3]

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

◆ operator-() [3/3]

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

Subtraction operator.

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

Definition at line 881 of file timepointbase.hpp.

◆ operator-=() [1/2]

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

◆ operator-=() [2/2]

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

Assignment by difference operator.

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

Definition at line 900 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, (cast to the derived type) to allow concatenated operations.

Definition at line 737 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 784 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 820 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 935 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 813 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 775 of file timepointbase.hpp.


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