Add "U8" character code table for binary STL.
[libsub.git] / src / sub_time.h
1 /*
2     Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef LIBSUB_SUB_TIME_H
21 #define LIBSUB_SUB_TIME_H
22
23 #include "rational.h"
24 #include <boost/optional.hpp>
25
26 namespace sub {
27
28 class Time
29 {
30 public:
31         Time ()
32                 : _seconds (0)
33                 , _frames (0)
34         {}
35
36         int hours () const;
37         int minutes () const;
38         int seconds () const;
39
40         int frames_at (Rational rate) const;
41         int milliseconds () const;
42
43         double all_as_seconds () const;
44
45         void add (Time t);
46         void scale (float f);
47
48         static Time from_hmsf (int h, int m, int s, int f, boost::optional<Rational> rate = boost::optional<Rational> ());
49         static Time from_hms (int h, int m, int s, int ms);
50         static Time from_frames (int frames, Rational rate);
51
52 private:
53         friend bool operator< (Time const & a, Time const & b);
54         friend bool operator> (Time const & a, Time const & b);
55         friend bool operator== (Time const & a, Time const & b);
56         friend std::ostream& operator<< (std::ostream& s, Time const & t);
57
58         Time (int seconds, int frames, boost::optional<Rational> rate)
59                 : _seconds (seconds)
60                 , _frames (frames)
61                 , _rate (rate)
62         {}
63
64         int _seconds;
65         int _frames;
66         boost::optional<Rational> _rate;
67 };
68
69 bool operator< (Time const & a, Time const & b);
70 bool operator> (Time const & a, Time const & b);
71 bool operator== (Time const & a, Time const & b);
72 bool operator!= (Time const & a, Time const & b);
73 std::ostream& operator<< (std::ostream& s, Time const & t);
74
75 }
76
77 #endif