Drop QFile::fileEngine
authorJoão Abecasis <joao.abecasis@nokia.com>
Sat, 4 Feb 2012 00:10:55 +0000 (01:10 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 16 Feb 2012 00:59:56 +0000 (01:59 +0100)
The function was already marked as internal.

By moving access to the underlying file engine to private API this
supports the effort to completely drop file engines from public API. In
the future, the goal is to completely drop the file-engine abstraction
as it exists today.

Change-Id: I332fa56e70c87e83c1e08bb9f75e04df7c93fec7
Reviewed-by: Jonas Gastal <jgastal@profusion.mobi>
Reviewed-by: Anselmo L. S. Melo <anselmo.melo@openbossa.org>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
src/corelib/io/qfile.cpp
src/corelib/io/qfile.h
src/corelib/io/qfile_p.h
src/corelib/io/qtemporaryfile.cpp
src/corelib/io/qtemporaryfile.h

index d7308c7..58935fa 100644 (file)
@@ -130,6 +130,13 @@ QFilePrivate::openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handl
 #endif
 }
 
 #endif
 }
 
+QAbstractFileEngine *QFilePrivate::engine() const
+{
+    if (!fileEngine)
+        fileEngine = QAbstractFileEngine::create(fileName);
+    return fileEngine;
+}
+
 inline bool QFilePrivate::ensureFlushed() const
 {
     // This function ensures that the write buffer has been flushed (const
 inline bool QFilePrivate::ensureFlushed() const
 {
     // This function ensures that the write buffer has been flushed (const
@@ -424,7 +431,8 @@ QFile::~QFile()
 */
 QString QFile::fileName() const
 {
 */
 QString QFile::fileName() const
 {
-    return fileEngine()->fileName(QAbstractFileEngine::DefaultName);
+    Q_D(const QFile);
+    return d->engine()->fileName(QAbstractFileEngine::DefaultName);
 }
 
 /*!
 }
 
 /*!
@@ -569,8 +577,9 @@ QFile::setDecodingFunction(DecoderFn f)
 bool
 QFile::exists() const
 {
 bool
 QFile::exists() const
 {
+    Q_D(const QFile);
     // 0x1000000 = QAbstractFileEngine::Refresh, forcing an update
     // 0x1000000 = QAbstractFileEngine::Refresh, forcing an update
-    return (fileEngine()->fileFlags(QAbstractFileEngine::FlagsMask
+    return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask
                                     | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);
 }
 
                                     | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);
 }
 
@@ -608,7 +617,8 @@ QFile::exists(const QString &fileName)
 QString
 QFile::readLink() const
 {
 QString
 QFile::readLink() const
 {
-    return fileEngine()->fileName(QAbstractFileEngine::LinkName);
+    Q_D(const QFile);
+    return d->engine()->fileName(QAbstractFileEngine::LinkName);
 }
 
 /*!
 }
 
 /*!
@@ -654,7 +664,7 @@ QFile::remove()
     unsetError();
     close();
     if(error() == QFile::NoError) {
     unsetError();
     close();
     if(error() == QFile::NoError) {
-        if(fileEngine()->remove()) {
+        if (d->engine()->remove()) {
             unsetError();
             return true;
         }
             unsetError();
             return true;
         }
@@ -709,7 +719,7 @@ QFile::rename(const QString &newName)
     unsetError();
     close();
     if(error() == QFile::NoError) {
     unsetError();
     close();
     if(error() == QFile::NoError) {
-        if (fileEngine()->rename(newName)) {
+        if (d->engine()->rename(newName)) {
             unsetError();
             // engine was able to handle the new name so we just reset it
             d->fileEngine->setFileName(newName);
             unsetError();
             // engine was able to handle the new name so we just reset it
             d->fileEngine->setFileName(newName);
@@ -806,7 +816,7 @@ QFile::link(const QString &linkName)
         return false;
     }
     QFileInfo fi(linkName);
         return false;
     }
     QFileInfo fi(linkName);
-    if(fileEngine()->link(fi.absoluteFilePath())) {
+    if (d->engine()->link(fi.absoluteFilePath())) {
         unsetError();
         return true;
     }
         unsetError();
         return true;
     }
@@ -861,7 +871,7 @@ QFile::copy(const QString &newName)
     unsetError();
     close();
     if(error() == QFile::NoError) {
     unsetError();
     close();
     if(error() == QFile::NoError) {
-        if(fileEngine()->copy(newName)) {
+        if (d->engine()->copy(newName)) {
             unsetError();
             return true;
         } else {
             unsetError();
             return true;
         } else {
@@ -996,7 +1006,7 @@ bool QFile::open(OpenMode mode)
     }
 
     // QIODevice provides the buffering, so there's no need to request it from the file engine.
     }
 
     // QIODevice provides the buffering, so there's no need to request it from the file engine.
-    if (fileEngine()->open(mode | QIODevice::Unbuffered)) {
+    if (d->engine()->open(mode | QIODevice::Unbuffered)) {
         QIODevice::open(mode);
         if (mode & Append)
             seek(size());
         QIODevice::open(mode);
         if (mode & Append)
             seek(size());
@@ -1271,7 +1281,7 @@ QFile::handle() const
 uchar *QFile::map(qint64 offset, qint64 size, MemoryMapFlags flags)
 {
     Q_D(QFile);
 uchar *QFile::map(qint64 offset, qint64 size, MemoryMapFlags flags)
 {
     Q_D(QFile);
-    if (fileEngine()
+    if (d->engine()
             && d->fileEngine->supportsExtension(QAbstractFileEngine::MapExtension)) {
         unsetError();
         uchar *address = d->fileEngine->map(offset, size, flags);
             && d->fileEngine->supportsExtension(QAbstractFileEngine::MapExtension)) {
         unsetError();
         uchar *address = d->fileEngine->map(offset, size, flags);
@@ -1293,7 +1303,7 @@ uchar *QFile::map(qint64 offset, qint64 size, MemoryMapFlags flags)
 bool QFile::unmap(uchar *address)
 {
     Q_D(QFile);
 bool QFile::unmap(uchar *address)
 {
     Q_D(QFile);
-    if (fileEngine()
+    if (d->engine()
         && d->fileEngine->supportsExtension(QAbstractFileEngine::UnMapExtension)) {
         unsetError();
         bool success = d->fileEngine->unmap(address);
         && d->fileEngine->supportsExtension(QAbstractFileEngine::UnMapExtension)) {
         unsetError();
         bool success = d->fileEngine->unmap(address);
@@ -1320,7 +1330,7 @@ QFile::resize(qint64 sz)
     Q_D(QFile);
     if (!d->ensureFlushed())
         return false;
     Q_D(QFile);
     if (!d->ensureFlushed())
         return false;
-    fileEngine();
+    d->engine();
     if (isOpen() && d->fileEngine->pos() > sz)
         seek(sz);
     if(d->fileEngine->setSize(sz)) {
     if (isOpen() && d->fileEngine->pos() > sz)
         seek(sz);
     if(d->fileEngine->setSize(sz)) {
@@ -1360,7 +1370,8 @@ QFile::resize(const QString &fileName, qint64 sz)
 QFile::Permissions
 QFile::permissions() const
 {
 QFile::Permissions
 QFile::permissions() const
 {
-    QAbstractFileEngine::FileFlags perms = fileEngine()->fileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask;
+    Q_D(const QFile);
+    QAbstractFileEngine::FileFlags perms = d->engine()->fileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask;
     return QFile::Permissions((int)perms); //ewww
 }
 
     return QFile::Permissions((int)perms); //ewww
 }
 
@@ -1389,7 +1400,7 @@ bool
 QFile::setPermissions(Permissions permissions)
 {
     Q_D(QFile);
 QFile::setPermissions(Permissions permissions)
 {
     Q_D(QFile);
-    if(fileEngine()->setPermissions(permissions)) {
+    if (d->engine()->setPermissions(permissions)) {
         unsetError();
         return true;
     }
         unsetError();
         return true;
     }
@@ -1490,7 +1501,7 @@ qint64 QFile::size() const
     Q_D(const QFile);
     if (!d->ensureFlushed())
         return 0;
     Q_D(const QFile);
     if (!d->ensureFlushed())
         return 0;
-    d->cachedSize = fileEngine()->size();
+    d->cachedSize = d->engine()->size();
     return d->cachedSize;
 }
 
     return d->cachedSize;
 }
 
@@ -1731,18 +1742,6 @@ QFile::writeData(const char *data, qint64 len)
 }
 
 /*!
 }
 
 /*!
-    \internal
-    Returns the QIOEngine for this QFile object.
-*/
-QAbstractFileEngine *QFile::fileEngine() const
-{
-    Q_D(const QFile);
-    if(!d->fileEngine)
-        d->fileEngine = QAbstractFileEngine::create(d->fileName);
-    return d->fileEngine;
-}
-
-/*!
     Returns the file error status.
 
     The I/O device status returns an error code. For example, if open()
     Returns the file error status.
 
     The I/O device status returns an error code. For example, if open()
index bc278cf..bf7290d 100644 (file)
@@ -54,8 +54,7 @@ QT_BEGIN_HEADER
 
 QT_BEGIN_NAMESPACE
 
 
 QT_BEGIN_NAMESPACE
 
-
-class QAbstractFileEngine;
+class QTemporaryFile;
 class QFilePrivate;
 
 class Q_CORE_EXPORT QFile : public QIODevice
 class QFilePrivate;
 
 class Q_CORE_EXPORT QFile : public QIODevice
@@ -174,8 +173,6 @@ public:
     uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
     bool unmap(uchar *address);
 
     uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
     bool unmap(uchar *address);
 
-    virtual QAbstractFileEngine *fileEngine() const;
-
 protected:
 #ifdef QT_NO_QOBJECT
     QFile(QFilePrivate &dd);
 protected:
 #ifdef QT_NO_QOBJECT
     QFile(QFilePrivate &dd);
@@ -188,6 +185,7 @@ protected:
     qint64 readLineData(char *data, qint64 maxlen);
 
 private:
     qint64 readLineData(char *data, qint64 maxlen);
 
 private:
+    friend class QTemporaryFile;
     Q_DISABLE_COPY(QFile)
 };
 
     Q_DISABLE_COPY(QFile)
 };
 
index b932627..4a637d4 100644 (file)
 
 QT_BEGIN_NAMESPACE
 
 
 QT_BEGIN_NAMESPACE
 
+class QTemporaryFile;
+
 class QFilePrivate : public QIODevicePrivate
 {
     Q_DECLARE_PUBLIC(QFile)
 class QFilePrivate : public QIODevicePrivate
 {
     Q_DECLARE_PUBLIC(QFile)
+    friend class QTemporaryFile;
 
 protected:
     QFilePrivate();
 
 protected:
     QFilePrivate();
@@ -70,6 +73,8 @@ protected:
     bool openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags);
     bool openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handleFlags);
 
     bool openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags);
     bool openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handleFlags);
 
+    virtual QAbstractFileEngine *engine() const;
+
     QString fileName;
     mutable QAbstractFileEngine *fileEngine;
 
     QString fileName;
     mutable QAbstractFileEngine *fileEngine;
 
index b80ba6e..75681da 100644 (file)
@@ -407,6 +407,8 @@ protected:
     QTemporaryFilePrivate();
     ~QTemporaryFilePrivate();
 
     QTemporaryFilePrivate();
     ~QTemporaryFilePrivate();
 
+    QAbstractFileEngine *engine() const;
+
     bool autoRemove;
     QString templateName;
 };
     bool autoRemove;
     QString templateName;
 };
@@ -419,6 +421,17 @@ QTemporaryFilePrivate::~QTemporaryFilePrivate()
 {
 }
 
 {
 }
 
+QAbstractFileEngine *QTemporaryFilePrivate::engine() const
+{
+    if (!fileEngine) {
+        if (fileName.isEmpty())
+            fileEngine = new QTemporaryFileEngine(templateName);
+        else
+            fileEngine = new QTemporaryFileEngine(fileName, false);
+    }
+    return fileEngine;
+}
+
 static QString defaultTemplateName()
 {
     QString baseName;
 static QString defaultTemplateName()
 {
     QString baseName;
@@ -640,7 +653,7 @@ QString QTemporaryFile::fileName() const
     Q_D(const QTemporaryFile);
     if(d->fileName.isEmpty())
         return QString();
     Q_D(const QTemporaryFile);
     if(d->fileName.isEmpty())
         return QString();
-    return fileEngine()->fileName(QAbstractFileEngine::DefaultName);
+    return d->engine()->fileName(QAbstractFileEngine::DefaultName);
 }
 
 /*!
 }
 
 /*!
@@ -692,7 +705,7 @@ void QTemporaryFile::setFileTemplate(const QString &name)
 */
 QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
 {
 */
 QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
 {
-    if (QAbstractFileEngine *engine = file.fileEngine()) {
+    if (QAbstractFileEngine *engine = file.d_func()->engine()) {
         if(engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)
             return 0; //local already
         //cache
         if(engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)
             return 0; //local already
         //cache
@@ -726,22 +739,6 @@ QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
 }
 
 /*!
 }
 
 /*!
-   \internal
-*/
-
-QAbstractFileEngine *QTemporaryFile::fileEngine() const
-{
-    Q_D(const QTemporaryFile);
-    if(!d->fileEngine) {
-        if (d->fileName.isEmpty())
-            d->fileEngine = new QTemporaryFileEngine(d->templateName);
-        else
-            d->fileEngine = new QTemporaryFileEngine(d->fileName, false);
-    }
-    return d->fileEngine;
-}
-
-/*!
    \reimp
 
     Creates a unique file name for the temporary file, and opens it.  You can
    \reimp
 
     Creates a unique file name for the temporary file, and opens it.  You can
@@ -752,7 +749,7 @@ bool QTemporaryFile::open(OpenMode flags)
 {
     Q_D(QTemporaryFile);
     if (!d->fileName.isEmpty()) {
 {
     Q_D(QTemporaryFile);
     if (!d->fileName.isEmpty()) {
-        if (static_cast<QTemporaryFileEngine*>(fileEngine())->isReallyOpen()) {
+        if (static_cast<QTemporaryFileEngine*>(d->engine())->isReallyOpen()) {
             setOpenMode(flags);
             return true;
         }
             setOpenMode(flags);
             return true;
         }
index 8b14e5a..e766569 100644 (file)
@@ -88,8 +88,6 @@ public:
         { QFile file(fileName); return createLocalFile(file); }
     static QTemporaryFile *createLocalFile(QFile &file);
 
         { QFile file(fileName); return createLocalFile(file); }
     static QTemporaryFile *createLocalFile(QFile &file);
 
-    virtual QAbstractFileEngine *fileEngine() const;
-
 protected:
     bool open(OpenMode flags);
 
 protected:
     bool open(OpenMode flags);