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()

void ConsoleReader::listSockets()
{
for (std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i) {
for (const auto &socket : *sockets) {
std::cout << "_____________________________________________________________________________\n" << std::endl;
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;
std::cout << "Socket Name: " << (*i)->socketName.toStdString() << "\t Remote Password: " << (*i)->remotePassword.toStdString() << "\t Timezone: " << +(*i)->timezone << ((*i)->dst ? " (DST)" : "") << std::endl;
std::cout << "Off timer: " << (*i)->offTime << " " << ((*i)->offTimerEnabled ? "(enabled)" : "(disabled)") << "\t\t Time: " << (*i)->socketDateTime.toString().toStdString() << std::endl;
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;
std::cout << "Socket Name: " << socket->socketName.toStdString() << "\t Remote Password: " << socket->remotePassword.toStdString() << "\t Timezone: " << + socket->timezone << (socket->dst ? " (DST)" : "") << std::endl;
std::cout << "Off timer: " << socket->offTime << " " << (socket->offTimerEnabled ? "(enabled)" : "(disabled)") << "\t\t Time: " << socket->socketDateTime.toString().toStdString() << std::endl;
}
std::cout << "_____________________________________________________________________________\n" << std::endl;
if (sockets->size() > 0) {

+ 2
- 2
dialog.cpp View File

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


+ 8
- 8
server.cpp View File

@@ -43,7 +43,7 @@ Server::Server(std::vector<Socket*> *sockets_vector)
Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
{
QNetworkConfiguration *cfgInitial = new QNetworkConfiguration;
QNetworkConfiguration *cfg = new QNetworkConfiguration;
const QNetworkConfiguration *cfg = new QNetworkConfiguration;
QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager;
ncm->updateConfigurations();
*cfgInitial = ncm->defaultConfiguration();
@@ -57,9 +57,9 @@ Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
while (!stop) {
QThread::sleep(1);

auto nc = ncm->allConfigurations();
const auto nc = ncm->allConfigurations();

for (auto & x : nc) {
for (const auto &x : nc) {
if (x.bearerType() == QNetworkConfiguration::BearerWLAN) {
if (x.name() == "WiWo-S20") {
qDebug() << "Connecting to WiWo-S20 wireless";
@@ -151,8 +151,8 @@ void Server::readPendingDatagrams()
if (reply != discover && reply.left(2) == magicKey) { // check for Magic Key
if (reply.mid(4, 2) == QStringLiteral("qa").toLatin1() || reply.mid(4, 2) == QStringLiteral("qg").toLatin1()) { // Reply to discover packet
bool duplicate = false;
for (std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i) {
if ((*i)->ip == sender) {
for (const auto &socket : *sockets) {
if (socket->ip == sender) {
duplicate = true;
break;
}
@@ -167,9 +167,9 @@ void Server::readPendingDatagrams()
} else {
mac = reply.mid(6, 6);
}
for (std::vector<Socket*>::iterator i = sockets->begin() ; i != sockets->end(); ++i) {
if ((*i)->mac == mac) {
(*i)->parseReply(reply);
for (const auto &socket : *sockets) {
if (socket->mac == mac) {
socket->parseReply(reply);
break;
}


Loading…
Cancel
Save