diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-01-08 21:56:40 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-01-08 21:56:56 +0100 |
| commit | 444809fb888ed99803f2d19c94d3faef067cf348 (patch) | |
| tree | e221f08bb20af8007b5ae2df028b30c41b36e68e /src | |
| parent | 1776f46fd988b4a61ed9dfa64e5b4dd2196cdd66 (diff) | |
c++ tidying.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/audio_mapping.cc | 34 | ||||
| -rw-r--r-- | src/lib/cinema.cc | 7 | ||||
| -rw-r--r-- | src/lib/colour_conversion.cc | 51 | ||||
| -rw-r--r-- | src/lib/config.cc | 81 | ||||
| -rw-r--r-- | src/lib/content.cc | 23 | ||||
| -rw-r--r-- | src/lib/ffmpeg_content.cc | 82 | ||||
| -rw-r--r-- | src/lib/text_content.cc | 60 | ||||
| -rw-r--r-- | src/lib/text_content.h | 2 |
8 files changed, 166 insertions, 174 deletions
diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index da9f9822e..0f330dc2b 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -155,24 +155,22 @@ AudioMapping::AudioMapping (cxml::ConstNodePtr node, int state_version) if (state_version <= 5) { /* Old-style: on/off mapping */ - list<cxml::NodePtr> const c = node->node_children ("Map"); - for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) { - set ((*i)->number_child<int> ("ContentIndex"), static_cast<dcp::Channel> ((*i)->number_child<int> ("DCP")), 1); + for (auto i: node->node_children ("Map")) { + set (i->number_child<int>("ContentIndex"), static_cast<dcp::Channel>(i->number_child<int>("DCP")), 1); } } else { - list<cxml::NodePtr> const c = node->node_children ("Gain"); - for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) { + for (auto i: node->node_children("Gain")) { if (state_version < 32) { set ( - (*i)->number_attribute<int> ("Content"), - static_cast<dcp::Channel> ((*i)->number_attribute<int> ("DCP")), - raw_convert<float> ((*i)->content ()) + i->number_attribute<int>("Content"), + static_cast<dcp::Channel>(i->number_attribute<int>("DCP")), + raw_convert<float>(i->content()) ); } else { set ( - (*i)->number_attribute<int> ("Input"), - (*i)->number_attribute<int> ("Output"), - raw_convert<float> ((*i)->content ()) + i->number_attribute<int>("Input"), + i->number_attribute<int>("Output"), + raw_convert<float>(i->content()) ); } } @@ -203,7 +201,7 @@ AudioMapping::as_xml (xmlpp::Node* node) const for (int c = 0; c < _input_channels; ++c) { for (int d = 0; d < _output_channels; ++d) { - xmlpp::Element* t = node->add_child ("Gain"); + auto t = node->add_child ("Gain"); t->set_attribute ("Input", raw_convert<string> (c)); t->set_attribute ("Output", raw_convert<string> (d)); t->add_child_text (raw_convert<string> (get (c, d))); @@ -236,9 +234,9 @@ AudioMapping::mapped_output_channels () const list<int> mapped; - for (vector<vector<float> >::const_iterator i = _gain.begin(); i != _gain.end(); ++i) { + for (auto const& i: _gain) { for (auto j: dcp::used_audio_channels()) { - if (abs ((*i)[j]) > minus_96_db) { + if (abs(i[j]) > minus_96_db) { mapped.push_back (j); } } @@ -253,9 +251,9 @@ AudioMapping::mapped_output_channels () const void AudioMapping::unmap_all () { - for (vector<vector<float> >::iterator i = _gain.begin(); i != _gain.end(); ++i) { - for (vector<float>::iterator j = i->begin(); j != i->end(); ++j) { - *j = 0; + for (auto& i: _gain) { + for (auto& j: i) { + j = 0; } } } diff --git a/src/lib/cinema.cc b/src/lib/cinema.cc index 42557efc3..9a3b55e0a 100644 --- a/src/lib/cinema.cc +++ b/src/lib/cinema.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -55,9 +55,8 @@ Cinema::Cinema (cxml::ConstNodePtr node) void Cinema::read_screens (cxml::ConstNodePtr node) { - list<cxml::NodePtr> s = node->node_children ("Screen"); - for (list<cxml::NodePtr>::iterator i = s.begin(); i != s.end(); ++i) { - add_screen (shared_ptr<Screen> (new Screen (*i))); + for (auto i: node->node_children("Screen")) { + add_screen (shared_ptr<Screen>(new Screen(i))); } } diff --git a/src/lib/colour_conversion.cc b/src/lib/colour_conversion.cc index e0158b735..57e73a5b5 100644 --- a/src/lib/colour_conversion.cc +++ b/src/lib/colour_conversion.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -41,6 +41,7 @@ using std::list; using std::string; using std::cout; using std::vector; +using std::make_shared; using std::shared_ptr; using boost::optional; using std::dynamic_pointer_cast; @@ -68,19 +69,19 @@ ColourConversion::ColourConversion (cxml::NodePtr node, int version) /* Version 2.x */ - cxml::ConstNodePtr in_node = node->node_child ("InputTransferFunction"); - string in_type = in_node->string_child ("Type"); + auto in_node = node->node_child ("InputTransferFunction"); + auto in_type = in_node->string_child ("Type"); if (in_type == "Gamma") { - _in.reset (new dcp::GammaTransferFunction (in_node->number_child<double> ("Gamma"))); + _in = make_shared<dcp::GammaTransferFunction>(in_node->number_child<double> ("Gamma")); } else if (in_type == "ModifiedGamma") { - _in.reset (new dcp::ModifiedGammaTransferFunction ( - in_node->number_child<double> ("Power"), - in_node->number_child<double> ("Threshold"), - in_node->number_child<double> ("A"), - in_node->number_child<double> ("B") - )); + _in = make_shared<dcp::ModifiedGammaTransferFunction>( + in_node->number_child<double>("Power"), + in_node->number_child<double>("Threshold"), + in_node->number_child<double>("A"), + in_node->number_child<double>("B") + ); } else if (in_type == "SGamut3") { - _in.reset (new dcp::SGamut3TransferFunction ()); + _in = make_shared<dcp::SGamut3TransferFunction>(); } } else { @@ -96,14 +97,14 @@ ColourConversion::ColourConversion (cxml::NodePtr node, int version) _yuv_to_rgb = static_cast<dcp::YUVToRGB> (node->optional_number_child<int>("YUVToRGB").get_value_or (dcp::YUV_TO_RGB_REC601)); - list<cxml::NodePtr> m = node->node_children ("Matrix"); + auto m = node->node_children ("Matrix"); if (!m.empty ()) { /* Read in old <Matrix> nodes and convert them to chromaticities */ boost::numeric::ublas::matrix<double> C (3, 3); - for (list<cxml::NodePtr>::iterator i = m.begin(); i != m.end(); ++i) { - int const ti = (*i)->number_attribute<int> ("i"); - int const tj = (*i)->number_attribute<int> ("j"); - C(ti, tj) = raw_convert<double> ((*i)->content ()); + for (auto i: m) { + int const ti = i->number_attribute<int>("i"); + int const tj = i->number_attribute<int>("j"); + C(ti, tj) = raw_convert<double>(i->content()); } double const rd = C(0, 0) + C(1, 0) + C(2, 0); @@ -127,11 +128,11 @@ ColourConversion::ColourConversion (cxml::NodePtr node, int version) } } - optional<double> gamma = node->optional_number_child<double> ("OutputGamma"); + auto gamma = node->optional_number_child<double>("OutputGamma"); if (gamma) { - _out.reset (new dcp::GammaTransferFunction (node->number_child<double> ("OutputGamma"))); + _out = make_shared<dcp::GammaTransferFunction>(node->number_child<double>("OutputGamma")); } else { - _out.reset (new dcp::IdentityTransferFunction ()); + _out = make_shared<dcp::IdentityTransferFunction>(); } } @@ -148,13 +149,13 @@ ColourConversion::from_xml (cxml::NodePtr node, int version) void ColourConversion::as_xml (xmlpp::Node* node) const { - xmlpp::Node* in_node = node->add_child ("InputTransferFunction"); + auto in_node = node->add_child ("InputTransferFunction"); if (dynamic_pointer_cast<const dcp::GammaTransferFunction> (_in)) { - shared_ptr<const dcp::GammaTransferFunction> tf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_in); + auto tf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_in); in_node->add_child("Type")->add_child_text ("Gamma"); in_node->add_child("Gamma")->add_child_text (raw_convert<string> (tf->gamma ())); } else if (dynamic_pointer_cast<const dcp::ModifiedGammaTransferFunction> (_in)) { - shared_ptr<const dcp::ModifiedGammaTransferFunction> tf = dynamic_pointer_cast<const dcp::ModifiedGammaTransferFunction> (_in); + auto tf = dynamic_pointer_cast<const dcp::ModifiedGammaTransferFunction> (_in); in_node->add_child("Type")->add_child_text ("ModifiedGamma"); in_node->add_child("Power")->add_child_text (raw_convert<string> (tf->power ())); in_node->add_child("Threshold")->add_child_text (raw_convert<string> (tf->threshold ())); @@ -187,14 +188,14 @@ ColourConversion::as_xml (xmlpp::Node* node) const optional<size_t> ColourConversion::preset () const { - vector<PresetColourConversion> presets = PresetColourConversion::all (); + auto presets = PresetColourConversion::all (); size_t i = 0; while (i < presets.size() && presets[i].conversion != *this) { ++i; } if (i >= presets.size ()) { - return optional<size_t> (); + return {}; } return i; @@ -230,7 +231,7 @@ ColourConversion::identifier () const digester.add (_adjusted_white.get().y); } - shared_ptr<const dcp::GammaTransferFunction> gf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_out); + auto gf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_out); if (gf) { digester.add (gf->gamma ()); } diff --git a/src/lib/config.cc b/src/lib/config.cc index a3eb1b77a..eae57cc06 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -59,6 +59,7 @@ using std::remove; using std::exception; using std::cerr; using std::shared_ptr; +using std::make_shared; using boost::optional; using std::dynamic_pointer_cast; using boost::algorithm::trim; @@ -198,15 +199,13 @@ Config::restore_defaults () shared_ptr<dcp::CertificateChain> Config::create_certificate_chain () { - return shared_ptr<dcp::CertificateChain> ( - new dcp::CertificateChain ( - openssl_path(), - "dcpomatic.com", - "dcpomatic.com", - ".dcpomatic.smpte-430-2.ROOT", - ".dcpomatic.smpte-430-2.INTERMEDIATE", - "CS.dcpomatic.smpte-430-2.LEAF" - ) + return make_shared<dcp::CertificateChain> ( + openssl_path(), + "dcpomatic.com", + "dcpomatic.com", + ".dcpomatic.smpte-430-2.ROOT", + ".dcpomatic.smpte-430-2.INTERMEDIATE", + "CS.dcpomatic.smpte-430-2.LEAF" ); } @@ -233,7 +232,7 @@ try cxml::Document f ("Config"); f.read_file (config_file ()); - optional<int> version = f.optional_number_child<int> ("Version"); + auto version = f.optional_number_child<int> ("Version"); if (version && *version < _current_version) { /* Back up the old config before we re-write it in a back-incompatible way */ backup (); @@ -252,13 +251,13 @@ try _default_directory = boost::optional<boost::filesystem::path> (); } - boost::optional<int> b = f.optional_number_child<int> ("ServerPort"); + auto b = f.optional_number_child<int> ("ServerPort"); if (!b) { b = f.optional_number_child<int> ("ServerPortBase"); } _server_port_base = b.get (); - boost::optional<bool> u = f.optional_bool_child ("UseAnyServers"); + auto u = f.optional_bool_child ("UseAnyServers"); _use_any_servers = u.get_value_or (true); for (auto i: f.node_children("Server")) { @@ -278,7 +277,7 @@ try _language = f.optional_string_child ("Language"); - optional<string> c = f.optional_string_child ("DefaultContainer"); + auto c = f.optional_string_child ("DefaultContainer"); if (c) { _default_container = Ratio::from_id (c.get ()); } @@ -297,7 +296,7 @@ try _dcp_issuer = f.string_child ("DCPIssuer"); } - optional<bool> up = f.optional_bool_child("UploadAfterMakeDCP"); + auto up = f.optional_bool_child("UploadAfterMakeDCP"); if (!up) { up = f.optional_bool_child("DefaultUploadAfterMakeDCP"); } @@ -391,9 +390,9 @@ try _player_history.push_back (i->content ()); } - cxml::NodePtr signer = f.optional_node_child ("Signer"); + auto signer = f.optional_node_child ("Signer"); if (signer) { - shared_ptr<dcp::CertificateChain> c (new dcp::CertificateChain ()); + auto c = make_shared<dcp::CertificateChain>(); /* Read the signing certificates and private key in from the config file */ for (auto i: signer->node_children ("Certificate")) { c->add (dcp::Certificate (i->content ())); @@ -405,9 +404,9 @@ try _signer_chain = create_certificate_chain (); } - cxml::NodePtr decryption = f.optional_node_child ("Decryption"); + auto decryption = f.optional_node_child ("Decryption"); if (decryption) { - shared_ptr<dcp::CertificateChain> c (new dcp::CertificateChain ()); + auto c = make_shared<dcp::CertificateChain>(); for (auto i: decryption->node_children ("Certificate")) { c->add (dcp::Certificate (i->content ())); } @@ -421,7 +420,7 @@ try of the nags. */ for (auto i: f.node_children("Nagged")) { - int const id = i->number_attribute<int>("Id"); + auto const id = i->number_attribute<int>("Id"); if (id >= 0 && id < NAG_COUNT) { _nagged[id] = raw_convert<int>(i->content()); } @@ -444,7 +443,7 @@ try } if (bad) { - optional<bool> const remake = Bad(*bad); + auto const remake = Bad(*bad); if (remake && *remake) { switch (*bad) { case BAD_SIGNER_UTF8_STRINGS: @@ -519,7 +518,7 @@ try _gdc_username = f.optional_string_child("GDCUsername"); _gdc_password = f.optional_string_child("GDCPassword"); - optional<string> pm = f.optional_string_child("PlayerMode"); + auto pm = f.optional_string_child("PlayerMode"); if (pm && *pm == "window") { _player_mode = PLAYER_MODE_WINDOW; } else if (pm && *pm == "full") { @@ -529,7 +528,7 @@ try } _image_display = f.optional_number_child<int>("ImageDisplay").get_value_or(0); - optional<string> vc = f.optional_string_child("VideoViewType"); + auto vc = f.optional_string_child("VideoViewType"); if (vc && *vc == "opengl") { _video_view_type = VIDEO_VIEW_OPENGL; } else if (vc && *vc == "simple") { @@ -601,7 +600,7 @@ void Config::write_config () const { xmlpp::Document doc; - xmlpp::Element* root = doc.create_root_node ("Config"); + auto root = doc.create_root_node ("Config"); /* [XML] Version The version number of the configuration file format. */ root->add_child("Version")->add_child_text (raw_convert<string>(_current_version)); @@ -779,7 +778,7 @@ Config::write_config () const /* [XML] Signer Certificate chain and private key to use when signing DCPs and KDMs. Should contain <code><Certificate></code> tags in order and a <code><PrivateKey></code> tag all containing PEM-encoded certificates or private keys as appropriate. */ - xmlpp::Element* signer = root->add_child ("Signer"); + auto signer = root->add_child ("Signer"); DCPOMATIC_ASSERT (_signer_chain); for (auto const& i: _signer_chain->unordered()) { signer->add_child("Certificate")->add_child_text (i.certificate (true)); @@ -787,7 +786,7 @@ Config::write_config () const signer->add_child("PrivateKey")->add_child_text (_signer_chain->key().get ()); /* [XML] Decryption Certificate chain and private key to use when decrypting KDMs */ - xmlpp::Element* decryption = root->add_child ("Decryption"); + auto decryption = root->add_child ("Decryption"); DCPOMATIC_ASSERT (_decryption_chain); for (auto const& i: _decryption_chain->unordered()) { decryption->add_child("Certificate")->add_child_text (i.certificate (true)); @@ -975,9 +974,9 @@ Config::write_config () const } try { - string const s = doc.write_to_string_formatted (); + auto const s = doc.write_to_string_formatted (); boost::filesystem::path tmp (string(config_file().string()).append(".tmp")); - FILE* f = fopen_boost (tmp, "w"); + auto f = fopen_boost (tmp, "w"); if (!f) { throw FileError (_("Could not open file for writing"), tmp); } @@ -995,10 +994,10 @@ Config::write_config () const template <class T> void -write_file (string root_node, string node, string version, list<shared_ptr<T> > things, boost::filesystem::path file) +write_file (string root_node, string node, string version, list<shared_ptr<T>> things, boost::filesystem::path file) { xmlpp::Document doc; - xmlpp::Element* root = doc.create_root_node (root_node); + auto root = doc.create_root_node (root_node); root->add_child("Version")->add_child_text(version); for (auto i: things) { @@ -1051,7 +1050,7 @@ Config::directory_or (optional<boost::filesystem::path> dir, boost::filesystem:: } boost::system::error_code ec; - bool const e = boost::filesystem::exists (*dir, ec); + auto const e = boost::filesystem::exists (*dir, ec); if (ec || !e) { return a; } @@ -1169,7 +1168,7 @@ Config::add_to_history_internal (vector<boost::filesystem::path>& h, boost::file void Config::clean_history_internal (vector<boost::filesystem::path>& h) { - vector<boost::filesystem::path> old = h; + auto old = h; h.clear (); for (auto i: old) { try { @@ -1192,12 +1191,11 @@ void Config::read_cinemas (cxml::Document const & f) { _cinemas.clear (); - list<cxml::NodePtr> cin = f.node_children ("Cinema"); for (auto i: f.node_children("Cinema")) { /* Slightly grotty two-part construction of Cinema here so that we can use shared_from_this. */ - shared_ptr<Cinema> cinema (new Cinema (i)); + auto cinema = make_shared<Cinema>(i); cinema->read_screens (i); _cinemas.push_back (cinema); } @@ -1227,7 +1225,6 @@ void Config::read_dkdm_recipients (cxml::Document const & f) { _dkdm_recipients.clear (); - list<cxml::NodePtr> cin = f.node_children ("DKDMRecipient"); for (auto i: f.node_children("DKDMRecipient")) { _dkdm_recipients.push_back (shared_ptr<DKDMRecipient>(new DKDMRecipient(i))); } @@ -1263,12 +1260,12 @@ list<string> Config::templates () const { if (!boost::filesystem::exists (path ("templates"))) { - return list<string> (); + return {}; } list<string> n; - for (boost::filesystem::directory_iterator i (path("templates")); i != boost::filesystem::directory_iterator(); ++i) { - n.push_back (i->path().filename().string()); + for (auto const& i: boost::filesystem::directory_iterator(path("templates"))) { + n.push_back (i.path().filename().string()); } return n; } @@ -1302,7 +1299,7 @@ boost::filesystem::path Config::config_file () { cxml::Document f ("Config"); - boost::filesystem::path main = path("config.xml", false); + auto main = path("config.xml", false); if (!boost::filesystem::exists (main)) { /* It doesn't exist, so there can't be any links; just return it */ return main; @@ -1311,7 +1308,7 @@ Config::config_file () /* See if there's a link */ try { f.read_file (main); - optional<string> link = f.optional_string_child("Link"); + auto link = f.optional_string_child("Link"); if (link) { return *link; } @@ -1356,7 +1353,7 @@ Config::copy_and_link (boost::filesystem::path new_file) const bool Config::have_write_permission () const { - FILE* f = fopen_boost (config_file(), "r+"); + auto f = fopen_boost (config_file(), "r+"); if (!f) { return false; } @@ -1409,7 +1406,7 @@ void Config::set_audio_mapping_to_default () { DCPOMATIC_ASSERT (_audio_mapping); - int const ch = _audio_mapping->output_channels (); + auto const ch = _audio_mapping->output_channels (); _audio_mapping = boost::none; _audio_mapping = audio_mapping (ch); changed (AUDIO_MAPPING); diff --git a/src/lib/content.cc b/src/lib/content.cc index 5fb9d324a..d4dffe777 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -91,10 +91,9 @@ Content::Content (boost::filesystem::path p) Content::Content (cxml::ConstNodePtr node) : _change_signals_frequent (false) { - list<cxml::NodePtr> path_children = node->node_children ("Path"); - for (auto i: path_children) { + for (auto i: node->node_children("Path")) { _paths.push_back (i->content()); - optional<time_t> const mod = i->optional_number_attribute<time_t>("mtime"); + auto const mod = i->optional_number_attribute<time_t>("mtime"); if (mod) { _last_write_times.push_back (*mod); } else if (boost::filesystem::exists(i->content())) { @@ -169,7 +168,7 @@ string Content::calculate_digest () const { boost::mutex::scoped_lock lm (_mutex); - vector<boost::filesystem::path> p = _paths; + auto p = _paths; lm.unlock (); /* Some content files are very big, so we use a poor man's @@ -186,7 +185,7 @@ Content::examine (shared_ptr<const Film>, shared_ptr<Job> job) job->sub (_("Computing digest")); } - string const d = calculate_digest (); + auto const d = calculate_digest (); boost::mutex::scoped_lock lm (_mutex); _digest = d; @@ -282,7 +281,7 @@ Content::clone () const { /* This is a bit naughty, but I can't think of a compelling reason not to do it ... */ xmlpp::Document doc; - xmlpp::Node* node = doc.create_root_node ("Content"); + auto node = doc.create_root_node ("Content"); as_xml (node, true); /* notes is unused here (we assume) */ @@ -293,7 +292,7 @@ Content::clone () const string Content::technical_summary () const { - string s = String::compose ("%1 %2 %3", path_summary(), digest(), position().seconds()); + auto s = String::compose ("%1 %2 %3", path_summary(), digest(), position().seconds()); if (_video_frame_rate) { s += String::compose(" %1", *_video_frame_rate); } @@ -303,7 +302,7 @@ Content::technical_summary () const DCPTime Content::length_after_trim (shared_ptr<const Film> film) const { - DCPTime length = max(DCPTime(), full_length(film) - DCPTime(trim_start() + trim_end(), film->active_frame_rate_change(position()))); + auto length = max(DCPTime(), full_length(film) - DCPTime(trim_start() + trim_end(), film->active_frame_rate_change(position()))); if (video) { length = length.round(film->video_frame_rate()); } @@ -358,7 +357,7 @@ Content::path_summary () const DCPOMATIC_ASSERT (number_of_paths ()); - string s = path(0).filename().string (); + auto s = path(0).filename().string(); if (number_of_paths() > 1) { s += " ..."; } @@ -473,8 +472,8 @@ Content::take_settings_from (shared_ptr<const Content> c) audio->take_settings_from (c->audio); } - list<shared_ptr<TextContent> >::iterator i = text.begin (); - list<shared_ptr<TextContent> >::const_iterator j = c->text.begin (); + auto i = text.begin (); + auto j = c->text.begin (); while (i != text.end() && j != c->text.end()) { (*i)->take_settings_from (*j); ++i; diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 234c792fd..2c42cf579 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -52,6 +52,7 @@ using std::cout; using std::pair; using std::make_pair; using std::max; +using std::make_shared; using std::shared_ptr; using std::dynamic_pointer_cast; using boost::optional; @@ -73,7 +74,7 @@ template <class T> optional<T> get_optional_enum (cxml::ConstNodePtr node, string name) { - optional<int> const v = node->optional_number_child<int>(name); + auto const v = node->optional_number_child<int>(name); if (!v) { return optional<T>(); } @@ -87,35 +88,32 @@ FFmpegContent::FFmpegContent (cxml::ConstNodePtr node, int version, list<string> audio = AudioContent::from_xml (this, node, version); text = TextContent::from_xml (this, node, version); - list<cxml::NodePtr> c = node->node_children ("SubtitleStream"); - for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) { - _subtitle_streams.push_back (shared_ptr<FFmpegSubtitleStream> (new FFmpegSubtitleStream (*i, version))); - if ((*i)->optional_number_child<int> ("Selected")) { + for (auto i: node->node_children("SubtitleStream")) { + _subtitle_streams.push_back (make_shared<FFmpegSubtitleStream>(i, version)); + if (i->optional_number_child<int>("Selected")) { _subtitle_stream = _subtitle_streams.back (); } } - c = node->node_children ("AudioStream"); - for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) { - shared_ptr<FFmpegAudioStream> as (new FFmpegAudioStream (*i, version)); + for (auto i: node->node_children("AudioStream")) { + auto as = make_shared<FFmpegAudioStream>(i, version); audio->add_stream (as); - if (version < 11 && !(*i)->optional_node_child ("Selected")) { + if (version < 11 && !i->optional_node_child ("Selected")) { /* This is an old file and this stream is not selected, so un-map it */ as->set_mapping (AudioMapping (as->channels (), MAX_DCP_AUDIO_CHANNELS)); } } - c = node->node_children ("Filter"); - for (list<cxml::NodePtr>::iterator i = c.begin(); i != c.end(); ++i) { - Filter const * f = Filter::from_id ((*i)->content ()); + for (auto i: node->node_children("Filter")) { + Filter const * f = Filter::from_id(i->content()); if (f) { _filters.push_back (f); } else { - notes.push_back (String::compose (_("DCP-o-matic no longer supports the `%1' filter, so it has been turned off."), (*i)->content())); + notes.push_back (String::compose (_("DCP-o-matic no longer supports the `%1' filter, so it has been turned off."), i->content())); } } - optional<ContentTime::Type> const f = node->optional_number_child<ContentTime::Type> ("FirstVideo"); + auto const f = node->optional_number_child<ContentTime::Type> ("FirstVideo"); if (f) { _first_video = ContentTime (f.get ()); } @@ -130,7 +128,7 @@ FFmpegContent::FFmpegContent (cxml::ConstNodePtr node, int version, list<string> FFmpegContent::FFmpegContent (vector<shared_ptr<Content> > c) : Content (c) { - vector<shared_ptr<Content> >::const_iterator i = c.begin (); + auto i = c.begin (); bool need_video = false; bool need_audio = false; @@ -156,20 +154,20 @@ FFmpegContent::FFmpegContent (vector<shared_ptr<Content> > c) } if (need_video) { - video.reset (new VideoContent (this, c)); + video = make_shared<VideoContent>(this, c); } if (need_audio) { - audio.reset (new AudioContent (this, c)); + audio = make_shared<AudioContent>(this, c); } if (need_text) { - text.push_back (shared_ptr<TextContent> (new TextContent (this, c))); + text.push_back (make_shared<TextContent>(this, c)); } - shared_ptr<FFmpegContent> ref = dynamic_pointer_cast<FFmpegContent> (c[0]); + auto ref = dynamic_pointer_cast<FFmpegContent> (c[0]); DCPOMATIC_ASSERT (ref); for (size_t i = 0; i < c.size(); ++i) { - shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c[i]); + auto fc = dynamic_pointer_cast<FFmpegContent>(c[i]); if (fc->only_text() && fc->only_text()->use() && *(fc->_subtitle_stream.get()) != *(ref->_subtitle_stream.get())) { throw JoinError (_("Content to be joined must use the same subtitle stream.")); } @@ -202,7 +200,7 @@ FFmpegContent::as_xml (xmlpp::Node* node, bool with_paths) const audio->as_xml (node); for (auto i: audio->streams ()) { - shared_ptr<FFmpegAudioStream> f = dynamic_pointer_cast<FFmpegAudioStream> (i); + auto f = dynamic_pointer_cast<FFmpegAudioStream> (i); DCPOMATIC_ASSERT (f); f->as_xml (node->add_child("AudioStream")); } @@ -214,16 +212,16 @@ FFmpegContent::as_xml (xmlpp::Node* node, bool with_paths) const boost::mutex::scoped_lock lm (_mutex); - for (vector<shared_ptr<FFmpegSubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) { - xmlpp::Node* t = node->add_child("SubtitleStream"); - if (_subtitle_stream && *i == _subtitle_stream) { + for (auto i: _subtitle_streams) { + auto t = node->add_child("SubtitleStream"); + if (_subtitle_stream && i == _subtitle_stream) { t->add_child("Selected")->add_child_text("1"); } - (*i)->as_xml (t); + i->as_xml (t); } - for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) { - node->add_child("Filter")->add_child_text ((*i)->id ()); + for (auto i: _filters) { + node->add_child("Filter")->add_child_text(i->id()); } if (_first_video) { @@ -259,14 +257,14 @@ FFmpegContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job) Content::examine (film, job); - shared_ptr<FFmpegExaminer> examiner (new FFmpegExaminer (shared_from_this (), job)); + auto examiner = make_shared<FFmpegExaminer>(shared_from_this (), job); if (examiner->has_video ()) { video.reset (new VideoContent (this)); video->take_from_examiner (examiner); } - boost::filesystem::path first_path = path (0); + auto first_path = path (0); { boost::mutex::scoped_lock lm (_mutex); @@ -280,7 +278,7 @@ FFmpegContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job) _bits_per_pixel = examiner->bits_per_pixel (); if (examiner->rotation()) { - double rot = *examiner->rotation (); + auto rot = *examiner->rotation (); if (fabs (rot - 180) < 1.0) { _filters.push_back (Filter::from_id ("vflip")); _filters.push_back (Filter::from_id ("hflip")); @@ -293,14 +291,14 @@ FFmpegContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job) } if (!examiner->audio_streams().empty ()) { - audio.reset (new AudioContent (this)); + audio = make_shared<AudioContent>(this); - for (auto i: examiner->audio_streams ()) { + for (auto i: examiner->audio_streams()) { audio->add_stream (i); } - AudioStreamPtr as = audio->streams().front(); - AudioMapping m = as->mapping (); + auto as = audio->streams().front(); + auto m = as->mapping (); m.make_default (film ? film->audio_processor() : 0, first_path); as->set_mapping (m); } @@ -308,7 +306,7 @@ FFmpegContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job) _subtitle_streams = examiner->subtitle_streams (); if (!_subtitle_streams.empty ()) { text.clear (); - text.push_back (shared_ptr<TextContent> (new TextContent (this, TEXT_OPEN_SUBTITLE, TEXT_UNKNOWN))); + text.push_back (make_shared<TextContent>(this, TEXT_OPEN_SUBTITLE, TEXT_UNKNOWN)); _subtitle_stream = _subtitle_streams.front (); } } @@ -357,9 +355,9 @@ FFmpegContent::technical_summary () const ss = _subtitle_stream->technical_summary (); } - string filt = Filter::ffmpeg_string (_filters); + auto filt = Filter::ffmpeg_string (_filters); - string s = Content::technical_summary (); + auto s = Content::technical_summary (); if (video) { s += " - " + video->technical_summary (); @@ -465,8 +463,8 @@ FFmpegContent::identifier () const s += "_" + _subtitle_stream->identifier (); } - for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) { - s += "_" + (*i)->id (); + for (auto i: _filters) { + s += "_" + i->id(); } return s; @@ -477,7 +475,7 @@ FFmpegContent::set_default_colour_conversion () { DCPOMATIC_ASSERT (video); - dcp::Size const s = video->size (); + auto const s = video->size (); boost::mutex::scoped_lock lm (_mutex); @@ -680,7 +678,7 @@ FFmpegContent::ffmpeg_audio_streams () const void FFmpegContent::take_settings_from (shared_ptr<const Content> c) { - shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (c); + auto fc = dynamic_pointer_cast<const FFmpegContent> (c); if (!fc) { return; } diff --git a/src/lib/text_content.cc b/src/lib/text_content.cc index 2f01bb2fa..a9ed86083 100644 --- a/src/lib/text_content.cc +++ b/src/lib/text_content.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -35,6 +35,7 @@ using std::vector; using std::cout; using std::list; using std::shared_ptr; +using std::make_shared; using std::dynamic_pointer_cast; using boost::optional; using dcp::raw_convert; @@ -76,7 +77,7 @@ TextContent::TextContent (Content* parent, TextType type, TextType original_type /** @return TextContents from node or <Text> nodes under node (according to version). * The list could be empty if no TextContents are found. */ -list<shared_ptr<TextContent> > +list<shared_ptr<TextContent>> TextContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version) { if (version < 34) { @@ -84,7 +85,7 @@ TextContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version) subtitle streams, so check for that. */ if (node->string_child("Type") == "FFmpeg" && node->node_children("SubtitleStream").empty()) { - return list<shared_ptr<TextContent> >(); + return {}; } /* Otherwise we can drop through to the newer logic */ @@ -92,20 +93,20 @@ TextContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version) if (version < 37) { if (!node->optional_number_child<double>("SubtitleXOffset") && !node->optional_number_child<double>("SubtitleOffset")) { - return list<shared_ptr<TextContent> >(); + return {}; } - list<shared_ptr<TextContent> > c; - c.push_back (shared_ptr<TextContent> (new TextContent (parent, node, version))); + list<shared_ptr<TextContent>> c; + c.push_back (make_shared<TextContent>(parent, node, version)); return c; } if (!node->optional_node_child("Text")) { - return list<shared_ptr<TextContent> >(); + return {}; } - list<shared_ptr<TextContent> > c; + list<shared_ptr<TextContent>> c; for (auto i: node->node_children("Text")) { - c.push_back (shared_ptr<TextContent> (new TextContent (parent, i, version))); + c.push_back (make_shared<TextContent>(parent, i, version)); } return c; @@ -150,7 +151,7 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version) _effect = dcp::NONE; } - optional<string> effect = node->optional_string_child("Effect"); + auto effect = node->optional_string_child("Effect"); if (effect) { if (*effect == "none") { _effect = dcp::NONE; @@ -171,17 +172,17 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version) _x_scale = _y_scale = node->number_child<double> ("SubtitleScale"); } - optional<int> r = node->optional_number_child<int>("Red"); - optional<int> g = node->optional_number_child<int>("Green"); - optional<int> b = node->optional_number_child<int>("Blue"); + auto r = node->optional_number_child<int>("Red"); + auto g = node->optional_number_child<int>("Green"); + auto b = node->optional_number_child<int>("Blue"); if (r && g && b) { _colour = dcp::Colour (*r, *g, *b); } if (version >= 36) { - optional<int> er = node->optional_number_child<int>("EffectRed"); - optional<int> eg = node->optional_number_child<int>("EffectGreen"); - optional<int> eb = node->optional_number_child<int>("EffectBlue"); + auto er = node->optional_number_child<int>("EffectRed"); + auto eg = node->optional_number_child<int>("EffectGreen"); + auto eb = node->optional_number_child<int>("EffectBlue"); if (er && eg && eb) { _effect_colour = dcp::Colour (*er, *eg, *eb); } @@ -213,9 +214,8 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version) _fade_out = ContentTime (*fo); } - list<cxml::NodePtr> fonts = node->node_children ("Font"); - for (list<cxml::NodePtr>::const_iterator i = fonts.begin(); i != fonts.end(); ++i) { - _fonts.push_back (shared_ptr<Font> (new Font (*i))); + for (auto i: node->node_children ("Font")) { + _fonts.push_back (make_shared<Font>(i)); } connect_to_fonts (); @@ -227,21 +227,21 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version) } } - cxml::ConstNodePtr dt = node->optional_node_child("DCPTrack"); + auto dt = node->optional_node_child("DCPTrack"); if (dt) { _dcp_track = DCPTextTrack (dt); } } -TextContent::TextContent (Content* parent, vector<shared_ptr<Content> > c) +TextContent::TextContent (Content* parent, vector<shared_ptr<Content>> c) : ContentPart (parent) { /* This constructor is for join which is only supported for content types that have a single text, so we can use only_text() here. */ - shared_ptr<TextContent> ref = c[0]->only_text(); + auto ref = c[0]->only_text(); DCPOMATIC_ASSERT (ref); - list<shared_ptr<Font> > ref_fonts = ref->fonts (); + auto ref_fonts = ref->fonts (); for (size_t i = 1; i < c.size(); ++i) { @@ -281,7 +281,7 @@ TextContent::TextContent (Content* parent, vector<shared_ptr<Content> > c) throw JoinError (_("Content to be joined must have the same outline width.")); } - list<shared_ptr<Font> > fonts = c[i]->only_text()->fonts (); + auto fonts = c[i]->only_text()->fonts (); if (fonts.size() != ref_fonts.size()) { throw JoinError (_("Content to be joined must use the same fonts.")); } @@ -290,8 +290,8 @@ TextContent::TextContent (Content* parent, vector<shared_ptr<Content> > c) throw JoinError (_("Content to be joined must use the same DCP track.")); } - list<shared_ptr<Font> >::const_iterator j = ref_fonts.begin (); - list<shared_ptr<Font> >::const_iterator k = fonts.begin (); + auto j = ref_fonts.begin (); + auto k = fonts.begin (); while (j != ref_fonts.end ()) { if (**j != **k) { @@ -326,7 +326,7 @@ TextContent::as_xml (xmlpp::Node* root) const { boost::mutex::scoped_lock lm (_mutex); - xmlpp::Element* text = root->add_child ("Text"); + auto text = root->add_child ("Text"); text->add_child("Use")->add_child_text (_use ? "1" : "0"); text->add_child("Burn")->add_child_text (_burn ? "1" : "0"); @@ -366,8 +366,8 @@ TextContent::as_xml (xmlpp::Node* root) const } text->add_child("OutlineWidth")->add_child_text (raw_convert<string> (_outline_width)); - for (list<shared_ptr<Font> >::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { - (*i)->as_xml (text->add_child("Font")); + for (auto i: _fonts) { + i->as_xml (text->add_child("Font")); } text->add_child("Type")->add_child_text (text_type_to_string(_type)); @@ -380,7 +380,7 @@ TextContent::as_xml (xmlpp::Node* root) const string TextContent::identifier () const { - string s = raw_convert<string> (x_scale()) + auto s = raw_convert<string> (x_scale()) + "_" + raw_convert<string> (y_scale()) + "_" + raw_convert<string> (x_offset()) + "_" + raw_convert<string> (y_offset()) diff --git a/src/lib/text_content.h b/src/lib/text_content.h index 21d09ad12..e566d0552 100644 --- a/src/lib/text_content.h +++ b/src/lib/text_content.h @@ -63,6 +63,7 @@ class TextContent : public ContentPart public: TextContent (Content* parent, TextType type, TextType original_type); TextContent (Content* parent, std::vector<std::shared_ptr<Content> >); + TextContent (Content* parent, cxml::ConstNodePtr, int version); void as_xml (xmlpp::Node *) const; std::string identifier () const; @@ -182,7 +183,6 @@ public: private: friend struct ffmpeg_pts_offset_test; - TextContent (Content* parent, cxml::ConstNodePtr, int version); void font_changed (); void connect_to_fonts (); |
