Convert some loops into C++11 ranged based for loops.
This commit is contained in:
parent
a9e76830c1
commit
9ce7a65869
|
@ -122,11 +122,11 @@ void ConsoleReader::run()
|
||||||
|
|
||||||
void ConsoleReader::listSockets()
|
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 << "_____________________________________________________________________________\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 << "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: " << (*i)->socketName.toStdString() << "\t Remote Password: " << (*i)->remotePassword.toStdString() << "\t Timezone: " << +(*i)->timezone << ((*i)->dst ? " (DST)" : "") << 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: " << (*i)->offTime << " " << ((*i)->offTimerEnabled ? "(enabled)" : "(disabled)") << "\t\t Time: " << (*i)->socketDateTime.toString().toStdString() << 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;
|
std::cout << "_____________________________________________________________________________\n" << std::endl;
|
||||||
if (sockets->size() > 0) {
|
if (sockets->size() > 0) {
|
||||||
|
|
|
@ -54,8 +54,8 @@ void Dialog::updateUi()
|
||||||
void Dialog::discovered()
|
void Dialog::discovered()
|
||||||
{
|
{
|
||||||
ui->socketsComboBox->clear();
|
ui->socketsComboBox->clear();
|
||||||
for (std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i) {
|
for (const auto &socket : *sockets) {
|
||||||
connect(*i, &Socket::stateChanged, this, &Dialog::updateUi);
|
connect(socket, &Socket::stateChanged, this, &Dialog::updateUi);
|
||||||
ui->socketsComboBox->addItem("Socket");
|
ui->socketsComboBox->addItem("Socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
server.cpp
16
server.cpp
|
@ -43,7 +43,7 @@ Server::Server(std::vector<Socket*> *sockets_vector)
|
||||||
Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
|
Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
|
||||||
{
|
{
|
||||||
QNetworkConfiguration *cfgInitial = new QNetworkConfiguration;
|
QNetworkConfiguration *cfgInitial = new QNetworkConfiguration;
|
||||||
QNetworkConfiguration *cfg = new QNetworkConfiguration;
|
const QNetworkConfiguration *cfg = new QNetworkConfiguration;
|
||||||
QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager;
|
QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager;
|
||||||
ncm->updateConfigurations();
|
ncm->updateConfigurations();
|
||||||
*cfgInitial = ncm->defaultConfiguration();
|
*cfgInitial = ncm->defaultConfiguration();
|
||||||
|
@ -57,9 +57,9 @@ Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
|
||||||
while (!stop) {
|
while (!stop) {
|
||||||
QThread::sleep(1);
|
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.bearerType() == QNetworkConfiguration::BearerWLAN) {
|
||||||
if (x.name() == "WiWo-S20") {
|
if (x.name() == "WiWo-S20") {
|
||||||
qDebug() << "Connecting to WiWo-S20 wireless";
|
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 != 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
|
if (reply.mid(4, 2) == QStringLiteral("qa").toLatin1() || reply.mid(4, 2) == QStringLiteral("qg").toLatin1()) { // Reply to discover packet
|
||||||
bool duplicate = false;
|
bool duplicate = false;
|
||||||
for (std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i) {
|
for (const auto &socket : *sockets) {
|
||||||
if ((*i)->ip == sender) {
|
if (socket->ip == sender) {
|
||||||
duplicate = true;
|
duplicate = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -167,9 +167,9 @@ void Server::readPendingDatagrams()
|
||||||
} else {
|
} else {
|
||||||
mac = reply.mid(6, 6);
|
mac = reply.mid(6, 6);
|
||||||
}
|
}
|
||||||
for (std::vector<Socket*>::iterator i = sockets->begin() ; i != sockets->end(); ++i) {
|
for (const auto &socket : *sockets) {
|
||||||
if ((*i)->mac == mac) {
|
if (socket->mac == mac) {
|
||||||
(*i)->parseReply(reply);
|
socket->parseReply(reply);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue