summaryrefslogtreecommitdiff
path: root/src/serialport
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2016-04-30 10:25:27 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2016-05-13 11:27:08 +0000
commit2ac9c0c0e6210f73884bbe2bcb3d8269519003a8 (patch)
treee6f9334060f66448d9dff69c723eab6871ff3485 /src/serialport
parenta11fa1dfd529948da961d3d292926a15f9b7005b (diff)
downloadqtserialport-2ac9c0c0e6210f73884bbe2bcb3d8269519003a8.tar.gz
Replace 'Q_FOREACH' with the range-based 'for'
Change-Id: I057267982ac946ce1ec863a79120cd21cd563c4b Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src/serialport')
-rw-r--r--src/serialport/qserialport_unix.cpp4
-rw-r--r--src/serialport/qserialportinfo.cpp14
-rw-r--r--src/serialport/qserialportinfo_freebsd.cpp15
-rw-r--r--src/serialport/qserialportinfo_unix.cpp9
-rw-r--r--src/serialport/qserialportinfo_win.cpp7
5 files changed, 28 insertions, 21 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 4d17b7d..41dad55 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -125,7 +125,7 @@ QString serialPortLockFilePath(const QString &portName)
QString lockFilePath;
- foreach (const QString &lockDirectoryPath, lockDirectoryPaths) {
+ for (const QString &lockDirectoryPath : lockDirectoryPaths) {
const QString filePath = lockDirectoryPath + fileName;
QFileInfo lockDirectoryInfo(lockDirectoryPath);
@@ -139,7 +139,7 @@ QString serialPortLockFilePath(const QString &portName)
if (lockFilePath.isEmpty()) {
qWarning("The following directories are not readable or writable for detaling with lock files\n");
- foreach (const QString &lockDirectoryPath, lockDirectoryPaths)
+ for (const QString &lockDirectoryPath : lockDirectoryPaths)
qWarning("\t%s\n", qPrintable(lockDirectoryPath));
return QString();
}
diff --git a/src/serialport/qserialportinfo.cpp b/src/serialport/qserialportinfo.cpp
index 76c18da..acd0179 100644
--- a/src/serialport/qserialportinfo.cpp
+++ b/src/serialport/qserialportinfo.cpp
@@ -88,9 +88,10 @@ QSerialPortInfo::QSerialPortInfo(const QSerialPortInfo &other)
*/
QSerialPortInfo::QSerialPortInfo(const QSerialPort &port)
{
- foreach (const QSerialPortInfo &serialPortInfo, availablePorts()) {
- if (port.portName() == serialPortInfo.portName()) {
- *this = serialPortInfo;
+ const auto infos = QSerialPortInfo::availablePorts();
+ for (const QSerialPortInfo &info : infos) {
+ if (port.portName() == info.portName()) {
+ *this = info;
break;
}
}
@@ -105,9 +106,10 @@ QSerialPortInfo::QSerialPortInfo(const QSerialPort &port)
*/
QSerialPortInfo::QSerialPortInfo(const QString &name)
{
- foreach (const QSerialPortInfo &serialPortInfo, availablePorts()) {
- if (name == serialPortInfo.portName()) {
- *this = serialPortInfo;
+ const auto infos = QSerialPortInfo::availablePorts();
+ for (const QSerialPortInfo &info : infos) {
+ if (name == info.portName()) {
+ *this = info;
break;
}
}
diff --git a/src/serialport/qserialportinfo_freebsd.cpp b/src/serialport/qserialportinfo_freebsd.cpp
index 552db89..219cd7c 100644
--- a/src/serialport/qserialportinfo_freebsd.cpp
+++ b/src/serialport/qserialportinfo_freebsd.cpp
@@ -122,7 +122,7 @@ static QVector<int> nextOid(const QVector<int> &previousOid)
QVector<int> mib;
mib.append(0); // Magic undocumented code (CTL_UNSPEC ?)
mib.append(2); // Magic undocumented code
- foreach (int code, previousOid)
+ for (int code : previousOid)
mib.append(code);
size_t requiredLength = 0;
@@ -144,7 +144,7 @@ static NodeInfo nodeForOid(const QVector<int> &oid)
QVector<int> mib;
mib.append(0); // Magic undocumented code (CTL_UNSPEC ?)
mib.append(1); // Magic undocumented code
- foreach (int code, oid)
+ for (int code : oid)
mib.append(code);
// query node name
@@ -234,7 +234,8 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
QList<QSerialPortInfo> cuaCandidates;
QList<QSerialPortInfo> ttyCandidates;
- foreach (const QString &portName, deviceDir.entryList()) {
+ const auto portNames = deviceDir.entryList();
+ for (const QString &portName : portNames) {
if (portName.endsWith(QLatin1String(".init"))
|| portName.endsWith(QLatin1String(".lock"))) {
continue;
@@ -244,7 +245,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
priv.portName = portName;
priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(portName);
- foreach (const NodeInfo &node, nodes) {
+ for (const NodeInfo &node : nodes) {
const int pnpinfoindex = node.name.indexOf(QLatin1String("\%pnpinfo"));
if (pnpinfoindex == -1)
continue;
@@ -288,7 +289,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
const QString descnode = QString(QLatin1String("%1\%desc")).arg(nodebase);
// search for description and manufacturer properties
- foreach (const NodeInfo &node, nodes) {
+ for (const NodeInfo &node : nodes) {
if (node.name != descnode)
continue;
@@ -313,10 +314,10 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
QList<QSerialPortInfo> serialPortInfoList;
- foreach (const QSerialPortInfo &cuaCandidate, cuaCandidates) {
+ for (const QSerialPortInfo &cuaCandidate : qAsConst(cuaCandidates)) {
const QString cuaPortName = cuaCandidate.portName();
const QString cuaToken = deviceProperty(cuaPortName, "cua");
- foreach (const QSerialPortInfo &ttyCandidate, ttyCandidates) {
+ for (const QSerialPortInfo &ttyCandidate : qAsConst(ttyCandidates)) {
const QString ttyPortName = ttyCandidate.portName();
const QString ttyToken = deviceProperty(ttyPortName, "tty");
if (cuaToken != ttyToken)
diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp
index a93ac05..3a37999 100644
--- a/src/serialport/qserialportinfo_unix.cpp
+++ b/src/serialport/qserialportinfo_unix.cpp
@@ -90,7 +90,8 @@ static QStringList filteredDeviceFilePaths()
deviceDir.setNameFilters(deviceFileNameFilterList);
deviceDir.setFilter(QDir::Files | QDir::System | QDir::NoSymLinks);
QStringList deviceFilePaths;
- foreach (const QFileInfo &deviceFileInfo, deviceDir.entryInfoList()) {
+ const auto deviceFileInfos = deviceDir.entryInfoList();
+ for (const QFileInfo &deviceFileInfo : deviceFileInfos) {
const QString deviceAbsoluteFilePath = deviceFileInfo.absoluteFilePath();
#ifdef Q_OS_FREEBSD
@@ -115,7 +116,8 @@ QList<QSerialPortInfo> availablePortsByFiltersOfDevices(bool &ok)
{
QList<QSerialPortInfo> serialPortInfoList;
- foreach (const QString &deviceFilePath, filteredDeviceFilePaths()) {
+ const auto deviceFilePaths = filteredDeviceFilePaths();
+ for (const QString &deviceFilePath : deviceFilePaths) {
QSerialPortInfoPrivate priv;
priv.device = deviceFilePath;
priv.portName = QSerialPortInfoPrivate::portNameFromSystemLocation(deviceFilePath);
@@ -250,7 +252,8 @@ QList<QSerialPortInfo> availablePortsBySysfs(bool &ok)
QList<QSerialPortInfo> serialPortInfoList;
ttySysClassDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
- foreach (const QFileInfo &fileInfo, ttySysClassDir.entryInfoList()) {
+ const auto fileInfos = ttySysClassDir.entryInfoList();
+ for (const QFileInfo &fileInfo : fileInfos) {
if (!fileInfo.isSymLink())
continue;
diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp
index 262ff47..9c5305c 100644
--- a/src/serialport/qserialportinfo_win.cpp
+++ b/src/serialport/qserialportinfo_win.cpp
@@ -344,9 +344,10 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
::SetupDiDestroyDeviceInfoList(deviceInfoSet);
}
- foreach (const QString &portName, portNamesFromHardwareDeviceMap()) {
- if (std::find_if(serialPortInfoList.begin(), serialPortInfoList.end(),
- SerialPortNameEqualFunctor(portName)) == serialPortInfoList.end()) {
+ const auto portNames = portNamesFromHardwareDeviceMap();
+ for (const QString &portName : portNames) {
+ if (std::find_if(serialPortInfoList.cbegin(), serialPortInfoList.cend(),
+ SerialPortNameEqualFunctor(portName)) == serialPortInfoList.cend()) {
QSerialPortInfoPrivate priv;
priv.portName = portName;
priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(portName);