39 #include <libcxml/cxml.h>
40 #include <boost/algorithm/string.hpp>
45 using boost::algorithm::trim;
46 using boost::optional;
50 static vector<RatingSystem> rating_systems_list;
53 Rating::Rating (cxml::ConstNodePtr node)
54 : agency(node->string_child(
"Agency"))
55 , label(node->string_child(
"Label"))
62 Rating::as_xml (xmlpp::Element* parent)
const
64 cxml::add_text_child(parent,
"Agency",
agency);
65 cxml::add_text_child(parent,
"Label",
label);
79 return rating_systems_list;
84 dcp::load_rating_list(boost::filesystem::path ratings_file)
86 File f(ratings_file,
"r");
88 throw FileError (
"Could not open ratings file", ratings_file, errno);
91 auto get_line_no_throw = [&f, ratings_file]() -> optional<string> {
93 char* r = f.gets(buffer,
sizeof(buffer));
102 auto get_line = [ratings_file, &get_line_no_throw]() {
103 auto line = get_line_no_throw();
105 throw FileError(
"Bad ratings file", ratings_file, -1);
110 optional<string> agency;
116 auto name = get_line();
117 auto country_and_region_names = get_line();
118 auto country_code = get_line();
120 RatingSystem system(*agency, name, country_and_region_names, country_code);
122 auto rating = get_line_no_throw();
127 if (rating->substr(0, 4) ==
"http") {
132 system.ratings.push_back(
dcp::Rating(*agency, *rating));
135 rating_systems_list.push_back(system);
An exception related to a file.
Exceptions thrown by libdcp.
Namespace for everything in libdcp.
Utility methods and classes.