summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2019-04-11 22:52:41 +0200
committerPeterN <peter@fuzzle.org>2019-04-13 12:49:18 +0100
commit5b77102b63f77bfbad02ae3383b87fbef6e60e7d (patch)
tree2ba70a19ea4f3617d12206ccee34c3c34d58dfa7 /src
parentb52561fd381e2c8230730e852406b85210993a98 (diff)
downloadopenttd-5b77102b63f77bfbad02ae3383b87fbef6e60e7d.tar.xz
Codechange: use std::sort() to sort file lists
Diffstat (limited to 'src')
-rw-r--r--src/fios.cpp21
-rw-r--r--src/fios.h3
-rw-r--r--src/fios_gui.cpp3
3 files changed, 12 insertions, 15 deletions
diff --git a/src/fios.cpp b/src/fios.cpp
index 008f552e6..76a2e7430 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -47,21 +47,20 @@ extern void GetOldSaveGameName(const char *file, char *title, const char *last);
/**
* Compare two FiosItem's. Used with sort when sorting the file list.
- * @param da A pointer to the first FiosItem to compare.
- * @param db A pointer to the second FiosItem to compare.
- * @return -1, 0 or 1, depending on how the two items should be sorted.
+ * @param other The FiosItem to compare to.
+ * @return for ascending order: returns true if da < db. Vice versa for descending order.
*/
-int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db)
+bool FiosItem::operator< (const FiosItem &other) const
{
- int r = 0;
+ bool r = false;
- if ((_savegame_sort_order & SORT_BY_NAME) == 0 && da->mtime != db->mtime) {
- r = da->mtime < db->mtime ? -1 : 1;
+ if ((_savegame_sort_order & SORT_BY_NAME) == 0 && (*this).mtime != other.mtime) {
+ r = (*this).mtime < other.mtime;
} else {
- r = strcasecmp(da->title, db->title);
+ r = strcasecmp((*this).title, other.title) < 0;
}
- if (_savegame_sort_order & SORT_DESCENDING) r = -r;
+ if (_savegame_sort_order & SORT_DESCENDING) r = !r;
return r;
}
@@ -380,7 +379,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.data(), file_list.files.size(), CompareFiosItems);
+ std::sort(file_list.files.begin(), file_list.files.end());
_savegame_sort_order = order;
}
@@ -395,7 +394,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c
scanner.Scan(nullptr, subdir, true, true);
}
- QSortT(file_list.Get(sort_start), file_list.Length() - sort_start, CompareFiosItems);
+ std::sort(file_list.files.begin() + sort_start, file_list.files.end());
/* Show drives */
FiosGetDrives(file_list);
diff --git a/src/fios.h b/src/fios.h
index 5688e88cf..7b10dea4c 100644
--- a/src/fios.h
+++ b/src/fios.h
@@ -107,6 +107,7 @@ struct FiosItem {
uint64 mtime;
char title[64];
char name[MAX_PATH];
+ bool operator< (const FiosItem &other) const;
};
/** List of file information. */
@@ -227,6 +228,4 @@ 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);
-
#endif /* FIOS_H */
diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp
index c78271122..1a8e7fdeb 100644
--- a/src/fios_gui.cpp
+++ b/src/fios_gui.cpp
@@ -260,8 +260,7 @@ static void SortSaveGameList(FileList &file_list)
}
}
- size_t s_amount = file_list.Length() - sort_start - sort_end;
- QSortT(file_list.Get(sort_start), s_amount, CompareFiosItems);
+ std::sort(file_list.files.begin() + sort_start, file_list.files.end() - sort_end);
}
struct SaveLoadWindow : public Window {