Added convenience functions to TimeRange

This commit is contained in:
Daniel Wolf 2016-12-14 21:00:55 +01:00
parent c86512f73e
commit bdfd77bc4a
2 changed files with 35 additions and 0 deletions

View File

@ -35,6 +35,26 @@ bool TimeRange::empty() const {
return start == end; return start == end;
} }
void TimeRange::setStart(time_type newStart) {
resize(newStart, end);
}
void TimeRange::setEnd(time_type newEnd) {
resize(start, newEnd);
}
void TimeRange::setStartIfEarlier(time_type newStart) {
if (newStart < start) {
setStart(newStart);
}
}
void TimeRange::setEndIfLater(time_type newEnd) {
if (newEnd > end) {
setEnd(newEnd);
}
}
void TimeRange::resize(const TimeRange& newRange) { void TimeRange::resize(const TimeRange& newRange) {
start = newRange.start; start = newRange.start;
end = newRange.end; end = newRange.end;
@ -63,6 +83,14 @@ void TimeRange::trim(const TimeRange& limits) {
resize(newRange); resize(newRange);
} }
void TimeRange::trimLeft(time_type value) {
trim({value, end});
}
void TimeRange::trimRight(time_type value) {
trim({start, value});
}
bool TimeRange::operator==(const TimeRange& rhs) const { bool TimeRange::operator==(const TimeRange& rhs) const {
return start == rhs.start && end == rhs.end; return start == rhs.start && end == rhs.end;
} }

View File

@ -19,12 +19,19 @@ public:
time_type getDuration() const; time_type getDuration() const;
bool empty() const; bool empty() const;
void setStart(time_type newStart);
void setEnd(time_type newEnd);
void setStartIfEarlier(time_type newStart);
void setEndIfLater(time_type newEnd);
void resize(const TimeRange& newRange); void resize(const TimeRange& newRange);
void resize(time_type start, time_type end); void resize(time_type start, time_type end);
void shift(time_type offset); void shift(time_type offset);
void grow(time_type value); void grow(time_type value);
void shrink(time_type value); void shrink(time_type value);
void trim(const TimeRange& limits); void trim(const TimeRange& limits);
void trimLeft(time_type value);
void trimRight(time_type value);
bool operator==(const TimeRange& rhs) const; bool operator==(const TimeRange& rhs) const;
bool operator!=(const TimeRange& rhs) const; bool operator!=(const TimeRange& rhs) const;