[vlmc-devel] Project: Use unique_ptr for m_projectFile

Yikai Lu git at videolan.org
Mon Jul 17 17:42:29 CEST 2017


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Mon Jul 17 17:40:48 2017 +0200| [4ec757c196587aafc803ef624bb97bc4b8a5b925] | committer: Yikai Lu

Project: Use unique_ptr for m_projectFile

> https://code.videolan.org/videolan/vlmc/commit/4ec757c196587aafc803ef624bb97bc4b8a5b925
---

 src/Project/Project.cpp | 20 +++++++-------------
 src/Project/Project.h   |  4 +++-
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/src/Project/Project.cpp b/src/Project/Project.cpp
index 795c6b9b..7dc5107d 100644
--- a/src/Project/Project.cpp
+++ b/src/Project/Project.cpp
@@ -72,7 +72,6 @@ Project::Project( Settings* settings )
 
 Project::~Project()
 {
-    delete m_projectFile;
     delete m_settings;
     delete m_timer;
 }
@@ -96,10 +95,10 @@ Project::load( const QString& path )
     bool            outdatedBackupFound = false;
 
     // Always consider the actual project as the project file
-    m_projectFile = new QFile( path );
+    m_projectFile.reset( new QFile( path ) );
     if ( m_projectFile->exists() == false )
     {
-        delete m_projectFile;
+        m_projectFile.release();
         return false;
     }
 
@@ -115,8 +114,7 @@ Project::load( const QString& path )
             if ( autoBackup.open( QFile::ReadOnly ) == false )
             {
                 vlmcCritical() << "Can't open project file" << backupFilename;
-                delete m_projectFile;
-                m_projectFile = nullptr;
+                m_projectFile.release();
                 return false;
             }
             autoBackupFound = true;
@@ -127,8 +125,7 @@ Project::load( const QString& path )
     {
         if ( m_projectFile->open( QFile::ReadOnly ) == false )
         {
-            delete m_projectFile;
-            m_projectFile = nullptr;
+            m_projectFile.release();
             return false;
         }
         m_settings->setSettingsFile( path );
@@ -159,8 +156,7 @@ Project::save()
 void
 Project::saveAs( const QString& fileName )
 {
-    delete m_projectFile;
-    m_projectFile = new QFile( fileName );
+    m_projectFile.reset( new QFile( fileName ) );
     saveProject( fileName );
 }
 
@@ -169,8 +165,7 @@ Project::newProject( const QString& projectName, const QString& projectFilePath
 {
     closeProject();
     m_settings->setValue( "general/ProjectName", projectName );
-    m_projectFile = new QFile( projectFilePath );
-    save();
+    saveAs( projectFilePath );
 }
 
 void
@@ -258,8 +253,7 @@ Project::closeProject()
         return;
     m_settings->restoreDefaultValues();
     emit projectClosed();
-    delete m_projectFile;
-    m_projectFile = nullptr;
+    m_projectFile.release();
 }
 
 bool
diff --git a/src/Project/Project.h b/src/Project/Project.h
index 42a4e69d..b5279bdf 100644
--- a/src/Project/Project.h
+++ b/src/Project/Project.h
@@ -25,6 +25,8 @@
 
 #include "config.h"
 
+#include <memory>
+
 #include <QObject>
 
 class QFile;
@@ -124,7 +126,7 @@ class Project : public QObject
         void                fpsChanged( double fps );
 
     private:
-        QFile*              m_projectFile;
+        std::unique_ptr<QFile>              m_projectFile;
         bool                m_isClean;
         bool                m_libraryCleanState;
         QTimer*             m_timer;



More information about the Vlmc-devel mailing list