summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-01-08 16:25:42 +0100
committerCarl Hetherington <cth@carlh.net>2024-01-09 11:54:16 +0100
commit12d1abf033654727d6ab6278087ff7cfc65d63f6 (patch)
treeb920b3c3614fc91a1cb2a220972042e6318a6fd4 /src/lib
parentad41d2dd987ffcd2068d9fbf4273108c9f796762 (diff)
Move ScopeGuard into libdcp.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/audio_buffers.cc6
-rw-r--r--src/lib/dcp_content.cc4
-rw-r--r--src/lib/scope_guard.h57
-rw-r--r--src/lib/util.cc4
-rw-r--r--src/lib/video_filter_graph.cc4
5 files changed, 9 insertions, 66 deletions
diff --git a/src/lib/audio_buffers.cc b/src/lib/audio_buffers.cc
index 0e31793ea..9b88827f7 100644
--- a/src/lib/audio_buffers.cc
+++ b/src/lib/audio_buffers.cc
@@ -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);
diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc
index b9b64149f..f3751b1d8 100644
--- a/src/lib/dcp_content.cc
+++ b/src/lib/dcp_content.cc
@@ -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
index ac60f9fea..000000000
--- a/src/lib/scope_guard.h
+++ /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
-
diff --git a/src/lib/util.cc b/src/lib/util.cc
index d23989afa..997470a21 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -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;
}
diff --git a/src/lib/video_filter_graph.cc b/src/lib/video_filter_graph.cc
index 89467ae94..d5840c6d3 100644
--- a/src/lib/video_filter_graph.cc
+++ b/src/lib/video_filter_graph.cc
@@ -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];