Remove Screen pointer from KDMWithMetadata, preferring to
[dcpomatic.git] / src / lib / kdm_with_metadata.cc
1 /*
2     Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "kdm_with_metadata.h"
22 #include "cinema.h"
23 #include "screen.h"
24 #include "util.h"
25 #include <boost/foreach.hpp>
26
27 using std::string;
28 using std::cout;
29 using std::list;
30 using boost::shared_ptr;
31 using boost::optional;
32
33 int
34 write_files (
35         list<KDMWithMetadataPtr> screen_kdms,
36         boost::filesystem::path directory,
37         dcp::NameFormat name_format,
38         dcp::NameFormat::Map name_values,
39         boost::function<bool (boost::filesystem::path)> confirm_overwrite
40         )
41 {
42         int written = 0;
43
44         if (directory == "-") {
45                 /* Write KDMs to the stdout */
46                 BOOST_FOREACH (KDMWithMetadataPtr i, screen_kdms) {
47                         cout << i->kdm_as_xml ();
48                         ++written;
49                 }
50
51                 return written;
52         }
53
54         if (!boost::filesystem::exists (directory)) {
55                 boost::filesystem::create_directories (directory);
56         }
57
58         /* Write KDMs to the specified directory */
59         BOOST_FOREACH (KDMWithMetadataPtr i, screen_kdms) {
60                 name_values['i'] = i->kdm_id ();
61                 boost::filesystem::path out = directory / careful_string_filter(name_format.get(name_values, ".xml"));
62                 if (!boost::filesystem::exists (out) || confirm_overwrite (out)) {
63                         i->kdm_as_xml (out);
64                         ++written;
65                 }
66         }
67
68         return written;
69 }
70
71
72 optional<string>
73 KDMWithMetadata::get (char k) const
74 {
75         dcp::NameFormat::Map::const_iterator i = _name_values.find (k);
76         if (i == _name_values.end()) {
77                 return optional<string>();
78         }
79
80         return i->second;
81 }