summaryrefslogtreecommitdiff
path: root/src/industry_gui.cpp
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2019-04-11 21:26:02 +0200
committerPeterN <peter@fuzzle.org>2019-04-13 12:49:18 +0100
commit2db88953e7e0e521b4514f356038eeb36b299dff (patch)
tree0f058052645065811ffa58deaee2e592583587b5 /src/industry_gui.cpp
parentb9b34f676b96e29ec91711bd7ff74d2492424655 (diff)
downloadopenttd-2db88953e7e0e521b4514f356038eeb36b299dff.tar.xz
Codechange: use std::sort() in GUIList
Diffstat (limited to 'src/industry_gui.cpp')
-rw-r--r--src/industry_gui.cpp36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 17212926d..98fb09859 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -1252,52 +1252,52 @@ protected:
}
/** Sort industries by name */
- static int CDECL IndustryNameSorter(const Industry * const *a, const Industry * const *b)
+ static bool IndustryNameSorter(const Industry * const &a, const Industry * const &b)
{
static char buf_cache[96];
static char buf[96];
- SetDParam(0, (*a)->index);
+ SetDParam(0, a->index);
GetString(buf, STR_INDUSTRY_NAME, lastof(buf));
- if (*b != last_industry) {
- last_industry = *b;
- SetDParam(0, (*b)->index);
+ if (b != last_industry) {
+ last_industry = b;
+ SetDParam(0, b->index);
GetString(buf_cache, STR_INDUSTRY_NAME, lastof(buf_cache));
}
- return strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
+ return strnatcmp(buf, buf_cache) < 0; // Sort by name (natural sorting).
}
/** Sort industries by type and name */
- static int CDECL IndustryTypeSorter(const Industry * const *a, const Industry * const *b)
+ static bool IndustryTypeSorter(const Industry * const &a, const Industry * const &b)
{
int it_a = 0;
- while (it_a != NUM_INDUSTRYTYPES && (*a)->type != _sorted_industry_types[it_a]) it_a++;
+ while (it_a != NUM_INDUSTRYTYPES && a->type != _sorted_industry_types[it_a]) it_a++;
int it_b = 0;
- while (it_b != NUM_INDUSTRYTYPES && (*b)->type != _sorted_industry_types[it_b]) it_b++;
+ while (it_b != NUM_INDUSTRYTYPES && b->type != _sorted_industry_types[it_b]) it_b++;
int r = it_a - it_b;
- return (r == 0) ? IndustryNameSorter(a, b) : r;
+ return (r == 0) ? IndustryNameSorter(a, b) : r < 0;
}
/** Sort industries by production and name */
- static int CDECL IndustryProductionSorter(const Industry * const *a, const Industry * const *b)
+ static bool IndustryProductionSorter(const Industry * const &a, const Industry * const &b)
{
uint prod_a = 0, prod_b = 0;
- for (uint i = 0; i < lengthof((*a)->produced_cargo); i++) {
- if ((*a)->produced_cargo[i] != CT_INVALID) prod_a += (*a)->last_month_production[i];
- if ((*b)->produced_cargo[i] != CT_INVALID) prod_b += (*b)->last_month_production[i];
+ for (uint i = 0; i < lengthof(a->produced_cargo); i++) {
+ if (a->produced_cargo[i] != CT_INVALID) prod_a += a->last_month_production[i];
+ if (b->produced_cargo[i] != CT_INVALID) prod_b += b->last_month_production[i];
}
int r = prod_a - prod_b;
- return (r == 0) ? IndustryTypeSorter(a, b) : r;
+ return (r == 0) ? IndustryTypeSorter(a, b) : r < 0;
}
/** Sort industries by transported cargo and name */
- static int CDECL IndustryTransportedCargoSorter(const Industry * const *a, const Industry * const *b)
+ static bool IndustryTransportedCargoSorter(const Industry * const &a, const Industry * const &b)
{
- int r = GetCargoTransportedSortValue(*a) - GetCargoTransportedSortValue(*b);
- return (r == 0) ? IndustryNameSorter(a, b) : r;
+ int r = GetCargoTransportedSortValue(a) - GetCargoTransportedSortValue(b);
+ return (r == 0) ? IndustryNameSorter(a, b) : r < 0;
}
/**