Use enum class for the things in types.h
[libdcp.git] / src / smpte_subtitle_asset.cc
index 0ebfcc61e868041f1202dcd0775718092c6ab0ce..49ccc5a9984c9fe4e992c19a5de4882647c34348 100644 (file)
@@ -56,11 +56,12 @@ using std::string;
 using std::list;
 using std::vector;
 using std::map;
-using boost::shared_ptr;
+using std::shared_ptr;
+using std::dynamic_pointer_cast;
+using std::make_shared;
 using boost::split;
 using boost::is_any_of;
 using boost::shared_array;
-using boost::dynamic_pointer_cast;
 using boost::optional;
 using boost::starts_with;
 using namespace dcp;
@@ -68,7 +69,7 @@ using namespace dcp;
 static string const subtitle_smpte_ns = "http://www.smpte-ra.org/schemas/428-7/2010/DCST";
 
 SMPTESubtitleAsset::SMPTESubtitleAsset ()
-       : MXF (SMPTE)
+       : MXF (Standard::SMPTE)
        , _intrinsic_duration (0)
        , _edit_rate (24, 1)
        , _time_code_rate (24)
@@ -101,7 +102,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file)
                        reader->ReadTimedTextResource (_raw_xml);
                        xml->read_string (_raw_xml);
                        parse_xml (xml);
-                       read_mxf_descriptor (reader, shared_ptr<DecryptionContext> (new DecryptionContext (optional<Key>(), SMPTE)));
+                       read_mxf_descriptor (reader, shared_ptr<DecryptionContext> (new DecryptionContext (optional<Key>(), Standard::SMPTE)));
                }
        } else {
                /* Plain XML */
@@ -140,6 +141,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file)
                                }
                        }
                }
+               _standard = Standard::SMPTE;
        }
 
        /* Check that all required image data have been found */
@@ -182,12 +184,12 @@ SMPTESubtitleAsset::parse_xml (shared_ptr<cxml::Document> xml)
 
        /* Now we need to drop down to xmlpp */
 
-       list<ParseState> ps;
+       vector<ParseState> ps;
        xmlpp::Node::NodeList c = xml->node()->get_children ();
        for (xmlpp::Node::NodeList::const_iterator i = c.begin(); i != c.end(); ++i) {
                xmlpp::Element const * e = dynamic_cast<xmlpp::Element const *> (*i);
                if (e && e->get_name() == "SubtitleList") {
-                       parse_subtitles (e, ps, _time_code_rate, SMPTE);
+                       parse_subtitles (e, ps, _time_code_rate, Standard::SMPTE);
                }
        }
 
@@ -221,7 +223,7 @@ SMPTESubtitleAsset::read_mxf_descriptor (shared_ptr<ASDCP::TimedText::MXFReader>
                switch (i->Type) {
                case ASDCP::TimedText::MT_OPENTYPE:
                {
-                       list<shared_ptr<SMPTELoadFontNode> >::const_iterator j = _load_font_nodes.begin ();
+                       auto j = _load_font_nodes.begin();
                        while (j != _load_font_nodes.end() && (*j)->urn != id) {
                                ++j;
                        }
@@ -233,7 +235,7 @@ SMPTESubtitleAsset::read_mxf_descriptor (shared_ptr<ASDCP::TimedText::MXFReader>
                }
                case ASDCP::TimedText::MT_PNG:
                {
-                       list<shared_ptr<Subtitle> >::const_iterator j = _subtitles.begin ();
+                       auto j = _subtitles.begin();
                        while (j != _subtitles.end() && ((!dynamic_pointer_cast<SubtitleImage>(*j)) || dynamic_pointer_cast<SubtitleImage>(*j)->id() != id)) {
                                ++j;
                        }
@@ -282,7 +284,7 @@ SMPTESubtitleAsset::set_key (Key key)
                        );
        }
 
-       shared_ptr<DecryptionContext> dec (new DecryptionContext (key, SMPTE));
+       auto dec = make_shared<DecryptionContext>(key, Standard::SMPTE);
        reader->ReadTimedTextResource (_raw_xml, dec->context(), dec->hmac());
        shared_ptr<cxml::Document> xml (new cxml::Document ("SubtitleReel"));
        xml->read_string (_raw_xml);
@@ -290,10 +292,10 @@ SMPTESubtitleAsset::set_key (Key key)
        read_mxf_descriptor (reader, dec);
 }
 
-list<shared_ptr<LoadFontNode> >
+vector<shared_ptr<LoadFontNode>>
 SMPTESubtitleAsset::load_font_nodes () const
 {
-       list<shared_ptr<LoadFontNode> > lf;
+       vector<shared_ptr<LoadFontNode>> lf;
        copy (_load_font_nodes.begin(), _load_font_nodes.end(), back_inserter (lf));
        return lf;
 }
@@ -331,7 +333,7 @@ SMPTESubtitleAsset::xml_as_string () const
        root->add_child("EditRate", "dcst")->add_child_text (_edit_rate.as_string ());
        root->add_child("TimeCodeRate", "dcst")->add_child_text (raw_convert<string> (_time_code_rate));
        if (_start_time) {
-               root->add_child("StartTime", "dcst")->add_child_text (_start_time.get().as_string (SMPTE));
+               root->add_child("StartTime", "dcst")->add_child_text(_start_time.get().as_string(Standard::SMPTE));
        }
 
        BOOST_FOREACH (shared_ptr<SMPTELoadFontNode> i, _load_font_nodes) {
@@ -340,7 +342,7 @@ SMPTESubtitleAsset::xml_as_string () const
                load_font->set_attribute ("ID", i->id);
        }
 
-       subtitles_as_xml (root->add_child ("SubtitleList", "dcst"), _time_code_rate, SMPTE);
+       subtitles_as_xml (root->add_child("SubtitleList", "dcst"), _time_code_rate, Standard::SMPTE);
 
        return doc.write_to_string ("UTF-8");
 }
