Skip to content
Snippets Groups Projects
Commit 74a6db0f authored by Sam Jenkins's avatar Sam Jenkins
Browse files

Re #23103 replaced some raw pointers in sample.h

parent def6eab3
No related branches found
No related tags found
No related merge requests found
...@@ -127,7 +127,7 @@ private: ...@@ -127,7 +127,7 @@ private:
/// An owned pointer to the SampleEnvironment object /// An owned pointer to the SampleEnvironment object
boost::shared_ptr<Geometry::SampleEnvironment> m_environment; boost::shared_ptr<Geometry::SampleEnvironment> m_environment;
/// Pointer to the OrientedLattice of the sample, NULL if not set. /// 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 /// CrystalStructure of the sample
std::unique_ptr<Geometry::CrystalStructure> m_crystalStructure; std::unique_ptr<Geometry::CrystalStructure> m_crystalStructure;
......
...@@ -48,16 +48,16 @@ Sample::Sample(const Sample &copy) ...@@ -48,16 +48,16 @@ Sample::Sample(const Sample &copy)
m_geom_id(copy.m_geom_id), m_thick(copy.m_thick), m_height(copy.m_height), m_geom_id(copy.m_geom_id), m_thick(copy.m_thick), m_height(copy.m_height),
m_width(copy.m_width) { m_width(copy.m_width) {
if (copy.m_lattice) if (copy.m_lattice)
m_lattice = new OrientedLattice(copy.getOrientedLattice()); m_lattice = std::make_unique<OrientedLattice>(copy.getOrientedLattice());
if (copy.hasCrystalStructure()) { if (copy.hasCrystalStructure()) {
m_crystalStructure.reset( m_crystalStructure = std::make_unique<Geometry::CrystalStructure>(
new Geometry::CrystalStructure(copy.getCrystalStructure())); copy.getCrystalStructure());
} }
} }
/// Destructor /// Destructor
Sample::~Sample() { delete m_lattice; } Sample::~Sample() {}
/** Assignment operator /** Assignment operator
* @param rhs :: const reference to the sample object * @param rhs :: const reference to the sample object
...@@ -75,12 +75,10 @@ Sample &Sample::operator=(const Sample &rhs) { ...@@ -75,12 +75,10 @@ Sample &Sample::operator=(const Sample &rhs) {
m_thick = rhs.m_thick; m_thick = rhs.m_thick;
m_height = rhs.m_height; m_height = rhs.m_height;
m_width = rhs.m_width; m_width = rhs.m_width;
if (m_lattice != nullptr)
delete m_lattice;
if (rhs.m_lattice) if (rhs.m_lattice)
m_lattice = new OrientedLattice(rhs.getOrientedLattice()); m_lattice = std::make_unique<OrientedLattice>(rhs.getOrientedLattice());
else else
m_lattice = nullptr; m_lattice.reset(nullptr);
m_crystalStructure.reset(); m_crystalStructure.reset();
if (rhs.hasCrystalStructure()) { if (rhs.hasCrystalStructure()) {
...@@ -179,13 +177,10 @@ OrientedLattice &Sample::getOrientedLattice() { ...@@ -179,13 +177,10 @@ OrientedLattice &Sample::getOrientedLattice() {
* @param latt :: A pointer to a OrientedLattice. * @param latt :: A pointer to a OrientedLattice.
*/ */
void Sample::setOrientedLattice(OrientedLattice *latt) { void Sample::setOrientedLattice(OrientedLattice *latt) {
if (m_lattice != nullptr) {
delete m_lattice;
}
if (latt != nullptr) if (latt != nullptr)
m_lattice = new OrientedLattice(*latt); m_lattice = std::make_unique<OrientedLattice>(*latt);
else else
m_lattice = nullptr; m_lattice.reset(nullptr);
} }
/** @return true if the sample has an OrientedLattice */ /** @return true if the sample has an OrientedLattice */
...@@ -394,7 +389,7 @@ int Sample::loadNexus(::NeXus::File *file, const std::string &group) { ...@@ -394,7 +389,7 @@ int Sample::loadNexus(::NeXus::File *file, const std::string &group) {
int num_oriented_lattice; int num_oriented_lattice;
file->readData("num_oriented_lattice", num_oriented_lattice); file->readData("num_oriented_lattice", num_oriented_lattice);
if (num_oriented_lattice > 0) { if (num_oriented_lattice > 0) {
m_lattice = new OrientedLattice; m_lattice = std::make_unique<OrientedLattice>();
m_lattice->loadNexus(file, "oriented_lattice"); m_lattice->loadNexus(file, "oriented_lattice");
} }
} }
...@@ -418,8 +413,7 @@ int Sample::loadNexus(::NeXus::File *file, const std::string &group) { ...@@ -418,8 +413,7 @@ int Sample::loadNexus(::NeXus::File *file, const std::string &group) {
*/ */
void Sample::clearOrientedLattice() { void Sample::clearOrientedLattice() {
if (m_lattice) { if (m_lattice) {
delete m_lattice; m_lattice.reset(nullptr);
m_lattice = nullptr;
} }
} }
} // namespace API } // namespace API
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment