Commit f05e1455 authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #19522 Add cleaner implementation

This removes the memory leak and adds a move method to PeaksWorkspace
parent 6f6c5afe
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "MantidDataObjects/PeakShapeEllipsoidFactory.h" #include "MantidDataObjects/PeakShapeEllipsoidFactory.h"
#include "MantidDataObjects/PeakShapeSphericalFactory.h" #include "MantidDataObjects/PeakShapeSphericalFactory.h"
#include "MantidDataObjects/PeaksWorkspace.h" #include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidDataObjects/Peak.h"
#include "MantidDataObjects/RebinnedOutput.h" #include "MantidDataObjects/RebinnedOutput.h"
#include "MantidGeometry/Instrument/Goniometer.h" #include "MantidGeometry/Instrument/Goniometer.h"
#include "MantidKernel/ArrayProperty.h" #include "MantidKernel/ArrayProperty.h"
...@@ -1068,12 +1069,12 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) { ...@@ -1068,12 +1069,12 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
// below this one) is set before QLabFrame as this causes Peak to ray trace // below this one) is set before QLabFrame as this causes Peak to ray trace
// to find the location of the detector, which significantly increases // to find the location of the detector, which significantly increases
// loading times. // loading times.
Geometry::IPeak *peak = new Peak();
const auto goniometer = peakWS->run().getGoniometer(); const auto goniometer = peakWS->run().getGoniometer();
peak->setInstrument(peakWS->getInstrument()); Peak peak;
peak->setGoniometerMatrix(goniometer.getR()); peak.setInstrument(peakWS->getInstrument());
peak->setRunNumber(peakWS->getRunNumber()); peak.setGoniometerMatrix(goniometer.getR());
peakWS->addPeak(*peak); peak.setRunNumber(peakWS->getRunNumber());
peakWS->addPeak(std::move(peak));
} }
for (const auto &str : columnNames) { for (const auto &str : columnNames) {
......
...@@ -94,6 +94,8 @@ public: ...@@ -94,6 +94,8 @@ public:
std::string getConvention() const override; std::string getConvention() const override;
void removePeak(int peakNum) override; void removePeak(int peakNum) override;
void addPeak(const Geometry::IPeak &ipeak) override; void addPeak(const Geometry::IPeak &ipeak) override;
/// Move a peak object into this peaks workspace
void addPeak(Peak &&ipeak);
Peak &getPeak(int peakNum) override; Peak &getPeak(int peakNum) override;
const Peak &getPeak(int peakNum) const override; const Peak &getPeak(int peakNum) const override;
......
...@@ -161,6 +161,14 @@ void PeaksWorkspace::addPeak(const Geometry::IPeak &ipeak) { ...@@ -161,6 +161,14 @@ void PeaksWorkspace::addPeak(const Geometry::IPeak &ipeak) {
} }
} }
//---------------------------------------------------------------------------------------------
/** Add a peak to the list
* @param ipeak :: Peak object to add (move) into this.
*/
void PeaksWorkspace::addPeak(Peak &&ipeak) {
peaks.push_back(ipeak);
}
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
/** Return a reference to the Peak /** Return a reference to the Peak
* @param peakNum :: index of the peak to get. * @param peakNum :: index of the peak to get.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment