summaryrefslogtreecommitdiff
path: root/src/lib/dcpomatic_time.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-09-16 11:48:39 +0100
committerCarl Hetherington <cth@carlh.net>2015-10-12 11:04:17 +0100
commit9610f4035114f499d098e8fd2d726d55ddd943ee (patch)
tree3d695577e3d73b5edacb7d155315f10a4d8076b5 /src/lib/dcpomatic_time.h
parent66e1735b0b77ee614ccc6ef253ef48036ba2d589 (diff)
Templatise TimePeriod and add DCPTimePeriod.
Diffstat (limited to 'src/lib/dcpomatic_time.h')
-rw-r--r--src/lib/dcpomatic_time.h31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h
index a5a0684e5..4fa6db0a4 100644
--- a/src/lib/dcpomatic_time.h
+++ b/src/lib/dcpomatic_time.h
@@ -228,31 +228,40 @@ typedef Time<ContentTimeDifferentiator, DCPTimeDifferentiator> ContentTime;
/** Time relative to the start of the output DCP in its frame rate */
typedef Time<DCPTimeDifferentiator, ContentTimeDifferentiator> DCPTime;
-class ContentTimePeriod
+template <class T>
+class TimePeriod
{
public:
- ContentTimePeriod () {}
+ TimePeriod () {}
- ContentTimePeriod (ContentTime f, ContentTime t)
+ TimePeriod (T f, T t)
: from (f)
, to (t)
{}
- ContentTime from;
- ContentTime to;
+ T from;
+ T to;
- ContentTimePeriod operator+ (ContentTime const & o) const {
- return ContentTimePeriod (from + o, to + o);
+ TimePeriod<T> operator+ (T const & o) const {
+ return TimePeriod<T> (from + o, to + o);
}
- bool overlaps (ContentTimePeriod const & o) const;
- bool contains (ContentTime const & o) const;
+ bool overlaps (TimePeriod<T> const & other) const {
+ return (from < other.to && to > other.from);
+ }
+
+ bool contains (T const & other) const {
+ return (from <= other && other < to);
+ }
- bool operator== (ContentTimePeriod const & o) const {
- return from == o.from && to == o.to;
+ bool operator== (TimePeriod<T> const & other) {
+ return from == other.from && to == other.to;
}
};
+typedef TimePeriod<ContentTime> ContentTimePeriod;
+typedef TimePeriod<DCPTime> DCPTimePeriod;
+
DCPTime min (DCPTime a, DCPTime b);
DCPTime max (DCPTime a, DCPTime b);
ContentTime min (ContentTime a, ContentTime b);