Use unique_ptr.
authorCarl Hetherington <cth@carlh.net>
Mon, 5 Jul 2021 13:22:00 +0000 (15:22 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 5 Jul 2021 13:22:56 +0000 (15:22 +0200)
src/lib/player.cc
src/lib/player.h
src/lib/shuffler.h
src/lib/string_text_file.cc

index 3a098c3..5de089b 100644 (file)
@@ -134,12 +134,6 @@ Player::construct ()
 }
 
 
-Player::~Player ()
-{
-       delete _shuffler;
-}
-
-
 void
 Player::setup_pieces ()
 {
@@ -170,8 +164,7 @@ Player::setup_pieces_unlocked ()
        auto old_pieces = _pieces;
        _pieces.clear ();
 
-       delete _shuffler;
-       _shuffler = new Shuffler();
+       _shuffler.reset (new Shuffler());
        _shuffler->Video.connect(bind(&Player::video, this, _1, _2));
 
        for (auto i: playlist()->content()) {
@@ -226,7 +219,7 @@ Player::setup_pieces_unlocked ()
                if (decoder->video) {
                        if (i->video->frame_type() == VideoFrameType::THREE_D_LEFT || i->video->frame_type() == VideoFrameType::THREE_D_RIGHT) {
                                /* We need a Shuffler to cope with 3D L/R video data arriving out of sequence */
-                               decoder->video->Data.connect (bind(&Shuffler::video, _shuffler, weak_ptr<Piece>(piece), _1));
+                               decoder->video->Data.connect (bind(&Shuffler::video, _shuffler.get(), weak_ptr<Piece>(piece), _1));
                        } else {
                                decoder->video->Data.connect (bind(&Player::video, this, weak_ptr<Piece>(piece), _1));
                        }
index daade1d..6cefbe2 100644 (file)
@@ -78,7 +78,6 @@ class Player : public std::enable_shared_from_this<Player>
 public:
        Player (std::shared_ptr<const Film>);
        Player (std::shared_ptr<const Film>, std::shared_ptr<const Playlist> playlist);
-       ~Player ();
 
        Player (Player const& Player) = delete;
        Player& operator= (Player const& Player) = delete;
@@ -208,7 +207,7 @@ private:
        LastVideoMap _last_video;
 
        AudioMerger _audio_merger;
-       Shuffler* _shuffler = nullptr;
+       std::unique_ptr<Shuffler> _shuffler;
        std::list<std::pair<std::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> > _delay;
 
        class StreamState
@@ -239,4 +238,5 @@ private:
        boost::signals2::scoped_connection _playlist_content_change_connection;
 };
 
+
 #endif
index 2b37b70..476f571 100644 (file)
 */
 
 
-#include "types.h"
+#ifndef DCPOMATIC_SHUFFLER_H
+#define DCPOMATIC_SHUFFLER_H
+
+
 #include "content_video.h"
+#include "types.h"
 #include <boost/signals2.hpp>
 
 
 struct shuffler_test5;
 
-
 class Piece;
 
 
@@ -48,3 +51,7 @@ private:
        boost::optional<ContentVideo> _last;
        static int const _max_size;
 };
+
+
+#endif
+
index 78c119d..8c2c565 100644 (file)
@@ -46,15 +46,15 @@ StringTextFile::StringTextFile (shared_ptr<const StringTextFileContent> content)
        string ext = content->path(0).extension().string();
        transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
 
-       sub::Reader* reader = 0;
+       std::unique_ptr<sub::Reader> reader;
 
        if (ext == ".stl") {
-               FILE* f = fopen_boost (content->path(0), "rb");
+               auto f = fopen_boost (content->path(0), "rb");
                if (!f) {
                        throw OpenFileError (content->path(0), errno, OpenFileError::READ);
                }
                try {
-                       reader = new sub::STLBinaryReader (f);
+                       reader.reset(new sub::STLBinaryReader(f));
                } catch (...) {
                        fclose (f);
                        throw;
@@ -100,17 +100,15 @@ StringTextFile::StringTextFile (shared_ptr<const StringTextFileContent> content)
                ucnv_close (to_utf8);
 
                if (ext == ".srt") {
-                       reader = new sub::SubripReader (utf8.get());
+                       reader.reset(new sub::SubripReader(utf8.get()));
                } else if (ext == ".ssa" || ext == ".ass") {
-                       reader = new sub::SSAReader (utf8.get());
+                       reader.reset(new sub::SSAReader(utf8.get()));
                }
        }
 
        if (reader) {
-               _subtitles = sub::collect<vector<sub::Subtitle> > (reader->subtitles ());
+               _subtitles = sub::collect<vector<sub::Subtitle>>(reader->subtitles());
        }
-
-       delete reader;
 }
 
 /** @return time of first subtitle, if there is one */