refactor: Use dynamic lookup with pure virtual methods

This makes it clearer what an IInterpolant and Interpolator must
implemented.
But it should be checked if using virtual here is okay performance-wise.
This commit is contained in:
Lars Toenning
2024-01-09 22:59:23 +01:00
parent be2c756c8c
commit cb7e6c43e2
7 changed files with 77 additions and 97 deletions

View File

@@ -15,7 +15,7 @@
namespace BlackMisc::Simulation
{
//! Cubic spline interpolator
class BLACKMISC_EXPORT CInterpolatorSpline : public CInterpolator<CInterpolatorSpline>
class BLACKMISC_EXPORT CInterpolatorSpline : public CInterpolator
{
virtual void anchor() override;
@@ -63,13 +63,11 @@ namespace BlackMisc::Simulation
//! Constructor
CInterpolant(const PosArray &pa, const PhysicalQuantities::CLengthUnit &altitudeUnit, const CInterpolatorLinearPbh &pbh);
//! Perform the interpolation
//! \param situation situation used as a base for interpolation. Contains for example the already interpolated PBH.
//! \return \p situation with interpolated position and altitude and updated timestamp
std::tuple<Geo::CCoordinateGeodetic, Aviation::CAltitude> interpolatePositionAndAltitude() const;
//! \copydoc BlackMisc::Simulation::IInterpolant::interpolatePositionAndAltitude
std::tuple<Geo::CCoordinateGeodetic, Aviation::CAltitude> interpolatePositionAndAltitude() const override;
//! Interpolate the ground information/factor
Aviation::COnGroundInfo interpolateGroundFactor() const;
//! \copydoc BlackMisc::Simulation::IInterpolant::interpolateGroundFactor
Aviation::COnGroundInfo interpolateGroundFactor() const override;
//! Set the time values
void setTimes(qint64 currentTimeMs, double timeFraction, qint64 interpolatedTimeMs);
@@ -77,7 +75,8 @@ namespace BlackMisc::Simulation
//! \private UNIT tests/ASSERT only
const PosArray &getPa() const { return m_pa; }
const IInterpolatorPbh &pbh() const { return m_pbh; }
//! \copydoc BlackMisc::Simulation::IInterpolant::pbh
const IInterpolatorPbh &pbh() const override { return m_pbh; }
private:
PosArray m_pa; //!< current positions array, latest values last
@@ -86,8 +85,8 @@ namespace BlackMisc::Simulation
CInterpolatorLinearPbh m_pbh; //!< the used PBH interpolator
};
//! Strategy used by CInterpolator::getInterpolatedSituation
CInterpolant getInterpolant(SituationLog &log);
//! \copydoc BlackMisc::Simulation::CInterpolator::getInterpolant
const IInterpolant &getInterpolant(SituationLog &log) override;
private:
//! Update the elevations used in CInterpolatorSpline::m_s