Ticket #8917: searchmanager.patch

File searchmanager.patch, 2.6 KB (added by peres, 13 years ago)

SearchManager.

  • archive.cpp

     
    293293        return 0;
    294294}
    295295
     296
     297
     298
     299DECLARE_SINGLETON(SearchManager);
     300
     301void SearchManager::addArchive(const String &name, ArchivePtr archive) {
     302        _searchSet.add(name, archive);
     303}
     304
     305void SearchManager::addDirectory(const String &name, const String &directory) {
     306        addDirectoryRecursive(name, 1);
     307}
     308
     309void SearchManager::addDirectoryRecursive(const String &name, const String &directory, int depth) {
     310        _searchSet.add(name, SharedPtr<FSDirectory>(new FSDirectory(directory, depth)));
     311}
     312
     313void SearchManager::remove(const String &name) {
     314        _searchSet.remove(name);
     315}
     316
     317void SearchManager::clear() {
     318        _searchSet.clear();
     319}
     320
     321bool SearchManager::hasFile(const String &name) {
     322        return _searchSet.hasFile(name);
     323}
     324
     325SeekableReadStream *SearchManager::openFile(const String &name) {
     326        return _searchSet.openFile(name);
     327}
     328
     329
    296330} // namespace Common
  • archive.h

     
    3131#include "common/hash-str.h"
    3232#include "common/list.h"
    3333#include "common/ptr.h"
     34#include "common/singleton.h"
    3435#include "common/stream.h"
    3536
    3637namespace Common {
     
    202203        virtual SeekableReadStream *openFile(const String &name);
    203204};
    204205
     206
     207
     208
     209class SearchManager : public Singleton<SearchManager>, public Archive {
     210
     211        SearchSet       _searchSet;
     212
     213public:
     214        /**
     215         *      Add an existing Archive. This is meant to support searching in system-specific
     216         *  archives, namely the MACOSX/IPHONE bundles.
     217         */
     218        void addArchive(const String &name, ArchivePtr archive);
     219
     220        /**
     221         *      Create and add a FSDirectory by name
     222         */
     223        void addDirectory(const String &name, const String &directory);
     224
     225        /**
     226         *      Create and add a FSDirectory and its subdirectories by name
     227         */
     228        void addDirectoryRecursive(const String &name, const String &directory, int depth = 4);
     229
     230        /**
     231         *      Remove an archive from the pool.
     232         */
     233        void remove(const String &name);
     234
     235        /**
     236         *      Clears the archive
     237         */
     238        void clear();
     239
     240
     241        virtual bool hasFile(const String &name);
     242        virtual int getAllNames(StringList &list) {
     243                return matchPattern(list, "*");
     244        }
     245
     246        /**
     247         * Implements openFile from Archive base class. The current policy is
     248         * opening the first file encountered that matches the name.
     249         */
     250        virtual SeekableReadStream *openFile(const String &name);
     251};
     252
     253/** Shortcut for accessing the search manager. */
     254#define SearchMan               Common::SearchManager::instance()
     255
    205256} // namespace Common
    206257
    207258#endif