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

Este commit está contenido en:
Andrius Štikonas 2016-09-02 22:33:26 +01:00
padre a9e76830c1
commit 9ce7a65869
Se han modificado 3 ficheros con 14 adiciones y 14 borrados

Ver fichero

@ -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) {

Ver fichero

@ -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");
}

Ver fichero

@ -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;
}