Skip to content

Commit 29b2aae

Browse files
committed
refactor: clang-tidy
1 parent 9b89607 commit 29b2aae

File tree

12 files changed

+195
-169
lines changed

12 files changed

+195
-169
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Checks:
1919
- '-readability-math-missing-parentheses'
2020
- '-readability-avoid-unconditional-preprocessor-if'
2121
- '-readability-magic-numbers'
22+
- '-readability-container-size-empty'
2223
- 'cppcoreguidelines-*'
2324
- '-cppcoreguidelines-avoid-magic-numbers'
2425
- '-cppcoreguidelines-non-private-member-variables-in-classes'

src/core/afv/clients/afvclient.cpp

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace swift::core::afv::clients
9797
if (!hasContexts()) { return; }
9898

9999
// Disconnect all previously connect signals between the AfvClient and the required contexts
100-
for (auto context : QVector<QObject *> { sApp->getIContextOwnAircraft(), sApp->getIContextNetwork() })
100+
for (auto *context : QVector<QObject *> { sApp->getIContextOwnAircraft(), sApp->getIContextNetwork() })
101101
{
102102
this->disconnect(context);
103103
context->disconnect(this);
@@ -465,11 +465,8 @@ namespace swift::core::afv::clients
465465
if (!enabledTransceivers.contains(id)) { return false; }
466466

467467
const auto transceivers = this->getTransceivers(); // threadsafe
468-
for (const TransceiverDto &dto : transceivers)
469-
{
470-
if (dto.id == id) { return true; }
471-
}
472-
return false;
468+
return std::any_of(transceivers.cbegin(), transceivers.cend(),
469+
[&id](const TransceiverDto &dto) { return dto.id == id; });
473470
}
474471

475472
bool CAfvClient::isEnabledComUnit(CComSystem::ComUnit comUnit) const
@@ -507,7 +504,7 @@ namespace swift::core::afv::clients
507504

508505
void CAfvClient::updateComFrequency(CComSystem::ComUnit comUnit, const CFrequency &comFrequency)
509506
{
510-
const quint32 freqHz = static_cast<quint32>(comFrequency.valueInteger(CFrequencyUnit::Hz()));
507+
const auto freqHz = static_cast<quint32>(comFrequency.valueInteger(CFrequencyUnit::Hz()));
511508
this->updateComFrequency(comUnitToTransceiverId(comUnit), freqHz);
512509
}
513510

@@ -592,11 +589,8 @@ namespace swift::core::afv::clients
592589
bool CAfvClient::isTransmittingTransceiver(quint16 id) const
593590
{
594591
QMutexLocker lock(&m_mutexTransceivers);
595-
for (const TxTransceiverDto &dto : m_transmittingTransceivers)
596-
{
597-
if (dto.id == id) { return true; }
598-
}
599-
return false;
592+
return std::any_of(m_transmittingTransceivers.cbegin(), m_transmittingTransceivers.cend(),
593+
[&id](const TxTransceiverDto &dto) { return dto.id == id; });
600594
}
601595

602596
bool CAfvClient::isTransmittingComUnit(CComSystem::ComUnit comUnit) const
@@ -747,21 +741,17 @@ namespace swift::core::afv::clients
747741
double CAfvClient::getComOutputVolumeDb(CComSystem::ComUnit comUnit) const
748742
{
749743
QMutexLocker lock(&m_mutexVolume);
750-
if (comUnit == CComSystem::Com1)
751-
return m_outputVolumeDbCom1;
752-
else if (comUnit == CComSystem::Com2)
753-
return m_outputVolumeDbCom2;
744+
if (comUnit == CComSystem::Com1) return m_outputVolumeDbCom1;
745+
if (comUnit == CComSystem::Com2) return m_outputVolumeDbCom2;
754746
qFatal("Invalid COM unit");
755747
return 0;
756748
}
757749

758750
double CAfvClient::getOutputGainRatio(CComSystem::ComUnit comUnit) const
759751
{
760752
QMutexLocker lock(&m_mutexVolume);
761-
if (comUnit == CComSystem::Com1)
762-
return m_outputGainRatioCom1;
763-
else if (comUnit == CComSystem::Com2)
764-
return m_outputGainRatioCom2;
753+
if (comUnit == CComSystem::Com1) return m_outputGainRatioCom1;
754+
if (comUnit == CComSystem::Com2) return m_outputGainRatioCom2;
765755
qFatal("Invalid COM unit");
766756
return 0;
767757
}
@@ -784,7 +774,7 @@ namespace swift::core::afv::clients
784774
{
785775
QMutexLocker lock(&m_mutexVolume);
786776
if (comUnit == CComSystem::Com1) { return m_outputVolumeCom1Normalized; }
787-
else if (comUnit == CComSystem::Com2) { return m_outputVolumeCom2Normalized; }
777+
if (comUnit == CComSystem::Com2) { return m_outputVolumeCom2Normalized; }
788778
qFatal("Invalid ComUnit");
789779
return 0;
790780
}
@@ -1069,7 +1059,10 @@ namespace swift::core::afv::clients
10691059
const int failures = ++m_heartBeatFailures;
10701060
if (failures < 2) { return; }
10711061

