From c03c0f3ccb67d20b9628d093afded61de9aa21e3 Mon Sep 17 00:00:00 2001 From: Tom Perkins <thomas.perkins@stfc.ac.uk> Date: Mon, 23 Nov 2015 11:58:16 +0000 Subject: [PATCH] Re #14390 Use smart pointers to automate memory management --- .../inc/MantidVatesAPI/MDEWLoadingPresenter.h | 2 +- .../inc/MantidVatesAPI/MDHWLoadingPresenter.h | 2 +- .../VatesAPI/src/EventNexusLoadingPresenter.cpp | 9 +++------ .../src/MDEWEventNexusLoadingPresenter.cpp | 17 +++++++---------- .../src/MDEWInMemoryLoadingPresenter.cpp | 17 +++++++---------- .../src/MDHWInMemoryLoadingPresenter.cpp | 4 ++-- .../VatesAPI/src/MDHWNexusLoadingPresenter.cpp | 7 ++----- Vates/VatesAPI/src/SQWLoadingPresenter.cpp | 7 ++----- 8 files changed, 25 insertions(+), 40 deletions(-) diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/MDEWLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/MDEWLoadingPresenter.h index 7b3b1ebb2f8..618e7d938b2 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/MDEWLoadingPresenter.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/MDEWLoadingPresenter.h @@ -61,7 +61,7 @@ namespace Mantid /*--------------------------------------------------------------------------- Common/shared operations and members for all MDEW file-type loading. ---------------------------------------------------------------------------*/ - MDLoadingView* m_view; + std::unique_ptr<MDLoadingView> m_view; Mantid::Geometry::MDGeometryBuilderXML<Mantid::Geometry::NoDimensionPolicy> xmlBuilder; Mantid::Geometry::IMDDimension_sptr tDimension; diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h index 682c7b81f07..5de80a7565d 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h @@ -65,7 +65,7 @@ protected: /*--------------------------------------------------------------------------- Common/shared operations and members for all MDHW file-type loading. ---------------------------------------------------------------------------*/ - MDLoadingView *m_view; + std::unique_ptr<MDLoadingView> m_view; Mantid::Geometry::MDGeometryBuilderXML<Mantid::Geometry::NoDimensionPolicy> xmlBuilder; diff --git a/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp b/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp index 1501c4fe652..18141371a9c 100644 --- a/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp @@ -33,7 +33,7 @@ namespace Mantid { throw std::invalid_argument("File name is an empty string."); } - if (NULL == this->m_view) + if (nullptr == this->m_view) { throw std::invalid_argument("View is NULL."); } @@ -168,11 +168,8 @@ namespace Mantid throw std::runtime_error("Does not have a 4th Dimension, so can be no T-axis"); } - ///Destructor - EventNexusLoadingPresenter::~EventNexusLoadingPresenter() - { - delete m_view; - } + /// Destructor + EventNexusLoadingPresenter::~EventNexusLoadingPresenter() {} /** Executes any meta-data loading required. diff --git a/Vates/VatesAPI/src/MDEWEventNexusLoadingPresenter.cpp b/Vates/VatesAPI/src/MDEWEventNexusLoadingPresenter.cpp index 79592b54bd1..b9e513cf9a6 100644 --- a/Vates/VatesAPI/src/MDEWEventNexusLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDEWEventNexusLoadingPresenter.cpp @@ -30,7 +30,7 @@ namespace Mantid { throw std::invalid_argument("File name is an empty string."); } - if(NULL == this->m_view) + if(nullptr == this->m_view) { throw std::invalid_argument("View is NULL."); } @@ -135,16 +135,13 @@ namespace Mantid AnalysisDataService::Instance().remove("MD_EVENT_WS_ID"); } - ///Destructor - MDEWEventNexusLoadingPresenter::~MDEWEventNexusLoadingPresenter() - { - delete m_view; - } + /// Destructor + MDEWEventNexusLoadingPresenter::~MDEWEventNexusLoadingPresenter() {} - /* - Getter for the workspace type name. - @return Workspace Type Name - */ + /* +Getter for the workspace type name. +@return Workspace Type Name +*/ std::string MDEWEventNexusLoadingPresenter::getWorkspaceTypeName() { return m_wsTypeName; diff --git a/Vates/VatesAPI/src/MDEWInMemoryLoadingPresenter.cpp b/Vates/VatesAPI/src/MDEWInMemoryLoadingPresenter.cpp index 4dbaf48cbfc..8ccdcee01eb 100644 --- a/Vates/VatesAPI/src/MDEWInMemoryLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDEWInMemoryLoadingPresenter.cpp @@ -33,7 +33,7 @@ namespace Mantid { throw std::invalid_argument("The repository is NULL"); } - if(NULL == m_view) + if(nullptr == m_view) { throw std::invalid_argument("View is NULL."); } @@ -127,16 +127,13 @@ namespace Mantid this->extractMetadata(eventWs); } - ///Destructor - MDEWInMemoryLoadingPresenter::~MDEWInMemoryLoadingPresenter() - { - delete m_view; - } + /// Destructor + MDEWInMemoryLoadingPresenter::~MDEWInMemoryLoadingPresenter() {} - /* - Getter for the workspace type name. - @return Workspace Type Name - */ + /* + Getter for the workspace type name. + @return Workspace Type Name + */ std::string MDEWInMemoryLoadingPresenter::getWorkspaceTypeName() { return m_wsTypeName; diff --git a/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp b/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp index cd33892016a..f276e40e97c 100644 --- a/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp @@ -32,7 +32,7 @@ MDHWInMemoryLoadingPresenter::MDHWInMemoryLoadingPresenter( if (NULL == repository) { throw std::invalid_argument("The repository is NULL"); } - if (NULL == m_view) { + if (nullptr == m_view) { throw std::invalid_argument("View is NULL."); } } @@ -138,7 +138,7 @@ void MDHWInMemoryLoadingPresenter::executeLoadMetadata() { } /// Destructor -MDHWInMemoryLoadingPresenter::~MDHWInMemoryLoadingPresenter() { delete m_view; } +MDHWInMemoryLoadingPresenter::~MDHWInMemoryLoadingPresenter() {} /* * Getter for the workspace type name. diff --git a/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp b/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp index eec4a5a3b10..42fd16b2b8a 100644 --- a/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp @@ -30,7 +30,7 @@ MDHWNexusLoadingPresenter::MDHWNexusLoadingPresenter(MDLoadingView* view, const { throw std::invalid_argument("File name is an empty string."); } - if(NULL == this->m_view) + if(nullptr == this->m_view) { throw std::invalid_argument("View is NULL."); } @@ -113,10 +113,7 @@ void MDHWNexusLoadingPresenter::executeLoadMetadata() * Destructor * @return */ -MDHWNexusLoadingPresenter::~MDHWNexusLoadingPresenter() -{ - delete m_view; -} +MDHWNexusLoadingPresenter::~MDHWNexusLoadingPresenter() {} /** * Getter for the workspace type name. diff --git a/Vates/VatesAPI/src/SQWLoadingPresenter.cpp b/Vates/VatesAPI/src/SQWLoadingPresenter.cpp index 7e51bd61e9f..d4483dce2b1 100644 --- a/Vates/VatesAPI/src/SQWLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/SQWLoadingPresenter.cpp @@ -27,7 +27,7 @@ namespace Mantid { throw std::invalid_argument("File name is an empty string."); } - if(NULL == this->m_view) + if(nullptr == this->m_view) { throw std::invalid_argument("View is NULL."); } @@ -162,10 +162,7 @@ namespace Mantid } ///Destructor - SQWLoadingPresenter::~SQWLoadingPresenter() - { - delete m_view; - } + SQWLoadingPresenter::~SQWLoadingPresenter() {} /* Getter for the workspace type name. -- GitLab