Move ScopeGuard into libdcp.
authorCarl Hetherington <cth@carlh.net>
Mon, 8 Jan 2024 15:25:42 +0000 (16:25 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 9 Jan 2024 10:54:16 +0000 (11:54 +0100)
19 files changed:
cscript
src/lib/audio_buffers.cc
src/lib/dcp_content.cc
src/lib/scope_guard.h [deleted file]
src/lib/util.cc
src/lib/video_filter_graph.cc
src/tools/dcpomatic_player.cc
src/wx/content_panel.cc
src/wx/controls.cc
src/wx/fonts_dialog.cc
src/wx/language_tag_widget.cc
src/wx/region_subtag_widget.cc
src/wx/screen_dialog.cc
src/wx/screens_panel.cc
src/wx/text_panel.cc
src/wx/timeline.cc
src/wx/timing_panel.cc
test/scope_guard_test.cc [deleted file]
test/wscript

diff --git a/cscript b/cscript
index fde56ad7741229e72970f1a1167e7c1ad291dc54..7ef3b1c0d46be7c2b954d3643ff8172249381a85 100644 (file)
--- a/cscript
+++ b/cscript
@@ -507,7 +507,7 @@ def dependencies(target, options):
         # Use distro-provided FFmpeg on Arch
         deps = []
 
-    deps.append(('libdcp', 'v1.8.92'))
+    deps.append(('libdcp', 'v1.8.93'))
     deps.append(('libsub', 'v1.6.45'))
     deps.append(('leqm-nrt', '30dcaea1373ac62fba050e02ce5b0c1085797a23'))
     deps.append(('rtaudio', 'f619b76'))
index 0e31793ea2d7634035343fb2245e562af442b9a0..9b88827f7af816252ec0bb7e6f23b788acccebae 100644 (file)
@@ -22,7 +22,7 @@
 #include "audio_buffers.h"
 #include "dcpomatic_assert.h"
 #include "maths_util.h"
-#include "scope_guard.h"
+#include <dcp/scope_guard.h>
 #include <cassert>
 #include <cstring>
 #include <cmath>
@@ -83,7 +83,7 @@ AudioBuffers::allocate (int channels, int frames)
        DCPOMATIC_ASSERT (frames >= 0);
        DCPOMATIC_ASSERT(frames == 0 || channels > 0);
 
-       ScopeGuard sg = [this]() { update_data_pointers(); };
+       dcp::ScopeGuard sg = [this]() { update_data_pointers(); };
 
        _data.resize(channels);
        for (int channel = 0; channel < channels; ++channel) {
@@ -344,7 +344,7 @@ AudioBuffers::set_channels(int new_channels)
 {
        DCPOMATIC_ASSERT(new_channels > 0);
 
-       ScopeGuard sg = [this]() { update_data_pointers(); };
+       dcp::ScopeGuard sg = [this]() { update_data_pointers(); };
 
        int const old_channels = channels();
        _data.resize(new_channels);
index b9b64149f1984832f200806be88c413eaf0fb235..f3751b1d83e665c0ae909ab48ba749be7488b404 100644 (file)
@@ -31,7 +31,6 @@
 #include "job.h"
 #include "log.h"
 #include "overlaps.h"
-#include "scope_guard.h"
 #include "text_content.h"
 #include "video_content.h"
 #include <dcp/dcp.h>
@@ -41,6 +40,7 @@
 #include <dcp/reel_picture_asset.h>
 #include <dcp/reel_subtitle_asset.h>
 #include <dcp/reel.h>
+#include <dcp/scope_guard.h>
 #include <libxml++/libxml++.h>
 #include <iterator>
 #include <iostream>
@@ -224,7 +224,7 @@ DCPContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
        string const old_name = name ();
 
        ContentChangeSignalDespatcher::instance()->suspend();
-       ScopeGuard sg = []() {
+       dcp::ScopeGuard sg = []() {
                ContentChangeSignalDespatcher::instance()->resume();
        };
 
diff --git a/src/lib/scope_guard.h b/src/lib/scope_guard.h
deleted file mode 100644 (file)
index ac60f9f..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-    Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
-
-    This file is part of DCP-o-matic.
-
-    DCP-o-matic is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    DCP-o-matic is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-
-#ifndef DCPOMATIC_SCOPE_GUARD_H
-#define DCPOMATIC_SCOPE_GUARD_H
-
-
-#include <functional>
-
-
-class ScopeGuard
-{
-public:
-       template <typename F>
-       ScopeGuard (F const& function)
-               : _function(function)
-       {}
-
-       ScopeGuard (ScopeGuard&& other)
-               : _function(std::move(other._function))
-       {
-               other._function = []{};
-       }
-
-       ScopeGuard (ScopeGuard const&) = delete;
-       ScopeGuard& operator=(ScopeGuard const&) = delete;
-
-       ~ScopeGuard ()
-       {
-               _function();
-       }
-
-private:
-       std::function<void()> _function;
-};
-
-
-#endif
-
index d23989afaadff0556842b8ba5fe6f01e86b96efd..997470a210d9437d87efa81a8bf1e12a81e8d69e 100644 (file)
@@ -46,7 +46,6 @@
 #include "ratio.h"
 #include "rect.h"
 #include "render_text.h"
-#include "scope_guard.h"
 #include "string_text.h"
 #include "text_decoder.h"
 #include "util.h"
@@ -58,6 +57,7 @@
 #include <dcp/locale_convert.h>
 #include <dcp/picture_asset.h>
 #include <dcp/raw_convert.h>
+#include <dcp/scope_guard.h>
 #include <dcp/sound_asset.h>
 #include <dcp/subtitle_asset.h>
 #include <dcp/util.h>
@@ -1094,7 +1094,7 @@ word_wrap(string input, int columns)
        icu::Locale locale;
        UErrorCode status = U_ZERO_ERROR;
        auto iter = icu::BreakIterator::createLineInstance(locale, status);
-       ScopeGuard sg = [iter]() { delete iter; };
+       dcp::ScopeGuard sg = [iter]() { delete iter; };
        if (U_FAILURE(status)) {
                return input;
        }
index 89467ae94e50746dccd5704f8be099bc78b9e9a2..d5840c6d3b6790e8364599b4416f1ac232390ac4 100644 (file)
@@ -23,8 +23,8 @@
 #include "dcpomatic_assert.h"
 #include "exceptions.h"
 #include "image.h"
-#include "scope_guard.h"
 #include "video_filter_graph.h"
+#include <dcp/scope_guard.h>
 extern "C" {
 #include <libavfilter/buffersrc.h>
 #include <libavfilter/buffersink.h>
@@ -63,7 +63,7 @@ VideoFilterGraph::process(shared_ptr<const Image> image)
                throw std::bad_alloc();
        }
 
-       ScopeGuard sg = [&frame]() { av_frame_free(&frame); };
+       dcp::ScopeGuard sg = [&frame]() { av_frame_free(&frame); };
 
        for (int i = 0; i < image->planes(); ++i) {
                frame->data[i] = image->data()[i];
index 133cabf9548522f3f294ff0712b5bc69513427b9..301e893ff66005be50ceca0963e153112d2cb906 100644 (file)
@@ -59,7 +59,6 @@
 #include "lib/player.h"
 #include "lib/player_video.h"
 #include "lib/ratio.h"
-#include "lib/scope_guard.h"
 #include "lib/scoped_temporary.h"
 #include "lib/server.h"
 #include "lib/text_content.h"
@@ -71,6 +70,7 @@
 #include <dcp/exceptions.h>
 #include <dcp/filesystem.h>
 #include <dcp/raw_convert.h>
+#include <dcp/scope_guard.h>
 #include <dcp/search.h>
 #include <dcp/warnings.h>
 LIBDCP_DISABLE_WARNINGS
@@ -707,7 +707,7 @@ private:
                        DCPOMATIC_ASSERT (dcp);
                        try {
                                if (dcp) {
-                                       ScopeGuard sg([this]() {
+                                       dcp::ScopeGuard sg([this]() {
                                                _viewer.set_coalesce_player_changes(false);
                                        });
                                        _viewer.set_coalesce_player_changes(true);
index 8a98bc1a43d706ee78336f1c61a8171ec9629d7f..1f54ae0cf8a17ccbfcb7044472edb2bf38c0e68a 100644 (file)
 #include "lib/image_content.h"
 #include "lib/log.h"
 #include "lib/playlist.h"
-#include "lib/scope_guard.h"
 #include "lib/string_text_file.h"
 #include "lib/string_text_file_content.h"
 #include "lib/text_content.h"
 #include "lib/video_content.h"
 #include <dcp/filesystem.h>
+#include <dcp/scope_guard.h>
 #include <dcp/warnings.h>
 LIBDCP_DISABLE_WARNINGS
 #include <wx/display.h>
@@ -820,7 +820,7 @@ ContentPanel::set_selection (ContentList cl)
 {
        {
                _no_check_selection = true;
-               ScopeGuard sg = [this]() { _no_check_selection = false; };
+               dcp::ScopeGuard sg = [this]() { _no_check_selection = false; };
 
                auto content = _film->content ();
                for (size_t i = 0; i < content.size(); ++i) {
index 0bb0960c8bd680c068dbd21336b1e45aefd53929..097daf9443a093fd71d966231ffad93b82aa3211 100644 (file)
@@ -37,7 +37,6 @@
 #include "lib/job.h"
 #include "lib/job_manager.h"
 #include "lib/player_video.h"
-#include "lib/scope_guard.h"
 #include <dcp/cpl.h>
 #include <dcp/dcp.h>
 #include <dcp/reel.h>
index f2c9de5cb1c1cd673646678dd44327c59488c21b..2fecdc086433996267e0a9dc6ef8959697cc5bc9 100644 (file)
@@ -25,7 +25,6 @@
 #include "wx_util.h"
 #include "lib/content.h"
 #include "lib/font.h"
-#include "lib/scope_guard.h"
 #include "lib/text_content.h"
 #include <dcp/filesystem.h>
 #include <dcp/warnings.h>
index 17683daf1e966bf35747cc7b66e75908aa0d18db..2f6ad2b8a4a06bc3f3258cd68a019bc83fa0933d 100644 (file)
@@ -23,7 +23,6 @@
 #include "language_tag_dialog.h"
 #include "language_tag_widget.h"
 #include "wx_util.h"
-#include "lib/scope_guard.h"
 #include <dcp/warnings.h>
 LIBDCP_DISABLE_WARNINGS
 #include <wx/wx.h>
index 66bba2285970ed7a8f90e10d569b88404d397dae..d2c99762a25675aa75cf9f030a211e7e1b36b457 100644 (file)
@@ -24,7 +24,6 @@
 #include "region_subtag_dialog.h"
 #include "region_subtag_widget.h"
 #include "wx_util.h"
-#include "lib/scope_guard.h"
 #include <dcp/warnings.h>
 LIBDCP_DISABLE_WARNINGS
 #include <wx/wx.h>
index 3b2a1bd8560f502eb970f3315e8fc1dfb5b9c3fc..0040ac31bcb9dcc6898deb3769be7427de17d9fb 100644 (file)
@@ -27,7 +27,6 @@
 #include "table_dialog.h"
 #include "wx_util.h"
 #include "lib/compose.hpp"
-#include "lib/scope_guard.h"
 #include "lib/util.h"
 #include <dcp/warnings.h>
 #include <dcp/exceptions.h>
index 721f4f4ccb35f11c1e142d2601b9ee5ed8c6e7cb..d3b1db77d4e36da0a04323244ac368922ec8789b 100644 (file)
@@ -27,9 +27,9 @@
 #include "wx_util.h"
 #include "lib/cinema.h"
 #include "lib/config.h"
-#include "lib/scope_guard.h"
 #include "lib/screen.h"
 #include "lib/timer.h"
+#include <dcp/scope_guard.h>
 
 
 using std::cout;
@@ -258,7 +258,7 @@ ScreensPanel::add_cinema_clicked ()
 
                try {
                        _ignore_cinemas_changed = true;
-                       ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
+                       dcp::ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
                        Config::instance()->add_cinema(cinema);
                } catch (FileError& e) {
                        error_dialog(GetParent(), _("Could not write cinema details to the cinemas.xml file.  Check that the location of cinemas.xml is valid in DCP-o-matic's preferences."), std_to_wx(e.what()));
@@ -355,7 +355,7 @@ ScreensPanel::remove_cinema_clicked ()
 
        for (auto const& cinema: cinemas_to_remove) {
                _ignore_cinemas_changed = true;
-               ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
+               dcp::ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
                for (auto screen: cinema->screens()) {
                        _checked_screens.erase(screen);
                }
@@ -717,7 +717,7 @@ bool
 ScreensPanel::notify_cinemas_changed()
 {
        _ignore_cinemas_changed = true;
-       ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
+       dcp::ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
 
        try {
                Config::instance()->changed(Config::CINEMAS);
index 3b7973e3021760f3f32700ed7b64abb765bb3f54..78c024565eb95434805ae3a5836b4a03abafb16a 100644 (file)
 #include "lib/ffmpeg_subtitle_stream.h"
 #include "lib/film.h"
 #include "lib/job_manager.h"
-#include "lib/scope_guard.h"
 #include "lib/string_text_file_content.h"
 #include "lib/string_text_file_decoder.h"
 #include "lib/subtitle_analysis.h"
 #include "lib/text_content.h"
 #include <dcp/filesystem.h>
+#include <dcp/scope_guard.h>
 #include <dcp/warnings.h>
 LIBDCP_DISABLE_WARNINGS
 #include <wx/spinctrl.h>
@@ -813,7 +813,7 @@ TextPanel::try_to_load_analysis ()
        }
 
        _loading_analysis = true;
-       ScopeGuard sg = [this]() {
+       dcp::ScopeGuard sg = [this]() {
                _loading_analysis = false;
                setup_sensitivity();
        };
index 9af8c3b85cb15ae4e0b11ae1fffc326d968bfcd1..4683769d403f423316e95ad0d841cb8b131b3466 100644 (file)
 #include "lib/film.h"
 #include "lib/image_content.h"
 #include "lib/playlist.h"
-#include "lib/scope_guard.h"
 #include "lib/text_content.h"
 #include "lib/timer.h"
 #include "lib/video_content.h"
+#include <dcp/scope_guard.h>
 #include <dcp/warnings.h>
 LIBDCP_DISABLE_WARNINGS
 #include <wx/graphics.h>
@@ -161,7 +161,7 @@ Timeline::paint_labels ()
                return;
        }
 
-       ScopeGuard sg = [gc]() { delete gc; };
+       dcp::ScopeGuard sg = [gc]() { delete gc; };
 
        int vsx, vsy;
        _labels_canvas->GetViewStart (&vsx, &vsy);
@@ -189,7 +189,7 @@ Timeline::paint_main ()
                return;
        }
 
-       ScopeGuard sg = [gc]() { delete gc; };
+       dcp::ScopeGuard sg = [gc]() { delete gc; };
 
        gc->SetAntialiasMode (wxANTIALIAS_DEFAULT);
 
index 98060bb87322c0a64122d4587a469917fbf67e08..55d9a5fbf6c10cae30e75bcd8ea2b0eca8556f65 100644 (file)
@@ -34,7 +34,6 @@
 #include "lib/ffmpeg_content.h"
 #include "lib/film.h"
 #include "lib/image_content.h"
-#include "lib/scope_guard.h"
 #include "lib/string_text_file_content.h"
 #include "lib/text_content.h"
 #include "lib/video_content.h"
diff --git a/test/scope_guard_test.cc b/test/scope_guard_test.cc
deleted file mode 100644 (file)
index f984f50..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-    Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
-
-    This file is part of DCP-o-matic.
-
-    DCP-o-matic is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    DCP-o-matic is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-
-#include "lib/scope_guard.h"
-#include <boost/test/unit_test.hpp>
-
-
-BOOST_AUTO_TEST_CASE (scope_guard_test)
-{
-       int x = 0;
-
-       {
-               ScopeGuard sg = [&x]() { x = 42; };
-               BOOST_CHECK_EQUAL (x, 0);
-       }
-
-       BOOST_CHECK_EQUAL (x, 42);
-}
index e8762009c736c1d5409e361b742ed7ceffba23f9..c5b06cc9e50c3fd6c8643e248b065769f8a3a975 100644 (file)
@@ -138,7 +138,6 @@ def build(bld):
                  remake_with_subtitle_test.cc
                  render_subtitles_test.cc
                  scaling_test.cc
-                 scope_guard_test.cc
                  scoped_temporary_test.cc
                  silence_padding_test.cc
                  shuffler_test.cc