Add WeakFilm and WeakConstFilm and use them a bit.
authorCarl Hetherington <cth@carlh.net>
Sun, 6 Dec 2020 20:36:37 +0000 (21:36 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 7 Dec 2020 00:20:25 +0000 (01:20 +0100)
src/lib/decoder.cc
src/lib/decoder.h
src/lib/hints.cc
src/lib/hints.h
src/lib/weak_film.h [new file with mode: 0644]
src/wx/smpte_metadata_dialog.cc
src/wx/smpte_metadata_dialog.h

index 0f2bc4358008e62123e8e042a8247c142e317c71..d51282b537dd1b97fc5f40df73c4b7f91a331d07 100644 (file)
@@ -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;
-}
index 316109ebb95e5eed3d12d3127c75354e3af33f7d..97de208b266b7ea3a95fd839f7dcb16f4edd66c5 100644 (file)
@@ -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
index 23d5a15fb128caaa086b4fc32523dd5b8ce2ac3b..5c9d3d8a41964fc96a33384dce8a2561f7129ffd 100644 (file)
@@ -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 ()
 {
index e100377639bd2a49ce30e9945737cc5c788cce1e..b8a8313014c34ebd18855ef0cbf89f87d36b48ff 100644 (file)
@@ -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 (file)
index 0000000..7311014
--- /dev/null
@@ -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
index 156f82ab5eb3a417882cac6f247090ce9314119a..87be156f51ea597a0ee7f43e26034624d6a68cbe 100644 (file)
@@ -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 ()
 {
index 36039c5018a9fea6a0fc9466b278caaa7b25b4ba..0f9c436b9dd9075271aa04d84769ed3ae581cb9c 100644 (file)
@@ -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;