From 9691fc54fa6a3409520a1a42e6eeb8e6a235f5f6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 21 Jan 2021 10:56:07 +0100 Subject: Some more use of enum class. --- src/colour_conversion.cc | 45 +++---- src/colour_conversion.h | 10 +- src/dcp.cc | 10 +- src/language_tag.cc | 61 +++++----- src/language_tag.h | 36 +++--- src/subtitle_asset.cc | 24 ++-- src/subtitle_asset.h | 2 +- src/verify.cc | 304 +++++++++++++++++++++++------------------------ src/verify.h | 10 +- 9 files changed, 250 insertions(+), 252 deletions(-) (limited to 'src') diff --git a/src/colour_conversion.cc b/src/colour_conversion.cc index de69c211..1251d94f 100644 --- a/src/colour_conversion.cc +++ b/src/colour_conversion.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2015 Carl Hetherington + Copyright (C) 2014-2021 Carl Hetherington This file is part of libdcp. @@ -42,6 +42,7 @@ #include using std::shared_ptr; +using std::make_shared; using boost::optional; using namespace dcp; @@ -49,14 +50,14 @@ ColourConversion const & ColourConversion::srgb_to_xyz () { static ColourConversion* c = new ColourConversion ( - shared_ptr (new ModifiedGammaTransferFunction (2.4, 0.04045, 0.055, 12.92)), - YUV_TO_RGB_REC601, + make_shared(2.4, 0.04045, 0.055, 12.92), + YUVToRGB::REC601, Chromaticity (0.64, 0.33), Chromaticity (0.3, 0.6), Chromaticity (0.15, 0.06), Chromaticity::D65 (), optional (), - shared_ptr (new GammaTransferFunction (2.6)) + make_shared(2.6) ); return *c; } @@ -65,14 +66,14 @@ ColourConversion const & ColourConversion::rec601_to_xyz () { static ColourConversion* c = new ColourConversion ( - shared_ptr (new GammaTransferFunction (2.2)), - YUV_TO_RGB_REC601, + make_shared(2.2), + YUVToRGB::REC601, Chromaticity (0.64, 0.33), Chromaticity (0.3, 0.6), Chromaticity (0.15, 0.06), Chromaticity::D65 (), optional (), - shared_ptr (new GammaTransferFunction (2.6)) + make_shared(2.6) ); return *c; } @@ -81,14 +82,14 @@ ColourConversion const & ColourConversion::rec709_to_xyz () { static ColourConversion* c = new ColourConversion ( - shared_ptr (new GammaTransferFunction (2.2)), - YUV_TO_RGB_REC709, + make_shared(2.2), + YUVToRGB::REC709, Chromaticity (0.64, 0.33), Chromaticity (0.3, 0.6), Chromaticity (0.15, 0.06), Chromaticity::D65 (), optional (), - shared_ptr (new GammaTransferFunction (2.6)) + make_shared(2.6) ); return *c; } @@ -97,14 +98,14 @@ ColourConversion const & ColourConversion::p3_to_xyz () { static ColourConversion* c = new ColourConversion ( - shared_ptr (new GammaTransferFunction (2.6)), - YUV_TO_RGB_REC709, + make_shared(2.6), + YUVToRGB::REC709, Chromaticity (0.68, 0.32), Chromaticity (0.265, 0.69), Chromaticity (0.15, 0.06), Chromaticity (0.314, 0.351), optional (), - shared_ptr (new GammaTransferFunction (2.6)) + make_shared(2.6) ); return *c; } @@ -116,14 +117,14 @@ ColourConversion::rec1886_to_xyz () 2.4 gamma, so here goes ... */ static ColourConversion* c = new ColourConversion ( - shared_ptr (new GammaTransferFunction (2.4)), - YUV_TO_RGB_REC709, + make_shared(2.4), + YUVToRGB::REC709, Chromaticity (0.64, 0.33), Chromaticity (0.3, 0.6), Chromaticity (0.15, 0.06), Chromaticity::D65 (), optional (), - shared_ptr (new GammaTransferFunction (2.6)) + make_shared(2.6) ); return *c; } @@ -132,14 +133,14 @@ ColourConversion const & ColourConversion::rec2020_to_xyz () { static ColourConversion* c = new ColourConversion ( - shared_ptr (new GammaTransferFunction (2.4)), - YUV_TO_RGB_REC709, + make_shared(2.4), + YUVToRGB::REC709, Chromaticity (0.708, 0.292), Chromaticity (0.170, 0.797), Chromaticity (0.131, 0.046), Chromaticity::D65 (), optional (), - shared_ptr (new GammaTransferFunction (2.6)) + make_shared(2.6) ); return *c; } @@ -149,14 +150,14 @@ ColourConversion const & ColourConversion::s_gamut3_to_xyz () { static ColourConversion* c = new ColourConversion ( - shared_ptr (new SGamut3TransferFunction ()), - YUV_TO_RGB_REC709, + make_shared(), + YUVToRGB::REC709, Chromaticity (0.73, 0.280), Chromaticity (0.140, 0.855), Chromaticity (0.100, -0.050), Chromaticity::D65 (), optional (), - shared_ptr (new IdentityTransferFunction ()) + make_shared() ); return *c; } diff --git a/src/colour_conversion.h b/src/colour_conversion.h index 17051bcd..d613c143 100644 --- a/src/colour_conversion.h +++ b/src/colour_conversion.h @@ -50,10 +50,10 @@ namespace dcp { class TransferFunction; -enum YUVToRGB { - YUV_TO_RGB_REC601, - YUV_TO_RGB_REC709, - YUV_TO_RGB_COUNT +enum class YUVToRGB { + REC601, + REC709, + COUNT }; /** @class ColourConversion @@ -64,7 +64,7 @@ class ColourConversion { public: ColourConversion () - : _yuv_to_rgb (YUV_TO_RGB_REC601) + : _yuv_to_rgb (YUVToRGB::REC601) {} ColourConversion ( diff --git a/src/dcp.cc b/src/dcp.cc index d8c8c130..de02f8fb 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -192,14 +192,14 @@ DCP::read (vector* notes, bool ignore_incorrect_picture_m claims to come from ClipsterDCI 5.10.0.5. */ if (notes) { - notes->push_back ({VerificationNote::VERIFY_WARNING, VerificationNote::EMPTY_ASSET_PATH}); + notes->push_back ({VerificationNote::Type::WARNING, VerificationNote::Code::EMPTY_ASSET_PATH}); } continue; } if (!boost::filesystem::exists(path)) { if (notes) { - notes->push_back ({VerificationNote::VERIFY_ERROR, VerificationNote::MISSING_ASSET, path}); + notes->push_back ({VerificationNote::Type::ERROR, VerificationNote::Code::MISSING_ASSET, path}); } continue; } @@ -235,12 +235,12 @@ DCP::read (vector* notes, bool ignore_incorrect_picture_m if (root == "CompositionPlaylist") { auto cpl = make_shared(path); if (_standard && cpl->standard() && cpl->standard().get() != _standard.get() && notes) { - notes->push_back ({VerificationNote::VERIFY_ERROR, VerificationNote::MISMATCHED_STANDARD}); + notes->push_back ({VerificationNote::Type::ERROR, VerificationNote::Code::MISMATCHED_STANDARD}); } _cpls.push_back (cpl); } else if (root == "DCSubtitle") { if (_standard && _standard.get() == Standard::SMPTE && notes) { - notes->push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::MISMATCHED_STANDARD)); + notes->push_back (VerificationNote(VerificationNote::Type::ERROR, VerificationNote::Code::MISMATCHED_STANDARD)); } other_assets.push_back (make_shared(path)); } @@ -268,7 +268,7 @@ DCP::read (vector* notes, bool ignore_incorrect_picture_m for (auto i: cpls()) { for (auto j: i->reel_mxfs()) { if (!j->asset_ref().resolved() && paths.find(j->asset_ref().id()) == paths.end()) { - notes->push_back (VerificationNote(VerificationNote::VERIFY_WARNING, VerificationNote::EXTERNAL_ASSET, j->asset_ref().id())); + notes->push_back (VerificationNote(VerificationNote::Type::WARNING, VerificationNote::Code::EXTERNAL_ASSET, j->asset_ref().id())); } } } diff --git a/src/language_tag.cc b/src/language_tag.cc index 2b63bbf9..148e054b 100644 --- a/src/language_tag.cc +++ b/src/language_tag.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington + Copyright (C) 2020-2021 Carl Hetherington This file is part of libdcp. @@ -51,8 +51,6 @@ using boost::algorithm::trim; using namespace dcp; - - static vector language_list; static vector variant_list; static vector region_list; @@ -60,7 +58,6 @@ static vector script_list; static vector extlang_list; - static optional find_in_list (vector const& list, string subtag) @@ -212,7 +209,7 @@ check_for_duplicates (vector const& subtags, dcp::LanguageTag::SubtagType typ vector sorted = subtags; sort (sorted.begin(), sorted.end()); optional last; - BOOST_FOREACH (T const& i, sorted) { + for (auto const& i: sorted) { if (last && i == *last) { throw LanguageTagError (String::compose("Duplicate %1 subtag %2", dcp::LanguageTag::subtag_type_name(type), i.subtag())); } @@ -224,7 +221,7 @@ check_for_duplicates (vector const& subtags, dcp::LanguageTag::SubtagType typ void LanguageTag::set_variants (vector variants) { - check_for_duplicates (variants, VARIANT); + check_for_duplicates (variants, SubtagType::VARIANT); _variants = variants; } @@ -243,7 +240,7 @@ LanguageTag::add_extlang (ExtlangSubtag extlang) void LanguageTag::set_extlangs (vector extlangs) { - check_for_duplicates (extlangs, EXTLANG); + check_for_duplicates (extlangs, SubtagType::EXTLANG); _extlangs = extlangs; } @@ -258,29 +255,29 @@ LanguageTag::description () const string d; BOOST_FOREACH (VariantSubtag const& i, _variants) { - optional variant = get_subtag_data (VARIANT, i.subtag()); + optional variant = get_subtag_data (SubtagType::VARIANT, i.subtag()); DCP_ASSERT (variant); d += variant->description + " dialect of "; } - optional language = get_subtag_data (LANGUAGE, _language->subtag()); + optional language = get_subtag_data (SubtagType::LANGUAGE, _language->subtag()); DCP_ASSERT (language); d += language->description; if (_script) { - optional script = get_subtag_data (SCRIPT, _script->subtag()); + optional script = get_subtag_data (SubtagType::SCRIPT, _script->subtag()); DCP_ASSERT (script); d += " written using the " + script->description + " script"; } if (_region) { - optional region = get_subtag_data (REGION, _region->subtag()); + optional region = get_subtag_data (SubtagType::REGION, _region->subtag()); DCP_ASSERT (region); d += " for " + region->description; } BOOST_FOREACH (ExtlangSubtag const& i, _extlangs) { - optional extlang = get_subtag_data (EXTLANG, i.subtag()); + optional extlang = get_subtag_data (SubtagType::EXTLANG, i.subtag()); DCP_ASSERT (extlang); d += ", " + extlang->description; } @@ -293,15 +290,15 @@ vector const & LanguageTag::get_all (SubtagType type) { switch (type) { - case LANGUAGE: + case SubtagType::LANGUAGE: return language_list; - case SCRIPT: + case SubtagType::SCRIPT: return script_list; - case REGION: + case SubtagType::REGION: return region_list; - case VARIANT: + case SubtagType::VARIANT: return variant_list; - case EXTLANG: + case SubtagType::EXTLANG: return extlang_list; } @@ -313,15 +310,15 @@ string LanguageTag::subtag_type_name (SubtagType type) { switch (type) { - case LANGUAGE: + case SubtagType::LANGUAGE: return "Language"; - case SCRIPT: + case SubtagType::SCRIPT: return "Script"; - case REGION: + case SubtagType::REGION: return "Region"; - case VARIANT: + case SubtagType::VARIANT: return "Variant"; - case EXTLANG: + case SubtagType::EXTLANG: return "Extended"; } @@ -377,23 +374,23 @@ LanguageTag::subtags () const vector > s; if (_language) { - s.push_back (make_pair(LANGUAGE, *get_subtag_data(LANGUAGE, _language->subtag()))); + s.push_back (make_pair(SubtagType::LANGUAGE, *get_subtag_data(SubtagType::LANGUAGE, _language->subtag()))); } if (_script) { - s.push_back (make_pair(SCRIPT, *get_subtag_data(SCRIPT, _script->subtag()))); + s.push_back (make_pair(SubtagType::SCRIPT, *get_subtag_data(SubtagType::SCRIPT, _script->subtag()))); } if (_region) { - s.push_back (make_pair(REGION, *get_subtag_data(REGION, _region->subtag()))); + s.push_back (make_pair(SubtagType::REGION, *get_subtag_data(SubtagType::REGION, _region->subtag()))); } BOOST_FOREACH (VariantSubtag const& i, _variants) { - s.push_back (make_pair(VARIANT, *get_subtag_data(VARIANT, i.subtag()))); + s.push_back (make_pair(SubtagType::VARIANT, *get_subtag_data(SubtagType::VARIANT, i.subtag()))); } BOOST_FOREACH (ExtlangSubtag const& i, _extlangs) { - s.push_back (make_pair(EXTLANG, *get_subtag_data(EXTLANG, i.subtag()))); + s.push_back (make_pair(SubtagType::EXTLANG, *get_subtag_data(SubtagType::EXTLANG, i.subtag()))); } return s; @@ -404,15 +401,15 @@ optional LanguageTag::get_subtag_data (LanguageTag::SubtagType type, string subtag) { switch (type) { - case dcp::LanguageTag::LANGUAGE: + case SubtagType::LANGUAGE: return find_in_list(language_list, subtag); - case dcp::LanguageTag::SCRIPT: + case SubtagType::SCRIPT: return find_in_list(script_list, subtag); - case dcp::LanguageTag::REGION: + case SubtagType::REGION: return find_in_list(region_list, subtag); - case dcp::LanguageTag::VARIANT: + case SubtagType::VARIANT: return find_in_list(variant_list, subtag); - case dcp::LanguageTag::EXTLANG: + case SubtagType::EXTLANG: return find_in_list(extlang_list, subtag); } diff --git a/src/language_tag.h b/src/language_tag.h index a0beaad0..06134b03 100644 --- a/src/language_tag.h +++ b/src/language_tag.h @@ -67,7 +67,7 @@ public: } }; - enum SubtagType + enum class SubtagType { LANGUAGE, SCRIPT, @@ -102,12 +102,12 @@ public: { public: LanguageSubtag (std::string subtag) - : Subtag(subtag, LANGUAGE) {} + : Subtag(subtag, SubtagType::LANGUAGE) {} LanguageSubtag (char const* subtag) - : Subtag(subtag, LANGUAGE) {} + : Subtag(subtag, SubtagType::LANGUAGE) {} SubtagType type () const { - return LANGUAGE; + return SubtagType::LANGUAGE; } }; @@ -115,12 +115,12 @@ public: { public: ScriptSubtag (std::string subtag) - : Subtag(subtag, SCRIPT) {} + : Subtag(subtag, SubtagType::SCRIPT) {} ScriptSubtag (char const* subtag) - : Subtag(subtag, SCRIPT) {} + : Subtag(subtag, SubtagType::SCRIPT) {} SubtagType type () const { - return SCRIPT; + return SubtagType::SCRIPT; } }; @@ -128,12 +128,12 @@ public: { public: RegionSubtag (std::string subtag) - : Subtag(subtag, REGION) {} + : Subtag(subtag, SubtagType::REGION) {} RegionSubtag (char const* subtag) - : Subtag(subtag, REGION) {} + : Subtag(subtag, SubtagType::REGION) {} SubtagType type () const { - return REGION; + return SubtagType::REGION; } }; @@ -141,12 +141,12 @@ public: { public: VariantSubtag (std::string subtag) - : Subtag(subtag, VARIANT) {} + : Subtag(subtag, SubtagType::VARIANT) {} VariantSubtag (char const* subtag) - : Subtag(subtag, VARIANT) {} + : Subtag(subtag, SubtagType::VARIANT) {} SubtagType type () const { - return VARIANT; + return SubtagType::VARIANT; } bool operator== (VariantSubtag const& other) const; @@ -158,12 +158,12 @@ public: { public: ExtlangSubtag (std::string subtag) - : Subtag(subtag, EXTLANG) {} + : Subtag(subtag, SubtagType::EXTLANG) {} ExtlangSubtag (char const* subtag) - : Subtag(subtag, EXTLANG) {} + : Subtag(subtag, SubtagType::EXTLANG) {} SubtagType type () const { - return EXTLANG; + return SubtagType::EXTLANG; } bool operator== (ExtlangSubtag const& other) const; @@ -205,13 +205,13 @@ public: void set_extlangs (std::vector extlangs); void add_extlang (ExtlangSubtag extlang); - std::vector > subtags () const; + std::vector> subtags () const; static std::vector const& get_all (SubtagType type); static std::string subtag_type_name (SubtagType type); static boost::optional get_subtag_description (SubtagType, std::string subtag); - static boost::optional get_subtag_data (SubtagType, std::string subtag); + static boost::optional get_subtag_data (SubtagType, std::string subtag); template static boost::optional get_subtag_description (T s) { diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 37b381ae..9d46cb5c 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -203,7 +203,7 @@ SubtitleAsset::text_node_state (xmlpp::Element const * node) const ps.direction = string_to_direction (d.get ()); } - ps.type = ParseState::TEXT; + ps.type = ParseState::Type::TEXT; return ps; } @@ -215,7 +215,7 @@ SubtitleAsset::image_node_state (xmlpp::Element const * node) const position_align (ps, node); - ps.type = ParseState::IMAGE; + ps.type = ParseState::Type::IMAGE; return ps; } @@ -360,7 +360,7 @@ SubtitleAsset::maybe_add_subtitle (string text, vector const & parse DCP_ASSERT (ps.type); switch (ps.type.get()) { - case ParseState::TEXT: + case ParseState::Type::TEXT: _subtitles.push_back ( shared_ptr ( new SubtitleString ( @@ -387,7 +387,7 @@ SubtitleAsset::maybe_add_subtitle (string text, vector const & parse ) ); break; - case ParseState::IMAGE: + case ParseState::Type::IMAGE: /* Add a subtitle with no image data and we'll fill that in later */ _subtitles.push_back ( shared_ptr ( @@ -465,7 +465,7 @@ Time SubtitleAsset::latest_subtitle_out () const { Time t; - BOOST_FOREACH (shared_ptr i, _subtitles) { + for (auto i: _subtitles) { if (i->out() > t) { t = i->out (); } @@ -481,7 +481,7 @@ SubtitleAsset::equals (shared_ptr other_asset, EqualityOptions opti return false; } - shared_ptr other = dynamic_pointer_cast (other_asset); + auto other = dynamic_pointer_cast (other_asset); if (!other) { return false; } @@ -539,7 +539,7 @@ SubtitleAsset::pull_fonts (shared_ptr part) } /* Pull up from children */ - BOOST_FOREACH (shared_ptr i, part->children) { + for (auto i: part->children) { pull_fonts (i); } @@ -597,14 +597,14 @@ SubtitleAsset::pull_fonts (shared_ptr part) void SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, Standard standard) const { - vector > sorted = _subtitles; + auto sorted = _subtitles; std::stable_sort(sorted.begin(), sorted.end(), SubtitleSorter()); /* Gather our subtitles into a hierarchy of Subtitle/Text/String objects, writing font information into the bottom level (String) objects. */ - shared_ptr root (new order::Part (shared_ptr ())); + auto root = make_shared(shared_ptr()); shared_ptr subtitle; shared_ptr text; @@ -618,7 +618,7 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, S float last_v_position; Direction last_direction; - BOOST_FOREACH (shared_ptr i, sorted) { + for (auto i: sorted) { if (!subtitle || (last_in != i->in() || last_out != i->out() || @@ -626,7 +626,7 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, S last_fade_down_time != i->fade_down_time()) ) { - subtitle.reset (new order::Subtitle (root, i->in(), i->out(), i->fade_up_time(), i->fade_down_time())); + subtitle = make_shared(root, i->in(), i->out(), i->fade_up_time(), i->fade_down_time()); root->children.push_back (subtitle); last_in = i->in (); @@ -636,7 +636,7 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, S text.reset (); } - shared_ptr is = dynamic_pointer_cast(i); + auto is = dynamic_pointer_cast(i); if (is) { if (!text || last_h_align != is->h_align() || diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 02976f7d..7502ad33 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -136,7 +136,7 @@ protected: boost::optional