rhubarb-lip-sync/src/Timed.h

127 lines
2.5 KiB
C
Raw Normal View History

2016-03-15 21:52:31 +00:00
#pragma once
2016-03-28 18:25:11 +00:00
#include <TimeRange.h>
2016-04-04 18:10:28 +00:00
#include <iostream>
2016-03-15 21:52:31 +00:00
template<typename TValue>
class Timed {
2016-03-15 21:52:31 +00:00
public:
Timed(TimeRange::time_type start, TimeRange::time_type end, const TValue& value) :
Timed(TimeRange(start, end), value)
2016-03-15 21:52:31 +00:00
{}
2016-04-09 20:07:25 +00:00
Timed(const TimeRange& timeRange, const TValue& value) :
timeRange(timeRange),
2016-04-04 18:10:28 +00:00
value(value)
{}
Timed(const Timed&) = default;
Timed(Timed&&) = default;
Timed& operator=(const Timed&) = default;
Timed& operator=(Timed&&) = default;
TimeRange& getTimeRange() {
return timeRange;
}
const TimeRange& getTimeRange() const {
return timeRange;
}
TimeRange::time_type getStart() const {
return timeRange.getStart();
}
TimeRange::time_type getEnd() const {
return timeRange.getEnd();
}
void setTimeRange(const TimeRange& timeRange) {
this->timeRange = timeRange;
}
2016-04-04 18:10:28 +00:00
TValue& getValue() {
return value;
}
2016-03-15 21:52:31 +00:00
const TValue& getValue() const {
return value;
}
void setValue(const TValue& value) {
2016-04-04 18:10:28 +00:00
this->value = value;
}
bool operator==(const Timed& rhs) const {
return timeRange == rhs.timeRange && value == rhs.value;
2016-04-04 18:10:28 +00:00
}
bool operator!=(const Timed& rhs) const {
return !operator==(rhs);
}
2016-03-15 21:52:31 +00:00
private:
TimeRange timeRange;
2016-04-04 18:10:28 +00:00
TValue value;
2016-03-15 21:52:31 +00:00
};
2016-04-04 18:10:28 +00:00
template<typename T>
std::ostream& operator<<(std::ostream& stream, const Timed<T>& timedValue) {
return stream << "Timed(" << timedValue.getStart() << ", " << timedValue.getEnd() << ", " << timedValue.getValue() << ")";
}
template<>
class Timed<void> {
public:
Timed(TimeRange::time_type start, TimeRange::time_type end) :
Timed(TimeRange(start, end))
{}
Timed(const TimeRange& timeRange) :
timeRange(timeRange)
{}
Timed(const Timed&) = default;
Timed(Timed&&) = default;
Timed& operator=(const Timed&) = default;
Timed& operator=(Timed&&) = default;
TimeRange& getTimeRange() {
return timeRange;
}
const TimeRange& getTimeRange() const {
return timeRange;
}
TimeRange::time_type getStart() const {
return timeRange.getStart();
}
TimeRange::time_type getEnd() const {
return timeRange.getEnd();
}
void setTimeRange(const TimeRange& timeRange) {
this->timeRange = timeRange;
}
bool operator==(const Timed& rhs) const {
return timeRange == rhs.timeRange;
}
bool operator!=(const Timed& rhs) const {
return !operator==(rhs);
}
private:
TimeRange timeRange;
};
template<typename T>
std::ostream& operator<<(std::ostream& stream, const Timed<void>& timedValue) {
return stream << "Timed<void>(" << timedValue.getTimeRange().getStart() << ", " << timedValue.getTimeRange().getEnd() << ")";
}