diff options
author | Patric Stout <truebrain@openttd.org> | 2021-05-31 22:26:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-31 22:26:44 +0200 |
commit | 9fff00ba205260ee5e11b50f87a3edee9b7e76a3 (patch) | |
tree | 2c6ee1eb6f0df2539c9ed17a2ae05541518a7dc9 /src/saveload/linkgraph_sl.cpp | |
parent | 956d761e3ef1968c6470a9e78597c5531ed7c332 (diff) | |
download | openttd-9fff00ba205260ee5e11b50f87a3edee9b7e76a3.tar.xz |
Codechange: C++-ify lists for SaveLoad (#9323)
Basically, this changes "SaveLoad *" to either:
1) "SaveLoadTable" if a list of SaveLoads was meant
2) "SaveLoad &" if a single entry was meant
As added bonus, this removes SL_END / SLE_END / SLEG_END. This
also adds core/span.hpp, a "std::span"-lite.
Diffstat (limited to 'src/saveload/linkgraph_sl.cpp')
-rw-r--r-- | src/saveload/linkgraph_sl.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/saveload/linkgraph_sl.cpp b/src/saveload/linkgraph_sl.cpp index 7d4fe5671..398300028 100644 --- a/src/saveload/linkgraph_sl.cpp +++ b/src/saveload/linkgraph_sl.cpp @@ -26,13 +26,12 @@ static uint16 _num_nodes; * Get a SaveLoad array for a link graph. * @return SaveLoad array for link graph. */ -const SaveLoad *GetLinkGraphDesc() +SaveLoadTable GetLinkGraphDesc() { static const SaveLoad link_graph_desc[] = { SLE_VAR(LinkGraph, last_compression, SLE_INT32), SLEG_VAR(_num_nodes, SLE_UINT16), SLE_VAR(LinkGraph, cargo, SLE_UINT8), - SLE_END() }; return link_graph_desc; } @@ -46,7 +45,7 @@ const SaveLoad *GetLinkGraphDesc() * Of course the settings have to be saved and loaded, too, to avoid desyncs. * @return Array of SaveLoad structs. */ -const SaveLoad *GetLinkGraphJobDesc() +SaveLoadTable GetLinkGraphJobDesc() { static std::vector<SaveLoad> saveloads; static const char *prefix = "linkgraph."; @@ -54,7 +53,6 @@ const SaveLoad *GetLinkGraphJobDesc() static const SaveLoad job_desc[] = { SLE_VAR(LinkGraphJob, join_date, SLE_INT32), SLE_VAR(LinkGraphJob, link_graph.index, SLE_UINT16), - SLE_END() }; /* The member offset arithmetic below is only valid if the types in question @@ -74,25 +72,23 @@ const SaveLoad *GetLinkGraphJobDesc() sl.address_proc = proc; } - int i = 0; - do { - saveloads.push_back(job_desc[i++]); - } while (saveloads.back().cmd != SL_END); + for (auto &sld : job_desc) { + saveloads.push_back(sld); + } } - return &saveloads[0]; + return saveloads; } /** * Get a SaveLoad array for the link graph schedule. * @return SaveLoad array for the link graph schedule. */ -const SaveLoad *GetLinkGraphScheduleDesc() +SaveLoadTable GetLinkGraphScheduleDesc() { static const SaveLoad schedule_desc[] = { SLE_LST(LinkGraphSchedule, schedule, REF_LINK_GRAPH), SLE_LST(LinkGraphSchedule, running, REF_LINK_GRAPH_JOB), - SLE_END() }; return schedule_desc; } @@ -108,7 +104,6 @@ static const SaveLoad _node_desc[] = { SLE_VAR(Node, demand, SLE_UINT32), SLE_VAR(Node, station, SLE_UINT16), SLE_VAR(Node, last_update, SLE_INT32), - SLE_END() }; /** @@ -121,7 +116,6 @@ static const SaveLoad _edge_desc[] = { SLE_VAR(Edge, last_unrestricted_update, SLE_INT32), SLE_CONDVAR(Edge, last_restricted_update, SLE_INT32, SLV_187, SL_MAX_VERSION), SLE_VAR(Edge, next_edge, SLE_UINT16), - SLE_END() }; /** |