1072-
QString un, pw, cs, client;
1062+
QString un;
1063+
QString pw;
1064+
QString cs;
1065+
QString client;
10731066
{
10741067
QMutexLocker lock(&m_mutexConnection);
10751068
un = m_connection->getUserName();
@@ -1331,17 +1324,17 @@ namespace swift::core::afv::clients
13311324
{
13321325
QMutexLocker lock(&m_mutex);
13331326
CFrequency roundedFrequency(static_cast<int>(roundedFrequencyHz), CFrequencyUnit::Hz());
1334-
const auto it = std::find_if(
1335-
m_aliasedStations.constBegin(), m_aliasedStations.constEnd(), [roundedFrequency](const StationDto &d) {
1336-
if (d.frequencyAliasHz > 100000000 &&
1337-
roundedFrequency.value(CFrequencyUnit::Hz()) > 100000000) // both VHF
1338-
{
1339-
const int aliasedFreqHz = static_cast<int>(qRound(d.frequencyAliasHz / 1000.0)) * 1000;
1340-
return CComSystem::isSameFrequency(CFrequency(aliasedFreqHz, CFrequencyUnit::Hz()),
1341-
roundedFrequency);
1342-
}
1343-
return d.frequencyAliasHz == roundedFrequency.value(CFrequencyUnit::Hz());
1344-
});
1327+
const auto it = std::find_if(m_aliasedStations.constBegin(), m_aliasedStations.constEnd(),
1328+
[roundedFrequency](const StationDto &d) {
1329+
if (d.frequencyAliasHz > 100000000 &&
1330+
roundedFrequency.value(CFrequencyUnit::Hz()) > 100000000) // both VHF
1331+
{
1332+
const int aliasedFreqHz = qRound(d.frequencyAliasHz / 1000.0) * 1000;
1333+
return CComSystem::isSameFrequency(
1334+
CFrequency(aliasedFreqHz, CFrequencyUnit::Hz()), roundedFrequency);
1335+
}
1336+
return d.frequencyAliasHz == roundedFrequency.value(CFrequencyUnit::Hz());
1337+
});
13451338

13461339
if (it != m_aliasedStations.constEnd())
13471340
{

src/core/airspaceanalyzer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ namespace swift::core
9999
m_simulatorMaxRenderedDistance = maxRenderedDistance;
100100
}
101101

102-
CAirspaceAnalyzer::~CAirspaceAnalyzer() {}
103-
104102
void CAirspaceAnalyzer::onNetworkPositionUpdate(const CAircraftSituation &situation,
105103
const CTransponder &transponder)
106104
{
@@ -172,7 +170,7 @@ namespace swift::core
172170
// this is a trick to not remove everything while debugging
173171
const qint64 currentTimeMsEpoch = QDateTime::currentMSecsSinceEpoch();
174172
const qint64 callDiffMs = currentTimeMsEpoch - m_lastWatchdogCallMsSinceEpoch;
175-
const qint64 callThresholdMs = static_cast<qint64>(updateInterval.count() * 1.5);
173+
constexpr auto callThresholdMs = static_cast<qint64>(updateInterval.count() * 1.5);
176174
m_lastWatchdogCallMsSinceEpoch = currentTimeMsEpoch;
177175
if (callDiffMs > callThresholdMs)
178176
{
@@ -228,8 +226,9 @@ namespace swift::core
228226
Q_ASSERT_X(!CThreadUtils::thisIsMainThread(), Q_FUNC_INFO, "Expect to run in background thread");
229227
Q_ASSERT_X(thread() != qApp->thread(), Q_FUNC_INFO, "Expect to run in background thread affinity");
230228

231-
bool restricted, enabled;
232-
int maxAircraft;
229+
bool restricted {};
230+
bool enabled {};
231+
int maxAircraft {};
233232
CLength maxRenderedDistance;
234233
{
235234
QReadLocker l(&m_lockRestrictions);

src/core/airspaceanalyzer.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,19 @@ namespace swift::core
6363
fsd::CFSDClient *fsdClient, CAirspaceMonitor *airspaceMonitorParent);
6464

6565
//! Destructor
66-
virtual ~CAirspaceAnalyzer() override;
66+
~CAirspaceAnalyzer() override = default;
67+
68+
//! Copy constructor
69+
CAirspaceAnalyzer(const CAirspaceAnalyzer &) = delete;
70+
71+
//! Copy assignment
72+
CAirspaceAnalyzer &operator=(const CAirspaceAnalyzer &) = delete;
73+
74+
//! Move constructor
75+
CAirspaceAnalyzer(CAirspaceAnalyzer &&) = delete;
76+
77+
//! Move assignment
78+
CAirspaceAnalyzer &operator=(CAirspaceAnalyzer &&) = delete;
6779

6880
//! Get the latest snapshot
6981
//! \threadsafe

src/core/airspacemonitor.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ namespace swift::core
176176
{
177177
if (!myself || !sApp || sApp->isShuttingDown()) // cppcheck-suppress knownConditionTrueFalse
178178
{
179-
return CFlightPlan();
179+
return {};
180180
}
181181
if (m_flightPlanCache.contains(callsign)) { plan = m_flightPlanCache[callsign]; }
182182
}
@@ -186,7 +186,7 @@ namespace swift::core
186186

187187
CFlightPlanRemarks CAirspaceMonitor::tryToGetFlightPlanRemarks(const CCallsign &callsign) const
188188
{
189-
if (callsign.isEmpty()) { return CFlightPlanRemarks(); }
189+
if (callsign.isEmpty()) { return {}; }
190190

191191
// full flight plan's remarks
192192
if (m_flightPlanCache.contains(callsign)) { return m_flightPlanCache[callsign].getFlightPlanRemarks(); }
@@ -198,7 +198,7 @@ namespace swift::core
198198
}
199199

200200
// unsupported
201-
return CFlightPlanRemarks();
201+
return {};
202202
}
203203

204204
CAtcStationList CAirspaceMonitor::getAtcStationsOnlineRecalculated()
@@ -524,14 +524,14 @@ namespace swift::core
524524
if (!sApp || sApp->isShuttingDown() || !sApp->getWebDataServices()) { return; }
525525
CClientList clients(this->getClients()); // copy
526526
bool changed = false;
527-
for (auto client = clients.begin(); client != clients.end(); ++client)
527+
for (auto &client : clients)
528528
{
529-
if (client->hasSpecifiedVoiceCapabilities()) { continue; } // we already have voice caps
529+
if (client.hasSpecifiedVoiceCapabilities()) { continue; } // we already have voice caps
530530
const CVoiceCapabilities vc =
531-
sApp->getWebDataServices()->getVoiceCapabilityForCallsign(client->getCallsign());
531+
sApp->getWebDataServices()->getVoiceCapabilityForCallsign(client.getCallsign());
532532
if (vc.isUnknown()) { continue; }
533533
changed = true;
534-
client->setVoiceCapabilities(vc);
534+
client.setVoiceCapabilities(vc);
535535
}
536536
if (!changed) { return; }
537537
this->setClients(clients);
@@ -756,7 +756,7 @@ namespace swift::core
756756
// TODO Replace with Qt 6.0 QStringView::slice()
757757
zuluTimeView.chop(1); // Remove z
758758

759-
bool ok;
759+
bool ok {};
760760
const int h = zuluTimeView.left(2).toInt(&ok);
761761
if (!ok) { return; }
762762
const int m = zuluTimeView.right(2).toInt(&ok);
@@ -1063,13 +1063,10 @@ namespace swift::core
10631063
callsign, rv.model.getAircraftIcaoCodeDesignator(), rv.model.getAirlineIcaoCodeVDesignator(),
10641064
rv.model.getLivery().getCombinedCode(), modelString, type, log, false);
10651065
}
1066-
else
1067-
{
1068-
lookupModel = rv.model;
1069-
CCallsign::addLogDetailsToList(log, callsign,
1070-
QStringLiteral("Matching script: Using model from matching script"),
1071-
CAirspaceMonitor::getLogCategories());
1072-
}
1066+
lookupModel = rv.model;
1067+
CCallsign::addLogDetailsToList(log, callsign,
1068+
QStringLiteral("Matching script: Using model from matching script"),
1069+
CAirspaceMonitor::getLogCategories());
10731070
}
10741071
}
10751072
else { CCallsign::addLogDetailsToList(log, callsign, QStringLiteral("No reverse lookup script used")); }
@@ -1451,19 +1448,19 @@ namespace swift::core
14511448
if (callsign.isEmpty()) { return; }
14521449

