Ocean
Ocean::Timestamp Class Reference

This class implements a timestamp. More...

Public Member Functions

 Timestamp ()=default
 Creates a new timestamp with invalid time. More...
 
 Timestamp (const bool toNow)
 Creates a new timestamp. More...
 
 Timestamp (const double timestamp)
 Creates a new timestamp with a given value. More...
 
TimestamptoNow ()
 Sets the timestamp to the current time. More...
 
TimestamptoInvalid ()
 Sets the timestamp to invalid. More...
 
int64_t nanoseconds () const
 Returns this timestamp in nanoseconds. More...
 
bool hasTimePassed (const double seconds, const Timestamp &currentTimestamp=Timestamp(true)) const
 Returns whether a specified amount of time has passed since this timestamp. More...
 
bool isValid () const
 Returns whether the timestamp holds a valid time. More...
 
bool isInvalid () const
 Returns whether the timestamp holds an invalid time. More...
 
Timestampoperator= (const double timestamp)
 Assign a new value. More...
 
Timestamp operator+ (const Timestamp &right) const
 Adds two timestamps. More...
 
Timestampoperator+= (const Timestamp &right)
 Adds and assigns two timestamps. More...
 
Timestamp operator+ (const double seconds) const
 Adds seconds to this timestamps. More...
 
Timestampoperator+= (const double seconds)
 Adds and assigns seconds to this timestamps. More...
 
Timestamp operator- (const Timestamp &right) const
 Subtracts two timestamps. More...
 
Timestampoperator-= (const Timestamp &right)
 Subtracts and assigns two timestamps. More...
 
Timestamp operator- (const double seconds) const
 Subtracts seconds from this timestamp. More...
 
Timestampoperator-= (const double seconds)
 Subtracts and assigns seconds from this timestamp. More...
 
bool operator< (const Timestamp &right) const
 Returns whether the this timestamp is lesser than the right one. More...
 
bool operator<= (const Timestamp &right) const
 Returns whether the this timestamp is lesser or equal to the right one. More...
 
bool operator> (const Timestamp &right) const
 Returns whether the this timestamp is greater than the right one. More...
 
bool operator>= (const Timestamp &right) const
 Returns whether the this timestamp is greater or equal to the right one. More...
 
bool operator== (const Timestamp &right) const
 Returns whether two timestamps are identical. More...
 
bool operator!= (const Timestamp &right) const
 Returns whether two timestamps are not identical. More...
 
 operator double () const
 Cast operator for the timestamp value. More...
 
size_t operator() (const Timestamp &timestamp) const
 Hash function. More...
 

Static Public Member Functions

static constexpr int64_t seconds2milliseconds (const double seconds)
 Converts seconds to milliseconds. More...
 
static constexpr int64_t seconds2microseconds (const double seconds)
 Converts seconds to microseconds. More...
 
static constexpr int64_t seconds2nanoseconds (const double seconds)
 Converts seconds to nanoseconds. More...
 
static constexpr double milliseconds2seconds (const int64_t milliseconds)
 Converts milliseconds to seconds. More...
 
static constexpr double microseconds2seconds (const int64_t microseconds)
 Converts microseconds to seconds. More...
 
static constexpr double nanoseconds2seconds (const int64_t nanoseconds)
 Converts nanoseconds to seconds. More...
 

Static Protected Member Functions

static constexpr double invalidTimestampValue ()
 Returns the of an invalid timestamp. More...
 

Protected Attributes

double value_ = invalidTimestampValue()
 Timestamp value. More...
 

Detailed Description

This class implements a timestamp.

The timestamp is specified by the number of seconds since 01.01.1970 00:00:00 in UTC time.
Depending on the underlying hardware the accuracy (update rate) of the timestamps can vary.
The timestamp class wraps a floating value with 64 bit precision.

Constructor & Destructor Documentation

◆ Timestamp() [1/3]

Ocean::Timestamp::Timestamp ( )
default

Creates a new timestamp with invalid time.

