From 9861afd8fde386ffc740ab12fad26f2d41213821 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 23 Jan 2009 04:36:18 +0000 Subject: Renamed ArchiveMember::open -> createReadStream, and made it a cv member (const); same for Archive::openFile svn-id: r36020 --- common/archive.cpp | 12 ++++++------ common/archive.h | 8 ++++---- common/fs.h | 25 +++++++++++-------------- common/unzip.cpp | 2 +- common/unzip.h | 2 +- 5 files changed, 23 insertions(+), 26 deletions(-) (limited to 'common') diff --git a/common/archive.cpp b/common/archive.cpp index 1a78f4629a..614215685a 100644 --- a/common/archive.cpp +++ b/common/archive.cpp @@ -38,7 +38,7 @@ String GenericArchiveMember::getName() const { return _name; } -SeekableReadStream *GenericArchiveMember::open() { +SeekableReadStream *GenericArchiveMember::createReadStream() const { return _parent->openFile(_name); } @@ -99,7 +99,7 @@ FSNode FSDirectory::getFSNode() const { return _node; } -FSNode FSDirectory::lookupCache(NodeCache &cache, const String &name) { +FSNode FSDirectory::lookupCache(NodeCache &cache, const String &name) const { // make caching as lazy as possible if (!name.empty()) { ensureCached(); @@ -136,7 +136,7 @@ ArchiveMemberPtr FSDirectory::getMember(const String &name) { return ArchiveMemberPtr(new FSNode(node)); } -SeekableReadStream *FSDirectory::openFile(const String &name) { +SeekableReadStream *FSDirectory::openFile(const String &name) const { if (name.empty() || !_node.isDirectory()) return 0; @@ -169,7 +169,7 @@ FSDirectory *FSDirectory::getSubDirectory(const String &prefix, const String &na return new FSDirectory(prefix, node, depth); } -void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) { +void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) const { if (depth <= 0) return; @@ -203,7 +203,7 @@ void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String& } -void FSDirectory::ensureCached() { +void FSDirectory::ensureCached() const { if (_cached) return; cacheDirectoryRecursive(_node, _depth, _prefix); @@ -434,7 +434,7 @@ ArchiveMemberPtr SearchSet::getMember(const String &name) { return ArchiveMemberPtr(); } -SeekableReadStream *SearchSet::openFile(const String &name) { +SeekableReadStream *SearchSet::openFile(const String &name) const { if (name.empty()) return 0; diff --git a/common/archive.h b/common/archive.h index db42df8546..ea556d199f 100644 --- a/common/archive.h +++ b/common/archive.h @@ -50,7 +50,7 @@ class SeekableReadStream; class ArchiveMember { public: virtual ~ArchiveMember() { } - virtual SeekableReadStream *open() = 0; + virtual SeekableReadStream *createReadStream() const = 0; virtual String getName() const = 0; virtual String getDisplayName() const { return getName(); } }; @@ -75,7 +75,7 @@ class GenericArchiveMember : public ArchiveMember { public: GenericArchiveMember(String name, Archive *parent); String getName() const; - SeekableReadStream *open(); + SeekableReadStream *createReadStream() const; }; @@ -120,7 +120,7 @@ public: * Create a stream bound to a file in the archive. * @return the newly created input stream */ - virtual SeekableReadStream *openFile(const String &name) = 0; + virtual SeekableReadStream *openFile(const String &name) const = 0; }; @@ -197,7 +197,7 @@ public: * Implements openFile from Archive base class. The current policy is * opening the first file encountered that matches the name. */ - virtual SeekableReadStream *openFile(const String &name); + virtual SeekableReadStream *openFile(const String &name) const; }; diff --git a/common/fs.h b/common/fs.h index 72b492e9c4..61ce21bec5 100644 --- a/common/fs.h +++ b/common/fs.h @@ -223,11 +223,6 @@ public: * @return pointer to the stream object, 0 in case of a failure */ virtual WriteStream *createWriteStream() const; - - // Compatibility with ArchiveMember API. - SeekableReadStream *open() { - return createReadStream(); - } }; /** @@ -262,22 +257,24 @@ public: class FSDirectory : public Archive { FSNode _node; + String _prefix; // string that is prepended to each cache item key + void setPrefix(const String &prefix); + // Caches are case insensitive, clashes are dealt with when creating // Key is stored in lowercase. typedef HashMap NodeCache; - NodeCache _fileCache, _subDirCache; - String _prefix; // string that is prepended to each cache item key - void setPrefix(const String &prefix); + mutable NodeCache _fileCache, _subDirCache; + mutable bool _cached; + mutable int _depth; // look for a match - FSNode lookupCache(NodeCache &cache, const String &name); + FSNode lookupCache(NodeCache &cache, const String &name) const; // cache management - void cacheDirectoryRecursive(FSNode node, int depth, const String& prefix); + void cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) const; + // fill cache if not already cached - void ensureCached(); - bool _cached; - int _depth; + void ensureCached() const; public: /** @@ -336,7 +333,7 @@ public: * Open the specified file. A full match of relative path and filename is needed * for success. */ - virtual SeekableReadStream *openFile(const String &name); + virtual SeekableReadStream *openFile(const String &name) const; }; diff --git a/common/unzip.cpp b/common/unzip.cpp index 25e26ec24c..9b102872f8 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -1428,7 +1428,7 @@ ArchiveMemberPtr ZipArchive::getMember(const String &name) { return ArchiveMemberPtr(new GenericArchiveMember(name, this)); } -Common::SeekableReadStream *ZipArchive::openFile(const Common::String &name) { +Common::SeekableReadStream *ZipArchive::openFile(const Common::String &name) const { if (!_zipFile) return 0; diff --git a/common/unzip.h b/common/unzip.h index 358bf6cbba..970a84ad57 100644 --- a/common/unzip.h +++ b/common/unzip.h @@ -62,7 +62,7 @@ public: virtual bool hasFile(const String &name); virtual int listMembers(ArchiveMemberList &list); virtual ArchiveMemberPtr getMember(const String &name); - virtual SeekableReadStream *openFile(const String &name); + virtual SeekableReadStream *openFile(const String &name) const; }; } // End of namespace Common -- cgit v1.2.3