SDL Utility
Time Class Reference

This class wraps std::chrono::duration and defines some conversions for commonly used times. More...

#include <Time.hpp>

Public Member Functions

 Time ()
 Default constructor. Constructs a time with value 0. More...
 
template<typename Rep = Int64, typename Period = std::ratio<1>>
Rep AsValue () const
 Returns the stored time in the specified format as a scalar. More...
 
float AsSeconds () const
 Returns the stored time in seconds. More...
 
Int32 AsMilliseconds () const
 Returns the stored time in milliseconds. More...
 
Int64 AsMicroseconds () const
 Returns the stored time in microseconds. More...
 
template<typename Rep = Int64, typename Period = std::ratio<1>>
std::chrono::duration< Rep, Period > AsChrono () const
 Returns the stored time in the specified format as a std::duration. More...
 
std::chrono::seconds AsChronoSeconds () const
 Returns the stored time in std::chrono::seconds. More...
 
std::chrono::milliseconds AsChronoMilliseconds () const
 Returns the stored time in std::chrono::milliseconds. More...
 
std::chrono::microseconds AsChronoMicroseconds () const
 Returns the stored time in std::chrono::microseconds. More...
 

Static Public Member Functions

template<typename Rep = Int64, typename Period = std::ratio<1>>
static Time Create (const Rep &duration)
 Stores the given scalar as a time, using the given format. More...
 
template<typename Rep = Int64, typename Period = std::ratio<1>>
static Time Create (const std::chrono::duration< Rep, Period > &duration)
 Stores the given std::duration. More...
 
static Time Now ()
 Creates a Time object storing the current point in time. More...
 

Friends

Time Seconds (float seconds)
 Creates a Time object from a given number of seconds. More...
 
Time Milliseconds (Int32 milliseconds)
 Creates a Time object from a given number of milliseconds. More...
 
Time Microseconds (Int64 microseconds)
 Creates a Time object from a given number of microseconds. More...
 
bool operator== (const Time &left, const Time &right)
 Overload of == operator comparing two Times. More...
 
bool operator!= (const Time &left, const Time &right)
 Overload of != operator comparing two Times. More...
 
bool operator< (const Time &left, const Time &right)
 Overload of < operator comparing two Times. More...
 
bool operator> (const Time &left, const Time &right)
 Overload of > operator comparing two Times. More...
 
bool operator<= (const Time &left, const Time &right)
 Overload of <= operator comparing two Times. More...
 
bool operator>= (const Time &left, const Time &right)
 Overload of < operator comparing two Times. More...
 
Time operator- (const Time &right)
 Overload of the unary - operator. More...
 
Time operator+ (const Time &left, const Time &right)
 Overload of + operator to add two Times. More...
 
Timeoperator+= (Time &left, const Time &right)
 Overload of += operator to add two Times. More...
 
Time operator- (const Time &left, const Time &right)
 Overload of - operator to subtract two Times. More...
 
Timeoperator-= (Time &left, const Time &right)
 Overload of -= operator to subtract two Times. More...
 
Time operator* (const Time &left, float right)
 Overload of * operator to multiply a Time with a scalar. More...
 
Time operator* (const Time &left, Int64 right)
 Overload of * operator to multiply a Time with a scalar. More...
 
Time operator* (float left, const Time &right)
 Overload of * operator to multiply a Time with a scalar. More...
 
Time operator* (Int64 left, const Time &right)
 Overload of * operator to multiply a Time with a scalar. More...
 
Timeoperator*= (Time &left, float right)
 Overload of *= operator to multiply a Time with a scalar. More...
 
Timeoperator*= (Time &left, Int64 right)
 Overload of *= operator to multiply a Time with a scalar. More...
 
Time operator/ (const Time &left, float right)
 Overload of / operator to divide a Time by a scalar. More...
 
Time operator/ (const Time &left, Int64 right)
 Overload of / operator to divide a Time by a scalar. More...
 
Timeoperator/= (Time &left, float right)
 Overload of /= operator to divide a Time by a scalar. More...
 
Timeoperator/= (Time &left, Int64 right)
 Overload of /= operator to divide a Time by a scalar. More...
 
float operator/ (const Time &left, const Time &right)
 Overload of / operator to divide two Times. More...
 
