Added first version of the SearchManager, as it is presented in patch tracker item 2093502.

svn-id: r34492
This commit is contained in:
Nicola Mettifogo 2008-09-11 13:24:01 +00:00
parent 224f95537b
commit 166386b581
2 changed files with 85 additions and 0 deletions

View File

@ -293,4 +293,38 @@ SeekableReadStream *SearchSet::openFile(const String &name) {
return 0;
}
DECLARE_SINGLETON(SearchManager);
void SearchManager::addArchive(const String &name, ArchivePtr archive) {
_searchSet.add(name, archive);
}
void SearchManager::addDirectory(const String &name, const String &directory) {
addDirectoryRecursive(name, 1);
}
void SearchManager::addDirectoryRecursive(const String &name, const String &directory, int depth) {
_searchSet.add(name, SharedPtr<FSDirectory>(new FSDirectory(directory, depth)));
}
void SearchManager::remove(const String &name) {
_searchSet.remove(name);
}
void SearchManager::clear() {
_searchSet.clear();
}
bool SearchManager::hasFile(const String &name) {
return _searchSet.hasFile(name);
}
SeekableReadStream *SearchManager::openFile(const String &name) {
return _searchSet.openFile(name);
}
} // namespace Common

View File

@ -31,6 +31,7 @@
#include "common/hash-str.h"
#include "common/list.h"
#include "common/ptr.h"
#include "common/singleton.h"
#include "common/stream.h"
namespace Common {
@ -202,6 +203,56 @@ public:
virtual SeekableReadStream *openFile(const String &name);
};
class SearchManager : public Singleton<SearchManager>, public Archive {
SearchSet _searchSet;
public:
/**
* Add an existing Archive. This is meant to support searching in system-specific
* archives, namely the MACOSX/IPHONE bundles.
*/
void addArchive(const String &name, ArchivePtr archive);
/**
* Create and add a FSDirectory by name
*/
void addDirectory(const String &name, const String &directory);
/**
* Create and add a FSDirectory and its subdirectories by name
*/
void addDirectoryRecursive(const String &name, const String &directory, int depth = 4);
/**
* Remove an archive from the pool.
*/
void remove(const String &name);
/**
* Clears the archive
*/
void clear();
virtual bool hasFile(const String &name);
virtual int getAllNames(StringList &list) {
return matchPattern(list, "*");
}
/**
* 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);
};
/** Shortcut for accessing the search manager. */
#define SearchMan Common::SearchManager::instance()
} // namespace Common
#endif