mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-07-31 22:05:38 +08:00
Use std::as_const (C++17 feature)
This commit is contained in:
@@ -163,22 +163,22 @@ namespace BlackSample
|
||||
QString containsStr("aaa");
|
||||
number = 0;
|
||||
timer.start();
|
||||
for (const auto &str : as_const(strList1)) { if (newRegex.match(str).hasMatch()) number++; }
|
||||
for (const auto &str : std::as_const(strList1)) { if (newRegex.match(str).hasMatch()) number++; }
|
||||
ms = timer.elapsed();
|
||||
out << "new regex matched " << number << " of" << strList1.size() << " strings in " << ms << "ms" << Qt::endl;
|
||||
number = 0;
|
||||
timer.start();
|
||||
for (const auto &str : as_const(strList2)) { if (fullRegex.exactMatch(str)) number++; }
|
||||
for (const auto &str : std::as_const(strList2)) { if (fullRegex.exactMatch(str)) number++; }
|
||||
ms = timer.elapsed();
|
||||
out << "full regex matched " << number << " of" << strList2.size() << " strings in " << ms << "ms" << Qt::endl;
|
||||
number = 0;
|
||||
timer.start();
|
||||
for (const auto &str : as_const(strList3)) { if (wildcardRegex.exactMatch(str)) number++; }
|
||||
for (const auto &str : std::as_const(strList3)) { if (wildcardRegex.exactMatch(str)) number++; }
|
||||
ms = timer.elapsed();
|
||||
out << "wildcard matched " << number << " of " << strList3.size() << " strings in " << ms << "ms" << Qt::endl;
|
||||
number = 0;
|
||||
timer.start();
|
||||
for (const auto &str : as_const(strList4)) { if (str.contains(containsStr)) number++; }
|
||||
for (const auto &str : std::as_const(strList4)) { if (str.contains(containsStr)) number++; }
|
||||
ms = timer.elapsed();
|
||||
out << "contains matched " << number << " of " << strList4.size() << " strings in " << ms << "ms" << Qt::endl;
|
||||
|
||||
@@ -361,7 +361,7 @@ namespace BlackSample
|
||||
upperRegex.optimize();
|
||||
|
||||
timer.start();
|
||||
for (const QString &s : as_const(strings))
|
||||
for (const QString &s : std::as_const(strings))
|
||||
{
|
||||
auto c = containsChar(s, [](QChar c) { return c.isUpper(); });
|
||||
Q_UNUSED(c);
|
||||
@@ -369,7 +369,7 @@ namespace BlackSample
|
||||
out << "Check 100,000 strings for containing uppercase letter: (utility) " << timer.elapsed() << "ms" << Qt::endl;
|
||||
|
||||
timer.start();
|
||||
for (const QString &s : as_const(strings))
|
||||
for (const QString &s : std::as_const(strings))
|
||||
{
|
||||
auto c = s.contains(upperRegex);
|
||||
Q_UNUSED(c);
|
||||
@@ -377,7 +377,7 @@ namespace BlackSample
|
||||
out << "Check 100,000 strings for containing uppercase letter: (regex) " << timer.elapsed() << "ms" << endl << Qt::endl;
|
||||
|
||||
timer.start();
|
||||
for (const QString &s : as_const(strings))
|
||||
for (const QString &s : std::as_const(strings))
|
||||
{
|
||||
auto i = indexOfChar(s, [](QChar c) { return c.isUpper(); });
|
||||
Q_UNUSED(i);
|
||||
@@ -385,7 +385,7 @@ namespace BlackSample
|
||||
out << "Check 100,000 strings for index of first uppercase letter: (utility) " << timer.elapsed() << "ms" << Qt::endl;
|
||||
|
||||
timer.start();
|
||||
for (const QString &s : as_const(strings))
|
||||
for (const QString &s : std::as_const(strings))
|
||||
{
|
||||
auto i = s.indexOf(upperRegex);
|
||||
Q_UNUSED(i);
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace BlackCore
|
||||
QVector<float> buffer;
|
||||
m_sampleProvider->readSamples(buffer, count);
|
||||
|
||||
for (float sample : as_const(buffer))
|
||||
for (float sample : std::as_const(buffer))
|
||||
{
|
||||
const float absSample = qAbs(sample);
|
||||
if (absSample > m_maxSampleOutput) { m_maxSampleOutput = absSample; }
|
||||
|
||||
@@ -282,7 +282,7 @@ namespace BlackCore
|
||||
|
||||
// we might have unresolved callsigns
|
||||
// those are the ones not in range
|
||||
for (const CCallsign &callsign : as_const(searchList))
|
||||
for (const CCallsign &callsign : std::as_const(searchList))
|
||||
{
|
||||
const CUserList usersByCallsign = sApp->getWebDataServices()->getUsersForCallsign(callsign);
|
||||
if (usersByCallsign.isEmpty())
|
||||
|
||||
@@ -371,7 +371,7 @@ namespace BlackCore
|
||||
myAircraft.getHeading().normalizedTo360Degrees().value(CAngleUnit::deg()),
|
||||
myAircraft.getParts().isOnGround());
|
||||
|
||||
for (const auto &receiver : as_const(m_interimPositionReceivers))
|
||||
for (const auto &receiver : std::as_const(m_interimPositionReceivers))
|
||||
{
|
||||
interimPilotDataUpdate.setReceiver(receiver.asString());
|
||||
sendQueudedMessage(interimPilotDataUpdate);
|
||||
@@ -1774,7 +1774,7 @@ namespace BlackCore
|
||||
{
|
||||
emit atisLogoffTimeReplyReceived(sender, message);
|
||||
CInformationMessage atisMessage(CInformationMessage::ATIS);
|
||||
for (const auto &line : as_const(pendingQuery.m_atisMessage))
|
||||
for (const auto &line : std::as_const(pendingQuery.m_atisMessage))
|
||||
{
|
||||
if (!atisMessage.isEmpty()) atisMessage.appendMessage("\n");
|
||||
atisMessage.appendMessage(line);
|
||||
@@ -1871,7 +1871,7 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
if (callStatistics.isEmpty()) { return QString(); }
|
||||
for (const auto [key, value] : makePairsRange(as_const(callStatistics)))
|
||||
for (const auto [key, value] : makePairsRange(std::as_const(callStatistics)))
|
||||
{
|
||||
// key is pair.first, value is pair.second
|
||||
transformed.push_back({ value, key });
|
||||
@@ -1975,7 +1975,7 @@ namespace BlackCore
|
||||
if (m_printToConsole) { qDebug() << "FSD Recv=>" << line; }
|
||||
emitRawFsdMessage(line, false);
|
||||
|
||||
for (const QString &str : makeKeysRange(as_const(m_messageTypeMapping)))
|
||||
for (const QString &str : makeKeysRange(std::as_const(m_messageTypeMapping)))
|
||||
{
|
||||
if (line.startsWith(str))
|
||||
{
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace BlackCore
|
||||
if (action.isEmpty()) { return; }
|
||||
if (m_actionRelayingEnabled && shouldEmit) { emit remoteActionFromLocal(action, isKeyDown); }
|
||||
|
||||
for (const auto &boundAction : as_const(m_boundActions))
|
||||
for (const auto &boundAction : std::as_const(m_boundActions))
|
||||
{
|
||||
if (boundAction.m_action == action)
|
||||
{
|
||||
@@ -178,7 +178,7 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
QSet<QString> newActiveActions;
|
||||
for (const auto [combination, action] : makePairsRange(as_const(m_configuredActions)))
|
||||
for (const auto [combination, action] : makePairsRange(std::as_const(m_configuredActions)))
|
||||
{
|
||||
if (combination.isSubsetOf(currentCombination))
|
||||
{
|
||||
|
||||
@@ -366,7 +366,7 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
// blink mode, toggle aircraft
|
||||
for (const CSimulatedAircraft &aircraft : as_const(m_highlightedAircraft))
|
||||
for (const CSimulatedAircraft &aircraft : std::as_const(m_highlightedAircraft))
|
||||
{
|
||||
if (m_blinkCycle) { this->callPhysicallyRemoveRemoteAircraft(aircraft.getCallsign(), true); }
|
||||
else { this->callPhysicallyAddRemoteAircraft(aircraft); }
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace BlackCore
|
||||
const WeatherRequest weatherRequest = m_pendingRequests.constFirst();
|
||||
const CLength maxDistance(100.0, CLengthUnit::km());
|
||||
|
||||
for (IWeatherData *plugin : as_const(m_weatherDataPlugins))
|
||||
for (IWeatherData *plugin : std::as_const(m_weatherDataPlugins))
|
||||
{
|
||||
if (!plugin) { continue; }
|
||||
if (weatherRequest.filePath.isEmpty())
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace BlackGui
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
int added = 0;
|
||||
for (const CAtcStation &station : as_const(stations))
|
||||
for (const CAtcStation &station : std::as_const(stations))
|
||||
{
|
||||
if (m_ignoreNonAtc)
|
||||
{
|
||||
|
||||
@@ -159,7 +159,7 @@ namespace BlackGui
|
||||
|
||||
QStringList select = comp.missingInTarget.values();
|
||||
select.append(comp.newerInSource.values());
|
||||
for (const QString &file : as_const(comp.missingInTarget))
|
||||
for (const QString &file : std::as_const(comp.missingInTarget))
|
||||
{
|
||||
const QModelIndex index = sourceModel->index(file);
|
||||
if (!index.isValid()) continue;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace BlackGui
|
||||
connect(ui->pb_Update, &QPushButton::clicked, this, &CWeatherComponent::updateWeatherInformationForced);
|
||||
|
||||
m_weatherScenarios = CWeatherGrid::getAllScenarios();
|
||||
for (const auto &scenario : as_const(m_weatherScenarios))
|
||||
for (const auto &scenario : std::as_const(m_weatherScenarios))
|
||||
{
|
||||
ui->cb_weatherScenario->addItem(scenario.getName(), QVariant::fromValue(scenario));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace BlackGui
|
||||
{
|
||||
ui->setupUi(this);
|
||||
m_allCheckBoxes = this->findChildren<QCheckBox *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QCheckBox *cb : as_const(m_allCheckBoxes))
|
||||
for (QCheckBox *cb : std::as_const(m_allCheckBoxes))
|
||||
{
|
||||
connect(cb, &QCheckBox::stateChanged, this, &CInterpolationSetupForm::onCheckboxChanged);
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ namespace BlackGui
|
||||
|
||||
void CInfoArea::adjustSizeForAllDockWidgets()
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
|
||||
for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
|
||||
{
|
||||
dw->adjustSize();
|
||||
}
|
||||
@@ -348,7 +348,7 @@ namespace BlackGui
|
||||
|
||||
void CInfoArea::floatAllWidgets()
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
|
||||
for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
|
||||
{
|
||||
if (dw->isFloating()) { continue; }
|
||||
dw->toggleFloating();
|
||||
@@ -357,7 +357,7 @@ namespace BlackGui
|
||||
|
||||
void CInfoArea::resetAllFloatingWidgetSettings()
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
|
||||
for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
|
||||
{
|
||||
if (!dw || !dw->isFloating()) { continue; }
|
||||
dw->resetSettings();
|
||||
@@ -366,7 +366,7 @@ namespace BlackGui
|
||||
|
||||
void CInfoArea::resetAllWidgetSettings()
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
|
||||
for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
|
||||
{
|
||||
if (!dw || !dw->isFloating()) { continue; }
|
||||
dw->resetSettings();
|
||||
@@ -375,7 +375,7 @@ namespace BlackGui
|
||||
|
||||
void CInfoArea::allFloatingOnTop()
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
|
||||
for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
|
||||
{
|
||||
const bool f = dw->isFloating();
|
||||
CGuiUtility::stayOnTop(f, dw);
|
||||
@@ -511,11 +511,11 @@ namespace BlackGui
|
||||
|
||||
void CInfoArea::displayStatusMessage(const CStatusMessage &statusMessage)
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
|
||||
for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
|
||||
{
|
||||
dw->displayStatusMessage(statusMessage);
|
||||
}
|
||||
for (CInfoArea *ia : as_const(m_childInfoAreas))
|
||||
for (CInfoArea *ia : std::as_const(m_childInfoAreas))
|
||||
{
|
||||
ia->displayStatusMessage(statusMessage);
|
||||
}
|
||||
@@ -523,11 +523,11 @@ namespace BlackGui
|
||||
|
||||
void CInfoArea::displayStatusMessages(const CStatusMessageList &statusMessages)
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
|
||||
for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
|
||||
{
|
||||
dw->displayStatusMessages(statusMessages);
|
||||
}
|
||||
for (CInfoArea *ia : as_const(m_childInfoAreas))
|
||||
for (CInfoArea *ia : std::as_const(m_childInfoAreas))
|
||||
{
|
||||
ia->displayStatusMessages(statusMessages);
|
||||
}
|
||||
@@ -535,7 +535,7 @@ namespace BlackGui
|
||||
|
||||
void CInfoArea::setDockArea(Qt::DockWidgetArea area)
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
|
||||
for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
|
||||
{
|
||||
Qt::DockWidgetAreas newAreas = static_cast<Qt::DockWidgetAreas>(area);
|
||||
Qt::DockWidgetAreas oldAreas = dw->allowedAreas();
|
||||
@@ -678,7 +678,7 @@ namespace BlackGui
|
||||
|
||||
void CInfoArea::connectTopLevelChanged()
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
|
||||
for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
|
||||
{
|
||||
connect(dw, &CDockWidgetInfoArea::widgetTopLevelChanged, this, &CInfoArea::onWidgetTopLevelChanged, Qt::QueuedConnection);
|
||||
}
|
||||
@@ -815,7 +815,7 @@ namespace BlackGui
|
||||
|
||||
void CInfoArea::setFeaturesForDockableWidgets(QDockWidget::DockWidgetFeatures features)
|
||||
{
|
||||
for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
|
||||
for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
|
||||
{
|
||||
dw->setFeatures(features);
|
||||
}
|
||||
@@ -898,7 +898,7 @@ namespace BlackGui
|
||||
{
|
||||
if (show == m_showTabTexts) { return; }
|
||||
m_showTabTexts = show;
|
||||
for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
|
||||
for (CDockWidgetInfoArea *dw : std::as_const(m_dockWidgetInfoAreas))
|
||||
{
|
||||
dw->showTitleWhenDocked(show);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace BlackGui
|
||||
const QMap<QString, BlackMisc::CIcons::IconIndex> availableActionsAndIcons = sApp->getInputManager()->allAvailableActionsAndIcons();
|
||||
QStringList keys = availableActionsAndIcons.keys();
|
||||
keys.sort();
|
||||
for (const QString &actionPath : as_const(keys))
|
||||
for (const QString &actionPath : std::as_const(keys))
|
||||
{
|
||||
QString currentPath;
|
||||
const QStringList tokens = actionPath.split("/", Qt::SkipEmptyParts);
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace BlackGui
|
||||
QStandardItemModel::clear();
|
||||
|
||||
int visibleColumns = 0;
|
||||
for (const QString &suffix : as_const(m_suffixes))
|
||||
for (const QString &suffix : std::as_const(m_suffixes))
|
||||
{
|
||||
// ownership of QStandardItem is taken by model
|
||||
QStandardItem *typeFolderFirstColumn = new QStandardItem(CCallsign::atcSuffixToIcon(suffix).toQIcon(), suffix);
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace BlackGui
|
||||
QList<double> series;
|
||||
CDistributorList distributorList(distributors.keys());
|
||||
distributorList.sortByKey();
|
||||
for (const CDistributor &distributor : as_const(distributorList))
|
||||
for (const CDistributor &distributor : std::as_const(distributorList))
|
||||
{
|
||||
const int c = distributors[distributor];
|
||||
if (c < 1) { continue; }
|
||||
@@ -93,7 +93,7 @@ namespace BlackGui
|
||||
CAircraftIcaoCodeList icaoList(icaos.keys());
|
||||
icaoList.sortByDesignatorAndRank();
|
||||
|
||||
for (const CAircraftIcaoCode &icao : as_const(icaoList))
|
||||
for (const CAircraftIcaoCode &icao : std::as_const(icaoList))
|
||||
{
|
||||
const int c = icaos[icao];
|
||||
if (c < 1) { continue; }
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace BlackInput
|
||||
CJoystickButtonList CJoystickMacOS::getAllAvailableJoystickButtons() const
|
||||
{
|
||||
CJoystickButtonList availableButtons;
|
||||
for (const CJoystickDevice *device : as_const(m_joystickDevices))
|
||||
for (const CJoystickDevice *device : std::as_const(m_joystickDevices))
|
||||
{
|
||||
availableButtons.push_back(device->getDeviceButtons());
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace BlackInput
|
||||
return hr;
|
||||
}
|
||||
|
||||
for (const CJoystickDeviceInput &input : as_const(m_joystickDeviceInputs))
|
||||
for (const CJoystickDeviceInput &input : std::as_const(m_joystickDeviceInputs))
|
||||
{
|
||||
const qint32 buttonIndex = input.m_offset - DIJOFS_BUTTON0;
|
||||
const bool isPressed = state.rgbButtons[buttonIndex] & 0x80;
|
||||
@@ -198,7 +198,7 @@ namespace BlackInput
|
||||
CJoystickWindows::~CJoystickWindows()
|
||||
{
|
||||
// All DirectInput devices need to be cleaned up before the call to CoUninitialize()
|
||||
for (CJoystickDevice *joystickDevice : as_const(m_joystickDevices))
|
||||
for (CJoystickDevice *joystickDevice : std::as_const(m_joystickDevices))
|
||||
{
|
||||
delete joystickDevice;
|
||||
}
|
||||
@@ -212,7 +212,7 @@ namespace BlackInput
|
||||
CJoystickButtonList CJoystickWindows::getAllAvailableJoystickButtons() const
|
||||
{
|
||||
CJoystickButtonList availableButtons;
|
||||
for (const CJoystickDevice *device : as_const(m_joystickDevices))
|
||||
for (const CJoystickDevice *device : std::as_const(m_joystickDevices))
|
||||
{
|
||||
availableButtons.push_back(device->getDeviceButtons());
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ namespace BlackMisc
|
||||
if (sort) { icaos.sortByDesignatorAndRank(); }
|
||||
|
||||
// 3 steps to get a proper sort order of the string list
|
||||
for (const CAircraftIcaoCode &icao : as_const(icaos))
|
||||
for (const CAircraftIcaoCode &icao : std::as_const(icaos))
|
||||
{
|
||||
c.append(withCategory ? icao.getCombinedIcaoCategoryStringWithKey() : icao.getCombinedIcaoStringWithKey());
|
||||
}
|
||||
@@ -245,7 +245,7 @@ namespace BlackMisc
|
||||
{
|
||||
icaos = icaos.findWithIataCode(true);
|
||||
if (sort) { icaos.sortBy(&CAircraftIcaoCode::getIataCode, &CAircraftIcaoCode::getRank); }
|
||||
for (const CAircraftIcaoCode &icao : as_const(icaos))
|
||||
for (const CAircraftIcaoCode &icao : std::as_const(icaos))
|
||||
{
|
||||
c.append(icao.getCombinedIataStringWithKey());
|
||||
}
|
||||
@@ -441,7 +441,7 @@ namespace BlackMisc
|
||||
CAircraftIcaoCodeList grouped; // will contain the entries with the best rank
|
||||
QString designator;
|
||||
QString manufacturer;
|
||||
for (const CAircraftIcaoCode &code : as_const(copy))
|
||||
for (const CAircraftIcaoCode &code : std::as_const(copy))
|
||||
{
|
||||
if (code.getDesignator() != designator || code.getManufacturer() != manufacturer)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
*/
|
||||
|
||||
#include "blackmisc/connectionguard.h"
|
||||
#include "blackmisc/range.h" // for as_const
|
||||
|
||||
#include <utility> // for as_const
|
||||
|
||||
#include <QObject>
|
||||
|
||||
@@ -45,7 +46,7 @@ namespace BlackMisc
|
||||
{
|
||||
if (m_connections.isEmpty()) { return 0; }
|
||||
int c = 0;
|
||||
for (const QMetaObject::Connection &con : as_const(m_connections))
|
||||
for (const QMetaObject::Connection &con : std::as_const(m_connections))
|
||||
{
|
||||
if (QObject::disconnect(con)) { c++; }
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ namespace BlackMisc
|
||||
std::swap(m_queue, queue);
|
||||
lock.unlock();
|
||||
|
||||
for (const auto &pair : BlackMisc::as_const(queue))
|
||||
for (const auto &pair : std::as_const(queue))
|
||||
{
|
||||
m_page->setValuesFromCache(pair.first, pair.second);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace BlackMisc
|
||||
CArtifactList copy(*this);
|
||||
copy.sortByVersion(Qt::DescendingOrder);
|
||||
QStringList names;
|
||||
for (const CArtifact &artifact : as_const(copy))
|
||||
for (const CArtifact &artifact : std::as_const(copy))
|
||||
{
|
||||
if (artifact.hasName())
|
||||
{
|
||||
@@ -180,7 +180,7 @@ namespace BlackMisc
|
||||
CArtifactList copy(*this);
|
||||
copy.sortByVersion(Qt::DescendingOrder);
|
||||
QStringList versions;
|
||||
for (const CArtifact &artifact : as_const(copy))
|
||||
for (const CArtifact &artifact : std::as_const(copy))
|
||||
{
|
||||
if (artifact.hasVersion())
|
||||
{
|
||||
|
||||
@@ -264,7 +264,7 @@ namespace BlackMisc
|
||||
break;
|
||||
case SERVERMODE_P2P:
|
||||
{
|
||||
for (QDBusConnection connection : as_const(m_connections))
|
||||
for (QDBusConnection connection : std::as_const(m_connections))
|
||||
{
|
||||
if (connection.registerObject(path, object, registerOptions()))
|
||||
{
|
||||
@@ -300,7 +300,7 @@ namespace BlackMisc
|
||||
|
||||
void CDBusServer::removeAllObjects()
|
||||
{
|
||||
for (const QString &path : makeKeysRange(as_const(m_objects)))
|
||||
for (const QString &path : makeKeysRange(std::as_const(m_objects)))
|
||||
{
|
||||
switch (m_serverMode)
|
||||
{
|
||||
@@ -311,7 +311,7 @@ namespace BlackMisc
|
||||
QDBusConnection::systemBus().unregisterObject(path);
|
||||
break;
|
||||
case SERVERMODE_P2P:
|
||||
for (QDBusConnection connection : as_const(m_connections))
|
||||
for (QDBusConnection connection : std::as_const(m_connections))
|
||||
{
|
||||
connection.unregisterObject(path);
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ namespace BlackMisc
|
||||
|
||||
Q_ASSERT_X(comp.sameNameInSource.size() == comp.sameNameInTarget.size(), Q_FUNC_INFO, "Same sets require same size");
|
||||
QSet<QString>::const_iterator targetIt = comp.sameNameInTarget.cbegin();
|
||||
for (const QString &sourceFile : as_const(comp.sameNameInSource))
|
||||
for (const QString &sourceFile : std::as_const(comp.sameNameInSource))
|
||||
{
|
||||
const QFileInfo source(sourceFile);
|
||||
const QFileInfo target(*targetIt);
|
||||
|
||||
@@ -286,7 +286,7 @@ namespace BlackMisc
|
||||
|
||||
QString last;
|
||||
QStringList result;
|
||||
for (const QString &path : as_const(dirs))
|
||||
for (const QString &path : std::as_const(dirs))
|
||||
{
|
||||
if (path.isEmpty()) { continue; }
|
||||
if (last.isEmpty() || !path.startsWith(last, cs))
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace BlackMisc
|
||||
QString CJsonException::stackString()
|
||||
{
|
||||
QStringList list;
|
||||
for (const auto scope : BlackMisc::as_const(jsonStack()))
|
||||
for (const auto scope : std::as_const(jsonStack()))
|
||||
{
|
||||
list.push_back(scope->m_string ? *scope->m_string : scope->m_latin1); // clazy:exclude=reserve-candidates
|
||||
if (scope->m_index >= 0) { list.back() += u'[' % QString::number(scope->m_index) % u']'; }
|
||||
|
||||
@@ -27,18 +27,6 @@ namespace BlackMisc
|
||||
{
|
||||
template <class> class CRange;
|
||||
|
||||
/*!
|
||||
* Own implementation of C++17 std::as_const. Adds const to any lvalue.
|
||||
* Useful with non-mutating range-for loops to avoid unnecessary detachment of Qt implicitly shared containers.
|
||||
* Does not allow rvalues, as that could easily lead to undefined behaviour.
|
||||
*/
|
||||
//! @{
|
||||
template <class T>
|
||||
constexpr std::add_const_t<T> &as_const(T &v) noexcept { return v; }
|
||||
template <class T>
|
||||
void as_const(const T &&) = delete;
|
||||
//! @}
|
||||
|
||||
/*!
|
||||
* Any container class with begin and end iterators can inherit from this CRTP class
|
||||
* to gain some useful algorithms as member functions.
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace BlackMisc
|
||||
|
||||
if (!m_duplex) { return; }
|
||||
|
||||
for (const auto &filter : as_const(getChannel(channel).peerSubscriptions))
|
||||
for (const auto &filter : std::as_const(getChannel(channel).peerSubscriptions))
|
||||
{
|
||||
if (filter.matches(param))
|
||||
{
|
||||
@@ -103,7 +103,7 @@ namespace BlackMisc
|
||||
|
||||
void CDataLinkDBus::handlePeerEvent(const QString &channel, const CVariant ¶m)
|
||||
{
|
||||
for (const auto &observerWeak : as_const(getChannel(channel).passiveObservers))
|
||||
for (const auto &observerWeak : std::as_const(getChannel(channel).passiveObservers))
|
||||
{
|
||||
auto observer = observerWeak.lock();
|
||||
if (observer && observer->eventSubscription().matches(param))
|
||||
@@ -124,7 +124,7 @@ namespace BlackMisc
|
||||
void CDataLinkDBus::announceLocalSubscriptions(const QString &channel)
|
||||
{
|
||||
CVariantList filters;
|
||||
for (const auto &observerWeak : as_const(getChannel(channel).passiveObservers))
|
||||
for (const auto &observerWeak : std::as_const(getChannel(channel).passiveObservers))
|
||||
{
|
||||
auto observer = observerWeak.lock();
|
||||
if (observer) { filters.push_back(observer->eventSubscription()); }
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace BlackMisc
|
||||
|
||||
void CDataLinkLocal::dispatchEvent(const CVariant ¶m, const QString &channel)
|
||||
{
|
||||
for (const auto &observerWeak : as_const(getChannel(channel).passiveObservers))
|
||||
for (const auto &observerWeak : std::as_const(getChannel(channel).passiveObservers))
|
||||
{
|
||||
auto observer = observerWeak.lock();
|
||||
if (observer && observer->eventSubscription().matches(param))
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace BlackMisc
|
||||
|
||||
void CSimpleCommandParser::registerCommand(const CSimpleCommandParser::CommandHtmlHelp &command)
|
||||
{
|
||||
for (const CommandHtmlHelp &help : as_const(s_commands))
|
||||
for (const CommandHtmlHelp &help : std::as_const(s_commands))
|
||||
{
|
||||
// avoid duplicates
|
||||
if (help.command == command.command) { return; }
|
||||
|
||||
@@ -1572,7 +1572,7 @@ namespace BlackMisc
|
||||
)
|
||||
);
|
||||
|
||||
for (const CAircraftModel &model : as_const(sorted))
|
||||
for (const CAircraftModel &model : std::as_const(sorted))
|
||||
{
|
||||
if (wasStopped) { break; } // allow breaking from external
|
||||
bool ok = false;
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace BlackMisc
|
||||
CAircraftModelList sortedByAircraft(models);
|
||||
sortedByAircraft.sortBy(&CAircraftModel::getAircraftIcaoCodeDesignator);
|
||||
|
||||
for (const CAircraftModel &model : as_const(sortedByAircraft))
|
||||
for (const CAircraftModel &model : std::as_const(sortedByAircraft))
|
||||
{
|
||||
const QString aircraftIcao(model.hasAircraftDesignator() ? model.getAircraftIcaoCodeDesignator() : emptyDesignator);
|
||||
if (!modelsByDesignator.contains(aircraftIcao))
|
||||
@@ -81,7 +81,7 @@ namespace BlackMisc
|
||||
// header
|
||||
html += "<thead><tr>\n"
|
||||
"<th></th>";
|
||||
for (const QString &airline : as_const(airlineIcaos))
|
||||
for (const QString &airline : std::as_const(airlineIcaos))
|
||||
{
|
||||
html += "<th>";
|
||||
html += airline;
|
||||
@@ -91,7 +91,7 @@ namespace BlackMisc
|
||||
"<tbody>\n";
|
||||
|
||||
// fill data
|
||||
for (const QString &aircraftIcao : as_const(aircraftIcaos))
|
||||
for (const QString &aircraftIcao : std::as_const(aircraftIcaos))
|
||||
{
|
||||
html += "<tr>\n"
|
||||
" <th>";
|
||||
@@ -99,7 +99,7 @@ namespace BlackMisc
|
||||
html += "</th>\n";
|
||||
|
||||
const QMap<QString, CAircraftModelList> &airlineModels = modelsByDesignator[aircraftIcao];
|
||||
for (const QString &airline : as_const(airlineIcaos))
|
||||
for (const QString &airline : std::as_const(airlineIcaos))
|
||||
{
|
||||
if (airlineModels.contains(airline))
|
||||
{
|
||||
|
||||
@@ -389,7 +389,7 @@ namespace BlackMisc
|
||||
Q_ASSERT_X(fileTimestamp.isValid(), Q_FUNC_INFO, "Missing file timestamp");
|
||||
|
||||
CAircraftCfgEntriesList result;
|
||||
for (const CAircraftCfgEntries &e : as_const(tempEntries))
|
||||
for (const CAircraftCfgEntries &e : std::as_const(tempEntries))
|
||||
{
|
||||
if (e.getTitle().isEmpty())
|
||||
{
|
||||
|
||||
@@ -275,7 +275,7 @@ namespace BlackMisc
|
||||
file.close();
|
||||
parseFullPackage(content, package);
|
||||
|
||||
for (const auto &plane : as_const(package.planes))
|
||||
for (const auto &plane : std::as_const(package.planes))
|
||||
{
|
||||
if (installedModels.containsModelString(plane.getModelName()))
|
||||
{
|
||||
|
||||
@@ -178,14 +178,14 @@ namespace BlackMisc
|
||||
CValueCache::Element &CValueCache::getElement(const QString &key)
|
||||
{
|
||||
QMutexLocker lock(&m_mutex);
|
||||
return getElement(key, as_const(m_elements).lowerBound(key));
|
||||
return getElement(key, std::as_const(m_elements).lowerBound(key));
|
||||
}
|
||||
|
||||
CValueCache::Element &CValueCache::getElement(const QString &key, QMap<QString, ElementPtr>::const_iterator pos)
|
||||
{
|
||||
QMutexLocker lock(&m_mutex);
|
||||
if (pos != m_elements.cend() && pos.key() == key) { return **pos; }
|
||||
Q_ASSERT(pos == as_const(m_elements).lowerBound(key));
|
||||
Q_ASSERT(pos == std::as_const(m_elements).lowerBound(key));
|
||||
return **m_elements.insert(pos, key, ElementPtr(new Element(key)));
|
||||
}
|
||||
|
||||
@@ -256,8 +256,8 @@ namespace BlackMisc
|
||||
QMutexLocker lock(&m_mutex);
|
||||
if (values.empty()) { return; }
|
||||
m_elements.detach(); //! \fixme see http://doc.qt.io/qt-5/containers.html#implicit-sharing-iterator-problem
|
||||
auto out = as_const(m_elements).lowerBound(values.cbegin().key());
|
||||
auto end = as_const(m_elements).upperBound((values.cend() - 1).key());
|
||||
auto out = std::as_const(m_elements).lowerBound(values.cbegin().key());
|
||||
auto end = std::as_const(m_elements).upperBound((values.cend() - 1).key());
|
||||
for (auto in = values.cbegin(); in != values.cend(); ++in)
|
||||
{
|
||||
while (out != end && out.key() < in.key()) { ++out; }
|
||||
@@ -293,8 +293,8 @@ namespace BlackMisc
|
||||
CValueCachePacket ratifiedChanges(values.isSaved());
|
||||
CValueCachePacket ackedChanges(values.isSaved());
|
||||
m_elements.detach(); //! \fixme see http://doc.qt.io/qt-5/containers.html#implicit-sharing-iterator-problem
|
||||
auto out = as_const(m_elements).lowerBound(values.cbegin().key());
|
||||
auto end = as_const(m_elements).upperBound((values.cend() - 1).key());
|
||||
auto out = std::as_const(m_elements).lowerBound(values.cbegin().key());
|
||||
auto end = std::as_const(m_elements).upperBound((values.cend() - 1).key());
|
||||
for (auto in = values.cbegin(); in != values.cend(); ++in)
|
||||
{
|
||||
while (out != end && out.key() < in.key()) { ++out; }
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace BlackMisc
|
||||
CTemperatureLayerList temperatureLayers = gridPoint.getTemperatureLayers();
|
||||
temperatureLayers.sort([](const CTemperatureLayer & a, const CTemperatureLayer & b) { return a.getLevel() < b.getLevel(); });
|
||||
qtout << " Temperature Layers: " << sep;
|
||||
for (const auto &temperatureLayer : as_const(temperatureLayers))
|
||||
for (const auto &temperatureLayer : std::as_const(temperatureLayers))
|
||||
{
|
||||
qtout << " Level: " << temperatureLayer.getLevel().toQString() << sep;
|
||||
qtout << " Temperature: " << temperatureLayer.getTemperature().toQString() << sep;
|
||||
@@ -89,7 +89,7 @@ namespace BlackMisc
|
||||
CWindLayerList windLayers = gridPoint.getWindLayers();
|
||||
windLayers.sort([](const CWindLayer & a, const CWindLayer & b) { return a.getLevel() < b.getLevel(); });
|
||||
qtout << " Wind Layers: " << sep;
|
||||
for (const auto &windLayer : as_const(windLayers))
|
||||
for (const auto &windLayer : std::as_const(windLayers))
|
||||
{
|
||||
qtout << " Level: " << windLayer.getLevel().toQString() << sep;
|
||||
qtout << " Wind: " << windLayer.getDirection().toQString() << " at " << windLayer.getSpeed().toQString() << sep;
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace BlackSound
|
||||
Q_ASSERT(tonePairs.size() > 0);
|
||||
QByteArray finalBufferData;
|
||||
|
||||
for (const auto &tonePair : as_const(tonePairs))
|
||||
for (const auto &tonePair : std::as_const(tonePairs))
|
||||
{
|
||||
if (m_tonePairCache.contains(tonePair))
|
||||
{
|
||||
|
||||
@@ -957,7 +957,7 @@ namespace BlackSimPlugin
|
||||
timeoutCallsigns.push_back(cs);
|
||||
}
|
||||
|
||||
for (const CCallsign &cs : as_const(timeoutCallsigns))
|
||||
for (const CCallsign &cs : std::as_const(timeoutCallsigns))
|
||||
{
|
||||
m_addingInProgressAircraft.remove(cs);
|
||||
CLogMessage(this).warning(u"Adding for '%1' timed out") << cs.asString();
|
||||
|
||||
@@ -443,7 +443,7 @@ namespace BlackSimPlugin
|
||||
int CSimConnectObjects::countConfirmedAdded()
|
||||
{
|
||||
int c = 0;
|
||||
for (const CSimConnectObject &simObject : as_const(*this))
|
||||
for (const CSimConnectObject &simObject : std::as_const(*this))
|
||||
{
|
||||
if (simObject.isConfirmedAdded()) { c++; }
|
||||
}
|
||||
@@ -542,7 +542,7 @@ namespace BlackSimPlugin
|
||||
CSimConnectObjects removedObjects;
|
||||
|
||||
const qint64 ts = QDateTime::currentMSecsSinceEpoch();
|
||||
for (const CSimConnectObject &simObject : as_const(*this))
|
||||
for (const CSimConnectObject &simObject : std::as_const(*this))
|
||||
{
|
||||
// verification takes at least a second, so we need some time before outdating
|
||||
if (type != CSimConnectObject::AllTypes && simObject.getType() != type) { continue; }
|
||||
|
||||
@@ -1205,7 +1205,7 @@ namespace BlackSimPlugin
|
||||
CSimulatedAircraftList toBeAddedAircraft; // aircraft still to be added
|
||||
CCallsignSet toBeRemovedCallsigns;
|
||||
|
||||
for (const CSimConnectObject &pendingSimObj : as_const(m_addPendingAircraft))
|
||||
for (const CSimConnectObject &pendingSimObj : std::as_const(m_addPendingAircraft))
|
||||
{
|
||||
BLACK_VERIFY_X(pendingSimObj.hasCallsign(), Q_FUNC_INFO, "missing callsign");
|
||||
if (!pendingSimObj.hasCallsign()) { continue; }
|
||||
|
||||
@@ -719,13 +719,13 @@ namespace BlackSimPlugin
|
||||
// comment KB 2019-06
|
||||
// a package is one xsb_aircraft.txt file BB has 9, X-CSL has 76
|
||||
QSet<QString> superpackages;
|
||||
for (const Prefix &package : as_const(packages))
|
||||
for (const Prefix &package : std::as_const(packages))
|
||||
{
|
||||
superpackages.insert(package.parent());
|
||||
}
|
||||
|
||||
const QDir simDir = getSimulatorSettings().getSimulatorDirectoryOrDefault();
|
||||
for (const QString &package : as_const(superpackages))
|
||||
for (const QString &package : std::as_const(superpackages))
|
||||
{
|
||||
if (CDirectoryUtils::isSameOrSubDirectoryOf(package, simDir))
|
||||
{
|
||||
@@ -946,7 +946,7 @@ namespace BlackSimPlugin
|
||||
cloudLayers.sortBy(&CCloudLayer::getBase);
|
||||
// todo: Instead of truncate, find the 3 vertical closest cloud layers
|
||||
cloudLayers.truncate(3);
|
||||
for (const auto &cloudLayer : as_const(cloudLayers))
|
||||
for (const auto &cloudLayer : std::as_const(cloudLayers))
|
||||
{
|
||||
const int base = cloudLayer.getBase().valueInteger(CLengthUnit::m());
|
||||
const int top = cloudLayer.getTop().valueInteger(CLengthUnit::m());
|
||||
@@ -1383,7 +1383,7 @@ namespace BlackSimPlugin
|
||||
timeoutCallsigns.push_back(cs);
|
||||
}
|
||||
|
||||
for (const CCallsign &cs : as_const(timeoutCallsigns))
|
||||
for (const CCallsign &cs : std::as_const(timeoutCallsigns))
|
||||
{
|
||||
m_addingInProgressAircraft.remove(cs);
|
||||
CLogMessage(this).warning(u"Adding for '%1' timed out") << cs.asString();
|
||||
|
||||
@@ -402,7 +402,7 @@ namespace BlackWxPlugin
|
||||
CLogMessage(this).debug() << "Obtained" << weatherGridPointsNo << "grid points.";
|
||||
|
||||
constexpr int maxPoints = 200;
|
||||
for (const GfsGridPoint &gfsGridPoint : as_const(m_gfsWeatherGrid))
|
||||
for (const GfsGridPoint &gfsGridPoint : std::as_const(m_gfsWeatherGrid))
|
||||
{
|
||||
if (QThread::currentThread()->isInterruptionRequested()) { return false; }
|
||||
|
||||
@@ -431,7 +431,7 @@ namespace BlackWxPlugin
|
||||
}
|
||||
|
||||
CCloudLayerList cloudLayers;
|
||||
for (const GfsCloudLayer &gfsCloudLayer : as_const(gfsGridPoint.cloudLayers))
|
||||
for (const GfsCloudLayer &gfsCloudLayer : std::as_const(gfsGridPoint.cloudLayers))
|
||||
{
|
||||
if (std::isnan(gfsCloudLayer.bottomLevelPressure) || std::isnan(gfsCloudLayer.topLevelPressure) || std::isnan(gfsCloudLayer.topLevelTemperature)) { continue; }
|
||||
|
||||
@@ -623,7 +623,7 @@ namespace BlackWxPlugin
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const CGridPoint &fixedGridPoint : as_const(m_grid))
|
||||
for (const CGridPoint &fixedGridPoint : std::as_const(m_grid))
|
||||
{
|
||||
const CLength distance = calculateGreatCircleDistance(gridPointPosition, fixedGridPoint.getPosition());
|
||||
if (distance.isNull())
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace BlackMiscTest
|
||||
time.start();
|
||||
for (int i = 0; i < Loops; ++i)
|
||||
{
|
||||
for (const CAircraftSituationList &s : as_const(listOfLists1))
|
||||
for (const CAircraftSituationList &s : std::as_const(listOfLists1))
|
||||
{
|
||||
const CAircraftSituation s1 = s.oldestAdjustedObject();
|
||||
const CAircraftSituation s2 = s.latestAdjustedObject();
|
||||
@@ -262,7 +262,7 @@ namespace BlackMiscTest
|
||||
time.start();
|
||||
for (int i = 0; i < Loops; ++i)
|
||||
{
|
||||
for (const CAircraftSituationList &s : as_const(listOfLists2))
|
||||
for (const CAircraftSituationList &s : std::as_const(listOfLists2))
|
||||
{
|
||||
const CAircraftSituation s1 = s.oldestAdjustedObject();
|
||||
const CAircraftSituation s2 = s.latestAdjustedObject();
|
||||
|
||||
Reference in New Issue
Block a user