aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2008-03-29 21:12:36 +0000
committerMax Horn2008-03-29 21:12:36 +0000
commitdbe38029db40911cc82136820a771b2fc85454f2 (patch)
tree183991175713fe302a74e620bc639c218b231ab9 /common
parente411ccc01f4d6e2071cb5d2d86590fa8041486a5 (diff)
downloadscummvm-rg350-dbe38029db40911cc82136820a771b2fc85454f2.tar.gz
scummvm-rg350-dbe38029db40911cc82136820a771b2fc85454f2.tar.bz2
scummvm-rg350-dbe38029db40911cc82136820a771b2fc85454f2.zip
Changed FilesystemNode to use a SharedPtr instead of implementing its own ref counting
svn-id: r31303
Diffstat (limited to 'common')
-rw-r--r--common/fs.cpp50
-rw-r--r--common/fs.h26
2 files changed, 10 insertions, 66 deletions
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<AbstractFilesystemNode>(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<FilesystemNode> {};
*/
class FilesystemNode {
private:
- int *_refCount;
- AbstractFilesystemNode *_realNode;
+ Common::SharedPtr<AbstractFilesystemNode> _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