summaryrefslogtreecommitdiff
path: root/src/content_kind.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-09-02 22:43:19 +0200
committerCarl Hetherington <cth@carlh.net>2022-09-02 22:43:19 +0200
commitd9b957d7da123e4b6e5f2449f5d45c12fce225f8 (patch)
tree46fb87683ff357aff3b886a5e6201a9bb390d3a9 /src/content_kind.cc
parentfeff11732f33487a5bec6fb568f43f86c1a0ab0b (diff)
Replace ContentKind enum with a class.
Diffstat (limited to 'src/content_kind.cc')
-rw-r--r--src/content_kind.cc106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/content_kind.cc b/src/content_kind.cc
new file mode 100644
index 00000000..4b0da53c
--- /dev/null
+++ b/src/content_kind.cc
@@ -0,0 +1,106 @@
+/*
+ Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
+
+ This file is part of libdcp.
+
+ libdcp is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ libdcp is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libdcp. If not, see <http://www.gnu.org/licenses/>.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations
+ including the two.
+
+ You must obey the GNU General Public License in all respects
+ for all of the code used other than OpenSSL. If you modify
+ file(s) with this exception, you may extend this exception to your
+ version of the file(s), but you are not obligated to do so. If you
+ do not wish to do so, delete this exception statement from your
+ version. If you delete this exception statement from all source
+ files in the program, then also delete it here.
+*/
+
+
+#include "content_kind.h"
+#include "dcp_assert.h"
+#include <algorithm>
+#include <iostream>
+
+
+using std::string;
+using std::vector;
+using namespace dcp;
+
+
+ContentKind const ContentKind::FEATURE = ContentKind{"feature"};
+ContentKind const ContentKind::SHORT = ContentKind{"short"};
+ContentKind const ContentKind::TRAILER = ContentKind{"trailer"};
+ContentKind const ContentKind::TEST = ContentKind{"test"};
+ContentKind const ContentKind::TRANSITIONAL = ContentKind{"transitional"};
+ContentKind const ContentKind::RATING = ContentKind{"rating"};
+ContentKind const ContentKind::TEASER = ContentKind{"teaser"};
+ContentKind const ContentKind::POLICY = ContentKind{"policy"};
+ContentKind const ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT = ContentKind{"psa"};
+ContentKind const ContentKind::ADVERTISEMENT = ContentKind{"advertisement"};
+ContentKind const ContentKind::EPISODE = ContentKind{"episode"};
+ContentKind const ContentKind::PROMO = ContentKind{"promo"};
+
+
+vector<ContentKind>
+ContentKind::all()
+{
+ return {
+ ContentKind::FEATURE,
+ ContentKind::SHORT,
+ ContentKind::TRAILER,
+ ContentKind::TEST,
+ ContentKind::TRANSITIONAL,
+ ContentKind::RATING,
+ ContentKind::TEASER,
+ ContentKind::POLICY,
+ ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT,
+ ContentKind::ADVERTISEMENT,
+ ContentKind::EPISODE,
+ ContentKind::PROMO
+ };
+}
+
+
+ContentKind
+ContentKind::from_name(string name)
+{
+ auto const all_kinds = all();
+ std::transform(name.begin(), name.end(), name.begin(), ::tolower);
+ auto iter = std::find_if(all_kinds.begin(), all_kinds.end(), [&name](ContentKind const& k) { return k.name() == name; });
+ if (iter == all_kinds.end()) {
+ throw BadContentKindError(name);
+ }
+ return *iter;
+}
+
+
+bool
+dcp::operator==(ContentKind const& a, ContentKind const& b)
+{
+ return a.name() == b.name();
+}
+
+
+bool
+dcp::operator!=(ContentKind const& a, ContentKind const& b)
+{
+ return !(a == b);
+}
+
+