From 84761bb3f4c540cbe4666f1004436af2d92fdf88 Mon Sep 17 00:00:00 2001
From: Walter Van Herck <w.van.herck@fz-juelich.de>
Date: Mon, 15 Jan 2018 10:29:56 +0100
Subject: [PATCH] Replace naked pointer with unique_ptr

---
 Core/Simulation/OffSpecSimulation.cpp | 25 ++++++++++---------------
 Core/Simulation/OffSpecSimulation.h   |  2 +-
 auto/Wrap/libBornAgainCore_wrap.cpp   |  2 +-
 3 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/Core/Simulation/OffSpecSimulation.cpp b/Core/Simulation/OffSpecSimulation.cpp
index 6498be03b56..5c8c81a30ee 100644
--- a/Core/Simulation/OffSpecSimulation.cpp
+++ b/Core/Simulation/OffSpecSimulation.cpp
@@ -23,21 +23,18 @@
 #include "SimulationElement.h"
 
 OffSpecSimulation::OffSpecSimulation()
-    : mp_alpha_i_axis(nullptr)
 {
     initialize();
 }
 
 OffSpecSimulation::OffSpecSimulation(const MultiLayer& p_sample)
     : Simulation(p_sample)
-    , mp_alpha_i_axis(nullptr)
 {
     initialize();
 }
 
 OffSpecSimulation::OffSpecSimulation(const std::shared_ptr<IMultiLayerBuilder> p_sample_builder)
     : Simulation(p_sample_builder)
-    , mp_alpha_i_axis(nullptr)
 {
     initialize();
 }
@@ -50,12 +47,11 @@ void OffSpecSimulation::prepareSimulation()
 
 OffSpecSimulation::OffSpecSimulation(const OffSpecSimulation& other)
     : Simulation(other)
-    , mp_alpha_i_axis(nullptr)
     , m_sim_elements(other.m_sim_elements)
     , m_storage(other.m_storage)
 {
-    if(other.mp_alpha_i_axis)
-        mp_alpha_i_axis = other.mp_alpha_i_axis->clone();
+    if(other.mP_alpha_i_axis)
+        mP_alpha_i_axis.reset(other.mP_alpha_i_axis->clone());
     m_intensity_map.copyFrom(other.m_intensity_map);
     initialize();
 }
@@ -63,7 +59,7 @@ OffSpecSimulation::OffSpecSimulation(const OffSpecSimulation& other)
 size_t OffSpecSimulation::numberOfSimulationElements() const
 {
     checkInitialization();
-    return getInstrument().getDetector()->numberOfSimulationElements()*mp_alpha_i_axis->size();
+    return getInstrument().getDetector()->numberOfSimulationElements()*mP_alpha_i_axis->size();
 }
 
 Histogram2D* OffSpecSimulation::getIntensityData() const
@@ -74,8 +70,7 @@ Histogram2D* OffSpecSimulation::getIntensityData() const
 
 void OffSpecSimulation::setBeamParameters(double lambda, const IAxis& alpha_axis, double phi_i)
 {
-    delete mp_alpha_i_axis;
-    mp_alpha_i_axis = alpha_axis.clone();
+    mP_alpha_i_axis.reset(alpha_axis.clone());
     if (alpha_axis.size()<1)
         throw Exceptions::ClassInitializationException(
                 "OffSpecSimulation::prepareSimulation() "
@@ -123,9 +118,9 @@ void OffSpecSimulation::initSimulationElementVector(bool init_storage)
     double phi_i = beam.getPhi();
     checkInitialization();
 
-    for (size_t iAlpha = 0; iAlpha < mp_alpha_i_axis->size(); ++iAlpha) {
+    for (size_t iAlpha = 0; iAlpha < mP_alpha_i_axis->size(); ++iAlpha) {
         // Incoming angle by convention defined as positive:
-        double alpha_i = mp_alpha_i_axis->getBin(iAlpha).getMidPoint();
+        double alpha_i = mP_alpha_i_axis->getBin(iAlpha).getMidPoint();
         beam.setCentralK(wavelength, alpha_i, phi_i);
         m_instrument.setBeam(beam);
         std::vector<SimulationElement> sim_elements_alpha_i =
@@ -168,15 +163,15 @@ void OffSpecSimulation::transferResultsToIntensityMap()
         throw Exceptions::RuntimeErrorException(
             "OffSpecSimulation::transferResultsToIntensityMap: "
             "intensity map size does not conform to number of calculated intensities");
-    for (size_t i=0; i<mp_alpha_i_axis->size(); ++i)
+    for (size_t i=0; i<mP_alpha_i_axis->size(); ++i)
         transferDetectorImage(i);
 }
 
 void OffSpecSimulation::updateIntensityMap()
 {
     m_intensity_map.clear();
-    if (mp_alpha_i_axis)
-        m_intensity_map.addAxis(*mp_alpha_i_axis);
+    if (mP_alpha_i_axis)
+        m_intensity_map.addAxis(*mP_alpha_i_axis);
     size_t detector_dimension = m_instrument.getDetectorDimension();
     if (detector_dimension==2)
         m_intensity_map.addAxis(m_instrument.getDetectorAxis(1));
@@ -200,7 +195,7 @@ void OffSpecSimulation::transferDetectorImage(size_t index)
 
 void OffSpecSimulation::checkInitialization() const
 {
-    if (!mp_alpha_i_axis || mp_alpha_i_axis->size()<1)
+    if (!mP_alpha_i_axis || mP_alpha_i_axis->size()<1)
         throw Exceptions::ClassInitializationException(
                 "OffSpecSimulation::checkInitialization() "
                 "Incoming alpha range not configured.");
diff --git a/Core/Simulation/OffSpecSimulation.h b/Core/Simulation/OffSpecSimulation.h
index 1f145ee8fa2..58676c71028 100644
--- a/Core/Simulation/OffSpecSimulation.h
+++ b/Core/Simulation/OffSpecSimulation.h
@@ -98,7 +98,7 @@ private:
 
     void moveDataFromStorage() override;
 
-    IAxis* mp_alpha_i_axis;
+    std::unique_ptr<IAxis> mP_alpha_i_axis;
     OutputData<double> m_intensity_map;
     std::vector<SimulationElement> m_sim_elements;
     std::vector<SimulationElement> m_storage;
diff --git a/auto/Wrap/libBornAgainCore_wrap.cpp b/auto/Wrap/libBornAgainCore_wrap.cpp
index 2a90b3f4915..1abafec3baf 100644
--- a/auto/Wrap/libBornAgainCore_wrap.cpp
+++ b/auto/Wrap/libBornAgainCore_wrap.cpp
@@ -5996,7 +5996,7 @@ SWIG_AsVal_std_complex_Sl_double_Sg_  (PyObject *o, std::complex<double>* val)
 
 
 SWIGINTERNINLINE PyObject*
-SWIG_From_std_complex_Sl_double_Sg_  (/*@SWIG:/usr/local/share/swig/3.0.8/typemaps/swigmacros.swg,104,%ifcplusplus@*/
+SWIG_From_std_complex_Sl_double_Sg_  (/*@SWIG:/usr/share/swig3.0/typemaps/swigmacros.swg,104,%ifcplusplus@*/
 
 const std::complex<double>&
 
-- 
GitLab