mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-21 19:51:49 +00:00
FilesystemNode code: some comment cleanup; added FilesystemNode::openForReading() and openForWriting() methods (for now these are simple wrappers around Common::File)
svn-id: r33590
This commit is contained in:
parent
01f07b5e21
commit
4d5df949c7
@ -23,10 +23,13 @@
|
||||
*/
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/file.h"
|
||||
#include "common/system.h"
|
||||
#include "backends/fs/abstract-fs.h"
|
||||
#include "backends/fs/fs-factory.h"
|
||||
|
||||
//namespace Common {
|
||||
|
||||
FilesystemNode::FilesystemNode() {
|
||||
}
|
||||
|
||||
@ -170,3 +173,41 @@ bool FilesystemNode::lookupFile(FSList &results, const Common::String &p, bool h
|
||||
|
||||
return !results.empty();
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *FilesystemNode::openForReading() {
|
||||
if (_realNode == 0)
|
||||
return 0;
|
||||
#if 0
|
||||
return _realNode->openForReading();
|
||||
#else
|
||||
// FIXME: Until we support openForReading in AbstractFilesystemNode,
|
||||
// we just use Common::File.
|
||||
Common::File *confFile = new Common::File();
|
||||
assert(confFile);
|
||||
if (!confFile->open(*this)) {
|
||||
delete confFile;
|
||||
confFile = 0;
|
||||
}
|
||||
return confFile;
|
||||
#endif
|
||||
}
|
||||
|
||||
Common::WriteStream *FilesystemNode::openForWriting() {
|
||||
if (_realNode == 0)
|
||||
return 0;
|
||||
#if 0
|
||||
return _realNode->openForWriting();
|
||||
#else
|
||||
// FIXME: Until we support openForWriting in AbstractFilesystemNode,
|
||||
// we just use Common::DumpFile.
|
||||
Common::DumpFile *confFile = new Common::DumpFile();
|
||||
assert(confFile);
|
||||
if (!confFile->open(*this)) {
|
||||
delete confFile;
|
||||
confFile = 0;
|
||||
}
|
||||
return confFile;
|
||||
#endif
|
||||
}
|
||||
|
||||
//} // End of namespace Common
|
||||
|
67
common/fs.h
67
common/fs.h
@ -29,10 +29,18 @@
|
||||
#include "common/ptr.h"
|
||||
#include "common/str.h"
|
||||
|
||||
class AbstractFilesystemNode;
|
||||
|
||||
namespace Common {
|
||||
class SeekableReadStream;
|
||||
class WriteStream;
|
||||
}
|
||||
|
||||
//namespace Common {
|
||||
|
||||
class FilesystemNode;
|
||||
class AbstractFilesystemNode;
|
||||
//class SeekableReadStream;
|
||||
//class WriteStream;
|
||||
|
||||
/**
|
||||
* List of multiple file system nodes. E.g. the contents of a given directory.
|
||||
@ -49,22 +57,6 @@ class FSList : public Common::Array<FilesystemNode> {};
|
||||
* To this end, we abstract away from paths; implementations can be based on
|
||||
* paths (and it's left to them whether / or \ or : is the path separator :-);
|
||||
* but it is also possible to use inodes or vrefs (MacOS 9) or anything else.
|
||||
*
|
||||
* NOTE: Backends still have to provide a way to extract a path from a FSIntern
|
||||
*
|
||||
* You may ask now: "isn't this cheating? Why do we go through all this when we use
|
||||
* a path in the end anyway?!?".
|
||||
* Well, for once as long as we don't provide our own file open/read/write API, we
|
||||
* still have to use fopen(). Since all our targets already support fopen(), it should
|
||||
* be possible to get a fopen() compatible string for any file system node.
|
||||
*
|
||||
* Secondly, with this abstraction layer, we still avoid a lot of complications based on
|
||||
* differences in FS roots, different path separators, or even systems with no real
|
||||
* paths (MacOS 9 doesn't even have the notion of a "current directory").
|
||||
* And if we ever want to support devices with no FS in the classical sense (Palm...),
|
||||
* we can build upon this.
|
||||
*
|
||||
* This class acts as a wrapper around the AbstractFilesystemNode class defined in backends/fs.
|
||||
*/
|
||||
class FilesystemNode {
|
||||
private:
|
||||
@ -108,9 +100,9 @@ public:
|
||||
bool operator<(const FilesystemNode& node) const;
|
||||
|
||||
/**
|
||||
* Indicates whether the object referred by this path exists in the filesystem or not.
|
||||
* Indicates whether the object referred by this node exists in the filesystem or not.
|
||||
*
|
||||
* @return bool true if the path exists, false otherwise.
|
||||
* @return bool true if the node exists, false otherwise.
|
||||
*/
|
||||
virtual bool exists() const;
|
||||
|
||||
@ -168,7 +160,7 @@ public:
|
||||
FilesystemNode getParent() const;
|
||||
|
||||
/**
|
||||
* Indicates whether the path refers to a directory or not.
|
||||
* Indicates whether the node refers to a directory or not.
|
||||
*
|
||||
* @todo Currently we assume that a node that is not a directory
|
||||
* automatically is a file (ignoring things like symlinks or pipes).
|
||||
@ -179,28 +171,28 @@ public:
|
||||
virtual bool isDirectory() const;
|
||||
|
||||
/**
|
||||
* Indicates whether the object referred by this path can be read from or not.
|
||||
* Indicates whether the object referred by this node can be read from or not.
|
||||
*
|
||||
* If the path refers to a directory, readability implies being able to read
|
||||
* If the node refers to a directory, readability implies being able to read
|
||||
* and list the directory entries.
|
||||
*
|
||||
* If the path refers to a file, readability implies being able to read the
|
||||
* If the node refers to a file, readability implies being able to read the
|
||||
* contents of the file.
|
||||
*
|
||||
* @return bool true if the object can be read, false otherwise.
|
||||
* @return true if the object can be read, false otherwise.
|
||||
*/
|
||||
virtual bool isReadable() const;
|
||||
|
||||
/**
|
||||
* Indicates whether the object referred by this path can be written to or not.
|
||||
* Indicates whether the object referred by this node can be written to or not.
|
||||
*
|
||||
* If the path refers to a directory, writability implies being able to modify
|
||||
* If the node refers to a directory, writability implies being able to modify
|
||||
* the directory entry (i.e. rename the directory, remove it or write files inside of it).
|
||||
*
|
||||
* If the path refers to a file, writability implies being able to write data
|
||||
* If the node refers to a file, writability implies being able to write data
|
||||
* to the file.
|
||||
*
|
||||
* @return bool true if the object can be written to, false otherwise.
|
||||
* @return true if the object can be written to, false otherwise.
|
||||
*/
|
||||
virtual bool isWritable() const;
|
||||
|
||||
@ -221,6 +213,25 @@ 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;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a SeekableReadStream instance corresponding to the file
|
||||
* referred by this node. This assumes that the node actually refers
|
||||
* to a readable file. If this is not the case, 0 is returned.
|
||||
*
|
||||
* @return pointer to the stream object, 0 in case of a failure
|
||||
*/
|
||||
virtual Common::SeekableReadStream *openForReading();
|
||||
|
||||
/**
|
||||
* Creates a WriteStream instance corresponding to the file
|
||||
* referred by this node. This assumes that the node actually refers
|
||||
* to a readable file. If this is not the case, 0 is returned.
|
||||
*
|
||||
* @return pointer to the stream object, 0 in case of a failure
|
||||
*/
|
||||
virtual Common::WriteStream *openForWriting();
|
||||
};
|
||||
|
||||
//} // End of namespace Common
|
||||
|
Loading…
x
Reference in New Issue
Block a user