diff options
author | David Corrales | 2007-05-03 02:39:33 +0000 |
---|---|---|
committer | David Corrales | 2007-05-03 02:39:33 +0000 |
commit | c459f054b46b8791ce206c2ee13d455a9c10fe4d (patch) | |
tree | b36dc6034bfb9659e57e28de8a509a7b1de4554d /common | |
parent | 8f5abc1924d5d7bdbc9684b870394f93ad80d2ff (diff) | |
download | scummvm-rg350-c459f054b46b8791ce206c2ee13d455a9c10fe4d.tar.gz scummvm-rg350-c459f054b46b8791ce206c2ee13d455a9c10fe4d.tar.bz2 scummvm-rg350-c459f054b46b8791ce206c2ee13d455a9c10fe4d.zip |
Use abstract factories to initialize FilesystemNode objects.
svn-id: r26739
Diffstat (limited to 'common')
-rw-r--r-- | common/fs.cpp | 23 | ||||
-rw-r--r-- | common/fs.h | 90 |
2 files changed, 59 insertions, 54 deletions
diff --git a/common/fs.cpp b/common/fs.cpp index 10087cd91c..cdc3e5f799 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -23,7 +23,7 @@ #include "backends/fs/abstract-fs.h" #include "common/util.h" - +#include "backends/fs/FilesystemFactoryMaker.cpp" FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { _realNode = realNode; @@ -43,10 +43,12 @@ FilesystemNode::FilesystemNode(const FilesystemNode &node) { } FilesystemNode::FilesystemNode(const Common::String &p) { + AbstractFilesystemFactory *factory = FilesystemFactoryMaker::makeFactory(); + if (p.empty() || p == ".") - _realNode = AbstractFilesystemNode::getCurrentDirectory(); + _realNode = factory->makeCurrentDirectoryFileNode(); else - _realNode = AbstractFilesystemNode::getNodeForPath(p); + _realNode = factory->makeFileNodePath(p); _refCount = new int(1); } @@ -65,7 +67,7 @@ void FilesystemNode::decRefCount() { } } -FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) { +FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) { if (node._refCount) ++(*node._refCount); @@ -87,7 +89,7 @@ FilesystemNode FilesystemNode::getParent() const { if (_realNode == 0) return *this; - AbstractFilesystemNode *node = _realNode->parent(); + AbstractFilesystemNode *node = _realNode->getParent(); if (node == 0) { return *this; } else { @@ -100,7 +102,7 @@ FilesystemNode FilesystemNode::getChild(const Common::String &n) const { return *this; assert(_realNode->isDirectory()); - AbstractFilesystemNode *node = _realNode->child(n); + AbstractFilesystemNode *node = _realNode->getChild(n); return FilesystemNode(node); } @@ -110,7 +112,7 @@ bool FilesystemNode::listDir(FSList &fslist, ListMode mode) const { AbstractFSList tmp; - if (!_realNode->listDir(tmp, mode)) + if (!_realNode->getChildren(tmp, mode)) return false; fslist.clear(); @@ -129,20 +131,19 @@ bool FilesystemNode::isDirectory() const { Common::String FilesystemNode::displayName() const { assert(_realNode); - return _realNode->displayName(); + return _realNode->getDisplayName(); } Common::String FilesystemNode::name() const { assert(_realNode); - return _realNode->name(); + return _realNode->getName(); } Common::String FilesystemNode::path() const { assert(_realNode); - return _realNode->path(); + return _realNode->getPath(); } - bool FilesystemNode::operator< (const FilesystemNode& node) const { if (isDirectory() && !node.isDirectory()) diff --git a/common/fs.h b/common/fs.h index 2d906431ca..6a89bfcdaf 100644 --- a/common/fs.h +++ b/common/fs.h @@ -30,7 +30,6 @@ class FilesystemNode; class AbstractFilesystemNode; - /** * List of multiple file system nodes. E.g. the contents of a given directory. * This is subclass instead of just a typedef so that we can use forward @@ -38,9 +37,8 @@ class AbstractFilesystemNode; */ class FSList : public Common::Array<FilesystemNode> {}; - /** - * FilesystemNode provides an abstraction for file pathes, allowing for portable + * FilesystemNode provides an abstraction for file paths, allowing for portable * file system browsing. To this ends, multiple or single roots have to be supported * (compare Unix with a single root, Windows with multiple roots C:, D:, ...). * @@ -64,8 +62,8 @@ class FSList : public Common::Array<FilesystemNode> {}; */ class FilesystemNode { private: - AbstractFilesystemNode *_realNode; int *_refCount; + AbstractFilesystemNode *_realNode; FilesystemNode(AbstractFilesystemNode *realNode); @@ -110,43 +108,13 @@ public: /** * Copy operator. */ - FilesystemNode &operator =(const FilesystemNode &node); - - /** - * Checks if the FilesystemNode is valid for any usage - */ - bool isValid() const; - - /** - * 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; - - /** - * 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 Common::String &name) const; - - /** - * Return a list of child nodes of this directory node. If called on a node - * that does not represent a directory, false is returned. - * @return true if succesful, false otherwise (e.g. when the directory does not exist). - * @todo Rename this to listChildren or getChildren. - */ - virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; - + FilesystemNode &operator= (const FilesystemNode &node); + /** - * 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. + * Compare the name of this node to the name of another. Directories + * go before normal files. */ - virtual bool isDirectory() const; + bool operator< (const FilesystemNode& node) const; /** * Return a human readable string for this node, usable for display (e.g. @@ -180,15 +148,51 @@ public: virtual Common::String path() const; /** - * Compare the name of this node to the name of another. Directories - * go before normal files. + * Fetch a child node of this node, with the given name. Only valid for + * directory nodes (an assertion is triggered otherwise). + * If no child node with the given name exists, an invalid node is returned. */ - bool operator< (const FilesystemNode& node) const; + FilesystemNode getChild(const Common::String &name) const; + + /** + * Return a list of child nodes of this directory node. If called on a node + * that does not represent a directory, false is returned. + * + * @return true if succesful, false otherwise (e.g. when the directory does not exist). + * @todo Rename this to listChildren or getChildren. + */ + virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; + + /** + * 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; + + /** + * Indicates whether this path refers to a directory or not. + * + * @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; + + /** + * Indicates whether this path is valid or not for usage. + */ + bool isValid() const; protected: + /** + * Decreases the reference count to the FilesystemNode, and if necessary, + * deletes the corresponding underlying references. + */ void decRefCount(); }; //} // End of namespace Common -#endif +#endif //COMMON_FS_H |