◆ Timestamp() [2/3]

Ocean::Timestamp::Timestamp ( const bool  toNow)
explicit

Creates a new timestamp.

Parameters
toNowDetermines whether the timestamp holds the seconds since 01.01.1970 00:00:00 in UTC time, otherwise the timestamp will be initialized as invalid

◆ Timestamp() [3/3]

Ocean::Timestamp::Timestamp ( const double  timestamp)
inlineexplicit

Creates a new timestamp with a given value.

Parameters
timestampTimestamp value

Member Function Documentation

◆ hasTimePassed()

bool Ocean::Timestamp::hasTimePassed ( const double  seconds,
const Timestamp currentTimestamp = Timestamp(true) 
) const
inline

Returns whether a specified amount of time has passed since this timestamp.

This function returns 'thisTimestamp + seconds <= currentTimestamp'.

Parameters
secondsThe number of seconds defining the time to check, with range [0, infinity)
currentTimestampThe current timestamp to use for comparison
Returns
True, if the time has passed or if this timestamp is invalid

◆ invalidTimestampValue()

constexpr double Ocean::Timestamp::invalidTimestampValue ( )
staticconstexprprotected

Returns the of an invalid timestamp.

Returns
Invalid timestamp value

◆ isInvalid()

bool Ocean::Timestamp::isInvalid ( ) const
inline

Returns whether the timestamp holds an invalid time.

Returns
True, if so

◆ isValid()

bool Ocean::Timestamp::isValid ( ) const
inline

Returns whether the timestamp holds a valid time.

Returns
True, if so

◆ microseconds2seconds()

constexpr double Ocean::Timestamp::microseconds2seconds ( const int64_t  microseconds)
staticconstexpr

Converts microseconds to seconds.

Parameters
microsecondsThe microseconds to convert, with range (-infinity, infinity)
Returns
The resulting seconds

◆ milliseconds2seconds()

constexpr double Ocean::Timestamp::milliseconds2seconds ( const int64_t  milliseconds)
staticconstexpr

Converts milliseconds to seconds.

Parameters
millisecondsThe milliseconds to convert, with range (-infinity, infinity)
Returns
The resulting seconds

◆ nanoseconds()

int64_t Ocean::Timestamp::nanoseconds ( ) const
inline

Returns this timestamp in nanoseconds.

Returns
The timestamp in nanoseconds, with range (-infinity, infinity)

◆ nanoseconds2seconds()

constexpr double Ocean::Timestamp::nanoseconds2seconds ( const int64_t  nanoseconds)
staticconstexpr

Converts nanoseconds to seconds.

Parameters
nanosecondsThe nanoseconds to convert, with range (-infinity, infinity)
Returns
The resulting seconds

◆ operator double()

Ocean::Timestamp::operator double ( ) const
inlineexplicit

Cast operator for the timestamp value.

Returns
Timestamp

◆ operator!=()

bool Ocean::Timestamp::operator!= ( const Timestamp right) const
inline

Returns whether two timestamps are not identical.

Parameters
rightThe right timestamp
Returns
True, if so

◆ operator()()

size_t Ocean::Timestamp::operator() ( const Timestamp timestamp) const
inline

Hash function.

Parameters
timestampThe timestamp for which the hash value will be determined
Returns
The resulting hash value

◆ operator+() [1/2]

Timestamp Ocean::Timestamp::operator+ ( const double  seconds) const
inline

Adds seconds to this timestamps.

Parameters
secondsThe number of seconds to add, with range (-infinity, infinity)
Returns
New timestamp

◆ operator+() [2/2]

Timestamp Ocean::Timestamp::operator+ ( const Timestamp right) const
inline

Adds two timestamps.

Parameters
rightThe right timestamp
Returns
New timestamp

◆ operator+=() [1/2]

Timestamp & Ocean::Timestamp::operator+= ( const double  seconds)
inline

Adds and assigns seconds to this timestamps.

