From dfb68bf9190ec0be31f01b61c17aebc8b6e30ad8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 6 Dec 2020 21:36:37 +0100 Subject: Add WeakFilm and WeakConstFilm and use them a bit. --- src/lib/decoder.cc | 10 +------- src/lib/decoder.h | 9 ++----- src/lib/hints.cc | 11 +------- src/lib/hints.h | 5 ++-- src/lib/weak_film.h | 57 +++++++++++++++++++++++++++++++++++++++++ src/wx/smpte_metadata_dialog.cc | 11 +------- src/wx/smpte_metadata_dialog.h | 5 ++-- 7 files changed, 66 insertions(+), 42 deletions(-) create mode 100644 src/lib/weak_film.h (limited to 'src') diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index 0f2bc4358..d51282b53 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -32,7 +32,7 @@ using boost::weak_ptr; using namespace dcpomatic; Decoder::Decoder (weak_ptr film) - : _film (film) + : WeakConstFilm (film) { } @@ -93,11 +93,3 @@ Decoder::only_text () const } return text.front (); } - -shared_ptr -Decoder::film () const -{ - shared_ptr f = _film.lock (); - DCPOMATIC_ASSERT (f); - return f; -} diff --git a/src/lib/decoder.h b/src/lib/decoder.h index 316109ebb..97de208b2 100644 --- a/src/lib/decoder.h +++ b/src/lib/decoder.h @@ -28,6 +28,7 @@ #include "types.h" #include "film.h" #include "dcpomatic_time.h" +#include "weak_film.h" #include class Decoded; @@ -40,7 +41,7 @@ class DecoderPart; /** @class Decoder. * @brief Parent class for decoders of content. */ -class Decoder : public boost::noncopyable +class Decoder : public boost::noncopyable, public WeakConstFilm { public: Decoder (boost::weak_ptr film); @@ -60,12 +61,6 @@ public: virtual void seek (dcpomatic::ContentTime time, bool accurate); virtual dcpomatic::ContentTime position () const; - -protected: - boost::shared_ptr film () const; - -private: - boost::weak_ptr _film; }; #endif diff --git a/src/lib/hints.cc b/src/lib/hints.cc index 23d5a15fb..5c9d3d8a4 100644 --- a/src/lib/hints.cc +++ b/src/lib/hints.cc @@ -56,7 +56,7 @@ using namespace boost::placeholders; #endif Hints::Hints (weak_ptr film) - : _film (film) + : WeakConstFilm (film) , _long_ccap (false) , _overlap_ccap (false) , _too_many_ccap_lines (false) @@ -460,15 +460,6 @@ Hints::open_subtitle (PlayerText text, DCPTimePeriod period) } -shared_ptr -Hints::film () const -{ - shared_ptr film = _film.lock (); - DCPOMATIC_ASSERT (film); - return film; -} - - void Hints::check_ffec_and_ffmc_in_smpte_feature () { diff --git a/src/lib/hints.h b/src/lib/hints.h index e10037763..b8a831301 100644 --- a/src/lib/hints.h +++ b/src/lib/hints.h @@ -23,6 +23,7 @@ #include "types.h" #include "dcp_text_track.h" #include "dcpomatic_time.h" +#include "weak_film.h" #include #include #include @@ -31,7 +32,7 @@ class Film; -class Hints : public Signaller, public ExceptionStore +class Hints : public Signaller, public ExceptionStore, public WeakConstFilm { public: explicit Hints (boost::weak_ptr film); @@ -55,7 +56,6 @@ private: void text (PlayerText text, TextType type, dcpomatic::DCPTimePeriod period); void closed_caption (PlayerText text, dcpomatic::DCPTimePeriod period); void open_subtitle (PlayerText text, dcpomatic::DCPTimePeriod period); - boost::shared_ptr film () const; void check_big_font_files (); void check_few_audio_channels (); @@ -70,7 +70,6 @@ private: void check_loudness (); void check_ffec_and_ffmc_in_smpte_feature (); - boost::weak_ptr _film; boost::thread _thread; bool _long_ccap; diff --git a/src/lib/weak_film.h b/src/lib/weak_film.h new file mode 100644 index 000000000..731101474 --- /dev/null +++ b/src/lib/weak_film.h @@ -0,0 +1,57 @@ +/* + Copyright (C) 2020 Carl Hetherington + + 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 . + +*/ + + +#ifndef DCPOMATIC_WEAK_FILM_H +#define DCPOMATIC_WEAK_FILM_H + + +#include "dcpomatic_assert.h" +#include +#include + + +class Film; + + +template +class WeakFilmTemplate +{ +public: + WeakFilmTemplate (boost::weak_ptr f) + : _film(f) + {} + +protected: + boost::weak_ptr _film; + + boost::shared_ptr film () const { + boost::shared_ptr f = _film.lock(); + DCPOMATIC_ASSERT (f); + return f; + } +}; + + +typedef WeakFilmTemplate WeakConstFilm; +typedef WeakFilmTemplate WeakFilm; + + +#endif diff --git a/src/wx/smpte_metadata_dialog.cc b/src/wx/smpte_metadata_dialog.cc index 156f82ab5..87be156f5 100644 --- a/src/wx/smpte_metadata_dialog.cc +++ b/src/wx/smpte_metadata_dialog.cc @@ -66,7 +66,7 @@ content_versions_column (string v, int) SMPTEMetadataDialog::SMPTEMetadataDialog (wxWindow* parent, weak_ptr weak_film) : wxDialog (parent, wxID_ANY, _("Metadata")) - , _film (weak_film) + , WeakFilm (weak_film) { wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); SetSizer (overall_sizer); @@ -367,15 +367,6 @@ SMPTEMetadataDialog::edit_release_territory () } -shared_ptr -SMPTEMetadataDialog::film () const -{ - shared_ptr film = _film.lock (); - DCPOMATIC_ASSERT (film); - return film; -} - - void SMPTEMetadataDialog::version_number_changed () { diff --git a/src/wx/smpte_metadata_dialog.h b/src/wx/smpte_metadata_dialog.h index 36039c501..0f9c436b9 100644 --- a/src/wx/smpte_metadata_dialog.h +++ b/src/wx/smpte_metadata_dialog.h @@ -21,6 +21,7 @@ #include "editable_list.h" #include "language_tag_dialog.h" #include "lib/film.h" +#include "lib/weak_film.h" #include #include #include @@ -35,7 +36,7 @@ class ContentVersionDialog; class LanguageTagWidget; -class SMPTEMetadataDialog : public wxDialog +class SMPTEMetadataDialog : public wxDialog, public WeakFilm { public: SMPTEMetadataDialog (wxWindow* parent, boost::weak_ptr film); @@ -60,9 +61,7 @@ private: void luminance_changed (); void film_changed (ChangeType type, Film::Property property); void setup_sensitivity (); - boost::shared_ptr film () const; - boost::weak_ptr _film; LanguageTagWidget* _name_language; LanguageTagWidget* _audio_language; wxCheckBox* _enable_main_subtitle_language; -- cgit v1.2.3