Added new AbstractFilesystemNode::child() resp. FilesystemNode::getChild() methods
svn-id: r22249
This commit is contained in:
parent
8542e92ed3
commit
8300d1d2a9
9 changed files with 131 additions and 18 deletions
|
@ -71,6 +71,7 @@ class AmigaOSFilesystemNode : public AbstractFilesystemNode {
|
||||||
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
|
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
|
||||||
virtual FSList listVolumes(void) const;
|
virtual FSList listVolumes(void) const;
|
||||||
virtual AbstractFilesystemNode *parent() const;
|
virtual AbstractFilesystemNode *parent() const;
|
||||||
|
virtual AbstractFilesystemNode *child(const String &name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
AbstractFilesystemNode *FilesystemNode::getRoot() {
|
AbstractFilesystemNode *FilesystemNode::getRoot() {
|
||||||
|
@ -323,6 +324,10 @@ AbstractFilesystemNode *AmigaOSFilesystemNode::parent() const {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AbstractFilesystemNode *AmigaOSFilesystemNode::child(const String &name) const {
|
||||||
|
TODO
|
||||||
|
}
|
||||||
|
|
||||||
FSList AmigaOSFilesystemNode::listVolumes(void) const {
|
FSList AmigaOSFilesystemNode::listVolumes(void) const {
|
||||||
ENTER();
|
ENTER();
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,9 @@ FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FilesystemNode FilesystemNode::getParent() const {
|
FilesystemNode FilesystemNode::getParent() const {
|
||||||
|
if (_realNode == 0)
|
||||||
|
return *this;
|
||||||
|
|
||||||
AbstractFilesystemNode *node = _realNode->parent();
|
AbstractFilesystemNode *node = _realNode->parent();
|
||||||
if (node == 0) {
|
if (node == 0) {
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -92,22 +95,39 @@ FilesystemNode FilesystemNode::getParent() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilesystemNode FilesystemNode::getChild(const String &name) const {
|
||||||
|
if (_realNode == 0)
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
assert(_realNode->isDirectory());
|
||||||
|
AbstractFilesystemNode *node = _realNode->child(name);
|
||||||
|
return AbstractFilesystemNode::wrap(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
FSList FilesystemNode::listDir(ListMode mode) const {
|
||||||
|
assert(_realNode);
|
||||||
|
assert(_realNode->isDirectory());
|
||||||
|
return _realNode->listDir(mode);
|
||||||
|
}
|
||||||
|
|
||||||
Common::String FilesystemNode::displayName() const {
|
Common::String FilesystemNode::displayName() const {
|
||||||
|
assert(_realNode);
|
||||||
return _realNode->displayName();
|
return _realNode->displayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilesystemNode::isValid() const {
|
bool FilesystemNode::isValid() const {
|
||||||
|
if (_realNode == 0)
|
||||||
|
return false;
|
||||||
return _realNode->isValid();
|
return _realNode->isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilesystemNode::isDirectory() const {
|
bool FilesystemNode::isDirectory() const {
|
||||||
|
if (_realNode == 0)
|
||||||
|
return false;
|
||||||
return _realNode->isDirectory();
|
return _realNode->isDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::String FilesystemNode::path() const {
|
Common::String FilesystemNode::path() const {
|
||||||
|
assert(_realNode);
|
||||||
return _realNode->path();
|
return _realNode->path();
|
||||||
}
|
}
|
||||||
|
|
||||||
FSList FilesystemNode::listDir(ListMode mode) const {
|
|
||||||
return _realNode->listDir(mode);
|
|
||||||
}
|
|
||||||
|
|
|
@ -80,6 +80,13 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual AbstractFilesystemNode *parent() const = 0;
|
virtual AbstractFilesystemNode *parent() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The child node with the given name. If no child with this name
|
||||||
|
* exists, returns 0. Will never be called on a node which is not
|
||||||
|
* a directory node.
|
||||||
|
*/
|
||||||
|
virtual AbstractFilesystemNode *child(const String &name) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is a rather ugly hack which is used internally by the
|
* This method is a rather ugly hack which is used internally by the
|
||||||
* actual node implementions to wrap up raw nodes inside FilesystemNode
|
* actual node implementions to wrap up raw nodes inside FilesystemNode
|
||||||
|
@ -104,29 +111,45 @@ public:
|
||||||
virtual ~AbstractFilesystemNode() {}
|
virtual ~AbstractFilesystemNode() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return display name, used by e.g. the GUI to present the file in the file browser.
|
* Return a human readable string for this node, usable for display (e.g.
|
||||||
|
* in the GUI code). Do *not* rely on it being usable for anything else,
|
||||||
|
* like constructing paths!
|
||||||
* @return the display name
|
* @return the display name
|
||||||
*/
|
*/
|
||||||
virtual String displayName() const = 0;
|
virtual String displayName() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this node valid (i.e. referring to an actual FS object)?
|
* Is this node valid? Returns true if the file/directory pointed
|
||||||
|
* to by this node exists, false otherwise.
|
||||||
|
*
|
||||||
|
* @todo Maybe rename this to exists() ? Or maybe even distinguish between
|
||||||
|
* the two? E.g. a path may be non-existant but valid, while another might
|
||||||
|
* be completely invalid). But do we ever need to make that distinction?
|
||||||
*/
|
*/
|
||||||
virtual bool isValid() const = 0;
|
virtual bool isValid() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this node a directory or not?
|
* Is this node pointing to a directory?
|
||||||
|
* @todo Currently we assume that a valid node that is not a directory
|
||||||
|
* automatically is a file (ignoring things like symlinks). That might
|
||||||
|
* actually be OK... but we could still add an isFile method. Or even replace
|
||||||
|
* isValid and isDirectory by a getType() method that can return values like
|
||||||
|
* kDirNodeType, kFileNodeType, kInvalidNodeType.
|
||||||
*/
|
*/
|
||||||
virtual bool isDirectory() const = 0;
|
virtual bool isDirectory() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A path representation suitable for use with fopen()
|
* Return a string representation of the file which can be passed to fopen(),
|
||||||
|
* and is suitable for archiving (i.e. writing to the config file).
|
||||||
|
* This will usually be a 'path' (hence the name of the method), but can
|
||||||
|
* be anything that fulfilly the above criterions.
|
||||||
*/
|
*/
|
||||||
virtual String path() const = 0;
|
virtual String path() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List the content of this directory node.
|
* Return a list of child nodes of this directory node. If called
|
||||||
* If this node is not a directory, throw an exception or call error().
|
* on a node that does not represent a directory, an error is triggered.
|
||||||
|
* @todo Rename this to listChildren.
|
||||||
*/
|
*/
|
||||||
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const = 0;
|
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const = 0;
|
||||||
|
|
||||||
|
@ -189,27 +212,43 @@ private:
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Create a new FilesystemNode refering to the specified path. This is
|
||||||
|
* the counterpart to the path() method.
|
||||||
|
*/
|
||||||
|
FilesystemNode(const String &path);
|
||||||
|
|
||||||
|
|
||||||
FilesystemNode();
|
FilesystemNode();
|
||||||
FilesystemNode(const FilesystemNode &node);
|
FilesystemNode(const FilesystemNode &node);
|
||||||
FilesystemNode(const String &path);
|
|
||||||
~FilesystemNode();
|
~FilesystemNode();
|
||||||
|
|
||||||
FilesystemNode &operator =(const FilesystemNode &node);
|
FilesystemNode &operator =(const FilesystemNode &node);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the parent node of this node. If this node has no parent node,
|
||||||
|
* then it returns a duplicate of this node.
|
||||||
|
*/
|
||||||
FilesystemNode getParent() const;
|
FilesystemNode getParent() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch a child node of this node, with the given name. Only valid for
|
||||||
|
* directory nodes (an assertion is triggered otherwise). If no no child
|
||||||
|
* node with the given name exists, an invalid node is returned.
|
||||||
|
*/
|
||||||
|
FilesystemNode getChild(const String &name) const;
|
||||||
|
|
||||||
|
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
|
||||||
virtual String displayName() const;
|
virtual String displayName() const;
|
||||||
virtual bool isValid() const;
|
virtual bool isValid() const;
|
||||||
virtual bool isDirectory() const;
|
virtual bool isDirectory() const;
|
||||||
virtual String path() const;
|
virtual String path() const;
|
||||||
|
|
||||||
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void decRefCount();
|
void decRefCount();
|
||||||
|
|
||||||
virtual AbstractFilesystemNode *parent() const { return 0; }
|
virtual AbstractFilesystemNode *parent() const { return 0; }
|
||||||
|
virtual AbstractFilesystemNode *child(const String &name) const { return 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ class ABoxFilesystemNode : public AbstractFilesystemNode {
|
||||||
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
|
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
|
||||||
static FSList listRoot();
|
static FSList listRoot();
|
||||||
virtual AbstractFilesystemNode *parent() const;
|
virtual AbstractFilesystemNode *parent() const;
|
||||||
|
virtual AbstractFilesystemNode *child(const String &name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -212,6 +213,10 @@ AbstractFilesystemNode *ABoxFilesystemNode::parent() const
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AbstractFilesystemNode *ABoxFilesystemNode::child(const String &name) const {
|
||||||
|
TODO
|
||||||
|
}
|
||||||
|
|
||||||
FSList ABoxFilesystemNode::listRoot()
|
FSList ABoxFilesystemNode::listRoot()
|
||||||
{
|
{
|
||||||
FSList myList;
|
FSList myList;
|
||||||
|
|
|
@ -50,6 +50,7 @@ public:
|
||||||
|
|
||||||
virtual FSList listDir(ListMode) const;
|
virtual FSList listDir(ListMode) const;
|
||||||
virtual AbstractFilesystemNode *parent() const;
|
virtual AbstractFilesystemNode *parent() const;
|
||||||
|
virtual AbstractFilesystemNode *child(const String &name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void addFile (FSList &list, ListMode mode, const Char *base, FileInfoType* find_data);
|
static void addFile (FSList &list, ListMode mode, const Char *base, FileInfoType* find_data);
|
||||||
|
@ -170,4 +171,9 @@ AbstractFilesystemNode *PalmOSFilesystemNode::parent() const {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AbstractFilesystemNode *PalmOSFilesystemNode::child(const String &name) const {
|
||||||
|
TODO
|
||||||
|
}
|
||||||
|
|
||||||
#endif // PALMOS_MODE
|
#endif // PALMOS_MODE
|
||||||
|
|
|
@ -49,7 +49,7 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
POSIXFilesystemNode();
|
POSIXFilesystemNode();
|
||||||
POSIXFilesystemNode(const String &path, bool useStat = false);
|
POSIXFilesystemNode(const String &path, bool verify = false);
|
||||||
|
|
||||||
virtual String displayName() const { return _displayName; }
|
virtual String displayName() const { return _displayName; }
|
||||||
virtual bool isValid() const { return _isValid; }
|
virtual bool isValid() const { return _isValid; }
|
||||||
|
@ -58,6 +58,7 @@ public:
|
||||||
|
|
||||||
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
|
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
|
||||||
virtual AbstractFilesystemNode *parent() const;
|
virtual AbstractFilesystemNode *parent() const;
|
||||||
|
virtual AbstractFilesystemNode *child(const String &name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,7 +104,7 @@ POSIXFilesystemNode::POSIXFilesystemNode() {
|
||||||
_isDirectory = true;
|
_isDirectory = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool useStat) {
|
POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool verify) {
|
||||||
assert(p.size() > 0);
|
assert(p.size() > 0);
|
||||||
|
|
||||||
_path = p;
|
_path = p;
|
||||||
|
@ -111,14 +112,22 @@ POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool useStat) {
|
||||||
_isValid = true;
|
_isValid = true;
|
||||||
_isDirectory = true;
|
_isDirectory = true;
|
||||||
|
|
||||||
#ifndef __DC__
|
if (verify) {
|
||||||
if (useStat) {
|
#ifdef __DC__
|
||||||
|
FIXME;
|
||||||
|
/*
|
||||||
|
FIXME: Is there really no way to at least verify the path is valid?
|
||||||
|
Or is it too slow, or what? Please clarify with a comment here.
|
||||||
|
(Of course we could just fopen here, but that wouldn't be able to deal
|
||||||
|
with directories...
|
||||||
|
*/
|
||||||
|
#else
|
||||||
struct stat st;
|
struct stat st;
|
||||||
_isValid = (0 == stat(_path.c_str(), &st));
|
_isValid = (0 == stat(_path.c_str(), &st));
|
||||||
_isDirectory = S_ISDIR(st.st_mode);
|
_isDirectory = S_ISDIR(st.st_mode);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FSList POSIXFilesystemNode::listDir(ListMode mode) const {
|
FSList POSIXFilesystemNode::listDir(ListMode mode) const {
|
||||||
assert(_isDirectory);
|
assert(_isDirectory);
|
||||||
|
@ -200,4 +209,17 @@ AbstractFilesystemNode *POSIXFilesystemNode::parent() const {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AbstractFilesystemNode *POSIXFilesystemNode::child(const String &name) const {
|
||||||
|
// FIXME: Pretty lame implementation! We do no error checking to speak
|
||||||
|
// of, do not check if this is a special node, etc.
|
||||||
|
assert(_isDirectory);
|
||||||
|
String newPath(_path);
|
||||||
|
if (_path.lastChar() != '/')
|
||||||
|
newPath += '/';
|
||||||
|
newPath += name;
|
||||||
|
POSIXFilesystemNode *p = new POSIXFilesystemNode(newPath, true);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // defined(UNIX)
|
#endif // defined(UNIX)
|
||||||
|
|
|
@ -45,6 +45,8 @@ public:
|
||||||
|
|
||||||
virtual FSList listDir(ListMode) const;
|
virtual FSList listDir(ListMode) const;
|
||||||
virtual AbstractFilesystemNode *parent() const;
|
virtual AbstractFilesystemNode *parent() const;
|
||||||
|
virtual AbstractFilesystemNode *child(const String &name) const;
|
||||||
|
|
||||||
virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); }
|
virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -135,3 +137,7 @@ AbstractFilesystemNode *Ps2FilesystemNode::parent() const {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AbstractFilesystemNode *Ps2FilesystemNode::child(const String &name) const {
|
||||||
|
TODO
|
||||||
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ public:
|
||||||
|
|
||||||
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
|
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
|
||||||
virtual AbstractFilesystemNode *parent() const;
|
virtual AbstractFilesystemNode *parent() const;
|
||||||
|
virtual AbstractFilesystemNode *child(const String &name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -198,4 +199,8 @@ AbstractFilesystemNode *SymbianFilesystemNode::parent() const {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AbstractFilesystemNode *SymbianFilesystemNode::child(const String &name) const {
|
||||||
|
TODO
|
||||||
|
}
|
||||||
|
|
||||||
#endif // defined(__SYMBIAN32__)
|
#endif // defined(__SYMBIAN32__)
|
||||||
|
|
|
@ -51,6 +51,7 @@ public:
|
||||||
|
|
||||||
virtual FSList listDir(ListMode) const;
|
virtual FSList listDir(ListMode) const;
|
||||||
virtual AbstractFilesystemNode *parent() const;
|
virtual AbstractFilesystemNode *parent() const;
|
||||||
|
virtual AbstractFilesystemNode *child(const String &name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static char *toAscii(TCHAR *x);
|
static char *toAscii(TCHAR *x);
|
||||||
|
@ -228,4 +229,8 @@ AbstractFilesystemNode *WindowsFilesystemNode::parent() const {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AbstractFilesystemNode *WindowsFilesystemNode::child(const String &name) const {
|
||||||
|
TODO
|
||||||
|
}
|
||||||
|
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue