[Scummvm-cvs-logs] SF.net SVN: scummvm: [21617] scummvm/trunk/gui
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Tue Apr 4 16:56:17 CEST 2006
Revision: 21617
Author: fingolfin
Date: 2006-04-04 16:55:47 -0700 (Tue, 04 Apr 2006)
ViewCVS: http://svn.sourceforge.net/scummvm/?rev=21617&view=rev
Log Message:
-----------
Turned FSList::sort into a generic function which can be applied to anything which implements comparable iterators (like Array, List, or plain C arrays)
Modified Paths:
--------------
scummvm/trunk/backends/fs/fs.cpp
scummvm/trunk/backends/fs/fs.h
scummvm/trunk/common/func.h
scummvm/trunk/gui/browser.cpp
Modified: scummvm/trunk/backends/fs/fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/fs.cpp 2006-04-04 23:52:56 UTC (rev 21616)
+++ scummvm/trunk/backends/fs/fs.cpp 2006-04-04 23:55:47 UTC (rev 21617)
@@ -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;
Modified: scummvm/trunk/backends/fs/fs.h
===================================================================
--- scummvm/trunk/backends/fs/fs.h 2006-04-04 23:52:56 UTC (rev 21616)
+++ scummvm/trunk/backends/fs/fs.h 2006-04-04 23:55:47 UTC (rev 21617)
@@ -60,11 +60,10 @@
/**
* 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> {};
/**
Modified: scummvm/trunk/common/func.h
===================================================================
--- scummvm/trunk/common/func.h 2006-04-04 23:52:56 UTC (rev 21616)
+++ scummvm/trunk/common/func.h 2006-04-04 23:55:47 UTC (rev 21617)
@@ -62,7 +62,29 @@
#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
#endif
Modified: scummvm/trunk/gui/browser.cpp
===================================================================
--- scummvm/trunk/gui/browser.cpp 2006-04-04 23:52:56 UTC (rev 21616)
+++ scummvm/trunk/gui/browser.cpp 2006-04-04 23:55:47 UTC (rev 21617)
@@ -27,6 +27,7 @@
#include "backends/fs/fs.h"
#include "common/system.h"
+#include "common/func.h"
namespace GUI {
@@ -225,7 +226,7 @@
_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;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list