Browse Source

Convert some loops into C++11 ranged based for loops.

master
Andrius Štikonas 3 years ago
parent
commit
9ce7a65869
3 changed files with 14 additions and 14 deletions
  1. 4
    4
      consolereader.cpp
  2. 2
    2
      dialog.cpp
  3. 8
    8
      server.cpp

+ 4
- 4
consolereader.cpp View File

@@ -122,11 +122,11 @@ void ConsoleReader::run()
122 122
 
123 123
 void ConsoleReader::listSockets()
124 124
 {
125
-    for (std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i) {
125
+    for (const auto &socket : *sockets) {
126 126
         std::cout << "_____________________________________________________________________________\n" << std::endl;
127
-        std::cout << "IP Address: " << (*i)->ip.toString().remove("::ffff:").toStdString() << "\t MAC Address: " << (*i)->mac.toHex().toStdString()  << "\t Power: " << ((*i)->powered ? "On" : "Off") << std::endl;
128
-        std::cout << "Socket Name: " << (*i)->socketName.toStdString() << "\t Remote Password: " << (*i)->remotePassword.toStdString() << "\t Timezone: " << +(*i)->timezone << ((*i)->dst ? " (DST)" : "") << std::endl;
129
-        std::cout << "Off timer: " << (*i)->offTime << " " << ((*i)->offTimerEnabled ? "(enabled)" : "(disabled)")  << "\t\t Time: " << (*i)->socketDateTime.toString().toStdString() << std::endl;
127
+        std::cout << "IP Address: " << socket->ip.toString().remove("::ffff:").toStdString() << "\t MAC Address: " << socket->mac.toHex().toStdString()  << "\t Power: " << (socket->powered ? "On" : "Off") << std::endl;
128
+        std::cout << "Socket Name: " << socket->socketName.toStdString() << "\t Remote Password: " << socket->remotePassword.toStdString() << "\t Timezone: " << + socket->timezone << (socket->dst ? " (DST)" : "") << std::endl;
129
+        std::cout << "Off timer: " << socket->offTime << " " << (socket->offTimerEnabled ? "(enabled)" : "(disabled)")  << "\t\t Time: " << socket->socketDateTime.toString().toStdString() << std::endl;
130 130
     }
131 131
     std::cout << "_____________________________________________________________________________\n" << std::endl;
132 132
     if (sockets->size() > 0) {

+ 2
- 2
dialog.cpp View File

@@ -54,8 +54,8 @@ void Dialog::updateUi()
54 54
 void Dialog::discovered()
55 55
 {
56 56
     ui->socketsComboBox->clear();
57
-    for (std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i) {
58
-        connect(*i, &Socket::stateChanged, this, &Dialog::updateUi);
57
+    for (const auto &socket : *sockets) {
58
+        connect(socket, &Socket::stateChanged, this, &Dialog::updateUi);
59 59
         ui->socketsComboBox->addItem("Socket");
60 60
     }
61 61
 

+ 8
- 8
server.cpp View File

@@ -43,7 +43,7 @@ Server::Server(std::vector<Socket*> *sockets_vector)
43 43
 Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
44 44
 {
45 45
     QNetworkConfiguration *cfgInitial = new QNetworkConfiguration;
46
-    QNetworkConfiguration *cfg = new QNetworkConfiguration;
46
+    const QNetworkConfiguration *cfg = new QNetworkConfiguration;
47 47
     QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager;
48 48
     ncm->updateConfigurations();
49 49
     *cfgInitial = ncm->defaultConfiguration();
@@ -57,9 +57,9 @@ Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
57 57
     while (!stop) {
58 58
         QThread::sleep(1);
59 59
 
60
-        auto nc = ncm->allConfigurations();
60
+        const auto nc = ncm->allConfigurations();
61 61
 
62
-    for (auto & x : nc) {
62
+    for (const auto &x : nc) {
63 63
             if (x.bearerType() == QNetworkConfiguration::BearerWLAN) {
64 64
                 if (x.name() == "WiWo-S20") {
65 65
                     qDebug() << "Connecting to WiWo-S20 wireless";
@@ -151,8 +151,8 @@ void Server::readPendingDatagrams()
151 151
         if (reply != discover && reply.left(2) == magicKey) {    // check for Magic Key
152 152
             if (reply.mid(4, 2) == QStringLiteral("qa").toLatin1() || reply.mid(4, 2) == QStringLiteral("qg").toLatin1()) {      // Reply to discover packet
153 153
                 bool duplicate = false;
154
-                for (std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i) {
155
-                    if ((*i)->ip == sender) {
154
+                for (const auto &socket : *sockets) {
155
+                    if (socket->ip == sender) {
156 156
                         duplicate = true;
157 157
                         break;
158 158
                     }
@@ -167,9 +167,9 @@ void Server::readPendingDatagrams()
167 167
             } else {
168 168
                 mac = reply.mid(6, 6);
169 169
             }
170
-            for (std::vector<Socket*>::iterator i = sockets->begin() ; i != sockets->end(); ++i) {
171
-                if ((*i)->mac == mac) {
172
-                    (*i)->parseReply(reply);
170
+            for (const auto &socket : *sockets) {
171
+                if (socket->mac == mac) {
172
+                    socket->parseReply(reply);
173 173
                     break;
174 174
                 }
175 175
 

Loading…
Cancel
Save