summaryrefslogtreecommitdiff
path: root/src/industry_gui.cpp
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2019-04-13 23:46:11 +0200
committerglx22 <glx22@users.noreply.github.com>2019-04-18 21:49:34 +0200
commit48f99fd980f0577ab4336d7807a1781000253c3b (patch)
treed65f41f03d71eb004aeb5c9e6d9af12159348dd2 /src/industry_gui.cpp
parent60da17418a190eb262eda5eadb03954a8b98a0e6 (diff)
downloadopenttd-48f99fd980f0577ab4336d7807a1781000253c3b.tar.xz
Codechange: use std::array for _sorted_industry_types
Diffstat (limited to 'src/industry_gui.cpp')
-rw-r--r--src/industry_gui.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 98fb09859..f698ace57 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -183,23 +183,23 @@ static inline void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixTy
}
}
-IndustryType _sorted_industry_types[NUM_INDUSTRYTYPES]; ///< Industry types sorted by name.
+std::array<IndustryType, NUM_INDUSTRYTYPES> _sorted_industry_types; ///< Industry types sorted by name.
/** Sort industry types by their name. */
-static int CDECL IndustryTypeNameSorter(const IndustryType *a, const IndustryType *b)
+static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
{
static char industry_name[2][64];
- const IndustrySpec *indsp1 = GetIndustrySpec(*a);
+ const IndustrySpec *indsp1 = GetIndustrySpec(a);
GetString(industry_name[0], indsp1->name, lastof(industry_name[0]));
- const IndustrySpec *indsp2 = GetIndustrySpec(*b);
+ const IndustrySpec *indsp2 = GetIndustrySpec(b);
GetString(industry_name[1], indsp2->name, lastof(industry_name[1]));
int r = strnatcmp(industry_name[0], industry_name[1]); // Sort by name (natural sorting).
/* If the names are equal, sort by industry type. */
- return (r != 0) ? r : (*a - *b);
+ return (r != 0) ? r < 0 : (a < b);
}
/**
@@ -213,7 +213,7 @@ void SortIndustryTypes()
}
/* Sort industry types by name. */
- QSortT(_sorted_industry_types, NUM_INDUSTRYTYPES, &IndustryTypeNameSorter);
+ std::sort(_sorted_industry_types.begin(), _sorted_industry_types.end(), IndustryTypeNameSorter);
}
/**
@@ -302,8 +302,7 @@ class BuildIndustryWindow : public Window {
* The tests performed after the enabled allow to load the industries
* In the same way they are inserted by grf (if any)
*/
- for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) {
- IndustryType ind = _sorted_industry_types[i];
+ for (IndustryType ind : _sorted_industry_types) {
const IndustrySpec *indsp = GetIndustrySpec(ind);
if (indsp->enabled) {
/* Rule is that editor mode loads all industries.
@@ -2723,8 +2722,7 @@ struct IndustryCargoesWindow : public Window {
case WID_IC_IND_DROPDOWN: {
DropDownList lst;
- for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) {
- IndustryType ind = _sorted_industry_types[i];
+ for (IndustryType ind : _sorted_industry_types) {
const IndustrySpec *indsp = GetIndustrySpec(ind);
if (!indsp->enabled) continue;
lst.emplace_back(new DropDownListStringItem(indsp->name, ind, false));
@@ -2811,10 +2809,10 @@ const int IndustryCargoesWindow::VERT_TEXT_PADDING = 5; ///< Vertical padding ar
static void ShowIndustryCargoesWindow(IndustryType id)
{
if (id >= NUM_INDUSTRYTYPES) {
- for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) {
- const IndustrySpec *indsp = GetIndustrySpec(_sorted_industry_types[i]);
+ for (IndustryType ind : _sorted_industry_types) {
+ const IndustrySpec *indsp = GetIndustrySpec(ind);
if (indsp->enabled) {
- id = _sorted_industry_types[i];
+ id = ind;
break;
}
}