From: Carl Hetherington Date: Fri, 8 Jan 2021 20:56:40 +0000 (+0100) Subject: c++ tidying. X-Git-Tag: v2.15.121~19 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=444809fb888ed99803f2d19c94d3faef067cf348 c++ tidying. --- 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 + Copyright (C) 2013-2021 Carl Hetherington 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 const c = node->node_children ("Map"); - for (list::const_iterator i = c.begin(); i != c.end(); ++i) { - set ((*i)->number_child ("ContentIndex"), static_cast ((*i)->number_child ("DCP")), 1); + for (auto i: node->node_children ("Map")) { + set (i->number_child("ContentIndex"), static_cast(i->number_child("DCP")), 1); } } else { - list const c = node->node_children ("Gain"); - for (list::const_iterator i = c.begin(); i != c.end(); ++i) { + for (auto i: node->node_children("Gain")) { if (state_version < 32) { set ( - (*i)->number_attribute ("Content"), - static_cast ((*i)->number_attribute ("DCP")), - raw_convert ((*i)->content ()) + i->number_attribute("Content"), + static_cast(i->number_attribute("DCP")), + raw_convert(i->content()) ); } else { set ( - (*i)->number_attribute ("Input"), - (*i)->number_attribute ("Output"), - raw_convert ((*i)->content ()) + i->number_attribute("Input"), + i->number_attribute("Output"), + raw_convert(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 (c)); t->set_attribute ("Output", raw_convert (d)); t->add_child_text (raw_convert (get (c, d))); @@ -236,9 +234,9 @@ AudioMapping::mapped_output_channels () const list mapped; - for (vector >::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 >::iterator i = _gain.begin(); i != _gain.end(); ++i) { - for (vector::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 + Copyright (C) 2013-2021 Carl Hetherington 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 s = node->node_children ("Screen"); - for (list::iterator i = s.begin(); i != s.end(); ++i) { - add_screen (shared_ptr (new Screen (*i))); + for (auto i: node->node_children("Screen")) { + add_screen (shared_ptr(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 + Copyright (C) 2013-2021 Carl Hetherington 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 ("Gamma"))); + _in = make_shared(in_node->number_child ("Gamma")); } else if (in_type == "ModifiedGamma") { - _in.reset (new dcp::ModifiedGammaTransferFunction ( - in_node->number_child ("Power"), - in_node->number_child ("Threshold"), - in_node->number_child ("A"), - in_node->number_child ("B") - )); + _in = make_shared( + in_node->number_child("Power"), + in_node->number_child("Threshold"), + in_node->number_child("A"), + in_node->number_child("B") + ); } else if (in_type == "SGamut3") { - _in.reset (new dcp::SGamut3TransferFunction ()); + _in = make_shared(); } } else { @@ -96,14 +97,14 @@ ColourConversion::ColourConversion (cxml::NodePtr node, int version) _yuv_to_rgb = static_cast (node->optional_number_child("YUVToRGB").get_value_or (dcp::YUV_TO_RGB_REC601)); - list m = node->node_children ("Matrix"); + auto m = node->node_children ("Matrix"); if (!m.empty ()) { /* Read in old nodes and convert them to chromaticities */ boost::numeric::ublas::matrix C (3, 3); - for (list::iterator i = m.begin(); i != m.end(); ++i) { - int const ti = (*i)->number_attribute ("i"); - int const tj = (*i)->number_attribute ("j"); - C(ti, tj) = raw_convert ((*i)->content ()); + for (auto i: m) { + int const ti = i->number_attribute("i"); + int const tj = i->number_attribute("j"); + C(ti, tj) = raw_convert(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 gamma = node->optional_number_child ("OutputGamma"); + auto gamma = node->optional_number_child("OutputGamma"); if (gamma) { - _out.reset (new dcp::GammaTransferFunction (node->number_child ("OutputGamma"))); + _out = make_shared(node->number_child("OutputGamma")); } else { - _out.reset (new dcp::IdentityTransferFunction ()); + _out = make_shared(); } } @@ -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 (_in)) { - shared_ptr tf = dynamic_pointer_cast (_in); + auto tf = dynamic_pointer_cast (_in); in_node->add_child("Type")->add_child_text ("Gamma"); in_node->add_child("Gamma")->add_child_text (raw_convert (tf->gamma ())); } else if (dynamic_pointer_cast (_in)) { - shared_ptr tf = dynamic_pointer_cast (_in); + auto tf = dynamic_pointer_cast (_in); in_node->add_child("Type")->add_child_text ("ModifiedGamma"); in_node->add_child("Power")->add_child_text (raw_convert (tf->power ())); in_node->add_child("Threshold")->add_child_text (raw_convert (tf->threshold ())); @@ -187,14 +188,14 @@ ColourConversion::as_xml (xmlpp::Node* node) const optional ColourConversion::preset () const { - vector 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 (); + return {}; } return i; @@ -230,7 +231,7 @@ ColourConversion::identifier () const digester.add (_adjusted_white.get().y); } - shared_ptr gf = dynamic_pointer_cast (_out); + auto gf = dynamic_pointer_cast (_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 + Copyright (C) 2012-2021 Carl Hetherington 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 Config::create_certificate_chain () { - return shared_ptr ( - 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 ( + 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 version = f.optional_number_child ("Version"); + auto version = f.optional_number_child ("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::optional b = f.optional_number_child ("ServerPort"); + auto b = f.optional_number_child ("ServerPort"); if (!b) { b = f.optional_number_child ("ServerPortBase"); } _server_port_base = b.get (); - boost::optional 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 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 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 c (new dcp::CertificateChain ()); + auto c = make_shared(); /* 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 c (new dcp::CertificateChain ()); + auto c = make_shared(); 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("Id"); + auto const id = i->number_attribute("Id"); if (id >= 0 && id < NAG_COUNT) { _nagged[id] = raw_convert(i->content()); } @@ -444,7 +443,7 @@ try } if (bad) { - optional 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 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("ImageDisplay").get_value_or(0); - optional 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(_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 <Certificate> tags in order and a <PrivateKey> 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 void -write_file (string root_node, string node, string version, list > things, boost::filesystem::path file) +write_file (string root_node, string node, string version, list> 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 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& h, boost::file void Config::clean_history_internal (vector& h) { - vector 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 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 (new Cinema (i)); + auto cinema = make_shared(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 cin = f.node_children ("DKDMRecipient"); for (auto i: f.node_children("DKDMRecipient")) { _dkdm_recipients.push_back (shared_ptr(new DKDMRecipient(i))); } @@ -1263,12 +1260,12 @@ list Config::templates () const { if (!boost::filesystem::exists (path ("templates"))) { - return list (); + return {}; } list 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 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 + Copyright (C) 2013-2021 Carl Hetherington 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 path_children = node->node_children ("Path"); - for (auto i: path_children) { + for (auto i: node->node_children("Path")) { _paths.push_back (i->content()); - optional const mod = i->optional_number_attribute("mtime"); + auto const mod = i->optional_number_attribute("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 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, shared_ptr 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 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 c) audio->take_settings_from (c->audio); } - list >::iterator i = text.begin (); - list >::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 + Copyright (C) 2013-2021 Carl Hetherington 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 optional get_optional_enum (cxml::ConstNodePtr node, string name) { - optional const v = node->optional_number_child(name); + auto const v = node->optional_number_child(name); if (!v) { return optional(); } @@ -87,35 +88,32 @@ FFmpegContent::FFmpegContent (cxml::ConstNodePtr node, int version, list audio = AudioContent::from_xml (this, node, version); text = TextContent::from_xml (this, node, version); - list c = node->node_children ("SubtitleStream"); - for (list::const_iterator i = c.begin(); i != c.end(); ++i) { - _subtitle_streams.push_back (shared_ptr (new FFmpegSubtitleStream (*i, version))); - if ((*i)->optional_number_child ("Selected")) { + for (auto i: node->node_children("SubtitleStream")) { + _subtitle_streams.push_back (make_shared(i, version)); + if (i->optional_number_child("Selected")) { _subtitle_stream = _subtitle_streams.back (); } } - c = node->node_children ("AudioStream"); - for (list::const_iterator i = c.begin(); i != c.end(); ++i) { - shared_ptr as (new FFmpegAudioStream (*i, version)); + for (auto i: node->node_children("AudioStream")) { + auto as = make_shared(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::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 const f = node->optional_number_child ("FirstVideo"); + auto const f = node->optional_number_child ("FirstVideo"); if (f) { _first_video = ContentTime (f.get ()); } @@ -130,7 +128,7 @@ FFmpegContent::FFmpegContent (cxml::ConstNodePtr node, int version, list FFmpegContent::FFmpegContent (vector > c) : Content (c) { - vector >::const_iterator i = c.begin (); + auto i = c.begin (); bool need_video = false; bool need_audio = false; @@ -156,20 +154,20 @@ FFmpegContent::FFmpegContent (vector > c) } if (need_video) { - video.reset (new VideoContent (this, c)); + video = make_shared(this, c); } if (need_audio) { - audio.reset (new AudioContent (this, c)); + audio = make_shared(this, c); } if (need_text) { - text.push_back (shared_ptr (new TextContent (this, c))); + text.push_back (make_shared(this, c)); } - shared_ptr ref = dynamic_pointer_cast (c[0]); + auto ref = dynamic_pointer_cast (c[0]); DCPOMATIC_ASSERT (ref); for (size_t i = 0; i < c.size(); ++i) { - shared_ptr fc = dynamic_pointer_cast (c[i]); + auto fc = dynamic_pointer_cast(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 f = dynamic_pointer_cast (i); + auto f = dynamic_pointer_cast (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 >::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::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 film, shared_ptr job) Content::examine (film, job); - shared_ptr examiner (new FFmpegExaminer (shared_from_this (), job)); + auto examiner = make_shared(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 film, shared_ptr 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 film, shared_ptr job) } if (!examiner->audio_streams().empty ()) { - audio.reset (new AudioContent (this)); + audio = make_shared(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 film, shared_ptr job) _subtitle_streams = examiner->subtitle_streams (); if (!_subtitle_streams.empty ()) { text.clear (); - text.push_back (shared_ptr (new TextContent (this, TEXT_OPEN_SUBTITLE, TEXT_UNKNOWN))); + text.push_back (make_shared(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::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 c) { - shared_ptr fc = dynamic_pointer_cast (c); + auto fc = dynamic_pointer_cast (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 + Copyright (C) 2013-2021 Carl Hetherington 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 nodes under node (according to version). * The list could be empty if no TextContents are found. */ -list > +list> 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 >(); + 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("SubtitleXOffset") && !node->optional_number_child("SubtitleOffset")) { - return list >(); + return {}; } - list > c; - c.push_back (shared_ptr (new TextContent (parent, node, version))); + list> c; + c.push_back (make_shared(parent, node, version)); return c; } if (!node->optional_node_child("Text")) { - return list >(); + return {}; } - list > c; + list> c; for (auto i: node->node_children("Text")) { - c.push_back (shared_ptr (new TextContent (parent, i, version))); + c.push_back (make_shared(parent, i, version)); } return c; @@ -150,7 +151,7 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version) _effect = dcp::NONE; } - optional 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 ("SubtitleScale"); } - optional r = node->optional_number_child("Red"); - optional g = node->optional_number_child("Green"); - optional b = node->optional_number_child("Blue"); + auto r = node->optional_number_child("Red"); + auto g = node->optional_number_child("Green"); + auto b = node->optional_number_child("Blue"); if (r && g && b) { _colour = dcp::Colour (*r, *g, *b); } if (version >= 36) { - optional er = node->optional_number_child("EffectRed"); - optional eg = node->optional_number_child("EffectGreen"); - optional eb = node->optional_number_child("EffectBlue"); + auto er = node->optional_number_child("EffectRed"); + auto eg = node->optional_number_child("EffectGreen"); + auto eb = node->optional_number_child("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 fonts = node->node_children ("Font"); - for (list::const_iterator i = fonts.begin(); i != fonts.end(); ++i) { - _fonts.push_back (shared_ptr (new Font (*i))); + for (auto i: node->node_children ("Font")) { + _fonts.push_back (make_shared(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 > c) +TextContent::TextContent (Content* parent, vector> 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 ref = c[0]->only_text(); + auto ref = c[0]->only_text(); DCPOMATIC_ASSERT (ref); - list > 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 > c) throw JoinError (_("Content to be joined must have the same outline width.")); } - list > 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 > c) throw JoinError (_("Content to be joined must use the same DCP track.")); } - list >::const_iterator j = ref_fonts.begin (); - list >::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 (_outline_width)); - for (list >::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 (x_scale()) + auto s = raw_convert (x_scale()) + "_" + raw_convert (y_scale()) + "_" + raw_convert (x_offset()) + "_" + raw_convert (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 >); + 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 ();