aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-02-22 16:48:02 +0000
committerMax Horn2009-02-22 16:48:02 +0000
commit9b45dd2849359c1dd2405ef9f957625c9ca80b6e (patch)
tree308e297345334fac48db6b832706b946db694d12
parentc397b37bfb2bbd0cd304e1f45c1323c726a120f2 (diff)
downloadscummvm-rg350-9b45dd2849359c1dd2405ef9f957625c9ca80b6e.tar.gz
scummvm-rg350-9b45dd2849359c1dd2405ef9f957625c9ca80b6e.tar.bz2
scummvm-rg350-9b45dd2849359c1dd2405ef9f957625c9ca80b6e.zip
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)
svn-id: r38787
-rw-r--r--common/archive.cpp36
-rw-r--r--common/archive.h3
-rw-r--r--common/fs.h2
3 files changed, 24 insertions, 17 deletions
diff --git a/common/archive.cpp b/common/archive.cpp
index 8add12e570..88c56d4908 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -99,49 +99,51 @@ FSNode FSDirectory::getFSNode() const {
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 @@ FSDirectory *FSDirectory::getSubDirectory(const String &prefix, const String &na
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 @@ SeekableReadStream *SearchSet::createReadStreamForMember(const String &name) con
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;
diff --git a/common/archive.h b/common/archive.h
index a7ebb8aa75..ba3445cc16 100644
--- a/common/archive.h
+++ b/common/archive.h
@@ -116,7 +116,8 @@ public:
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;
diff --git a/common/fs.h b/common/fs.h
index bfbbb532e0..1dcd07b1cf 100644
--- a/common/fs.h
+++ b/common/fs.h
@@ -268,7 +268,7 @@ class FSDirectory : public Archive {
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;