Added operators to Time

This commit is contained in:
Robert 2021-04-24 00:58:38 +02:00
parent 4b1ed7da1e
commit cf859223ab
2 changed files with 186 additions and 16 deletions

View file

@ -25,38 +25,159 @@ Int64 Time::AsMicroseconds() const
std::chrono::seconds Time::AsChronoSeconds() const
{
return AsChrono<std::chrono::seconds>();
return AsChrono<long long, std::ratio<1>>();
}
std::chrono::milliseconds Time::AsChronoMilliseconds() const
{
return AsChrono<std::chrono::milliseconds>();
return AsChrono<long long, std::milli>();
}
std::chrono::microseconds Time::AsChronoMicroseconds() const
{
return AsChrono<std::chrono::microseconds>();
return AsChrono<long long, std::micro>();
}
Time Seconds(float seconds)
{
Time newTime;
newTime.microseconds = std::chrono::duration_cast<std::chrono::duration<Int64, std::micro>>(std::chrono::duration<float>(seconds));
return newTime;
return Create<float>(seconds);
}
Time Milliseconds(Int32 milliseconds)
{
Time newTime;
newTime.microseconds = std::chrono::duration_cast<std::chrono::duration<Int64, std::micro>>(std::chrono::duration<Int32, std::milli>(milliseconds));
return newTime;
return Create<Int32, std::milli>(milliseconds);
}
Time Microseconds(Int64 microseconds)
{
Time newTime;
newTime.microseconds = std::chrono::duration<Int64, std::micro>(microseconds);
return newTime;
return Create<Int64, std::micro>(microseconds);
}
bool operator==(const Time& left, const Time& right)
{
return (left.microseconds == right.microseconds);
}
bool operator!=(const Time& left, const Time& right)
{
return (left.microseconds != right.microseconds);
}
bool operator<(const Time& left, const Time& right)
{
return (left.microseconds < right.microseconds);
}
bool operator>(const Time& left, const Time& right)
{
return (left.microseconds > right.microseconds);
}
bool operator<=(const Time& left, const Time& right)
{
return (left.microseconds <= right.microseconds);
}
bool operator>=(const Time& left, const Time& right)
{
return (left.microseconds >= right.microseconds);
}
Time operator-(const Time& right)
{
return Create(-right.microseconds);
}
Time operator+(const Time& left, const Time& right)
{
return Create(left.microseconds + right.microseconds);
}
Time& operator+=(Time& left, const Time& right)
{
left = left + right;
return left;
}
Time operator-(const Time& left, const Time& right)
{
return Create(left.microseconds - right.microseconds);
}
Time& operator-=(Time& left, const Time& right)
{
left = left - right;
return left;
}
Time operator*(const Time& left, float right)
{
return Create(left.microseconds * right);
}
Time operator*(const Time& left, Int64 right)
{
return Create(left.microseconds * right);
}
Time operator*(float left, const Time& right)
{
return (right * left);
}
Time operator*(Int64 left, const Time& right)
{
return (right * left);
}
Time& operator*=(Time& left, float right)
{
left = left * right;
return left;
}
Time& operator*=(Time& left, Int64 right)
{
left = left * right;
return left;
}
Time operator/(const Time& left, float right)
{
return Create(left.microseconds / right);
}
Time operator/(const Time& left, Int64 right)
{
return Create(left.microseconds / right);
}
Time& operator/=(Time& left, float right)
{
left = left / right;
return left;
}
Time& operator/=(Time& left, Int64 right)
{
left = left / right;
return left;
}
float operator/(const Time& left, const Time& right)
{
return ((float)(left.AsMicroseconds()) / (float)(right.AsMicroseconds()));
}
Time operator%(const Time& left, const Time& right)
{
return Create(left.microseconds % right.microseconds);
}
Time& operator%=(Time& left, const Time& right)
{
left = left % right;
return left;
}
SDLU_END