diff --git a/Framework/API/inc/MantidAPI/Algorithm.h b/Framework/API/inc/MantidAPI/Algorithm.h index 37c4df0ab86e57e1c2c58dda569702dae656609a..22c0052248afc5cbd5ed379f1b10cba6354d6ac6 100644 --- a/Framework/API/inc/MantidAPI/Algorithm.h +++ b/Framework/API/inc/MantidAPI/Algorithm.h @@ -441,15 +441,17 @@ 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/inc/MantidAPI/IFunction.h b/Framework/API/inc/MantidAPI/IFunction.h index 31fd0923a40fa9fa5f782c5843328fb762cf5194..976f91742f0fe916dbc03cd3e358ba972699e7c3 100644 --- a/Framework/API/inc/MantidAPI/IFunction.h +++ b/Framework/API/inc/MantidAPI/IFunction.h @@ -534,9 +534,9 @@ public: bool isParallel() const { return m_isParallel; } /// Set a function handler - void setHandler(FunctionHandler *handler); + void setHandler(std::unique_ptr<FunctionHandler> handler); /// Return the handler - FunctionHandler *getHandler() const { return m_handler; } + FunctionHandler *getHandler() const { return m_handler.get(); } /// Describe parameter status in relation to fitting: /// Active: Fit varies such parameter directly. @@ -597,7 +597,7 @@ protected: bool m_isParallel; /// Pointer to a function handler - FunctionHandler *m_handler; + std::unique_ptr<FunctionHandler> m_handler; /// Pointer to the progress handler boost::shared_ptr<Kernel::ProgressBase> m_progReporter; diff --git a/Framework/API/inc/MantidAPI/Sample.h b/Framework/API/inc/MantidAPI/Sample.h index af2a5f6199aab87a5a27f987efcf5a9d05b36598..9e7f7ba256f26c351cb7b0b535a2a0cea4fd1713 100644 --- a/Framework/API/inc/MantidAPI/Sample.h +++ b/Framework/API/inc/MantidAPI/Sample.h @@ -127,7 +127,7 @@ private: /// An owned pointer to the SampleEnvironment object boost::shared_ptr<Geometry::SampleEnvironment> m_environment; /// Pointer to the OrientedLattice of the sample, NULL if not set. - Geometry::OrientedLattice *m_lattice; + std::unique_ptr<Geometry::OrientedLattice> m_lattice; /// CrystalStructure of the sample std::unique_ptr<Geometry::CrystalStructure> m_crystalStructure; diff --git a/Framework/API/src/Algorithm.cpp b/Framework/API/src/Algorithm.cpp index 7bf4718f14e411bddaa53c2fe382185b037c1d88..bca85de4090054db07337f38aac8286666a32455 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/API/src/IFunction.cpp b/Framework/API/src/IFunction.cpp index 74d02c7dc04146465946f9a4ab9e30a1aaf6efbc..887c0892f8798c17846f127ad097b0db14e823d4 100644 --- a/Framework/API/src/IFunction.cpp +++ b/Framework/API/src/IFunction.cpp @@ -66,13 +66,7 @@ struct TieNode { /** * Destructor */ -IFunction::~IFunction() { - m_attrs.clear(); - if (m_handler) { - delete m_handler; - m_handler = nullptr; - } -} +IFunction::~IFunction() { m_attrs.clear(); } /** * Virtual copy constructor @@ -558,8 +552,8 @@ std::vector<std::string> IFunction::getParameterNames() const { /** Set a function handler * @param handler :: A new handler */ -void IFunction::setHandler(FunctionHandler *handler) { - m_handler = handler; +void IFunction::setHandler(std::unique_ptr<FunctionHandler> handler) { + m_handler = std::move(handler); if (handler && handler->function().get() != this) { throw std::runtime_error("Function handler points to a different function"); } diff --git a/Framework/API/src/Sample.cpp b/Framework/API/src/Sample.cpp index fa1078cd5c8c9eb1701fdc166edf502ea669856f..a6a06f5b07d363412697dce657bbd395287ebf83 100644 --- a/Framework/API/src/Sample.cpp +++ b/Framework/API/src/Sample.cpp @@ -48,16 +48,16 @@ Sample::Sample(const Sample ©) m_geom_id(copy.m_geom_id), m_thick(copy.m_thick), m_height(copy.m_height), m_width(copy.m_width) { if (copy.m_lattice) - m_lattice = new OrientedLattice(copy.getOrientedLattice()); + m_lattice = std::make_unique<OrientedLattice>(copy.getOrientedLattice()); if (copy.hasCrystalStructure()) { - m_crystalStructure.reset( - new Geometry::CrystalStructure(copy.getCrystalStructure())); + m_crystalStructure = std::make_unique<Geometry::CrystalStructure>( + copy.getCrystalStructure()); } } /// Destructor -Sample::~Sample() { delete m_lattice; } +Sample::~Sample() = default; /** Assignment operator * @param rhs :: const reference to the sample object @@ -75,12 +75,10 @@ Sample &Sample::operator=(const Sample &rhs) { m_thick = rhs.m_thick; m_height = rhs.m_height; m_width = rhs.m_width; - if (m_lattice != nullptr) - delete m_lattice; if (rhs.m_lattice) - m_lattice = new OrientedLattice(rhs.getOrientedLattice()); + m_lattice = std::make_unique<OrientedLattice>(rhs.getOrientedLattice()); else - m_lattice = nullptr; + m_lattice.reset(nullptr); m_crystalStructure.reset(); if (rhs.hasCrystalStructure()) { @@ -179,13 +177,10 @@ OrientedLattice &Sample::getOrientedLattice() { * @param latt :: A pointer to a OrientedLattice. */ void Sample::setOrientedLattice(OrientedLattice *latt) { - if (m_lattice != nullptr) { - delete m_lattice; - } if (latt != nullptr) - m_lattice = new OrientedLattice(*latt); + m_lattice = std::make_unique<OrientedLattice>(*latt); else - m_lattice = nullptr; + m_lattice.reset(nullptr); } /** @return true if the sample has an OrientedLattice */ @@ -394,7 +389,7 @@ int Sample::loadNexus(::NeXus::File *file, const std::string &group) { int num_oriented_lattice; file->readData("num_oriented_lattice", num_oriented_lattice); if (num_oriented_lattice > 0) { - m_lattice = new OrientedLattice; + m_lattice = std::make_unique<OrientedLattice>(); m_lattice->loadNexus(file, "oriented_lattice"); } } @@ -418,8 +413,7 @@ int Sample::loadNexus(::NeXus::File *file, const std::string &group) { */ void Sample::clearOrientedLattice() { if (m_lattice) { - delete m_lattice; - m_lattice = nullptr; + m_lattice.reset(nullptr); } } } // namespace API diff --git a/Framework/Algorithms/inc/MantidAlgorithms/AlignDetectors.h b/Framework/Algorithms/inc/MantidAlgorithms/AlignDetectors.h index f6142bb49c5dbddf979a6f94cfdf5303a2a23f1c..74198235cb60dc8293acca81e86fa32879b796fe 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/AlignDetectors.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/AlignDetectors.h @@ -43,7 +43,6 @@ class ConversionFactors; class DLLExport AlignDetectors : public API::Algorithm { public: AlignDetectors(); - ~AlignDetectors() override; /// Algorithms name for identification. @see Algorithm::name const std::string name() const override; @@ -83,9 +82,6 @@ private: /// number of spectra in input workspace int64_t m_numberOfSpectra; - - /// Map of conversion factors for TOF to d-Spacing conversion - std::map<detid_t, double> *tofToDmap; }; } // namespace Algorithms diff --git a/Framework/Algorithms/inc/MantidAlgorithms/CreateSampleWorkspace.h b/Framework/Algorithms/inc/MantidAlgorithms/CreateSampleWorkspace.h index 5167bf138567b65c59992785e2a3fa4176231824..d64feb5626b2834783008dcd5c043cca59d01ddf 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/CreateSampleWorkspace.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/CreateSampleWorkspace.h @@ -24,7 +24,6 @@ namespace Algorithms { class DLLExport CreateSampleWorkspace : public API::Algorithm { public: CreateSampleWorkspace(); - ~CreateSampleWorkspace() override; const std::string name() const override; int version() const override; @@ -72,7 +71,7 @@ private: void addChopperParameters(API::MatrixWorkspace_sptr &ws); /// A pointer to the random number generator - Kernel::PseudoRandomNumberGenerator *m_randGen; + std::unique_ptr<Kernel::PseudoRandomNumberGenerator> m_randGen; std::map<std::string, std::string> m_preDefinedFunctionmap; }; diff --git a/Framework/Algorithms/inc/MantidAlgorithms/He3TubeEfficiency.h b/Framework/Algorithms/inc/MantidAlgorithms/He3TubeEfficiency.h index afff45a5ade87e7796f77664d18b0f3c7186261c..14e02be2b9d2a1b6c141e46a90c51375a6c7b82d 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/He3TubeEfficiency.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/He3TubeEfficiency.h @@ -50,8 +50,7 @@ class DLLExport He3TubeEfficiency : public API::Algorithm { public: /// Default constructor He3TubeEfficiency(); - /// Virtual destructor - ~He3TubeEfficiency() override; + /// Algorithm's name for identification overriding a virtual method const std::string name() const override { return "He3TubeEfficiency"; } /// Summary of algorithms purpose @@ -118,7 +117,7 @@ private: /// The spectra numbers that were skipped std::vector<specnum_t> m_spectraSkipped; /// Algorithm progress keeper - API::Progress *m_progress; + std::unique_ptr<API::Progress> m_progress; }; } // namespace Algorithms diff --git a/Framework/Algorithms/inc/MantidAlgorithms/ScaleX.h b/Framework/Algorithms/inc/MantidAlgorithms/ScaleX.h index 45b9511f791c6e485e76463c789d9ad3a032ce5c..22dd73f60eb9fbfa4994bc3a02f50362edd04972 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/ScaleX.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/ScaleX.h @@ -35,8 +35,7 @@ class DLLExport ScaleX : public API::Algorithm { public: /// Default constructor ScaleX(); - /// Destructor - ~ScaleX() override; + /// Algorithm's name for identification overriding a virtual method const std::string name() const override { return "ScaleX"; } /// Summary of algorithms purpose @@ -70,7 +69,7 @@ private: const size_t index); /// The progress reporting object - API::Progress *m_progress; + std::unique_ptr<API::Progress> m_progress; /// Scaling factor double m_algFactor; diff --git a/Framework/Algorithms/inc/MantidAlgorithms/WorkspaceJoiners.h b/Framework/Algorithms/inc/MantidAlgorithms/WorkspaceJoiners.h index fe4f8745c31ff546f7c57b42cdc0af18c0c943fd..69e3144e512141320a4c8c420df85f8bec19310a 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/WorkspaceJoiners.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/WorkspaceJoiners.h @@ -25,7 +25,6 @@ namespace Algorithms { class DLLExport WorkspaceJoiners : public API::Algorithm { public: WorkspaceJoiners(); - ~WorkspaceJoiners() override; const std::string category() const override; @@ -51,7 +50,7 @@ protected: const API::MatrixWorkspace &ws2, API::MatrixWorkspace &output) = 0; - API::Progress *m_progress; ///< Progress reporting object + std::unique_ptr<API::Progress> m_progress; ///< Progress reporting object }; } // namespace Algorithms diff --git a/Framework/Algorithms/src/AddPeak.cpp b/Framework/Algorithms/src/AddPeak.cpp index c497c06dff57379cf0e9e3c7cd2489cb086c72ca..116bb58502d32d3127ade2711a0cfa5456dcb311 100644 --- a/Framework/Algorithms/src/AddPeak.cpp +++ b/Framework/Algorithms/src/AddPeak.cpp @@ -117,8 +117,8 @@ void AddPeak::exec() { Qy *= knorm; Qz *= knorm; - Mantid::Geometry::IPeak *peak = - peaksWS->createPeak(Mantid::Kernel::V3D(Qx, Qy, Qz), l2); + auto peak = std::unique_ptr<Mantid::Geometry::IPeak>( + peaksWS->createPeak(Mantid::Kernel::V3D(Qx, Qy, Qz), l2)); peak->setDetectorID(detID); peak->setGoniometerMatrix(runWS->run().getGoniometer().getR()); peak->setBinCount(count); @@ -128,7 +128,6 @@ void AddPeak::exec() { peak->setSigmaIntensity(std::sqrt(height)); peaksWS->addPeak(*peak); - delete peak; // peaksWS->modified(); } diff --git a/Framework/Algorithms/src/AlignDetectors.cpp b/Framework/Algorithms/src/AlignDetectors.cpp index 0503c00533f2a31c5527ebef60c271c6cd5dcb75..8e766661918dc5da3d65ed72bee09863e129a97c 100644 --- a/Framework/Algorithms/src/AlignDetectors.cpp +++ b/Framework/Algorithms/src/AlignDetectors.cpp @@ -111,12 +111,7 @@ const std::string AlignDetectors::summary() const { } /// (Empty) Constructor -AlignDetectors::AlignDetectors() : m_numberOfSpectra(0) { - this->tofToDmap = nullptr; -} - -/// Destructor -AlignDetectors::~AlignDetectors() { delete this->tofToDmap; } +AlignDetectors::AlignDetectors() : m_numberOfSpectra(0) {} void AlignDetectors::init() { auto wsValidator = boost::make_shared<CompositeValidator>(); diff --git a/Framework/Algorithms/src/CreateSampleWorkspace.cpp b/Framework/Algorithms/src/CreateSampleWorkspace.cpp index 39b8e554d034c8b9f2132c2a120417bbd8058a40..7981e567b731d26b2c5b7bbf060f9668a85de7a4 100644 --- a/Framework/Algorithms/src/CreateSampleWorkspace.cpp +++ b/Framework/Algorithms/src/CreateSampleWorkspace.cpp @@ -50,10 +50,6 @@ DECLARE_ALGORITHM(CreateSampleWorkspace) */ CreateSampleWorkspace::CreateSampleWorkspace() : m_randGen(nullptr) {} -/** Destructor - */ -CreateSampleWorkspace::~CreateSampleWorkspace() { delete m_randGen; } - /// Algorithm's name for identification. @see Algorithm::name const std::string CreateSampleWorkspace::name() const { return "CreateSampleWorkspace"; @@ -225,7 +221,7 @@ void CreateSampleWorkspace::exec() { if (isRandom) { seedValue = static_cast<int>(std::time(nullptr)); } - m_randGen = new Kernel::MersenneTwister(seedValue); + m_randGen = std::make_unique<Kernel::MersenneTwister>(seedValue); } int numPixels = numBanks * bankPixelWidth * bankPixelWidth; diff --git a/Framework/Algorithms/src/He3TubeEfficiency.cpp b/Framework/Algorithms/src/He3TubeEfficiency.cpp index f547ba828d687cdfcd3fd946bf8d274d1aa16e70..1cbbf3a9a238c034d8668ef0867a0f3b62d3bbf7 100644 --- a/Framework/Algorithms/src/He3TubeEfficiency.cpp +++ b/Framework/Algorithms/src/He3TubeEfficiency.cpp @@ -47,13 +47,6 @@ He3TubeEfficiency::He3TubeEfficiency() m_shapeCache.clear(); } -/// Destructor -He3TubeEfficiency::~He3TubeEfficiency() { - if (m_progress) { - delete m_progress; - } -} - /** * Declare algorithm properties */ @@ -125,7 +118,7 @@ void He3TubeEfficiency::exec() { } std::size_t numHists = m_inputWS->getNumberHistograms(); - m_progress = new API::Progress(this, 0.0, 1.0, numHists); + m_progress = std::make_unique<API::Progress>(this, 0.0, 1.0, numHists); const auto &spectrumInfo = m_inputWS->spectrumInfo(); PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWS, *m_outputWS)) @@ -425,7 +418,7 @@ void He3TubeEfficiency::execEvent() { std::size_t numHistograms = m_outputWS->getNumberHistograms(); auto &spectrumInfo = m_outputWS->mutableSpectrumInfo(); - m_progress = new API::Progress(this, 0.0, 1.0, numHistograms); + m_progress = std::make_unique<API::Progress>(this, 0.0, 1.0, numHistograms); PARALLEL_FOR_IF(Kernel::threadSafe(*m_outputWS)) for (int i = 0; i < static_cast<int>(numHistograms); ++i) { diff --git a/Framework/Algorithms/src/ScaleX.cpp b/Framework/Algorithms/src/ScaleX.cpp index d9d21e2c34e8e630303e79b0ed63eafe565409df..49db28dfa97bf663bf74e2df4f2604cc26a46c85 100644 --- a/Framework/Algorithms/src/ScaleX.cpp +++ b/Framework/Algorithms/src/ScaleX.cpp @@ -35,11 +35,6 @@ ScaleX::ScaleX() : API::Algorithm(), m_progress(nullptr), m_algFactor(1.0), m_parname(), m_combine(false), m_binOp(), m_wi_min(-1), m_wi_max(-1) {} -/** - * Destructor - */ -ScaleX::~ScaleX() { delete m_progress; } - /** * Initialisation method. Declares properties to be used in algorithm. */ @@ -99,7 +94,7 @@ void ScaleX::exec() { API::MatrixWorkspace_sptr outputW = createOutputWS(inputW); // Get number of histograms int histnumber = static_cast<int>(inputW->getNumberHistograms()); - m_progress = new API::Progress(this, 0.0, 1.0, histnumber + 1); + m_progress = std::make_unique<API::Progress>(this, 0.0, 1.0, histnumber + 1); m_progress->report("Scaling X"); m_wi_min = 0; m_wi_max = histnumber - 1; diff --git a/Framework/Algorithms/src/WorkspaceJoiners.cpp b/Framework/Algorithms/src/WorkspaceJoiners.cpp index 5f8ae044a5c27d58d8733cc735ec28ad06efeb9d..375a72b239e424f672491706a3a6a592f22911df 100644 --- a/Framework/Algorithms/src/WorkspaceJoiners.cpp +++ b/Framework/Algorithms/src/WorkspaceJoiners.cpp @@ -25,10 +25,6 @@ using namespace DataObjects; */ WorkspaceJoiners::WorkspaceJoiners() : Algorithm(), m_progress(nullptr) {} -/** Destructor - */ -WorkspaceJoiners::~WorkspaceJoiners() { delete m_progress; } - /// Algorithm's category for identification. @see Algorithm::category const std::string WorkspaceJoiners::category() const { return "Transforms\\Merging"; @@ -53,7 +49,7 @@ MatrixWorkspace_sptr WorkspaceJoiners::execWS2D(const MatrixWorkspace &ws1, auto XValues = ws1.refX(0); // Initialize the progress reporting object - m_progress = new API::Progress(this, 0.0, 1.0, totalHists); + m_progress = std::make_unique<API::Progress>(this, 0.0, 1.0, totalHists); // Loop over the input workspaces in turn copying the data into the output one const int64_t &nhist1 = ws1.getNumberHistograms(); @@ -134,7 +130,7 @@ WorkspaceJoiners::execEvent(const DataObjects::EventWorkspace &eventWs1, create<EventWorkspace>(eventWs1, totalHists, eventWs1.binEdges(0)); // Initialize the progress reporting object - m_progress = new API::Progress(this, 0.0, 1.0, totalHists); + m_progress = std::make_unique<API::Progress>(this, 0.0, 1.0, totalHists); const int64_t &nhist1 = eventWs1.getNumberHistograms(); for (int64_t i = 0; i < nhist1; ++i) { diff --git a/Framework/CurveFitting/inc/MantidCurveFitting/FuncMinimizers/LevenbergMarquardtMinimizer.h b/Framework/CurveFitting/inc/MantidCurveFitting/FuncMinimizers/LevenbergMarquardtMinimizer.h index 0eb61f9101610dbfdbc940e2814ceed65a745b94..693118aacc9d76f6dcd31846a975767770fab373 100644 --- a/Framework/CurveFitting/inc/MantidCurveFitting/FuncMinimizers/LevenbergMarquardtMinimizer.h +++ b/Framework/CurveFitting/inc/MantidCurveFitting/FuncMinimizers/LevenbergMarquardtMinimizer.h @@ -47,7 +47,7 @@ private: int hasConverged(); /// GSL data container - GSL_FitData *m_data; + std::unique_ptr<GSL_FitData> m_data; /// GSL minimizer container gsl_multifit_function_fdf gslContainer; diff --git a/Framework/CurveFitting/src/FuncMinimizers/LevenbergMarquardtMinimizer.cpp b/Framework/CurveFitting/src/FuncMinimizers/LevenbergMarquardtMinimizer.cpp index c70d8e809d71eff8f2ef3fcea483cd43c3c053e7..8685dc4ce45ddf8d489c38e8700515c574f0e008 100644 --- a/Framework/CurveFitting/src/FuncMinimizers/LevenbergMarquardtMinimizer.cpp +++ b/Framework/CurveFitting/src/FuncMinimizers/LevenbergMarquardtMinimizer.cpp @@ -60,7 +60,7 @@ void LevenbergMarquardtMinimizer::initialize( boost::dynamic_pointer_cast<CostFunctions::CostFuncLeastSquares>( costFunction); if (leastSquares) { - m_data = new GSL_FitData(leastSquares); + m_data = std::make_unique<GSL_FitData>(leastSquares); } else { throw std::runtime_error("LevenbergMarquardt can only be used with Least " "squares cost function."); @@ -73,9 +73,10 @@ void LevenbergMarquardtMinimizer::initialize( gslContainer.f = &gsl_f; gslContainer.df = &gsl_df; gslContainer.fdf = &gsl_fdf; + gslContainer.n = m_data->n; gslContainer.p = m_data->p; - gslContainer.params = m_data; + gslContainer.params = m_data.get(); // setup GSL solver m_gslSolver = gsl_multifit_fdfsolver_alloc(T, m_data->n, m_data->p); @@ -92,9 +93,6 @@ void LevenbergMarquardtMinimizer::initialize( } LevenbergMarquardtMinimizer::~LevenbergMarquardtMinimizer() { - if (m_data) { - delete m_data; - } if (m_gslSolver) { gsl_multifit_fdfsolver_free(m_gslSolver); } diff --git a/Framework/DataHandling/src/LoadNexusMonitors2.cpp b/Framework/DataHandling/src/LoadNexusMonitors2.cpp index c7170e43299e8ffaa40369047ac9abd008b66472..24eb8df7bcf3299cb5d16678c0b04e3cc4dbc72e 100644 --- a/Framework/DataHandling/src/LoadNexusMonitors2.cpp +++ b/Framework/DataHandling/src/LoadNexusMonitors2.cpp @@ -426,18 +426,16 @@ void LoadNexusMonitors2::runLoadLogs(const std::string filename, **/ bool LoadNexusMonitors2::canOpenAsNeXus(const std::string &fname) { bool res = true; - ::NeXus::File *f = nullptr; + std::unique_ptr<::NeXus::File> filePointer; try { - f = new ::NeXus::File(fname); - if (f) - f->getEntries(); + filePointer = std::make_unique<::NeXus::File>(fname); + if (filePointer) + filePointer->getEntries(); } catch (::NeXus::Exception &e) { g_log.error() << "Failed to open as a NeXus file: '" << fname << "', error description: " << e.what() << '\n'; res = false; } - if (f) - delete f; return res; } diff --git a/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspaceIterator.h b/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspaceIterator.h index 1455b821bc1866612083ea4daaf0687992da07f2..e13c043b9f47e70ec88fe986a7d1a206e2282e8f 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspaceIterator.h +++ b/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspaceIterator.h @@ -140,7 +140,7 @@ protected: uint64_t m_max; /// Implicit function to limit volume searched - Mantid::Geometry::MDImplicitFunction *m_function; + std::unique_ptr<Mantid::Geometry::MDImplicitFunction> m_function; /// Number of dimensions size_t m_nd; diff --git a/Framework/DataObjects/src/MDHistoWorkspaceIterator.cpp b/Framework/DataObjects/src/MDHistoWorkspaceIterator.cpp index bb6280ec1429c66c737dceec01f2fd7f9fc9152a..6e0e88ac766730f2abc6edd6e412506f1a48bf1a 100644 --- a/Framework/DataObjects/src/MDHistoWorkspaceIterator.cpp +++ b/Framework/DataObjects/src/MDHistoWorkspaceIterator.cpp @@ -168,7 +168,7 @@ void MDHistoWorkspaceIterator::init( m_begin = beginPos; m_pos = m_begin; - m_function = function; + m_function.reset(function); m_max = endPos; if (m_max > m_ws->getNPoints()) @@ -249,12 +249,7 @@ MDHistoWorkspaceIterator::~MDHistoWorkspaceIterator() { delete[] m_index; delete[] m_indexMax; delete[] m_indexMaker; - - if (m_function) - delete m_function; - m_function = nullptr; } - //---------------------------------------------------------------------------------------------- /** @return the number of points to be iterated on */ size_t MDHistoWorkspaceIterator::getDataSize() const { diff --git a/Framework/Geometry/inc/MantidGeometry/IObjComponent.h b/Framework/Geometry/inc/MantidGeometry/IObjComponent.h index 1a79d17461c56005f4545b933c2371682e215c65..08a188ede6cb35b7174cc9ba7f12f7f3d921a591 100644 --- a/Framework/Geometry/inc/MantidGeometry/IObjComponent.h +++ b/Framework/Geometry/inc/MantidGeometry/IObjComponent.h @@ -90,7 +90,7 @@ public: virtual const Kernel::Material material() const = 0; /// Gets the GeometryHandler - GeometryHandler *Handle() const { return handle; } + GeometryHandler *Handle() const { return handle.get(); } protected: /// Reset the current geometry handler @@ -98,7 +98,7 @@ protected: private: /// Geometry Handle for rendering - GeometryHandler *handle; + std::unique_ptr<GeometryHandler> handle; friend class GeometryHandler; }; diff --git a/Framework/Geometry/src/IObjComponent.cpp b/Framework/Geometry/src/IObjComponent.cpp index c07c94c7979b2f57f61a8b2e43a0e447927cc881..6787cf01eecc17718af1b6abe4ee502c8edbfa02 100644 --- a/Framework/Geometry/src/IObjComponent.cpp +++ b/Framework/Geometry/src/IObjComponent.cpp @@ -13,21 +13,20 @@ namespace Mantid { namespace Geometry { -IObjComponent::IObjComponent() { handle = new GeometryHandler(this); } +IObjComponent::IObjComponent() { + handle = std::make_unique<GeometryHandler>(this); +} /** Constructor, specifying the GeometryHandler (renderer engine) * for this IObjComponent. */ IObjComponent::IObjComponent(GeometryHandler *the_handler) { - handle = the_handler; + handle.reset(the_handler); } // Looking to get rid of the first of these constructors in due course (and // probably add others) -IObjComponent::~IObjComponent() { - if (handle != nullptr) - delete handle; -} +IObjComponent::~IObjComponent() = default; /** * Set the geometry handler for IObjComponent @@ -37,7 +36,7 @@ IObjComponent::~IObjComponent() { void IObjComponent::setGeometryHandler(GeometryHandler *h) { if (h == nullptr) return; - this->handle = h; + this->handle.reset(h); } /** @@ -45,7 +44,7 @@ void IObjComponent::setGeometryHandler(GeometryHandler *h) { */ IObjComponent::IObjComponent(const IObjComponent &) { // Copy constructor just creates new handle. Copies nothing. - handle = new GeometryHandler(this); + handle = std::make_unique<GeometryHandler>(this); } /** @@ -56,7 +55,7 @@ IObjComponent::IObjComponent(const IObjComponent &) { IObjComponent &IObjComponent::operator=(const IObjComponent &rhs) { if (&rhs != this) { // Assignment operator copies nothing. Just creates new handle. - handle = new GeometryHandler(this); + handle = std::make_unique<GeometryHandler>(this); } return *this; } diff --git a/Framework/ICat/src/ICat3/ICat3Helper.cpp b/Framework/ICat/src/ICat3/ICat3Helper.cpp index 70fcd3a91ef39f0723ace3d6bd772c3ddeb75efc..200cea75df2fd73c83e517555e30bb7bbb9f65f3 100644 --- a/Framework/ICat/src/ICat3/ICat3Helper.cpp +++ b/Framework/ICat/src/ICat3/ICat3Helper.cpp @@ -190,18 +190,15 @@ void CICatHelper::saveInvestigationIncludesResponse( savetoTableWorkspace((*datafile_citr)->location, t); // File creation Time. - std::string *creationtime = nullptr; - if ((*datafile_citr)->datafileCreateTime != nullptr) { - time_t crtime = *(*datafile_citr)->datafileCreateTime; - char temp[25]; - strftime(temp, 25, "%Y-%b-%d %H:%M:%S", localtime(&crtime)); - std::string ftime(temp); - creationtime = new std::string; - creationtime->assign(ftime); + if ((*datafile_citr)->datafileCreateTime) { + const static std::string format("%Y-%b-%d %H:%M:%S"); + std::string creationTime; + creationTime.resize(format.size()); + const time_t crtime = *(*datafile_citr)->datafileCreateTime; + strftime(const_cast<char *>(creationTime.data()), creationTime.size(), + format.data(), localtime(&crtime)); + savetoTableWorkspace(creationTime.data(), t); } - savetoTableWorkspace(creationtime, t); - if (creationtime) - delete creationtime; // savetoTableWorkspace((*datafile_citr)->id, t); @@ -385,8 +382,8 @@ void CICatHelper::doMyDataSearch(API::ITableWorkspace_sptr &ws_sptr) { std::string sessionID = m_session->getSessionId(); request.sessionId = &sessionID; // investigation include - boost::shared_ptr<ns1__investigationInclude> invstInculde_sptr( - new ns1__investigationInclude); + boost::shared_ptr<ns1__investigationInclude> invstInculde_sptr = + boost::make_shared<ns1__investigationInclude>(); request.investigationInclude = invstInculde_sptr.get(); *request.investigationInclude = ns1__investigationInclude__INVESTIGATORS_USCORESHIFTS_USCOREAND_USCORESAMPLES; diff --git a/Framework/Kernel/inc/MantidKernel/ConfigService.h b/Framework/Kernel/inc/MantidKernel/ConfigService.h index 2530996bee636dc0a6b8b0204024b1bce49abd0c..7f220c2e7a874780c2abbf39206cf7a4c8026742 100644 --- a/Framework/Kernel/inc/MantidKernel/ConfigService.h +++ b/Framework/Kernel/inc/MantidKernel/ConfigService.h @@ -16,6 +16,7 @@ #include <boost/optional/optional.hpp> #include <map> +#include <memory> #include <set> #include <string> #include <vector> @@ -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/inc/MantidKernel/InternetHelper.h b/Framework/Kernel/inc/MantidKernel/InternetHelper.h index 2447b3c1c11a950a57c88ad45c13b2c5fdf1f3dd..9b15a860223b79c4da8c66be9aadff3653c5c788 100644 --- a/Framework/Kernel/inc/MantidKernel/InternetHelper.h +++ b/Framework/Kernel/inc/MantidKernel/InternetHelper.h @@ -12,6 +12,7 @@ #include <ios> #include <map> +#include <memory> #include <string> namespace Poco { @@ -157,8 +158,8 @@ protected: std::string m_contentType; std::string m_body; StringToStringMap m_headers; - Poco::Net::HTTPRequest *m_request; - Poco::Net::HTTPResponse *m_response; + std::unique_ptr<Poco::Net::HTTPRequest> m_request; + std::unique_ptr<Poco::Net::HTTPResponse> m_response; }; } // namespace Kernel diff --git a/Framework/Kernel/inc/MantidKernel/ThreadPool.h b/Framework/Kernel/inc/MantidKernel/ThreadPool.h index 6825b7ece64609a41952cc57bcd13d21048a6a59..7dd51777ba32c6b7018779de810b51ada5727160 100644 --- a/Framework/Kernel/inc/MantidKernel/ThreadPool.h +++ b/Framework/Kernel/inc/MantidKernel/ThreadPool.h @@ -54,19 +54,19 @@ protected: size_t m_numThreads; /// The ThreadScheduler instance taking care of task scheduling - ThreadScheduler *m_scheduler; + std::unique_ptr<ThreadScheduler> m_scheduler; /// Vector with all the threads that are started - std::vector<Poco::Thread *> m_threads; + std::vector<std::unique_ptr<Poco::Thread>> m_threads; /// Vector of the POCO-required classes to actually run in a thread. - std::vector<ThreadPoolRunnable *> m_runnables; + std::vector<std::unique_ptr<ThreadPoolRunnable>> m_runnables; /// Have the threads started? bool m_started; /// Progress reporter - ProgressBase *m_prog; + std::unique_ptr<ProgressBase> m_prog; private: // prohibit default copy constructor as it does not work diff --git a/Framework/Kernel/src/ANN/bd_tree.h b/Framework/Kernel/src/ANN/bd_tree.h index 7670c06383cf326770f93958e6866df18f8733dc..10ba69c5a0b904de4bc474c8ff53a63b223e08ea 100644 --- a/Framework/Kernel/src/ANN/bd_tree.h +++ b/Framework/Kernel/src/ANN/bd_tree.h @@ -78,12 +78,11 @@ public: ~ANNbd_shrink() override // destructor { - if (child[ANN_IN] != nullptr && child[ANN_IN] != KD_TRIVIAL) + if (child[ANN_IN] != KD_TRIVIAL) delete child[ANN_IN]; - if (child[ANN_OUT] != nullptr && child[ANN_OUT] != KD_TRIVIAL) + if (child[ANN_OUT] != KD_TRIVIAL) delete child[ANN_OUT]; - if (bnds != nullptr) - delete[] bnds; // delete bounds + delete[] bnds; // delete bounds } void getStats( // get tree statistics diff --git a/Framework/Kernel/src/ConfigService.cpp b/Framework/Kernel/src/ConfigService.cpp index 5951d5dc97d495d4e5559c6e24724b6a420d7015..152ddb1f0272e87791ec67a2a17c1e5a8a9855ce 100644 --- a/Framework/Kernel/src/ConfigService.cpp +++ b/Framework/Kernel/src/ConfigService.cpp @@ -169,7 +169,8 @@ 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 +281,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 +386,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 +427,9 @@ 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 +463,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'; diff --git a/Framework/Kernel/src/InternetHelper.cpp b/Framework/Kernel/src/InternetHelper.cpp index 55d54fd383593e99fa1bb6694fe55bc5f31c8fbf..c71a1583afeae5f0f5ff88ecb34d752ea8221dbb 100644 --- a/Framework/Kernel/src/InternetHelper.cpp +++ b/Framework/Kernel/src/InternetHelper.cpp @@ -108,14 +108,7 @@ InternetHelper::InternetHelper(const Kernel::ProxyInfo &proxy) //---------------------------------------------------------------------------------------------- /** Destructor */ -InternetHelper::~InternetHelper() { - if (m_request != nullptr) { - delete m_request; - } - if (m_response != nullptr) { - delete m_response; - } -} +InternetHelper::~InternetHelper() = default; void InternetHelper::setupProxyOnSession(HTTPClientSession &session, const std::string &proxyUrl) { @@ -127,17 +120,9 @@ void InternetHelper::setupProxyOnSession(HTTPClientSession &session, } void InternetHelper::createRequest(Poco::URI &uri) { - if (m_request != nullptr) { - delete m_request; - } - if (m_response != nullptr) { - delete m_response; - } - - m_request = - new HTTPRequest(m_method, uri.getPathAndQuery(), HTTPMessage::HTTP_1_1); - - m_response = new HTTPResponse(); + m_request = std::make_unique<HTTPRequest>(m_method, uri.getPathAndQuery(), + HTTPMessage::HTTP_1_1); + m_response = std::make_unique<HTTPResponse>(); if (!m_contentType.empty()) { m_request->setContentType(m_contentType); } diff --git a/Framework/Kernel/src/ThreadPool.cpp b/Framework/Kernel/src/ThreadPool.cpp index c84e988f2d0d1c001d16fa43122e2981fb8c8890..f381b9f7f3b35934a9ae73ac078cf98d99eaee45 100644 --- a/Framework/Kernel/src/ThreadPool.cpp +++ b/Framework/Kernel/src/ThreadPool.cpp @@ -43,7 +43,8 @@ namespace Kernel { */ ThreadPool::ThreadPool(ThreadScheduler *scheduler, size_t numThreads, ProgressBase *prog) - : m_scheduler(scheduler), m_started(false), m_prog(prog) { + : m_scheduler(std::unique_ptr<ThreadScheduler>(scheduler)), + m_started(false), m_prog(std::unique_ptr<ProgressBase>(prog)) { if (!m_scheduler) throw std::invalid_argument( "NULL ThreadScheduler passed to ThreadPool constructor."); @@ -59,12 +60,7 @@ ThreadPool::ThreadPool(ThreadScheduler *scheduler, size_t numThreads, //-------------------------------------------------------------------------------- /** Destructor. Deletes the ThreadScheduler. */ -ThreadPool::~ThreadPool() { - if (m_scheduler) - delete m_scheduler; - if (m_prog) - delete m_prog; -} +ThreadPool::~ThreadPool() = default; //-------------------------------------------------------------------------------- /** Return the number of physical cores available on the system. @@ -102,13 +98,6 @@ size_t ThreadPool::getNumPhysicalCores() { void ThreadPool::start(double waitSec) { if (m_started) throw std::runtime_error("Threads have already started."); - - // Delete any old threads (they should NOT be running!) - for (auto &thread : m_threads) - delete thread; - for (auto &runnable : m_runnables) - delete runnable; - // Now, launch that many threads and let them wait for new tasks. m_threads.clear(); m_runnables.clear(); @@ -117,14 +106,13 @@ void ThreadPool::start(double waitSec) { std::ostringstream name; name << "Thread" << i; // Create the thread - Poco::Thread *thread = new Poco::Thread(name.str()); - m_threads.push_back(thread); - + auto thread = std::make_unique<Poco::Thread>(name.str()); // Make the runnable object and run it - auto runnable = new ThreadPoolRunnable(i, m_scheduler, m_prog, waitSec); - m_runnables.push_back(runnable); - + auto runnable = std::make_unique<ThreadPoolRunnable>(i, m_scheduler.get(), + m_prog.get(), waitSec); thread->start(*runnable); + m_threads.push_back(std::move(thread)); + m_runnables.push_back(std::move(runnable)); } // Yep, all the threads are running. m_started = true; @@ -184,15 +172,12 @@ void ThreadPool::joinAll() { // Sequentially join all the threads. for (auto &thread : m_threads) { thread->join(); - delete thread; } // Clear the vectors (the threads are deleted now). m_threads.clear(); // Get rid of the runnables too - for (auto &runnable : m_runnables) - delete runnable; m_runnables.clear(); // This will make threads restart diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModel.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModel.h index b0b741f84c299154067f9f8278fb7515099f5cce..f5028d7a5ebdb6b8a89c7346e9403b31f5050862 100644 --- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModel.h +++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModel.h @@ -116,7 +116,7 @@ private: /// same ion std::string m_MagIonName; /// Owned pointer to magnetic form factor cache - PhysicalConstants::MagneticFormFactorTable *m_formFactorTable; + std::unique_ptr<PhysicalConstants::MagneticFormFactorTable> m_formFactorTable; }; /// boost::shared_ptr typedef diff --git a/Framework/MDAlgorithms/src/Quantification/ForegroundModel.cpp b/Framework/MDAlgorithms/src/Quantification/ForegroundModel.cpp index ee9b018c843b557512d5552a3f26e30ba58dc047..6d18dd22a19b5a0afb7467b71ca22b047ed1f4bd 100644 --- a/Framework/MDAlgorithms/src/Quantification/ForegroundModel.cpp +++ b/Framework/MDAlgorithms/src/Quantification/ForegroundModel.cpp @@ -44,7 +44,7 @@ ForegroundModel::ForegroundModel(const API::IFunction &fittingFunction) /** */ -ForegroundModel::~ForegroundModel() { delete m_formFactorTable; } +ForegroundModel::~ForegroundModel() = default; /** * Set a reference to the convolved fitting function. Required as we need a @@ -135,16 +135,14 @@ const API::IFunction &ForegroundModel::functionUnderMinimization() const { void ForegroundModel::setFormFactorIon(const std::string &ionType) { // "0" indicates off if (ionType == "0") { - delete m_formFactorTable; - m_formFactorTable = nullptr; + m_formFactorTable.reset(nullptr); } else { using namespace PhysicalConstants; if (m_MagIonName != ionType) { if (m_formFactorTable) { - delete m_formFactorTable; } - m_formFactorTable = new MagneticFormFactorTable(FORM_FACTOR_TABLE_LENGTH, - getMagneticIon(ionType)); + m_formFactorTable = std::make_unique<MagneticFormFactorTable>( + FORM_FACTOR_TABLE_LENGTH, getMagneticIon(ionType)); m_MagIonName = ionType; } } diff --git a/Framework/MDAlgorithms/test/CreateMDFitWorkspaceTest.h b/Framework/MDAlgorithms/test/CreateMDFitWorkspaceTest.h index d38da7a6f6e03c90283efe11c3ea6d18a7b05792..0b4a0dc47232830a3645bf716e38312bf7986741 100644 --- a/Framework/MDAlgorithms/test/CreateMDFitWorkspaceTest.h +++ b/Framework/MDAlgorithms/test/CreateMDFitWorkspaceTest.h @@ -30,15 +30,12 @@ public: maker.execute(); TS_ASSERT(maker.isExecuted()); - IFitFunction *fun = FunctionFactory::Instance().createInitialized( - "name=UserFunctionMD,Formula=h*exp(-a*(x-c)^2),Workspace=" - "CreateMDFitWorkspaceTest_ws"); + std::unique_ptr<IFitFunction> fun = std::unique_ptr<IFitFunction>( + FunctionFactory::Instance().createInitialized( + "name=UserFunctionMD,Formula=h*exp(-a*(x-c)^2),Workspace=" + "CreateMDFitWorkspaceTest_ws")); TS_ASSERT(fun); TS_ASSERT(fun->getWorkspace()); - - if (fun) { - delete fun; - } } }; diff --git a/Framework/MDAlgorithms/test/MDWSTransfTest.h b/Framework/MDAlgorithms/test/MDWSTransfTest.h index bc9ab71e5e0409dd69e8bd17fd2246b90006b038..c7f67afb682f29a9a85dec2fff4049ba441074bd 100644 --- a/Framework/MDAlgorithms/test/MDWSTransfTest.h +++ b/Framework/MDAlgorithms/test/MDWSTransfTest.h @@ -37,7 +37,7 @@ public: class MDWSTransfTest : public CxxTest::TestSuite { Mantid::API::MatrixWorkspace_sptr ws2D; - Geometry::OrientedLattice *pLattice; + std::unique_ptr<Geometry::OrientedLattice> pLattice; // this is permutation matrix which transforms Mantid coordinate system (beam // along Z-axis) // to Horace coordinate system (beam along X-axis); @@ -73,7 +73,7 @@ public: TS_ASSERT_EQUALS(CnvrtToMD::SampleFrame, Transf.findTargetFrame(TargWSDescription)); - spws->mutableSample().setOrientedLattice(pLattice); + spws->mutableSample().setOrientedLattice(pLattice.get()); TS_ASSERT_EQUALS(CnvrtToMD::HKLFrame, Transf.findTargetFrame(TargWSDescription)); } @@ -100,7 +100,7 @@ public: CnvrtToMD::SampleFrame, CnvrtToMD::HKLScale), std::invalid_argument); - spws->mutableSample().setOrientedLattice(pLattice); + spws->mutableSample().setOrientedLattice(pLattice.get()); WorkspaceCreationHelper::setGoniometer(spws, 20, 0, 0); @@ -148,11 +148,9 @@ public: std::vector<double> minVal(4, -3), maxVal(4, 3); TWS.setMinMax(minVal, maxVal); - if (pLattice) - delete pLattice; - pLattice = - new Geometry::OrientedLattice(5 * M_PI, M_PI, 2 * M_PI, 90., 90., 90.); - ws2D->mutableSample().setOrientedLattice(pLattice); + pLattice = std::make_unique<Geometry::OrientedLattice>( + 5 * M_PI, M_PI, 2 * M_PI, 90., 90., 90.); + ws2D->mutableSample().setOrientedLattice(pLattice.get()); TWS.buildFromMatrixWS(ws2D, "Q3D", "Direct"); std::vector<double> u(3, 0); @@ -410,8 +408,8 @@ public: // add workspace energy ws2D->mutableRun().addProperty("Ei", 13., "meV", true); - pLattice = new Geometry::OrientedLattice(3, 3, 2, 90, 90, 90); - ws2D->mutableSample().setOrientedLattice(pLattice); + pLattice = std::make_unique<Geometry::OrientedLattice>(3, 3, 2, 90, 90, 90); + ws2D->mutableSample().setOrientedLattice(pLattice.get()); // S_mantid*k_mantid = S_hor*k_hor; -- both Mantid and Horace produce the // same kind of crystal frame diff --git a/Framework/RemoteJobManagers/inc/MantidRemoteJobManagers/MantidWebServiceAPIHelper.h b/Framework/RemoteJobManagers/inc/MantidRemoteJobManagers/MantidWebServiceAPIHelper.h index d1dc13d5fd0d2bb1b903e1373bcc48f0087cc704..e20648c266cbe986498223c78626a3419af024b6 100644 --- a/Framework/RemoteJobManagers/inc/MantidRemoteJobManagers/MantidWebServiceAPIHelper.h +++ b/Framework/RemoteJobManagers/inc/MantidRemoteJobManagers/MantidWebServiceAPIHelper.h @@ -7,12 +7,12 @@ #ifndef MANTID_REMOTEJOBMANAGERS_MANTIDWEBSERVICEAPIHELPER_H #define MANTID_REMOTEJOBMANAGERS_MANTIDWEBSERVICEAPIHELPER_H +#include "MantidKernel/DllConfig.h" #include <map> +#include <memory> #include <string> #include <vector> -#include "MantidKernel/DllConfig.h" - #include <Poco/Net/HTTPResponse.h> namespace Poco { @@ -111,10 +111,10 @@ private: static std::vector<Poco::Net::HTTPCookie> g_cookies; Poco::Net::NameValueCollection getCookies() const; - mutable Poco::Net::HTTPClientSession - *m_session; // Pointer to session object for all our HTTP requests - // (Has to be a pointer because we allocate and delete - // it multiple times) + mutable std::unique_ptr<Poco::Net::HTTPClientSession> + m_session; // Pointer to session object for all our HTTP requests + // (Has to be a pointer because we allocate and delete + // it multiple times) Poco::Net::HTTPResponse m_response; // Response object for all of our HTTP requests diff --git a/Framework/RemoteJobManagers/src/MantidWebServiceAPIHelper.cpp b/Framework/RemoteJobManagers/src/MantidWebServiceAPIHelper.cpp index 37c3d23e2b9ad8b61ac1f794cbdcf60cd9b8a921..bce4eddc99267699855fa375b6ddb81e1d7b20cc 100644 --- a/Framework/RemoteJobManagers/src/MantidWebServiceAPIHelper.cpp +++ b/Framework/RemoteJobManagers/src/MantidWebServiceAPIHelper.cpp @@ -39,7 +39,7 @@ MantidWebServiceAPIHelper::MantidWebServiceAPIHelper() m_serviceBaseUrl = "https://fermi.ornl.gov/MantidRemote"; } -MantidWebServiceAPIHelper::~MantidWebServiceAPIHelper() { delete m_session; } +MantidWebServiceAPIHelper::~MantidWebServiceAPIHelper() = default; std::istream &MantidWebServiceAPIHelper::httpGet( const std::string &path, const std::string &query_str, @@ -186,10 +186,7 @@ void MantidWebServiceAPIHelper::initHTTPRequest(Poco::Net::HTTPRequest &req, std::string extraPath, std::string queryString) const { // Set up the session object - if (m_session) { - delete m_session; - m_session = nullptr; - } + m_session.reset(); if (Poco::URI(m_serviceBaseUrl).getScheme() == "https") { // Create an HTTPS session @@ -200,15 +197,15 @@ void MantidWebServiceAPIHelper::initHTTPRequest(Poco::Net::HTTPRequest &req, new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", "", Poco::Net::Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); - m_session = new Poco::Net::HTTPSClientSession( + m_session = std::make_unique<Poco::Net::HTTPSClientSession>( Poco::URI(m_serviceBaseUrl).getHost(), Poco::URI(m_serviceBaseUrl).getPort(), context); } else { // Create a regular HTTP client session. (NOTE: Using unencrypted HTTP is a // really bad idea! We'll be sending passwords in the clear!) - m_session = - new Poco::Net::HTTPClientSession(Poco::URI(m_serviceBaseUrl).getHost(), - Poco::URI(m_serviceBaseUrl).getPort()); + m_session = std::make_unique<Poco::Net::HTTPClientSession>( + Poco::URI(m_serviceBaseUrl).getHost(), + Poco::URI(m_serviceBaseUrl).getPort()); } Poco::URI uri(m_serviceBaseUrl); diff --git a/MantidPlot/src/Graph.cpp b/MantidPlot/src/Graph.cpp index e969a22b4632c3d20efc890826e53e79405f1e7e..e08d3d805207ac09dc9ea0703ebfdce58357a4f8 100644 --- a/MantidPlot/src/Graph.cpp +++ b/MantidPlot/src/Graph.cpp @@ -244,8 +244,7 @@ MultiLayer *Graph::multiLayer() { void Graph::deselectMarker() { selectedMarker = -1; - if (d_markers_selector) - delete d_markers_selector; + delete d_markers_selector; emit enableTextEditor(nullptr); @@ -4564,8 +4563,7 @@ void Graph::setActiveTool(PlotToolInterface *tool) { return; } - if (d_active_tool) - delete d_active_tool; + delete d_active_tool; d_active_tool = tool; } @@ -4577,21 +4575,17 @@ void Graph::disableTools() { if (drawLineActive()) drawLine(false); - if (d_active_tool) - delete d_active_tool; + delete d_active_tool; d_active_tool = nullptr; - if (d_range_selector) - delete d_range_selector; + delete d_range_selector; d_range_selector = nullptr; } bool Graph::enableRangeSelectors(const QObject *status_target, const char *status_slot) { - if (d_range_selector) { - delete d_range_selector; - d_range_selector = nullptr; - } + delete d_range_selector; + d_range_selector = nullptr; d_range_selector = new RangeSelectorTool(this, status_target, status_slot); setActiveTool(d_range_selector); connect(d_range_selector, SIGNAL(changed()), this, @@ -4848,14 +4842,10 @@ bool Graph::validCurvesDataSize() { Graph::~Graph() { setActiveTool(nullptr); - if (d_range_selector) - delete d_range_selector; - if (d_peak_fit_tool) - delete d_peak_fit_tool; - if (d_magnifier) - delete d_magnifier; - if (d_panner) - delete d_panner; + delete d_range_selector; + delete d_peak_fit_tool; + delete d_magnifier; + delete d_panner; delete titlePicker; delete scalePicker; delete cp; @@ -5361,10 +5351,8 @@ void Graph::changeIntensity(bool bIntensityChanged) { * @param on :: boolean parameter to switch on zooming */ void Graph::enablePanningMagnifier(bool on) { - if (d_magnifier) - delete d_magnifier; - if (d_panner) - delete d_panner; + delete d_magnifier; + delete d_panner; QwtPlotCanvas *cnvs = d_plot->canvas(); // canvas(); if (on) { @@ -5400,8 +5388,7 @@ bool Graph::isFixedAspectRatioEnabled() { */ void Graph::enableFixedAspectRatio(bool on) { #if QWT_VERSION >= 0x050200 - if (d_rescaler) - delete d_rescaler; + delete d_rescaler; QwtPlotCanvas *cnvs = d_plot->canvas(); if (on) { diff --git a/qt/widgets/common/src/FitPropertyBrowser.cpp b/qt/widgets/common/src/FitPropertyBrowser.cpp index 704df897bf2c46b2d6f9fc824493a48e75087408..7026a402cdb5356cfca92c8886b8b5562a34d720 100644 --- a/qt/widgets/common/src/FitPropertyBrowser.cpp +++ b/qt/widgets/common/src/FitPropertyBrowser.cpp @@ -787,10 +787,11 @@ void FitPropertyBrowser::createCompositeFunction( } setWorkspace(m_compositeFunction); - PropertyHandler *h = new PropertyHandler( + auto h = std::make_unique<PropertyHandler>( m_compositeFunction, Mantid::API::CompositeFunction_sptr(), this); - m_compositeFunction->setHandler(h); - setCurrentFunction(h); + m_compositeFunction->setHandler(std::move(h)); + setCurrentFunction( + static_cast<PropertyHandler *>(m_compositeFunction->getHandler())); if (m_auto_back) { addAutoBackground(); diff --git a/qt/widgets/common/src/PropertyHandler.cpp b/qt/widgets/common/src/PropertyHandler.cpp index e05c45879b1e89bdbc1c107ff4f4d63a92fb7c5b..f13a0e39c1552e747fcdb9e400d48e393714bfc3 100644 --- a/qt/widgets/common/src/PropertyHandler.cpp +++ b/qt/widgets/common/src/PropertyHandler.cpp @@ -118,8 +118,8 @@ void PropertyHandler::init() { throw std::runtime_error( "IFunction expected but func function of another type"); } - PropertyHandler *h = new PropertyHandler(f, m_cf, m_browser); - f->setHandler(h); + auto h = std::make_unique<PropertyHandler>(f, m_cf, m_browser); + f->setHandler(std::move(h)); } } @@ -417,10 +417,10 @@ PropertyHandler *PropertyHandler::addFunction(const std::string &fnName) { return nullptr; } - PropertyHandler *h = new PropertyHandler(f, m_cf, m_browser); - f->setHandler(h); + auto h = std::make_unique<PropertyHandler>(f, m_cf, m_browser); h->setAttribute("StartX", m_browser->startX()); h->setAttribute("EndX", m_browser->endX()); + f->setHandler(std::move(h)); // enable the change slots m_browser->m_changeSlotsEnabled = true; @@ -431,9 +431,10 @@ PropertyHandler *PropertyHandler::addFunction(const std::string &fnName) { m_browser->setDefaultBackgroundType(f->name()); } m_browser->setFocus(); - m_browser->setCurrentFunction(h); + auto return_ptr = static_cast<PropertyHandler *>(f->getHandler()); + m_browser->setCurrentFunction(return_ptr); - return h; + return return_ptr; } // Removes handled function from its parent function and @@ -1038,10 +1039,11 @@ Mantid::API::IFunction_sptr PropertyHandler::changeType(QtProperty *prop) { emit m_browser->removePlotSignal(this); Mantid::API::IFunction_sptr f_old = function(); - PropertyHandler *h = new PropertyHandler(f, m_parent, m_browser, m_item); + std::unique_ptr<PropertyHandler> h = + std::make_unique<PropertyHandler>(f, m_parent, m_browser, m_item); if (this == m_browser->m_autoBackground) { if (dynamic_cast<Mantid::API::IBackgroundFunction *>(f.get())) { - m_browser->m_autoBackground = h; + m_browser->m_autoBackground = h.get(); h->fit(); } else { @@ -1051,12 +1053,12 @@ Mantid::API::IFunction_sptr PropertyHandler::changeType(QtProperty *prop) { if (m_parent) { m_parent->replaceFunctionPtr(f_old, f); } - f->setHandler(h); // calculate the baseline if (h->pfun()) { h->setCentre(h->centre()); // this sets m_ci h->calcBase(); } + f->setHandler(std::move(h)); // at this point this handler does not exist any more. only return is // possible return f;