Remove all use of stringstream in an attempt to fix
[dcpomatic.git] / src / lib / dcpomatic_time.cc
1 /*
2     Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "dcpomatic_time.h"
22 #include <inttypes.h>
23
24 using std::string;
25
26 template <>
27 Time<ContentTimeDifferentiator, DCPTimeDifferentiator>::Time (DCPTime d, FrameRateChange f)
28         : _t (llrint (d.get() * f.speed_up))
29 {
30
31 }
32
33 template <>
34 Time<DCPTimeDifferentiator, ContentTimeDifferentiator>::Time (ContentTime d, FrameRateChange f)
35         : _t (llrint (d.get() / f.speed_up))
36 {
37
38 }
39
40 DCPTime
41 min (DCPTime a, DCPTime b)
42 {
43         if (a < b) {
44                 return a;
45         }
46
47         return b;
48 }
49
50 DCPTime
51 max (DCPTime a, DCPTime b)
52 {
53         if (a > b) {
54                 return a;
55         }
56
57         return b;
58 }
59
60 ContentTime
61 min (ContentTime a, ContentTime b)
62 {
63         if (a < b) {
64                 return a;
65         }
66
67         return b;
68 }
69
70 ContentTime
71 max (ContentTime a, ContentTime b)
72 {
73         if (a > b) {
74                 return a;
75         }
76
77         return b;
78 }
79
80 string
81 to_string (ContentTime t)
82 {
83         char buffer[64];
84         snprintf (buffer, sizeof(buffer), "[CONT %" PRId64 " %fs]", t.get(), t.seconds());
85         return buffer;
86 }
87
88 string
89 to_string (DCPTime t)
90 {
91         char buffer[64];
92         snprintf (buffer, sizeof(buffer), "[DCP %" PRId64 " %fs]", t.get(), t.seconds());
93         return buffer;
94 }
95
96 string
97 to_string (DCPTimePeriod p)
98 {
99         char buffer[64];
100         snprintf (buffer, sizeof(buffer), "[DCP %" PRId64 " %fs -> %" PRId64 " %fs]", p.from.get(), p.from.seconds(), p.to.get(), p.to.seconds());
101         return buffer;
102 }