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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Apr 30 15:53:01 CEST 2006


Revision: 22249
Author:   fingolfin
Date:     2006-04-30 15:52:10 -0700 (Sun, 30 Apr 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22249&view=rev

Log Message:
-----------
Added new AbstractFilesystemNode::child() resp. FilesystemNode::getChild() methods

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
Modified: scummvm/trunk/backends/fs/amigaos4/amigaos4-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/amigaos4/amigaos4-fs.cpp	2006-04-30 20:36:14 UTC (rev 22248)
+++ scummvm/trunk/backends/fs/amigaos4/amigaos4-fs.cpp	2006-04-30 22:52:10 UTC (rev 22249)
@@ -71,6 +71,7 @@
 		virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
 		virtual FSList listVolumes(void) const;
 		virtual AbstractFilesystemNode *parent() const;
+		virtual AbstractFilesystemNode *child(const String &name) const;
 };
 
 AbstractFilesystemNode *FilesystemNode::getRoot() {
@@ -323,6 +324,10 @@
 	return node;
 }
 
+AbstractFilesystemNode *AmigaOSFilesystemNode::child(const String &name) const {
+	TODO
+}
+
 FSList AmigaOSFilesystemNode::listVolumes(void)	const {
 	ENTER();
 

Modified: scummvm/trunk/backends/fs/fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/fs.cpp	2006-04-30 20:36:14 UTC (rev 22248)
+++ scummvm/trunk/backends/fs/fs.cpp	2006-04-30 22:52:10 UTC (rev 22249)
@@ -84,6 +84,9 @@
 }
 
 FilesystemNode FilesystemNode::getParent() const {
+	if (_realNode == 0)
+		return *this;
+
 	AbstractFilesystemNode *node = _realNode->parent();
 	if (node == 0) {
 		return *this;
@@ -92,22 +95,39 @@
 	}
 }
 
+FilesystemNode FilesystemNode::getChild(const String &name) const {
+	if (_realNode == 0)
+		return *this;
+
+	assert(_realNode->isDirectory());
+	AbstractFilesystemNode *node = _realNode->child(name);
+	return AbstractFilesystemNode::wrap(node);
+}
+
+FSList FilesystemNode::listDir(ListMode mode) const {
+	assert(_realNode);
+	assert(_realNode->isDirectory());
+	return _realNode->listDir(mode);
+}
+
 Common::String FilesystemNode::displayName() const {
+	assert(_realNode);
 	return _realNode->displayName();
 }
 
 bool FilesystemNode::isValid() const {
+	if (_realNode == 0)
+		return false;
 	return _realNode->isValid();
 }
 
 bool FilesystemNode::isDirectory() const {
+	if (_realNode == 0)
+		return false;
 	return _realNode->isDirectory();
 }
 
 Common::String FilesystemNode::path() const {
+	assert(_realNode);
 	return _realNode->path();
 }
-
-FSList FilesystemNode::listDir(ListMode mode) const {
-	return _realNode->listDir(mode);
-}

Modified: scummvm/trunk/backends/fs/fs.h
===================================================================
--- scummvm/trunk/backends/fs/fs.h	2006-04-30 20:36:14 UTC (rev 22248)
+++ scummvm/trunk/backends/fs/fs.h	2006-04-30 22:52:10 UTC (rev 22249)
@@ -81,6 +81,13 @@
 	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
@@ -104,29 +111,45 @@
 	virtual ~AbstractFilesystemNode() {}
 
 	/**
-	 * Return display name, used by e.g. the GUI to present the file in the file browser.
+	 * 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 (i.e. referring to an actual FS object)?
+	 * 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 a directory or not?
+	 * 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;
 
 	/**
-	 * A path representation suitable for use with fopen()
+	 * 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;
 
 	/**
-	 * List the content of this directory node.
-	 * If this node is not a directory, throw an exception or call error().
+	 * 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;
 
@@ -189,27 +212,43 @@
 
 
 public:
+	/**
+	 * Create a new FilesystemNode refering to the specified path. This is
+	 * the counterpart to the path() method.
+	 */
+	FilesystemNode(const String &path);
+
+
 	FilesystemNode();
 	FilesystemNode(const FilesystemNode &node);
-	FilesystemNode(const String &path);
 	~FilesystemNode();
 
 	FilesystemNode &operator  =(const FilesystemNode &node);
 
+	/**
+	 * Get the parent node of this node. If this node has no parent node,
+	 * then it returns a duplicate of this node.
+	 */
 	FilesystemNode getParent() const;
 
+	/**
+	 * Fetch a child node of this node, with the given name. Only valid for
+	 * directory nodes (an assertion is triggered otherwise). If no no child
+	 * node with the given name exists, an invalid node is returned.
+	 */
+	FilesystemNode getChild(const String &name) const;
 
+	virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
 	virtual String displayName() const;
 	virtual bool isValid() const;
 	virtual bool isDirectory() const;
 	virtual String path() const;
 
-	virtual FSList listDir(ListMode mode = kListDirectoriesOnly) 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-04-30 20:36:14 UTC (rev 22248)
+++ scummvm/trunk/backends/fs/morphos/abox-fs.cpp	2006-04-30 22:52:10 UTC (rev 22249)
@@ -53,6 +53,7 @@
 		virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
 		static  FSList listRoot();
 		virtual AbstractFilesystemNode *parent() const;
+		virtual AbstractFilesystemNode *child(const String &name) const;
 };
 
 
@@ -212,6 +213,10 @@
 	return node;
 }
 
