Skip to content

Commit dacf2c5

Browse files
committed
refactor: Use composition over inheritance
1 parent 75e5e73 commit dacf2c5

File tree

4 files changed

+11
-48
lines changed

4 files changed

+11
-48
lines changed

src/core/airspacemonitor.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ namespace swift::core
5757
CAirspaceMonitor::CAirspaceMonitor(IOwnAircraftProvider *ownAircraftProvider,
5858
IAircraftModelSetProvider *modelSetProvider, CFSDClient *fsdClient,
5959
QObject *parent)
60-
: CRemoteAircraftProvider(parent), COwnAircraftAware(ownAircraftProvider),
61-
CAircraftModelSetAware(modelSetProvider), m_fsdClient(fsdClient),
62-
m_analyzer(new CAirspaceAnalyzer(ownAircraftProvider, m_fsdClient, this))
60+
: CRemoteAircraftProvider(parent), COwnAircraftAware(ownAircraftProvider), m_modelSetProvider(modelSetProvider),
61+
m_fsdClient(fsdClient), m_analyzer(new CAirspaceAnalyzer(ownAircraftProvider, m_fsdClient, this))
6362
{
6463
this->setObjectName("CAirspaceMonitor");
6564
this->enableReverseLookupMessages(sApp->isDeveloperFlagSet() || CBuildConfig::isLocalDeveloperDebugBuild() ?
@@ -891,7 +890,7 @@ namespace swift::core
891890
const QString &liveryString, const QString &modelString, CAircraftModel::ModelType type,
892891
CStatusMessageList *log, bool runMatchinScript)
893892
{
894-
const int modelSetCount = this->getModelSetCount();
893+
const int modelSetCount = m_modelSetProvider->getModelSetCount();
895894
CCallsign::addLogDetailsToList(
896895
log, callsign, QStringLiteral("Reverse lookup (with FP data), model set count: %1").arg(modelSetCount),
897896
CAirspaceMonitor::getLogCategories());
@@ -901,7 +900,7 @@ namespace swift::core
901900
if (hasAnyId) { this->markAsSwiftClient(callsign); }
902901

903902
CAircraftModel lookupModel; // result
904-
const CAircraftModelList modelSet = this->getModelSet();
903+
const CAircraftModelList modelSet = m_modelSetProvider->getModelSet();
905904
const CAircraftMatcherSetup setup = m_matchingSettings.get();
906905
do {
907906
// directly check model string

src/core/airspacemonitor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ namespace swift::core
5858
// CAirspaceMonitor
5959
public swift::misc::network::CClientProvider, // those data will be provided from the class CAirspaceMonitor
6060
public swift::misc::simulation::COwnAircraftAware, // used to obtain in memory information about own aircraft
61-
public swift::misc::simulation::CSimulationEnvironmentAware, // elevation info etc. from simulator
62-
public swift::misc::simulation::CAircraftModelSetAware // model set for reverse lookup
61+
public swift::misc::simulation::CSimulationEnvironmentAware // elevation info etc. from simulator
6362
{
6463
// CRemoteAircraftProvider is QObject
6564
Q_OBJECT
@@ -279,6 +278,7 @@ namespace swift::core
279278
}; //!< settings
280279
QQueue<swift::misc::aviation::CCallsign> m_queryAtis; //!< query the ATIS
281280
QQueue<swift::misc::aviation::CCallsign> m_queryPilot; //!< query the pilot data
281+
misc::simulation::IAircraftModelSetProvider *m_modelSetProvider = nullptr; //!< model set for reverse lookup
282282
fsd::CFSDClient *m_fsdClient = nullptr; //!< corresponding network interface
283283
CAirspaceAnalyzer *m_analyzer = nullptr; //!< owned analyzer
284284
int m_maxDistanceNM = 125; //!< position range / FSD range
Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
// SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
22
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3-
43
#include "misc/simulation/aircraftmodelsetprovider.h"
5-
64
namespace swift::misc::simulation
75
{
8-
// pin vtables to this file
9-
void CAircraftModelSetAware::anchor() {}
10-
11-
CAircraftModelList CAircraftModelSetAware::getModelSet() const
12-
{
13-
if (!this->hasProvider()) { return CAircraftModelList(); }
14-
return this->provider()->getModelSet();
15-
}
16-
17-
int CAircraftModelSetAware::getModelSetCount() const
18-
{
19-
if (!this->hasProvider()) { return -1; }
20-
return this->provider()->getModelSetCount();
21-
}
22-
23-
} // namespace swift::misc::simulation
6+
// pin vtable to this file
7+
void IAircraftModelSetProvider::anchor() {}
8+
} // namespace swift::misc::simulation

src/misc/simulation/aircraftmodelsetprovider.h

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace swift::misc::simulation
1515
//! Value object encapsulating a list of aircraft models
1616
class SWIFT_MISC_EXPORT IAircraftModelSetProvider : public IProvider
1717
{
18+
virtual void anchor();
19+
1820
public:
1921
//! Get the model set models
2022
virtual CAircraftModelList getModelSet() const = 0;
@@ -26,29 +28,6 @@ namespace swift::misc::simulation
2628
IAircraftModelSetProvider() = default;
2729
};
2830

29-
//! Delegating class which can be directly used to access an \sa IAircraftModelSetProvider instance
30-
class SWIFT_MISC_EXPORT CAircraftModelSetAware : public IProviderAware<IAircraftModelSetProvider>
31-
{
32-
virtual void anchor();
33-
34-
public:
35-
//! Set the provider
36-
void setAircraftModelSetProvider(IAircraftModelSetProvider *provider) { this->setProvider(provider); }
37-
38-
//! \copydoc IAircraftModelSetProvider::getModelSet
39-
CAircraftModelList getModelSet() const;
40-
41-
//! \copydoc IAircraftModelSetProvider::getModelSetCount
42-
int getModelSetCount() const;
43-
44-
protected:
45-
//! Constructor
46-
CAircraftModelSetAware(IAircraftModelSetProvider *modelSetProvider) : IProviderAware(modelSetProvider)
47-
{
48-
Q_ASSERT(modelSetProvider);
49-
}
50-
};
51-
5231
} // namespace swift::misc::simulation
5332

5433
Q_DECLARE_INTERFACE(swift::misc::simulation::IAircraftModelSetProvider,

0 commit comments

Comments
 (0)