@@ -349,7 +351,7 @@ SMPTESubtitleAsset::xml_as_string () const
 void
 SMPTESubtitleAsset::write (boost::filesystem::path p) const
 {
-       EncryptionContext enc (key(), SMPTE);
+       EncryptionContext enc (key(), Standard::SMPTE);
 
        ASDCP::WriterInfo writer_info;
        fill_writer_info (&writer_info, _id);
@@ -361,7 +363,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const
        /* Font references */
 
        BOOST_FOREACH (shared_ptr<dcp::SMPTELoadFontNode> i, _load_font_nodes) {
-               list<Font>::const_iterator j = _fonts.begin ();
+               auto j = _fonts.begin();
                while (j != _fonts.end() && j->load_id != i->id) {
                        ++j;
                }
@@ -412,7 +414,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const
        /* Font payload */
 
        BOOST_FOREACH (shared_ptr<dcp::SMPTELoadFontNode> i, _load_font_nodes) {
-               list<Font>::const_iterator j = _fonts.begin ();
+               auto j = _fonts.begin();
                while (j != _fonts.end() && j->load_id != i->id) {
                        ++j;
                }
@@ -457,21 +459,21 @@ SMPTESubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions
 
        shared_ptr<const SMPTESubtitleAsset> other = dynamic_pointer_cast<const SMPTESubtitleAsset> (other_asset);
        if (!other) {
-               note (DCP_ERROR, "Subtitles are in different standards");
+               note (NoteType::ERROR, "Subtitles are in different standards");
                return false;
        }
 
-       list<shared_ptr<SMPTELoadFontNode> >::const_iterator i = _load_font_nodes.begin ();
-       list<shared_ptr<SMPTELoadFontNode> >::const_iterator j = other->_load_font_nodes.begin ();
+       auto i = _load_font_nodes.begin();
+       auto j = other->_load_font_nodes.begin();
 
        while (i != _load_font_nodes.end ()) {
                if (j == other->_load_font_nodes.end ()) {
-                       note (DCP_ERROR, "<LoadFont> nodes differ");
+                       note (NoteType::ERROR, "<LoadFont> nodes differ");
                        return false;
                }
 
                if ((*i)->id != (*j)->id) {
-                       note (DCP_ERROR, "<LoadFont> nodes differ");
+                       note (NoteType::ERROR, "<LoadFont> nodes differ");
                        return false;
                }
 
@@ -480,46 +482,46 @@ SMPTESubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions
        }
 
        if (_content_title_text != other->_content_title_text) {
-               note (DCP_ERROR, "Subtitle content title texts differ");
+               note (NoteType::ERROR, "Subtitle content title texts differ");
                return false;
        }
 
        if (_language != other->_language) {
-               note (DCP_ERROR, String::compose("Subtitle languages differ (`%1' vs `%2')", _language.get_value_or("[none]"), other->_language.get_value_or("[none]")));
+               note (NoteType::ERROR, String::compose("Subtitle languages differ (`%1' vs `%2')", _language.get_value_or("[none]"), other->_language.get_value_or("[none]")));
                return false;
        }
 
        if (_annotation_text != other->_annotation_text) {
-               note (DCP_ERROR, "Subtitle annotation texts differ");
+               note (NoteType::ERROR, "Subtitle annotation texts differ");
                return false;
        }
 
        if (_issue_date != other->_issue_date) {
                if (options.issue_dates_can_differ) {
-                       note (DCP_NOTE, "Subtitle issue dates differ");
+                       note (NoteType::NOTE, "Subtitle issue dates differ");
                } else {
-                       note (DCP_ERROR, "Subtitle issue dates differ");
+                       note (NoteType::ERROR, "Subtitle issue dates differ");
                        return false;
                }
        }
 
        if (_reel_number != other->_reel_number) {
-               note (DCP_ERROR, "Subtitle reel numbers differ");
+               note (NoteType::ERROR, "Subtitle reel numbers differ");
                return false;
        }
 
        if (_edit_rate != other->_edit_rate) {
-               note (DCP_ERROR, "Subtitle edit rates differ");
+               note (NoteType::ERROR, "Subtitle edit rates differ");
                return false;
        }
 
        if (_time_code_rate != other->_time_code_rate) {
-               note (DCP_ERROR, "Subtitle time code rates differ");
+               note (NoteType::ERROR, "Subtitle time code rates differ");
                return false;
        }
 
        if (_start_time != other->_start_time) {
-               note (DCP_ERROR, "Subtitle start times differ");
+               note (NoteType::ERROR, "Subtitle start times differ");
                return false;
        }
 
@@ -527,10 +529,10 @@ SMPTESubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions
 }
 
 void
-SMPTESubtitleAsset::add_font (string load_id, boost::filesystem::path file)
+SMPTESubtitleAsset::add_font (string load_id, dcp::ArrayData data)
 {
        string const uuid = make_uuid ();
-       _fonts.push_back (Font (load_id, uuid, file));
+       _fonts.push_back (Font(load_id, uuid, data));
        _load_font_nodes.push_back (shared_ptr<SMPTELoadFontNode> (new SMPTELoadFontNode (load_id, uuid)));
 }