Changed FilesystemNode to use a SharedPtr instead of implementing its own ref counting
svn-id: r31303
This commit is contained in:
parent
e411ccc01f
commit
dbe38029db
2 changed files with 10 additions and 66 deletions
|
@ -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;
|
||||
|
|
26
common/fs.h
26
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue