From ab8498faa0d63ffec28b8a14b6e34f363d6ccd34 Mon Sep 17 00:00:00 2001 From: Walter Van Herck <w.van.herck@fz-juelich.de> Date: Thu, 7 Sep 2017 10:43:58 +0200 Subject: [PATCH] Layer: remove private copy constructor and refactor clone and cloneInvertB --- Core/Multilayer/Layer.cpp | 26 +++++++++----------------- Core/Multilayer/Layer.h | 1 - 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/Core/Multilayer/Layer.cpp b/Core/Multilayer/Layer.cpp index 0737cd99694..7446356c3f4 100644 --- a/Core/Multilayer/Layer.cpp +++ b/Core/Multilayer/Layer.cpp @@ -36,16 +36,20 @@ Layer::Layer(HomogeneousMaterial material, double thickness) Layer::~Layer() {} -Layer*Layer::clone() const +Layer* Layer::clone() const { - return new Layer(*this); + Layer* p_result = shallowClone(); + p_result->m_n_slices = m_n_slices; + for (auto p_layout : layouts()) + p_result->addLayout(*p_layout); + return p_result; } Layer* Layer::cloneInvertB() const { - Layer* p_clone = new Layer(m_material.inverted(), m_thickness); - p_clone->m_B_field = - m_B_field; - return p_clone; + Layer* p_result = shallowClone(); + p_result->m_B_field = -m_B_field; + return p_result; } SafePointerVector<Layer> Layer::cloneSliced(ZLimits limits, Layer::ELayerType layer_type) const @@ -160,18 +164,6 @@ void Layer::initBField(kvector_t h_field, double b_z) m_B_field.setZ(b_z); } -Layer::Layer(const Layer& other) - : m_material(other.m_material) -{ - setName(other.getName()); - m_thickness = other.m_thickness; - m_n_slices = other.m_n_slices; - m_B_field = other.m_B_field; - for (auto p_layout : other.layouts()) - addLayout(*p_layout); - registerThickness(); -} - Layer* Layer::shallowClone() const { Layer* p_result = new Layer(m_material, m_thickness); diff --git a/Core/Multilayer/Layer.h b/Core/Multilayer/Layer.h index 62e5d270d0c..ca777912ed3 100644 --- a/Core/Multilayer/Layer.h +++ b/Core/Multilayer/Layer.h @@ -81,7 +81,6 @@ public: static constexpr double Magnetic_Permeability = 4e-7 * M_PI; private: - Layer(const Layer& other); //! Clone the layer without its layouts Layer* shallowClone() const; //! Clone and offsets the particles in the z-direction -- GitLab