From dbe38029db40911cc82136820a771b2fc85454f2 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 29 Mar 2008 21:12:36 +0000 Subject: Changed FilesystemNode to use a SharedPtr instead of implementing its own ref counting svn-id: r31303 --- common/fs.cpp | 50 +++++++------------------------------------------- common/fs.h | 26 +++----------------------- 2 files changed, 10 insertions(+), 66 deletions(-) (limited to 'common') diff --git a/common/fs.cpp b/common/fs.cpp index bd35f0de53..7d803dacd4 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -28,46 +28,21 @@ #include "backends/fs/fs-factory.h" FilesystemNode::FilesystemNode() { - _realNode = 0; - _refCount = 0; } -FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { - _realNode = realNode; - _refCount = new int(1); -} - -FilesystemNode::FilesystemNode(const FilesystemNode &node) { - _realNode = node._realNode; - _refCount = node._refCount; - if (_refCount) - ++(*_refCount); +FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) + : _realNode(realNode) { } FilesystemNode::FilesystemNode(const Common::String &p) { FilesystemFactory *factory = g_system->getFilesystemFactory(); - + AbstractFilesystemNode *tmp = 0; + if (p.empty() || p == ".") - _realNode = factory->makeCurrentDirectoryFileNode(); + tmp = factory->makeCurrentDirectoryFileNode(); else - _realNode = factory->makeFileNodePath(p); - _refCount = new int(1); -} - -FilesystemNode::~FilesystemNode() { - decRefCount(); -} - -FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) { - if (node._refCount) - ++(*node._refCount); - - decRefCount(); - - _realNode = node._realNode; - _refCount = node._refCount; - - return *this; + tmp = factory->makeFileNodePath(p); + _realNode = Common::SharedPtr(tmp); } bool FilesystemNode::operator<(const FilesystemNode& node) const { @@ -77,17 +52,6 @@ bool FilesystemNode::operator<(const FilesystemNode& node) const { return scumm_stricmp(getDisplayName().c_str(), node.getDisplayName().c_str()) < 0; } -void FilesystemNode::decRefCount() { - if (_refCount) { - assert(*_refCount > 0); - --(*_refCount); - if (*_refCount == 0) { - delete _refCount; - delete _realNode; - } - } -} - bool FilesystemNode::exists() const { if (_realNode == 0) return false; diff --git a/common/fs.h b/common/fs.h index b287280ca4..ed7355cc00 100644 --- a/common/fs.h +++ b/common/fs.h @@ -26,6 +26,7 @@ #define COMMON_FS_H #include "common/array.h" +#include "common/ptr.h" #include "common/str.h" //namespace Common { @@ -67,8 +68,7 @@ class FSList : public Common::Array {}; */ class FilesystemNode { private: - int *_refCount; - AbstractFilesystemNode *_realNode; + Common::SharedPtr _realNode; FilesystemNode(AbstractFilesystemNode *realNode); public: @@ -99,20 +99,7 @@ public: */ explicit FilesystemNode(const Common::String &path); - /** - * Copy constructor. - */ - FilesystemNode(const FilesystemNode &node); - - /** - * Destructor. - */ - virtual ~FilesystemNode(); - - /** - * Copy operator. - */ - FilesystemNode &operator= (const FilesystemNode &node); + virtual ~FilesystemNode() {} /** * Compare the name of this node to the name of another. Directories @@ -234,13 +221,6 @@ public: * @return true if matches could be found, false otherwise. */ virtual bool lookupFile(FSList &results, const Common::String &pattern, bool hidden, bool exhaustive, int depth = -1) const; - -protected: - /** - * Decreases the reference count to the FilesystemNode, and if necessary, - * deletes the corresponding underlying references. - */ - void decRefCount(); }; //} // End of namespace Common -- cgit v1.2.3