From 9f125fddff88bf62d36381f9d3f09e5240b033d5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 18 May 2023 22:21:33 +0200 Subject: [PATCH] Cleanup: replace some list with vector. --- src/lib/cinema.cc | 5 ++++- src/lib/cinema.h | 8 ++++---- src/lib/dkdm_recipient.h | 4 ++-- src/lib/emailer.cc | 6 +++--- src/lib/emailer.h | 12 ++++++------ src/lib/kdm_cli.cc | 10 +++++----- src/lib/kdm_with_metadata.h | 6 +++--- src/lib/screen.cc | 2 +- src/lib/send_notification_email_job.cc | 6 +----- src/tools/dcpomatic.cc | 3 +-- src/wx/cinema_dialog.cc | 16 +++------------- src/wx/cinema_dialog.h | 5 ++--- src/wx/recipient_dialog.cc | 9 +++------ src/wx/recipient_dialog.h | 4 ++-- test/config_test.cc | 6 +++--- test/kdm_cli_test.cc | 5 ++--- test/kdm_naming_test.cc | 6 +++--- 17 files changed, 48 insertions(+), 65 deletions(-) diff --git a/src/lib/cinema.cc b/src/lib/cinema.cc index 57780fa7b..3b4b9d7b6 100644 --- a/src/lib/cinema.cc +++ b/src/lib/cinema.cc @@ -91,7 +91,10 @@ Cinema::add_screen (shared_ptr s) void Cinema::remove_screen (shared_ptr s) { - _screens.remove (s); + auto iter = std::find(_screens.begin(), _screens.end(), s); + if (iter != _screens.end()) { + _screens.erase(iter); + } } void diff --git a/src/lib/cinema.h b/src/lib/cinema.h index c17454db9..6c202a7bf 100644 --- a/src/lib/cinema.h +++ b/src/lib/cinema.h @@ -44,7 +44,7 @@ namespace dcpomatic { class Cinema : public std::enable_shared_from_this { public: - Cinema (std::string const & name_, std::list const & e, std::string notes_, int utc_offset_hour, int utc_offset_minute) + Cinema(std::string const & name_, std::vector const & e, std::string notes_, int utc_offset_hour, int utc_offset_minute) : name (name_) , emails (e) , notes (notes_) @@ -65,7 +65,7 @@ public: void set_utc_offset_minute (int m); std::string name; - std::list emails; + std::vector emails; std::string notes; int utc_offset_hour () const { @@ -76,12 +76,12 @@ public: return _utc_offset_minute; } - std::list> screens () const { + std::vector> screens() const { return _screens; } private: - std::list> _screens; + std::vector> _screens; /** Offset such that the equivalent time in UTC can be determined by subtracting the offset from the local time. */ diff --git a/src/lib/dkdm_recipient.h b/src/lib/dkdm_recipient.h index 6e9e4dfb1..7a0fa0185 100644 --- a/src/lib/dkdm_recipient.h +++ b/src/lib/dkdm_recipient.h @@ -33,7 +33,7 @@ public: std::string const& name_, std::string const& notes_, boost::optional recipient_, - std::list emails_, + std::vector emails_, int utc_offset_hour_, int utc_offset_minute_ ) @@ -49,7 +49,7 @@ public: void as_xml (xmlpp::Element *) const override; - std::list emails; + std::vector emails; int utc_offset_hour; int utc_offset_minute; }; diff --git a/src/lib/emailer.cc b/src/lib/emailer.cc index e21bbfe2d..f580e3c56 100644 --- a/src/lib/emailer.cc +++ b/src/lib/emailer.cc @@ -31,15 +31,15 @@ using std::cout; -using std::list; using std::min; using std::pair; using std::shared_ptr; using std::string; +using std::vector; using dcp::ArrayData; -Emailer::Emailer (string from, list to, string subject, string body) +Emailer::Emailer(string from, vector to, string subject, string body) : _from (from) , _to (to) , _subject (subject) @@ -247,7 +247,7 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str string -Emailer::address_list (list addresses) +Emailer::address_list(vector addresses) { string o; for (auto i: addresses) { diff --git a/src/lib/emailer.h b/src/lib/emailer.h index ef41b0320..78942ad1e 100644 --- a/src/lib/emailer.h +++ b/src/lib/emailer.h @@ -26,7 +26,7 @@ class Emailer { public: - Emailer (std::string from, std::list to, std::string subject, std::string body); + Emailer(std::string from, std::vector to, std::string subject, std::string body); void add_cc (std::string cc); void add_bcc (std::string bcc); @@ -46,7 +46,7 @@ public: return _email; } - static std::string address_list (std::list addresses); + static std::string address_list(std::vector addresses); private: @@ -54,11 +54,11 @@ private: static std::string encode_rfc1342 (std::string subject); std::string _from; - std::list _to; + std::vector _to; std::string _subject; std::string _body; - std::list _cc; - std::list _bcc; + std::vector _cc; + std::vector _bcc; struct Attachment { boost::filesystem::path file; @@ -66,7 +66,7 @@ private: std::string mime_type; }; - std::list _attachments; + std::vector _attachments; std::string _email; size_t _offset; std::string _notes; diff --git a/src/lib/kdm_cli.cc b/src/lib/kdm_cli.cc index 925626119..05a59142f 100644 --- a/src/lib/kdm_cli.cc +++ b/src/lib/kdm_cli.cc @@ -203,7 +203,7 @@ find_cinema (string cinema_name) static void from_film ( - list> screens, + vector> screens, boost::filesystem::path film_dir, bool verbose, boost::filesystem::path output, @@ -346,7 +346,7 @@ kdm_from_dkdm ( static void from_dkdm ( - list> screens, + vector> screens, dcp::DecryptedKDM dkdm, bool verbose, boost::filesystem::path output, @@ -396,7 +396,7 @@ from_dkdm ( name_values['e'] = end.date() + " " + end.time_of_day(true, false); name_values['i'] = kdm.cpl_id(); - kdms.push_back (make_shared(name_values, i->cinema.get(), i->cinema ? i->cinema->emails : list(), kdm)); + kdms.push_back(make_shared(name_values, i->cinema.get(), i->cinema ? i->cinema->emails : vector(), kdm)); } write_files (kdms, zip, output, container_name_format, filename_format, verbose, out); if (email) { @@ -441,7 +441,7 @@ try shared_ptr cinema; optional certificate; optional screen; - list> screens; + vector> screens; optional dkdm; optional valid_from; optional valid_to; @@ -552,7 +552,7 @@ try (for lookup) and by creating a Cinema which the next Screen will be added to. */ cinema_name = optarg; - cinema = make_shared(optarg, list(), "", 0, 0); + cinema = make_shared(optarg, vector(), "", 0, 0); break; case 'S': /* Similarly, this could be the name of a new (temporary) screen or the name of a screen diff --git a/src/lib/kdm_with_metadata.h b/src/lib/kdm_with_metadata.h index df9f04125..fbeeffbc1 100644 --- a/src/lib/kdm_with_metadata.h +++ b/src/lib/kdm_with_metadata.h @@ -33,7 +33,7 @@ class Cinema; class KDMWithMetadata { public: - KDMWithMetadata (dcp::NameFormat::Map const& name_values, void const* group, std::list emails, dcp::EncryptedKDM kdm) + KDMWithMetadata(dcp::NameFormat::Map const& name_values, void const* group, std::vector emails, dcp::EncryptedKDM kdm) : _name_values (name_values) , _group (group) , _emails (emails) @@ -58,14 +58,14 @@ public: return _group; } - std::list emails () const { + std::vector emails() const { return _emails; } private: dcp::NameFormat::Map _name_values; void const* _group; - std::list _emails; + std::vector _emails; dcp::EncryptedKDM _kdm; }; diff --git a/src/lib/screen.cc b/src/lib/screen.cc index dbf013111..097ff80b8 100644 --- a/src/lib/screen.cc +++ b/src/lib/screen.cc @@ -116,6 +116,6 @@ kdm_for_screen ( name_values['e'] = end.date() + " " + end.time_of_day(true, false); name_values['i'] = kdm.cpl_id(); - return make_shared(name_values, cinema.get(), cinema ? cinema->emails : list(), kdm); + return make_shared(name_values, cinema.get(), cinema ? cinema->emails : vector(), kdm); } diff --git a/src/lib/send_notification_email_job.cc b/src/lib/send_notification_email_job.cc index c4d5a6518..2dd1f63f2 100644 --- a/src/lib/send_notification_email_job.cc +++ b/src/lib/send_notification_email_job.cc @@ -24,13 +24,11 @@ #include "config.h" #include "emailer.h" #include "compose.hpp" -#include #include "i18n.h" using std::string; -using std::list; using std::shared_ptr; @@ -73,9 +71,7 @@ SendNotificationEmailJob::run () } set_progress_unknown (); - list to; - to.push_back (config->notification_to()); - Emailer email (config->notification_from(), to, config->notification_subject(), _body); + Emailer email (config->notification_from(), { config->notification_to() }, config->notification_subject(), _body); for (auto i: config->notification_cc()) { email.add_cc (i); } diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index 3d944e780..d6b6bc2b7 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -1115,12 +1115,11 @@ private: for (auto i: translations) { body += i.first + "\n" + i.second + "\n\n"; } - list to = { "carl@dcpomatic.com" }; if (dialog.email().find("@") == string::npos) { error_dialog (this, _("You must enter a valid email address when sending translations, " "otherwise the DCP-o-matic maintainers cannot credit you or contact you with questions.")); } else { - Emailer emailer(dialog.email(), to, "DCP-o-matic translations", body); + Emailer emailer(dialog.email(), { "carl@dcpomatic.com" }, "DCP-o-matic translations", body); try { emailer.send ("main.carlh.net", 2525, EmailProtocol::STARTTLS); } catch (NetworkError& e) { diff --git a/src/wx/cinema_dialog.cc b/src/wx/cinema_dialog.cc index 8c7194c4a..84fde5f41 100644 --- a/src/wx/cinema_dialog.cc +++ b/src/wx/cinema_dialog.cc @@ -28,7 +28,6 @@ using std::back_inserter; using std::copy; using std::cout; -using std::list; using std::string; using std::vector; using boost::bind; @@ -37,7 +36,7 @@ using namespace boost::placeholders; #endif -CinemaDialog::CinemaDialog (wxWindow* parent, wxString title, string name, list emails, string notes, int utc_offset_hour, int utc_offset_minute) +CinemaDialog::CinemaDialog(wxWindow* parent, wxString title, string name, vector emails, string notes, int utc_offset_hour, int utc_offset_minute) : wxDialog (parent, wxID_ANY, title) { auto overall_sizer = new wxBoxSizer (wxVERTICAL); @@ -69,7 +68,7 @@ CinemaDialog::CinemaDialog (wxWindow* parent, wxString title, string name, list< vector columns; columns.push_back (EditableListColumn(_("Address"), 500, true)); _email_list = new EditableList ( - this, columns, bind (&CinemaDialog::get_emails, this), bind (&CinemaDialog::set_emails, this, _1), [](string s, int) { + this, columns, bind(&CinemaDialog::emails, this), bind (&CinemaDialog::set_emails, this, _1), [](string s, int) { return s; }, EditableListTitle::INVISIBLE, EditableListButton::NEW | EditableListButton::EDIT | EditableListButton::REMOVE ); @@ -117,21 +116,12 @@ CinemaDialog::set_emails (vector e) vector -CinemaDialog::get_emails () const +CinemaDialog::emails() const { return _emails; } -list -CinemaDialog::emails () const -{ - list e; - copy (_emails.begin(), _emails.end(), back_inserter(e)); - return e; -} - - int CinemaDialog::utc_offset_hour () const { diff --git a/src/wx/cinema_dialog.h b/src/wx/cinema_dialog.h index a878e6055..0b8362843 100644 --- a/src/wx/cinema_dialog.h +++ b/src/wx/cinema_dialog.h @@ -37,7 +37,7 @@ public: wxWindow *, wxString, std::string name = "", - std::list emails = std::list (), + std::vector emails = std::vector(), std::string notes = "", int utc_offset_hour = 0, int utc_offset_minute = 0 @@ -45,12 +45,11 @@ public: std::string name () const; std::string notes () const; - std::list emails () const; + std::vector emails () const; int utc_offset_hour () const; int utc_offset_minute () const; private: - std::vector get_emails () const; void set_emails (std::vector); wxTextCtrl* _name; diff --git a/src/wx/recipient_dialog.cc b/src/wx/recipient_dialog.cc index b685f884a..b166f265d 100644 --- a/src/wx/recipient_dialog.cc +++ b/src/wx/recipient_dialog.cc @@ -38,7 +38,6 @@ LIBDCP_ENABLE_WARNINGS using std::cout; -using std::list; using std::string; using std::vector; using boost::bind; @@ -56,7 +55,7 @@ column (string s) RecipientDialog::RecipientDialog ( - wxWindow* parent, wxString title, string name, string notes, list emails, int utc_offset_hour, int utc_offset_minute, optional recipient + wxWindow* parent, wxString title, string name, string notes, vector emails, int utc_offset_hour, int utc_offset_minute, optional recipient ) : wxDialog (parent, wxID_ANY, title) , _recipient (recipient) @@ -233,12 +232,10 @@ RecipientDialog::set_emails (vector e) } -list +vector RecipientDialog::emails () const { - list e; - copy (_emails.begin(), _emails.end(), back_inserter(e)); - return e; + return _emails; } diff --git a/src/wx/recipient_dialog.h b/src/wx/recipient_dialog.h index 2ed6d3f31..a46e67af5 100644 --- a/src/wx/recipient_dialog.h +++ b/src/wx/recipient_dialog.h @@ -43,7 +43,7 @@ public: wxString, std::string name = "", std::string notes = "", - std::list emails = std::list(), + std::vector emails = std::vector(), int utc_offset_hour = 0, int utc_offset_minute = 0, boost::optional c = boost::optional() @@ -52,7 +52,7 @@ public: std::string name () const; std::string notes () const; boost::optional recipient () const; - std::list emails () const; + std::vector emails () const; int utc_offset_hour () const; int utc_offset_minute () const; diff --git a/test/config_test.cc b/test/config_test.cc index e90550085..103a6a585 100644 --- a/test/config_test.cc +++ b/test/config_test.cc @@ -26,10 +26,10 @@ #include -using std::list; -using std::ofstream; using std::make_shared; +using std::ofstream; using std::string; +using std::vector; using boost::optional; @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE (config_keep_cinemas_if_making_new_config) Config::instance()->write(); - Config::instance()->add_cinema(make_shared("My Great Cinema", list(), "", 0, 0)); + Config::instance()->add_cinema(make_shared("My Great Cinema", vector(), "", 0, 0)); Config::instance()->write(); boost::filesystem::copy_file (dir / "cinemas.xml", dir / "backup_for_test.xml"); diff --git a/test/kdm_cli_test.cc b/test/kdm_cli_test.cc index e300d82a5..c91cb64f4 100644 --- a/test/kdm_cli_test.cc +++ b/test/kdm_cli_test.cc @@ -31,7 +31,6 @@ #include -using std::list; using std::string; using std::vector; using boost::optional; @@ -86,13 +85,13 @@ setup_test_config() auto config = Config::instance(); auto const cert = dcp::Certificate(dcp::file_to_string("test/data/cert.pem")); - auto cinema_a = std::make_shared("Dean's Screens", list(), "", 0, 0); + auto cinema_a = std::make_shared("Dean's Screens", vector(), "", 0, 0); cinema_a->add_screen(std::make_shared("Screen 1", "", cert, boost::none, std::vector())); cinema_a->add_screen(std::make_shared("Screen 2", "", cert, boost::none, std::vector())); cinema_a->add_screen(std::make_shared("Screen 3", "", cert, boost::none, std::vector())); config->add_cinema(cinema_a); - auto cinema_b = std::make_shared("Floyd's Celluloid", list(), "", 0, 0); + auto cinema_b = std::make_shared("Floyd's Celluloid", vector(), "", 0, 0); cinema_b->add_screen(std::make_shared("Foo", "", cert, boost::none, std::vector())); cinema_b->add_screen(std::make_shared("Bar", "", cert, boost::none, std::vector())); config->add_cinema(cinema_b); diff --git a/test/kdm_naming_test.cc b/test/kdm_naming_test.cc index 30356afbf..32500553e 100644 --- a/test/kdm_naming_test.cc +++ b/test/kdm_naming_test.cc @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE (single_kdm_naming_test) auto crypt_cert = c->decryption_chain()->leaf(); /* Cinema A: UTC +4:30 */ - auto cinema_a = make_shared("Cinema A", list(), "", 4, 30); + auto cinema_a = make_shared("Cinema A", vector(), "", 4, 30); cinema_a_screen_1 = std::make_shared("Screen 1", "", crypt_cert, boost::none, vector()); cinema_a->add_screen (cinema_a_screen_1); cinema_a_screen_2 = std::make_shared("Screen 2", "", crypt_cert, boost::none, vector()); @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE (single_kdm_naming_test) c->add_cinema (cinema_a); /* Cinema B: UTC -1:00 */ - auto cinema_b = make_shared("Cinema B", list(), "", -1, 0); + auto cinema_b = make_shared("Cinema B", vector(), "", -1, 0); cinema_b_screen_x = std::make_shared("Screen X", "", crypt_cert, boost::none, vector()); cinema_b->add_screen (cinema_b_screen_x); cinema_b_screen_y = std::make_shared("Screen Y", "", crypt_cert, boost::none, vector()); @@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE (directory_kdm_naming_test, * boost::unit_test::depends_on( string const from_string = from.date() + " " + from.time_of_day(true, false); string const until_string = until.date() + " " + until.time_of_day(true, false); - list> screens = { + vector> screens = { cinema_a_screen_2, cinema_b_screen_x, cinema_a_screen_1, (cinema_b_screen_z) }; -- 2.30.2