Re-work Subtitle class; remove STL text writer.
[libsub.git] / src / frame_time.h
1 /*
2     Copyright (C) 2014 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_FRAME_TIME_H
21 #define LIBSUB_FRAME_TIME_H
22
23 #include <iostream>
24
25 namespace sub {
26
27 /** @class FrameTime
28  *  @brief A time in hours, minutes, seconds and frames.
29  */
30 class FrameTime
31 {
32 public:
33         FrameTime ()
34                 : _hours (0)
35                 , _minutes (0)
36                 , _seconds (0)
37                 , _frames (0)
38         {}
39                           
40         FrameTime (int h, int m, int s, int f)
41                 : _hours (h)
42                 , _minutes (m)
43                 , _seconds (s)
44                 , _frames (f)
45         {}
46
47         int hours () const {
48                 return _hours;
49         }
50         
51         int minutes () const {
52                 return _minutes;
53         }
54         
55         int seconds () const {
56                 return _seconds;
57         }
58         
59         int frames () const {
60                 return _frames;
61         }
62
63         std::string timecode () const;
64
65 private:
66         friend bool operator== (FrameTime const & a, FrameTime const & b);
67         friend bool operator< (FrameTime const & a, FrameTime const & b);
68         friend std::ostream& operator<< (std::ostream& s, FrameTime const & t);
69         
70         int _hours;
71         int _minutes;
72         int _seconds;
73         int _frames;
74 };
75
76 bool operator== (FrameTime const & a, FrameTime const & b);
77 bool operator< (FrameTime const & a, FrameTime const & b);
78 std::ostream& operator<< (std::ostream&, FrameTime const & t);
79         
80 }
81
82 #endif