8 #ifndef META_OCEAN_BASE_TIMESTAMP_H
9 #define META_OCEAN_BASE_TIMESTAMP_H
54 inline explicit Timestamp(
const double timestamp);
73 inline int64_t nanoseconds()
const;
82 inline bool hasTimePassed(
const double seconds,
const Timestamp& currentTimestamp =
Timestamp(
true))
const;
88 inline bool isValid()
const;
94 inline bool isInvalid()
const;
101 inline Timestamp& operator=(
const double timestamp);
129 inline Timestamp& operator+=(
const double seconds);
157 inline Timestamp& operator-=(
const double seconds);
164 inline bool operator<(
const Timestamp& right)
const;
171 inline bool operator<=(
const Timestamp& right)
const;
178 inline bool operator>(
const Timestamp& right)
const;
185 inline bool operator>=(
const Timestamp& right)
const;
192 inline bool operator==(
const Timestamp& right)
const;
199 inline bool operator!=(
const Timestamp& right)
const;
205 explicit inline operator double()
const;
212 inline size_t operator()(
const Timestamp& timestamp)
const;
219 static constexpr int64_t seconds2milliseconds(
const double seconds);
226 static constexpr int64_t seconds2microseconds(
const double seconds);
233 static constexpr int64_t seconds2nanoseconds(
const double seconds);
240 static constexpr
double milliseconds2seconds(
const int64_t milliseconds);
247 static constexpr
double microseconds2seconds(
const int64_t microseconds);
254 static constexpr
double nanoseconds2seconds(
const int64_t nanoseconds);
262 static constexpr
double invalidTimestampValue();
267 double value_ = invalidTimestampValue();
292 ocean_assert(seconds >= 0.0);
293 ocean_assert(currentTimestamp.
isValid());
300 return double(*
this) + seconds <= double(currentTimestamp);
398 inline Timestamp::operator double()
const
405 return std::hash<double>{}(double(timestamp));
414 return int64_t(seconds * 1.0e3 + 0.5);
418 return int64_t(seconds * 1.0e3 - 0.5);
429 return int64_t(seconds * 1.0e6 + 0.5);
433 return int64_t(seconds * 1.0e6 - 0.5);
445 return int64_t(seconds * 1.0e9 + 0.5);
449 return int64_t(seconds * 1.0e9 - 0.5);
455 return double(milliseconds) / 1.0e3;
460 return double(microseconds) / 1.0e6;
This class implements a timestamp.
Definition: Timestamp.h:36
bool operator>=(const Timestamp &right) const
Returns whether the this timestamp is greater or equal to the right one.
Definition: Timestamp.h:383
static constexpr int64_t seconds2milliseconds(const double seconds)
Converts seconds to milliseconds.
Definition: Timestamp.h:408
bool isValid() const
Returns whether the timestamp holds a valid time.
Definition: Timestamp.h:303
size_t operator()(const Timestamp ×tamp) const
Hash function.
Definition: Timestamp.h:403
static constexpr double nanoseconds2seconds(const int64_t nanoseconds)
Converts nanoseconds to seconds.
Definition: Timestamp.h:463
bool operator!=(const Timestamp &right) const
Returns whether two timestamps are not identical.
Definition: Timestamp.h:393
Timestamp(const bool toNow)
Creates a new timestamp.
static constexpr int64_t seconds2microseconds(const double seconds)
Converts seconds to microseconds.
Definition: Timestamp.h:422
static constexpr double microseconds2seconds(const int64_t microseconds)
Converts microseconds to seconds.
Definition: Timestamp.h:458
bool hasTimePassed(const double seconds, const Timestamp ¤tTimestamp=Timestamp(true)) const
Returns whether a specified amount of time has passed since this timestamp.
Definition: Timestamp.h:290
Timestamp & toInvalid()
Sets the timestamp to invalid.
Definition: Timestamp.h:276
bool operator<=(const Timestamp &right) const
Returns whether the this timestamp is lesser or equal to the right one.
Definition: Timestamp.h:373
bool operator==(const Timestamp &right) const
Returns whether two timestamps are identical.
Definition: Timestamp.h:388
double value_
Timestamp value.
Definition: Timestamp.h:267
int64_t nanoseconds() const
Returns this timestamp in nanoseconds.
Definition: Timestamp.h:283
bool operator>(const Timestamp &right) const
Returns whether the this timestamp is greater than the right one.
Definition: Timestamp.h:378
bool operator<(const Timestamp &right) const
Returns whether the this timestamp is lesser than the right one.
Definition: Timestamp.h:368
Timestamp operator-(const Timestamp &right) const
Subtracts two timestamps.
Definition: Timestamp.h:344
Timestamp operator+(const Timestamp &right) const
Adds two timestamps.
Definition: Timestamp.h:320
Timestamp & operator+=(const Timestamp &right)
Adds and assigns two timestamps.
Definition: Timestamp.h:325
static constexpr int64_t seconds2nanoseconds(const double seconds)
Converts seconds to nanoseconds.
Definition: Timestamp.h:437
bool isInvalid() const
Returns whether the timestamp holds an invalid time.
Definition: Timestamp.h:308
Timestamp()=default
Creates a new timestamp with invalid time.
Timestamp & toNow()
Sets the timestamp to the current time.
static constexpr double invalidTimestampValue()
Returns the of an invalid timestamp.
Definition: Timestamp.h:468
static constexpr double milliseconds2seconds(const int64_t milliseconds)
Converts milliseconds to seconds.
Definition: Timestamp.h:453
Timestamp & operator=(const double timestamp)
Assign a new value.
Definition: Timestamp.h:313
Timestamp & operator-=(const Timestamp &right)
Subtracts and assigns two timestamps.
Definition: Timestamp.h:349
std::vector< Timestamp > Timestamps
Definition of a vector holding Timestamp objects.
Definition: Timestamp.h:19
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15
AutomaticDifferentiationT< T1, TNumeric1 > operator-(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:484
AutomaticDifferentiationT< T1, TNumeric1 > operator+(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:418