Since we do ref counting on the nodes now, we can re-use the root nodes now

svn-id: r15851
This commit is contained in:
Max Horn 2004-11-21 13:18:07 +00:00
parent eb44281ecb
commit 01cb15b9b2
6 changed files with 40 additions and 31 deletions

View file

@ -72,7 +72,10 @@ FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) {
} }
FilesystemNode FilesystemNode::getParent() const { FilesystemNode FilesystemNode::getParent() const {
FilesystemNode wrapper; AbstractFilesystemNode *node = _realNode->parent();
wrapper._realNode = _realNode->parent(); if (node == 0)
return wrapper; return *this;
else {
return AbstractFilesystemNode::wrap(node);
}
} }

View file

@ -139,6 +139,17 @@ public:
{ {
return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0; return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0;
} }
/* TODO:
bool exists();
bool isDirectory();
bool isFile();
bool isReadable();
bool isWriteable();
*/
}; };
class FilesystemNode : public AbstractFilesystemNode { class FilesystemNode : public AbstractFilesystemNode {

View file

@ -207,18 +207,15 @@ AbstractFilesystemNode *ABoxFilesystemNode::parent() const
if (!_isDirectory) if (!_isDirectory)
error("parent() called on file node"); error("parent() called on file node");
if (_lock == NULL) if (_lock == NULL) {
/* Parent of the root is the root itself */ /* Parent of the root is the root itself */
node = clone(); node = 0;
else } else {
{
BPTR parent_lock = ParentDir(_lock); BPTR parent_lock = ParentDir(_lock);
if (parent_lock) if (parent_lock) {
{
node = new ABoxFilesystemNode(parent_lock); node = new ABoxFilesystemNode(parent_lock);
UnLock(parent_lock); UnLock(parent_lock);
} } else
else
node = new ABoxFilesystemNode(); node = new ABoxFilesystemNode();
} }

View file

@ -136,13 +136,13 @@ const char *lastPathComponent(const Common::String &str) {
} }
AbstractFilesystemNode *PalmOSFilesystemNode::parent() const { AbstractFilesystemNode *PalmOSFilesystemNode::parent() const {
PalmOSFilesystemNode *p = 0;
PalmOSFilesystemNode *p = new PalmOSFilesystemNode();
if (!_isPseudoRoot) { if (!_isPseudoRoot) {
const char *start = _path.c_str(); const char *start = _path.c_str();
const char *end = lastPathComponent(_path); const char *end = lastPathComponent(_path);
p = new PalmOSFilesystemNode();
p->_path = String(start, end - start); p->_path = String(start, end - start);
p->_isValid = true; p->_isValid = true;
p->_isDirectory = true; p->_isDirectory = true;

View file

@ -185,22 +185,19 @@ FSList POSIXFilesystemNode::listDir(ListMode mode) const {
} }
AbstractFilesystemNode *POSIXFilesystemNode::parent() const { AbstractFilesystemNode *POSIXFilesystemNode::parent() const {
POSIXFilesystemNode *p = new POSIXFilesystemNode(); if (_path == "/")
return 0;
// Root node is its own parent. Still we can't just return this POSIXFilesystemNode *p = new POSIXFilesystemNode();
// as the GUI code will call delete on the old node.
if (_path != "/") {
const char *start = _path.c_str(); const char *start = _path.c_str();
const char *end = lastPathComponent(_path); const char *end = lastPathComponent(_path);
p->_path = String(start, end - start); p->_path = String(start, end - start);
p->_displayName = lastPathComponent(p->_path); p->_displayName = lastPathComponent(p->_path);
} else {
p->_path = _path;
p->_displayName = _displayName;
}
p->_isValid = true; p->_isValid = true;
p->_isDirectory = true; p->_isDirectory = true;
return p; return p;
} }

View file

@ -197,11 +197,12 @@ const char *lastPathComponent(const Common::String &str) {
AbstractFilesystemNode *WindowsFilesystemNode::parent() const { AbstractFilesystemNode *WindowsFilesystemNode::parent() const {
assert(_isValid || _isPseudoRoot); assert(_isValid || _isPseudoRoot);
WindowsFilesystemNode *p = new WindowsFilesystemNode(); WindowsFilesystemNode *p = 0;
if (!_isPseudoRoot && _path.size() > 3) { if (!_isPseudoRoot && _path.size() > 3) {
const char *start = _path.c_str(); const char *start = _path.c_str();
const char *end = lastPathComponent(_path); const char *end = lastPathComponent(_path);
p = new WindowsFilesystemNode();
p->_path = String(start, end - start); p->_path = String(start, end - start);
p->_isValid = true; p->_isValid = true;
p->_isDirectory = true; p->_isDirectory = true;