Files
oak-editor/app/common/timerange.cpp
T
itsmattkc 16f80386e8 added qhash functions for timerange and rational
So these keys can be used in QHash containers, they need functions for how to
create those hashes.
2019-11-15 13:55:05 +09:00

66 lines
989 B
C++

#include "timerange.h"
TimeRange::TimeRange(const rational &in, const rational &out) :
in_(in),
out_(out)
{
normalize();
}
const rational &TimeRange::in() const
{
return in_;
}
const rational &TimeRange::out() const
{
return out_;
}
const rational &TimeRange::length() const
{
return length_;
}
void TimeRange::set_in(const rational &in)
{
in_ = in;
normalize();
}
void TimeRange::set_out(const rational &out)
{
out_ = out;
normalize();
}
void TimeRange::set_range(const rational &in, const rational &out)
{
in_ = in;
out_ = out;
normalize();
}
bool TimeRange::operator==(const TimeRange &r) const
{
return in() == r.in() && out() == r.out();
}
void TimeRange::normalize()
{
// If `out` is earlier than `in`, swap them
if (out_ < in_) {
rational temp = in_;
in_ = out_;
out_ = temp;
}
// Calculate length
length_ = out_ - in_;
}
uint qHash(const TimeRange &r, uint seed)
{
return qHash(r.in(), seed) ^ qHash(r.out(), seed);
}