Cleanup: pass EqualityOptions as const&
[libdcp.git] / src / interop_subtitle_asset.cc
index 0faf7bd5330c15f47335e3e25ad0d22e3eb3d2bf..e7c1432b75ee56b6972020a85c4c93175aaa275e 100644 (file)
@@ -140,7 +140,7 @@ InteropSubtitleAsset::add_font (string load_id, dcp::ArrayData data)
 
 
 bool
-InteropSubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions options, NoteHandler note) const
+InteropSubtitleAsset::equals(shared_ptr<const Asset> other_asset, EqualityOptions const& options, NoteHandler note) const
 {
        if (!SubtitleAsset::equals (other_asset, options, note)) {
                return false;
@@ -214,13 +214,10 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const
        /* Fonts */
        for (auto i: _load_font_nodes) {
                auto file = p.parent_path() / i->uri;
-               auto j = _fonts.begin();
-               while (j != _fonts.end() && j->load_id != i->id) {
-                       ++j;
-               }
-               if (j != _fonts.end ()) {
-                       j->data.write (file);
-                       j->file = file;
+               auto font_with_id = std::find_if(_fonts.begin(), _fonts.end(), [i](Font const& font) { return font.load_id == i->id; });
+               if (font_with_id != _fonts.end()) {
+                       font_with_id->data.write(file);
+                       font_with_id->file = file;
                }
        }
 }
@@ -239,37 +236,44 @@ InteropSubtitleAsset::resolve_fonts (vector<shared_ptr<Asset>> assets)
                        continue;
                }
 
-               for (auto load_font_node: _load_font_nodes) {
-                       auto iter = std::find_if(_fonts.begin(), _fonts.end(), [load_font_node](Font const& font) { return font.load_id == load_font_node->id; });
+               DCP_ASSERT(_file);
 
-                       DCP_ASSERT(_file);
+               for (auto load_font_node: _load_font_nodes) {
                        auto const path_in_load_font_node = _file->parent_path() / load_font_node->uri;
-
-                       if (iter == _fonts.end() && font->file() && path_in_load_font_node == *font->file()) {
-                               _fonts.push_back(Font(load_font_node->id, asset->id(), font->file().get()));
+                       if (font->file() && path_in_load_font_node == *font->file()) {
+                               auto existing = std::find_if(_fonts.begin(), _fonts.end(), [load_font_node](Font const& font) { return font.load_id == load_font_node->id; });
+                               if (existing != _fonts.end()) {
+                                       *existing = Font(load_font_node->id, asset->id(), font->file().get());
+                               } else {
+                                       _fonts.push_back(Font(load_font_node->id, asset->id(), font->file().get()));
+                               }
                        }
                }
        }
 }
 
 
-void
-InteropSubtitleAsset::add_font_assets (vector<shared_ptr<Asset>>& assets)
+vector<shared_ptr<Asset>>
+InteropSubtitleAsset::font_assets()
 {
+       vector<shared_ptr<Asset>> assets;
        for (auto const& i: _fonts) {
                DCP_ASSERT (i.file);
-               assets.push_back (make_shared<FontAsset>(i.uuid, i.file.get()));
+               assets.push_back(make_shared<FontAsset>(i.uuid, i.file.get()));
        }
+       return assets;
 }
 
 
-void
-InteropSubtitleAsset::add_font_assets(vector<shared_ptr<const Asset>>& assets)
+vector<shared_ptr<const Asset>>
+InteropSubtitleAsset::font_assets() const
 {
+       vector<shared_ptr<const Asset>> assets;
        for (auto const& i: _fonts) {
                DCP_ASSERT (i.file);
-               assets.push_back (make_shared<FontAsset>(i.uuid, i.file.get()));
+               assets.push_back(make_shared<const FontAsset>(i.uuid, i.file.get()));
        }
+       return assets;
 }