Use dcp::file_to_string().
[dcpomatic.git] / src / lib / dcp_content_type.cc
1 /*
2     Copyright (C) 2012-2021 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 /** @file src/content_type.cc
22  *  @brief A description of the type of content for a DCP (e.g. feature, trailer etc.)
23  */
24
25 #include "dcp_content_type.h"
26 #include "dcpomatic_assert.h"
27
28 #include "i18n.h"
29
30
31 using boost::optional;
32 using namespace std;
33
34
35 vector<DCPContentType const *> DCPContentType::_dcp_content_types;
36
37
38 DCPContentType::DCPContentType (string p, dcp::ContentKind k, string d)
39         : _pretty_name (p)
40         , _libdcp_kind (k)
41         , _isdcf_name (d)
42 {
43
44 }
45
46
47 void
48 DCPContentType::setup_dcp_content_types ()
49 {
50         _dcp_content_types = {
51                 new DCPContentType(_("Feature"), dcp::ContentKind::FEATURE, N_("FTR")),
52                 new DCPContentType(_("Short"), dcp::ContentKind::SHORT, N_("SHR")),
53                 new DCPContentType(_("Trailer"), dcp::ContentKind::TRAILER, N_("TLR")),
54                 new DCPContentType(_("Test"), dcp::ContentKind::TEST, N_("TST")),
55                 new DCPContentType(_("Transitional"), dcp::ContentKind::TRANSITIONAL, N_("XSN")),
56                 new DCPContentType(_("Rating"), dcp::ContentKind::RATING, N_("RTG")),
57                 new DCPContentType(_("Teaser"), dcp::ContentKind::TEASER, N_("TSR")),
58                 new DCPContentType(_("Policy"), dcp::ContentKind::POLICY, N_("POL")),
59                 new DCPContentType(_("Public Service Announcement"), dcp::ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT, N_("PSA")),
60                 new DCPContentType(_("Advertisement"), dcp::ContentKind::ADVERTISEMENT, N_("ADV")),
61                 new DCPContentType(_("Episode"), dcp::ContentKind::EPISODE, N_("EPS")),
62                 new DCPContentType(_("Promo"), dcp::ContentKind::PROMO, N_("PRO"))
63         };
64 }
65
66
67 DCPContentType const *
68 DCPContentType::from_isdcf_name (string n)
69 {
70         for (auto i: _dcp_content_types) {
71                 if (i->isdcf_name() == n) {
72                         return i;
73                 }
74         }
75
76         return 0;
77 }
78
79
80 DCPContentType const *
81 DCPContentType::from_libdcp_kind (dcp::ContentKind kind)
82 {
83         for (auto i: _dcp_content_types) {
84                 if (i->libdcp_kind() == kind) {
85                         return i;
86                 }
87         }
88
89         DCPOMATIC_ASSERT (false);
90         return nullptr;
91 }
92
93
94 DCPContentType const *
95 DCPContentType::from_index (int n)
96 {
97         DCPOMATIC_ASSERT (n >= 0 && n < int(_dcp_content_types.size()));
98         return _dcp_content_types[n];
99 }
100
101
102 optional<int>
103 DCPContentType::as_index (DCPContentType const * c)
104 {
105         vector<DCPContentType*>::size_type i = 0;
106         while (i < _dcp_content_types.size() && _dcp_content_types[i] != c) {
107                 ++i;
108         }
109
110         if (i == _dcp_content_types.size()) {
111                 return {};
112         }
113
114         return i;
115 }
116
117
118 vector<DCPContentType const *>
119 DCPContentType::all ()
120 {
121         return _dcp_content_types;
122 }