Templatise TimePeriod and add DCPTimePeriod.
authorCarl Hetherington <cth@carlh.net>
Wed, 16 Sep 2015 10:48:39 +0000 (11:48 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 12 Oct 2015 10:04:17 +0000 (11:04 +0100)
src/lib/dcpomatic_time.cc
src/lib/dcpomatic_time.h

index 28f76607499134933815f888815265fdbceae9c4..49309b1d27a3ca190de2b981f172fb8417f85867 100644 (file)
@@ -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);
-}
index a5a0684e591b104656985e8dfcf427b19100c703..4fa6db0a4c690311dbb31974861ec349ad2d2392 100644 (file)
@@ -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);