Modified Common::SearchSet to take signed integer priorities, for convenience (so that one can add archives with less-than-default priority)

svn-id: r34659
This commit is contained in:
Max Horn 2008-09-27 18:32:01 +00:00
parent 3779fc2170
commit 479e67f2f2
5 changed files with 29 additions and 10 deletions

View File

@ -275,7 +275,7 @@ FilesystemFactory *OSystem_SDL::getFilesystemFactory() {
return _fsFactory; return _fsFactory;
} }
void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s, uint priority) { void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
#ifdef DATA_PATH #ifdef DATA_PATH
// Add the global DATA_PATH to the directory search list // Add the global DATA_PATH to the directory search list

View File

@ -209,7 +209,7 @@ public:
virtual Common::SaveFileManager *getSavefileManager(); virtual Common::SaveFileManager *getSavefileManager();
virtual FilesystemFactory *getFilesystemFactory(); virtual FilesystemFactory *getFilesystemFactory();
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, uint priority = 0); virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
virtual Common::SeekableReadStream *openConfigFileForReading(); virtual Common::SeekableReadStream *openConfigFileForReading();
virtual Common::WriteStream *openConfigFileForWriting(); virtual Common::WriteStream *openConfigFileForWriting();

View File

@ -26,6 +26,7 @@
#include "common/archive.h" #include "common/archive.h"
#include "common/fs.h" #include "common/fs.h"
#include "common/util.h" #include "common/util.h"
#include "common/system.h"
namespace Common { namespace Common {
@ -231,7 +232,7 @@ void SearchSet::insert(const Node &node) {
_list.insert(it, node); _list.insert(it, node);
} }
void SearchSet::add(const String& name, ArchivePtr archive, uint priority) { void SearchSet::add(const String& name, ArchivePtr archive, int priority) {
if (find(name) == _list.end()) { if (find(name) == _list.end()) {
Node node = { priority, name, archive }; Node node = { priority, name, archive };
insert(node); insert(node);
@ -256,7 +257,7 @@ void SearchSet::clear() {
_list.clear(); _list.clear();
} }
void SearchSet::setPriority(const String& name, uint priority) { void SearchSet::setPriority(const String& name, int priority) {
ArchiveList::iterator it = find(name); ArchiveList::iterator it = find(name);
if (it == _list.end()) { if (it == _list.end()) {
warning("SearchSet::setPriority: archive '%s' is not present", name.c_str()); warning("SearchSet::setPriority: archive '%s' is not present", name.c_str());
@ -328,6 +329,10 @@ SeekableReadStream *SearchSet::openFile(const String &name) {
DECLARE_SINGLETON(SearchManager); DECLARE_SINGLETON(SearchManager);
SearchManager::SearchManager() {
clear(); // Force a reset
}
void SearchManager::addArchive(const String &name, ArchivePtr archive) { void SearchManager::addArchive(const String &name, ArchivePtr archive) {
add(name, archive); add(name, archive);
} }
@ -337,8 +342,16 @@ void SearchManager::addDirectory(const String &name, const String &directory) {
} }
void SearchManager::addDirectoryRecursive(const String &name, const String &directory, int depth) { void SearchManager::addDirectoryRecursive(const String &name, const String &directory, int depth) {
add(name, SharedPtr<FSDirectory>(new FSDirectory(directory, depth))); add(name, ArchivePtr(new FSDirectory(directory, depth)));
} }
void SearchManager::clear() {
SearchSet::clear();
// Always keep system specific archives in the SearchManager.
// But we give them a lower priority than the default priority (which is 0),
// so that archives added by client code are searched first.
g_system->addSysArchivesToSearchSet(*this, -1);
}
} // namespace Common } // namespace Common

View File

@ -153,7 +153,7 @@ public:
*/ */
class SearchSet : public Archive { class SearchSet : public Archive {
struct Node { struct Node {
uint _priority; int _priority;
String _name; String _name;
ArchivePtr _arc; ArchivePtr _arc;
}; };
@ -169,7 +169,7 @@ public:
/** /**
* Add a new archive to the searchable set. * Add a new archive to the searchable set.
*/ */
void add(const String& name, ArchivePtr archive, uint priority = 0); void add(const String& name, ArchivePtr archive, int priority = 0);
/** /**
* Remove an archive from the searchable set. * Remove an archive from the searchable set.
@ -184,12 +184,12 @@ public:
/** /**
* Empties the searchable set. * Empties the searchable set.
*/ */
void clear(); virtual void clear();
/** /**
* Change the order of searches. * Change the order of searches.
*/ */
void setPriority(const String& name, uint priority); void setPriority(const String& name, int priority);
virtual bool hasFile(const String &name); virtual bool hasFile(const String &name);
virtual int matchPattern(StringList &list, const String &pattern); virtual int matchPattern(StringList &list, const String &pattern);
@ -205,6 +205,8 @@ public:
class SearchManager : public Singleton<SearchManager>, public SearchSet { class SearchManager : public Singleton<SearchManager>, public SearchSet {
public: public:
SearchManager();
/** /**
* Add an existing Archive. This is meant to support searching in system-specific * Add an existing Archive. This is meant to support searching in system-specific
* archives, namely the MACOSX/IPHONE bundles. * archives, namely the MACOSX/IPHONE bundles.
@ -221,6 +223,10 @@ public:
*/ */
void addDirectoryRecursive(const String &name, const String &directory, int depth = 4); void addDirectoryRecursive(const String &name, const String &directory, int depth = 4);
/**
* TODO
*/
virtual void clear();
}; };
/** Shortcut for accessing the search manager. */ /** Shortcut for accessing the search manager. */

View File

@ -917,7 +917,7 @@ public:
* @param s the SearchSet to which the system specific dirs, if any, are added * @param s the SearchSet to which the system specific dirs, if any, are added
* @param priority the priority with which those dirs are added * @param priority the priority with which those dirs are added
*/ */
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, uint priority = 0) {} virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) {}
/** /**
* Open the default config file for reading, by returning a suitable * Open the default config file for reading, by returning a suitable