summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2019-12-16 19:28:46 +0100
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-12-21 20:13:03 +0100
commit09fa39c5b59d88a076a244cf1623a53b0ffa1434 (patch)
treec4b7006085df37a7c0b5f5a5bb3e62bcc53cae42 /src
parent00c2a98cf395d6e2a85290048e7be7a7f6ce0d04 (diff)
downloadopenttd-09fa39c5b59d88a076a244cf1623a53b0ffa1434.tar.xz
Codechange: Replace linkgraph related FOR_ALL with range-based for loops
Diffstat (limited to 'src')
-rw-r--r--src/date.cpp3
-rw-r--r--src/linkgraph/linkgraph.h2
-rw-r--r--src/linkgraph/linkgraphjob.h2
-rw-r--r--src/linkgraph/linkgraphschedule.cpp6
-rw-r--r--src/saveload/linkgraph_sl.cpp14
5 files changed, 8 insertions, 19 deletions
diff --git a/src/date.cpp b/src/date.cpp
index 74ad76d14..778688720 100644
--- a/src/date.cpp
+++ b/src/date.cpp
@@ -210,8 +210,7 @@ static void OnNewYear()
_date -= days_this_year;
FOR_ALL_VEHICLES(v) v->date_of_last_service -= days_this_year;
- LinkGraph *lg;
- FOR_ALL_LINK_GRAPHS(lg) lg->ShiftDates(-days_this_year);
+ for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(-days_this_year);
/* Because the _date wraps here, and text-messages expire by game-days, we have to clean out
* all of them if the date is set back, else those messages will hang for ever */
diff --git a/src/linkgraph/linkgraph.h b/src/linkgraph/linkgraph.h
index 4995efd96..997d94623 100644
--- a/src/linkgraph/linkgraph.h
+++ b/src/linkgraph/linkgraph.h
@@ -534,6 +534,4 @@ protected:
EdgeMatrix edges; ///< Edges in the component.
};
-#define FOR_ALL_LINK_GRAPHS(var) FOR_ALL_ITEMS_FROM(LinkGraph, link_graph_index, var, 0)
-
#endif /* LINKGRAPH_H */
diff --git a/src/linkgraph/linkgraphjob.h b/src/linkgraph/linkgraphjob.h
index 955ebefd3..9344ea246 100644
--- a/src/linkgraph/linkgraphjob.h
+++ b/src/linkgraph/linkgraphjob.h
@@ -334,8 +334,6 @@ public:
inline const LinkGraph &Graph() const { return this->link_graph; }
};
-#define FOR_ALL_LINK_GRAPH_JOBS(var) FOR_ALL_ITEMS_FROM(LinkGraphJob, link_graph_job_index, var, 0)
-
/**
* A leg of a path in the link graph. Paths can form trees by being "forked".
*/
diff --git a/src/linkgraph/linkgraphschedule.cpp b/src/linkgraph/linkgraphschedule.cpp
index b1ee71f9a..964744509 100644
--- a/src/linkgraph/linkgraphschedule.cpp
+++ b/src/linkgraph/linkgraphschedule.cpp
@@ -107,10 +107,8 @@ void LinkGraphSchedule::SpawnAll()
*/
void LinkGraphSchedule::ShiftDates(int interval)
{
- LinkGraph *lg;
- FOR_ALL_LINK_GRAPHS(lg) lg->ShiftDates(interval);
- LinkGraphJob *lgj;
- FOR_ALL_LINK_GRAPH_JOBS(lgj) lgj->ShiftJoinDate(interval);
+ for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(interval);
+ for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) lgj->ShiftJoinDate(interval);
}
/**
diff --git a/src/saveload/linkgraph_sl.cpp b/src/saveload/linkgraph_sl.cpp
index 608630b83..29b685cf7 100644
--- a/src/saveload/linkgraph_sl.cpp
+++ b/src/saveload/linkgraph_sl.cpp
@@ -228,17 +228,15 @@ static void Load_LGRS()
void AfterLoadLinkGraphs()
{
if (IsSavegameVersionBefore(SLV_191)) {
- LinkGraph *lg;
- FOR_ALL_LINK_GRAPHS(lg) {
+ for (LinkGraph *lg : LinkGraph::Iterate()) {
for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
const Station *st = Station::GetIfValid((*lg)[node_id].Station());
if (st != nullptr) (*lg)[node_id].UpdateLocation(st->xy);
}
}
- LinkGraphJob *lgj;
- FOR_ALL_LINK_GRAPH_JOBS(lgj) {
- lg = &(const_cast<LinkGraph &>(lgj->Graph()));
+ for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
+ LinkGraph *lg = &(const_cast<LinkGraph &>(lgj->Graph()));
for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
const Station *st = Station::GetIfValid((*lg)[node_id].Station());
if (st != nullptr) (*lg)[node_id].UpdateLocation(st->xy);
@@ -254,8 +252,7 @@ void AfterLoadLinkGraphs()
*/
static void Save_LGRP()
{
- LinkGraph *lg;
- FOR_ALL_LINK_GRAPHS(lg) {
+ for (LinkGraph *lg : LinkGraph::Iterate()) {
SlSetArrayIndex(lg->index);
SlAutolength((AutolengthProc*)DoSave_LGRP, lg);
}
@@ -266,8 +263,7 @@ static void Save_LGRP()
*/
static void Save_LGRJ()
{
- LinkGraphJob *lgj;
- FOR_ALL_LINK_GRAPH_JOBS(lgj) {
+ for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
SlSetArrayIndex(lgj->index);
SlAutolength((AutolengthProc*)DoSave_LGRJ, lgj);
}