diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-09-02 22:43:19 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-09-02 22:43:19 +0200 |
| commit | d9b957d7da123e4b6e5f2449f5d45c12fce225f8 (patch) | |
| tree | 46fb87683ff357aff3b886a5e6201a9bb390d3a9 /src | |
| parent | feff11732f33487a5bec6fb568f43f86c1a0ab0b (diff) | |
Replace ContentKind enum with a class.
Diffstat (limited to 'src')
| -rw-r--r-- | src/content_kind.cc | 106 | ||||
| -rw-r--r-- | src/content_kind.h | 87 | ||||
| -rw-r--r-- | src/cpl.cc | 4 | ||||
| -rw-r--r-- | src/cpl.h | 1 | ||||
| -rw-r--r-- | src/types.cc | 79 | ||||
| -rw-r--r-- | src/types.h | 21 | ||||
| -rw-r--r-- | src/wscript | 2 |
7 files changed, 198 insertions, 102 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); +} + + diff --git a/src/content_kind.h b/src/content_kind.h new file mode 100644 index 00000000..08aa17b4 --- /dev/null +++ b/src/content_kind.h @@ -0,0 +1,87 @@ +/* + 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. +*/ + + +#ifndef LIBDCP_CONTENT_KIND_H +#define LIBDCP_CONTENT_KIND_H + + +#include <boost/optional.hpp> +#include <string> +#include <vector> + + +namespace dcp { + + +class ContentKind +{ +public: + std::string name() const { + return _name; + } + + static const ContentKind FEATURE; + static const ContentKind SHORT; + static const ContentKind TRAILER; + static const ContentKind TEST; + static const ContentKind TRANSITIONAL; + static const ContentKind RATING; + static const ContentKind TEASER; + static const ContentKind POLICY; + static const ContentKind PUBLIC_SERVICE_ANNOUNCEMENT; + static const ContentKind ADVERTISEMENT; + static const ContentKind EPISODE; + static const ContentKind PROMO; + + static ContentKind from_name(std::string name); + static std::vector<ContentKind> all(); + +private: + explicit ContentKind(std::string name) + : _name(name) + {} + + std::string _name; +}; + + +bool operator==(ContentKind const& a, ContentKind const& b); +bool operator!=(ContentKind const& a, ContentKind const& b); + + +} + + +#endif + @@ -122,7 +122,7 @@ CPL::CPL (boost::filesystem::path file) _creator = f.optional_string_child("Creator").get_value_or(""); _issue_date = f.string_child ("IssueDate"); _content_title_text = f.string_child ("ContentTitleText"); - _content_kind = content_kind_from_string (f.string_child ("ContentKind")); + _content_kind = ContentKind::from_name(f.string_child("ContentKind")); shared_ptr<cxml::Node> content_version = f.optional_node_child ("ContentVersion"); if (content_version) { /* XXX: SMPTE should insist that Id is present */ @@ -198,7 +198,7 @@ CPL::write_xml (boost::filesystem::path file, shared_ptr<const CertificateChain> root->add_child("Issuer")->add_child_text (_issuer); root->add_child("Creator")->add_child_text (_creator); root->add_child("ContentTitleText")->add_child_text (_content_title_text); - root->add_child("ContentKind")->add_child_text (content_kind_to_string (_content_kind)); + root->add_child("ContentKind")->add_child_text(_content_kind.name()); if (_content_versions.empty()) { ContentVersion cv; cv.as_xml (root); @@ -43,6 +43,7 @@ #include "asset.h" #include "certificate.h" +#include "content_kind.h" #include "key.h" #include "language_tag.h" #include "rating.h" diff --git a/src/types.cc b/src/types.cc index d3be8a3d..15a05f79 100644 --- a/src/types.cc +++ b/src/types.cc @@ -293,85 +293,6 @@ dcp::string_to_direction (string s) } -/** Convert a content kind to a string which can be used in a - * <ContentKind> node - * @param kind ContentKind - * @return string - */ -string -dcp::content_kind_to_string (ContentKind kind) -{ - switch (kind) { - case ContentKind::FEATURE: - return "feature"; - case ContentKind::SHORT: - return "short"; - case ContentKind::TRAILER: - return "trailer"; - case ContentKind::TEST: - return "test"; - case ContentKind::TRANSITIONAL: - return "transitional"; - case ContentKind::RATING: - return "rating"; - case ContentKind::TEASER: - return "teaser"; - case ContentKind::POLICY: - return "policy"; - case ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT: - return "psa"; - case ContentKind::ADVERTISEMENT: - return "advertisement"; - case ContentKind::EPISODE: - return "episode"; - case ContentKind::PROMO: - return "promo"; - } - - DCP_ASSERT (false); -} - - -/** Convert a string from a <ContentKind> node to a libdcp ContentKind. - * Reasonably tolerant about varying case - * @param kind Content kind string - * @return libdcp ContentKind - */ -dcp::ContentKind -dcp::content_kind_from_string (string kind) -{ - transform (kind.begin(), kind.end(), kind.begin(), ::tolower); - - if (kind == "feature") { - return ContentKind::FEATURE; - } else if (kind == "short") { - return ContentKind::SHORT; - } else if (kind == "trailer") { - return ContentKind::TRAILER; - } else if (kind == "test") { - return ContentKind::TEST; - } else if (kind == "transitional") { - return ContentKind::TRANSITIONAL; - } else if (kind == "rating") { - return ContentKind::RATING; - } else if (kind == "teaser") { - return ContentKind::TEASER; - } else if (kind == "policy") { - return ContentKind::POLICY; - } else if (kind == "psa") { - return ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT; - } else if (kind == "advertisement") { - return ContentKind::ADVERTISEMENT; - } else if (kind == "episode") { - return ContentKind::EPISODE; - } else if (kind == "promo") { - return ContentKind::PROMO; - } - - throw BadContentKindError (kind); -} - - string dcp::marker_to_string (dcp::Marker m) { diff --git a/src/types.h b/src/types.h index b6335546..32f1bfc4 100644 --- a/src/types.h +++ b/src/types.h @@ -129,27 +129,6 @@ extern std::string channel_to_mca_name (Channel c, MCASoundField field); extern ASDCP::UL channel_to_mca_universal_label (Channel c, MCASoundField field, ASDCP::Dictionary const* dict); -enum class ContentKind -{ - FEATURE, - SHORT, - TRAILER, - TEST, - TRANSITIONAL, - RATING, - TEASER, - POLICY, - PUBLIC_SERVICE_ANNOUNCEMENT, - ADVERTISEMENT, - EPISODE, - PROMO -}; - - -extern std::string content_kind_to_string (ContentKind kind); -extern ContentKind content_kind_from_string (std::string kind); - - enum class Effect { NONE, diff --git a/src/wscript b/src/wscript index 31d83115..e74c3241 100644 --- a/src/wscript +++ b/src/wscript @@ -47,6 +47,7 @@ def build(bld): chromaticity.cc colour_conversion.cc combine.cc + content_kind.cc cpl.cc data.cc dcp.cc @@ -138,6 +139,7 @@ def build(bld): colour_conversion.h combine.h compose.hpp + content_kind.h cpl.h crypto_context.h data.h |
