67 lines
982 B
C++
67 lines
982 B
C++
#include "timerange.h"
|
|
|
|
#include <utility>
|
|
|
|
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() + out()) < (r.in() + r.out());
|
|
}
|
|
|
|
bool TimeRange::operator>(const TimeRange &r) const
|
|
{
|
|
return (in() + out()) > (r.in() + r.out());
|
|
}
|
|
|
|
void TimeRange::normalize()
|
|
{
|
|
// If `out` is earlier than `in`, swap them
|
|
if (out_ < in_)
|
|
{
|
|
std::swap(out_, in_);
|
|
}
|
|
|
|
// Calculate length
|
|
length_ = out_ - in_;
|
|
}
|