diff options
author | Max Horn | 2002-11-21 02:51:50 +0000 |
---|---|---|
committer | Max Horn | 2002-11-21 02:51:50 +0000 |
commit | 1f8cc789ced902dcf454591c4fafc1a27fde7c64 (patch) | |
tree | f391c7d59a9b37b5a84212031f50ecb700b6bd1c /backends | |
parent | 4896b55670ec9ccc032e6bdeab512434f3c99361 (diff) | |
download | scummvm-rg350-1f8cc789ced902dcf454591c4fafc1a27fde7c64.tar.gz scummvm-rg350-1f8cc789ced902dcf454591c4fafc1a27fde7c64.tar.bz2 scummvm-rg350-1f8cc789ced902dcf454591c4fafc1a27fde7c64.zip |
sort FSList by displayname
svn-id: r5648
Diffstat (limited to 'backends')
-rw-r--r-- | backends/fs/fs.h | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/backends/fs/fs.h b/backends/fs/fs.h index 7bb63c9671..abade8f189 100644 --- a/backends/fs/fs.h +++ b/backends/fs/fs.h @@ -132,11 +132,19 @@ public: * 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 @@ public: 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 |