ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

fs.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_FS_H
00024 #define COMMON_FS_H
00025 
00026 #include "common/array.h"
00027 #include "common/archive.h"
00028 #include "common/hash-str.h"
00029 #include "common/hashmap.h"
00030 #include "common/ptr.h"
00031 #include "common/str.h"
00032 
00033 class AbstractFSNode;
00034 
00035 namespace Common {
00036 
00037 class FSNode;
00038 class SeekableReadStream;
00039 class WriteStream;
00040 
00046 class FSList : public Array<FSNode> {};
00047 
00058 class FSNode : public ArchiveMember {
00059 private:
00060     friend class ::AbstractFSNode;
00061     SharedPtr<AbstractFSNode>   _realNode;
00068     FSNode(AbstractFSNode *realNode);
00069 
00070 public:
00074     enum ListMode {
00075         kListFilesOnly = 1,
00076         kListDirectoriesOnly = 2,
00077         kListAll = 3
00078     };
00079 
00085     FSNode();
00086 
00096     explicit FSNode(const String &path);
00097 
00098     virtual ~FSNode() {}
00099 
00104     bool operator<(const FSNode& node) const;
00105 
00111     bool exists() const;
00112 
00130     FSNode getChild(const String &name) const;
00131 
00138     bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly, bool hidden = true) const;
00139 
00147     virtual String getDisplayName() const;
00148 
00157     virtual String getName() const;
00158 
00171     String getPath() const;
00172 
00177     FSNode getParent() const;
00178 
00188     bool isDirectory() const;
00189 
00201     bool isReadable() const;
00202 
00214     bool isWritable() const;
00215 
00223     virtual SeekableReadStream *createReadStream() const;
00224 
00232     WriteStream *createWriteStream() const;
00233 
00241     bool createDirectory() const;
00242 };
00243 
00284 class FSDirectory : public Archive {
00285     FSNode _node;
00286     int _depth;
00287     bool _flat;
00288     bool _ignoreClashes;
00289 
00290     String  _prefix; // string that is prepended to each cache item key
00291     void setPrefix(const String &prefix);
00292 
00293     // Caches are case insensitive, clashes are dealt with when creating
00294     // Key is stored in lowercase.
00295     typedef HashMap<String, FSNode, IgnoreCase_Hash, IgnoreCase_EqualTo> NodeCache;
00296     mutable NodeCache   _fileCache, _subDirCache;
00297     mutable bool _cached;
00298 
00299     // look for a match
00300     FSNode *lookupCache(NodeCache &cache, const String &name) const;
00301 
00302     // cache management
00303     void cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) const;
00304 
00305     // fill cache if not already cached
00306     void ensureCached() const;
00307 
00308 public:
00314     FSDirectory(const String &name, int depth = 1, bool flat = false,
00315                 bool ignoreClashes = false);
00316     FSDirectory(const FSNode &node, int depth = 1, bool flat = false,
00317                 bool ignoreClashes = false);
00318 
00323     FSDirectory(const String &prefix, const String &name, int depth = 1,
00324                 bool flat = false, bool ignoreClashes = false);
00325     FSDirectory(const String &prefix, const FSNode &node, int depth = 1,
00326                 bool flat = false, bool ignoreClashes = false);
00327 
00328     virtual ~FSDirectory();
00329 
00333     FSNode getFSNode() const;
00334 
00340     FSDirectory *getSubDirectory(const String &name, int depth = 1, bool flat = false,
00341                                  bool ignoreClashes = false);
00342     FSDirectory *getSubDirectory(const String &prefix, const String &name, int depth = 1,
00343                                  bool flat = false, bool ignoreClashes = false);
00344 
00349     virtual bool hasFile(const String &name) const;
00350 
00354     virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern) const;
00355 
00359     virtual int listMembers(ArchiveMemberList &list) const;
00360 
00365     virtual const ArchiveMemberPtr getMember(const String &name) const;
00366 
00371     virtual SeekableReadStream *createReadStreamForMember(const String &name) const;
00372 };
00373 
00374 
00375 } // End of namespace Common
00376 
00377 #endif //COMMON_FS_H


Generated on Sat Mar 28 2020 05:00:34 for ResidualVM by doxygen 1.7.1
curved edge   curved edge