Moved operators inside the class, made all functions to be constexpr
This commit is contained in:
@@ -18,79 +18,61 @@ namespace OpenVulkano::Math
|
||||
uint64_t timestamp;
|
||||
|
||||
public:
|
||||
explicit Timestamp(uint64_t nanos = 0) : timestamp(nanos) {}
|
||||
explicit Timestamp(double seconds) : timestamp(static_cast<uint64_t>(seconds * SECONDS_TO_NANOS)) {}
|
||||
explicit constexpr Timestamp(uint64_t nanos = 0) : timestamp(nanos) {}
|
||||
explicit constexpr Timestamp(double seconds) : timestamp(static_cast<uint64_t>(seconds * SECONDS_TO_NANOS)) {}
|
||||
|
||||
[[nodiscard]] uint64_t GetNanos() const { return timestamp; }
|
||||
[[nodiscard]] double GetSeconds() const { return timestamp * NANOS_TO_SECONDS; }
|
||||
[[nodiscard]] constexpr uint64_t GetNanos() const { return timestamp; }
|
||||
[[nodiscard]] constexpr double GetSeconds() const { return timestamp * NANOS_TO_SECONDS; }
|
||||
|
||||
Timestamp& operator+=(const Timestamp& rhs)
|
||||
constexpr Timestamp& operator+=(const Timestamp& rhs)
|
||||
{
|
||||
timestamp += rhs.timestamp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Timestamp& operator-=(const Timestamp& rhs)
|
||||
constexpr Timestamp& operator-=(const Timestamp& rhs)
|
||||
{
|
||||
timestamp -= rhs.timestamp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Timestamp& operator =(double time)
|
||||
constexpr Timestamp& operator =(double time)
|
||||
{
|
||||
timestamp = Timestamp(time).timestamp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Timestamp& operator =(uint64_t time)
|
||||
constexpr Timestamp& operator =(uint64_t time)
|
||||
{
|
||||
timestamp = time;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr inline bool operator==(const Timestamp& rhs) const { return GetNanos() == rhs.GetNanos(); }
|
||||
|
||||
constexpr inline bool operator!=(const Timestamp& rhs) const { return !(*this == rhs); }
|
||||
|
||||
constexpr inline bool operator<(const Timestamp& rhs) const { return GetNanos() < rhs.GetNanos(); }
|
||||
|
||||
constexpr inline bool operator>(const Timestamp& rhs) const { return rhs < *this; }
|
||||
|
||||
constexpr inline bool operator>=(const Timestamp& rhs) const { return !(*this < rhs); }
|
||||
|
||||
constexpr inline bool operator<=(const Timestamp& rhs) const { return !(rhs < *this); }
|
||||
|
||||
constexpr inline Timestamp operator-(const Timestamp& rhs) const
|
||||
{
|
||||
return Timestamp(GetNanos() - rhs.GetNanos());
|
||||
}
|
||||
|
||||
constexpr inline Timestamp operator+(const Timestamp& rhs) const
|
||||
{
|
||||
return Timestamp(GetNanos() + rhs.GetNanos());
|
||||
}
|
||||
|
||||
constexpr inline double operator/(const Timestamp& rhs) const
|
||||
{
|
||||
return GetNanos() / static_cast<double>(rhs.GetNanos());
|
||||
}
|
||||
};
|
||||
|
||||
inline bool operator==(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return lhs.GetNanos() == rhs.GetNanos();
|
||||
}
|
||||
|
||||
inline bool operator!=(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return lhs.GetNanos() < rhs.GetNanos();
|
||||
}
|
||||
|
||||
inline bool operator>(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>=(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
inline Timestamp operator-(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return Timestamp(lhs.GetNanos() - rhs.GetNanos());
|
||||
}
|
||||
|
||||
inline Timestamp operator+(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return Timestamp(lhs.GetNanos() + rhs.GetNanos());
|
||||
}
|
||||
|
||||
inline double operator/(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return lhs.GetNanos() / static_cast<double>(rhs.GetNanos());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user