From 711d8f3be1e3fe29eee9f69b05800f11822b14a5 Mon Sep 17 00:00:00 2001 From: Walter Van Herck <w.van.herck@fz-juelich.de> Date: Wed, 15 May 2019 17:02:58 +0200 Subject: [PATCH] Replace awkward access to interference function of layout with a getter --- Core/Aggregate/ILayout.h | 3 +++ Core/Aggregate/ParticleLayout.cpp | 5 +++++ Core/Aggregate/ParticleLayout.h | 2 ++ Core/Multilayer/LayoutStrategyBuilder.cpp | 6 +----- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Core/Aggregate/ILayout.h b/Core/Aggregate/ILayout.h index 2d5d419fe76..c3cde085ea5 100644 --- a/Core/Aggregate/ILayout.h +++ b/Core/Aggregate/ILayout.h @@ -45,6 +45,9 @@ public: //! and generates new particles if an IAbstractParticle denotes a collection virtual SafePointerVector<IParticle> particles() const = 0; + //! Returns the interference function + virtual const IInterferenceFunction* interferenceFunction() const = 0; + /// Get total abundance of all particles virtual double getTotalAbundance() const = 0; diff --git a/Core/Aggregate/ParticleLayout.cpp b/Core/Aggregate/ParticleLayout.cpp index 2d627d79707..9992bfc7530 100644 --- a/Core/Aggregate/ParticleLayout.cpp +++ b/Core/Aggregate/ParticleLayout.cpp @@ -133,6 +133,11 @@ SafePointerVector<IParticle> ParticleLayout::particles() const return particle_vector; } +const IInterferenceFunction *ParticleLayout::interferenceFunction() const +{ + return mP_interference_function.get(); +} + double ParticleLayout::getTotalAbundance() const { double result = 0.0; diff --git a/Core/Aggregate/ParticleLayout.h b/Core/Aggregate/ParticleLayout.h index 4813d18d08b..90259c12c6e 100644 --- a/Core/Aggregate/ParticleLayout.h +++ b/Core/Aggregate/ParticleLayout.h @@ -45,6 +45,8 @@ public: SafePointerVector<IParticle> particles() const final override; + const IInterferenceFunction* interferenceFunction() const final override; + double getTotalAbundance() const final override; void setInterferenceFunction(const IInterferenceFunction& interference_function); diff --git a/Core/Multilayer/LayoutStrategyBuilder.cpp b/Core/Multilayer/LayoutStrategyBuilder.cpp index 8faa607c9da..0adf69e0dde 100644 --- a/Core/Multilayer/LayoutStrategyBuilder.cpp +++ b/Core/Multilayer/LayoutStrategyBuilder.cpp @@ -64,11 +64,7 @@ void LayoutStrategyBuilder::createStrategy() SafePointerVector<class FormFactorCoherentSum> ff_wrappers = collectFormFactorList(); // TODO: this needs to be updated (no dynamic_cast or unnecessary accessors) - const IInterferenceFunction* p_iff { nullptr }; - for (auto p_child : mp_layout->getChildren()) { - if ( (p_iff = dynamic_cast<const IInterferenceFunction*>(p_child)) ) - break; - } + const IInterferenceFunction* p_iff = mp_layout->interferenceFunction(); checkInterferenceFunction(p_iff); switch (mp_layout->getApproximation()) -- GitLab