From 5d9b35510d7d6aad9408e12aaebed2a79e3ed826 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 20 Nov 2004 21:35:49 +0000 Subject: Changed the FilesystemNode implementation to make it easier to use (client code doesn't have to worry about the memory managment anymore, it's all 'automatic' now). May have introduced a mem leak or two, please check :-) svn-id: r15848 --- backends/fs/posix/posix-fs.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 86c29910b5..a2f35ad108 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -45,7 +45,7 @@ * Implementation of the ScummVM file system API based on POSIX. */ -class POSIXFilesystemNode : public FilesystemNode { +class POSIXFilesystemNode : public AbstractFilesystemNode { protected: String _displayName; bool _isDirectory; @@ -62,9 +62,8 @@ public: virtual bool isDirectory() const { return _isDirectory; } virtual String path() const { return _path; } - virtual FSList *listDir(ListMode mode = kListDirectoriesOnly) const; - virtual FilesystemNode *parent() const; - virtual FilesystemNode *clone() const { return new POSIXFilesystemNode(this); } + virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const; + virtual AbstractFilesystemNode *parent() const; }; @@ -79,12 +78,12 @@ static const char *lastPathComponent(const Common::String &str) { return cur+1; } -FilesystemNode *FilesystemNode::getRoot() { +AbstractFilesystemNode *FilesystemNode::getRoot() { return new POSIXFilesystemNode(); } #ifdef MACOSX -FilesystemNode *FilesystemNode::getNodeForPath(const String &path) { +AbstractFilesystemNode *FilesystemNode::getNodeForPath(const String &path) { return new POSIXFilesystemNode(path); } #endif @@ -140,15 +139,16 @@ POSIXFilesystemNode::POSIXFilesystemNode(const POSIXFilesystemNode *node) { _path = node->_path; } -FSList *POSIXFilesystemNode::listDir(ListMode mode) const { +FSList POSIXFilesystemNode::listDir(ListMode mode) const { assert(_isDirectory); DIR *dirp = opendir(_path.c_str()); struct stat st; struct dirent *dp; - FSList *myList = new FSList(); + FSList myList; - if (dirp == NULL) return myList; + if (dirp == NULL) + return myList; // ... loop over dir entries using readdir while ((dp = readdir(dirp)) != NULL) { @@ -178,13 +178,13 @@ FSList *POSIXFilesystemNode::listDir(ListMode mode) const { if (entry._isDirectory) entry._path += "/"; - myList->push_back(entry); + myList.push_back(wrap(new POSIXFilesystemNode(&entry))); } closedir(dirp); return myList; } -FilesystemNode *POSIXFilesystemNode::parent() const { +AbstractFilesystemNode *POSIXFilesystemNode::parent() const { POSIXFilesystemNode *p = new POSIXFilesystemNode(); // Root node is its own parent. Still we can't just return this -- cgit v1.2.3