<ContentVersion> is optional in Interop so we can't assume it's there.
authorCarl Hetherington <cth@carlh.net>
Sun, 27 Sep 2020 18:20:23 +0000 (20:20 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 27 Sep 2020 18:20:23 +0000 (20:20 +0200)
src/cpl.cc
src/cpl.h
test/write_subtitle_test.cc

index ead592fd4e1e2abcc10879d75edc07081e2dcfa0..2768e797583b295b9b00ac93f15ab8d0378df55a 100644 (file)
@@ -654,10 +654,13 @@ CPL::set_content_versions (vector<ContentVersion> v)
 }
 
 
-ContentVersion
+optional<ContentVersion>
 CPL::content_version () const
 {
-       DCP_ASSERT (!_content_versions.empty());
+       if (_content_versions.empty()) {
+               return optional<ContentVersion>();
+       }
+
        return _content_versions[0];
 }
 
index 72366ee3d9bbe0a2f6e996c4614a524fa212036b..c1f505dfe964550594d8e22204e75e8e52a32e92 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -140,7 +140,7 @@ public:
                return _content_kind;
        }
 
-       ContentVersion content_version () const;
+       boost::optional<ContentVersion> content_version () const;
 
        std::vector<ContentVersion> content_versions () const {
                return _content_versions;
index b7d8119a5d22f7770033fcd9b6c032ee7db32ef6..4bdc6e9d04995f027bfc6bc97c51536d3dd5eb6d 100644 (file)
@@ -46,6 +46,7 @@
 
 using std::list;
 using std::string;
+using boost::optional;
 using boost::shared_ptr;
 
 /** Test dcp::order::Font::take_intersection */
@@ -372,9 +373,10 @@ BOOST_AUTO_TEST_CASE (write_interop_subtitle_test3)
        cpl->set_creator (creator);
        cpl->set_issue_date (issue_date);
        cpl->set_annotation_text (annotation_text);
-       dcp::ContentVersion cv = cpl->content_version();
-       cv.label_text = "foo";
-       cpl->set_content_version (cv);
+       optional<dcp::ContentVersion> cv = cpl->content_version();
+       BOOST_REQUIRE (cv);
+       cv->label_text = "foo";
+       cpl->set_content_version (*cv);
 
        dcp::DCP dcp ("build/test/write_interop_subtitle_test3");
        dcp.add (cpl);