libsub
 All Classes Files Functions Variables
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 <boost/optional.hpp>
24 
25 namespace sub {
26 
27 class Rational
28 {
29 public:
30  Rational (int numerator_, int denominator_)
31  : numerator (numerator_)
32  , denominator (denominator_)
33  {}
34 
35  int numerator;
36  int denominator;
37 
38  double fraction () const {
39  return double (numerator) / denominator;
40  }
41 };
42 
43 class Time
44 {
45 public:
46  Time ()
47  : _seconds (0)
48  , _frames (0)
49  {}
50 
51  int hours () const;
52  int minutes () const;
53  int seconds () const;
54 
55  int frames_at (Rational rate) const;
56  int milliseconds () const;
57 
58  double all_as_seconds () const;
59 
60  static Time from_hmsf (int h, int m, int s, int f, boost::optional<Rational> rate = boost::optional<Rational> ());
61  static Time from_hms (int h, int m, int s, int ms);
62 
63 private:
64  friend bool operator< (Time const & a, Time const & b);
65  friend bool operator> (Time const & a, Time const & b);
66  friend bool operator== (Time const & a, Time const & b);
67  friend std::ostream& operator<< (std::ostream& s, Time const & t);
68 
69  Time (int seconds, int frames, boost::optional<Rational> rate)
70  : _seconds (seconds)
71  , _frames (frames)
72  , _rate (rate)
73  {}
74 
75  int _seconds;
76  int _frames;
77  boost::optional<Rational> _rate;
78 };
79 
80 bool operator< (Time const & a, Time const & b);
81 bool operator> (Time const & a, Time const & b);
82 bool operator== (Time const & a, Time const & b);
83 bool operator!= (Time const & a, Time const & b);
84 std::ostream& operator<< (std::ostream& s, Time const & t);
85 
86 }
87 
88 #endif
Definition: collect.h:26
Definition: sub_time.h:43
Definition: sub_time.h:27