Make CPL annotation_text optional.
authorCarl Hetherington <cth@carlh.net>
Thu, 14 Jan 2021 21:20:06 +0000 (22:20 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 17 Jan 2021 19:13:23 +0000 (20:13 +0100)
src/cpl.cc
src/cpl.h
test/read_dcp_test.cc
tools/dcpinfo.cc

index 04bc9f5c11c235256bb267e85338e7367036282d..caf4be1e89c58b75bd1d13f8644f5dc64954073f 100644 (file)
@@ -103,7 +103,7 @@ CPL::CPL (boost::filesystem::path file)
        }
 
        _id = remove_urn_uuid (f.string_child ("Id"));
-       _annotation_text = f.optional_string_child("AnnotationText").get_value_or("");
+       _annotation_text = f.optional_string_child("AnnotationText");
        _issuer = f.optional_string_child("Issuer").get_value_or("");
        _creator = f.optional_string_child("Creator").get_value_or("");
        _issue_date = f.string_child ("IssueDate");
@@ -178,7 +178,9 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptr<cons
        }
 
        root->add_child("Id")->add_child_text ("urn:uuid:" + _id);
-       root->add_child("AnnotationText")->add_child_text (_annotation_text);
+       if (_annotation_text) {
+               root->add_child("AnnotationText")->add_child_text (*_annotation_text);
+       }
        root->add_child("IssueDate")->add_child_text (_issue_date);
        root->add_child("Issuer")->add_child_text (_issuer);
        root->add_child("Creator")->add_child_text (_creator);
@@ -548,7 +550,7 @@ CPL::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler not
        }
 
        if (_annotation_text != other_cpl->_annotation_text && !opt.cpl_annotation_texts_can_differ) {
-               string const s = "CPL: annotation texts differ: " + _annotation_text + " vs " + other_cpl->_annotation_text + "\n";
+               string const s = "CPL: annotation texts differ: " + _annotation_text.get_value_or("") + " vs " + other_cpl->_annotation_text.get_value_or("") + "\n";
                note (DCP_ERROR, s);
                return false;
        }
index c2a8b07d6c8406d77ec0507e76517ba1d01abf3d..3bfffcb53bce348f88a43c60ff053e94935e1c0b 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -117,8 +117,8 @@ public:
                _issue_date = issue_date;
        }
 
-       /** @return contents of the &lt;AnnotationText&gt; node */
-       std::string annotation_text () const {
+       /** @return contents of the &lt;AnnotationText&gt; node, if present */
+       boost::optional<std::string> annotation_text () const {
                return _annotation_text;
        }
 
@@ -290,7 +290,7 @@ private:
        std::string _issuer;
        std::string _creator;
        std::string _issue_date;
-       std::string _annotation_text;
+       boost::optional<std::string> _annotation_text;
        std::string _content_title_text;            ///< &lt;ContentTitleText&gt;
        ContentKind _content_kind;                  ///< &lt;ContentKind&gt;
        std::vector<ContentVersion> _content_versions;
index 7eed18d0aa82c159218f7101d69c842259b9402d..b42a3c391bdc3b0444a184ea79c86bbde5195e13 100644 (file)
@@ -48,8 +48,9 @@ BOOST_AUTO_TEST_CASE (read_dcp_test1)
        auto cpls = d.cpls ();
        BOOST_CHECK_EQUAL (cpls.size(), 1);
 
-       BOOST_CHECK_EQUAL (cpls.front()->annotation_text(), "A Test DCP");
-       BOOST_CHECK_EQUAL (cpls.front()->content_kind(), dcp::FEATURE);
+       BOOST_REQUIRE (cpls[0]->annotation_text());
+       BOOST_CHECK_EQUAL (cpls[0]->annotation_text().get(), "A Test DCP");
+       BOOST_CHECK_EQUAL (cpls[0]->content_kind(), dcp::FEATURE);
        BOOST_REQUIRE (d.standard());
        BOOST_CHECK_EQUAL (d.standard(), dcp::SMPTE);
 }
@@ -63,8 +64,9 @@ BOOST_AUTO_TEST_CASE (read_dcp_test2)
        auto cpls = d.cpls ();
        BOOST_CHECK_EQUAL (cpls.size(), 1);
 
-       BOOST_CHECK_EQUAL (cpls.front()->annotation_text(), "Test_FTR-1_F-119_10_2K_20160524_IOP_OV");
-       BOOST_CHECK_EQUAL (cpls.front()->content_kind(), dcp::FEATURE);
+       BOOST_REQUIRE (cpls[0]->annotation_text());
+       BOOST_CHECK_EQUAL (cpls[0]->annotation_text().get(), "Test_FTR-1_F-119_10_2K_20160524_IOP_OV");
+       BOOST_CHECK_EQUAL (cpls[0]->content_kind(), dcp::FEATURE);
        BOOST_REQUIRE (d.standard());
        BOOST_CHECK_EQUAL (d.standard(), dcp::INTEROP);
 }
index 5ca9b24ff651cc427193e6ca2937acd02f679b51..aa1ce8c2425f8e1167991a83c4794f3f787ec5b4 100644 (file)
@@ -397,7 +397,7 @@ main (int argc, char* argv[])
        dcp::Time total_time;
 
        BOOST_FOREACH (shared_ptr<CPL> i, cpls) {
-               OUTPUT_CPL_NAME_ID("  CPL: %1 %2\n", i->annotation_text(), i->id());
+               OUTPUT_CPL_NAME_ID("  CPL: %1 %2\n", i->annotation_text().get_value_or(""), i->id());
 
                int R = 1;
                BOOST_FOREACH (shared_ptr<Reel> j, i->reels()) {