From: Carl Hetherington Date: Wed, 16 Sep 2015 10:48:39 +0000 (+0100) Subject: Templatise TimePeriod and add DCPTimePeriod. X-Git-Tag: v2.4.11~10 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=9610f4035114f499d098e8fd2d726d55ddd943ee;p=dcpomatic.git Templatise TimePeriod and add DCPTimePeriod. --- diff --git a/src/lib/dcpomatic_time.cc b/src/lib/dcpomatic_time.cc index 28f766074..49309b1d2 100644 --- a/src/lib/dcpomatic_time.cc +++ b/src/lib/dcpomatic_time.cc @@ -88,15 +88,3 @@ operator<< (ostream& s, DCPTime t) s << "[DCP " << t.get() << " " << t.seconds() << "s]"; return s; } - -bool -ContentTimePeriod::overlaps (ContentTimePeriod const & other) const -{ - return (from < other.to && to > other.from); -} - -bool -ContentTimePeriod::contains (ContentTime const & other) const -{ - return (from <= other && other < to); -} 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 ContentTime; /** Time relative to the start of the output DCP in its frame rate */ typedef Time DCPTime; -class ContentTimePeriod +template +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 operator+ (T const & o) const { + return TimePeriod (from + o, to + o); } - bool overlaps (ContentTimePeriod const & o) const; - bool contains (ContentTime const & o) const; + bool overlaps (TimePeriod 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 const & other) { + return from == other.from && to == other.to; } }; +typedef TimePeriod ContentTimePeriod; +typedef TimePeriod DCPTimePeriod; + DCPTime min (DCPTime a, DCPTime b); DCPTime max (DCPTime a, DCPTime b); ContentTime min (ContentTime a, ContentTime b);