Try to add correct namespace for 3D CPLs.
[libdcp.git] / src / dcp_time.cc
index bc15c367054ca20183b16d9673c8246013c731d4..7d3111d270fbef814e05a7a398f8eadd9978023e 100644 (file)
@@ -39,9 +39,14 @@ Time::Time (int frame, int frames_per_second)
        , s (0)
        , t (0)
 {
-       float sec_float = float (frame) / frames_per_second;
-       t = (int (floor (sec_float * 1000)) % 1000) / 4;
-       s = floor (sec_float);
+       set (double (frame) / frames_per_second);
+}
+
+void
+Time::set (double ss)
+{
+       t = (int (round (ss * 1000)) % 1000) / 4;
+       s = floor (ss);
 
        if (s > 60) {
                m = s / 60;
@@ -59,7 +64,7 @@ Time::Time (string time)
        vector<string> b;
        split (b, time, is_any_of (":"));
        if (b.size() != 4) {
-               throw DCPReadError ("unrecognised time specification");
+               boost::throw_exception (DCPReadError ("unrecognised time specification"));
        }
        
        h = lexical_cast<int> (b[0]);
@@ -74,6 +79,12 @@ libdcp::operator== (Time const & a, Time const & b)
        return (a.h == b.h && a.m == b.m && a.s == b.s && a.t == b.t);
 }
 
+bool
+libdcp::operator!= (Time const & a, Time const & b)
+{
+       return !(a == b);
+}
+
 bool
 libdcp::operator<= (Time const & a, Time const & b)
 {
@@ -210,3 +221,20 @@ libdcp::operator/ (Time a, Time const & b)
        int64_t const bt = b.h * 3600 * 250 + b.m * 60 * 250 + b.s * 250 + b.t;
        return float (at) / bt;
 }
+
+/** @return A string of the form h:m:s:t */
+string
+Time::to_string () const
+{
+       stringstream str;
+       str << h << ":" << m << ":" << s << ":" << t;
+       return str.str ();
+}
+
+/** @return This time in ticks */
+int64_t
+Time::to_ticks () const
+{
+       return t + s * 25 + m * 60 * 25 + h * 60 * 60 * 25;
+}
+