[Scummvm-cvs-logs] CVS: scummvm/backends/fs fs.h,1.4,1.5
Max Horn
fingolfin at users.sourceforge.net
Wed Nov 20 18:52:05 CET 2002
Update of /cvsroot/scummvm/scummvm/backends/fs
In directory sc8-pr-cvs1:/tmp/cvs-serv3676
Modified Files:
fs.h
Log Message:
sort FSList by displayname
Index: fs.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/fs/fs.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- fs.h 19 Nov 2002 01:36:47 -0000 1.4
+++ fs.h 21 Nov 2002 02:51:50 -0000 1.5
@@ -132,11 +132,19 @@
* Return a clone of this node allocated with new().
*/
virtual FilesystemNode *clone() const = 0;
+
+ /*
+ * Compare the name of this node to the name of another.
+ */
+ virtual bool operator< (const FilesystemNode& node) const
+ {
+ return displayName() < node.displayName();
+ }
};
/*
- * A list of multiple file system nodes. E.g. the contents of a given directory.
+ * A sorted list of multiple file system nodes. E.g. the contents of a given directory.
*/
class FSList : ScummVM::List<FilesystemNode *> {
public:
@@ -149,7 +157,15 @@
void push_back(const FilesystemNode& element)
{
ensureCapacity(_size + 1);
- _data[_size++] = element.clone();
+ // Determine where to insert the item.
+ // TODO this is inefficient, should use binary search instead
+ int i = 0;
+ while (i < _size && *_data[i] < element)
+ i++;
+ if (i < _size)
+ memmove(&_data[i+1], &_data[i], (_size - i) * sizeof(FilesystemNode *));
+ _data[i] = element.clone();
+ _size++;
}
const FilesystemNode& operator [](int idx) const
More information about the Scummvm-git-logs
mailing list