Last active
August 24, 2017 18:46
-
-
Save LordAro/760063761dc46bacb0c37576c296361a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 37747050d5e069f037e735ee3d61efcd1ce46b51 Mon Sep 17 00:00:00 2001 | |
From: Charles Pigott <charlespigott@googlemail.com> | |
Date: Sun, 18 Jun 2017 15:58:40 +0100 | |
Subject: [PATCH 1/2] -Codechange: Replace all sort functions with std::sort | |
variants. | |
--- | |
projects/openttd_vs100.vcxproj | 1 - | |
projects/openttd_vs100.vcxproj.filters | 3 - | |
projects/openttd_vs140.vcxproj | 1 - | |
projects/openttd_vs140.vcxproj.filters | 3 - | |
projects/openttd_vs80.vcproj | 4 - | |
projects/openttd_vs90.vcproj | 4 - | |
source.list | 1 - | |
src/autoreplace_gui.cpp | 6 +- | |
src/bridge_gui.cpp | 12 +- | |
src/build_vehicle_gui.cpp | 281 +++++++++++++++------------------ | |
src/cargotype.cpp | 33 ++-- | |
src/core/smallmap_type.hpp | 9 +- | |
src/core/sort_func.hpp | 89 ----------- | |
src/engine_gui.cpp | 4 +- | |
src/engine_gui.h | 2 +- | |
src/fios.cpp | 18 +-- | |
src/fios.h | 20 ++- | |
src/fios_gui.cpp | 3 +- | |
src/gfx.cpp | 8 +- | |
src/graph_gui.cpp | 4 +- | |
src/group_gui.cpp | 18 +-- | |
src/highscore.cpp | 10 +- | |
src/industry_gui.cpp | 50 +++--- | |
src/network/network_content_gui.cpp | 20 ++- | |
src/network/network_gui.cpp | 57 ++++--- | |
src/newgrf_config.cpp | 17 +- | |
src/newgrf_engine.cpp | 14 +- | |
src/newgrf_gui.cpp | 12 +- | |
src/rail_cmd.cpp | 6 +- | |
src/settings_gui.cpp | 8 +- | |
src/signs_gui.cpp | 13 +- | |
src/sortlist_type.h | 54 +++++-- | |
src/station_gui.cpp | 57 ++++--- | |
src/story_gui.cpp | 8 +- | |
src/strings.cpp | 8 +- | |
src/strings_func.h | 2 +- | |
src/timetable_cmd.cpp | 21 +-- | |
src/town_gui.cpp | 50 +++--- | |
src/vehicle_gui.cpp | 93 +++++------ | |
src/video/cocoa/cocoa_v.mm | 11 +- | |
src/widgets/dropdown.cpp | 8 +- | |
src/widgets/dropdown_type.h | 2 +- | |
src/window.cpp | 8 +- | |
43 files changed, 471 insertions(+), 582 deletions(-) | |
delete mode 100644 src/core/sort_func.hpp | |
diff --git a/projects/openttd_vs100.vcxproj b/projects/openttd_vs100.vcxproj | |
index 9c3b10786..3fdc5e31b 100644 | |
--- a/projects/openttd_vs100.vcxproj | |
+++ b/projects/openttd_vs100.vcxproj | |
@@ -698,7 +698,6 @@ | |
<ClInclude Include="..\src\core\smallmatrix_type.hpp" /> | |
<ClInclude Include="..\src\core\smallstack_type.hpp" /> | |
<ClInclude Include="..\src\core\smallvec_type.hpp" /> | |
- <ClInclude Include="..\src\core\sort_func.hpp" /> | |
<ClInclude Include="..\src\core\string_compare_type.hpp" /> | |
<ClCompile Include="..\src\aircraft_gui.cpp" /> | |
<ClCompile Include="..\src\airport_gui.cpp" /> | |
diff --git a/projects/openttd_vs100.vcxproj.filters b/projects/openttd_vs100.vcxproj.filters | |
index 06800ffda..b0e5d7e52 100644 | |
--- a/projects/openttd_vs100.vcxproj.filters | |
+++ b/projects/openttd_vs100.vcxproj.filters | |
@@ -1287,9 +1287,6 @@ | |
<ClInclude Include="..\src\core\smallvec_type.hpp"> | |
<Filter>Core Source Code</Filter> | |
</ClInclude> | |
- <ClInclude Include="..\src\core\sort_func.hpp"> | |
- <Filter>Core Source Code</Filter> | |
- </ClInclude> | |
<ClInclude Include="..\src\core\string_compare_type.hpp"> | |
<Filter>Core Source Code</Filter> | |
</ClInclude> | |
diff --git a/projects/openttd_vs140.vcxproj b/projects/openttd_vs140.vcxproj | |
index eb8494167..87628881b 100644 | |
--- a/projects/openttd_vs140.vcxproj | |
+++ b/projects/openttd_vs140.vcxproj | |
@@ -715,7 +715,6 @@ | |
<ClInclude Include="..\src\core\smallmatrix_type.hpp" /> | |
<ClInclude Include="..\src\core\smallstack_type.hpp" /> | |
<ClInclude Include="..\src\core\smallvec_type.hpp" /> | |
- <ClInclude Include="..\src\core\sort_func.hpp" /> | |
<ClInclude Include="..\src\core\string_compare_type.hpp" /> | |
<ClCompile Include="..\src\aircraft_gui.cpp" /> | |
<ClCompile Include="..\src\airport_gui.cpp" /> | |
diff --git a/projects/openttd_vs140.vcxproj.filters b/projects/openttd_vs140.vcxproj.filters | |
index 06800ffda..b0e5d7e52 100644 | |
--- a/projects/openttd_vs140.vcxproj.filters | |
+++ b/projects/openttd_vs140.vcxproj.filters | |
@@ -1287,9 +1287,6 @@ | |
<ClInclude Include="..\src\core\smallvec_type.hpp"> | |
<Filter>Core Source Code</Filter> | |
</ClInclude> | |
- <ClInclude Include="..\src\core\sort_func.hpp"> | |
- <Filter>Core Source Code</Filter> | |
- </ClInclude> | |
<ClInclude Include="..\src\core\string_compare_type.hpp"> | |
<Filter>Core Source Code</Filter> | |
</ClInclude> | |
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj | |
index 70dcab226..522741fcb 100644 | |
--- a/projects/openttd_vs80.vcproj | |
+++ b/projects/openttd_vs80.vcproj | |
@@ -2022,10 +2022,6 @@ | |
RelativePath=".\..\src\core\smallvec_type.hpp" | |
> | |
</File> | |
- <File | |
- RelativePath=".\..\src\core\sort_func.hpp" | |
- > | |
- </File> | |
<File | |
RelativePath=".\..\src\core\string_compare_type.hpp" | |
> | |
diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj | |
index dd722d085..c99a10332 100644 | |
--- a/projects/openttd_vs90.vcproj | |
+++ b/projects/openttd_vs90.vcproj | |
@@ -2019,10 +2019,6 @@ | |
RelativePath=".\..\src\core\smallvec_type.hpp" | |
> | |
</File> | |
- <File | |
- RelativePath=".\..\src\core\sort_func.hpp" | |
- > | |
- </File> | |
<File | |
RelativePath=".\..\src\core\string_compare_type.hpp" | |
> | |
diff --git a/source.list b/source.list | |
index df35cdd26..888578b4b 100644 | |
--- a/source.list | |
+++ b/source.list | |
@@ -442,7 +442,6 @@ core/smallmap_type.hpp | |
core/smallmatrix_type.hpp | |
core/smallstack_type.hpp | |
core/smallvec_type.hpp | |
-core/sort_func.hpp | |
core/string_compare_type.hpp | |
# GUI Source Code | |
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp | |
index 1074d1dd7..7342c1864 100644 | |
--- a/src/autoreplace_gui.cpp | |
+++ b/src/autoreplace_gui.cpp | |
@@ -32,11 +32,9 @@ | |
void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group); | |
-static int CDECL EngineNumberSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL EngineNumberSorter(const EngineID &a, const EngineID &b) | |
{ | |
- int r = Engine::Get(*a)->list_position - Engine::Get(*b)->list_position; | |
- | |
- return r; | |
+ return Engine::Get(a)->list_position < Engine::Get(b)->list_position; | |
} | |
/** | |
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp | |
index 797ead1f5..dfbe5d435 100644 | |
--- a/src/bridge_gui.cpp | |
+++ b/src/bridge_gui.cpp | |
@@ -93,21 +93,21 @@ private: | |
Scrollbar *vscroll; | |
/** Sort the bridges by their index */ | |
- static int CDECL BridgeIndexSorter(const BuildBridgeData *a, const BuildBridgeData *b) | |
+ static bool CDECL BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b) | |
{ | |
- return a->index - b->index; | |
+ return a.index < b.index; | |
} | |
/** Sort the bridges by their price */ | |
- static int CDECL BridgePriceSorter(const BuildBridgeData *a, const BuildBridgeData *b) | |
+ static bool CDECL BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b) | |
{ | |
- return a->cost - b->cost; | |
+ return a.cost < b.cost; | |
} | |
/** Sort the bridges by their maximum speed */ | |
- static int CDECL BridgeSpeedSorter(const BuildBridgeData *a, const BuildBridgeData *b) | |
+ static bool CDECL BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b) | |
{ | |
- return a->spec->speed - b->spec->speed; | |
+ return a.spec->speed < b.spec->speed; | |
} | |
void BuildBridge(uint8 i) | |
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp | |
index 655a18d7f..22a09afa6 100644 | |
--- a/src/build_vehicle_gui.cpp | |
+++ b/src/build_vehicle_gui.cpp | |
@@ -99,47 +99,46 @@ static CargoID _engine_sort_last_cargo_criteria[] = {CF_ANY, CF_ANY, CF_ANY, CF_ | |
/** | |
* Determines order of engines by engineID | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL EngineNumberSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL EngineNumberSorter(const EngineID &a, const EngineID &b) | |
{ | |
- int r = Engine::Get(*a)->list_position - Engine::Get(*b)->list_position; | |
- | |
- return _engine_sort_direction ? -r : r; | |
+ const int va = Engine::Get(a)->list_position; | |
+ const int vb = Engine::Get(b)->list_position; | |
+ return va != vb && _engine_sort_direction != (va < vb); | |
} | |
/** | |
* Determines order of engines by introduction date | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL EngineIntroDateSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL EngineIntroDateSorter(const EngineID &a, const EngineID &b) | |
{ | |
- const int va = Engine::Get(*a)->intro_date; | |
- const int vb = Engine::Get(*b)->intro_date; | |
- const int r = va - vb; | |
+ const int va = Engine::Get(a)->intro_date; | |
+ const int vb = Engine::Get(b)->intro_date; | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/** | |
* Determines order of engines by name | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL EngineNameSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL EngineNameSorter(const EngineID &a, const EngineID &b) | |
{ | |
static EngineID last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE }; | |
static char last_name[2][64] = { "\0", "\0" }; | |
- const EngineID va = *a; | |
- const EngineID vb = *b; | |
+ const EngineID va = a; | |
+ const EngineID vb = b; | |
if (va != last_engine[0]) { | |
last_engine[0] = va; | |
@@ -157,121 +156,115 @@ static int CDECL EngineNameSorter(const EngineID *a, const EngineID *b) | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ return _engine_sort_direction != (r < 0); | |
} | |
/** | |
* Determines order of engines by reliability | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL EngineReliabilitySorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL EngineReliabilitySorter(const EngineID &a, const EngineID &b) | |
{ | |
- const int va = Engine::Get(*a)->reliability; | |
- const int vb = Engine::Get(*b)->reliability; | |
- const int r = va - vb; | |
+ const int va = Engine::Get(a)->reliability; | |
+ const int vb = Engine::Get(b)->reliability; | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/** | |
* Determines order of engines by purchase cost | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL EngineCostSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL EngineCostSorter(const EngineID &a, const EngineID &b) | |
{ | |
- Money va = Engine::Get(*a)->GetCost(); | |
- Money vb = Engine::Get(*b)->GetCost(); | |
- int r = ClampToI32(va - vb); | |
+ Money va = Engine::Get(a)->GetCost(); | |
+ Money vb = Engine::Get(b)->GetCost(); | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/** | |
* Determines order of engines by speed | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL EngineSpeedSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL EngineSpeedSorter(const EngineID &a, const EngineID &b) | |
{ | |
- int va = Engine::Get(*a)->GetDisplayMaxSpeed(); | |
- int vb = Engine::Get(*b)->GetDisplayMaxSpeed(); | |
- int r = va - vb; | |
+ int va = Engine::Get(a)->GetDisplayMaxSpeed(); | |
+ int vb = Engine::Get(b)->GetDisplayMaxSpeed(); | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/** | |
* Determines order of engines by power | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL EnginePowerSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL EnginePowerSorter(const EngineID &a, const EngineID &b) | |
{ | |
- int va = Engine::Get(*a)->GetPower(); | |
- int vb = Engine::Get(*b)->GetPower(); | |
- int r = va - vb; | |
+ int va = Engine::Get(a)->GetPower(); | |
+ int vb = Engine::Get(b)->GetPower(); | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/** | |
* Determines order of engines by tractive effort | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL EngineTractiveEffortSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL EngineTractiveEffortSorter(const EngineID &a, const EngineID &b) | |
{ | |
- int va = Engine::Get(*a)->GetDisplayMaxTractiveEffort(); | |
- int vb = Engine::Get(*b)->GetDisplayMaxTractiveEffort(); | |
- int r = va - vb; | |
+ int va = Engine::Get(a)->GetDisplayMaxTractiveEffort(); | |
+ int vb = Engine::Get(b)->GetDisplayMaxTractiveEffort(); | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/** | |
* Determines order of engines by running costs | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL EngineRunningCostSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL EngineRunningCostSorter(const EngineID &a, const EngineID &b) | |
{ | |
- Money va = Engine::Get(*a)->GetRunningCost(); | |
- Money vb = Engine::Get(*b)->GetRunningCost(); | |
- int r = ClampToI32(va - vb); | |
+ Money va = Engine::Get(a)->GetRunningCost(); | |
+ Money vb = Engine::Get(b)->GetRunningCost(); | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/** | |
* Determines order of engines by running costs | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL EnginePowerVsRunningCostSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL EnginePowerVsRunningCostSorter(const EngineID &a, const EngineID &b) | |
{ | |
- const Engine *e_a = Engine::Get(*a); | |
- const Engine *e_b = Engine::Get(*b); | |
+ const Engine *e_a = Engine::Get(a); | |
+ const Engine *e_b = Engine::Get(b); | |
/* Here we are using a few tricks to get the right sort. | |
* We want power/running cost, but since we usually got higher running cost than power and we store the result in an int, | |
@@ -281,139 +274,125 @@ static int CDECL EnginePowerVsRunningCostSorter(const EngineID *a, const EngineI | |
* Since it would be multiplying with 2 in both numerator and denominator, it will even themselves out and we skip checking for multiheaded. */ | |
Money va = (e_a->GetRunningCost()) / max(1U, (uint)e_a->GetPower()); | |
Money vb = (e_b->GetRunningCost()) / max(1U, (uint)e_b->GetPower()); | |
- int r = ClampToI32(vb - va); | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/* Train sorting functions */ | |
/** | |
* Determines order of train engines by capacity | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL TrainEngineCapacitySorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL TrainEngineCapacitySorter(const EngineID &a, const EngineID &b) | |
{ | |
- const RailVehicleInfo *rvi_a = RailVehInfo(*a); | |
- const RailVehicleInfo *rvi_b = RailVehInfo(*b); | |
+ const RailVehicleInfo *rvi_a = RailVehInfo(a); | |
+ const RailVehicleInfo *rvi_b = RailVehInfo(b); | |
- int va = GetTotalCapacityOfArticulatedParts(*a) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); | |
- int vb = GetTotalCapacityOfArticulatedParts(*b) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); | |
- int r = va - vb; | |
+ int va = GetTotalCapacityOfArticulatedParts(a) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); | |
+ int vb = GetTotalCapacityOfArticulatedParts(b) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/** | |
* Determines order of train engines by engine / wagon | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL TrainEnginesThenWagonsSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL TrainEnginesThenWagonsSorter(const EngineID &a, const EngineID &b) | |
{ | |
- int val_a = (RailVehInfo(*a)->railveh_type == RAILVEH_WAGON ? 1 : 0); | |
- int val_b = (RailVehInfo(*b)->railveh_type == RAILVEH_WAGON ? 1 : 0); | |
- int r = val_a - val_b; | |
+ bool va = RailVehInfo(a)->railveh_type == RAILVEH_WAGON; | |
+ bool vb = RailVehInfo(b)->railveh_type == RAILVEH_WAGON; | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != va; | |
} | |
/* Road vehicle sorting functions */ | |
/** | |
* Determines order of road vehicles by capacity | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL RoadVehEngineCapacitySorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL RoadVehEngineCapacitySorter(const EngineID &a, const EngineID &b) | |
{ | |
- int va = GetTotalCapacityOfArticulatedParts(*a); | |
- int vb = GetTotalCapacityOfArticulatedParts(*b); | |
- int r = va - vb; | |
+ int va = GetTotalCapacityOfArticulatedParts(a); | |
+ int vb = GetTotalCapacityOfArticulatedParts(b); | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/* Ship vehicle sorting functions */ | |
/** | |
* Determines order of ships by capacity | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL ShipEngineCapacitySorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL ShipEngineCapacitySorter(const EngineID &a, const EngineID &b) | |
{ | |
- const Engine *e_a = Engine::Get(*a); | |
- const Engine *e_b = Engine::Get(*b); | |
+ const Engine *e_a = Engine::Get(a); | |
+ const Engine *e_b = Engine::Get(b); | |
int va = e_a->GetDisplayDefaultCapacity(); | |
int vb = e_b->GetDisplayDefaultCapacity(); | |
- int r = va - vb; | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/* Aircraft sorting functions */ | |
/** | |
* Determines order of aircraft by cargo | |
- * @param *a first engine to compare | |
- * @param *b second engine to compare | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal | |
+ * @param a first engine to compare | |
+ * @param b second engine to compare | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL AircraftEngineCargoSorter(const EngineID &a, const EngineID &b) | |
{ | |
- const Engine *e_a = Engine::Get(*a); | |
- const Engine *e_b = Engine::Get(*b); | |
+ const Engine *e_a = Engine::Get(a); | |
+ const Engine *e_b = Engine::Get(b); | |
uint16 mail_a, mail_b; | |
int va = e_a->GetDisplayDefaultCapacity(&mail_a); | |
int vb = e_b->GetDisplayDefaultCapacity(&mail_b); | |
- int r = va - vb; | |
- | |
- if (r == 0) { | |
- /* The planes have the same passenger capacity. Check mail capacity instead */ | |
- r = mail_a - mail_b; | |
- if (r == 0) { | |
- /* Use EngineID to sort instead since we want consistent sorting */ | |
- return EngineNumberSorter(a, b); | |
- } | |
- } | |
- return _engine_sort_direction ? -r : r; | |
+ /* The planes have the same passenger capacity. Check mail capacity instead. | |
+ * If both equal, use EngineID to sort instead since we want consistent sorting */ | |
+ if (va == vb && mail_a == mail_b) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va != vb ? va < vb : mail_a < mail_b); | |
} | |
/** | |
* Determines order of aircraft by range. | |
- * @param *a first engine to compare. | |
- * @param *b second engine to compare. | |
- * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal. | |
+ * @param a first engine to compare. | |
+ * @param b second engine to compare. | |
+ * @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static int CDECL AircraftRangeSorter(const EngineID *a, const EngineID *b) | |
+static bool CDECL AircraftRangeSorter(const EngineID &a, const EngineID &b) | |
{ | |
- uint16 r_a = Engine::Get(*a)->GetRange(); | |
- uint16 r_b = Engine::Get(*b)->GetRange(); | |
- | |
- int r = r_a - r_b; | |
+ uint16 va = Engine::Get(a)->GetRange(); | |
+ uint16 vb = Engine::Get(b)->GetRange(); | |
/* Use EngineID to sort instead since we want consistent sorting */ | |
- if (r == 0) return EngineNumberSorter(a, b); | |
- return _engine_sort_direction ? -r : r; | |
+ if (va == vb) return EngineNumberSorter(a, b); | |
+ return _engine_sort_direction != (va < vb); | |
} | |
/** Sort functions for the vehicle sort criteria, for each vehicle type. */ | |
diff --git a/src/cargotype.cpp b/src/cargotype.cpp | |
index 863c58561..ce7622798 100644 | |
--- a/src/cargotype.cpp | |
+++ b/src/cargotype.cpp | |
@@ -10,11 +10,13 @@ | |
/** @file cargotype.cpp Implementation of cargoes. */ | |
#include "stdafx.h" | |
+ | |
+#include <algorithm> | |
+ | |
#include "cargotype.h" | |
#include "newgrf_cargo.h" | |
#include "string_func.h" | |
#include "strings_func.h" | |
-#include "core/sort_func.hpp" | |
#include "table/sprites.h" | |
#include "table/strings.h" | |
@@ -138,35 +140,28 @@ uint8 _sorted_standard_cargo_specs_size; ///< Number of standard cargo s | |
/** Sort cargo specifications by their name. */ | |
-static int CDECL CargoSpecNameSorter(const CargoSpec * const *a, const CargoSpec * const *b) | |
+static bool CDECL CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpec * const &b) | |
{ | |
static char a_name[64]; | |
static char b_name[64]; | |
- GetString(a_name, (*a)->name, lastof(a_name)); | |
- GetString(b_name, (*b)->name, lastof(b_name)); | |
+ GetString(a_name, a->name, lastof(a_name)); | |
+ GetString(b_name, b->name, lastof(b_name)); | |
int res = strnatcmp(a_name, b_name); // Sort by name (natural sorting). | |
/* If the names are equal, sort by cargo bitnum. */ | |
- return (res != 0) ? res : ((*a)->bitnum - (*b)->bitnum); | |
+ return (res != 0) ? res < 0 : (a->bitnum < b->bitnum); | |
} | |
/** Sort cargo specifications by their cargo class. */ | |
-static int CDECL CargoSpecClassSorter(const CargoSpec * const *a, const CargoSpec * const *b) | |
+static bool CDECL CargoSpecClassSorter(const CargoSpec * const &a, const CargoSpec * const &b) | |
{ | |
- int res = ((*b)->classes & CC_PASSENGERS) - ((*a)->classes & CC_PASSENGERS); | |
- if (res == 0) { | |
- res = ((*b)->classes & CC_MAIL) - ((*a)->classes & CC_MAIL); | |
- if (res == 0) { | |
- res = ((*a)->classes & CC_SPECIAL) - ((*b)->classes & CC_SPECIAL); | |
- if (res == 0) { | |
- return CargoSpecNameSorter(a, b); | |
- } | |
- } | |
- } | |
- | |
- return res; | |
+ int r = (b->classes & CC_PASSENGERS) - (a->classes & CC_PASSENGERS); | |
+ if (r == 0) r = (b->classes & CC_MAIL) - (a->classes & CC_MAIL); | |
+ if (r == 0) r = (a->classes & CC_SPECIAL) - (b->classes & CC_SPECIAL); | |
+ if (r == 0) return CargoSpecNameSorter(a, b); | |
+ return r < 0; | |
} | |
/** Initialize the list of sorted cargo specifications. */ | |
@@ -181,7 +176,7 @@ void InitializeSortedCargoSpecs() | |
} | |
/* Sort cargo specifications by cargo class and name. */ | |
- QSortT(_sorted_cargo_specs, _sorted_cargo_specs_size, &CargoSpecClassSorter); | |
+ std::sort(_sorted_cargo_specs, _sorted_cargo_specs + _sorted_cargo_specs_size, &CargoSpecClassSorter); | |
_standard_cargo_mask = 0; | |
diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp | |
index dda0fc2a1..49b5f3b34 100644 | |
--- a/src/core/smallmap_type.hpp | |
+++ b/src/core/smallmap_type.hpp | |
@@ -12,8 +12,9 @@ | |
#ifndef SMALLMAP_TYPE_HPP | |
#define SMALLMAP_TYPE_HPP | |
+#include <algorithm> | |
+ | |
#include "smallvec_type.hpp" | |
-#include "sort_func.hpp" | |
/** | |
* Simple pair of data. Both types have to be POD ("Plain Old Data")! | |
@@ -146,12 +147,12 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> { | |
inline void SortByKey() | |
{ | |
- QSortT(this->Begin(), this->items, KeySorter); | |
+ std::sort(this->Begin(), this->End(), KeySorter); | |
} | |
- static int CDECL KeySorter(const Pair *a, const Pair *b) | |
+ static bool CDECL KeySorter(const Pair &a, const Pair &b) | |
{ | |
- return a->first - b->first; | |
+ return a->first < b->first; | |
} | |
}; | |
diff --git a/src/core/sort_func.hpp b/src/core/sort_func.hpp | |
deleted file mode 100644 | |
index 470a0ccf4..000000000 | |
--- a/src/core/sort_func.hpp | |
+++ /dev/null | |
@@ -1,89 +0,0 @@ | |
-/* $Id$ */ | |
- | |
-/* | |
- * This file is part of OpenTTD. | |
- * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. | |
- * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
- * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. | |
- */ | |
- | |
-/** @file sort_func.hpp Functions related to sorting operations. */ | |
- | |
-#ifndef SORT_FUNC_HPP | |
-#define SORT_FUNC_HPP | |
- | |
-#include "mem_func.hpp" | |
- | |
-/** | |
- * Type safe qsort() | |
- * | |
- * @note Use this sort for irregular sorted data. | |
- * | |
- * @param base Pointer to the first element of the array to be sorted. | |
- * @param num Number of elements in the array pointed by base. | |
- * @param comparator Function that compares two elements. | |
- * @param desc Sort descending. | |
- */ | |
-template <typename T> | |
-static inline void QSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false) | |
-{ | |
- if (num < 2) return; | |
- | |
- qsort(base, num, sizeof(T), (int (CDECL *)(const void *, const void *))comparator); | |
- | |
- if (desc) MemReverseT(base, num); | |
-} | |
- | |
-/** | |
- * Type safe Gnome Sort. | |
- * | |
- * This is a slightly modified Gnome search. The basic | |
- * Gnome search tries to sort already sorted list parts. | |
- * The modification skips these. | |
- * | |
- * @note Use this sort for presorted / regular sorted data. | |
- * | |
- * @param base Pointer to the first element of the array to be sorted. | |
- * @param num Number of elements in the array pointed by base. | |
- * @param comparator Function that compares two elements. | |
- * @param desc Sort descending. | |
- */ | |
-template <typename T> | |
-static inline void GSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false) | |
-{ | |
- if (num < 2) return; | |
- | |
- assert(base != NULL); | |
- assert(comparator != NULL); | |
- | |
- T *a = base; | |
- T *b = base + 1; | |
- uint offset = 0; | |
- | |
- while (num > 1) { | |
- const int diff = comparator(a, b); | |
- if ((!desc && diff <= 0) || (desc && diff >= 0)) { | |
- if (offset != 0) { | |
- /* Jump back to the last direction switch point */ | |
- a += offset; | |
- b += offset; | |
- offset = 0; | |
- continue; | |
- } | |
- | |
- a++; | |
- b++; | |
- num--; | |
- } else { | |
- Swap(*a, *b); | |
- | |
- if (a == base) continue; | |
- | |
- a--; | |
- b--; | |
- offset++; | |
- } | |
- } | |
-} | |
- | |
-#endif /* SORT_FUNC_HPP */ | |
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp | |
index 5e9e8cef7..f125eb73a 100644 | |
--- a/src/engine_gui.cpp | |
+++ b/src/engine_gui.cpp | |
@@ -329,7 +329,7 @@ void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare) | |
/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems) | |
* generally, do not sort if there are less than 2 items */ | |
if (size < 2) return; | |
- QSortT(el->Begin(), size, compare); | |
+ std::sort(el->Begin(), el->End(), compare); | |
} | |
/** | |
@@ -344,6 +344,6 @@ void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, ui | |
if (num_items < 2) return; | |
assert(begin < el->Length()); | |
assert(begin + num_items <= el->Length()); | |
- QSortT(el->Get(begin), num_items, compare); | |
+ std::sort(el->Get(begin), el->Get(begin + num_items), compare); | |
} | |
diff --git a/src/engine_gui.h b/src/engine_gui.h | |
index fc0b7ad7d..ac2ec718f 100644 | |
--- a/src/engine_gui.h | |
+++ b/src/engine_gui.h | |
@@ -19,7 +19,7 @@ | |
typedef GUIList<EngineID, CargoID> GUIEngineList; | |
-typedef int CDECL EngList_SortTypeFunction(const EngineID*, const EngineID*); ///< argument type for #EngList_Sort. | |
+typedef bool CDECL EngList_SortTypeFunction(const EngineID&, const EngineID&); ///< argument type for #EngList_Sort. | |
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare); | |
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); | |
diff --git a/src/fios.cpp b/src/fios.cpp | |
index 5e78fb1b4..b30baa452 100644 | |
--- a/src/fios.cpp | |
+++ b/src/fios.cpp | |
@@ -49,18 +49,14 @@ extern void GetOldSaveGameName(const char *file, char *title, const char *last); | |
* @param db A pointer to the second FiosItem to compare. | |
* @return -1, 0 or 1, depending on how the two items should be sorted. | |
*/ | |
-int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db) | |
+bool CDECL CompareFiosItems(const FiosItem &da, const FiosItem &db) | |
{ | |
- int r = 0; | |
- | |
- if ((_savegame_sort_order & SORT_BY_NAME) == 0 && da->mtime != db->mtime) { | |
- r = da->mtime < db->mtime ? -1 : 1; | |
- } else { | |
- r = strcasecmp(da->title, db->title); | |
+ if ((_savegame_sort_order & SORT_BY_NAME) == 0 && da.mtime != db.mtime) { | |
+ return (_savegame_sort_order & SORT_DESCENDING) != (da.mtime < db.mtime); | |
} | |
- if (_savegame_sort_order & SORT_DESCENDING) r = -r; | |
- return r; | |
+ int r = strcasecmp(da.title, db.title); | |
+ return r != 0 && (_savegame_sort_order & SORT_DESCENDING) != r; | |
} | |
FileList::~FileList() | |
@@ -399,7 +395,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c | |
{ | |
SortingBits order = _savegame_sort_order; | |
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING; | |
- QSortT(file_list.files.Begin(), file_list.files.Length(), CompareFiosItems); | |
+ std::sort(file_list.files.Begin(), file_list.files.End(), CompareFiosItems); | |
_savegame_sort_order = order; | |
} | |
@@ -414,7 +410,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c | |
scanner.Scan(NULL, subdir, true, true); | |
} | |
- QSortT(file_list.Get(sort_start), file_list.Length() - sort_start, CompareFiosItems); | |
+ std::sort(file_list.Get(sort_start), file_list.End(), CompareFiosItems); | |
/* Show drives */ | |
FiosGetDrives(file_list); | |
diff --git a/src/fios.h b/src/fios.h | |
index 5e17e8ee1..fc3daffc1 100644 | |
--- a/src/fios.h | |
+++ b/src/fios.h | |
@@ -134,6 +134,15 @@ public: | |
return this->files.Begin(); | |
} | |
+ /** | |
+ * Get a pointer to the first file information. | |
+ * @return Address of the first file information. | |
+ */ | |
+ inline FiosItem *Begin() | |
+ { | |
+ return this->files.Begin(); | |
+ } | |
+ | |
/** | |
* Get a pointer behind the last file information. | |
* @return Address behind the last file information. | |
@@ -143,6 +152,15 @@ public: | |
return this->files.End(); | |
} | |
+ /** | |
+ * Get a pointer behind the last file information. | |
+ * @return Address behind the last file information. | |
+ */ | |
+ inline FiosItem *End() | |
+ { | |
+ return this->files.End(); | |
+ } | |
+ | |
/** | |
* Get a pointer to the indicated file information. File information must exist. | |
* @return Address of the indicated existing file information. | |
@@ -219,6 +237,6 @@ void FiosMakeSavegameName(char *buf, const char *name, const char *last); | |
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last); | |
-int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b); | |
+bool CDECL CompareFiosItems(const FiosItem &a, const FiosItem &b); | |
#endif /* FIOS_H */ | |
diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp | |
index f20cfd792..b8f118f48 100644 | |
--- a/src/fios_gui.cpp | |
+++ b/src/fios_gui.cpp | |
@@ -221,8 +221,7 @@ static void SortSaveGameList(FileList &file_list) | |
} | |
} | |
- uint s_amount = file_list.Length() - sort_start - sort_end; | |
- QSortT(file_list.Get(sort_start), s_amount, CompareFiosItems); | |
+ std::sort(file_list.Get(sort_start), file_list.Get(sort_end), CompareFiosItems); | |
} | |
struct SaveLoadWindow : public Window { | |
diff --git a/src/gfx.cpp b/src/gfx.cpp | |
index 719505157..d55c74f38 100644 | |
--- a/src/gfx.cpp | |
+++ b/src/gfx.cpp | |
@@ -1699,14 +1699,12 @@ bool ToggleFullScreen(bool fs) | |
return result; | |
} | |
-static int CDECL compare_res(const Dimension *pa, const Dimension *pb) | |
+static bool CDECL compare_res(const Dimension &pa, const Dimension &pb) | |
{ | |
- int x = pa->width - pb->width; | |
- if (x != 0) return x; | |
- return pa->height - pb->height; | |
+ return pa.width < pb.width || (pa.width == pb.width && pa.height < pb.height); | |
} | |
void SortResolutions(int count) | |
{ | |
- QSortT(_resolutions, count, &compare_res); | |
+ std::sort(_resolutions, _resolutions + count, &compare_res); | |
} | |
diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp | |
index c12c6ace4..16fc1107a 100644 | |
--- a/src/graph_gui.cpp | |
+++ b/src/graph_gui.cpp | |
@@ -1151,9 +1151,9 @@ private: | |
} | |
/** Sort the company league by performance history */ | |
- static int CDECL PerformanceSorter(const Company * const *c1, const Company * const *c2) | |
+ static bool CDECL PerformanceSorter(const Company * const &c1, const Company * const &c2) | |
{ | |
- return (*c2)->old_economy[0].performance_history - (*c1)->old_economy[0].performance_history; | |
+ return c2->old_economy[0].performance_history < c1->old_economy[0].performance_history; | |
} | |
public: | |
diff --git a/src/group_gui.cpp b/src/group_gui.cpp | |
index d3e1eafbb..713b11cdb 100644 | |
--- a/src/group_gui.cpp | |
+++ b/src/group_gui.cpp | |
@@ -134,26 +134,26 @@ private: | |
} | |
/** Sort the groups by their name */ | |
- static int CDECL GroupNameSorter(const Group * const *a, const Group * const *b) | |
+ static bool CDECL GroupNameSorter(const Group * const &a, const Group * const &b) | |
{ | |
static const Group *last_group[2] = { NULL, NULL }; | |
static char last_name[2][64] = { "", "" }; | |
- if (*a != last_group[0]) { | |
- last_group[0] = *a; | |
- SetDParam(0, (*a)->index); | |
+ if (a != last_group[0]) { | |
+ last_group[0] = a; | |
+ SetDParam(0, a->index); | |
GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0])); | |
} | |
- if (*b != last_group[1]) { | |
- last_group[1] = *b; | |
- SetDParam(0, (*b)->index); | |
+ if (b != last_group[1]) { | |
+ last_group[1] = b; | |
+ SetDParam(0, b->index); | |
GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1])); | |
} | |
int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting). | |
- if (r == 0) return (*a)->index - (*b)->index; | |
- return r; | |
+ if (r == 0) return a->index < b->index; | |
+ return r < 0; | |
} | |
/** | |
diff --git a/src/highscore.cpp b/src/highscore.cpp | |
index 86e4f5ae8..57bb2e9f3 100644 | |
--- a/src/highscore.cpp | |
+++ b/src/highscore.cpp | |
@@ -10,6 +10,9 @@ | |
/** @file highscore.cpp Definition of functions used for highscore handling */ | |
#include "stdafx.h" | |
+ | |
+#include <algorithm> | |
+ | |
#include "highscore.h" | |
#include "company_base.h" | |
#include "company_func.h" | |
@@ -17,7 +20,6 @@ | |
#include "string_func.h" | |
#include "strings_func.h" | |
#include "table/strings.h" | |
-#include "core/sort_func.hpp" | |
#include "debug.h" | |
#include "safeguards.h" | |
@@ -79,9 +81,9 @@ int8 SaveHighScoreValue(const Company *c) | |
} | |
/** Sort all companies given their performance */ | |
-static int CDECL HighScoreSorter(const Company * const *a, const Company * const *b) | |
+static bool CDECL HighScoreSorter(const Company * const &a, const Company * const &b) | |
{ | |
- return (*b)->old_economy[0].performance_history - (*a)->old_economy[0].performance_history; | |
+ return b->old_economy[0].performance_history < a->old_economy[0].performance_history; | |
} | |
/** | |
@@ -98,7 +100,7 @@ int8 SaveHighScoreValueNetwork() | |
/* Sort all active companies with the highest score first */ | |
FOR_ALL_COMPANIES(c) cl[count++] = c; | |
- QSortT(cl, count, &HighScoreSorter); | |
+ std::sort(cl, cl + count, &HighScoreSorter); | |
{ | |
uint i; | |
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp | |
index 41b3c573f..9849ef4cc 100644 | |
--- a/src/industry_gui.cpp | |
+++ b/src/industry_gui.cpp | |
@@ -160,20 +160,20 @@ static inline void GetAllCargoSuffixes(uint cb_offset, CargoSuffixType cst, cons | |
IndustryType _sorted_industry_types[NUM_INDUSTRYTYPES]; ///< Industry types sorted by name. | |
/** Sort industry types by their name. */ | |
-static int CDECL IndustryTypeNameSorter(const IndustryType *a, const IndustryType *b) | |
+static bool CDECL 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); | |
} | |
/** | |
@@ -187,7 +187,7 @@ void SortIndustryTypes() | |
} | |
/* Sort industry types by name. */ | |
- QSortT(_sorted_industry_types, NUM_INDUSTRYTYPES, &IndustryTypeNameSorter); | |
+ std::sort(std::begin(_sorted_industry_types), std::end(_sorted_industry_types), IndustryTypeNameSorter); | |
} | |
/** | |
@@ -1201,52 +1201,50 @@ protected: | |
} | |
/** Sort industries by name */ | |
- static int CDECL IndustryNameSorter(const Industry * const *a, const Industry * const *b) | |
+ static bool CDECL 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 CDECL 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++; | |
- int r = it_a - it_b; | |
- return (r == 0) ? IndustryNameSorter(a, b) : r; | |
+ while (it_b != NUM_INDUSTRYTYPES && b->type != _sorted_industry_types[it_b]) it_b++; | |
+ return (it_a == it_b) ? IndustryNameSorter(a, b) : it_a < it_b; | |
} | |
/** Sort industries by production and name */ | |
- static int CDECL IndustryProductionSorter(const Industry * const *a, const Industry * const *b) | |
+ static bool CDECL 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 (prod_a == prod_b) ? IndustryTypeSorter(a, b) : prod_a < prod_b; | |
} | |
/** Sort industries by transported cargo and name */ | |
- static int CDECL IndustryTransportedCargoSorter(const Industry * const *a, const Industry * const *b) | |
+ static bool CDECL IndustryTransportedCargoSorter(const Industry * const &a, const Industry * const &b) | |
{ | |
- int r = GetCargoTransportedSortValue(*a) - GetCargoTransportedSortValue(*b); | |
- return (r == 0) ? IndustryNameSorter(a, b) : r; | |
+ int va = GetCargoTransportedSortValue(a); | |
+ int vb = GetCargoTransportedSortValue(b); | |
+ return (va == vb) ? IndustryNameSorter(a, b) : va < vb; | |
} | |
/** | |
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp | |
index 4b1332c58..67e775d61 100644 | |
--- a/src/network/network_content_gui.cpp | |
+++ b/src/network/network_content_gui.cpp | |
@@ -407,28 +407,26 @@ class NetworkContentListWindow : public Window, ContentCallback { | |
} | |
/** Sort content by name. */ | |
- static int CDECL NameSorter(const ContentInfo * const *a, const ContentInfo * const *b) | |
+ static bool CDECL NameSorter(const ContentInfo * const &a, const ContentInfo * const &b) | |
{ | |
- return strnatcmp((*a)->name, (*b)->name, true); // Sort by name (natural sorting). | |
+ return strnatcmp(a->name, b->name, true) < 0; // Sort by name (natural sorting). | |
} | |
/** Sort content by type. */ | |
- static int CDECL TypeSorter(const ContentInfo * const *a, const ContentInfo * const *b) | |
+ static bool CDECL TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b) | |
{ | |
int r = 0; | |
- if ((*a)->type != (*b)->type) { | |
- r = strnatcmp(content_type_strs[(*a)->type], content_type_strs[(*b)->type]); | |
+ if (a->type != b->type) { | |
+ r = strnatcmp(content_type_strs[a->type], content_type_strs[b->type]); | |
} | |
- if (r == 0) r = NameSorter(a, b); | |
- return r; | |
+ if (r == 0) return NameSorter(a, b); | |
+ return r < 0; | |
} | |
/** Sort content by state. */ | |
- static int CDECL StateSorter(const ContentInfo * const *a, const ContentInfo * const *b) | |
+ static bool CDECL StateSorter(const ContentInfo * const &a, const ContentInfo * const &b) | |
{ | |
- int r = (*a)->state - (*b)->state; | |
- if (r == 0) r = TypeSorter(a, b); | |
- return r; | |
+ return (a->state == b->state) ? TypeSorter(a, b) : a->state < b->state; | |
} | |
/** Sort the content list */ | |
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp | |
index 3e4a4b050..57d3eb89d 100644 | |
--- a/src/network/network_gui.cpp | |
+++ b/src/network/network_gui.cpp | |
@@ -74,7 +74,7 @@ void SortNetworkLanguages() | |
} | |
/* Sort the strings (we don't move 'any' and the 'invalid' one) */ | |
- QSortT(_language_dropdown + 1, NETLANG_COUNT - 1, &StringIDSorter); | |
+ std::sort(_language_dropdown + 1, _language_dropdown + NETLANG_COUNT - 1, &StringIDSorter); | |
} | |
/** | |
@@ -276,10 +276,10 @@ protected: | |
} | |
/** Sort servers by name. */ | |
- static int CDECL NGameNameSorter(NetworkGameList * const *a, NetworkGameList * const *b) | |
+ static bool CDECL NGameNameSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
- int r = strnatcmp((*a)->info.server_name, (*b)->info.server_name, true); // Sort by name (natural sorting). | |
- return r == 0 ? (*a)->address.CompareTo((*b)->address) : r; | |
+ int r = strnatcmp(a->info.server_name, b->info.server_name, true); // Sort by name (natural sorting). | |
+ return r == 0 ? a->address.CompareTo(b->address) < 0 : r < 0; | |
} | |
/** | |
@@ -287,60 +287,59 @@ protected: | |
* server. If the two servers have the same amount, the one with the | |
* higher maximum is preferred. | |
*/ | |
- static int CDECL NGameClientSorter(NetworkGameList * const *a, NetworkGameList * const *b) | |
+ static bool CDECL NGameClientSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
/* Reverse as per default we are interested in most-clients first */ | |
- int r = (*a)->info.clients_on - (*b)->info.clients_on; | |
+ const NetworkGameInfo *gia = &a->info; | |
+ const NetworkGameInfo *gib = &b->info; | |
- if (r == 0) r = (*a)->info.clients_max - (*b)->info.clients_max; | |
- if (r == 0) r = NGameNameSorter(a, b); | |
- | |
- return r; | |
+ if (gia->clients_on != gib->clients_on) return gia->clients_on < gib->clients_on; | |
+ if (gia->clients_max != gib->clients_max) return gia->clients_max < gib->clients_max; | |
+ return NGameNameSorter(a, b); | |
} | |
/** Sort servers by map size */ | |
- static int CDECL NGameMapSizeSorter(NetworkGameList * const *a, NetworkGameList * const *b) | |
+ static bool CDECL NGameMapSizeSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
/* Sort by the area of the map. */ | |
- int r = ((*a)->info.map_height) * ((*a)->info.map_width) - ((*b)->info.map_height) * ((*b)->info.map_width); | |
+ int va = a->info.map_height * a->info.map_width; | |
+ int vb = b->info.map_height * b->info.map_width; | |
- if (r == 0) r = (*a)->info.map_width - (*b)->info.map_width; | |
- return (r != 0) ? r : NGameClientSorter(a, b); | |
+ if (va != vb) return va < vb; | |
+ if (a->info.map_width != b->info.map_width) return a->info.map_width < b->info.map_width; | |
+ return NGameClientSorter(a, b); | |
} | |
/** Sort servers by current date */ | |
- static int CDECL NGameDateSorter(NetworkGameList * const *a, NetworkGameList * const *b) | |
+ static bool CDECL NGameDateSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
- int r = (*a)->info.game_date - (*b)->info.game_date; | |
- return (r != 0) ? r : NGameClientSorter(a, b); | |
+ return a->info.game_date == b->info.game_date ? NGameClientSorter(a, b) : a->info.game_date < b->info.game_date; | |
} | |
/** Sort servers by the number of days the game is running */ | |
- static int CDECL NGameYearsSorter(NetworkGameList * const *a, NetworkGameList * const *b) | |
+ static bool CDECL NGameYearsSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
- int r = (*a)->info.game_date - (*a)->info.start_date - (*b)->info.game_date + (*b)->info.start_date; | |
- return (r != 0) ? r : NGameDateSorter(a, b); | |
+ int va = a->info.game_date - a->info.start_date; | |
+ int vb = b->info.game_date - b->info.start_date; | |
+ return va != vb ? NGameDateSorter(a, b) : va < vb; | |
} | |
/** | |
* Sort servers by joinability. If both servers are the | |
* same, prefer the non-passworded server first. | |
*/ | |
- static int CDECL NGameAllowedSorter(NetworkGameList * const *a, NetworkGameList * const *b) | |
+ static bool CDECL NGameAllowedSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
/* The servers we do not know anything about (the ones that did not reply) should be at the bottom) */ | |
- int r = StrEmpty((*a)->info.server_revision) - StrEmpty((*b)->info.server_revision); | |
- | |
+ if (StrEmpty(a->info.server_revision) != StrEmpty(b->info.server_revision)) return StrEmpty(a->info.server_revision); | |
/* Reverse default as we are interested in version-compatible clients first */ | |
- if (r == 0) r = (*b)->info.version_compatible - (*a)->info.version_compatible; | |
+ if (b->info.version_compatible != a->info.version_compatible) return b->info.version_compatible; | |
/* The version-compatible ones are then sorted with NewGRF compatible first, incompatible last */ | |
- if (r == 0) r = (*b)->info.compatible - (*a)->info.compatible; | |
+ if (b->info.compatible != a->info.compatible) return b->info.compatible; | |
/* Passworded servers should be below unpassworded servers */ | |
- if (r == 0) r = (*a)->info.use_password - (*b)->info.use_password; | |
+ if (a->info.use_password != b->info.use_password) return a->info.use_password; | |
/* Finally sort on the number of clients of the server */ | |
- if (r == 0) r = -NGameClientSorter(a, b); | |
- | |
- return r; | |
+ return !NGameClientSorter(a, b); | |
} | |
/** Sort the server list */ | |
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp | |
index 593851e28..1333a9f29 100644 | |
--- a/src/newgrf_config.cpp | |
+++ b/src/newgrf_config.cpp | |
@@ -706,17 +706,14 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const | |
} | |
/** | |
- * Simple sorter for GRFS | |
- * @param p1 the first GRFConfig * | |
- * @param p2 the second GRFConfig * | |
- * @return the same strcmp would return for the name of the NewGRF. | |
+ * Simple sorter for GRFs | |
+ * @param c1 the first GRFConfig | |
+ * @param c2 the second GRFConfig | |
+ * @return True if c1 < c2, when sorted naturally. | |
*/ | |
-static int CDECL GRFSorter(GRFConfig * const *p1, GRFConfig * const *p2) | |
+static bool CDECL GRFSorter(GRFConfig * const &c1, GRFConfig * const &c2) | |
{ | |
- const GRFConfig *c1 = *p1; | |
- const GRFConfig *c2 = *p2; | |
- | |
- return strnatcmp(c1->GetName(), c2->GetName()); | |
+ return strnatcmp(c1->GetName(), c2->GetName()) < 0; | |
} | |
/** | |
@@ -747,7 +744,7 @@ void DoScanNewGRFFiles(void *callback) | |
/* Number of files is not necessarily right */ | |
num = i; | |
- QSortT(to_sort, num, &GRFSorter); | |
+ std::sort(to_sort, to_sort + num, &GRFSorter); | |
for (i = 1; i < num; i++) { | |
to_sort[i - 1]->next = to_sort[i]; | |
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp | |
index 8dd8d545a..8ba85a9d6 100644 | |
--- a/src/newgrf_engine.cpp | |
+++ b/src/newgrf_engine.cpp | |
@@ -1232,19 +1232,19 @@ void AlterVehicleListOrder(EngineID engine, uint target) | |
* @param b right side | |
* @return comparison result | |
*/ | |
-static int CDECL EnginePreSort(const EngineID *a, const EngineID *b) | |
+static bool CDECL EnginePreSort(const EngineID &a, const EngineID &b) | |
{ | |
- const EngineIDMapping *id_a = _engine_mngr.Get(*a); | |
- const EngineIDMapping *id_b = _engine_mngr.Get(*b); | |
+ const EngineIDMapping *id_a = _engine_mngr.Get(a); | |
+ const EngineIDMapping *id_b = _engine_mngr.Get(b); | |
/* 1. Sort by engine type */ | |
- if (id_a->type != id_b->type) return (int)id_a->type - (int)id_b->type; | |
+ if (id_a->type != id_b->type) return (int)id_a->type < (int)id_b->type; | |
/* 2. Sort by scope-GRFID */ | |
- if (id_a->grfid != id_b->grfid) return id_a->grfid < id_b->grfid ? -1 : 1; | |
+ if (id_a->grfid != id_b->grfid) return id_a->grfid < id_b->grfid; | |
/* 3. Sort by local ID */ | |
- return (int)id_a->internal_id - (int)id_b->internal_id; | |
+ return (int)id_a->internal_id < (int)id_b->internal_id; | |
} | |
/** | |
@@ -1258,7 +1258,7 @@ void CommitVehicleListOrderChanges() | |
FOR_ALL_ENGINES(e) { | |
*ordering.Append() = e->index; | |
} | |
- QSortT(ordering.Begin(), ordering.Length(), EnginePreSort); | |
+ std::sort(ordering.Begin(), ordering.End(), EnginePreSort); | |
/* Apply Insertion-Sort operations */ | |
const ListOrderChange *end = _list_order_changes.End(); | |
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp | |
index c0aa160c2..2b4dcf50d 100644 | |
--- a/src/newgrf_gui.cpp | |
+++ b/src/newgrf_gui.cpp | |
@@ -1438,15 +1438,13 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { | |
private: | |
/** Sort grfs by name. */ | |
- static int CDECL NameSorter(const GRFConfig * const *a, const GRFConfig * const *b) | |
+ static bool CDECL NameSorter(const GRFConfig * const &a, const GRFConfig * const &b) | |
{ | |
- int i = strnatcmp((*a)->GetName(), (*b)->GetName(), true); // Sort by name (natural sorting). | |
- if (i != 0) return i; | |
+ int i = strnatcmp(a->GetName(), b->GetName(), true); // Sort by name (natural sorting). | |
+ if (i != 0) return i < 0; | |
- i = (*a)->version - (*b)->version; | |
- if (i != 0) return i; | |
- | |
- return memcmp((*a)->ident.md5sum, (*b)->ident.md5sum, lengthof((*b)->ident.md5sum)); | |
+ if (a->version != b->version) return a->version < b->version; | |
+ return memcmp(a->ident.md5sum, b->ident.md5sum, lengthof(b->ident.md5sum)) < 0; | |
} | |
/** Filter grfs by tags/name */ | |
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp | |
index 9f284fc30..d2494026d 100644 | |
--- a/src/rail_cmd.cpp | |
+++ b/src/rail_cmd.cpp | |
@@ -127,9 +127,9 @@ void ResolveRailTypeGUISprites(RailtypeInfo *rti) | |
* @param second The railtype to compare. | |
* @return True iff the first should be sorted before the second. | |
*/ | |
-static int CDECL CompareRailTypes(const RailType *first, const RailType *second) | |
+static bool CDECL CompareRailTypes(const RailType &first, const RailType &second) | |
{ | |
- return GetRailTypeInfo(*first)->sorting_order - GetRailTypeInfo(*second)->sorting_order; | |
+ return GetRailTypeInfo(first)->sorting_order < GetRailTypeInfo(second)->sorting_order; | |
} | |
/** | |
@@ -148,7 +148,7 @@ void InitRailTypes() | |
_sorted_railtypes[_sorted_railtypes_size++] = rt; | |
} | |
} | |
- QSortT(_sorted_railtypes, _sorted_railtypes_size, CompareRailTypes); | |
+ std::sort(_sorted_railtypes, _sorted_railtypes + _sorted_railtypes_size, CompareRailTypes); | |
} | |
/** | |
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp | |
index 0420ba15b..6fe5f592d 100644 | |
--- a/src/settings_gui.cpp | |
+++ b/src/settings_gui.cpp | |
@@ -201,7 +201,7 @@ struct GameOptionsWindow : Window { | |
if (i == CURRENCY_CUSTOM) continue; | |
*list->Append() = new DropDownListStringItem(*items, i, HasBit(disabled, i)); | |
} | |
- QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc); | |
+ std::sort(list->Begin(), list->End(), DropDownListStringItem::NatSortFunc); | |
/* Append custom currency at the end */ | |
*list->Append() = new DropDownListItem(-1, false); // separator line | |
@@ -239,7 +239,7 @@ struct GameOptionsWindow : Window { | |
int result = _nb_orig_names + i; | |
*list->Append() = new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0); | |
} | |
- QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc); | |
+ std::sort(list->Begin(), list->End(), DropDownListStringItem::NatSortFunc); | |
int newgrf_size = list->Length(); | |
/* Insert newgrf_names at the top of the list */ | |
@@ -252,7 +252,7 @@ struct GameOptionsWindow : Window { | |
for (int i = 0; i < _nb_orig_names; i++) { | |
*list->Append() = new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0); | |
} | |
- QSortT(list->Begin() + newgrf_size, list->Length() - newgrf_size, DropDownListStringItem::NatSortFunc); | |
+ std::sort(list->Begin() + newgrf_size, list->End(), DropDownListStringItem::NatSortFunc); | |
break; | |
} | |
@@ -272,7 +272,7 @@ struct GameOptionsWindow : Window { | |
if (&_languages[i] == _current_language) *selected_index = i; | |
*list->Append() = new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false); | |
} | |
- QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc); | |
+ std::sort(list->Begin(), list->End(), DropDownListStringItem::NatSortFunc); | |
break; | |
} | |
diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp | |
index 15adef089..22b9c941f 100644 | |
--- a/src/signs_gui.cpp | |
+++ b/src/signs_gui.cpp | |
@@ -72,23 +72,22 @@ struct SignList { | |
} | |
/** Sort signs by their name */ | |
- static int CDECL SignNameSorter(const Sign * const *a, const Sign * const *b) | |
+ static bool CDECL SignNameSorter(const Sign * const &a, const Sign * const &b) | |
{ | |
static char buf_cache[64]; | |
char buf[64]; | |
- SetDParam(0, (*a)->index); | |
+ SetDParam(0, a->index); | |
GetString(buf, STR_SIGN_NAME, lastof(buf)); | |
- if (*b != last_sign) { | |
- last_sign = *b; | |
- SetDParam(0, (*b)->index); | |
+ if (b != last_sign) { | |
+ last_sign = b; | |
+ SetDParam(0, b->index); | |
GetString(buf_cache, STR_SIGN_NAME, lastof(buf_cache)); | |
} | |
int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting). | |
- | |
- return r != 0 ? r : ((*a)->index - (*b)->index); | |
+ return r != 0 ? r < 0 : a->index < b->index; | |
} | |
void SortSignsList() | |
diff --git a/src/sortlist_type.h b/src/sortlist_type.h | |
index 1a30c3b1a..95af651c9 100644 | |
--- a/src/sortlist_type.h | |
+++ b/src/sortlist_type.h | |
@@ -12,9 +12,11 @@ | |
#ifndef SORTLIST_TYPE_H | |
#define SORTLIST_TYPE_H | |
+#include <algorithm> | |
+#include <functional> | |
+ | |
#include "core/enum_type.hpp" | |
#include "core/bitmath_func.hpp" | |
-#include "core/sort_func.hpp" | |
#include "core/smallvec_type.hpp" | |
#include "date_type.h" | |
@@ -41,6 +43,44 @@ struct Filtering { | |
byte criteria; ///< Filtering criteria | |
}; | |
+/** | |
+ * An functor object that negates the return value of a binary function. | |
+ * Approximately equal to C++17s std::not_fn | |
+ * @tparam F Function type to negate. | |
+ * @tparam T Argument type, passed to F. | |
+ */ | |
+template <typename F, typename T> | |
+struct BinNegator { | |
+ /** | |
+ * Constructor. | |
+ * @param f Function pointer to negate. | |
+ */ | |
+ BinNegator(F *f) : f(f) {} | |
+ | |
+ /** | |
+ * Binary call operator. Actually does the operation. | |
+ * @param a First operand. | |
+ * @param b Second operand. | |
+ * @return Inverse result of f. | |
+ */ | |
+ bool operator()(const T &a, const T &b) | |
+ { | |
+ return !f(a, b); | |
+ }; | |
+ | |
+ /** | |
+ * Constructor function. | |
+ * @param f Function to be negated. | |
+ * @return Negated functor. | |
+ */ | |
+ static BinNegator<F, T> Make(F *f) | |
+ { | |
+ return BinNegator<F, T>(f); | |
+ } | |
+ | |
+ F *f; | |
+}; | |
+ | |
/** | |
* List template of 'things' \p T to sort in a GUI. | |
* @tparam T Type of data stored in the list to represent each item. | |
@@ -49,8 +89,8 @@ struct Filtering { | |
template <typename T, typename F = const char*> | |
class GUIList : public SmallVector<T, 32> { | |
public: | |
- typedef int CDECL SortFunction(const T*, const T*); ///< Signature of sort function. | |
- typedef bool CDECL FilterFunction(const T*, F); ///< Signature of filter function. | |
+ typedef bool CDECL SortFunction(const T&, const T&); ///< Signature of sort function. | |
+ typedef bool CDECL FilterFunction(const T*, F); ///< Signature of filter function. | |
protected: | |
SortFunction * const *sort_func_list; ///< the sort criteria functions | |
@@ -265,16 +305,12 @@ public: | |
/* Do not sort when the list is not sortable */ | |
if (!this->IsSortable()) return false; | |
- const bool desc = (this->flags & VL_DESC) != 0; | |
- | |
if (this->flags & VL_FIRST_SORT) { | |
CLRBITS(this->flags, VL_FIRST_SORT); | |
- | |
- QSortT(this->data, this->items, compare, desc); | |
- return true; | |
} | |
- GSortT(this->data, this->items, compare, desc); | |
+ std::sort(this->Begin(), this->End(), compare); | |
+ if ((this->flags & VL_DESC) != 0) std::reverse(this->Begin(), this->End()); | |
return true; | |
} | |
diff --git a/src/station_gui.cpp b/src/station_gui.cpp | |
index aa2017018..74a5fbb4e 100644 | |
--- a/src/station_gui.cpp | |
+++ b/src/station_gui.cpp | |
@@ -209,85 +209,84 @@ protected: | |
} | |
/** Sort stations by their name */ | |
- static int CDECL StationNameSorter(const Station * const *a, const Station * const *b) | |
+ static bool CDECL StationNameSorter(const Station * const &a, const Station * const &b) | |
{ | |
static char buf_cache[64]; | |
char buf[64]; | |
- SetDParam(0, (*a)->index); | |
+ SetDParam(0, a->index); | |
GetString(buf, STR_STATION_NAME, lastof(buf)); | |
- if (*b != last_station) { | |
- last_station = *b; | |
- SetDParam(0, (*b)->index); | |
+ if (b != last_station) { | |
+ last_station = b; | |
+ SetDParam(0, b->index); | |
GetString(buf_cache, STR_STATION_NAME, lastof(buf_cache)); | |
} | |
int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting). | |
- if (r == 0) return (*a)->index - (*b)->index; | |
- return r; | |
+ return r == 0 ? a->index < b->index : r < 0; | |
} | |
/** Sort stations by their type */ | |
- static int CDECL StationTypeSorter(const Station * const *a, const Station * const *b) | |
+ static bool CDECL StationTypeSorter(const Station * const &a, const Station * const &b) | |
{ | |
- return (*a)->facilities - (*b)->facilities; | |
+ return a->facilities < b->facilities; | |
} | |
/** Sort stations by their waiting cargo */ | |
- static int CDECL StationWaitingTotalSorter(const Station * const *a, const Station * const *b) | |
+ static bool CDECL StationWaitingTotalSorter(const Station * const &a, const Station * const &b) | |
{ | |
- int diff = 0; | |
+ int totala = 0; | |
+ int totalb = 0; | |
CargoID j; | |
FOR_EACH_SET_CARGO_ID(j, cargo_filter) { | |
- diff += (*a)->goods[j].cargo.TotalCount() - (*b)->goods[j].cargo.TotalCount(); | |
+ totala += a->goods[j].cargo.TotalCount(); | |
+ totalb += b->goods[j].cargo.TotalCount(); | |
} | |
- | |
- return diff; | |
+ return totala < totalb; | |
} | |
/** Sort stations by their available waiting cargo */ | |
- static int CDECL StationWaitingAvailableSorter(const Station * const *a, const Station * const *b) | |
+ static bool CDECL StationWaitingAvailableSorter(const Station * const &a, const Station * const &b) | |
{ | |
- int diff = 0; | |
+ int totala = 0; | |
+ int totalb = 0; | |
CargoID j; | |
FOR_EACH_SET_CARGO_ID(j, cargo_filter) { | |
- diff += (*a)->goods[j].cargo.AvailableCount() - (*b)->goods[j].cargo.AvailableCount(); | |
+ totala += a->goods[j].cargo.AvailableCount(); | |
+ totalb += b->goods[j].cargo.AvailableCount(); | |
} | |
- | |
- return diff; | |
+ return totala < totalb; | |
} | |
/** Sort stations by their rating */ | |
- static int CDECL StationRatingMaxSorter(const Station * const *a, const Station * const *b) | |
+ static bool CDECL StationRatingMaxSorter(const Station * const &a, const Station * const &b) | |
{ | |
byte maxr1 = 0; | |
byte maxr2 = 0; | |
CargoID j; | |
FOR_EACH_SET_CARGO_ID(j, cargo_filter) { | |
- if ((*a)->goods[j].HasRating()) maxr1 = max(maxr1, (*a)->goods[j].rating); | |
- if ((*b)->goods[j].HasRating()) maxr2 = max(maxr2, (*b)->goods[j].rating); | |
+ if (a->goods[j].HasRating()) maxr1 = max(maxr1, a->goods[j].rating); | |
+ if (b->goods[j].HasRating()) maxr2 = max(maxr2, b->goods[j].rating); | |
} | |
- | |
- return maxr1 - maxr2; | |
+ return maxr1 < maxr2; | |
} | |
/** Sort stations by their rating */ | |
- static int CDECL StationRatingMinSorter(const Station * const *a, const Station * const *b) | |
+ static bool CDECL StationRatingMinSorter(const Station * const &a, const Station * const &b) | |
{ | |
byte minr1 = 255; | |
byte minr2 = 255; | |
for (CargoID j = 0; j < NUM_CARGO; j++) { | |
if (!HasBit(cargo_filter, j)) continue; | |
- if ((*a)->goods[j].HasRating()) minr1 = min(minr1, (*a)->goods[j].rating); | |
- if ((*b)->goods[j].HasRating()) minr2 = min(minr2, (*b)->goods[j].rating); | |
+ if (a->goods[j].HasRating()) minr1 = min(minr1, a->goods[j].rating); | |
+ if (b->goods[j].HasRating()) minr2 = min(minr2, b->goods[j].rating); | |
} | |
- | |
- return -(minr1 - minr2); | |
+ return minr2 < minr1; // Inverse | |
} | |
/** Sort the stations list */ | |
diff --git a/src/story_gui.cpp b/src/story_gui.cpp | |
index 003843310..2ee00225c 100644 | |
--- a/src/story_gui.cpp | |
+++ b/src/story_gui.cpp | |
@@ -69,9 +69,9 @@ protected: | |
} | |
/** Sort story pages by order value. */ | |
- static int CDECL PageOrderSorter(const StoryPage * const *a, const StoryPage * const *b) | |
+ static bool CDECL PageOrderSorter(const StoryPage * const &a, const StoryPage * const &b) | |
{ | |
- return (*a)->sort_value - (*b)->sort_value; | |
+ return a->sort_value < b->sort_value; | |
} | |
/** (Re)Build story page element list. */ | |
@@ -98,9 +98,9 @@ protected: | |
} | |
/** Sort story page elements by order value. */ | |
- static int CDECL PageElementOrderSorter(const StoryPageElement * const *a, const StoryPageElement * const *b) | |
+ static bool CDECL PageElementOrderSorter(const StoryPageElement * const &a, const StoryPageElement * const &b) | |
{ | |
- return (*a)->sort_value - (*b)->sort_value; | |
+ return a->sort_value < b->sort_value; | |
} | |
/* | |
diff --git a/src/strings.cpp b/src/strings.cpp | |
index 1c539d934..476a9095d 100644 | |
--- a/src/strings.cpp | |
+++ b/src/strings.cpp | |
@@ -1857,14 +1857,14 @@ const char *GetCurrentLocale(const char *param) | |
const char *GetCurrentLocale(const char *param); | |
#endif /* !(defined(WIN32) || defined(__APPLE__)) */ | |
-int CDECL StringIDSorter(const StringID *a, const StringID *b) | |
+bool CDECL StringIDSorter(const StringID &a, const StringID &b) | |
{ | |
char stra[512]; | |
char strb[512]; | |
- GetString(stra, *a, lastof(stra)); | |
- GetString(strb, *b, lastof(strb)); | |
+ GetString(stra, a, lastof(stra)); | |
+ GetString(strb, b, lastof(strb)); | |
- return strnatcmp(stra, strb); | |
+ return strnatcmp(stra, strb) < 0; | |
} | |
/** | |
diff --git a/src/strings_func.h b/src/strings_func.h | |
index 0da711bc4..4d17a5462 100644 | |
--- a/src/strings_func.h | |
+++ b/src/strings_func.h | |
@@ -238,7 +238,7 @@ extern TextDirection _current_text_dir; ///< Text direction of the currently sel | |
void InitializeLanguagePacks(); | |
const char *GetCurrentLanguageIsoCode(); | |
-int CDECL StringIDSorter(const StringID *a, const StringID *b); | |
+bool CDECL StringIDSorter(const StringID &a, const StringID &b); | |
/** | |
* A searcher for missing glyphs. | |
diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp | |
index 29986c353..7f44520be 100644 | |
--- a/src/timetable_cmd.cpp | |
+++ b/src/timetable_cmd.cpp | |
@@ -16,7 +16,6 @@ | |
#include "window_func.h" | |
#include "vehicle_base.h" | |
#include "cmd_helper.h" | |
-#include "core/sort_func.hpp" | |
#include "table/strings.h" | |
@@ -215,16 +214,12 @@ CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, | |
/** | |
* Order vehicles based on their timetable. The vehicles will be sorted in order | |
* they would reach the first station. | |
- * | |
- * @param ap First Vehicle pointer. | |
- * @param bp Second Vehicle pointer. | |
+ * @param a First Vehicle. | |
+ * @param b Second Vehicle. | |
* @return Comparison value. | |
*/ | |
-static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp) | |
+static bool CDECL VehicleTimetableSorter(Vehicle * const &a, Vehicle * const &b) | |
{ | |
- const Vehicle *a = *ap; | |
- const Vehicle *b = *bp; | |
- | |
VehicleOrderID a_order = a->cur_real_order_index; | |
VehicleOrderID b_order = b->cur_real_order_index; | |
int j = (int)b_order - (int)a_order; | |
@@ -242,15 +237,15 @@ static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp | |
/* First check the order index that accounted for loading, then just the raw one. */ | |
int i = (int)b_order - (int)a_order; | |
- if (i != 0) return i; | |
- if (j != 0) return j; | |
+ if (i != 0) return i < 0; | |
+ if (j != 0) return j < 0; | |
/* Look at the time we spent in this order; the higher, the closer to its destination. */ | |
i = b->current_order_time - a->current_order_time; | |
- if (i != 0) return i; | |
+ if (i != 0) return i < 0; | |
/* If all else is equal, use some unique index to sort it the same way. */ | |
- return b->unitnumber - a->unitnumber; | |
+ return b->unitnumber < a->unitnumber; | |
} | |
/** | |
@@ -295,7 +290,7 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1, | |
int num_vehs = vehs.Length(); | |
if (num_vehs >= 2) { | |
- QSortT(vehs.Begin(), vehs.Length(), &VehicleTimetableSorter); | |
+ std::sort(vehs.Begin(), vehs.End(), &VehicleTimetableSorter); | |
} | |
int base = vehs.FindIndex(v); | |
diff --git a/src/town_gui.cpp b/src/town_gui.cpp | |
index 696b71afd..da54ef23a 100644 | |
--- a/src/town_gui.cpp | |
+++ b/src/town_gui.cpp | |
@@ -667,54 +667,46 @@ private: | |
} | |
/** Sort by town name */ | |
- static int CDECL TownNameSorter(const Town * const *a, const Town * const *b) | |
+ static bool CDECL TownNameSorter(const Town * const &a, const Town * const &b) | |
{ | |
static char buf_cache[64]; | |
- const Town *ta = *a; | |
- const Town *tb = *b; | |
char buf[64]; | |
- SetDParam(0, ta->index); | |
+ SetDParam(0, a->index); | |
GetString(buf, STR_TOWN_NAME, lastof(buf)); | |
- /* If 'b' is the same town as in the last round, use the cached value | |
- * We do this to speed stuff up ('b' is called with the same value a lot of | |
+ /* If b is the same town as in the last round, use the cached value | |
+ * We do this to speed stuff up (b is called with the same value a lot of | |
* times after each other) */ | |
- if (tb != last_town) { | |
- last_town = tb; | |
- SetDParam(0, tb->index); | |
+ if (b != last_town) { | |
+ last_town = b; | |
+ SetDParam(0, b->index); | |
GetString(buf_cache, STR_TOWN_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 by population (default descending, as big towns are of the most interest). */ | |
- static int CDECL TownPopulationSorter(const Town * const *a, const Town * const *b) | |
+ static bool CDECL TownPopulationSorter(const Town * const &a, const Town * const &b) | |
{ | |
- uint32 a_population = (*a)->cache.population; | |
- uint32 b_population = (*b)->cache.population; | |
+ uint32 a_population = a->cache.population; | |
+ uint32 b_population = b->cache.population; | |
if (a_population == b_population) return TownDirectoryWindow::TownNameSorter(a, b); | |
- return (a_population < b_population) ? -1 : 1; | |
+ return a_population < b_population; | |
} | |
/** Sort by town rating */ | |
- static int CDECL TownRatingSorter(const Town * const *a, const Town * const *b) | |
+ static bool CDECL TownRatingSorter(const Town * const &a, const Town * const &b) | |
{ | |
- int before = TownDirectoryWindow::last_sorting.order ? 1 : -1; // Value to get 'a' before 'b'. | |
- | |
- /* Towns without rating are always after towns with rating. */ | |
- if (HasBit((*a)->have_ratings, _local_company)) { | |
- if (HasBit((*b)->have_ratings, _local_company)) { | |
- int16 a_rating = (*a)->ratings[_local_company]; | |
- int16 b_rating = (*b)->ratings[_local_company]; | |
- if (a_rating == b_rating) return TownDirectoryWindow::TownNameSorter(a, b); | |
- return (a_rating < b_rating) ? -1 : 1; | |
- } | |
- return before; | |
- } | |
- if (HasBit((*b)->have_ratings, _local_company)) return -before; | |
- return -before * TownDirectoryWindow::TownNameSorter(a, b); // Sort unrated towns always on ascending town name. | |
+ bool before = !TownDirectoryWindow::last_sorting.order; // Value to get 'a' before 'b'. | |
+ | |
+ int16 a_rating = HasBit(a->have_ratings, _local_company) ? a->ratings[_local_company] : INT16_MIN; // Value that is < RATING_MINIMUM | |
+ int16 b_rating = HasBit(b->have_ratings, _local_company) ? b->ratings[_local_company] : INT16_MIN; | |
+ if (a_rating == INT16_MIN) return !before; | |
+ if (b_rating == INT16_MIN) return before; | |
+ if (a_rating != b_rating) return a_rating < b_rating; | |
+ return TownDirectoryWindow::TownNameSorter(a, b); // Sort unrated towns always on ascending town name. | |
} | |
public: | |
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp | |
index 8ebd73a8a..6f49cfe7a 100644 | |
--- a/src/vehicle_gui.cpp | |
+++ b/src/vehicle_gui.cpp | |
@@ -194,7 +194,7 @@ void BaseVehicleListWindow::SortVehicleList() | |
void DepotSortList(VehicleList *list) | |
{ | |
if (list->Length() < 2) return; | |
- QSortT(list->Begin(), list->Length(), &VehicleNumberSorter); | |
+ std::sort(list->Begin(), list->End(), &VehicleNumberSorter); | |
} | |
/** draw the vehicle profit button in the vehicle list window. */ | |
@@ -1085,62 +1085,63 @@ StringID GetCargoSubtypeText(const Vehicle *v) | |
} | |
/** Sort vehicles by their number */ | |
-static int CDECL VehicleNumberSorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleNumberSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
- return (*a)->unitnumber - (*b)->unitnumber; | |
+ return a->unitnumber < b->unitnumber; | |
} | |
/** Sort vehicles by their name */ | |
-static int CDECL VehicleNameSorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleNameSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
static char last_name[2][64]; | |
- if (*a != _last_vehicle[0]) { | |
- _last_vehicle[0] = *a; | |
- SetDParam(0, (*a)->index); | |
+ if (a != _last_vehicle[0]) { | |
+ _last_vehicle[0] = a; | |
+ SetDParam(0, a->index); | |
GetString(last_name[0], STR_VEHICLE_NAME, lastof(last_name[0])); | |
} | |
- if (*b != _last_vehicle[1]) { | |
- _last_vehicle[1] = *b; | |
- SetDParam(0, (*b)->index); | |
+ if (b != _last_vehicle[1]) { | |
+ _last_vehicle[1] = b; | |
+ SetDParam(0, b->index); | |
GetString(last_name[1], STR_VEHICLE_NAME, lastof(last_name[1])); | |
} | |
int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting). | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ return (r != 0) ? r < 0 : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by their age */ | |
-static int CDECL VehicleAgeSorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleAgeSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
- int r = (*a)->age - (*b)->age; | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ return a->age != b->age ? a->age < b->age : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by this year profit */ | |
-static int CDECL VehicleProfitThisYearSorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleProfitThisYearSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
- int r = ClampToI32((*a)->GetDisplayProfitThisYear() - (*b)->GetDisplayProfitThisYear()); | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ int va = a->GetDisplayProfitThisYear(); | |
+ int vb = b->GetDisplayProfitThisYear(); | |
+ return va != vb ? va < vb : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by last year profit */ | |
-static int CDECL VehicleProfitLastYearSorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleProfitLastYearSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
- int r = ClampToI32((*a)->GetDisplayProfitLastYear() - (*b)->GetDisplayProfitLastYear()); | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ int va = a->GetDisplayProfitLastYear(); | |
+ int vb = b->GetDisplayProfitLastYear(); | |
+ return va != vb ? va < vb : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by their cargo */ | |
-static int CDECL VehicleCargoSorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleCargoSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
const Vehicle *v; | |
CargoArray diff; | |
/* Append the cargo of the connected waggons */ | |
- for (v = *a; v != NULL; v = v->Next()) diff[v->cargo_type] += v->cargo_cap; | |
- for (v = *b; v != NULL; v = v->Next()) diff[v->cargo_type] -= v->cargo_cap; | |
+ for (v = a; v != NULL; v = v->Next()) diff[v->cargo_type] += v->cargo_cap; | |
+ for (v = b; v != NULL; v = v->Next()) diff[v->cargo_type] -= v->cargo_cap; | |
int r = 0; | |
for (CargoID i = 0; i < NUM_CARGO; i++) { | |
@@ -1148,62 +1149,62 @@ static int CDECL VehicleCargoSorter(const Vehicle * const *a, const Vehicle * co | |
if (r != 0) break; | |
} | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ return (r != 0) ? r < 0 : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by their reliability */ | |
-static int CDECL VehicleReliabilitySorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleReliabilitySorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
- int r = (*a)->reliability - (*b)->reliability; | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ return a->reliability != b->reliability ? a->reliability < b->reliability : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by their max speed */ | |
-static int CDECL VehicleMaxSpeedSorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleMaxSpeedSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
- int r = (*a)->vcache.cached_max_speed - (*b)->vcache.cached_max_speed; | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ int va = a->vcache.cached_max_speed; | |
+ int vb = b->vcache.cached_max_speed; | |
+ return va != vb ? va < vb : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by model */ | |
-static int CDECL VehicleModelSorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleModelSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
- int r = (*a)->engine_type - (*b)->engine_type; | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ return a->engine_type != b->engine_type ? a->engine_type < b->engine_type : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by their value */ | |
-static int CDECL VehicleValueSorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleValueSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
const Vehicle *u; | |
Money diff = 0; | |
- for (u = *a; u != NULL; u = u->Next()) diff += u->value; | |
- for (u = *b; u != NULL; u = u->Next()) diff -= u->value; | |
+ for (u = a; u != NULL; u = u->Next()) diff += u->value; | |
+ for (u = b; u != NULL; u = u->Next()) diff -= u->value; | |
int r = ClampToI32(diff); | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ return (r != 0) ? r < 0 : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by their length */ | |
-static int CDECL VehicleLengthSorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleLengthSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
- int r = (*a)->GetGroundVehicleCache()->cached_total_length - (*b)->GetGroundVehicleCache()->cached_total_length; | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ int va = a->GetGroundVehicleCache()->cached_total_length; | |
+ int vb = b->GetGroundVehicleCache()->cached_total_length; | |
+ return va != vb ? va < vb : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by the time they can still live */ | |
-static int CDECL VehicleTimeToLiveSorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleTimeToLiveSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
- int r = ClampToI32(((*a)->max_age - (*a)->age) - ((*b)->max_age - (*b)->age)); | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ int va = a->max_age - a->age; | |
+ int vb = b->max_age - b->age; | |
+ return va != vb ? va < vb : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by the timetable delay */ | |
-static int CDECL VehicleTimetableDelaySorter(const Vehicle * const *a, const Vehicle * const *b) | |
+static bool CDECL VehicleTimetableDelaySorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
- int r = (*a)->lateness_counter - (*b)->lateness_counter; | |
- return (r != 0) ? r : VehicleNumberSorter(a, b); | |
+ return a->lateness_counter != b->lateness_counter ? a->lateness_counter < b->lateness_counter : VehicleNumberSorter(a, b); | |
} | |
void InitializeGUI() | |
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm | |
index 4df7cb003..037a7e798 100644 | |
--- a/src/video/cocoa/cocoa_v.mm | |
+++ b/src/video/cocoa/cocoa_v.mm | |
@@ -36,6 +36,7 @@ | |
#include "../../window_func.h" | |
#include "../../window_gui.h" | |
+#import <algorithm> | |
#import <sys/param.h> /* for MAXPATHLEN */ | |
/** | |
@@ -226,13 +227,9 @@ static void setupApplication() | |
} | |
-static int CDECL ModeSorter(const OTTD_Point *p1, const OTTD_Point *p2) | |
+static bool CDECL ModeSorter(const OTTD_Point &p1, const OTTD_Point &p2) | |
{ | |
- if (p1->x < p2->x) return -1; | |
- if (p1->x > p2->x) return +1; | |
- if (p1->y < p2->y) return -1; | |
- if (p1->y > p2->y) return +1; | |
- return 0; | |
+ return p1.x < p2.x || (p1.x == p2.x && p1.y < p2.y); | |
} | |
uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int device_depth) | |
@@ -278,7 +275,7 @@ uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_i | |
} | |
/* Sort list smallest to largest */ | |
- QSortT(modes, count, &ModeSorter); | |
+ std::sort(modes, modes + count, &ModeSorter); | |
return count; | |
} | |
diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp | |
index d4c229cb1..7f5fce130 100644 | |
--- a/src/widgets/dropdown.cpp | |
+++ b/src/widgets/dropdown.cpp | |
@@ -50,12 +50,12 @@ void DropDownListStringItem::Draw(int left, int right, int top, int bottom, bool | |
* @return true if \a first precedes \a second. | |
* @warning All items in the list need to be derivates of DropDownListStringItem. | |
*/ | |
-/* static */ int DropDownListStringItem::NatSortFunc(const DropDownListItem * const *first, const DropDownListItem * const * second) | |
+/* static */ bool DropDownListStringItem::NatSortFunc(const DropDownListItem * const &first, const DropDownListItem * const &second) | |
{ | |
char buffer1[512], buffer2[512]; | |
- GetString(buffer1, static_cast<const DropDownListStringItem*>(*first)->String(), lastof(buffer1)); | |
- GetString(buffer2, static_cast<const DropDownListStringItem*>(*second)->String(), lastof(buffer2)); | |
- return strnatcmp(buffer1, buffer2); | |
+ GetString(buffer1, static_cast<const DropDownListStringItem*>(first)->String(), lastof(buffer1)); | |
+ GetString(buffer2, static_cast<const DropDownListStringItem*>(second)->String(), lastof(buffer2)); | |
+ return strnatcmp(buffer1, buffer2) < 0; | |
} | |
StringID DropDownListParamStringItem::String() const | |
diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h | |
index b65d4557b..e87ea1e85 100644 | |
--- a/src/widgets/dropdown_type.h | |
+++ b/src/widgets/dropdown_type.h | |
@@ -50,7 +50,7 @@ public: | |
virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const; | |
virtual StringID String() const { return this->string; } | |
- static int CDECL NatSortFunc(const DropDownListItem * const *first, const DropDownListItem * const *second); | |
+ static bool CDECL NatSortFunc(const DropDownListItem * const &first, const DropDownListItem * const &second); | |
}; | |
/** | |
diff --git a/src/window.cpp b/src/window.cpp | |
index 6538caffd..53b1cb1dd 100644 | |
--- a/src/window.cpp | |
+++ b/src/window.cpp | |
@@ -150,10 +150,10 @@ void WindowDesc::LoadFromConfig() | |
/** | |
* Sort WindowDesc by ini_key. | |
*/ | |
-static int CDECL DescSorter(WindowDesc * const *a, WindowDesc * const *b) | |
+static bool CDECL DescSorter(WindowDesc * const &a, WindowDesc * const &b) | |
{ | |
- if ((*a)->ini_key != NULL && (*b)->ini_key != NULL) return strcmp((*a)->ini_key, (*b)->ini_key); | |
- return ((*b)->ini_key != NULL ? 1 : 0) - ((*a)->ini_key != NULL ? 1 : 0); | |
+ if (a->ini_key != NULL && b->ini_key != NULL) return strcmp(a->ini_key, b->ini_key) < 0; | |
+ return a->ini_key != NULL; | |
} | |
/** | |
@@ -162,7 +162,7 @@ static int CDECL DescSorter(WindowDesc * const *a, WindowDesc * const *b) | |
void WindowDesc::SaveToConfig() | |
{ | |
/* Sort the stuff to get a nice ini file on first write */ | |
- QSortT(_window_descs->Begin(), _window_descs->Length(), DescSorter); | |
+ std::sort(_window_descs->Begin(), _window_descs->End(), &DescSorter); | |
IniFile *ini = new IniFile(); | |
ini->LoadFromDisk(_windows_file, NO_DIRECTORY); | |
-- | |
2.14.1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From eeec2cba966e9dc3ccea2aff08632275945b90b1 Mon Sep 17 00:00:00 2001 | |
From: Charles Pigott <charlespigott@googlemail.com> | |
Date: Tue, 8 Aug 2017 20:30:43 +0100 | |
Subject: [PATCH 2/2] -Codechange: Remove useless CDECL declarations on sort | |
functions. | |
--- | |
src/autoreplace_gui.cpp | 2 +- | |
src/bridge_gui.cpp | 6 +++--- | |
src/build_vehicle_gui.cpp | 32 ++++++++++++++++---------------- | |
src/cargotype.cpp | 4 ++-- | |
src/core/smallmap_type.hpp | 2 +- | |
src/engine_gui.h | 2 +- | |
src/fios.cpp | 2 +- | |
src/fios.h | 2 +- | |
src/gfx.cpp | 2 +- | |
src/graph_gui.cpp | 2 +- | |
src/group_gui.cpp | 2 +- | |
src/highscore.cpp | 2 +- | |
src/industry_gui.cpp | 10 +++++----- | |
src/network/network_content_gui.cpp | 6 +++--- | |
src/network/network_gui.cpp | 12 ++++++------ | |
src/newgrf_config.cpp | 2 +- | |
src/newgrf_engine.cpp | 2 +- | |
src/newgrf_gui.cpp | 2 +- | |
src/rail_cmd.cpp | 2 +- | |
src/signs_gui.cpp | 2 +- | |
src/sortlist_type.h | 2 +- | |
src/station_gui.cpp | 12 ++++++------ | |
src/story_gui.cpp | 4 ++-- | |
src/strings.cpp | 2 +- | |
src/strings_func.h | 2 +- | |
src/timetable_cmd.cpp | 2 +- | |
src/town_gui.cpp | 6 +++--- | |
src/vehicle_gui.cpp | 26 +++++++++++++------------- | |
src/video/cocoa/cocoa_v.mm | 2 +- | |
src/widgets/dropdown_type.h | 2 +- | |
src/window.cpp | 2 +- | |
31 files changed, 80 insertions(+), 80 deletions(-) | |
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp | |
index 7342c1864..96ae5ff38 100644 | |
--- a/src/autoreplace_gui.cpp | |
+++ b/src/autoreplace_gui.cpp | |
@@ -32,7 +32,7 @@ | |
void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group); | |
-static bool CDECL EngineNumberSorter(const EngineID &a, const EngineID &b) | |
+static bool EngineNumberSorter(const EngineID &a, const EngineID &b) | |
{ | |
return Engine::Get(a)->list_position < Engine::Get(b)->list_position; | |
} | |
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp | |
index dfbe5d435..4a7b341f2 100644 | |
--- a/src/bridge_gui.cpp | |
+++ b/src/bridge_gui.cpp | |
@@ -93,19 +93,19 @@ private: | |
Scrollbar *vscroll; | |
/** Sort the bridges by their index */ | |
- static bool CDECL BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b) | |
+ static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b) | |
{ | |
return a.index < b.index; | |
} | |
/** Sort the bridges by their price */ | |
- static bool CDECL BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b) | |
+ static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b) | |
{ | |
return a.cost < b.cost; | |
} | |
/** Sort the bridges by their maximum speed */ | |
- static bool CDECL BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b) | |
+ static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b) | |
{ | |
return a.spec->speed < b.spec->speed; | |
} | |
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp | |
index 22a09afa6..402300892 100644 | |
--- a/src/build_vehicle_gui.cpp | |
+++ b/src/build_vehicle_gui.cpp | |
@@ -103,7 +103,7 @@ static CargoID _engine_sort_last_cargo_criteria[] = {CF_ANY, CF_ANY, CF_ANY, CF_ | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL EngineNumberSorter(const EngineID &a, const EngineID &b) | |
+static bool EngineNumberSorter(const EngineID &a, const EngineID &b) | |
{ | |
const int va = Engine::Get(a)->list_position; | |
const int vb = Engine::Get(b)->list_position; | |
@@ -116,7 +116,7 @@ static bool CDECL EngineNumberSorter(const EngineID &a, const EngineID &b) | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL EngineIntroDateSorter(const EngineID &a, const EngineID &b) | |
+static bool EngineIntroDateSorter(const EngineID &a, const EngineID &b) | |
{ | |
const int va = Engine::Get(a)->intro_date; | |
const int vb = Engine::Get(b)->intro_date; | |
@@ -132,7 +132,7 @@ static bool CDECL EngineIntroDateSorter(const EngineID &a, const EngineID &b) | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL EngineNameSorter(const EngineID &a, const EngineID &b) | |
+static bool EngineNameSorter(const EngineID &a, const EngineID &b) | |
{ | |
static EngineID last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE }; | |
static char last_name[2][64] = { "\0", "\0" }; | |
@@ -165,7 +165,7 @@ static bool CDECL EngineNameSorter(const EngineID &a, const EngineID &b) | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL EngineReliabilitySorter(const EngineID &a, const EngineID &b) | |
+static bool EngineReliabilitySorter(const EngineID &a, const EngineID &b) | |
{ | |
const int va = Engine::Get(a)->reliability; | |
const int vb = Engine::Get(b)->reliability; | |
@@ -181,7 +181,7 @@ static bool CDECL EngineReliabilitySorter(const EngineID &a, const EngineID &b) | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL EngineCostSorter(const EngineID &a, const EngineID &b) | |
+static bool EngineCostSorter(const EngineID &a, const EngineID &b) | |
{ | |
Money va = Engine::Get(a)->GetCost(); | |
Money vb = Engine::Get(b)->GetCost(); | |
@@ -197,7 +197,7 @@ static bool CDECL EngineCostSorter(const EngineID &a, const EngineID &b) | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL EngineSpeedSorter(const EngineID &a, const EngineID &b) | |
+static bool EngineSpeedSorter(const EngineID &a, const EngineID &b) | |
{ | |
int va = Engine::Get(a)->GetDisplayMaxSpeed(); | |
int vb = Engine::Get(b)->GetDisplayMaxSpeed(); | |
@@ -213,7 +213,7 @@ static bool CDECL EngineSpeedSorter(const EngineID &a, const EngineID &b) | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL EnginePowerSorter(const EngineID &a, const EngineID &b) | |
+static bool EnginePowerSorter(const EngineID &a, const EngineID &b) | |
{ | |
int va = Engine::Get(a)->GetPower(); | |
int vb = Engine::Get(b)->GetPower(); | |
@@ -229,7 +229,7 @@ static bool CDECL EnginePowerSorter(const EngineID &a, const EngineID &b) | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL EngineTractiveEffortSorter(const EngineID &a, const EngineID &b) | |
+static bool EngineTractiveEffortSorter(const EngineID &a, const EngineID &b) | |
{ | |
int va = Engine::Get(a)->GetDisplayMaxTractiveEffort(); | |
int vb = Engine::Get(b)->GetDisplayMaxTractiveEffort(); | |
@@ -245,7 +245,7 @@ static bool CDECL EngineTractiveEffortSorter(const EngineID &a, const EngineID & | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL EngineRunningCostSorter(const EngineID &a, const EngineID &b) | |
+static bool EngineRunningCostSorter(const EngineID &a, const EngineID &b) | |
{ | |
Money va = Engine::Get(a)->GetRunningCost(); | |
Money vb = Engine::Get(b)->GetRunningCost(); | |
@@ -261,7 +261,7 @@ static bool CDECL EngineRunningCostSorter(const EngineID &a, const EngineID &b) | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL EnginePowerVsRunningCostSorter(const EngineID &a, const EngineID &b) | |
+static bool EnginePowerVsRunningCostSorter(const EngineID &a, const EngineID &b) | |
{ | |
const Engine *e_a = Engine::Get(a); | |
const Engine *e_b = Engine::Get(b); | |
@@ -288,7 +288,7 @@ static bool CDECL EnginePowerVsRunningCostSorter(const EngineID &a, const Engine | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL TrainEngineCapacitySorter(const EngineID &a, const EngineID &b) | |
+static bool TrainEngineCapacitySorter(const EngineID &a, const EngineID &b) | |
{ | |
const RailVehicleInfo *rvi_a = RailVehInfo(a); | |
const RailVehicleInfo *rvi_b = RailVehInfo(b); | |
@@ -307,7 +307,7 @@ static bool CDECL TrainEngineCapacitySorter(const EngineID &a, const EngineID &b | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL TrainEnginesThenWagonsSorter(const EngineID &a, const EngineID &b) | |
+static bool TrainEnginesThenWagonsSorter(const EngineID &a, const EngineID &b) | |
{ | |
bool va = RailVehInfo(a)->railveh_type == RAILVEH_WAGON; | |
bool vb = RailVehInfo(b)->railveh_type == RAILVEH_WAGON; | |
@@ -325,7 +325,7 @@ static bool CDECL TrainEnginesThenWagonsSorter(const EngineID &a, const EngineID | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL RoadVehEngineCapacitySorter(const EngineID &a, const EngineID &b) | |
+static bool RoadVehEngineCapacitySorter(const EngineID &a, const EngineID &b) | |
{ | |
int va = GetTotalCapacityOfArticulatedParts(a); | |
int vb = GetTotalCapacityOfArticulatedParts(b); | |
@@ -343,7 +343,7 @@ static bool CDECL RoadVehEngineCapacitySorter(const EngineID &a, const EngineID | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL ShipEngineCapacitySorter(const EngineID &a, const EngineID &b) | |
+static bool ShipEngineCapacitySorter(const EngineID &a, const EngineID &b) | |
{ | |
const Engine *e_a = Engine::Get(a); | |
const Engine *e_b = Engine::Get(b); | |
@@ -364,7 +364,7 @@ static bool CDECL ShipEngineCapacitySorter(const EngineID &a, const EngineID &b) | |
* @param b second engine to compare | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL AircraftEngineCargoSorter(const EngineID &a, const EngineID &b) | |
+static bool AircraftEngineCargoSorter(const EngineID &a, const EngineID &b) | |
{ | |
const Engine *e_a = Engine::Get(a); | |
const Engine *e_b = Engine::Get(b); | |
@@ -385,7 +385,7 @@ static bool CDECL AircraftEngineCargoSorter(const EngineID &a, const EngineID &b | |
* @param b second engine to compare. | |
* @return For descending order, returns true if a < b and false otherwise. Vice versa for ascending order. | |
*/ | |
-static bool CDECL AircraftRangeSorter(const EngineID &a, const EngineID &b) | |
+static bool AircraftRangeSorter(const EngineID &a, const EngineID &b) | |
{ | |
uint16 va = Engine::Get(a)->GetRange(); | |
uint16 vb = Engine::Get(b)->GetRange(); | |
diff --git a/src/cargotype.cpp b/src/cargotype.cpp | |
index ce7622798..d17f16755 100644 | |
--- a/src/cargotype.cpp | |
+++ b/src/cargotype.cpp | |
@@ -140,7 +140,7 @@ uint8 _sorted_standard_cargo_specs_size; ///< Number of standard cargo s | |
/** Sort cargo specifications by their name. */ | |
-static bool CDECL CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpec * const &b) | |
+static bool CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpec * const &b) | |
{ | |
static char a_name[64]; | |
static char b_name[64]; | |
@@ -155,7 +155,7 @@ static bool CDECL CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpe | |
} | |
/** Sort cargo specifications by their cargo class. */ | |
-static bool CDECL CargoSpecClassSorter(const CargoSpec * const &a, const CargoSpec * const &b) | |
+static bool CargoSpecClassSorter(const CargoSpec * const &a, const CargoSpec * const &b) | |
{ | |
int r = (b->classes & CC_PASSENGERS) - (a->classes & CC_PASSENGERS); | |
if (r == 0) r = (b->classes & CC_MAIL) - (a->classes & CC_MAIL); | |
diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp | |
index 49b5f3b34..8c85dd254 100644 | |
--- a/src/core/smallmap_type.hpp | |
+++ b/src/core/smallmap_type.hpp | |
@@ -150,7 +150,7 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> { | |
std::sort(this->Begin(), this->End(), KeySorter); | |
} | |
- static bool CDECL KeySorter(const Pair &a, const Pair &b) | |
+ static bool KeySorter(const Pair &a, const Pair &b) | |
{ | |
return a->first < b->first; | |
} | |
diff --git a/src/engine_gui.h b/src/engine_gui.h | |
index ac2ec718f..e95cc13e4 100644 | |
--- a/src/engine_gui.h | |
+++ b/src/engine_gui.h | |
@@ -19,7 +19,7 @@ | |
typedef GUIList<EngineID, CargoID> GUIEngineList; | |
-typedef bool CDECL EngList_SortTypeFunction(const EngineID&, const EngineID&); ///< argument type for #EngList_Sort. | |
+typedef bool EngList_SortTypeFunction(const EngineID&, const EngineID&); ///< argument type for #EngList_Sort. | |
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare); | |
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); | |
diff --git a/src/fios.cpp b/src/fios.cpp | |
index b30baa452..d890f1bc1 100644 | |
--- a/src/fios.cpp | |
+++ b/src/fios.cpp | |
@@ -49,7 +49,7 @@ extern void GetOldSaveGameName(const char *file, char *title, const char *last); | |
* @param db A pointer to the second FiosItem to compare. | |
* @return -1, 0 or 1, depending on how the two items should be sorted. | |
*/ | |
-bool CDECL CompareFiosItems(const FiosItem &da, const FiosItem &db) | |
+bool CompareFiosItems(const FiosItem &da, const FiosItem &db) | |
{ | |
if ((_savegame_sort_order & SORT_BY_NAME) == 0 && da.mtime != db.mtime) { | |
return (_savegame_sort_order & SORT_DESCENDING) != (da.mtime < db.mtime); | |
diff --git a/src/fios.h b/src/fios.h | |
index fc3daffc1..f3b8a57e1 100644 | |
--- a/src/fios.h | |
+++ b/src/fios.h | |
@@ -237,6 +237,6 @@ void FiosMakeSavegameName(char *buf, const char *name, const char *last); | |
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last); | |
-bool CDECL CompareFiosItems(const FiosItem &a, const FiosItem &b); | |
+bool CompareFiosItems(const FiosItem &a, const FiosItem &b); | |
#endif /* FIOS_H */ | |
diff --git a/src/gfx.cpp b/src/gfx.cpp | |
index d55c74f38..abf368ed2 100644 | |
--- a/src/gfx.cpp | |
+++ b/src/gfx.cpp | |
@@ -1699,7 +1699,7 @@ bool ToggleFullScreen(bool fs) | |
return result; | |
} | |
-static bool CDECL compare_res(const Dimension &pa, const Dimension &pb) | |
+static bool compare_res(const Dimension &pa, const Dimension &pb) | |
{ | |
return pa.width < pb.width || (pa.width == pb.width && pa.height < pb.height); | |
} | |
diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp | |
index 16fc1107a..ad80a26f2 100644 | |
--- a/src/graph_gui.cpp | |
+++ b/src/graph_gui.cpp | |
@@ -1151,7 +1151,7 @@ private: | |
} | |
/** Sort the company league by performance history */ | |
- static bool CDECL PerformanceSorter(const Company * const &c1, const Company * const &c2) | |
+ static bool PerformanceSorter(const Company * const &c1, const Company * const &c2) | |
{ | |
return c2->old_economy[0].performance_history < c1->old_economy[0].performance_history; | |
} | |
diff --git a/src/group_gui.cpp b/src/group_gui.cpp | |
index 713b11cdb..51c3f3e03 100644 | |
--- a/src/group_gui.cpp | |
+++ b/src/group_gui.cpp | |
@@ -134,7 +134,7 @@ private: | |
} | |
/** Sort the groups by their name */ | |
- static bool CDECL GroupNameSorter(const Group * const &a, const Group * const &b) | |
+ static bool GroupNameSorter(const Group * const &a, const Group * const &b) | |
{ | |
static const Group *last_group[2] = { NULL, NULL }; | |
static char last_name[2][64] = { "", "" }; | |
diff --git a/src/highscore.cpp b/src/highscore.cpp | |
index 57bb2e9f3..5c4978d94 100644 | |
--- a/src/highscore.cpp | |
+++ b/src/highscore.cpp | |
@@ -81,7 +81,7 @@ int8 SaveHighScoreValue(const Company *c) | |
} | |
/** Sort all companies given their performance */ | |
-static bool CDECL HighScoreSorter(const Company * const &a, const Company * const &b) | |
+static bool HighScoreSorter(const Company * const &a, const Company * const &b) | |
{ | |
return b->old_economy[0].performance_history < a->old_economy[0].performance_history; | |
} | |
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp | |
index 9849ef4cc..ccc03a7b7 100644 | |
--- a/src/industry_gui.cpp | |
+++ b/src/industry_gui.cpp | |
@@ -160,7 +160,7 @@ static inline void GetAllCargoSuffixes(uint cb_offset, CargoSuffixType cst, cons | |
IndustryType _sorted_industry_types[NUM_INDUSTRYTYPES]; ///< Industry types sorted by name. | |
/** Sort industry types by their name. */ | |
-static bool CDECL IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b) | |
+static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b) | |
{ | |
static char industry_name[2][64]; | |
@@ -1201,7 +1201,7 @@ protected: | |
} | |
/** Sort industries by name */ | |
- static bool 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]; | |
@@ -1219,7 +1219,7 @@ protected: | |
} | |
/** Sort industries by type and name */ | |
- static bool 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++; | |
@@ -1229,7 +1229,7 @@ protected: | |
} | |
/** Sort industries by production and name */ | |
- static bool 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++) { | |
@@ -1240,7 +1240,7 @@ protected: | |
} | |
/** Sort industries by transported cargo and name */ | |
- static bool CDECL IndustryTransportedCargoSorter(const Industry * const &a, const Industry * const &b) | |
+ static bool IndustryTransportedCargoSorter(const Industry * const &a, const Industry * const &b) | |
{ | |
int va = GetCargoTransportedSortValue(a); | |
int vb = GetCargoTransportedSortValue(b); | |
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp | |
index 67e775d61..9c7634fa5 100644 | |
--- a/src/network/network_content_gui.cpp | |
+++ b/src/network/network_content_gui.cpp | |
@@ -407,13 +407,13 @@ class NetworkContentListWindow : public Window, ContentCallback { | |
} | |
/** Sort content by name. */ | |
- static bool CDECL NameSorter(const ContentInfo * const &a, const ContentInfo * const &b) | |
+ static bool NameSorter(const ContentInfo * const &a, const ContentInfo * const &b) | |
{ | |
return strnatcmp(a->name, b->name, true) < 0; // Sort by name (natural sorting). | |
} | |
/** Sort content by type. */ | |
- static bool CDECL TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b) | |
+ static bool TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b) | |
{ | |
int r = 0; | |
if (a->type != b->type) { | |
@@ -424,7 +424,7 @@ class NetworkContentListWindow : public Window, ContentCallback { | |
} | |
/** Sort content by state. */ | |
- static bool CDECL StateSorter(const ContentInfo * const &a, const ContentInfo * const &b) | |
+ static bool StateSorter(const ContentInfo * const &a, const ContentInfo * const &b) | |
{ | |
return (a->state == b->state) ? TypeSorter(a, b) : a->state < b->state; | |
} | |
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp | |
index 57d3eb89d..549389675 100644 | |
--- a/src/network/network_gui.cpp | |
+++ b/src/network/network_gui.cpp | |
@@ -276,7 +276,7 @@ protected: | |
} | |
/** Sort servers by name. */ | |
- static bool CDECL NGameNameSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
+ static bool NGameNameSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
int r = strnatcmp(a->info.server_name, b->info.server_name, true); // Sort by name (natural sorting). | |
return r == 0 ? a->address.CompareTo(b->address) < 0 : r < 0; | |
@@ -287,7 +287,7 @@ protected: | |
* server. If the two servers have the same amount, the one with the | |
* higher maximum is preferred. | |
*/ | |
- static bool CDECL NGameClientSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
+ static bool NGameClientSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
/* Reverse as per default we are interested in most-clients first */ | |
const NetworkGameInfo *gia = &a->info; | |
@@ -299,7 +299,7 @@ protected: | |
} | |
/** Sort servers by map size */ | |
- static bool CDECL NGameMapSizeSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
+ static bool NGameMapSizeSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
/* Sort by the area of the map. */ | |
int va = a->info.map_height * a->info.map_width; | |
@@ -311,13 +311,13 @@ protected: | |
} | |
/** Sort servers by current date */ | |
- static bool CDECL NGameDateSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
+ static bool NGameDateSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
return a->info.game_date == b->info.game_date ? NGameClientSorter(a, b) : a->info.game_date < b->info.game_date; | |
} | |
/** Sort servers by the number of days the game is running */ | |
- static bool CDECL NGameYearsSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
+ static bool NGameYearsSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
int va = a->info.game_date - a->info.start_date; | |
int vb = b->info.game_date - b->info.start_date; | |
@@ -328,7 +328,7 @@ protected: | |
* Sort servers by joinability. If both servers are the | |
* same, prefer the non-passworded server first. | |
*/ | |
- static bool CDECL NGameAllowedSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
+ static bool NGameAllowedSorter(NetworkGameList * const &a, NetworkGameList * const &b) | |
{ | |
/* The servers we do not know anything about (the ones that did not reply) should be at the bottom) */ | |
if (StrEmpty(a->info.server_revision) != StrEmpty(b->info.server_revision)) return StrEmpty(a->info.server_revision); | |
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp | |
index 1333a9f29..1be67180a 100644 | |
--- a/src/newgrf_config.cpp | |
+++ b/src/newgrf_config.cpp | |
@@ -711,7 +711,7 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const | |
* @param c2 the second GRFConfig | |
* @return True if c1 < c2, when sorted naturally. | |
*/ | |
-static bool CDECL GRFSorter(GRFConfig * const &c1, GRFConfig * const &c2) | |
+static bool GRFSorter(GRFConfig * const &c1, GRFConfig * const &c2) | |
{ | |
return strnatcmp(c1->GetName(), c2->GetName()) < 0; | |
} | |
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp | |
index 8ba85a9d6..55693e77d 100644 | |
--- a/src/newgrf_engine.cpp | |
+++ b/src/newgrf_engine.cpp | |
@@ -1232,7 +1232,7 @@ void AlterVehicleListOrder(EngineID engine, uint target) | |
* @param b right side | |
* @return comparison result | |
*/ | |
-static bool CDECL EnginePreSort(const EngineID &a, const EngineID &b) | |
+static bool EnginePreSort(const EngineID &a, const EngineID &b) | |
{ | |
const EngineIDMapping *id_a = _engine_mngr.Get(a); | |
const EngineIDMapping *id_b = _engine_mngr.Get(b); | |
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp | |
index 2b4dcf50d..e44cbdd91 100644 | |
--- a/src/newgrf_gui.cpp | |
+++ b/src/newgrf_gui.cpp | |
@@ -1438,7 +1438,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { | |
private: | |
/** Sort grfs by name. */ | |
- static bool CDECL NameSorter(const GRFConfig * const &a, const GRFConfig * const &b) | |
+ static bool NameSorter(const GRFConfig * const &a, const GRFConfig * const &b) | |
{ | |
int i = strnatcmp(a->GetName(), b->GetName(), true); // Sort by name (natural sorting). | |
if (i != 0) return i < 0; | |
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp | |
index d2494026d..2263aa697 100644 | |
--- a/src/rail_cmd.cpp | |
+++ b/src/rail_cmd.cpp | |
@@ -127,7 +127,7 @@ void ResolveRailTypeGUISprites(RailtypeInfo *rti) | |
* @param second The railtype to compare. | |
* @return True iff the first should be sorted before the second. | |
*/ | |
-static bool CDECL CompareRailTypes(const RailType &first, const RailType &second) | |
+static bool CompareRailTypes(const RailType &first, const RailType &second) | |
{ | |
return GetRailTypeInfo(first)->sorting_order < GetRailTypeInfo(second)->sorting_order; | |
} | |
diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp | |
index 22b9c941f..6db75c23a 100644 | |
--- a/src/signs_gui.cpp | |
+++ b/src/signs_gui.cpp | |
@@ -72,7 +72,7 @@ struct SignList { | |
} | |
/** Sort signs by their name */ | |
- static bool CDECL SignNameSorter(const Sign * const &a, const Sign * const &b) | |
+ static bool SignNameSorter(const Sign * const &a, const Sign * const &b) | |
{ | |
static char buf_cache[64]; | |
char buf[64]; | |
diff --git a/src/sortlist_type.h b/src/sortlist_type.h | |
index 95af651c9..61f3e8cd6 100644 | |
--- a/src/sortlist_type.h | |
+++ b/src/sortlist_type.h | |
@@ -89,7 +89,7 @@ struct BinNegator { | |
template <typename T, typename F = const char*> | |
class GUIList : public SmallVector<T, 32> { | |
public: | |
- typedef bool CDECL SortFunction(const T&, const T&); ///< Signature of sort function. | |
+ typedef bool SortFunction(const T&, const T&); ///< Signature of sort function. | |
typedef bool CDECL FilterFunction(const T*, F); ///< Signature of filter function. | |
protected: | |
diff --git a/src/station_gui.cpp b/src/station_gui.cpp | |
index 74a5fbb4e..db84face9 100644 | |
--- a/src/station_gui.cpp | |
+++ b/src/station_gui.cpp | |
@@ -209,7 +209,7 @@ protected: | |
} | |
/** Sort stations by their name */ | |
- static bool CDECL StationNameSorter(const Station * const &a, const Station * const &b) | |
+ static bool StationNameSorter(const Station * const &a, const Station * const &b) | |
{ | |
static char buf_cache[64]; | |
char buf[64]; | |
@@ -228,13 +228,13 @@ protected: | |
} | |
/** Sort stations by their type */ | |
- static bool CDECL StationTypeSorter(const Station * const &a, const Station * const &b) | |
+ static bool StationTypeSorter(const Station * const &a, const Station * const &b) | |
{ | |
return a->facilities < b->facilities; | |
} | |
/** Sort stations by their waiting cargo */ | |
- static bool CDECL StationWaitingTotalSorter(const Station * const &a, const Station * const &b) | |
+ static bool StationWaitingTotalSorter(const Station * const &a, const Station * const &b) | |
{ | |
int totala = 0; | |
int totalb = 0; | |
@@ -248,7 +248,7 @@ protected: | |
} | |
/** Sort stations by their available waiting cargo */ | |
- static bool CDECL StationWaitingAvailableSorter(const Station * const &a, const Station * const &b) | |
+ static bool StationWaitingAvailableSorter(const Station * const &a, const Station * const &b) | |
{ | |
int totala = 0; | |
int totalb = 0; | |
@@ -262,7 +262,7 @@ protected: | |
} | |
/** Sort stations by their rating */ | |
- static bool CDECL StationRatingMaxSorter(const Station * const &a, const Station * const &b) | |
+ static bool StationRatingMaxSorter(const Station * const &a, const Station * const &b) | |
{ | |
byte maxr1 = 0; | |
byte maxr2 = 0; | |
@@ -276,7 +276,7 @@ protected: | |
} | |
/** Sort stations by their rating */ | |
- static bool CDECL StationRatingMinSorter(const Station * const &a, const Station * const &b) | |
+ static bool StationRatingMinSorter(const Station * const &a, const Station * const &b) | |
{ | |
byte minr1 = 255; | |
byte minr2 = 255; | |
diff --git a/src/story_gui.cpp b/src/story_gui.cpp | |
index 2ee00225c..2ed9cc988 100644 | |
--- a/src/story_gui.cpp | |
+++ b/src/story_gui.cpp | |
@@ -69,7 +69,7 @@ protected: | |
} | |
/** Sort story pages by order value. */ | |
- static bool CDECL PageOrderSorter(const StoryPage * const &a, const StoryPage * const &b) | |
+ static bool PageOrderSorter(const StoryPage * const &a, const StoryPage * const &b) | |
{ | |
return a->sort_value < b->sort_value; | |
} | |
@@ -98,7 +98,7 @@ protected: | |
} | |
/** Sort story page elements by order value. */ | |
- static bool CDECL PageElementOrderSorter(const StoryPageElement * const &a, const StoryPageElement * const &b) | |
+ static bool PageElementOrderSorter(const StoryPageElement * const &a, const StoryPageElement * const &b) | |
{ | |
return a->sort_value < b->sort_value; | |
} | |
diff --git a/src/strings.cpp b/src/strings.cpp | |
index 476a9095d..e5a433dbf 100644 | |
--- a/src/strings.cpp | |
+++ b/src/strings.cpp | |
@@ -1857,7 +1857,7 @@ const char *GetCurrentLocale(const char *param) | |
const char *GetCurrentLocale(const char *param); | |
#endif /* !(defined(WIN32) || defined(__APPLE__)) */ | |
-bool CDECL StringIDSorter(const StringID &a, const StringID &b) | |
+bool StringIDSorter(const StringID &a, const StringID &b) | |
{ | |
char stra[512]; | |
char strb[512]; | |
diff --git a/src/strings_func.h b/src/strings_func.h | |
index 4d17a5462..764fde569 100644 | |
--- a/src/strings_func.h | |
+++ b/src/strings_func.h | |
@@ -238,7 +238,7 @@ extern TextDirection _current_text_dir; ///< Text direction of the currently sel | |
void InitializeLanguagePacks(); | |
const char *GetCurrentLanguageIsoCode(); | |
-bool CDECL StringIDSorter(const StringID &a, const StringID &b); | |
+bool StringIDSorter(const StringID &a, const StringID &b); | |
/** | |
* A searcher for missing glyphs. | |
diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp | |
index 7f44520be..5d56eb23a 100644 | |
--- a/src/timetable_cmd.cpp | |
+++ b/src/timetable_cmd.cpp | |
@@ -218,7 +218,7 @@ CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, | |
* @param b Second Vehicle. | |
* @return Comparison value. | |
*/ | |
-static bool CDECL VehicleTimetableSorter(Vehicle * const &a, Vehicle * const &b) | |
+static bool VehicleTimetableSorter(Vehicle * const &a, Vehicle * const &b) | |
{ | |
VehicleOrderID a_order = a->cur_real_order_index; | |
VehicleOrderID b_order = b->cur_real_order_index; | |
diff --git a/src/town_gui.cpp b/src/town_gui.cpp | |
index da54ef23a..b1c1a384c 100644 | |
--- a/src/town_gui.cpp | |
+++ b/src/town_gui.cpp | |
@@ -667,7 +667,7 @@ private: | |
} | |
/** Sort by town name */ | |
- static bool CDECL TownNameSorter(const Town * const &a, const Town * const &b) | |
+ static bool TownNameSorter(const Town * const &a, const Town * const &b) | |
{ | |
static char buf_cache[64]; | |
char buf[64]; | |
@@ -688,7 +688,7 @@ private: | |
} | |
/** Sort by population (default descending, as big towns are of the most interest). */ | |
- static bool CDECL TownPopulationSorter(const Town * const &a, const Town * const &b) | |
+ static bool TownPopulationSorter(const Town * const &a, const Town * const &b) | |
{ | |
uint32 a_population = a->cache.population; | |
uint32 b_population = b->cache.population; | |
@@ -697,7 +697,7 @@ private: | |
} | |
/** Sort by town rating */ | |
- static bool CDECL TownRatingSorter(const Town * const &a, const Town * const &b) | |
+ static bool TownRatingSorter(const Town * const &a, const Town * const &b) | |
{ | |
bool before = !TownDirectoryWindow::last_sorting.order; // Value to get 'a' before 'b'. | |
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp | |
index 6f49cfe7a..5d93469e1 100644 | |
--- a/src/vehicle_gui.cpp | |
+++ b/src/vehicle_gui.cpp | |
@@ -1085,13 +1085,13 @@ StringID GetCargoSubtypeText(const Vehicle *v) | |
} | |
/** Sort vehicles by their number */ | |
-static bool CDECL VehicleNumberSorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleNumberSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
return a->unitnumber < b->unitnumber; | |
} | |
/** Sort vehicles by their name */ | |
-static bool CDECL VehicleNameSorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleNameSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
static char last_name[2][64]; | |
@@ -1112,13 +1112,13 @@ static bool CDECL VehicleNameSorter(const Vehicle * const &a, const Vehicle * co | |
} | |
/** Sort vehicles by their age */ | |
-static bool CDECL VehicleAgeSorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleAgeSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
return a->age != b->age ? a->age < b->age : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by this year profit */ | |
-static bool CDECL VehicleProfitThisYearSorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleProfitThisYearSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
int va = a->GetDisplayProfitThisYear(); | |
int vb = b->GetDisplayProfitThisYear(); | |
@@ -1126,7 +1126,7 @@ static bool CDECL VehicleProfitThisYearSorter(const Vehicle * const &a, const Ve | |
} | |
/** Sort vehicles by last year profit */ | |
-static bool CDECL VehicleProfitLastYearSorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleProfitLastYearSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
int va = a->GetDisplayProfitLastYear(); | |
int vb = b->GetDisplayProfitLastYear(); | |
@@ -1134,7 +1134,7 @@ static bool CDECL VehicleProfitLastYearSorter(const Vehicle * const &a, const Ve | |
} | |
/** Sort vehicles by their cargo */ | |
-static bool CDECL VehicleCargoSorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleCargoSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
const Vehicle *v; | |
CargoArray diff; | |
@@ -1153,13 +1153,13 @@ static bool CDECL VehicleCargoSorter(const Vehicle * const &a, const Vehicle * c | |
} | |
/** Sort vehicles by their reliability */ | |
-static bool CDECL VehicleReliabilitySorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleReliabilitySorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
return a->reliability != b->reliability ? a->reliability < b->reliability : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by their max speed */ | |
-static bool CDECL VehicleMaxSpeedSorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleMaxSpeedSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
int va = a->vcache.cached_max_speed; | |
int vb = b->vcache.cached_max_speed; | |
@@ -1167,13 +1167,13 @@ static bool CDECL VehicleMaxSpeedSorter(const Vehicle * const &a, const Vehicle | |
} | |
/** Sort vehicles by model */ | |
-static bool CDECL VehicleModelSorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleModelSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
return a->engine_type != b->engine_type ? a->engine_type < b->engine_type : VehicleNumberSorter(a, b); | |
} | |
/** Sort vehicles by their value */ | |
-static bool CDECL VehicleValueSorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleValueSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
const Vehicle *u; | |
Money diff = 0; | |
@@ -1186,7 +1186,7 @@ static bool CDECL VehicleValueSorter(const Vehicle * const &a, const Vehicle * c | |
} | |
/** Sort vehicles by their length */ | |
-static bool CDECL VehicleLengthSorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleLengthSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
int va = a->GetGroundVehicleCache()->cached_total_length; | |
int vb = b->GetGroundVehicleCache()->cached_total_length; | |
@@ -1194,7 +1194,7 @@ static bool CDECL VehicleLengthSorter(const Vehicle * const &a, const Vehicle * | |
} | |
/** Sort vehicles by the time they can still live */ | |
-static bool CDECL VehicleTimeToLiveSorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleTimeToLiveSorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
int va = a->max_age - a->age; | |
int vb = b->max_age - b->age; | |
@@ -1202,7 +1202,7 @@ static bool CDECL VehicleTimeToLiveSorter(const Vehicle * const &a, const Vehicl | |
} | |
/** Sort vehicles by the timetable delay */ | |
-static bool CDECL VehicleTimetableDelaySorter(const Vehicle * const &a, const Vehicle * const &b) | |
+static bool VehicleTimetableDelaySorter(const Vehicle * const &a, const Vehicle * const &b) | |
{ | |
return a->lateness_counter != b->lateness_counter ? a->lateness_counter < b->lateness_counter : VehicleNumberSorter(a, b); | |
} | |
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm | |
index 037a7e798..0e47df684 100644 | |
--- a/src/video/cocoa/cocoa_v.mm | |
+++ b/src/video/cocoa/cocoa_v.mm | |
@@ -227,7 +227,7 @@ static void setupApplication() | |
} | |
-static bool CDECL ModeSorter(const OTTD_Point &p1, const OTTD_Point &p2) | |
+static bool ModeSorter(const OTTD_Point &p1, const OTTD_Point &p2) | |
{ | |
return p1.x < p2.x || (p1.x == p2.x && p1.y < p2.y); | |
} | |
diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h | |
index e87ea1e85..6770bb05c 100644 | |
--- a/src/widgets/dropdown_type.h | |
+++ b/src/widgets/dropdown_type.h | |
@@ -50,7 +50,7 @@ public: | |
virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const; | |
virtual StringID String() const { return this->string; } | |
- static bool CDECL NatSortFunc(const DropDownListItem * const &first, const DropDownListItem * const &second); | |
+ static bool NatSortFunc(const DropDownListItem * const &first, const DropDownListItem * const &second); | |
}; | |
/** | |
diff --git a/src/window.cpp b/src/window.cpp | |
index 53b1cb1dd..7f72b89fa 100644 | |
--- a/src/window.cpp | |
+++ b/src/window.cpp | |
@@ -150,7 +150,7 @@ void WindowDesc::LoadFromConfig() | |
/** | |
* Sort WindowDesc by ini_key. | |
*/ | |
-static bool CDECL DescSorter(WindowDesc * const &a, WindowDesc * const &b) | |
+static bool DescSorter(WindowDesc * const &a, WindowDesc * const &b) | |
{ | |
if (a->ini_key != NULL && b->ini_key != NULL) return strcmp(a->ini_key, b->ini_key) < 0; | |
return a->ini_key != NULL; | |
-- | |
2.14.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment