diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cpl.cc | 14 | ||||
| -rw-r--r-- | src/cpl.h | 9 | ||||
| -rw-r--r-- | src/types.cc | 30 | ||||
| -rw-r--r-- | src/types.h | 26 |
4 files changed, 75 insertions, 4 deletions
@@ -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"); @@ -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; ///< <Id> in <ContentVersion> std::string _content_version_label_text; ///< <LabelText> in <ContentVersion> std::list<boost::shared_ptr<Reel> > _reels; + std::list<Rating> _ratings; /** Standard of CPL that was read in */ boost::optional<Standard> _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 <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; +} 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 <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 |