14531450
unsigned long pp = 0;
1454-
bool ok;
1451+
bool ok {};
14551452
pp = config.toULong(&ok, 10);
14561453

1457-
bool gear = (pp & 1u);
1458-
bool landLight = (pp & 2u);
1459-
bool navLight = (pp & 4u);
1460-
bool strobeLight = (pp & 8u);
1461-
bool beaconLight = (pp & 16u);
1462-
bool taxiLight = (pp & 32u);
1463-
bool engine1Running = (pp & 64u);
1464-
bool engine2Running = (pp & 128u);
1465-
bool engine3Running = (pp & 256u);
1466-
bool engine4Running = (pp & 512u);
1454+
bool gear = (pp & 1U);
1455+
bool landLight = (pp & 2U);
1456+
bool navLight = (pp & 4U);
1457+
bool strobeLight = (pp & 8U);
1458+
bool beaconLight = (pp & 16U);
1459+
bool taxiLight = (pp & 32U);
1460+
bool engine1Running = (pp & 64U);
1461+
bool engine2Running = (pp & 128U);
1462+
bool engine3Running = (pp & 256U);
1463+
bool engine4Running = (pp & 512U);
14671464

14681465
// CLogMessage(this).info(u"taxiLight %1 landLight %2 beaconLight %3 strobeLight %4 gear %5") << taxiLight <<
14691466
// landLight << beaconLight << strobeLight << gear; CLogMessage(this).info(u"engine1Running %1 engine2Running %2

