Support RatingList.
authorCarl Hetherington <cth@carlh.net>
Tue, 19 Mar 2019 19:47:07 +0000 (19:47 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 19 Mar 2019 19:47:07 +0000 (19:47 +0000)
src/cpl.cc
src/cpl.h
src/types.cc
src/types.h
test/wscript

index 0bf1582490155786f9727acc45e3c199a62acf79..11e7e1c74707aa669301ab77b01afd238a6b25f3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
@@ -105,7 +105,12 @@ CPL::CPL (boost::filesystem::path file)
                _content_version_label_text = content_version->string_child ("LabelText");
                content_version->done ();
        }
-       f.ignore_child ("RatingList");
+       cxml::ConstNodePtr rating_list = f.node_child ("RatingList");
+       if (rating_list) {
+               BOOST_FOREACH (cxml::ConstNodePtr i, rating_list->node_children("Rating")) {
+                       _ratings.push_back (Rating(i));
+               }
+       }
        _reels = type_grand_children<Reel> (f, "ReelList", "Reel");
 
        f.ignore_child ("Issuer");
@@ -156,7 +161,10 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptr<cons
                cv->add_child ("Id")->add_child_text (_content_version_id);
                cv->add_child ("LabelText")->add_child_text (_content_version_label_text);
        }
-       root->add_child("RatingList");
+       xmlpp::Element* rating_list = root->add_child("RatingList");
+       BOOST_FOREACH (Rating i, _ratings) {
+               i.as_xml (rating_list->add_child("Rating"));
+       }
 
        xmlpp::Element* reel_list = root->add_child ("ReelList");
 
index 553f54928795cb40bcfeffe10ce26b8ad337bd2f..70f306bfba4987f415ddb1d57cca5f25f6d3d4b7 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -141,6 +141,14 @@ public:
                return _standard;
        }
 
+       std::list<Rating> ratings () const {
+               return _ratings;
+       }
+
+       void set_ratings (std::list<Rating> r) {
+               _ratings = r;
+       }
+
        static std::string static_pkl_type (Standard standard);
 
 protected:
@@ -157,6 +165,7 @@ private:
        std::string _content_version_id;            ///< &lt;Id&gt; in &lt;ContentVersion&gt;
        std::string _content_version_label_text;    ///< &lt;LabelText&gt; in &lt;ContentVersion&gt;
        std::list<boost::shared_ptr<Reel> > _reels;
+       std::list<Rating> _ratings;
 
        /** Standard of CPL that was read in */
        boost::optional<Standard> _standard;
index d27b2ec186ece6773d0646309040927b2afd0eae..4c53b162722f4cab5b0b76c92580cb33ecb4cfe6 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
@@ -36,6 +36,7 @@
 #include "exceptions.h"
 #include "compose.hpp"
 #include "dcp_assert.h"
+#include <libxml++/libxml++.h>
 #include <boost/algorithm/string.hpp>
 #include <vector>
 #include <cstdio>
@@ -426,3 +427,30 @@ dcp::marker_from_string (string s)
 
        DCP_ASSERT (false);
 }
+
+Rating::Rating (cxml::ConstNodePtr node)
+{
+       agency = node->string_child("Agency");
+       label = node->string_child("Label");
+       node->done ();
+}
+
+void
+Rating::as_xml (xmlpp::Element* parent) const
+{
+       parent->add_child("Agency")->add_child_text(agency);
+       parent->add_child("Label")->add_child_text(label);
+}
+
+bool
+dcp::operator== (Rating const & a, Rating const & b)
+{
+       return a.agency == b.agency && a.label == b.label;
+}
+
+ostream &
+dcp::operator<< (ostream& s, Rating const & r)
+{
+       s << r.agency << " " << r.label;
+       return s;
+}
index a0965e8364790fa6129e1cf4a72588ea6116c18f..7f315e08ca55316c114b2d8dabf97e8be560df13 100644 (file)
 #ifndef LIBDCP_TYPES_H
 #define LIBDCP_TYPES_H
 
+#include <libcxml/cxml.h>
 #include <boost/shared_ptr.hpp>
 #include <boost/function.hpp>
 #include <string>
 
+namespace xmlpp {
+       class Element;
+}
+
 namespace dcp
 {
 
@@ -292,6 +297,27 @@ enum Marker {
 std::string marker_to_string (Marker);
 Marker marker_from_string (std::string);
 
+class Rating
+{
+public:
+       Rating (std::string agency_, std::string label_)
+               : agency (agency_)
+               , label (label_)
+       {}
+
+       explicit Rating (cxml::ConstNodePtr node);
+
+       void as_xml (xmlpp::Element* parent) const;
+
+       /** URI of the agency issuing the rating */
+       std::string agency;
+       /** Rating (e.g. PG, PG-13, 12A etc) */
+       std::string label;
+};
+
+extern bool operator== (Rating const & a, Rating const & b);
+extern std::ostream& operator<< (std::ostream& s, Rating const & r);
+
 }
 
 #endif
index 53d8461714e1d01a3de31320270292d943d905ab..d5412b4d7997ba3d5217571756bf252945a7ab3a 100644 (file)
@@ -67,6 +67,7 @@ def build(bld):
                  colour_test.cc
                  colour_conversion_test.cc
                  cpl_sar_test.cc
+                 cpl_ratings_test.cc
                  dcp_font_test.cc
                  dcp_test.cc
                  dcp_time_test.cc