Time operator% (const Time &left, const Time &right)
 Overload of % operator to calculate the modulo of a Time. More...
 
Timeoperator%= (Time &left, const Time &right)
 Overload of % operator to calculate the modulo of a Time. More...
 

Detailed Description

This class wraps std::chrono::duration and defines some conversions for commonly used times.

Constructor & Destructor Documentation

◆ Time()

Time::Time ( )

Default constructor. Constructs a time with value 0.

Member Function Documentation

◆ AsChrono()

template<typename Rep , typename Period >
std::chrono::duration< Rep, Period > Time::AsChrono
inline

Returns the stored time in the specified format as a std::duration.

Template Parameters
RepThe datatype to be returned
PeriodAn std::ratio representing the resolution of the time format. E.g. the number of seconds per time step
Returns
A std::duration value representing the stored time

◆ AsChronoMicroseconds()

std::chrono::microseconds Time::AsChronoMicroseconds ( ) const

Returns the stored time in std::chrono::microseconds.

◆ AsChronoMilliseconds()

std::chrono::milliseconds Time::AsChronoMilliseconds ( ) const

Returns the stored time in std::chrono::milliseconds.

◆ AsChronoSeconds()

std::chrono::seconds Time::AsChronoSeconds ( ) const

Returns the stored time in std::chrono::seconds.

◆ AsMicroseconds()

Int64 Time::AsMicroseconds ( ) const

Returns the stored time in microseconds.

◆ AsMilliseconds()

Int32 Time::AsMilliseconds ( ) const

Returns the stored time in milliseconds.

◆ AsSeconds()

float Time::AsSeconds ( ) const

Returns the stored time in seconds.

◆ AsValue()

template<typename Rep , typename Period >
Rep Time::AsValue
inline

Returns the stored time in the specified format as a scalar.

Template Parameters
RepThe datatype to be returned
PeriodAn std::ratio representing the resolution of the time format. E.g. the number of seconds per time step
Returns
A scalar value representing the stored time

◆ Create() [1/2]

template<typename Rep , typename Period >
Time Time::Create ( const Rep &  duration)
inlinestatic

Stores the given scalar as a time, using the given format.

Template Parameters
RepThe datatype to be returned
PeriodAn std::ratio representing the resolution of the time format. E.g. the number of seconds per time step
Returns
A Time object storing the given scalar

◆ Create() [2/2]

template<typename Rep , typename Period >
Time Time::Create ( const std::chrono::duration< Rep, Period > &  duration)
inlinestatic

Stores the given std::duration.

Template Parameters
RepThe datatype to be returned
PeriodAn std::ratio representing the resolution of the time format. E.g. the number of seconds per time step
Returns
A Time object storing the given std::duration

◆ Now()

Time Time::Now ( )
inlinestatic

Creates a Time object storing the current point in time.

Returns
A Time object storing the current time

Friends And Related Function Documentation

◆ Microseconds

Time Microseconds ( Int64  microseconds)
friend

Creates a Time object from a given number of microseconds.

Parameters
secondsThe number of microseconds to store

@ret A Time object storing the given microseconds

◆ Milliseconds

Time Milliseconds ( Int32  milliseconds)
friend

Creates a Time object from a given number of milliseconds.

Parameters
secondsThe number of milliseconds to store

@ret A Time object storing the given milliseconds

◆ operator!=

bool operator!= ( const Time left,
const Time right 
)
friend

Overload of != operator comparing two Times.

Parameters
leftLeft operand
rightRight operand
Returns
true if the two times are not the same

◆ operator%

Time operator% ( const Time left,
const Time right 
)
friend

Overload of % operator to calculate the modulo of a Time.

Parameters
leftLeft operand
rightRight operand
Returns
left % right

◆ operator%=

Time& operator%= ( Time left,
const Time right 
)
friend

Overload of % operator to calculate the modulo of a Time.

Parameters
leftLeft operand
rightRight operand
Returns
left

◆ operator* [1/4]

Time operator* ( const Time left,
float  right 
)
friend

Overload of * operator to multiply a Time with a scalar.

Parameters
leftLeft operand
rightRight operand
Returns
left scaled by a factor of right

◆ operator* [2/4]

Time operator* ( const Time left,
Int64  right 
)
friend

