[Scummvm-cvs-logs] SF.net SVN: scummvm: [31303] scummvm/trunk/common

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Mar 29 22:12:36 CET 2008


Revision: 31303
          http://scummvm.svn.sourceforge.net/scummvm/?rev=31303&view=rev
Author:   fingolfin
Date:     2008-03-29 14:12:36 -0700 (Sat, 29 Mar 2008)

Log Message:
-----------
Changed FilesystemNode to use a SharedPtr instead of implementing its own ref counting

Modified Paths:
--------------
    scummvm/trunk/common/fs.cpp
    scummvm/trunk/common/fs.h

Modified: scummvm/trunk/common/fs.cpp
===================================================================
--- scummvm/trunk/common/fs.cpp	2008-03-29 20:15:58 UTC (rev 31302)
+++ scummvm/trunk/common/fs.cpp	2008-03-29 21:12:36 UTC (rev 31303)
@@ -28,48 +28,23 @@
 #include "backends/fs/fs-factory.h"
 
 FilesystemNode::FilesystemNode() {
-	_realNode = 0;
-	_refCount = 0;
 }
 
-FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) {
-	_realNode = realNode;
-	_refCount = new int(1);
+FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) 
+	: _realNode(realNode) {
 }
 
-FilesystemNode::FilesystemNode(const FilesystemNode &node) {
-	_realNode = node._realNode;
-	_refCount = node._refCount;
-	if (_refCount)
-		++(*_refCount);
-}
-
 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);
+		tmp = factory->makeFileNodePath(p);
+	_realNode = Common::SharedPtr<AbstractFilesystemNode>(tmp);
 }
 
-FilesystemNode::~FilesystemNode() {
-	decRefCount();
-}
-
-FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) {
-	if (node._refCount)
-		++(*node._refCount);
-
-	decRefCount();
-
-	_realNode = node._realNode;
-	_refCount = node._refCount;
-
-	return *this;
-}
-
 bool FilesystemNode::operator<(const FilesystemNode& node) const {
 	if (isDirectory() != node.isDirectory())
 		return isDirectory();
@@ -77,17 +52,6 @@
 	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;

Modified: scummvm/trunk/common/fs.h
===================================================================
--- scummvm/trunk/common/fs.h	2008-03-29 20:15:58 UTC (rev 31302)
+++ scummvm/trunk/common/fs.h	2008-03-29 21:12:36 UTC (rev 31303)
@@ -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 FilesystemNode {
 private:
-	int *_refCount;
-	AbstractFilesystemNode *_realNode;
+	Common::SharedPtr<AbstractFilesystemNode>	_realNode;
 	FilesystemNode(AbstractFilesystemNode *realNode);
 
 public:
@@ -99,22 +99,9 @@
 	 */
 	explicit FilesystemNode(const Common::String &path);
 
-	/**
-	 * Copy constructor.
-	 */
-	FilesystemNode(const FilesystemNode &node);
+	virtual ~FilesystemNode() {}
 
 	/**
-	 * Destructor.
-	 */
-	virtual ~FilesystemNode();
-
-	/**
-	 * Copy operator.
-	 */
-	FilesystemNode &operator= (const FilesystemNode &node);
-
-	/**
 	 * Compare the name of this node to the name of another. Directories
 	 * go before normal files.
 	 */
@@ -234,13 +221,6 @@
 	 * @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


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list