Merge master
[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 <libxml++/nodes/element.h>
21 #include "reel.h"
22 #include "util.h"
23 #include "picture_asset.h"
24 #include "sound_asset.h"
25 #include "subtitle_asset.h"
26
27 using namespace std;
28 using namespace libdcp;
29
30 void
31 Reel::write_to_cpl (xmlpp::Node* parent) const
32 {
33         xmlpp::Element* reel = parent->add_child("Reel");
34         reel->add_child("Id")->add_child_text("urn:uuid:" + make_uuid());
35         xmlpp::Element* asset_list = reel->add_child("AssetList");
36
37         if (_main_picture) {
38                 _main_picture->write_to_cpl (asset_list);
39         }
40
41         if (_main_sound) {
42                 _main_sound->write_to_cpl (asset_list);
43         }
44
45         if (_main_subtitle) {
46                 _main_subtitle->write_to_cpl (asset_list);
47         }
48
49         s << "      </AssetList>\n"
50           << "    </Reel>\n";
51 }
52         
53 bool
54 Reel::equals (boost::shared_ptr<const Reel> other, EqualityOptions opt, list<string>& notes) const
55 {
56         if ((_main_picture && !other->_main_picture) || (!_main_picture && other->_main_picture)) {
57                 notes.push_back ("reel has different assets");
58                 return false;
59         }
60         
61         if (_main_picture && !_main_picture->equals (other->_main_picture, opt, notes)) {
62                 return false;
63         }
64
65         if ((_main_sound && !other->_main_sound) || (!_main_sound && other->_main_sound)) {
66                 notes.push_back ("reel has different assets");
67                 return false;
68         }
69         
70         if (_main_sound && !_main_sound->equals (other->_main_sound, opt, notes)) {
71                 return false;
72         }
73
74         if ((_main_subtitle && !other->_main_subtitle) || (!_main_subtitle && other->_main_subtitle)) {
75                 notes.push_back ("reel has different assets");
76                 return false;
77         }
78         
79         if (_main_subtitle && !_main_subtitle->equals (other->_main_subtitle, opt, notes)) {
80                 return false;
81         }
82
83         return true;
84 }
85