Overload of * operator to multiply a Time with a scalar.

Parameters
leftLeft operand
rightRight operand
Returns
left scaled by a factor of right

◆ operator* [3/4]

Time operator* ( float  left,
const Time right 
)
friend

Overload of * operator to multiply a Time with a scalar.

Parameters
leftLeft operand
rightRight operand
Returns
right scaled by a factor of left

◆ operator* [4/4]

Time operator* ( Int64  left,
const Time right 
)
friend

Overload of * operator to multiply a Time with a scalar.

Parameters
leftLeft operand
rightRight operand
Returns
right scaled by a factor of left

◆ operator*= [1/2]

Time& operator*= ( Time left,
float  right 
)
friend

Overload of *= operator to multiply a Time with a scalar.

Parameters
leftLeft operand
rightRight operand
Returns
left

◆ operator*= [2/2]

Time& operator*= ( Time left,
Int64  right 
)
friend

Overload of *= operator to multiply a Time with a scalar.

Parameters
leftLeft operand
rightRight operand
Returns
left

◆ operator+

Time operator+ ( const Time left,
const Time right 
)
friend

Overload of + operator to add two Times.

Parameters
leftLeft operand
rightRight operand
Returns
The sum of the two times

◆ operator+=

Time& operator+= ( Time left,
const Time right 
)
friend

Overload of += operator to add two Times.

Parameters
leftLeft operand
rightRight operand
Returns
left

◆ operator- [1/2]

Time operator- ( const Time left,
const Time right 
)
friend

Overload of - operator to subtract two Times.

Parameters
leftLeft operand
rightRight operand
Returns
The difference of the two times

◆ operator- [2/2]

Time operator- ( const Time right)
friend

Overload of the unary - operator.

Parameters
rightRight operand
Returns
The negated time stored in right

◆ operator-=

Time& operator-= ( Time left,
const Time right 
)
friend

Overload of -= operator to subtract two Times.

Parameters
leftLeft operand
rightRight operand
Returns
left

◆ operator/ [1/3]

float operator/ ( const Time left,
const Time right 
)
friend

Overload of / operator to divide two Times.

Parameters
leftLeft operand
rightRight operand
Returns
The ratio of two times

◆ operator/ [2/3]

Time operator/ ( const Time left,
float  right 
)
friend

Overload of / operator to divide a Time by a scalar.

Parameters
leftLeft operand
rightRight operand
Returns
left divided by right

◆ operator/ [3/3]

Time operator/ ( const Time left,
Int64  right 
)
friend

Overload of / operator to divide a Time by a scalar.

Parameters
leftLeft operand
rightRight operand
Returns
left divided by right

◆ operator/= [1/2]

Time& operator/= ( Time left,
float  right 
)
friend

Overload of /= operator to divide a Time by a scalar.

Parameters
leftLeft operand
rightRight operand
Returns
left

◆ operator/= [2/2]

Time& operator/= ( Time left,
Int64  right 
)
friend

Overload of /= operator to divide a Time by a scalar.

Parameters
leftLeft operand
rightRight operand
Returns
left

◆ operator<

bool operator< ( const Time left,
const Time right 
)
friend

Overload of < operator comparing two Times.

Parameters
leftLeft operand
rightRight operand
Returns
true if left is less than right

◆ operator<=

bool operator<= ( const Time left,
const Time right 
)
friend

Overload of <= operator comparing two Times.

Parameters
leftLeft operand
rightRight operand
Returns
true if left is less than or equal to right

◆ operator==

bool operator== ( const Time left,
const Time right 
)
friend

Overload of == operator comparing two Times.

Parameters
leftLeft operand
rightRight operand
Returns
true if the two times are the same

◆ operator>

bool operator> ( const Time left,
const Time right 
)
friend

Overload of > operator comparing two Times.

Parameters
leftLeft operand
rightRight operand
Returns
true if left is greater than right

◆ operator>=

bool operator>= ( const Time left,
const Time right 
)
friend

Overload of < operator comparing two Times.

Parameters
leftLeft operand
rightRight operand
Returns
true if left is greater than or equal to right

◆ Seconds

Time Seconds ( float  seconds)
friend

Creates a Time object from a given number of seconds.

Parameters
secondsThe number of seconds to store

@ret A Time object storing the given seconds


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