From 3bae1fb76f8d4751ee62717e3f18cee47d1deb90 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 19 Mar 2019 19:47:07 +0000 Subject: [PATCH] Support RatingList. --- src/cpl.cc | 14 +++++++++++--- src/cpl.h | 9 +++++++++ src/types.cc | 30 +++++++++++++++++++++++++++++- src/types.h | 26 ++++++++++++++++++++++++++ test/wscript | 1 + 5 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/cpl.cc b/src/cpl.cc index 0bf15824..11e7e1c7 100644 --- a/src/cpl.cc +++ b/src/cpl.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington + Copyright (C) 2012-2018 Carl Hetherington 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 (f, "ReelList", "Reel"); f.ignore_child ("Issuer"); @@ -156,7 +161,10 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptradd_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"); diff --git a/src/cpl.h b/src/cpl.h index 553f5492..70f306bf 100644 --- a/src/cpl.h +++ b/src/cpl.h @@ -141,6 +141,14 @@ public: return _standard; } + std::list ratings () const { + return _ratings; + } + + void set_ratings (std::list r) { + _ratings = r; + } + static std::string static_pkl_type (Standard standard); protected: @@ -157,6 +165,7 @@ private: std::string _content_version_id; ///< <Id> in <ContentVersion> std::string _content_version_label_text; ///< <LabelText> in <ContentVersion> std::list > _reels; + std::list _ratings; /** Standard of CPL that was read in */ boost::optional _standard; diff --git a/src/types.cc b/src/types.cc index d27b2ec1..4c53b162 100644 --- a/src/types.cc +++ b/src/types.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington + Copyright (C) 2012-2019 Carl Hetherington This file is part of libdcp. @@ -36,6 +36,7 @@ #include "exceptions.h" #include "compose.hpp" #include "dcp_assert.h" +#include #include #include #include @@ -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; +} diff --git a/src/types.h b/src/types.h index a0965e83..7f315e08 100644 --- a/src/types.h +++ b/src/types.h @@ -38,10 +38,15 @@ #ifndef LIBDCP_TYPES_H #define LIBDCP_TYPES_H +#include #include #include #include +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 diff --git a/test/wscript b/test/wscript index 53d84617..d5412b4d 100644 --- a/test/wscript +++ b/test/wscript @@ -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 -- 2.30.2