![]() |
CopperSpice API
2.0.0
|
The QAbstractFileEngine is a base class abstraction for accessing the file system. More...
Classes | |
class | ExtensionOption |
Provides an extended input argument to QAbstractFileEngine's extension support More... | |
class | ExtensionReturn |
Provides an extended output argument to QAbstractFileEngine's extension support More... | |
class | MapExtensionOption |
Indicates a file engine supports the map() method More... | |
class | MapExtensionReturn |
Indicates a file engine which supports returning an address from the map() method More... | |
class | UnMapExtensionOption |
Indicates a file engine supports the unmap() method More... | |
Public Typedefs | |
using | FileFlags = QFlags< FileFlag > |
Public Types | |
enum | Extension |
enum | FileFlag |
enum | FileName |
enum | FileOwner |
Public Methods | |
virtual | ~QAbstractFileEngine () |
bool | atEnd () const |
virtual QAbstractFileEngineIterator * | beginEntryList (QDir::Filters filters, const QStringList &filterNames) |
virtual bool | caseSensitive () const |
virtual bool | close () |
virtual bool | copy (const QString &newName) |
virtual QStringList | entryList (QDir::Filters filters, const QStringList &filterNames) const |
QFile::FileError | error () const |
QString | errorString () const |
virtual bool | extension (Extension extension, const ExtensionOption *option=nullptr, ExtensionReturn *output=nullptr) |
virtual FileFlags | fileFlags (FileFlags type=FileInfoAll) const |
virtual QString | fileName (FileName file=DefaultName) const |
virtual QDateTime | fileTime (QFileDevice::FileTimeType type) const |
virtual bool | flush () |
virtual int | handle () const |
virtual bool | isRelativePath () const |
virtual bool | isSequential () const |
virtual bool | link (const QString &newName) |
uchar * | map (qint64 offset, qint64 size, QFile::MemoryMapFlags flags) |
virtual bool | mkdir (const QString &dirName, bool createParentDirectories) const |
virtual bool | open (QIODevice::OpenMode mode) |
virtual QString | owner (FileOwner owner) const |
virtual uint | ownerId (FileOwner owner) const |
virtual qint64 | pos () const |
virtual qint64 | read (char *data, qint64 maxlen) |
virtual qint64 | readLine (char *data, qint64 maxlen) |
virtual bool | remove () |
virtual bool | rename (const QString &newName) |
virtual bool | renameOverwrite (const QString &newName) |
virtual bool | rmdir (const QString &dirName, bool recurseParentDirectories) const |
virtual bool | seek (qint64 offset) |
virtual void | setFileName (const QString &file) |
virtual bool | setFileTime (const QDateTime &newTime, QFileDevice::FileTimeType type) |
virtual bool | setPermissions (uint perms) |
virtual bool | setSize (qint64 size) |
virtual qint64 | size () const |
virtual bool | supportsExtension (Extension extension) const |
virtual bool | syncToDisk () |
bool | unmap (uchar *address) |
virtual qint64 | write (const char *data, qint64 len) |
Static Public Methods | |
static QAbstractFileEngine * | create (const QString &fileName) |
Protected Methods | |
QAbstractFileEngine () | |
void | setError (QFile::FileError error, const QString &errorString) |
This is a base class abstraction for accessing the file system.
The QDir, QFile, and QFileInfo classes will call methods in QAbstractFileEngine. To change the behavior of these classes create a new class which inherits from QAbstractFileEngine. To use your custom file engine, you will need to register your new class with CopperSpice by inheriting from QAbstractFileEngineHandler.
The design of QAbstractFileEngine is to refer to a single file or directory. The main file methods include setFileName(), rename(), and remove(). The methods for a directory are mkdir(), rmdir(), and entryList(). The methods caseSensitive(), isRelativePath(), fileFlags(), ownerId(), owner(), and fileTime() apply to both files and directories.
Typedef for QFlags<FileFlag> which contains an OR combination of FileFlag values.
Refer to QAbstractFileEngine::FileFlag for the enum documentation.
This enum describes the types of extensions the file engine can support. Before using an extension verify it is supported by calling supportsExtension().
Constant | Value | Description |
---|---|---|
QAbstractFileEngine::AtEndExtension | 0 | Test if the current file position is at the end of the file. This extension allows file engines with local buffering to report end-of-file status without checking the file size. It is useful for sequential files where the size of the file can not be used to determine whether or not you have reached the end. Calling extension() with this value returns true if the current position is at the end of the file, otherwise it returns false. |
QAbstractFileEngine::FastReadLineExtension | 1 | Test if the file engine provides a fast implementation for readLine(). If readLine() is not implemented in the file engine, QAbstractFileEngine will provide a default implementation based on calling read() repeatedly. If supportsExtension() returns false for this value QIODevice can provide a faster implementation by making use of its internal buffer. For engines which provide a fast readLine() implementation, returning false for this extension can avoid unnecessary double-buffering in QIODevice. |
QAbstractFileEngine::MapExtension | 2 | File engine has the ability to map a file into memory. |
QAbstractFileEngine::UnMapExtension | 3 | File engine provides the ability to unmap memory which was previously mapped. |
The permissions and types of a file which can be ORed together.
Constant | Value | Description |
---|---|---|
QAbstractFileEngine::ReadOwnerPerm | 0x4000 | Owner of the file has permission to read |
QAbstractFileEngine::WriteOwnerPerm | 0x2000 | Owner of the file has permission to write |
QAbstractFileEngine::ExeOwnerPerm | 0x1000 | Owner of the file has permission to execute |
QAbstractFileEngine::ReadUserPerm | 0x0400 | Current user has permission to read |
QAbstractFileEngine::WriteUserPerm | 0x0200 | Current user has permission to write |
QAbstractFileEngine::ExeUserPerm | 0x0100 | Current user has permission to execute |
QAbstractFileEngine::ReadGroupPerm | 0x0040 | Members of the current user's group have permission to read |
QAbstractFileEngine::WriteGroupPerm | 0x0020 | Members of the current user's group have permission to write |
QAbstractFileEngine::ExeGroupPerm | 0x0010 | Members of the current user's group have permission to execute |
QAbstractFileEngine::ReadOtherPerm | 0x0004 | All users have permission to read |
QAbstractFileEngine::WriteOtherPerm | 0x0002 | All users have permission to write |
QAbstractFileEngine::ExeOtherPerm | 0x0001 | All users have permission to execute |
QAbstractFileEngine::LinkType | 0x10000 | File is a link to another file or link |
QAbstractFileEngine::FileType | 0x20000 | File is a regular file, not a link or a directory |
QAbstractFileEngine::BundleType | 0x80000 | File is a Mac OS X bundle |
QAbstractFileEngine::DirectoryType | 0x40000 | File is a directory in the file system, not a file or a link |
QAbstractFileEngine::HiddenFlag | 0x0100000 | File is hidden |
QAbstractFileEngine::ExistsFlag | 0x0400000 | File actually exists in the file system |
QAbstractFileEngine::RootFlag | 0x0800000 | File or the file pointed to is the root of the filesystem |
QAbstractFileEngine::LocalDiskFlag | 0x0200000 | File resides on the local disk and can be passed to standard file methods |
QAbstractFileEngine::Refresh | 0x1000000 | Passing this flag will force the file engine to refresh all flags |
These values are used to request a file name in a particular format.
Constant | Value | Description |
---|---|---|
QAbstractFileEngine::DefaultName | 0 | Same filename which was passed to the QAbstractFileEngine |
QAbstractFileEngine::BaseName | 1 | Name of the file excluding the path |
QAbstractFileEngine::PathName | 2 | Path to the file excluding the base name |
QAbstractFileEngine::AbsoluteName | 3 | Absolute path to the file (including the base name) |
QAbstractFileEngine::AbsolutePathName | 4 | Absolute path to the file (excluding the base name) |
QAbstractFileEngine::LinkName | 5 | Full file name of the target of this link, empty if this file is not a link |
QAbstractFileEngine::CanonicalName | 6 | Often very similar to LinkName, will return the canonical path to the file |
QAbstractFileEngine::CanonicalPathName | 7 | Same as CanonicalName, excluding the base name |
QAbstractFileEngine::BundleName | 8 | Returns the name of the bundle |
|
virtual |
Destroys the current QAbstractFileEngine.
|
protected |
Constructs a new QAbstractFileEngine which does not refer to any specific file or directory.
bool QAbstractFileEngine::atEnd | ( | ) | const |
Returns true if the current position is at the end of the file, otherwise returns false.
This method calls extension() with the enum AtEndExtension. If the current QAbstractFileEngine does not support this extension, false will be returned.
|
virtual |
Returns a pointer to a QAbstractFileEngineIterator. Only files matching filters and filterNames will be part of the list. The caller is the owner of the iterator and is responsible for deleting it.
Reimplemented in QFSFileEngine::beginEntryList()
|
virtual |
This method returns true if the underlying file system is case sensitive, otherwise return false.
Reimplemented in QFSFileEngine::caseSensitive()
|
virtual |
Closes the file, returning true if successful, otherwise returns false. The default implementation always returns false.
Reimplemented in QFSFileEngine::close()
|
virtual |
Copies the contents of the current file to a file with the name newName. Returns true on success, otherwise false is returned.
Reimplemented in QFSFileEngine::copy()
|
static |
Creates and returns a QAbstractFileEngine for processing fileName. Normally, this method should not be called. Prefer using methods in QFile, QFileInfo or QDir.
When overriding this method only return a file engine which can handle the given fileName, otherwise it should return a nullptr.
|
virtual |
Returns a list of all files matching filters based on the filterNames in the current QAbstractFileEngine.
This method should return an empty list if the QAbstractFileEngine refers to a file rather than a directory. It should also return an empty list if the directory is unreadable, the directory does not exist, or if there are no filter matches.
Reimplemented in QFSFileEngine::entryList()
QFile::FileError QAbstractFileEngine::error | ( | ) | const |
Returns a value from the enum QFile::FileError which resulted from the last failed operation.
QString QAbstractFileEngine::errorString | ( | ) | const |
|
virtual |
This method can be reimplemented in a custom QAbstractFileEngine class to provide support for extensions. The value for option is the input to the extension and this method needs to store the output result in output.
The behavior of this method is determined by extension. You can call supportsExtension() to check if an extension is supported by the current file engine. By default, no extensions are supported and this method returns false.
This method returns the set of flags which are true for the current file, if they match the flags in the given type.
Reimplemented in QFSFileEngine::fileFlags()
Returns the file name for the current QAbstractFileEngine in the format specified by value of the file enum.
Reimplemented in QFSFileEngine::fileName()
|
virtual |
If type is CreationTime, returns when the file was created. If type is ModificationTime, returns when the file was most recently modified. If type is AccessTime, returns when the file was most recently accessed.
If the time can not be determined this method returns an invalid QDateTime().
Reimplemented in QFSFileEngine::fileTime()
|
virtual |
Flushes the current open file and returns true if successful, otherwise returns false. The default implementation always returns false.
Reimplemented in QFSFileEngine::flush()
|
virtual |
Returns the native file handle for the current QAbstractFileEngine. This handle must be used carefully since the type and value are platform specific. Using this method can lead to non-portable code.
Reimplemented in QFSFileEngine::handle()
|
virtual |
Return true if the file for the current QAbstractFileEngine has a relative path, otherwise return false.
Reimplemented in QFSFileEngine::isRelativePath()
|
virtual |
Returns true if the file is a sequential access device. Returns false if the file is a random access device. Operations involving size() and seek(int) are not valid on sequential devices.
Reimplemented in QFSFileEngine::isSequential()
|
virtual |
Creates a link from the file specified by fileName(), to the given newName. Returns true if successful, otherwise returns false.
The definition of a link depends on the underlying file system. On Unix it is a symbolic link. On Windows a link is a shortcut. To create a valid link on Windows the given newName must have a ".lnk" file extension.
Reimplemented in QFSFileEngine::link()
uchar * QAbstractFileEngine::map | ( | qint64 | offset, |
qint64 | size, | ||
QFile::MemoryMapFlags | flags | ||
) |
Makes an operating system call which mirrors the contents of the current file in memory.
This method maps size bytes of the current file into memory starting at offset. Returns a pointer to the beginning of the mapped memory when successful, otherwise returns a nullptr.
Calls extension() with the enum value MapExtensionOption. If the QAbstractFileEngine does not support this extension a nullptr is returned. The value for flags is not used.
|
virtual |
Creates a new directory with the specified dirName. If the operation succeeds return true, otherwise return false.
If createParentDirectories is true, then any parent directories in dirName which do not exist are also created. If createParentDirectories is false then any parent directories in dirName must already exist for this method to succeed.
Reimplemented in QFSFileEngine::mkdir()
|
virtual |
Opens the file in the specified mode. Returns true if the file was successfully opened, otherwise returns false. The mode is an OR combination of QIODevice::OpenMode and QIODevice::HandlingMode values.
Reimplemented in QFSFileEngine::open()
If owner is OwnerUser returns the name of the user who owns the file. If owner is OwnerGroup returns the name of the group who owns the file. If the owner can not be determined returns an empty QString().
Reimplemented in QFSFileEngine::owner()
If owner is OwnerUser returns the ID of the user who owns the file. If owner is OwnerGroup returns the ID of the group which owns the file. If the owner can not be determined -2 is returned.
Reimplemented in QFSFileEngine::ownerId()
|
virtual |
Returns the current file position. This is the position where data will be read/write.
Reimplemented in QFSFileEngine::pos()
Reads characters from the file into data. At most maxlen characters will be read. Returns -1 if a fatal error occurs or 0 if there are no bytes to read.
Reimplemented in QFSFileEngine::read()
This method reads one line which is terminated by a '\n' character into data. At most maxlen characters will be read. The end of line character is included.
Reimplemented in QFSFileEngine::readLine()
|
virtual |
Requests the file for the current QAbstractFileEngine should be deleted from the file system. If the operation succeeds return true, otherwise return false.
Reimplemented in QFSFileEngine::remove()
|
virtual |
Requests the file for the current QAbstractFileEngine should be renamed to newName. If the operation succeeds the method returns true, otherwise returns false.
Reimplemented in QFSFileEngine::rename()
|
virtual |
Requests the file for the current QAbstractFileEngine should be renamed to newName. If the new name already exists it must be overwritten. If the operation succeeds the method returns true, otherwise returns false.
Reimplemented in QFSFileEngine::renameOverwrite()
|
virtual |
Requests the directory dirName is deleted from the file system. When recurseParentDirectories is true, any empty parent directories must also be deleted. If recurseParentDirectories is false, only the dirName directory should be deleted. In most file systems a directory can not be deleted using this method if it is not empty. If the operation succeeds return true, otherwise return false.
Reimplemented in QFSFileEngine::rmdir()
|
virtual |
Sets the file position to the given offset. Returns true if the position was successfully set, otherwise returns false. The offset is from the beginning of the file unless the file is sequential.
Reimplemented in QFSFileEngine::seek()
|
protected |
Sets the error type to error and the error string to errorString.
|
virtual |
Sets the filename for the current QAbstractFileEngine to file.
Reimplemented in QFSFileEngine::setFileName()
|
virtual |
Sets the file time to newTime based on the given type. Returns true if successful, otherwise returns false.
The file must be open to use this method.
Reimplemented in QFSFileEngine::setFileTime()
|
virtual |
Set the file permission to perms. If the operation succeeds true is returned, otherwise false is returned.
Reimplemented in QFSFileEngine::setPermissions()
|
virtual |
Set the file to the given size. If size is larger than the current file the appended bytes are filled with zeros. If size is smaller, the file is truncated. If the operations succeeds returns true, otherwise returns false.
Reimplemented in QFSFileEngine::setSize()
|
virtual |
Returns the size of the file for the current QAbstractFileEngine.
Reimplemented in QFSFileEngine::size()
|
virtual |
This method returns true if the file engine supports extension, otherwise false is returned. By default no extensions are supported.
Reimplemented in QFSFileEngine::supportsExtension()
|
virtual |
Flushes the contents of the file for the current QAbstractFileEngine to the file on disk. Returns true if successful, otherwise returns false.
Reimplemented in QFSFileEngine::syncToDisk()
bool QAbstractFileEngine::unmap | ( | uchar * | address | ) |
Makes an operating system call which clears a memory mapping. The method map() must have been previously called.
This method undoes the mapping at the given address. Returns true if this succeeds, otherwise returns false.
Calls extension() with UnMapExtensionOption. If the engine does not support this extension false is returned.
Writes len number of bytes from data to the file for the current QAbstractFileEngine. If the write succeeds, the number of characters written is returned, otherwise returns -1.
Reimplemented in QFSFileEngine::write()