src/core/airspacemonitor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace swift::core
5353

5454
//! Keeps track of other entities in the airspace: aircraft, ATC stations, etc.
5555
//! Central instance of data for \sa IRemoteAircraftProvider.
56-
class SWIFT_CORE_EXPORT CAirspaceMonitor :
56+
class SWIFT_CORE_EXPORT CAirspaceMonitor final :
5757
public swift::misc::simulation::CRemoteAircraftProvider, // those data will be provided from the class
5858
// CAirspaceMonitor
5959
public swift::misc::network::CClientProvider, // those data will be provided from the class CAirspaceMonitor
@@ -198,7 +198,7 @@ namespace swift::core
198198
FsInnPacket() {}
199199

200200
//! Constructor
201-
FsInnPacket(const QString &aircraftIcaoDesignator, const QString &airlineDesignator,
201+
FsInnPacket(const QString &aircraftIcaoDesignator, const QString &airlineIcaoDesignator,
202202
const QString &combinedCode, const QString &modelString);
203203

204204
QString aircraftIcaoDesignator;
@@ -444,7 +444,7 @@ namespace swift::core
444444
//! Receive FSInn packet
445445
//! \remark This can happen even without a query before
446446
void onCustomFSInnPacketReceived(const swift::misc::aviation::CCallsign &callsign,
447-
const QString &airlineIcaoDesignator, const QString &aircraftDesignator,
447+
const QString &airlineIcaoDesignator, const QString &aircraftIcaoDesignator,
448448
const QString &combinedAircraftType, const QString &modelString);
449449

450450
void onRealNameReplyReceived(const swift::misc::aviation::CCallsign &callsign, const QString &realname);

src/core/db/backgrounddataupdater.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace swift::core::db
141141
if (c > 0)
142142
{
143143
const CStatusMessage m = modelCaches.setCachedModels(simulatorModels, singleSimulator);
144-
const int msElapsed = time.elapsed();
144+
const qint64 msElapsed = time.elapsed();
145145
this->addHistory(CLogMessage(this).info(u"Consolidated %1 models (%2) for '%3' in %4ms")
146146
<< c << description << singleSimulator.convertToQString() << msElapsed);
147147
CLogMessage::preformatted(m);

src/core/threadedreader.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "core/swiftcoreexport.h"
1919
#include "core/vatsim/vatsimsettings.h"
20-
#include "misc/logcategories.h"
2120
#include "misc/network/urlloglist.h"
2221
#include "misc/worker.h"
2322

@@ -39,7 +38,19 @@ namespace swift::core
3938
static const QStringList &getLogCategories();
4039

4140
//! Destructor
42-
virtual ~CThreadedReader() = default;
41+
~CThreadedReader() override = default;
42+
43+
//! Copy constructor
44+
CThreadedReader(const CThreadedReader &) = delete;
45+
46+
//! Copy assignment
47+
CThreadedReader &operator=(const CThreadedReader &) = delete;
48+
49+
//! Move constructor
50+
CThreadedReader(CThreadedReader &&) = delete;
51+
52+
//! Move assignment
53+
CThreadedReader &operator=(CThreadedReader &&) = delete;
4354

4455
//! Thread safe, get update timestamp
4556
//! \threadsafe

0 commit comments

Comments
 (0)