Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::Duration Class Reference

Strongly-typed time span with cached conversions between ns/ms/s. More...

#include <spk_duration.hpp>

Collaboration diagram for spk::Duration:
Collaboration graph

Public Member Functions

 Duration ()
 Constructs a zero duration (milliseconds by default).
 Duration (long double p_value, TimeUnit p_unit)
 Constructs a duration with value and unit.
 Duration (const Duration &p_other)
 Copies duration value and unit from another instance.
 Duration (Duration &&p_other) noexcept
 Moves duration value and cached data from another instance.
Durationoperator= (const Duration &p_other)
 Copies duration value and unit from another instance.
Durationoperator= (Duration &&p_other) noexcept
 Moves duration value and cache ownership from another instance.
long long nanoseconds () const
 Returns the duration in nanoseconds.
long long milliseconds () const
 Returns the duration in milliseconds.
double seconds () const
 Returns the duration in seconds.
Duration operator- () const
 Unary minus producing the symmetric duration.
Duration operator+ (const Duration &p_o) const
 Adds two durations.
Duration operator- (const Duration &p_o) const
 Subtracts another duration.
Durationoperator+= (const Duration &p_o)
 Adds another duration to this instance.
Durationoperator-= (const Duration &p_o)
 Subtracts another duration from this instance.
bool operator== (const Duration &p_o) const
 Equality comparison using canonical nanoseconds.
bool operator!= (const Duration &p_o) const
 Inequality comparison using canonical nanoseconds.
bool operator< (const Duration &p_o) const
 Strictly-less comparison using canonical nanoseconds.
bool operator> (const Duration &p_o) const
 Strictly-greater comparison using canonical nanoseconds.
bool operator<= (const Duration &p_o) const
 Less-or-equal comparison using canonical nanoseconds.
bool operator>= (const Duration &p_o) const
 Greater-or-equal comparison using canonical nanoseconds.

Detailed Description

Strongly-typed time span with cached conversions between ns/ms/s.

Constructor & Destructor Documentation

◆ Duration() [1/3]

spk::Duration::Duration ( long double p_value,
TimeUnit p_unit )

Constructs a duration with value and unit.

Parameters
p_valueNumeric value.
p_unitUnit (ns, ms, s).

◆ Duration() [2/3]

spk::Duration::Duration ( const Duration & p_other)

Copies duration value and unit from another instance.

Parameters
p_otherDuration to copy.
Here is the call graph for this function:

◆ Duration() [3/3]

spk::Duration::Duration ( Duration && p_other)
noexcept

Moves duration value and cached data from another instance.

Parameters
p_otherDuration to move.
Here is the call graph for this function:

Member Function Documentation

◆ milliseconds()

long long spk::Duration::milliseconds ( ) const

Returns the duration in milliseconds.

Returns
Duration value expressed in milliseconds.
Here is the caller graph for this function:

◆ nanoseconds()

long long spk::Duration::nanoseconds ( ) const

Returns the duration in nanoseconds.

Returns
Duration value expressed in nanoseconds.
Here is the caller graph for this function:

◆ operator!=()

bool spk::Duration::operator!= ( const Duration & p_o) const

Inequality comparison using canonical nanoseconds.

Parameters
p_oOther duration to compare.
Returns
true when durations differ.
Here is the call graph for this function:

◆ operator+()

Duration spk::Duration::operator+ ( const Duration & p_o) const

Adds two durations.

Parameters
p_oOther duration to add.
Returns
Sum of durations.
Here is the call graph for this function:

◆ operator+=()

Duration & spk::Duration::operator+= ( const Duration & p_o)

Adds another duration to this instance.

Parameters
p_oOther duration to add.
Returns
Reference to this duration.
Here is the call graph for this function:

◆ operator-() [1/2]

Duration spk::Duration::operator- ( ) const

Unary minus producing the symmetric duration.

Returns
Negated duration.
Here is the call graph for this function:

◆ operator-() [2/2]

Duration spk::Duration::operator- ( const Duration & p_o) const

Subtracts another duration.

Parameters
p_oOther duration to subtract.
Returns
Difference of durations.
Here is the call graph for this function:

◆ operator-=()

Duration & spk::Duration::operator-= ( const Duration & p_o)

Subtracts another duration from this instance.

Parameters
p_oOther duration to subtract.
Returns
Reference to this duration.
Here is the call graph for this function:

◆ operator<()

bool spk::Duration::operator< ( const Duration & p_o) const

Strictly-less comparison using canonical nanoseconds.

Parameters
p_oOther duration to compare.
Returns
true when this duration is shorter.
Here is the call graph for this function:

◆ operator<=()

bool spk::Duration::operator<= ( const Duration & p_o) const

Less-or-equal comparison using canonical nanoseconds.

Parameters
p_oOther duration to compare.
Returns
true when this duration is shorter or equal.
Here is the call graph for this function:

◆ operator=() [1/2]

Duration & spk::Duration::operator= ( const Duration & p_other)

Copies duration value and unit from another instance.

Parameters
p_otherDuration to copy.
Returns
Reference to this duration.
Here is the call graph for this function:

◆ operator=() [2/2]

Duration & spk::Duration::operator= ( Duration && p_other)
noexcept

Moves duration value and cache ownership from another instance.

Parameters
p_otherDuration to move.
Returns
Reference to this duration.
Here is the call graph for this function:

◆ operator==()

bool spk::Duration::operator== ( const Duration & p_o) const

Equality comparison using canonical nanoseconds.

Parameters
p_oOther duration to compare.
Returns
true when durations are equal.
Here is the call graph for this function:

◆ operator>()

bool spk::Duration::operator> ( const Duration & p_o) const

Strictly-greater comparison using canonical nanoseconds.

Parameters
p_oOther duration to compare.
Returns
true when this duration is longer.
Here is the call graph for this function:

◆ operator>=()

bool spk::Duration::operator>= ( const Duration & p_o) const

Greater-or-equal comparison using canonical nanoseconds.

Parameters
p_oOther duration to compare.
Returns
true when this duration is longer or equal.
Here is the call graph for this function:

◆ seconds()

double spk::Duration::seconds ( ) const

Returns the duration in seconds.

Returns
Duration value expressed in seconds.
Here is the caller graph for this function:

The documentation for this class was generated from the following files:
  • includes/structure/system/time/spk_duration.hpp
  • srcs/structure/system/time/spk_duration.cpp