Added time manipulation functions to TimeRange and Timeline

This commit is contained in:
Daniel Wolf 2016-04-19 22:06:20 +02:00
parent 895b942df3
commit baf2423b27
3 changed files with 29 additions and 0 deletions

View File

@ -32,6 +32,20 @@ void TimeRange::resize(time_type start, time_type end) {
resize(TimeRange(start, end));
}
void TimeRange::shift(time_type offset) {
start += offset;
end += offset;
}
void TimeRange::grow(time_type value) {
start -= value;
end += value;
}
void TimeRange::shrink(time_type value) {
grow(-value);
}
bool TimeRange::operator==(const TimeRange& rhs) const {
return start == rhs.start && end == rhs.end;
}

View File

@ -18,6 +18,9 @@ public:
void resize(const TimeRange& newRange);
void resize(time_type start, time_type end);
void shift(time_type offset);
void grow(time_type value);
void shrink(time_type value);
bool operator==(const TimeRange& rhs) const;
bool operator!=(const TimeRange& rhs) const;

View File

@ -191,6 +191,18 @@ public:
return reference(*this, time);
}
void shift(time_type offset) {
if (offset == time_type::zero()) return;
range.shift(offset);
set_type newElements;
for (Timed<T> element : elements) {
element.shift(offset);
newElements.insert(element);
}
elements = std::move(newElements);
}
Timeline(const Timeline&) = default;
Timeline(Timeline&&) = default;
Timeline& operator=(const Timeline&) = default;