Use EnumIndexedVector in DCPContent.
authorCarl Hetherington <cth@carlh.net>
Mon, 26 Sep 2022 22:34:17 +0000 (00:34 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 27 Sep 2022 11:46:16 +0000 (13:46 +0200)
src/lib/dcp_content.cc
src/lib/dcp_content.h

index 193c9995aee57516e15a6a5143237c352282ef63..2bbeba8c78c11dd03cae3028f773db72854cec32 100644 (file)
@@ -86,10 +86,6 @@ DCPContent::DCPContent (boost::filesystem::path p)
 
        read_directory (p);
        set_default_colour_conversion ();
-
-       for (int i = 0; i < static_cast<int>(TextType::COUNT); ++i) {
-               _reference_text[i] = false;
-       }
 }
 
 DCPContent::DCPContent (cxml::ConstNodePtr node, int version)
@@ -101,10 +97,6 @@ DCPContent::DCPContent (cxml::ConstNodePtr node, int version)
        text = TextContent::from_xml (this, node, version, notes);
        atmos = AtmosContent::from_xml (this, node);
 
-       for (int i = 0; i < static_cast<int>(TextType::COUNT); ++i) {
-               _reference_text[i] = false;
-       }
-
        if (video && audio) {
                audio->set_stream (
                        make_shared<AudioStream> (
@@ -128,11 +120,11 @@ DCPContent::DCPContent (cxml::ConstNodePtr node, int version)
        _reference_video = node->optional_bool_child ("ReferenceVideo").get_value_or (false);
        _reference_audio = node->optional_bool_child ("ReferenceAudio").get_value_or (false);
        if (version >= 37) {
-               _reference_text[static_cast<int>(TextType::OPEN_SUBTITLE)] = node->optional_bool_child("ReferenceOpenSubtitle").get_value_or(false);
-               _reference_text[static_cast<int>(TextType::CLOSED_CAPTION)] = node->optional_bool_child("ReferenceClosedCaption").get_value_or(false);
+               _reference_text[TextType::OPEN_SUBTITLE] = node->optional_bool_child("ReferenceOpenSubtitle").get_value_or(false);
+               _reference_text[TextType::CLOSED_CAPTION] = node->optional_bool_child("ReferenceClosedCaption").get_value_or(false);
        } else {
-               _reference_text[static_cast<int>(TextType::OPEN_SUBTITLE)] = node->optional_bool_child("ReferenceSubtitle").get_value_or(false);
-               _reference_text[static_cast<int>(TextType::CLOSED_CAPTION)] = false;
+               _reference_text[TextType::OPEN_SUBTITLE] = node->optional_bool_child("ReferenceSubtitle").get_value_or(false);
+               _reference_text[TextType::CLOSED_CAPTION] = false;
        }
        if (node->optional_string_child("Standard")) {
                auto const s = node->optional_string_child("Standard").get();
@@ -372,8 +364,8 @@ DCPContent::as_xml (xmlpp::Node* node, bool with_paths) const
        node->add_child("KDMValid")->add_child_text (_kdm_valid ? "1" : "0");
        node->add_child("ReferenceVideo")->add_child_text (_reference_video ? "1" : "0");
        node->add_child("ReferenceAudio")->add_child_text (_reference_audio ? "1" : "0");
-       node->add_child("ReferenceOpenSubtitle")->add_child_text(_reference_text[static_cast<int>(TextType::OPEN_SUBTITLE)] ? "1" : "0");
-       node->add_child("ReferenceClosedCaption")->add_child_text(_reference_text[static_cast<int>(TextType::CLOSED_CAPTION)] ? "1" : "0");
+       node->add_child("ReferenceOpenSubtitle")->add_child_text(_reference_text[TextType::OPEN_SUBTITLE] ? "1" : "0");
+       node->add_child("ReferenceClosedCaption")->add_child_text(_reference_text[TextType::CLOSED_CAPTION] ? "1" : "0");
        if (_standard) {
                switch (_standard.get ()) {
                case dcp::Standard::INTEROP:
@@ -446,8 +438,8 @@ DCPContent::identifier () const
        }
 
        s += string (_reference_video ? "1" : "0");
-       for (int i = 0; i < static_cast<int>(TextType::COUNT); ++i) {
-               s += string (_reference_text[i] ? "1" : "0");
+       for (auto text: _reference_text) {
+               s += string(text ? "1" : "0");
        }
        return s;
 }
@@ -540,7 +532,7 @@ DCPContent::set_reference_text (TextType type, bool r)
 
        {
                boost::mutex::scoped_lock lm (_mutex);
-               _reference_text[static_cast<int>(type)] = r;
+               _reference_text[type] = r;
        }
 }
 
@@ -785,9 +777,7 @@ DCPContent::take_settings_from (shared_ptr<const Content> c)
 
        _reference_video = dc->_reference_video;
        _reference_audio = dc->_reference_audio;
-       for (int i = 0; i < static_cast<int>(TextType::COUNT); ++i) {
-               _reference_text[i] = dc->_reference_text[i];
-       }
+       _reference_text = dc->_reference_text;
 }
 
 void
index efdfe30f705e84c5b6abcdaa4df88b9195283253..17a9a9386006f70fefa024f95c564af37792eeb0 100644 (file)
@@ -29,6 +29,7 @@
 
 
 #include "content.h"
+#include "enum_indexed_vector.h"
 #include "font.h"
 #include <libcxml/cxml.h>
 #include <dcp/content_kind.h>
@@ -123,7 +124,7 @@ public:
         */
        bool reference_text (TextType type) const {
                boost::mutex::scoped_lock lm (_mutex);
-               return _reference_text[static_cast<int>(type)];
+               return _reference_text[type];
        }
 
        bool can_reference_text (std::shared_ptr<const Film> film, TextType type, std::string &) const;
@@ -209,7 +210,7 @@ private:
         *  rather than by rewrapping.  The types here are the original text types,
         *  not what they are being used for.
         */
-       bool _reference_text[static_cast<int>(TextType::COUNT)];
+       EnumIndexedVector<bool, TextType> _reference_text;
 
        boost::optional<dcp::Standard> _standard;
        boost::optional<dcp::ContentKind> _content_kind;