From a5ebd022e7c924f86c3717e06c3e4b90654aaeb4 Mon Sep 17 00:00:00 2001 From: Sam Jenkins <s.jenkins@stfc.ac.uk> Date: Tue, 11 Dec 2018 09:24:28 +0000 Subject: [PATCH] Re #23103 changed owning raw pointers in algorithm and configservice --- Framework/API/inc/MantidAPI/Algorithm.h | 8 ++++---- Framework/API/src/Algorithm.cpp | 20 +++++++++---------- .../Kernel/inc/MantidKernel/ConfigService.h | 5 +++-- Framework/Kernel/src/ConfigService.cpp | 10 ++++------ 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Framework/API/inc/MantidAPI/Algorithm.h b/Framework/API/inc/MantidAPI/Algorithm.h index 37c4df0ab86..912bc7b1738 100644 --- a/Framework/API/inc/MantidAPI/Algorithm.h +++ b/Framework/API/inc/MantidAPI/Algorithm.h @@ -441,15 +441,15 @@ private: // --------------------- Private Members ----------------------------------- /// Poco::ActiveMethod used to implement asynchronous execution. - Poco::ActiveMethod<bool, Poco::Void, Algorithm, - Poco::ActiveStarter<Algorithm>> *m_executeAsync; + std::unique_ptr<Poco::ActiveMethod<bool, Poco::Void, Algorithm, + Poco::ActiveStarter<Algorithm>>> m_executeAsync; /// Sends notifications to observers. Observers can subscribe to /// notificationCenter /// using Poco::NotificationCenter::addObserver(...); - mutable Poco::NotificationCenter *m_notificationCenter; + mutable std::unique_ptr<Poco::NotificationCenter> m_notificationCenter; /// Child algorithm progress observer - mutable Poco::NObserver<Algorithm, ProgressNotification> *m_progressObserver; + mutable std::unique_ptr<Poco::NObserver<Algorithm, ProgressNotification>> m_progressObserver; bool m_isInitialized; ///< Algorithm has been initialized flag bool m_isExecuted; ///< Algorithm is executed flag diff --git a/Framework/API/src/Algorithm.cpp b/Framework/API/src/Algorithm.cpp index 7bf4718f14e..bca85de4090 100644 --- a/Framework/API/src/Algorithm.cpp +++ b/Framework/API/src/Algorithm.cpp @@ -107,11 +107,7 @@ Algorithm::Algorithm() m_communicator(Kernel::make_unique<Parallel::Communicator>()) {} /// Virtual destructor -Algorithm::~Algorithm() { - delete m_notificationCenter; - delete m_executeAsync; - delete m_progressObserver; -} +Algorithm::~Algorithm() {} //============================================================================================= //================================== Simple Getters/Setters @@ -1652,8 +1648,9 @@ private: * Asynchronous execution */ Poco::ActiveResult<bool> Algorithm::executeAsync() { - m_executeAsync = new Poco::ActiveMethod<bool, Poco::Void, Algorithm>( - this, &Algorithm::executeAsyncImpl); + m_executeAsync = + std::make_unique<Poco::ActiveMethod<bool, Poco::Void, Algorithm>>( + this, &Algorithm::executeAsyncImpl); return (*m_executeAsync)(Poco::Void()); } @@ -1672,7 +1669,7 @@ bool Algorithm::executeAsyncImpl(const Poco::Void &) { */ Poco::NotificationCenter &Algorithm::notificationCenter() const { if (!m_notificationCenter) - m_notificationCenter = new Poco::NotificationCenter; + m_notificationCenter = std::make_unique<Poco::NotificationCenter>(); return *m_notificationCenter; } @@ -1692,9 +1689,10 @@ void Algorithm::handleChildProgressNotification( */ const Poco::AbstractObserver &Algorithm::progressObserver() const { if (!m_progressObserver) - m_progressObserver = new Poco::NObserver<Algorithm, ProgressNotification>( - *const_cast<Algorithm *>(this), - &Algorithm::handleChildProgressNotification); + m_progressObserver = + std::make_unique<Poco::NObserver<Algorithm, ProgressNotification>>( + *const_cast<Algorithm *>(this), + &Algorithm::handleChildProgressNotification); return *m_progressObserver; } diff --git a/Framework/Kernel/inc/MantidKernel/ConfigService.h b/Framework/Kernel/inc/MantidKernel/ConfigService.h index 2530996bee6..5e9d462a498 100644 --- a/Framework/Kernel/inc/MantidKernel/ConfigService.h +++ b/Framework/Kernel/inc/MantidKernel/ConfigService.h @@ -19,6 +19,7 @@ #include <set> #include <string> #include <vector> +#include <memory> #include <Poco/Notification.h> #include <Poco/NotificationCenter.h> @@ -288,9 +289,9 @@ private: // Forward declaration of inner class template <class T> class WrappedObject; /// the POCO file config object - WrappedObject<Poco::Util::PropertyFileConfiguration> *m_pConf; + std::unique_ptr<WrappedObject<Poco::Util::PropertyFileConfiguration>> m_pConf; /// the POCO system Config Object - WrappedObject<Poco::Util::SystemConfiguration> *m_pSysConfig; + std::unique_ptr<WrappedObject<Poco::Util::SystemConfiguration>> m_pSysConfig; /// A set of property keys that have been changed mutable std::set<std::string> m_changed_keys; diff --git a/Framework/Kernel/src/ConfigService.cpp b/Framework/Kernel/src/ConfigService.cpp index 5951d5dc97d..34782f05e93 100644 --- a/Framework/Kernel/src/ConfigService.cpp +++ b/Framework/Kernel/src/ConfigService.cpp @@ -169,7 +169,7 @@ ConfigServiceImpl::ConfigServiceImpl() m_DataSearchDirs(), m_UserSearchDirs(), m_InstrumentDirs(), m_instr_prefixes(), m_proxyInfo(), m_isProxySet(false) { // getting at system details - m_pSysConfig = new WrappedObject<Poco::Util::SystemConfiguration>; + m_pSysConfig =std::make_unique<WrappedObject<Poco::Util::SystemConfiguration>>(); m_pConf = nullptr; // Register StdChannel with Poco @@ -280,8 +280,6 @@ ConfigServiceImpl::ConfigServiceImpl() ConfigServiceImpl::~ConfigServiceImpl() { // std::cerr << "ConfigService destroyed.\n"; Kernel::Logger::shutdown(); - delete m_pSysConfig; - delete m_pConf; // potential double delete??? clearFacilities(); } @@ -387,7 +385,7 @@ std::string checkForBadConfigOptions(const std::string &filename, */ void ConfigServiceImpl::loadConfig(const std::string &filename, const bool append) { - delete m_pConf; + if (!append) { // remove the previous property string m_PropertyString = ""; @@ -428,7 +426,7 @@ void ConfigServiceImpl::loadConfig(const std::string &filename, // use the cached property string to initialise the POCO property file std::istringstream istr(m_PropertyString); - m_pConf = new WrappedObject<Poco::Util::PropertyFileConfiguration>(istr); + m_pConf= std::make_unique<WrappedObject<Poco::Util::PropertyFileConfiguration>>(istr); } /** @@ -462,7 +460,7 @@ void ConfigServiceImpl::configureLogging() { try { // Configure the logging framework Poco::Util::LoggingConfigurator configurator; - configurator.configure(m_pConf); + configurator.configure(m_pConf.get()); } catch (std::exception &e) { std::cerr << "Trouble configuring the logging framework " << e.what() << '\n'; -- GitLab