[Scummvm-cvs-logs] SF.net SVN: scummvm:[38787] scummvm/trunk/common

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Feb 22 17:48:02 CET 2009


Revision: 38787
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38787&view=rev
Author:   fingolfin
Date:     2009-02-22 16:48:02 +0000 (Sun, 22 Feb 2009)

Log Message:
-----------
Modified FSDirectory::lookupCache to return a FSNode *pointer*, so that we can distinguish between lookup failures and invalid cache entries. Also changed SearchSet::createReadStreamForMember to not use hasFile anymore, based on the assumption that any Archive::createReadStreamForMember implementation has to verify whether the member name is valid anyway (clarified the doxygen docs accordingly)

Modified Paths:
--------------
    scummvm/trunk/common/archive.cpp
    scummvm/trunk/common/archive.h
    scummvm/trunk/common/fs.h

Modified: scummvm/trunk/common/archive.cpp
===================================================================
--- scummvm/trunk/common/archive.cpp	2009-02-22 16:27:48 UTC (rev 38786)
+++ scummvm/trunk/common/archive.cpp	2009-02-22 16:48:02 UTC (rev 38787)
@@ -99,49 +99,51 @@
 	return _node;
 }
 
-FSNode FSDirectory::lookupCache(NodeCache &cache, const String &name) const {
+FSNode *FSDirectory::lookupCache(NodeCache &cache, const String &name) const {
 	// make caching as lazy as possible
 	if (!name.empty()) {
 		ensureCached();
 
 		if (cache.contains(name))
-			return cache[name];
+			return &cache[name];
 	}
 
-	return FSNode();
+	return 0;
 }
 
 bool FSDirectory::hasFile(const String &name) {
 	if (name.empty() || !_node.isDirectory())
 		return false;
 
-	FSNode node = lookupCache(_fileCache, name);
-	return node.exists();
+	FSNode *node = lookupCache(_fileCache, name);
+	return node && node->exists();
 }
 
 ArchiveMemberPtr FSDirectory::getMember(const String &name) {
 	if (name.empty() || !_node.isDirectory())
 		return ArchiveMemberPtr();
 
-	FSNode node = lookupCache(_fileCache, name);
+	FSNode *node = lookupCache(_fileCache, name);
 
-	if (!node.exists()) {
+	if (!node || !node->exists()) {
 		warning("FSDirectory::getMember: FSNode does not exist");
 		return ArchiveMemberPtr();
-	} else if (node.isDirectory()) {
+	} else if (node->isDirectory()) {
 		warning("FSDirectory::getMember: FSNode is a directory");
 		return ArchiveMemberPtr();
 	}
 
-	return ArchiveMemberPtr(new FSNode(node));
+	return ArchiveMemberPtr(new FSNode(*node));
 }
 
 SeekableReadStream *FSDirectory::createReadStreamForMember(const String &name) const {
 	if (name.empty() || !_node.isDirectory())
 		return 0;
 
-	FSNode node = lookupCache(_fileCache, name);
-	SeekableReadStream *stream = node.createReadStream();
+	FSNode *node = lookupCache(_fileCache, name);
+	if (!node)
+		return 0;
+	SeekableReadStream *stream = node->createReadStream();
 	if (!stream)
 		warning("FSDirectory::createReadStreamForMember: Can't create stream for file '%s'", name.c_str());
 
@@ -156,8 +158,11 @@
 	if (name.empty() || !_node.isDirectory())
 		return 0;
 
-	FSNode node = lookupCache(_subDirCache, name);
-	return new FSDirectory(prefix, node, depth);
+	FSNode *node = lookupCache(_subDirCache, name);
+	if (!node)
+		return 0;
+
+	return new FSDirectory(prefix, *node, depth);
 }
 
 void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) const {
@@ -380,8 +385,9 @@
 
 	ArchiveNodeList::iterator it = _list.begin();
 	for ( ; it != _list.end(); ++it) {
-		if (it->_arc->hasFile(name))
-			return it->_arc->createReadStreamForMember(name);
+		SeekableReadStream *stream = it->_arc->createReadStreamForMember(name);
+		if (stream)
+			return stream;
 	}
 
 	return 0;

Modified: scummvm/trunk/common/archive.h
===================================================================
--- scummvm/trunk/common/archive.h	2009-02-22 16:27:48 UTC (rev 38786)
+++ scummvm/trunk/common/archive.h	2009-02-22 16:48:02 UTC (rev 38787)
@@ -116,7 +116,8 @@
 	virtual ArchiveMemberPtr getMember(const String &name) = 0;
 
 	/**
-	 * Create a stream bound to a file in the archive.
+	 * Create a stream bound to a member in the archive. If no member with the
+	 * specified name exists, then 0 is returned.
 	 * @return the newly created input stream
 	 */
 	virtual SeekableReadStream *createReadStreamForMember(const String &name) const = 0;

Modified: scummvm/trunk/common/fs.h
===================================================================
--- scummvm/trunk/common/fs.h	2009-02-22 16:27:48 UTC (rev 38786)
+++ scummvm/trunk/common/fs.h	2009-02-22 16:48:02 UTC (rev 38787)
@@ -268,7 +268,7 @@
 	mutable int	_depth;
 
 	// look for a match
-	FSNode lookupCache(NodeCache &cache, const String &name) const;
+	FSNode *lookupCache(NodeCache &cache, const String &name) const;
 
 	// cache management
 	void cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) const;


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