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 /backends/fs/palmos | |
| 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 'backends/fs/palmos')
| -rw-r--r-- | backends/fs/palmos/PalmOSFilesystemFactory.cpp | 23 | ||||
| -rw-r--r-- | backends/fs/palmos/PalmOSFilesystemFactory.h | 38 | ||||
| -rw-r--r-- | backends/fs/palmos/palmos-fs.cpp | 134 |
3 files changed, 135 insertions, 60 deletions
diff --git a/backends/fs/palmos/PalmOSFilesystemFactory.cpp b/backends/fs/palmos/PalmOSFilesystemFactory.cpp new file mode 100644 index 0000000000..15240d2397 --- /dev/null +++ b/backends/fs/palmos/PalmOSFilesystemFactory.cpp @@ -0,0 +1,23 @@ +#include "backends/fs/palmos/PalmOSFilesystemFactory.h" +#include "backends/fs/palmos/palmos-fs.cpp" + +PalmOSFilesystemFactory *PalmOSFilesystemFactory::_instance = 0; + +PalmOSFilesystemFactory *PalmOSFilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new PalmOSFilesystemFactory(); + } + return _instance; +} + +AbstractFilesystemNode *PalmOSFilesystemFactory::makeRootFileNode() const { + return new PalmOSFilesystemNode(); +} + +AbstractFilesystemNode *PalmOSFilesystemFactory::makeCurrentDirectoryFileNode() const { + return new PalmOSFilesystemNode(); +} + +AbstractFilesystemNode *PalmOSFilesystemFactory::makeFileNodePath(const String &path) const { + return new PalmOSFilesystemNode(path); +} diff --git a/backends/fs/palmos/PalmOSFilesystemFactory.h b/backends/fs/palmos/PalmOSFilesystemFactory.h new file mode 100644 index 0000000000..dd1f31b3c8 --- /dev/null +++ b/backends/fs/palmos/PalmOSFilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef PALMOSFILESYSTEMFACTORY_H_ +#define PALMOSFILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates PalmOSFilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class PalmOSFilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of PalmOSFilesystemFactory using the Singleton pattern. + * + * @return A unique instance of PalmOSFilesytemFactory. + */ + static PalmOSFilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~PalmOSFilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + PalmOSFilesystemFactory() {}; + +private: + static PalmOSFilesystemFactory *_instance; +}; + +#endif /*PALMOSFILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp index 4dfdb2f068..52fe741d26 100644 --- a/backends/fs/palmos/palmos-fs.cpp +++ b/backends/fs/palmos/palmos-fs.cpp @@ -27,36 +27,65 @@ #include <stdio.h> #include <stdlib.h> -/* +/** * Implementation of the ScummVM file system API based on PalmOS VFS API. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ - class PalmOSFilesystemNode : public AbstractFilesystemNode { protected: String _displayName; + String _path; bool _isDirectory; bool _isValid; bool _isPseudoRoot; - String _path; public: + /** + * Creates a PalmOSFilesystemNode with the root node as path. + */ PalmOSFilesystemNode(); + + /** + * Creates a POSIXFilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + */ PalmOSFilesystemNode(const String &p); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - virtual bool isValid() const { return _isValid; } + virtual String getDisplayName() const { return _displayName; } + virtual String getName() const { return _displayName; } + virtual String getPath() const { return _path; } virtual bool isDirectory() const { return _isDirectory; } - virtual String path() const { return _path; } + virtual bool isValid() const { return _isValid; } - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &n) const; + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual AbstractFilesystemNode *getParent() const; private: - static void addFile (AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data); + /** + * Adds a single WindowsFilesystemNode to a given list. + * This method is used by getChildren() to populate the directory entries list. + * + * @param list List to put the file entry node in. + * @param mode Mode to use while adding the file entry to the list. + * @param base String with the directory being listed. + * @param find_data Describes a file that the FindFirstFile, FindFirstFileEx, or FindNextFile functions find. + */ + static void addFile(AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data); }; +/** + * Returns the last component of a given path. + * + * Examples: + * /foo/bar.txt would return /bar.txt + * /foo/bar/ would return /bar/ + * + * @param str String containing the path. + * @return Pointer to the first char of the last component inside str. + */ static const char *lastPathComponent(const Common::String &str) { const char *start = str.c_str(); const char *cur = start + str.size() - 2; @@ -92,19 +121,6 @@ void PalmOSFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const ch list.push_back(new PalmOSFilesystemNode(entry)); } -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - return AbstractFilesystemNode::getRoot(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new PalmOSFilesystemNode(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new PalmOSFilesystemNode(path); -} - - PalmOSFilesystemNode::PalmOSFilesystemNode() { _isDirectory = true; _displayName = "Root"; @@ -119,13 +135,13 @@ PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { UInt32 attr; FileRef handle; - Err e = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); - if (!e) { - e = VFSFileGetAttributes(handle, &attr); + Err error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); + if (!error) { + error = VFSFileGetAttributes(handle, &attr); VFSFileClose(handle); } - if (e) { + if (error) { _isValid = false; _isDirectory = false; @@ -136,8 +152,31 @@ PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { _isPseudoRoot = false; } -bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { - Err e; +AbstractFilesystemNode *PalmOSFilesystemNode::getChild(const String &n) const { + assert(_isDirectory); + + String newPath(_path); + if (_path.lastChar() != '/') + newPath += '/'; + newPath += n; + + FileRef handle; + UInt32 attr; + Err error = VFSFileOpen(gVars->VFS.volRefNum, newPath.c_str(), vfsModeRead, &handle); + if (error) + return 0; + + error = VFSFileGetAttributes(handle, &attr); + VFSFileClose(handle); + + if (error || !(attr & vfsFileAttrDirectory)) + return 0; + + return new PalmOSFilesystemNode(newPath); +} + +bool PalmOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { + Err error; Char nameP[256]; FileInfoType desc; FileRef handle; @@ -145,14 +184,14 @@ bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const desc.nameP = nameP; desc.nameBufLen = 256; - e = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); + error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); - if (e) + if (error) return false; while(dirIterator != expIteratorStop) { - e = VFSDirEntryEnumerate(handle, &dirIterator, &desc); - if (!e) { + error = VFSDirEntryEnumerate(handle, &dirIterator, &desc); + if (!error) { addFile(myList, mode, _path.c_str(), &desc); } } @@ -162,8 +201,7 @@ bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const return true; } - -AbstractFilesystemNode *PalmOSFilesystemNode::parent() const { +AbstractFilesystemNode *PalmOSFilesystemNode::getParent() const { PalmOSFilesystemNode *p = 0; if (!_isPseudoRoot) { @@ -177,31 +215,7 @@ AbstractFilesystemNode *PalmOSFilesystemNode::parent() const { p->_displayName = lastPathComponent(p->_path); p->_isPseudoRoot =(p->_path == "/"); } - return p; -} - - -AbstractFilesystemNode *PalmOSFilesystemNode::child(const String &n) const { - assert(_isDirectory); - String newPath(_path); - - if (_path.lastChar() != '/') - newPath += '/'; - newPath += n; - - FileRef handle; - UInt32 attr; - Err e = VFSFileOpen(gVars->VFS.volRefNum, newPath.c_str(), vfsModeRead, &handle); - if (e) - return 0; - e = VFSFileGetAttributes(handle, &attr); - VFSFileClose(handle); - - if (e || !(attr & vfsFileAttrDirectory)) - return 0; - - PalmOSFilesystemNode *p = new PalmOSFilesystemNode(newPath); return p; } |
