diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-12-06 21:36:37 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-12-07 01:20:25 +0100 |
| commit | dfb68bf9190ec0be31f01b61c17aebc8b6e30ad8 (patch) | |
| tree | 7df185b2773729f244ab19622f10eb5f746b661f /src | |
| parent | 7c27dff5817715965e86798108c596f9a1675394 (diff) | |
Add WeakFilm and WeakConstFilm and use them a bit.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/decoder.cc | 10 | ||||
| -rw-r--r-- | src/lib/decoder.h | 9 | ||||
| -rw-r--r-- | src/lib/hints.cc | 11 | ||||
| -rw-r--r-- | src/lib/hints.h | 5 | ||||
| -rw-r--r-- | src/lib/weak_film.h | 57 | ||||
| -rw-r--r-- | src/wx/smpte_metadata_dialog.cc | 11 | ||||
| -rw-r--r-- | src/wx/smpte_metadata_dialog.h | 5 |
7 files changed, 66 insertions, 42 deletions
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<const Film> film) - : _film (film) + : WeakConstFilm (film) { } @@ -93,11 +93,3 @@ Decoder::only_text () const } return text.front (); } - -shared_ptr<const Film> -Decoder::film () const -{ - shared_ptr<const Film> 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 <boost/utility.hpp> 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<const Film> film); @@ -60,12 +61,6 @@ public: virtual void seek (dcpomatic::ContentTime time, bool accurate); virtual dcpomatic::ContentTime position () const; - -protected: - boost::shared_ptr<const Film> film () const; - -private: - boost::weak_ptr<const Film> _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<const Film> 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<const Film> -Hints::film () const -{ - shared_ptr<const Film> 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 <boost/weak_ptr.hpp> #include <boost/signals2.hpp> #include <boost/atomic.hpp> @@ -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<const Film> 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<const Film> 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<const Film> _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 <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_WEAK_FILM_H +#define DCPOMATIC_WEAK_FILM_H + + +#include "dcpomatic_assert.h" +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> + + +class Film; + + +template <class T> +class WeakFilmTemplate +{ +public: + WeakFilmTemplate (boost::weak_ptr<T> f) + : _film(f) + {} + +protected: + boost::weak_ptr<T> _film; + + boost::shared_ptr<T> film () const { + boost::shared_ptr<T> f = _film.lock(); + DCPOMATIC_ASSERT (f); + return f; + } +}; + + +typedef WeakFilmTemplate<const Film> WeakConstFilm; +typedef WeakFilmTemplate<Film> 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<Film> 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<Film> -SMPTEMetadataDialog::film () const -{ - shared_ptr<Film> 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 <dcp/language_tag.h> #include <dcp/types.h> #include <wx/wx.h> @@ -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> film); @@ -60,9 +61,7 @@ private: void luminance_changed (); void film_changed (ChangeType type, Film::Property property); void setup_sensitivity (); - boost::shared_ptr<Film> film () const; - boost::weak_ptr<Film> _film; LanguageTagWidget* _name_language; LanguageTagWidget* _audio_language; wxCheckBox* _enable_main_subtitle_language; |
