diff options
author | Johannes Schickel | 2008-10-22 17:44:12 +0000 |
---|---|---|
committer | Johannes Schickel | 2008-10-22 17:44:12 +0000 |
commit | 7d331b734186b6d3116debf34eb28bd6c3d807ed (patch) | |
tree | 9c4ae505beb7005ebd23118c4afb8c7eb8351ade /common | |
parent | f881b95dddd5b9a2bf15179a2b4376f551a20bff (diff) | |
download | scummvm-rg350-7d331b734186b6d3116debf34eb28bd6c3d807ed.tar.gz scummvm-rg350-7d331b734186b6d3116debf34eb28bd6c3d807ed.tar.bz2 scummvm-rg350-7d331b734186b6d3116debf34eb28bd6c3d807ed.zip |
Committed updated version of my patch #2184529 "SearchSet: Get rid of SharedPtr usage".
svn-id: r34837
Diffstat (limited to 'common')
-rw-r--r-- | common/archive.cpp | 13 | ||||
-rw-r--r-- | common/archive.h | 18 |
2 files changed, 19 insertions, 12 deletions
diff --git a/common/archive.cpp b/common/archive.cpp index 3c5df35326..8881d44116 100644 --- a/common/archive.cpp +++ b/common/archive.cpp @@ -281,9 +281,9 @@ void SearchSet::insert(const Node &node) { _list.insert(it, node); } -void SearchSet::add(const String& name, ArchivePtr archive, int priority) { +void SearchSet::add(const String& name, Archive *archive, int priority, bool autoFree) { if (find(name) == _list.end()) { - Node node(priority, name, archive); + Node node(priority, name, archive, autoFree); insert(node); } else { warning("SearchSet::add: archive '%s' already present", name.c_str()); @@ -294,6 +294,8 @@ void SearchSet::add(const String& name, ArchivePtr archive, int priority) { void SearchSet::remove(const String& name) { ArchiveList::iterator it = find(name); if (it != _list.end()) { + if (it->_autoFree) + delete it->_arc; _list.erase(it); } } @@ -303,6 +305,11 @@ bool SearchSet::hasArchive(const String &name) const { } void SearchSet::clear() { + for (ArchiveList::iterator i = _list.begin(); i != _list.end(); ++i) { + if (i->_autoFree) + delete i->_arc; + } + _list.clear(); } @@ -391,7 +398,7 @@ void SearchManager::addDirectory(const String &name, const FSNode &dir, int prio if (!dir.exists() || !dir.isDirectory()) return; - add(name, ArchivePtr(new FSDirectory(dir, depth)), priority); + add(name, new FSDirectory(dir, depth), priority); } void SearchManager::clear() { diff --git a/common/archive.h b/common/archive.h index 5f8cd9be60..1f29820aea 100644 --- a/common/archive.h +++ b/common/archive.h @@ -114,9 +114,6 @@ public: }; -typedef SharedPtr<Archive> ArchivePtr; - - /** * FSDirectory models a directory tree from the filesystem and allows users * to access it through the Archive interface. Searching is case-insensitive, @@ -228,11 +225,12 @@ public: */ class SearchSet : public Archive { struct Node { - int _priority; - String _name; - ArchivePtr _arc; - Node(int priority, const String &name, ArchivePtr arc) - : _priority(priority), _name(name), _arc(arc) { + int _priority; + String _name; + Archive *_arc; + bool _autoFree; + Node(int priority, const String &name, Archive *arc, bool autoFree) + : _priority(priority), _name(name), _arc(arc), _autoFree(autoFree) { } }; typedef List<Node> ArchiveList; @@ -244,10 +242,12 @@ class SearchSet : public Archive { void insert(const Node& node); public: + virtual ~SearchSet() { clear(); } + /** * Add a new archive to the searchable set. */ - void add(const String& name, ArchivePtr archive, int priority = 0); + void add(const String& name, Archive *arch, int priority = 0, bool autoFree = true); /** * Remove an archive from the searchable set. |