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 };
00234 
00269 class FSDirectory : public Archive {
00270     FSNode  _node;
00271 
00272     String  _prefix; // string that is prepended to each cache item key
00273     void setPrefix(const String &prefix);
00274 
00275     // Caches are case insensitive, clashes are dealt with when creating
00276     // Key is stored in lowercase.
00277     typedef HashMap<String, FSNode, IgnoreCase_Hash, IgnoreCase_EqualTo> NodeCache;
00278     mutable NodeCache   _fileCache, _subDirCache;
00279     mutable bool _cached;
00280     mutable int _depth;
00281     mutable bool _flat;
00282 
00283     // look for a match
00284     FSNode *lookupCache(NodeCache &cache, const String &name) const;
00285 
00286     // cache management
00287     void cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) const;
00288 
00289     // fill cache if not already cached
00290     void ensureCached() const;
00291 
00292 public:
00298     FSDirectory(const String &name, int depth = 1, bool flat = false);
00299     FSDirectory(const FSNode &node, int depth = 1, bool flat = false);
00300 
00305     FSDirectory(const String &prefix, const String &name, int depth = 1,
00306                 bool flat = false);
00307     FSDirectory(const String &prefix, const FSNode &node, int depth = 1,
00308                 bool flat = false);
00309 
00310     virtual ~FSDirectory();
00311 
00315     FSNode getFSNode() const;
00316 
00322     FSDirectory *getSubDirectory(const String &name, int depth = 1, bool flat = false);
00323     FSDirectory *getSubDirectory(const String &prefix, const String &name, int depth = 1, bool flat = false);
00324 
00329     virtual bool hasFile(const String &name) const;
00330 
00334     virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern) const;
00335 
00339     virtual int listMembers(ArchiveMemberList &list) const;
00340 
00345     virtual const ArchiveMemberPtr getMember(const String &name) const;
00346 
00351     virtual SeekableReadStream *createReadStreamForMember(const String &name) const;
00352 };
00353 
00354 
00355 } // End of namespace Common
00356 
00357 #endif //COMMON_FS_H


Generated on Sat Feb 16 2019 05:00:51 for ResidualVM by doxygen 1.7.1
curved edge   curved edge