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

common/archive.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_ARCHIVE_H
00024 #define COMMON_ARCHIVE_H
00025 
00026 #include "common/str.h"
00027 #include "common/list.h"
00028 #include "common/ptr.h"
00029 #include "common/singleton.h"
00030 
00031 namespace Common {
00032 
00033 class FSNode;
00034 class SeekableReadStream;
00035 
00036 
00045 class ArchiveMember {
00046 public:
00047     virtual ~ArchiveMember() { }
00048     virtual SeekableReadStream *createReadStream() const = 0;
00049     virtual String getName() const = 0;
00050     virtual String getDisplayName() const { return getName(); }
00051 };
00052 
00053 typedef SharedPtr<ArchiveMember> ArchiveMemberPtr;
00054 typedef List<ArchiveMemberPtr> ArchiveMemberList;
00055 
00056 struct ArchiveMemberListComparator {
00057     bool operator()(const ArchiveMemberPtr &a, const ArchiveMemberPtr &b) {
00058         return a->getName() < b->getName();
00059     }
00060 };
00061 
00062 class Archive;
00063 
00073 class GenericArchiveMember : public ArchiveMember {
00074     const Archive *_parent;
00075     const String _name;
00076 public:
00077     GenericArchiveMember(const String &name, const Archive *parent);
00078     String getName() const;
00079     SeekableReadStream *createReadStream() const;
00080 };
00081 
00082 
00088 class Archive {
00089 public:
00090     virtual ~Archive() { }
00091 
00097     virtual bool hasFile(const String &name) const = 0;
00098 
00105     virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern) const;
00106 
00113     virtual int listMembers(ArchiveMemberList &list) const = 0;
00114 
00118     virtual const ArchiveMemberPtr getMember(const String &name) const = 0;
00119 
00125     virtual SeekableReadStream *createReadStreamForMember(const String &name) const = 0;
00126 };
00127 
00128 
00136 class SearchSet : public Archive {
00137     struct Node {
00138         int     _priority;
00139         String  _name;
00140         Archive *_arc;
00141         bool    _autoFree;
00142         Node(int priority, const String &name, Archive *arc, bool autoFree)
00143             : _priority(priority), _name(name), _arc(arc), _autoFree(autoFree) {
00144         }
00145     };
00146     typedef List<Node> ArchiveNodeList;
00147     ArchiveNodeList _list;
00148 
00149     ArchiveNodeList::iterator find(const String &name);
00150     ArchiveNodeList::const_iterator find(const String &name) const;
00151 
00152     // Add an archive keeping the list sorted by descending priority.
00153     void insert(const Node& node);
00154 
00155 public:
00156     virtual ~SearchSet() { clear(); }
00157 
00161     void add(const String& name, Archive *arch, int priority = 0, bool autoFree = true);
00162 
00166     void addDirectory(const String &name, const String &directory, int priority = 0, int depth = 1, bool flat = false);
00167 
00171     void addDirectory(const String &name, const FSNode &directory, int priority = 0, int depth = 1, bool flat = false);
00172 
00193     void addSubDirectoryMatching(const FSNode &directory, const String &caselessName, int priority = 0, int depth = 1, bool flat = false) {
00194         addSubDirectoriesMatching(directory, caselessName, true, priority, depth, flat);
00195     }
00196 
00217     void addSubDirectoriesMatching(const FSNode &directory, String origPattern, bool ignoreCase, int priority = 0, int depth = 1, bool flat = false);
00218 
00222     void remove(const String& name);
00223 
00227     bool hasArchive(const String &name) const;
00228 
00232     virtual void clear();
00233 
00237     void setPriority(const String& name, int priority);
00238 
00239     virtual bool hasFile(const String &name) const;
00240     virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern) const;
00241     virtual int listMembers(ArchiveMemberList &list) const;
00242 
00243     virtual const ArchiveMemberPtr getMember(const String &name) const;
00244 
00249     virtual SeekableReadStream *createReadStreamForMember(const String &name) const;
00250 };
00251 
00252 
00253 class SearchManager : public Singleton<SearchManager>, public SearchSet {
00254 public:
00255 
00260     virtual void clear();
00261 
00262 private:
00263     friend class Singleton<SingletonBaseType>;
00264     SearchManager();
00265 };
00266 
00268 #define SearchMan       Common::SearchManager::instance()
00269 
00270 } // namespace Common
00271 
00272 #endif


Generated on Sat May 25 2019 05:00:38 for ResidualVM by doxygen 1.7.1
curved edge   curved edge