Parameters
secondsThe number of seconds to add, with range (-infinity, infinity)
Returns
Reference to this timestamp

◆ operator+=() [2/2]

Timestamp & Ocean::Timestamp::operator+= ( const Timestamp right)
inline

Adds and assigns two timestamps.

Parameters
rightThe right timestamp
Returns
Reference to this timestamp

◆ operator-() [1/2]

Timestamp Ocean::Timestamp::operator- ( const double  seconds) const
inline

Subtracts seconds from this timestamp.

Parameters
secondsThe number of seconds to subtract, with range (-infinity, infinity)
Returns
New timestamp

◆ operator-() [2/2]

Timestamp Ocean::Timestamp::operator- ( const Timestamp right) const
inline

Subtracts two timestamps.

Parameters
rightThe right timestamp
Returns
New timestamp

◆ operator-=() [1/2]

Timestamp & Ocean::Timestamp::operator-= ( const double  seconds)
inline

Subtracts and assigns seconds from this timestamp.

Parameters
secondsThe number of seconds to subtract, with range (-infinity, infinity)
Returns
Reference to this timestamp

◆ operator-=() [2/2]

Timestamp & Ocean::Timestamp::operator-= ( const Timestamp right)
inline

Subtracts and assigns two timestamps.

Parameters
rightThe right timestamp
Returns
Reference to this timestamp

◆ operator<()

bool Ocean::Timestamp::operator< ( const Timestamp right) const
inline

Returns whether the this timestamp is lesser than the right one.

Parameters
rightThe right timestamp
Returns
True, if so

◆ operator<=()

bool Ocean::Timestamp::operator<= ( const Timestamp right) const
inline

Returns whether the this timestamp is lesser or equal to the right one.

Parameters
rightThe right timestamp
Returns
True, if so

◆ operator=()

Timestamp & Ocean::Timestamp::operator= ( const double  timestamp)
inline

Assign a new value.

Parameters
timestampValue to assign
Returns
Reference to this timestamp

◆ operator==()

bool Ocean::Timestamp::operator== ( const Timestamp right) const
inline

Returns whether two timestamps are identical.

Parameters
rightThe right timestamp
Returns
True, if so

◆ operator>()

bool Ocean::Timestamp::operator> ( const Timestamp right) const
inline

Returns whether the this timestamp is greater than the right one.

Parameters
rightThe right timestamp
Returns
True, if so

◆ operator>=()

bool Ocean::Timestamp::operator>= ( const Timestamp right) const
inline

Returns whether the this timestamp is greater or equal to the right one.

Parameters
rightThe right timestamp
Returns
True, if so

◆ seconds2microseconds()

constexpr int64_t Ocean::Timestamp::seconds2microseconds ( const double  seconds)
staticconstexpr

Converts seconds to microseconds.

Parameters
secondsThe seconds to convert, with range (-infinity, infinity)
Returns
The resulting microseconds

◆ seconds2milliseconds()

constexpr int64_t Ocean::Timestamp::seconds2milliseconds ( const double  seconds)
staticconstexpr

Converts seconds to milliseconds.

Parameters
secondsThe seconds to convert, with range (-infinity, infinity)
Returns
The resulting milliseconds

◆ seconds2nanoseconds()

constexpr int64_t Ocean::Timestamp::seconds2nanoseconds ( const double  seconds)
staticconstexpr

Converts seconds to nanoseconds.

Parameters
secondsThe seconds to convert, with range (-infinity, infinity)
Returns
The resulting nanoseconds

◆ toInvalid()

Timestamp & Ocean::Timestamp::toInvalid ( )
inline

Sets the timestamp to invalid.

Returns
Reference to this object

◆ toNow()

Timestamp& Ocean::Timestamp::toNow ( )

Sets the timestamp to the current time.

The timestamp holds the seconds since 01.01.1970 00:00:00 in UTC time.

Returns
Reference to this object

Field Documentation

◆ value_

double Ocean::Timestamp::value_ = invalidTimestampValue()
protected

Timestamp value.


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