Cleanup: remove unnecessary clearing of 0-init-ed UTCOffset.
[libdcp.git] / src / content_kind.cc
1 /*
2     Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp 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     libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34
35 #include "content_kind.h"
36 #include "dcp_assert.h"
37 #include <algorithm>
38 #include <iostream>
39
40
41 using std::string;
42 using std::vector;
43 using namespace dcp;
44
45
46 static std::string const smpte_429_16_scope = "http://www.smpte-ra.org/schemas/429-16/2014/CPL-Metadata#scope/content-kind";
47 static std::string const smpte_2067_3_scope = "http://www.smpte-ra.org/schemas/2067-3/2013#content-kind";
48
49
50 ContentKind const ContentKind::FEATURE                     = ContentKind{"feature"};
51 ContentKind const ContentKind::SHORT                       = ContentKind{"short"};
52 ContentKind const ContentKind::TRAILER                     = ContentKind{"trailer"};
53 ContentKind const ContentKind::TEST                        = ContentKind{"test"};
54 ContentKind const ContentKind::TRANSITIONAL                = ContentKind{"transitional"};
55 ContentKind const ContentKind::RATING                      = ContentKind{"rating"};
56 ContentKind const ContentKind::TEASER                      = ContentKind{"teaser"};
57 ContentKind const ContentKind::POLICY                      = ContentKind{"policy"};
58 ContentKind const ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT = ContentKind{"psa"};
59 ContentKind const ContentKind::ADVERTISEMENT               = ContentKind{"advertisement"};
60 ContentKind const ContentKind::CLIP                        = ContentKind{"clip", smpte_429_16_scope};
61 ContentKind const ContentKind::PROMO                       = ContentKind{"promo", smpte_429_16_scope};
62 ContentKind const ContentKind::STEREOCARD                  = ContentKind{"stereocard", smpte_429_16_scope};
63 ContentKind const ContentKind::EPISODE                     = ContentKind{"episode", smpte_2067_3_scope};
64 ContentKind const ContentKind::HIGHLIGHTS                  = ContentKind{"highlights", smpte_2067_3_scope};
65 ContentKind const ContentKind::EVENT                       = ContentKind{"event", smpte_2067_3_scope};
66
67
68 vector<ContentKind>
69 ContentKind::all()
70 {
71         return {
72                 ContentKind::FEATURE,
73                 ContentKind::SHORT,
74                 ContentKind::TRAILER,
75                 ContentKind::TEST,
76                 ContentKind::TRANSITIONAL,
77                 ContentKind::RATING,
78                 ContentKind::TEASER,
79                 ContentKind::POLICY,
80                 ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT,
81                 ContentKind::ADVERTISEMENT,
82                 ContentKind::EPISODE,
83                 ContentKind::PROMO
84         };
85 }
86
87
88 ContentKind
89 ContentKind::from_name(string name)
90 {
91         auto const all_kinds = all();
92         std::transform(name.begin(), name.end(), name.begin(), ::tolower);
93         auto iter = std::find_if(all_kinds.begin(), all_kinds.end(), [&name](ContentKind const& k) { return k.name() == name; });
94         if (iter == all_kinds.end()) {
95                 throw BadContentKindError(name);
96         }
97         return *iter;
98 }
99
100
101 bool
102 dcp::operator==(ContentKind const& a, ContentKind const& b)
103 {
104         return a.name() == b.name() && a.scope() == b.scope();
105 }
106
107
108 bool
109 dcp::operator!=(ContentKind const& a, ContentKind const& b)
110 {
111         return !(a == b);
112 }
113
114