[Scummvm-cvs-logs] SF.net SVN: scummvm: [22297] scummvm/trunk/backends/fs

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed May 3 03:15:10 CEST 2006


Revision: 22297
Author:   fingolfin
Date:     2006-05-03 03:14:05 -0700 (Wed, 03 May 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22297&view=rev

Log Message:
-----------
Started to separate AbstractFilesystemNode from FilesystemNode

Modified Paths:
--------------
    scummvm/trunk/backends/fs/amigaos4/amigaos4-fs.cpp
    scummvm/trunk/backends/fs/fs.cpp
    scummvm/trunk/backends/fs/fs.h
    scummvm/trunk/backends/fs/morphos/abox-fs.cpp
    scummvm/trunk/backends/fs/palmos/palmos-fs.cpp
    scummvm/trunk/backends/fs/posix/posix-fs.cpp
    scummvm/trunk/backends/fs/ps2/ps2-fs.cpp
    scummvm/trunk/backends/fs/symbian/symbian-fs.cpp
    scummvm/trunk/backends/fs/windows/windows-fs.cpp

Added Paths:
-----------
    scummvm/trunk/backends/fs/abstract-fs.h
Added: scummvm/trunk/backends/fs/abstract-fs.h
===================================================================
--- scummvm/trunk/backends/fs/abstract-fs.h	                        (rev 0)
+++ scummvm/trunk/backends/fs/abstract-fs.h	2006-05-03 10:14:05 UTC (rev 22297)
@@ -0,0 +1,121 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2002-2006 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef BACKENDS_ABSTRACT_FS_H
+#define BACKENDS_ABSTRACT_FS_H
+
+#include "common/str.h"
+
+#include "backends/fs/fs.h"
+
+/**
+ * Abstract file system node. Private subclasses implement the actual
+ * functionality.
+ */
+class AbstractFilesystemNode {
+protected:
+	friend class FilesystemNode;
+	typedef Common::String String;
+	typedef FilesystemNode::ListMode ListMode;
+
+	/**
+	 * The parent node of this directory.
+	 * The parent of the root is the root itself.
+	 */
+	virtual AbstractFilesystemNode *parent() const = 0;
+
+	/**
+	 * The child node with the given name. If no child with this name
+	 * exists, returns 0. Will never be called on a node which is not
+	 * a directory node.
+	 */
+	virtual AbstractFilesystemNode *child(const String &name) const = 0;
+
+	/**
+	 * This method is a rather ugly hack which is used internally by the
+	 * actual node implementions to wrap up raw nodes inside FilesystemNode
+	 * objects. We probably want to get rid of this eventually and replace it
+	 * with a cleaner / more elegant solution, but for now it works.
+	 * @note This takes over ownership of node. Do not delete it yourself,
+	 *       else you'll get ugly crashes. You've been warned!
+	 */
+	static FilesystemNode wrap(AbstractFilesystemNode *node);
+
+public:
+	virtual ~AbstractFilesystemNode() {}
+
+	/**
+	 * Return a human readable string for this node, usable for display (e.g.
+	 * in the GUI code). Do *not* rely on it being usable for anything else,
+	 * like constructing paths!
+	 * @return the display name
+	 */
+	virtual String displayName() const = 0;
+
+	/**
+	 * Is this node valid? Returns true if the file/directory pointed
+	 * to by this node exists, false otherwise.
+	 *
+	 * @todo Maybe rename this to exists() ? Or maybe even distinguish between
+	 * the two? E.g. a path may be non-existant but valid, while another might
+	 * be completely invalid). But do we ever need to make that distinction?
+	 */
+	virtual bool isValid() const = 0;
+
+	/**
+	 * Is this node pointing to a directory?
+	 * @todo Currently we assume that a valid node that is not a directory
+	 * automatically is a file (ignoring things like symlinks). That might
+	 * actually be OK... but we could still add an isFile method. Or even replace
+	 * isValid and isDirectory by a getType() method that can return values like
+	 * kDirNodeType, kFileNodeType, kInvalidNodeType.
+	 */
+	virtual bool isDirectory() const = 0;
+
+	/**
+	 * Return a string representation of the file which can be passed to fopen(),
+	 * and is suitable for archiving (i.e. writing to the config file).
+	 * This will usually be a 'path' (hence the name of the method), but can
+	 * be anything that fulfilly the above criterions.
+	 */
+	virtual String path() const = 0;
+
+	/**
+	 * Return a list of child nodes of this directory node. If called
+	 * on a node that does not represent a directory, an error is triggered.
+	 * @todo Rename this to listChildren.
+	 */
+	virtual FSList listDir(ListMode mode) const = 0;
+
+
+	/* TODO:
+	bool exists();
+
+	bool isDirectory();
+	bool isFile();
+
+	bool isReadable();
+	bool isWriteable();
+	*/
+};
+
+
+#endif


Property changes on: scummvm/trunk/backends/fs/abstract-fs.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Modified: scummvm/trunk/backends/fs/amigaos4/amigaos4-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/amigaos4/amigaos4-fs.cpp	2006-05-03 10:12:42 UTC (rev 22296)
+++ scummvm/trunk/backends/fs/amigaos4/amigaos4-fs.cpp	2006-05-03 10:14:05 UTC (rev 22297)
@@ -37,6 +37,7 @@
 #include "common/util.h"
 
 #include "base/engine.h"
+#include "backends/fs/abstract-fs.h"
 #include "backends/fs/fs.h"
 
 #define ENTER() /* debug(6, "Enter") */
@@ -68,7 +69,7 @@
 		virtual bool isDirectory() const { return _bIsDirectory; };
 		virtual String path() const { return _sPath; };
 
-		virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
+		virtual FSList listDir(ListMode mode) const;
 		virtual FSList listVolumes(void) const;
 		virtual AbstractFilesystemNode *parent() const;
 		virtual AbstractFilesystemNode *child(const String &name) const;
@@ -263,9 +264,9 @@
 
 				struct ExAllData *ead = data;
 				do {
-					if ((mode == kListAll) ||
-						(EAD_IS_DRAWER(ead) && (mode == kListDirectoriesOnly)) ||
-						(EAD_IS_FILE(ead) && (mode == kListFilesOnly))) {
+					if ((mode == FilesystemNode::kListAll) ||
+						(EAD_IS_DRAWER(ead) && (mode == FilesystemNode::kListDirectoriesOnly)) ||
+						(EAD_IS_FILE(ead) && (mode == FilesystemNode::kListFilesOnly))) {
 						String full_path = _sPath;
 						full_path += (char*)ead->ed_Name;
 

Modified: scummvm/trunk/backends/fs/fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/fs.cpp	2006-05-03 10:12:42 UTC (rev 22296)
+++ scummvm/trunk/backends/fs/fs.cpp	2006-05-03 10:14:05 UTC (rev 22297)
@@ -21,6 +21,7 @@
 
 #include "common/stdafx.h"
 
+#include "backends/fs/abstract-fs.h"
 #include "backends/fs/fs.h"
 #include "common/util.h"
 
@@ -48,8 +49,7 @@
 	++(*_refCount);
 }
 
-FilesystemNode::FilesystemNode(const FilesystemNode &node)
-	: AbstractFilesystemNode() {
+FilesystemNode::FilesystemNode(const FilesystemNode &node) {
 	_realNode = node._realNode;
 	_refCount = node._refCount;
 	++(*_refCount);
@@ -131,3 +131,13 @@
 	assert(_realNode);
 	return _realNode->path();
 }
+
+
+bool FilesystemNode::operator< (const FilesystemNode& node) const
+{
+	if (isDirectory() && !node.isDirectory())
+		return true;
+	if (!isDirectory() && node.isDirectory())
+		return false;
+	return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0;
+}

Modified: scummvm/trunk/backends/fs/fs.h
===================================================================
--- scummvm/trunk/backends/fs/fs.h	2006-05-03 10:12:42 UTC (rev 22296)
+++ scummvm/trunk/backends/fs/fs.h	2006-05-03 10:14:05 UTC (rev 22297)
@@ -19,8 +19,8 @@
  * $Id$
  */
 
-#ifndef FS_H
-#define FS_H
+#ifndef BACKENDS_FS_H
+#define BACKENDS_FS_H
 
 /*
  * The API described in this header is meant to allow for file system browsing in a
@@ -56,6 +56,7 @@
 #include "common/str.h"
 
 class FilesystemNode;
+class AbstractFilesystemNode;
 
 
 /**
@@ -66,119 +67,7 @@
 class FSList : public Common::Array<FilesystemNode> {};
 
 
-/**
- * File system node.
- */
-class AbstractFilesystemNode {
-protected:
-	friend class FilesystemNode;
-	typedef Common::String String;
-
-	/**
-	 * The parent node of this directory.
-	 * The parent of the root is the root itself.
-	 */
-	virtual AbstractFilesystemNode *parent() const = 0;
-
-	/**
-	 * The child node with the given name. If no child with this name
-	 * exists, returns 0. Will never be called on a node which is not
-	 * a directory node.
-	 */
-	virtual AbstractFilesystemNode *child(const String &name) const = 0;
-
-	/**
-	 * This method is a rather ugly hack which is used internally by the
-	 * actual node implementions to wrap up raw nodes inside FilesystemNode
-	 * objects. We probably want to get rid of this eventually and replace it
-	 * with a cleaner / more elegant solution, but for now it works.
-	 * @note This takes over ownership of node. Do not delete it yourself,
-	 *       else you'll get ugly crashes. You've been warned!
-	 */
-	static FilesystemNode wrap(AbstractFilesystemNode *node);
-
-public:
-
-	/**
-	 * Flag to tell listDir() which kind of files to list.
-	 */
-	typedef enum {
-		kListFilesOnly = 1,
-		kListDirectoriesOnly = 2,
-		kListAll = 3
-	} ListMode;
-
-	virtual ~AbstractFilesystemNode() {}
-
-	/**
-	 * Return a human readable string for this node, usable for display (e.g.
-	 * in the GUI code). Do *not* rely on it being usable for anything else,
-	 * like constructing paths!
-	 * @return the display name
-	 */
-	virtual String displayName() const = 0;
-
-	/**
-	 * Is this node valid? Returns true if the file/directory pointed
-	 * to by this node exists, false otherwise.
-	 *
-	 * @todo Maybe rename this to exists() ? Or maybe even distinguish between
-	 * the two? E.g. a path may be non-existant but valid, while another might
-	 * be completely invalid). But do we ever need to make that distinction?
-	 */
-	virtual bool isValid() const = 0;
-
-	/**
-	 * Is this node pointing to a directory?
-	 * @todo Currently we assume that a valid node that is not a directory
-	 * automatically is a file (ignoring things like symlinks). That might
-	 * actually be OK... but we could still add an isFile method. Or even replace
-	 * isValid and isDirectory by a getType() method that can return values like
-	 * kDirNodeType, kFileNodeType, kInvalidNodeType.
-	 */
-	virtual bool isDirectory() const = 0;
-
-	/**
-	 * Return a string representation of the file which can be passed to fopen(),
-	 * and is suitable for archiving (i.e. writing to the config file).
-	 * This will usually be a 'path' (hence the name of the method), but can
-	 * be anything that fulfilly the above criterions.
-	 */
-	virtual String path() const = 0;
-
-	/**
-	 * Return a list of child nodes of this directory node. If called
-	 * on a node that does not represent a directory, an error is triggered.
-	 * @todo Rename this to listChildren.
-	 */
-	virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const = 0;
-
-	/**
-	 * Compare the name of this node to the name of another. Directories
-	 * go before normal files.
-	 */
-	virtual bool operator< (const AbstractFilesystemNode& node) const
-	{
-		if (isDirectory() && !node.isDirectory())
-			return true;
-		if (!isDirectory() && node.isDirectory())
-			return false;
-		return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0;
-	}
-
-
-	/* TODO:
-	bool exists();
-
-	bool isDirectory();
-	bool isFile();
-
-	bool isReadable();
-	bool isWriteable();
-	*/
-};
-
-class FilesystemNode : public AbstractFilesystemNode {
+class FilesystemNode {
 	friend class AbstractFilesystemNode;
 
 	typedef Common::String String;
@@ -213,6 +102,16 @@
 
 public:
 	/**
+	 * Flag to tell listDir() which kind of files to list.
+	 */
+	enum ListMode {
+		kListFilesOnly = 1,
+		kListDirectoriesOnly = 2,
+		kListAll = 3
+	};
+
+
+	/**
 	 * Create a new FilesystemNode refering to the specified path. This is
 	 * the counterpart to the path() method.
 	 */
@@ -221,7 +120,7 @@
 
 	FilesystemNode();
 	FilesystemNode(const FilesystemNode &node);
-	~FilesystemNode();
+	virtual ~FilesystemNode();
 
 	FilesystemNode &operator  =(const FilesystemNode &node);
 
@@ -244,11 +143,14 @@
 	virtual bool isDirectory() const;
 	virtual String path() const;
 
+	/**
+	 * Compare the name of this node to the name of another. Directories
+	 * go before normal files.
+	 */
+	bool operator< (const FilesystemNode& node) const;
+
 protected:
 	void decRefCount();
-
-	virtual AbstractFilesystemNode *parent() const { return 0; }
-	virtual AbstractFilesystemNode *child(const String &name) const { return 0; }
 };
 
 

Modified: scummvm/trunk/backends/fs/morphos/abox-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/morphos/abox-fs.cpp	2006-05-03 10:12:42 UTC (rev 22296)
+++ scummvm/trunk/backends/fs/morphos/abox-fs.cpp	2006-05-03 10:14:05 UTC (rev 22297)
@@ -26,6 +26,7 @@
 #include <stdio.h>
 
 #include "base/engine.h"
+#include "backends/fs/abstract-fs.h"
 #include "backends/fs/fs.h"
 
 /*
@@ -50,7 +51,7 @@
 		virtual bool isDirectory() const { return _isDirectory; }
 		virtual String path() const { return _path; }
 
-		virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
+		virtual FSList listDir(ListMode mode) const;
 		static  FSList listRoot();
 		virtual AbstractFilesystemNode *parent() const;
 		virtual AbstractFilesystemNode *child(const String &name) const;
@@ -161,8 +162,8 @@
 			String full_path;
 			BPTR lock;
 
-			if ((fib->fib_EntryType > 0 && (mode & kListDirectoriesOnly)) ||
-				 (fib->fib_EntryType < 0 && (mode & kListFilesOnly)))
+			if ((fib->fib_EntryType > 0 && (mode & FilesystemNode::kListDirectoriesOnly)) ||
+				 (fib->fib_EntryType < 0 && (mode & FilesystemNode::kListFilesOnly)))
 			{
 				full_path = _path;
 				full_path += fib->fib_FileName;

Modified: scummvm/trunk/backends/fs/palmos/palmos-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/palmos/palmos-fs.cpp	2006-05-03 10:12:42 UTC (rev 22296)
+++ scummvm/trunk/backends/fs/palmos/palmos-fs.cpp	2006-05-03 10:14:05 UTC (rev 22297)
@@ -62,8 +62,8 @@
 
 	isDirectory = (find_data->attributes & vfsFileAttrDirectory);
 
-	if ((!isDirectory && mode == kListDirectoriesOnly) ||
-		(isDirectory && mode == kListFilesOnly))
+	if ((!isDirectory && mode == FilesystemNode::kListDirectoriesOnly) ||
+		(isDirectory && mode == FilesystemNode::kListFilesOnly))
 		return;
 
 	entry._isDirectory = isDirectory;

Modified: scummvm/trunk/backends/fs/posix/posix-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/posix/posix-fs.cpp	2006-05-03 10:12:42 UTC (rev 22296)
+++ scummvm/trunk/backends/fs/posix/posix-fs.cpp	2006-05-03 10:14:05 UTC (rev 22297)
@@ -23,6 +23,7 @@
 
 #include "common/stdafx.h"
 
+#include "backends/fs/abstract-fs.h"
 #include "backends/fs/fs.h"
 
 #ifdef MACOSX
@@ -56,7 +57,7 @@
 	virtual bool isDirectory() const { return _isDirectory; }
 	virtual String path() const { return _path; }
 
-	virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
+	virtual FSList listDir(ListMode mode) const;
 	virtual AbstractFilesystemNode *parent() const;
 	virtual AbstractFilesystemNode *child(const String &name) const;
 };
@@ -185,8 +186,8 @@
 			continue;
 
 		// Honor the chosen mode
-		if ((mode == kListFilesOnly && entry._isDirectory) ||
-			(mode == kListDirectoriesOnly && !entry._isDirectory))
+		if ((mode == FilesystemNode::kListFilesOnly && entry._isDirectory) ||
+			(mode == FilesystemNode::kListDirectoriesOnly && !entry._isDirectory))
 			continue;
 
 		if (entry._isDirectory)

Modified: scummvm/trunk/backends/fs/ps2/ps2-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/ps2/ps2-fs.cpp	2006-05-03 10:12:42 UTC (rev 22296)
+++ scummvm/trunk/backends/fs/ps2/ps2-fs.cpp	2006-05-03 10:14:05 UTC (rev 22297)
@@ -19,6 +19,8 @@
  * $Id$
  */
 
+#include "common/stdafx.h"
+#include "backends/fs/abstract-fs.h"
 #include "backends/fs/fs.h"
 #include <kernel.h>
 #include <stdio.h>
@@ -88,10 +90,10 @@
 	sprintf(listDir, "%s/", _path.c_str() + 5);
 
 	switch(mode) {
-		case kListFilesOnly:
+		case FilesystemNode::kListFilesOnly:
 			files = CDVD_GetDir(listDir, NULL, CDVD_GET_FILES_ONLY, tocEntries, MAX_LIST_ENTRIES, NULL);
 			break;
-		case kListDirectoriesOnly:
+		case FilesystemNode::kListDirectoriesOnly:
 			files = CDVD_GetDir(listDir, NULL, CDVD_GET_DIRS_ONLY, tocEntries, MAX_LIST_ENTRIES, NULL);
 			break;
 		default:

Modified: scummvm/trunk/backends/fs/symbian/symbian-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/symbian/symbian-fs.cpp	2006-05-03 10:12:42 UTC (rev 22296)
+++ scummvm/trunk/backends/fs/symbian/symbian-fs.cpp	2006-05-03 10:14:05 UTC (rev 22297)
@@ -24,6 +24,7 @@
 
 #if defined (__SYMBIAN32__) 
 #include "common/stdafx.h"
+#include "backends/fs/abstract-fs.h"
 #include "backends/fs/fs.h"
 
 #include <dirent.h>
@@ -51,7 +52,7 @@
 	virtual bool isDirectory() const { return _isDirectory; }
 	virtual String path() const { return _path; }
 
-	virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
+	virtual FSList listDir(ListMode mode) const;
 	virtual AbstractFilesystemNode *parent() const;
 	virtual AbstractFilesystemNode *child(const String &name) const;
 };
@@ -166,8 +167,8 @@
 				entry._isDirectory = fileentry.IsDir();
 				
 				// Honor the chosen mode
-				if ((mode == kListFilesOnly && entry._isDirectory) ||
-					(mode == kListDirectoriesOnly && !entry._isDirectory))
+				if ((mode == FilesystemNode::kListFilesOnly && entry._isDirectory) ||
+					(mode == FilesystemNode::kListDirectoriesOnly && !entry._isDirectory))
 					continue;
 				
 				if (entry._isDirectory)

Modified: scummvm/trunk/backends/fs/windows/windows-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/windows/windows-fs.cpp	2006-05-03 10:12:42 UTC (rev 22296)
+++ scummvm/trunk/backends/fs/windows/windows-fs.cpp	2006-05-03 10:14:05 UTC (rev 22297)
@@ -22,6 +22,7 @@
 #ifdef WIN32
 
 #include "common/stdafx.h"
+#include "backends/fs/abstract-fs.h"
 #include "backends/fs/fs.h"
 #include <stdio.h>
 #include <stdlib.h>
@@ -103,8 +104,8 @@
 
 	isDirectory = (find_data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? true : false);
 
-	if ((!isDirectory && mode == kListDirectoriesOnly) ||
-		(isDirectory && mode == kListFilesOnly))
+	if ((!isDirectory && mode == FilesystemNode::kListDirectoriesOnly) ||
+		(isDirectory && mode == FilesystemNode::kListFilesOnly))
 		return;
 
 	entry._isDirectory = isDirectory;


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