+AbstractFilesystemNode *ABoxFilesystemNode::child(const String &name) const {
+	TODO
+}
+
 FSList ABoxFilesystemNode::listRoot()
 {
 	FSList myList;

Modified: scummvm/trunk/backends/fs/palmos/palmos-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/palmos/palmos-fs.cpp	2006-04-30 20:36:14 UTC (rev 22248)
+++ scummvm/trunk/backends/fs/palmos/palmos-fs.cpp	2006-04-30 22:52:10 UTC (rev 22249)
@@ -50,6 +50,7 @@
 
 	virtual FSList listDir(ListMode) const;
 	virtual AbstractFilesystemNode *parent() const;
+	virtual AbstractFilesystemNode *child(const String &name) const;
 
 private:
 	static void addFile (FSList &list, ListMode mode, const Char *base, FileInfoType* find_data);
@@ -170,4 +171,9 @@
 	return p;
 }
 
+
+AbstractFilesystemNode *PalmOSFilesystemNode::child(const String &name) const {
+	TODO
+}
+
 #endif // PALMOS_MODE

Modified: scummvm/trunk/backends/fs/posix/posix-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/posix/posix-fs.cpp	2006-04-30 20:36:14 UTC (rev 22248)
+++ scummvm/trunk/backends/fs/posix/posix-fs.cpp	2006-04-30 22:52:10 UTC (rev 22249)
@@ -49,7 +49,7 @@
 
 public:
 	POSIXFilesystemNode();
-	POSIXFilesystemNode(const String &path, bool useStat = false);
+	POSIXFilesystemNode(const String &path, bool verify = false);
 
 	virtual String displayName() const { return _displayName; }
 	virtual bool isValid() const { return _isValid; }
@@ -58,6 +58,7 @@
 
 	virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
 	virtual AbstractFilesystemNode *parent() const;
+	virtual AbstractFilesystemNode *child(const String &name) const;
 };
 
 
@@ -103,7 +104,7 @@
 	_isDirectory = true;
 }
 
-POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool useStat) {
+POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool verify) {
 	assert(p.size() > 0);
 
 	_path = p;
@@ -111,13 +112,21 @@
 	_isValid = true;
 	_isDirectory = true;
 
-#ifndef __DC__
-	if (useStat) {
+	if (verify) {
+#ifdef __DC__
+		FIXME;
+		/*
+		FIXME: Is there really no way to at least verify the path is valid?
+		Or is it too slow, or what? Please clarify with a comment here.
+		(Of course we could just fopen here, but that wouldn't be able to deal
+		with directories...
+		*/
+#else
 		struct stat st;
 		_isValid = (0 == stat(_path.c_str(), &st));
 		_isDirectory = S_ISDIR(st.st_mode);
+#endif
 	}
-#endif
 }
 
 FSList POSIXFilesystemNode::listDir(ListMode mode) const {
@@ -200,4 +209,17 @@
 	return p;
 }
 
+AbstractFilesystemNode *POSIXFilesystemNode::child(const String &name) const {
+	// FIXME: Pretty lame implementation! We do no error checking to speak
+	// of, do not check if this is a special node, etc.
+	assert(_isDirectory);
+	String newPath(_path);
+	if (_path.lastChar() != '/')
+		newPath += '/';
+	newPath += name;
+	POSIXFilesystemNode *p = new POSIXFilesystemNode(newPath, true);
+
+	return p;
+}
+
 #endif // defined(UNIX)

Modified: scummvm/trunk/backends/fs/ps2/ps2-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/ps2/ps2-fs.cpp	2006-04-30 20:36:14 UTC (rev 22248)
+++ scummvm/trunk/backends/fs/ps2/ps2-fs.cpp	2006-04-30 22:52:10 UTC (rev 22249)
@@ -45,6 +45,8 @@
 
 	virtual FSList listDir(ListMode) const;
 	virtual AbstractFilesystemNode *parent() const;
+	virtual AbstractFilesystemNode *child(const String &name) const;
+
 	virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); }
 };
 
@@ -135,3 +137,7 @@
 	return p;
 }
 
+
+AbstractFilesystemNode *Ps2FilesystemNode::child(const String &name) const {
+	TODO
+}

Modified: scummvm/trunk/backends/fs/symbian/symbian-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/symbian/symbian-fs.cpp	2006-04-30 20:36:14 UTC (rev 22248)
+++ scummvm/trunk/backends/fs/symbian/symbian-fs.cpp	2006-04-30 22:52:10 UTC (rev 22249)
@@ -52,6 +52,7 @@
 
 	virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
 	virtual AbstractFilesystemNode *parent() const;
+	virtual AbstractFilesystemNode *child(const String &name) const;
 };
 
 
@@ -198,4 +199,8 @@
 	return p;
 }
 
+AbstractFilesystemNode *SymbianFilesystemNode::child(const String &name) const {
+	TODO
+}
+
 #endif // defined(__SYMBIAN32__)

Modified: scummvm/trunk/backends/fs/windows/windows-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/windows/windows-fs.cpp	2006-04-30 20:36:14 UTC (rev 22248)
+++ scummvm/trunk/backends/fs/windows/windows-fs.cpp	2006-04-30 22:52:10 UTC (rev 22249)
@@ -51,6 +51,7 @@
 
 	virtual FSList listDir(ListMode) const;
 	virtual AbstractFilesystemNode *parent() const;
+	virtual AbstractFilesystemNode *child(const String &name) const;
 
 private:
 	static char *toAscii(TCHAR *x);
@@ -228,4 +229,8 @@
 	return p;
 }
 
+AbstractFilesystemNode *WindowsFilesystemNode::child(const String &name) const {
+	TODO
+}
+
 #endif // WIN32


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