aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/fs/fs.cpp15
-rw-r--r--backends/fs/fs.h7
-rw-r--r--common/func.h22
-rw-r--r--gui/browser.cpp3
4 files changed, 27 insertions, 20 deletions
diff --git a/backends/fs/fs.cpp b/backends/fs/fs.cpp
index 4cc0432638..ecb8f50aab 100644
--- a/backends/fs/fs.cpp
+++ b/backends/fs/fs.cpp
@@ -24,21 +24,6 @@
#include "backends/fs/fs.h"
#include "common/util.h"
-void FSList::sort() {
- // Simple selection sort
- for (iterator i = begin(); i != end(); ++i) {
- iterator m(i);
- iterator j(i);
- ++j;
- for (; j != end(); ++j)
- if (*j < *m)
- m = j;
- if (m != i)
- SWAP(*m, *i);
- }
-}
-
-
FilesystemNode AbstractFilesystemNode::wrap(AbstractFilesystemNode *node) {
FilesystemNode wrapper(node);
return wrapper;
diff --git a/backends/fs/fs.h b/backends/fs/fs.h
index 7005707b16..27f8c7679f 100644
--- a/backends/fs/fs.h
+++ b/backends/fs/fs.h
@@ -60,11 +60,10 @@ class FilesystemNode;
/**
* List of multiple file system nodes. E.g. the contents of a given directory.
+ * This is subclass instead of just a typedef so that we can use forward
+ * declarations of it in other places.
*/
-class FSList : public Common::Array<FilesystemNode> {
-public:
- void sort();
-};
+class FSList : public Common::Array<FilesystemNode> {};
/**
diff --git a/common/func.h b/common/func.h
index 10c80e66f5..e2cd20fdb3 100644
--- a/common/func.h
+++ b/common/func.h
@@ -62,6 +62,28 @@ GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned long);
#undef GENERATE_TRIVIAL_HASH_FUNCTOR
+// Simple sort function, modelled after std::sort.
+// Use it like this: sort(container.begin(), container.end()).
+// Also work on plain old int arrays etc.
+template <typename T>
+void sort(T first, T last) {
+ if (first == last)
+ return;
+
+ // Simple selection sort
+ T i(first);
+ for (; i != last; ++i) {
+ T min(i);
+ T j(i);
+ ++j;
+ for (; j != last; ++j)
+ if (*j < *min)
+ min = j;
+ if (min != i)
+ SWAP(*min, *i);
+ }
+}
+
} // End of namespace Common
diff --git a/gui/browser.cpp b/gui/browser.cpp
index 8c32502948..5876124c47 100644
--- a/gui/browser.cpp
+++ b/gui/browser.cpp
@@ -27,6 +27,7 @@
#include "backends/fs/fs.h"
#include "common/system.h"
+#include "common/func.h"
namespace GUI {
@@ -225,7 +226,7 @@ void BrowserDialog::updateListing() {
_nodeContent = _node.listDir(AbstractFilesystemNode::kListDirectoriesOnly);
else
_nodeContent = _node.listDir(AbstractFilesystemNode::kListAll);
- _nodeContent.sort();
+ Common::sort(_nodeContent.begin(), _nodeContent.end());
// Populate the ListWidget
Common::StringList list;