File indexing completed on 2024-07-14 03:55:25

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2009 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef KSYCOCADEVICES_P_H
0009 #define KSYCOCADEVICES_P_H
0010 
0011 #include <config-ksycoca.h>
0012 #include <stdlib.h>
0013 // TODO: remove mmap() from kdewin32 and use QFile::mmap() when needed
0014 #ifdef Q_OS_WIN
0015 #define HAVE_MMAP 0
0016 #endif
0017 
0018 class QString;
0019 class QDataStream;
0020 class QBuffer;
0021 class QFile;
0022 class QIODevice;
0023 class KMemFile;
0024 
0025 class KSycocaAbstractDevice
0026 {
0027 public:
0028     KSycocaAbstractDevice()
0029         : m_stream(nullptr)
0030     {
0031     }
0032 
0033     virtual ~KSycocaAbstractDevice();
0034 
0035     virtual QIODevice *device() = 0;
0036 
0037     QDataStream *&stream();
0038 
0039 private:
0040     QDataStream *m_stream;
0041 };
0042 
0043 #if HAVE_MMAP
0044 // Reading from a mmap'ed file
0045 class KSycocaMmapDevice : public KSycocaAbstractDevice
0046 {
0047 public:
0048     KSycocaMmapDevice(const char *sycoca_mmap, size_t sycoca_size);
0049     ~KSycocaMmapDevice() override;
0050     QIODevice *device() override;
0051 
0052 private:
0053     QBuffer *m_buffer;
0054 };
0055 #endif
0056 
0057 // Reading from a QFile
0058 class KSycocaFileDevice : public KSycocaAbstractDevice
0059 {
0060 public:
0061     explicit KSycocaFileDevice(const QString &path);
0062     ~KSycocaFileDevice() override;
0063     QIODevice *device() override;
0064 
0065 private:
0066     QFile *m_database;
0067 };
0068 
0069 #ifndef QT_NO_SHAREDMEMORY
0070 // Reading from a KMemFile
0071 class KSycocaMemFileDevice : public KSycocaAbstractDevice
0072 {
0073 public:
0074     explicit KSycocaMemFileDevice(const QString &path);
0075     ~KSycocaMemFileDevice() override;
0076     QIODevice *device() override;
0077 
0078 private:
0079     KMemFile *m_database;
0080 };
0081 #endif
0082 
0083 // Reading from a dummy memory buffer
0084 class KSycocaBufferDevice : public KSycocaAbstractDevice
0085 {
0086 public:
0087     KSycocaBufferDevice();
0088     ~KSycocaBufferDevice() override;
0089     QIODevice *device() override;
0090 
0091 private:
0092     QBuffer *m_buffer;
0093 };
0094 
0095 #endif /* KSYCOCADEVICES_P_H */