summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorHenry Wilson <m3henry@googlemail.com>2019-02-17 11:20:52 +0000
committerPeterN <peter@fuzzle.org>2019-03-26 20:15:57 +0000
commitab711e6942757d775c08c31a6c32d488feba1dba (patch)
treed102dc6d0e6b9c33e7205b63e3360ebd720a3ebb /src/network
parent297fd3dda3abe353ebe2fe77c67b011e24d403bc (diff)
downloadopenttd-ab711e6942757d775c08c31a6c32d488feba1dba.tar.xz
Codechange: Replaced SmallVector::[Begin|End]() with std alternatives
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/host.cpp6
-rw-r--r--src/network/core/tcp_connect.cpp2
-rw-r--r--src/network/core/tcp_http.cpp4
-rw-r--r--src/network/core/tcp_listen.h22
-rw-r--r--src/network/core/udp.cpp26
-rw-r--r--src/network/network.cpp4
-rw-r--r--src/network/network_client.cpp2
-rw-r--r--src/network/network_content.cpp90
-rw-r--r--src/network/network_content.h4
-rw-r--r--src/network/network_content_gui.cpp28
-rw-r--r--src/network/network_gui.cpp13
-rw-r--r--src/network/network_server.cpp4
-rw-r--r--src/network/network_udp.cpp6
13 files changed, 101 insertions, 110 deletions
diff --git a/src/network/core/host.cpp b/src/network/core/host.cpp
index b1ed71e92..35c7ce8ae 100644
--- a/src/network/core/host.cpp
+++ b/src/network/core/host.cpp
@@ -200,8 +200,8 @@ void NetworkFindBroadcastIPs(NetworkAddressList *broadcast)
/* Now display to the debug all the detected ips */
DEBUG(net, 3, "Detected broadcast addresses:");
int i = 0;
- for (NetworkAddress *addr = broadcast->Begin(); addr != broadcast->End(); addr++) {
- addr->SetPort(NETWORK_DEFAULT_PORT);
- DEBUG(net, 3, "%d) %s", i++, addr->GetHostname());
+ for (NetworkAddress &addr : *broadcast) {
+ addr.SetPort(NETWORK_DEFAULT_PORT);
+ DEBUG(net, 3, "%d) %s", i++, addr.GetHostname());
}
}
diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp
index f3dc2cb9a..d699cf60d 100644
--- a/src/network/core/tcp_connect.cpp
+++ b/src/network/core/tcp_connect.cpp
@@ -93,5 +93,5 @@ void TCPConnecter::Connect()
/** Kill all connection attempts. */
/* static */ void TCPConnecter::KillAll()
{
- for (TCPConnecter **iter = _tcp_connecters.Begin(); iter != _tcp_connecters.End(); iter++) (*iter)->killed = true;
+ for (TCPConnecter *conn : _tcp_connecters) conn->killed = true;
}
diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp
index abec3fbc8..cec77fb14 100644
--- a/src/network/core/tcp_http.cpp
+++ b/src/network/core/tcp_http.cpp
@@ -303,8 +303,8 @@ int NetworkHTTPSocketHandler::Receive()
struct timeval tv;
FD_ZERO(&read_fd);
- for (NetworkHTTPSocketHandler **iter = _http_connections.Begin(); iter < _http_connections.End(); iter++) {
- FD_SET((*iter)->sock, &read_fd);
+ for (NetworkHTTPSocketHandler *handler : _http_connections) {
+ FD_SET(handler->sock, &read_fd);
}
tv.tv_sec = tv.tv_usec = 0; // don't block at all.
diff --git a/src/network/core/tcp_listen.h b/src/network/core/tcp_listen.h
index 55594070b..744f8841f 100644
--- a/src/network/core/tcp_listen.h
+++ b/src/network/core/tcp_listen.h
@@ -54,13 +54,13 @@ public:
/* Check if the client is banned */
bool banned = false;
- for (char **iter = _network_ban_list.Begin(); iter != _network_ban_list.End(); iter++) {
- banned = address.IsInNetmask(*iter);
+ for (char *entry : _network_ban_list) {
+ banned = address.IsInNetmask(entry);
if (banned) {
Packet p(Tban_packet);
p.PrepareToSend();
- DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), *iter);
+ DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry);
if (send(s, (const char*)p.buffer, p.size, 0) < 0) {
DEBUG(net, 0, "send failed with error %d", GET_LAST_ERROR());
@@ -111,16 +111,16 @@ public:
}
/* take care of listener port */
- for (SocketList::iterator s = sockets.Begin(); s != sockets.End(); s++) {
- FD_SET(s->second, &read_fd);
+ for (auto &s : sockets) {
+ FD_SET(s.second, &read_fd);
}
tv.tv_sec = tv.tv_usec = 0; // don't block at all.
if (select(FD_SETSIZE, &read_fd, &write_fd, NULL, &tv) < 0) return false;
/* accept clients.. */
- for (SocketList::iterator s = sockets.Begin(); s != sockets.End(); s++) {
- if (FD_ISSET(s->second, &read_fd)) AcceptClient(s->second);
+ for (auto &s : sockets) {
+ if (FD_ISSET(s.second, &read_fd)) AcceptClient(s.second);
}
/* read stuff from clients */
@@ -145,8 +145,8 @@ public:
NetworkAddressList addresses;
GetBindAddresses(&addresses, port);
- for (NetworkAddress *address = addresses.Begin(); address != addresses.End(); address++) {
- address->Listen(SOCK_STREAM, &sockets);
+ for (NetworkAddress &address : addresses) {
+ address.Listen(SOCK_STREAM, &sockets);
}
if (sockets.size() == 0) {
@@ -161,8 +161,8 @@ public:
/** Close the sockets we're listening on. */
static void CloseListeners()
{
- for (SocketList::iterator s = sockets.Begin(); s != sockets.End(); s++) {
- closesocket(s->second);
+ for (auto &s : sockets) {
+ closesocket(s.second);
}
sockets.clear();
DEBUG(net, 1, "[%s] closed listeners", Tsocket::GetName());
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
index 7babf78d6..70bb0b9f0 100644
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -25,8 +25,8 @@
NetworkUDPSocketHandler::NetworkUDPSocketHandler(NetworkAddressList *bind)
{
if (bind != NULL) {
- for (NetworkAddress *addr = bind->Begin(); addr != bind->End(); addr++) {
- this->bind.push_back(*addr);
+ for (NetworkAddress &addr : *bind) {
+ this->bind.push_back(addr);
}
} else {
/* As hostname NULL and port 0/NULL don't go well when
@@ -47,8 +47,8 @@ bool NetworkUDPSocketHandler::Listen()
/* Make sure socket is closed */
this->Close();
- for (NetworkAddress *addr = this->bind.Begin(); addr != this->bind.End(); addr++) {
- addr->Listen(SOCK_DGRAM, &this->sockets);
+ for (NetworkAddress &addr : this->bind) {
+ addr.Listen(SOCK_DGRAM, &this->sockets);
}
return this->sockets.size() != 0;
@@ -59,8 +59,8 @@ bool NetworkUDPSocketHandler::Listen()
*/
void NetworkUDPSocketHandler::Close()
{
- for (SocketList::iterator s = this->sockets.Begin(); s != this->sockets.End(); s++) {
- closesocket(s->second);
+ for (auto &s : this->sockets) {
+ closesocket(s.second);
}
this->sockets.clear();
}
@@ -82,26 +82,26 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a
{
if (this->sockets.size() == 0) this->Listen();
- for (SocketList::iterator s = this->sockets.Begin(); s != this->sockets.End(); s++) {
+ for (auto &s : this->sockets) {
/* Make a local copy because if we resolve it we cannot
* easily unresolve it so we can resolve it later again. */
NetworkAddress send(*recv);
/* Not the same type */
- if (!send.IsFamily(s->first.GetAddress()->ss_family)) continue;
+ if (!send.IsFamily(s.first.GetAddress()->ss_family)) continue;
p->PrepareToSend();
if (broadcast) {
/* Enable broadcast */
unsigned long val = 1;
- if (setsockopt(s->second, SOL_SOCKET, SO_BROADCAST, (char *) &val, sizeof(val)) < 0) {
+ if (setsockopt(s.second, SOL_SOCKET, SO_BROADCAST, (char *) &val, sizeof(val)) < 0) {
DEBUG(net, 1, "[udp] setting broadcast failed with: %i", GET_LAST_ERROR());
}
}
/* Send the buffer */
- int res = sendto(s->second, (const char*)p->buffer, p->size, 0, (const struct sockaddr *)send.GetAddress(), send.GetAddressLength());
+ int res = sendto(s.second, (const char*)p->buffer, p->size, 0, (const struct sockaddr *)send.GetAddress(), send.GetAddressLength());
DEBUG(net, 7, "[udp] sendto(%s)", send.GetAddressAsString());
/* Check for any errors, but ignore it otherwise */
@@ -116,7 +116,7 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a
*/
void NetworkUDPSocketHandler::ReceivePackets()
{
- for (SocketList::iterator s = this->sockets.Begin(); s != this->sockets.End(); s++) {
+ for (auto &s : this->sockets) {
for (int i = 0; i < 1000; i++) { // Do not infinitely loop when DoSing with UDP
struct sockaddr_storage client_addr;
memset(&client_addr, 0, sizeof(client_addr));
@@ -125,8 +125,8 @@ void NetworkUDPSocketHandler::ReceivePackets()
socklen_t client_len = sizeof(client_addr);
/* Try to receive anything */
- SetNonBlocking(s->second); // Some OSes seem to lose the non-blocking status of the socket
- int nbytes = recvfrom(s->second, (char*)p.buffer, SEND_MTU, 0, (struct sockaddr *)&client_addr, &client_len);
+ SetNonBlocking(s.second); // Some OSes seem to lose the non-blocking status of the socket
+ int nbytes = recvfrom(s.second, (char*)p.buffer, SEND_MTU, 0, (struct sockaddr *)&client_addr, &client_len);
/* Did we get the bytes for the base header of the packet? */
if (nbytes <= 0) break; // No data, i.e. no packet
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 1ddd7478c..be92623e4 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -632,8 +632,8 @@ void NetworkAddServer(const char *b)
*/
void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
{
- for (char **iter = _network_bind_list.Begin(); iter != _network_bind_list.End(); iter++) {
- addresses->emplace_back(*iter, port);
+ for (char *iter : _network_bind_list) {
+ addresses->emplace_back(iter, port);
}
/* No address, so bind to everything. */
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index fff4dd328..12aa3fc0a 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -110,7 +110,7 @@ struct PacketReader : LoadFilter {
{
this->read_bytes = 0;
- this->block = this->blocks.Begin();
+ this->block = this->blocks.data();
this->buf = *this->block++;
this->bufe = this->buf + CHUNK;
}
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index 617a2bc6b..003ffdb8b 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -137,8 +137,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
if (ci->state == ContentInfo::UNSELECTED && ci->filesize == 0) ci->state = ContentInfo::DOES_NOT_EXIST;
/* Do we already have a stub for this? */
- for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
- ContentInfo *ici = *iter;
+ for (ContentInfo *ici : this->infos) {
if (ici->type == ci->type && ici->unique_id == ci->unique_id &&
memcmp(ci->md5sum, ici->md5sum, sizeof(ci->md5sum)) == 0) {
/* Preserve the name if possible */
@@ -168,8 +167,8 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
this->infos.push_back(ci);
/* Incoming data means that we might need to reconsider dependencies */
- for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
- this->CheckDependencyState(*iter);
+ for (ContentInfo *ici : this->infos) {
+ this->CheckDependencyState(ici);
}
this->OnReceiveContentInfo(ci);
@@ -253,8 +252,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
Packet *p = new Packet(send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID);
p->Send_uint8(cv->size());
- for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) {
- const ContentInfo *ci = *iter;
+ for (const ContentInfo *ci : *cv) {
p->Send_uint8((byte)ci->type);
p->Send_uint32(ci->unique_id);
if (!send_md5sum) continue;
@@ -266,11 +264,9 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
this->SendPacket(p);
- for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) {
- ContentInfo *ci = *iter;
+ for (ContentInfo *ci : *cv) {
bool found = false;
- for (ContentIterator iter2 = this->infos.Begin(); iter2 != this->infos.End(); iter2++) {
- ContentInfo *ci2 = *iter2;
+ for (ContentInfo *ci2 : this->infos) {
if (ci->type == ci2->type && ci->unique_id == ci2->unique_id &&
(!send_md5sum || memcmp(ci->md5sum, ci2->md5sum, sizeof(ci->md5sum)) == 0)) {
found = true;
@@ -296,8 +292,7 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uin
bytes = 0;
ContentIDList content;
- for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
- const ContentInfo *ci = *iter;
+ for (const ContentInfo *ci : this->infos) {
if (!ci->IsSelected() || ci->state == ContentInfo::ALREADY_HERE) continue;
content.push_back(ci->id);
@@ -333,8 +328,8 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentHTTP(const Conten
const char *lastof = content_request + bytes - 1;
char *p = content_request;
- for (const ContentID *id = content.Begin(); id != content.End(); id++) {
- p += seprintf(p, lastof, "%d\n", *id);
+ for (const ContentID &id : content) {
+ p += seprintf(p, lastof, "%d\n", id);
}
this->http_response_index = -1;
@@ -351,7 +346,7 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentHTTP(const Conten
void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const ContentIDList &content)
{
uint count = content.size();
- const ContentID *content_ids = content.Begin();
+ const ContentID *content_ids = content.data();
this->Connect();
while (count > 0) {
@@ -626,7 +621,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
#define check_and_terminate(p) { check_not_null(p); *(p) = '\0'; }
for (;;) {
- char *str = this->http_response.Begin() + this->http_response_index;
+ char *str = this->http_response.data() + this->http_response_index;
char *p = strchr(str, '\n');
check_and_terminate(p);
@@ -713,7 +708,7 @@ ClientNetworkContentSocketHandler::~ClientNetworkContentSocketHandler()
delete this->curInfo;
if (this->curFile != NULL) fclose(this->curFile);
- for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) delete *iter;
+ for (ContentInfo *ci : this->infos) delete ci;
}
/** Connect to the content server. */
@@ -807,8 +802,7 @@ void ClientNetworkContentSocketHandler::DownloadContentInfo(ContentID cid)
*/
ContentInfo *ClientNetworkContentSocketHandler::GetContent(ContentID cid)
{
- for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
- ContentInfo *ci = *iter;
+ for (ContentInfo *ci : this->infos) {
if (ci->id == cid) return ci;
}
return NULL;
@@ -844,8 +838,7 @@ void ClientNetworkContentSocketHandler::Unselect(ContentID cid)
/** Select everything we can select */
void ClientNetworkContentSocketHandler::SelectAll()
{
- for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
- ContentInfo *ci = *iter;
+ for (ContentInfo *ci : this->infos) {
if (ci->state == ContentInfo::UNSELECTED) {
ci->state = ContentInfo::SELECTED;
this->CheckDependencyState(ci);
@@ -856,8 +849,7 @@ void ClientNetworkContentSocketHandler::SelectAll()
/** Select everything that's an update for something we've got */
void ClientNetworkContentSocketHandler::SelectUpgrade()
{
- for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
- ContentInfo *ci = *iter;
+ for (ContentInfo *ci : this->infos) {
if (ci->state == ContentInfo::UNSELECTED && ci->upgrade) {
ci->state = ContentInfo::SELECTED;
this->CheckDependencyState(ci);
@@ -868,8 +860,7 @@ void ClientNetworkContentSocketHandler::SelectUpgrade()
/** Unselect everything that we've not downloaded so far. */
void ClientNetworkContentSocketHandler::UnselectAll()
{
- for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
- ContentInfo *ci = *iter;
+ for (ContentInfo *ci : this->infos) {
if (ci->IsSelected() && ci->state != ContentInfo::ALREADY_HERE) ci->state = ContentInfo::UNSELECTED;
}
}
@@ -899,8 +890,7 @@ void ClientNetworkContentSocketHandler::ToggleSelectedState(const ContentInfo *c
*/
void ClientNetworkContentSocketHandler::ReverseLookupDependency(ConstContentVector &parents, const ContentInfo *child) const
{
- for (ConstContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
- const ContentInfo *ci = *iter;
+ for (const ContentInfo * const &ci : this->infos) {
if (ci == child) continue;
for (uint i = 0; i < ci->dependency_count; i++) {
@@ -929,8 +919,8 @@ void ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(ConstContent
ConstContentVector parents;
this->ReverseLookupDependency(parents, tree[i]);
- for (ConstContentIterator piter = parents.Begin(); piter != parents.End(); piter++) {
- include(tree, *piter);
+ for (const ContentInfo *ci : parents) {
+ include(tree, ci);
}
}
}
@@ -965,8 +955,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
* we automatically selected them. */
ConstContentVector parents;
this->ReverseLookupDependency(parents, ci);
- for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
- const ContentInfo *c = *iter;
+ for (const ContentInfo *c : parents) {
if (!c->IsSelected()) continue;
this->Unselect(c->id);
@@ -987,9 +976,9 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
/* First check whether anything depends on us */
int sel_count = 0;
bool force_selection = false;
- for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
- if ((*iter)->IsSelected()) sel_count++;
- if ((*iter)->state == ContentInfo::SELECTED) force_selection = true;
+ for (const ContentInfo *ci : parents) {
+ if (ci->IsSelected()) sel_count++;
+ if (ci->state == ContentInfo::SELECTED) force_selection = true;
}
if (sel_count == 0) {
/* Nothing depends on us */
@@ -1004,8 +993,8 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
this->ReverseLookupTreeDependency(parents, c);
/* Is there anything that is "force" selected?, if so... we're done. */
- for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
- if ((*iter)->state != ContentInfo::SELECTED) continue;
+ for (const ContentInfo *ci : parents) {
+ if (ci->state != ContentInfo::SELECTED) continue;
force_selection = true;
break;
@@ -1018,12 +1007,11 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
* After that's done run over them once again to test their children
* to unselect. Don't do it immediately because it'll do exactly what
* we're doing now. */
- for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
- const ContentInfo *c = *iter;
+ for (const ContentInfo *c : parents) {
if (c->state == ContentInfo::AUTOSELECTED) this->Unselect(c->id);
}
- for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
- this->CheckDependencyState(this->GetContent((*iter)->id));
+ for (const ContentInfo *c : parents) {
+ this->CheckDependencyState(this->GetContent(c->id));
}
}
}
@@ -1031,7 +1019,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
/** Clear all downloaded content information. */
void ClientNetworkContentSocketHandler::Clear()
{
- for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) delete *iter;
+ for (ContentInfo *c : this->infos) delete c;
this->infos.clear();
this->requested.clear();
@@ -1041,37 +1029,37 @@ void ClientNetworkContentSocketHandler::Clear()
void ClientNetworkContentSocketHandler::OnConnect(bool success)
{
- for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
+ for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnConnect(success);
- if (iter != this->callbacks.End() && *iter == cb) iter++;
+ if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnDisconnect()
{
- for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
+ for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnDisconnect();
- if (iter != this->callbacks.End() && *iter == cb) iter++;
+ if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnReceiveContentInfo(const ContentInfo *ci)
{
- for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
+ for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnReceiveContentInfo(ci);
- if (iter != this->callbacks.End() && *iter == cb) iter++;
+ if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnDownloadProgress(const ContentInfo *ci, int bytes)
{
- for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
+ for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnDownloadProgress(ci, bytes);
- if (iter != this->callbacks.End() && *iter == cb) iter++;
+ if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
@@ -1082,9 +1070,9 @@ void ClientNetworkContentSocketHandler::OnDownloadComplete(ContentID cid)
ci->state = ContentInfo::ALREADY_HERE;
}
- for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
+ for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnDownloadComplete(cid);
- if (iter != this->callbacks.End() && *iter == cb) iter++;
+ if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
diff --git a/src/network/network_content.h b/src/network/network_content.h
index 08e7755aa..26300c4ca 100644
--- a/src/network/network_content.h
+++ b/src/network/network_content.h
@@ -131,11 +131,11 @@ public:
/** Get the number of content items we know locally. */
uint Length() const { return this->infos.size(); }
/** Get the begin of the content inf iterator. */
- ConstContentIterator Begin() const { return this->infos.Begin(); }
+ ConstContentIterator Begin() const { return this->infos.data(); }
/** Get the nth position of the content inf iterator. */
ConstContentIterator Get(uint32 index) const { return this->infos.data() + index; }
/** Get the end of the content inf iterator. */
- ConstContentIterator End() const { return this->infos.End(); }
+ ConstContentIterator End() const { return this->Begin() + this->Length(); }
void Clear();
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp
index 8e3ec9686..9ea56d747 100644
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -176,8 +176,8 @@ public:
~NetworkContentDownloadStatusWindow()
{
TarScanner::Mode mode = TarScanner::NONE;
- for (ContentType *iter = this->receivedTypes.Begin(); iter != this->receivedTypes.End(); iter++) {
- switch (*iter) {
+ for (auto ctype : this->receivedTypes) {
+ switch (ctype) {
case CONTENT_TYPE_AI:
case CONTENT_TYPE_AI_LIBRARY:
/* AI::Rescan calls the scanner. */
@@ -210,8 +210,8 @@ public:
TarScanner::DoScan(mode);
/* Tell all the backends about what we've downloaded */
- for (ContentType *iter = this->receivedTypes.Begin(); iter != this->receivedTypes.End(); iter++) {
- switch (*iter) {
+ for (auto ctype : this->receivedTypes) {
+ switch (ctype) {
case CONTENT_TYPE_AI:
case CONTENT_TYPE_AI_LIBRARY:
AI::Rescan();
@@ -333,8 +333,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
pos = strecpy(pos, "do=searchgrfid&q=", last);
bool first = true;
- for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
- const ContentInfo *ci = *iter;
+ for (const ContentInfo *ci : this->content) {
if (ci->state != ContentInfo::DOES_NOT_EXIST) continue;
if (!first) pos = strecpy(pos, ",", last);
@@ -635,8 +634,13 @@ public:
int sprite_y_offset = WD_MATRIX_TOP + (line_height - this->checkbox_size.height) / 2 - 1;
int text_y_offset = WD_MATRIX_TOP + (line_height - FONT_HEIGHT_NORMAL) / 2;
uint y = r.top;
- int cnt = 0;
- for (ConstContentIterator iter = this->content.data() + this->vscroll->GetPosition(); iter != this->content.End() && cnt < this->vscroll->GetCapacity(); iter++, cnt++) {
+
+ auto iter = this->content.begin() + this->vscroll->GetPosition();
+ auto end = iter + this->vscroll->GetCapacity();
+ if (end > this->content.end())
+ end = this->content.end();
+
+ for (/**/; iter != end; iter++) {
const ContentInfo *ci = *iter;
if (ci == this->selected) GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->resize.step_height - 1, PC_GREY);
@@ -761,8 +765,7 @@ public:
char buf[DRAW_STRING_BUFFER] = "";
char *p = buf;
- for (ConstContentIterator iter = tree.Begin(); iter != tree.End(); iter++) {
- const ContentInfo *ci = *iter;
+ for (const ContentInfo *ci : tree) {
if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
p += seprintf(p, lastof(buf), buf == p ? "%s" : ", %s", ci->name);
@@ -985,8 +988,7 @@ public:
this->filesize_sum = 0;
bool show_select_all = false;
bool show_select_upgrade = false;
- for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
- const ContentInfo *ci = *iter;
+ for (const ContentInfo *ci : this->content) {
switch (ci->state) {
case ContentInfo::SELECTED:
case ContentInfo::AUTOSELECTED:
@@ -1158,7 +1160,7 @@ void ShowNetworkContentListWindow(ContentVector *cv, ContentType type1, ContentT
ShowErrorMessage(STR_CONTENT_NO_ZLIB, STR_CONTENT_NO_ZLIB_SUB, WL_ERROR);
/* Connection failed... clean up the mess */
if (cv != NULL) {
- for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) delete *iter;
+ for (ContentInfo *ci : *cv) delete ci;
}
#endif /* WITH_ZLIB */
}
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 7b65f6b0c..a8dd2aa52 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -1045,8 +1045,8 @@ void ShowNetworkGameWindow()
if (first) {
first = false;
/* Add all servers from the config file to our list. */
- for (char **iter = _network_host_list.Begin(); iter != _network_host_list.End(); iter++) {
- NetworkAddServer(*iter);
+ for (char *iter : _network_host_list) {
+ NetworkAddServer(iter);
}
}
@@ -1783,8 +1783,8 @@ struct NetworkClientListPopupWindow : Window {
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
Dimension d = *size;
- for (const ClientListAction *action = this->actions.Begin(); action != this->actions.End(); action++) {
- d = maxdim(GetStringBoundingBox(action->name), d);
+ for (const ClientListAction &action : this->actions) {
+ d = maxdim(GetStringBoundingBox(action.name), d);
}
d.height *= this->actions.size();
@@ -1798,7 +1798,7 @@ struct NetworkClientListPopupWindow : Window {
/* Draw the actions */
int sel = this->sel_index;
int y = r.top + WD_FRAMERECT_TOP;
- for (const ClientListAction *action = this->actions.Begin(); action != this->actions.End(); action++, y += FONT_HEIGHT_NORMAL) {
+ for (const ClientListAction &action : this->actions) {
TextColour colour;
if (sel-- == 0) { // Selected item, highlight it
GfxFillRect(r.left + 1, y, r.right - 1, y + FONT_HEIGHT_NORMAL - 1, PC_BLACK);
@@ -1807,7 +1807,8 @@ struct NetworkClientListPopupWindow : Window {
colour = TC_BLACK;
}
- DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, action->name, colour);
+ DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, action.name, colour);
+ y += FONT_HEIGHT_NORMAL;
}
}
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 8a1e75d2f..36dde0f2c 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -2095,8 +2095,8 @@ uint NetworkServerKickOrBanIP(const char *ip, bool ban)
/* Add address to ban-list */
if (ban) {
bool contains = false;
- for (char **iter = _network_ban_list.Begin(); iter != _network_ban_list.End(); iter++) {
- if (strcmp(*iter, ip) == 0) {
+ for (char *iter : _network_ban_list) {
+ if (strcmp(iter, ip) == 0) {
contains = true;
break;
}
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index b416ee98e..2d7ee2d3c 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -495,12 +495,12 @@ void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFCo
/** Broadcast to all ips */
static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket)
{
- for (NetworkAddress *addr = _broadcast_list.Begin(); addr != _broadcast_list.End(); addr++) {
+ for (NetworkAddress &addr : _broadcast_list) {
Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
- DEBUG(net, 4, "[udp] broadcasting to %s", addr->GetHostname());
+ DEBUG(net, 4, "[udp] broadcasting to %s", addr.GetHostname());
- socket->SendPacket(&p, addr, true, true);
+ socket->SendPacket(&p, &addr, true, true);
}
}