431af69a2eb3c48367e5a9dbd7c742ff29537100
[libdcp.git] / src / reel.cc
1 /*
2     Copyright (C) 2012 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 #include "reel.h"
21 #include "util.h"
22 #include "picture_asset.h"
23 #include "sound_asset.h"
24 #include "subtitle_asset.h"
25
26 using namespace std;
27 using namespace libdcp;
28
29 void
30 Reel::write_to_cpl (ostream& s) const
31 {
32         s << "    <Reel>\n"
33           << "      <Id>urn:uuid:" << make_uuid() << "</Id>\n"
34           << "      <AssetList>\n";
35         
36         if (_main_picture) {
37                 _main_picture->write_to_cpl (s);
38         }
39
40         if (_main_sound) {
41                 _main_sound->write_to_cpl (s);
42         }
43
44         if (_main_subtitle) {
45                 _main_subtitle->write_to_cpl (s);
46         }
47 }
48         
49 void
50 Reel::write_to_pkl (ostream& s) const
51 {
52         if (_main_picture) {
53                 _main_picture->write_to_pkl (s);
54         }
55
56         if (_main_sound) {
57                 _main_sound->write_to_pkl (s);
58         }
59
60         if (_main_subtitle) {
61                 _main_subtitle->write_to_pkl (s);
62         }
63 }
64
65 void
66 Reel::write_to_assetmap (ostream& s) const
67 {
68         if (_main_picture) {
69                 _main_picture->write_to_assetmap (s);
70         }
71
72         if (_main_sound) {
73                 _main_sound->write_to_assetmap (s);
74         }
75
76         if (_main_subtitle) {
77                 _main_subtitle->write_to_assetmap (s);
78         }
79 }
80
81 list<string>
82 Reel::equals (boost::shared_ptr<const Reel> other, EqualityOptions opt) const
83 {
84         list<string> o;
85         
86         if ((_main_picture && !other->_main_picture) || (!_main_picture && other->_main_picture)) {
87                 o.push_back ("reel has different assets");
88         }
89         
90         if (_main_picture) {
91                 list<string> m = _main_picture->equals (other->_main_picture, opt);
92                 o.merge (m);
93         }
94
95         if ((_main_sound && !other->_main_sound) || (!_main_sound && other->_main_sound)) {
96                 o.push_back ("reel has different assets");
97         }
98         
99         if (_main_sound) {
100                 list<string> m = _main_sound->equals (other->_main_sound, opt);
101                 o.merge (m);
102         }
103
104         if ((_main_subtitle && !other->_main_subtitle) || (!_main_subtitle && other->_main_subtitle)) {
105                 o.push_back ("reel has different assets");
106         }
107         
108         if (_main_subtitle) {
109                 list<string> m = _main_subtitle->equals (other->_main_subtitle, opt);
110                 o.merge (m);
111         }
112
113         return o;
114 }
115