From d95eacd3851a20e52202465ec22b4f72a4983dc8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 11 Jan 2021 00:16:40 +0100 Subject: Replace std::list with std::vector in the API. --- src/certificate_chain.cc | 9 ++++++--- src/certificate_chain.h | 2 +- src/combine.cc | 7 +++---- src/cpl.cc | 10 +++++----- src/cpl.h | 13 ++++++------- src/dcp.cc | 16 ++++++++-------- src/dcp.h | 16 ++++++++-------- src/decrypted_kdm.cc | 4 ++-- src/decrypted_kdm.h | 4 ++-- src/encrypted_kdm.cc | 14 +++++++------- src/encrypted_kdm.h | 6 +++--- src/interop_subtitle_asset.cc | 25 +++++++++++++------------ src/interop_subtitle_asset.h | 8 ++++---- src/pkl.h | 2 +- src/reel.cc | 8 ++++---- src/reel.h | 11 +++++------ src/ref.cc | 8 ++++---- src/ref.h | 6 +++--- src/smpte_subtitle_asset.cc | 18 +++++++++--------- src/smpte_subtitle_asset.h | 4 ++-- src/subtitle_asset.cc | 30 +++++++++++++++--------------- src/subtitle_asset.h | 14 +++++++------- src/subtitle_asset_internal.h | 2 +- src/util.cc | 4 ++-- src/util.h | 2 +- src/verify.cc | 25 ++++++++++++------------- src/verify.h | 3 +-- src/xml.h | 10 +++++----- 28 files changed, 140 insertions(+), 141 deletions(-) (limited to 'src') diff --git a/src/certificate_chain.cc b/src/certificate_chain.cc index 2fb0f651..a4da0931 100644 --- a/src/certificate_chain.cc +++ b/src/certificate_chain.cc @@ -362,7 +362,7 @@ CertificateChain::List CertificateChain::leaf_to_root () const { List l = root_to_leaf (); - l.reverse (); + std::reverse (l.begin(), l.end()); return l; } @@ -387,7 +387,10 @@ CertificateChain::add (Certificate c) void CertificateChain::remove (Certificate c) { - _certificates.remove (c); + auto i = std::find(_certificates.begin(), _certificates.end(), c); + if (i != _certificates.end()) { + _certificates.erase (i); + } } /** Remove the i'th certificate in the list, as listed @@ -557,7 +560,7 @@ CertificateChain::List CertificateChain::root_to_leaf () const { List rtl = _certificates; - rtl.sort (); + std::sort (rtl.begin(), rtl.end()); do { if (chain_valid (rtl)) { return rtl; diff --git a/src/certificate_chain.h b/src/certificate_chain.h index 63ef8901..c74bc6e2 100644 --- a/src/certificate_chain.h +++ b/src/certificate_chain.h @@ -92,7 +92,7 @@ public: Certificate root () const; Certificate leaf () const; - typedef std::list List; + typedef std::vector List; List leaf_to_root () const; List root_to_leaf () const; diff --git a/src/combine.cc b/src/combine.cc index 5c9a1087..cd91d5b1 100644 --- a/src/combine.cc +++ b/src/combine.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington + Copyright (C) 2020-2021 Carl Hetherington This file is part of libdcp. @@ -48,7 +48,6 @@ #include -using std::list; using std::map; using std::set; using std::string; @@ -121,8 +120,8 @@ dcp::combine ( } } - list paths; - list > assets; + vector paths; + vector> assets; BOOST_FOREACH (path i, inputs) { DCP dcp (i); diff --git a/src/cpl.cc b/src/cpl.cc index 22abfb69..04bc9f5c 100644 --- a/src/cpl.cc +++ b/src/cpl.cc @@ -487,10 +487,10 @@ CPL::maybe_write_composition_metadata_asset (xmlpp::Element* node) const } -list> +vector> CPL::reel_mxfs () { - list> c; + vector> c; for (auto i: _reels) { if (i->main_picture ()) { @@ -513,10 +513,10 @@ CPL::reel_mxfs () return c; } -list> +vector> CPL::reel_mxfs () const { - list> c; + vector> c; for (auto i: _reels) { if (i->main_picture ()) { @@ -603,7 +603,7 @@ CPL::add (DecryptedKDM const & kdm) } void -CPL::resolve_refs (list> assets) +CPL::resolve_refs (vector> assets) { for (auto i: _reels) { i->resolve_refs (assets); diff --git a/src/cpl.h b/src/cpl.h index 6805cc89..c2a8b07d 100644 --- a/src/cpl.h +++ b/src/cpl.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2020 Carl Hetherington + Copyright (C) 2014-2021 Carl Hetherington This file is part of libdcp. @@ -50,7 +50,6 @@ #include #include #include -#include #include @@ -86,13 +85,13 @@ public: void add (DecryptedKDM const &); /** @return the reels in this CPL */ - std::list > reels () const { + std::vector> reels () const { return _reels; } /** @return the ReelMXFs in this CPL in all reels */ - std::list > reel_mxfs () const; - std::list > reel_mxfs (); + std::vector> reel_mxfs () const; + std::vector> reel_mxfs (); bool encrypted () const; @@ -102,7 +101,7 @@ public: std::shared_ptr ) const; - void resolve_refs (std::list >); + void resolve_refs (std::vector>); int64_t duration () const; @@ -316,7 +315,7 @@ private: /* See note for _release_territory above */ std::vector _additional_subtitle_languages; - std::list > _reels; + std::vector> _reels; /** Standard of CPL that was read in */ boost::optional _standard; diff --git a/src/dcp.cc b/src/dcp.cc index 17d5c88d..ca7313a5 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -105,10 +105,10 @@ DCP::DCP (boost::filesystem::path directory) * * Errors that are not fatal will be added to notes, if it's non-0. For example, * if the DCP contains a mixture of Interop and SMPTE elements this will result - * in a note being added to the list. + * in a note being added to the vector. */ void -DCP::read (list* notes, bool ignore_incorrect_picture_mxf_type) +DCP::read (vector* notes, bool ignore_incorrect_picture_mxf_type) { /* Read the ASSETMAP and PKL */ @@ -133,7 +133,7 @@ DCP::read (list* notes, bool ignore_incorrect_picture_mxf auto asset_nodes = asset_map.node_child("AssetList")->node_children ("Asset"); map paths; - list pkl_paths; + vector pkl_paths; for (auto i: asset_nodes) { if (i->node_child("ChunkList")->node_children("Chunk").size() != 1) { boost::throw_exception (XMLError ("unsupported asset chunk count")); @@ -181,7 +181,7 @@ DCP::read (list* notes, bool ignore_incorrect_picture_mxf /* Make a list of non-CPL/PKL assets so that we can resolve the references from the CPLs. */ - list> other_assets; + vector> other_assets; for (auto i: paths) { auto path = _directory / i.second; @@ -276,7 +276,7 @@ DCP::read (list* notes, bool ignore_incorrect_picture_mxf } void -DCP::resolve_refs (list> assets) +DCP::resolve_refs (vector> assets) { for (auto i: cpls()) { i->resolve_refs (assets); @@ -498,7 +498,7 @@ DCP::write_xml ( write_assetmap (standard, pkl->id(), pkl_path, issuer, creator, issue_date, annotation_text); } -list> +vector> DCP::cpls () const { return _cpls; @@ -508,10 +508,10 @@ DCP::cpls () const * an exception is thrown if they are found. * @return All assets (including CPLs). */ -list> +vector> DCP::assets (bool ignore_unresolved) const { - list> assets; + vector> assets; for (auto i: cpls()) { assets.push_back (i); for (auto j: i->reel_mxfs()) { diff --git a/src/dcp.h b/src/dcp.h index 3eab743e..73f154c7 100644 --- a/src/dcp.h +++ b/src/dcp.h @@ -91,7 +91,7 @@ public: * as stereoscopic if the monoscopic load fails; fixes problems some 3D DCPs that (I think) * have an incorrect descriptor in their MXF. */ - void read (std::list* notes = 0, bool ignore_incorrect_picture_mxf_type = false); + void read (std::vector* notes = 0, bool ignore_incorrect_picture_mxf_type = false); /** Compare this DCP with another, according to various options. * @param other DCP to compare this one to. @@ -103,8 +103,8 @@ public: void add (std::shared_ptr cpl); - std::list > cpls () const; - std::list > assets (bool ignore_unresolved = false) const; + std::vector> cpls () const; + std::vector> assets (bool ignore_unresolved = false) const; bool encrypted () const; @@ -120,7 +120,7 @@ public: NameFormat name_format = NameFormat("%t") ); - void resolve_refs (std::list > assets); + void resolve_refs (std::vector> assets); /** @return Standard of a DCP that was read in */ boost::optional standard () const { @@ -132,9 +132,9 @@ public: } /** @return PKLs if this DCP was read from an existing one, or if write_xml() has been called on it. - * If neither is true, this method returns an empty list. + * If neither is true, this method returns an empty vector. */ - std::list > pkls () const { + std::vector> pkls () const { return _pkls; } @@ -160,9 +160,9 @@ private: /** The directory that we are writing to */ boost::filesystem::path _directory; /** The CPLs that make up this DCP */ - std::list > _cpls; + std::vector> _cpls; /** The PKLs that make up this DCP */ - std::list > _pkls; + std::vector> _pkls; /** File that the ASSETMAP was read from or last written to */ mutable boost::optional _asset_map; diff --git a/src/decrypted_kdm.cc b/src/decrypted_kdm.cc index 043eac47..dd6def32 100644 --- a/src/decrypted_kdm.cc +++ b/src/decrypted_kdm.cc @@ -320,8 +320,8 @@ DecryptedKDM::encrypt ( } } - list > key_ids; - list keys; + vector> key_ids; + vector keys; BOOST_FOREACH (DecryptedKDMKey const & i, _keys) { /* We're making SMPTE keys so we must have a type for each one */ DCP_ASSERT (i.type()); diff --git a/src/decrypted_kdm.h b/src/decrypted_kdm.h index a67fdbfe..867e97ff 100644 --- a/src/decrypted_kdm.h +++ b/src/decrypted_kdm.h @@ -142,7 +142,7 @@ public: void add_key (DecryptedKDMKey key); /** @return This KDM's (decrypted) keys, which could be used to decrypt assets. */ - std::list keys () const { + std::vector keys () const { return _keys; } @@ -170,7 +170,7 @@ private: boost::optional _annotation_text; std::string _content_title_text; std::string _issue_date; - std::list _keys; + std::vector _keys; }; } diff --git a/src/encrypted_kdm.cc b/src/encrypted_kdm.cc index 77345a5d..a124fdf6 100644 --- a/src/encrypted_kdm.cc +++ b/src/encrypted_kdm.cc @@ -198,7 +198,7 @@ public: SignedInfo signed_info; string signature_value; - list x509_data; + vector x509_data; }; class AuthenticatedPrivate @@ -232,7 +232,7 @@ public: } } - list encrypted_key; + vector encrypted_key; }; class TypedKeyId @@ -288,7 +288,7 @@ public: } } - list typed_key_id; + vector typed_key_id; }; class AuthorizedDeviceInfo @@ -320,7 +320,7 @@ public: /** DeviceListIdentifier without the urn:uuid: prefix */ string device_list_identifier; boost::optional device_list_description; - std::list certificate_thumbprints; + std::vector certificate_thumbprints; }; class X509IssuerSerial @@ -586,8 +586,8 @@ EncryptedKDM::EncryptedKDM ( Formulation formulation, bool disable_forensic_marking_picture, optional disable_forensic_marking_audio, - list > key_ids, - list keys + vector> key_ids, + vector keys ) : _data (new data::EncryptedKDMData) { @@ -719,7 +719,7 @@ EncryptedKDM::as_xml () const return _data->as_xml()->write_to_string ("UTF-8"); } -list +vector EncryptedKDM::keys () const { return _data->authenticated_private.encrypted_key; diff --git a/src/encrypted_kdm.h b/src/encrypted_kdm.h index 175b578f..342bedca 100644 --- a/src/encrypted_kdm.h +++ b/src/encrypted_kdm.h @@ -84,7 +84,7 @@ public: * Note that the returned `keys' contain more than just the asset decryption * keys (also key id, CPL id etc.) */ - std::list keys () const; + std::vector keys () const; std::string id () const; boost::optional annotation_text () const; @@ -113,8 +113,8 @@ private: Formulation formulation, bool disable_forensic_marking_picture, boost::optional disable_forensic_marking_audio, - std::list > key_ids, - std::list keys + std::vector> key_ids, + std::vector keys ); data::EncryptedKDMData* _data; diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index ac3dcc98..edc51404 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -53,9 +53,10 @@ using std::cout; using std::cerr; using std::map; using std::shared_ptr; +using std::dynamic_pointer_cast; +using std::vector; using boost::shared_array; using boost::optional; -using std::dynamic_pointer_cast; using namespace dcp; InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file) @@ -73,7 +74,7 @@ InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file) /* Now we need to drop down to xmlpp */ - list ps; + vector ps; xmlpp::Node::NodeList c = xml->node()->get_children (); for (xmlpp::Node::NodeList::const_iterator i = c.begin(); i != c.end(); ++i) { xmlpp::Element const * e = dynamic_cast (*i); @@ -107,10 +108,10 @@ InteropSubtitleAsset::xml_as_string () const root->add_child("ReelNumber")->add_child_text (raw_convert (_reel_number)); root->add_child("Language")->add_child_text (_language); - for (list >::const_iterator i = _load_font_nodes.begin(); i != _load_font_nodes.end(); ++i) { + for (auto i: _load_font_nodes) { xmlpp::Element* load_font = root->add_child("LoadFont"); - load_font->set_attribute ("Id", (*i)->id); - load_font->set_attribute ("URI", (*i)->uri); + load_font->set_attribute ("Id", i->id); + load_font->set_attribute ("URI", i->uri); } subtitles_as_xml (root, 250, INTEROP); @@ -139,8 +140,8 @@ InteropSubtitleAsset::equals (shared_ptr other_asset, EqualityOptio } if (!options.load_font_nodes_can_differ) { - list >::const_iterator i = _load_font_nodes.begin (); - list >::const_iterator j = other->_load_font_nodes.begin (); + auto i = _load_font_nodes.begin(); + auto j = other->_load_font_nodes.begin(); while (i != _load_font_nodes.end ()) { if (j == other->_load_font_nodes.end ()) { @@ -166,10 +167,10 @@ InteropSubtitleAsset::equals (shared_ptr other_asset, EqualityOptio return true; } -list > +vector> InteropSubtitleAsset::load_font_nodes () const { - list > lf; + vector> lf; copy (_load_font_nodes.begin(), _load_font_nodes.end(), back_inserter (lf)); return lf; } @@ -201,7 +202,7 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const /* Fonts */ BOOST_FOREACH (shared_ptr i, _load_font_nodes) { boost::filesystem::path file = p.parent_path() / i->uri; - list::const_iterator j = _fonts.begin (); + auto j = _fonts.begin(); while (j != _fonts.end() && j->load_id != i->id) { ++j; } @@ -217,7 +218,7 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const * a list of font ID, load ID and data. */ void -InteropSubtitleAsset::resolve_fonts (list > assets) +InteropSubtitleAsset::resolve_fonts (vector> assets) { BOOST_FOREACH (shared_ptr i, assets) { shared_ptr font = dynamic_pointer_cast (i); @@ -242,7 +243,7 @@ InteropSubtitleAsset::resolve_fonts (list > assets) } void -InteropSubtitleAsset::add_font_assets (list >& assets) +InteropSubtitleAsset::add_font_assets (vector>& assets) { BOOST_FOREACH (Font const & i, _fonts) { DCP_ASSERT (i.file); diff --git a/src/interop_subtitle_asset.h b/src/interop_subtitle_asset.h index 7ce7d175..87e82633 100644 --- a/src/interop_subtitle_asset.h +++ b/src/interop_subtitle_asset.h @@ -62,14 +62,14 @@ public: void write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const; void add_to_pkl (std::shared_ptr pkl, boost::filesystem::path root) const; - std::list > load_font_nodes () const; + std::vector> load_font_nodes () const; void add_font (std::string load_id, dcp::ArrayData data); std::string xml_as_string () const; void write (boost::filesystem::path path) const; - void resolve_fonts (std::list > assets); - void add_font_assets (std::list >& assets); + void resolve_fonts (std::vector> assets); + void add_font_assets (std::vector>& assets); void set_font_file (std::string load_id, boost::filesystem::path file); /** Set the reel number or sub-element identifier @@ -123,7 +123,7 @@ private: std::string _reel_number; std::string _language; std::string _movie_title; - std::list > _load_font_nodes; + std::vector> _load_font_nodes; }; } diff --git a/src/pkl.h b/src/pkl.h index a27a9a33..0ea87219 100644 --- a/src/pkl.h +++ b/src/pkl.h @@ -103,7 +103,7 @@ private: std::string _issue_date; std::string _issuer; std::string _creator; - std::list > _asset_list; + std::vector> _asset_list; /** The most recent disk file used to read or write this PKL */ mutable boost::optional _file; }; diff --git a/src/reel.cc b/src/reel.cc index 8b748424..89056cff 100644 --- a/src/reel.cc +++ b/src/reel.cc @@ -59,12 +59,12 @@ #endif using std::string; -using std::list; using std::cout; using std::min; using std::make_shared; using std::shared_ptr; using std::dynamic_pointer_cast; +using std::vector; using namespace dcp; Reel::Reel (std::shared_ptr node) @@ -297,10 +297,10 @@ Reel::add (shared_ptr asset) } } -list> +vector> Reel::assets () const { - list> a; + vector> a; if (_main_picture) { a.push_back (_main_picture); } @@ -318,7 +318,7 @@ Reel::assets () const } void -Reel::resolve_refs (list> assets) +Reel::resolve_refs (vector> assets) { if (_main_picture) { _main_picture->asset_ref().resolve (assets); diff --git a/src/reel.h b/src/reel.h index 041e1ca1..083ecd0e 100644 --- a/src/reel.h +++ b/src/reel.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of libdcp. @@ -39,7 +39,6 @@ #include "ref.h" #include #include -#include namespace cxml { class Node; @@ -99,7 +98,7 @@ public: return _main_markers; } - std::list > closed_captions () const { + std::vector> closed_captions () const { return _closed_captions; } @@ -111,7 +110,7 @@ public: void add (std::shared_ptr asset); - std::list > assets () const; + std::vector> assets () const; xmlpp::Element* write_to_cpl (xmlpp::Element* node, Standard standard) const; @@ -121,14 +120,14 @@ public: void add (DecryptedKDM const &); - void resolve_refs (std::list >); + void resolve_refs (std::vector>); private: std::shared_ptr _main_picture; std::shared_ptr _main_sound; std::shared_ptr _main_subtitle; std::shared_ptr _main_markers; - std::list > _closed_captions; + std::vector> _closed_captions; std::shared_ptr _atmos; }; diff --git a/src/ref.cc b/src/ref.cc index 7512d32c..8527150d 100644 --- a/src/ref.cc +++ b/src/ref.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington + Copyright (C) 2015-2021 Carl Hetherington This file is part of libdcp. @@ -33,17 +33,17 @@ #include "ref.h" -using std::list; using std::shared_ptr; +using std::vector; using namespace dcp; /** Look through a list of assets and copy a shared_ptr to any asset * which matches the ID of this one. */ void -Ref::resolve (list > assets) +Ref::resolve (vector> assets) { - list >::iterator i = assets.begin(); + auto i = assets.begin(); while (i != assets.end() && !ids_equal ((*i)->id(), _id)) { ++i; } diff --git a/src/ref.h b/src/ref.h index 9ebe19b8..94add1c8 100644 --- a/src/ref.h +++ b/src/ref.h @@ -54,8 +54,8 @@ namespace dcp { * which represents the thing. * * If the Ref does not have a shared_ptr it may be given one by - * calling resolve() with a list of assets. The shared_ptr will be - * set up using any object on the list which has a matching ID. + * calling resolve() with a vector of assets. The shared_ptr will be + * set up using any object on the vector which has a matching ID. */ class Ref { @@ -77,7 +77,7 @@ public: _id = id; } - void resolve (std::list > assets); + void resolve (std::vector> assets); /** @return the ID of the thing that we are pointing to */ std::string id () const { diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 0e6c1254..7604fd39 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -183,7 +183,7 @@ SMPTESubtitleAsset::parse_xml (shared_ptr xml) /* Now we need to drop down to xmlpp */ - list ps; + vector ps; xmlpp::Node::NodeList c = xml->node()->get_children (); for (xmlpp::Node::NodeList::const_iterator i = c.begin(); i != c.end(); ++i) { xmlpp::Element const * e = dynamic_cast (*i); @@ -222,7 +222,7 @@ SMPTESubtitleAsset::read_mxf_descriptor (shared_ptr switch (i->Type) { case ASDCP::TimedText::MT_OPENTYPE: { - list >::const_iterator j = _load_font_nodes.begin (); + auto j = _load_font_nodes.begin(); while (j != _load_font_nodes.end() && (*j)->urn != id) { ++j; } @@ -234,7 +234,7 @@ SMPTESubtitleAsset::read_mxf_descriptor (shared_ptr } case ASDCP::TimedText::MT_PNG: { - list >::const_iterator j = _subtitles.begin (); + auto j = _subtitles.begin(); while (j != _subtitles.end() && ((!dynamic_pointer_cast(*j)) || dynamic_pointer_cast(*j)->id() != id)) { ++j; } @@ -291,10 +291,10 @@ SMPTESubtitleAsset::set_key (Key key) read_mxf_descriptor (reader, dec); } -list > +vector> SMPTESubtitleAsset::load_font_nodes () const { - list > lf; + vector> lf; copy (_load_font_nodes.begin(), _load_font_nodes.end(), back_inserter (lf)); return lf; } @@ -362,7 +362,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const /* Font references */ BOOST_FOREACH (shared_ptr i, _load_font_nodes) { - list::const_iterator j = _fonts.begin (); + auto j = _fonts.begin(); while (j != _fonts.end() && j->load_id != i->id) { ++j; } @@ -413,7 +413,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const /* Font payload */ BOOST_FOREACH (shared_ptr i, _load_font_nodes) { - list::const_iterator j = _fonts.begin (); + auto j = _fonts.begin(); while (j != _fonts.end() && j->load_id != i->id) { ++j; } @@ -462,8 +462,8 @@ SMPTESubtitleAsset::equals (shared_ptr other_asset, EqualityOptions return false; } - list >::const_iterator i = _load_font_nodes.begin (); - list >::const_iterator j = other->_load_font_nodes.begin (); + auto i = _load_font_nodes.begin(); + auto j = other->_load_font_nodes.begin(); while (i != _load_font_nodes.end ()) { if (j == other->_load_font_nodes.end ()) { diff --git a/src/smpte_subtitle_asset.h b/src/smpte_subtitle_asset.h index 6d7019a5..3459f559 100644 --- a/src/smpte_subtitle_asset.h +++ b/src/smpte_subtitle_asset.h @@ -73,7 +73,7 @@ public: NoteHandler note ) const; - std::list > load_font_nodes () const; + std::vector> load_font_nodes () const; std::string xml_as_string () const; void write (boost::filesystem::path path) const; @@ -199,7 +199,7 @@ private: int _time_code_rate; boost::optional