| 1 | /* |
| 2 | This file is part of the KDE project |
| 3 | SPDX-FileCopyrightText: 2009 David Faure <faure@kde.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 6 | */ |
| 7 | |
| 8 | #ifndef KSYCOCADEVICES_P_H |
| 9 | #define KSYCOCADEVICES_P_H |
| 10 | |
| 11 | #include <config-ksycoca.h> |
| 12 | #include <stdlib.h> |
| 13 | // TODO: remove mmap() from kdewin32 and use QFile::mmap() when needed |
| 14 | #ifdef Q_OS_WIN |
| 15 | #define HAVE_MMAP 0 |
| 16 | #endif |
| 17 | |
| 18 | class QString; |
| 19 | class QDataStream; |
| 20 | class QBuffer; |
| 21 | class QFile; |
| 22 | class QIODevice; |
| 23 | class KMemFile; |
| 24 | |
| 25 | class KSycocaAbstractDevice |
| 26 | { |
| 27 | public: |
| 28 | KSycocaAbstractDevice() |
| 29 | : m_stream(nullptr) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | virtual ~KSycocaAbstractDevice(); |
| 34 | |
| 35 | virtual QIODevice *device() = 0; |
| 36 | |
| 37 | QDataStream *&stream(); |
| 38 | |
| 39 | private: |
| 40 | QDataStream *m_stream; |
| 41 | }; |
| 42 | |
| 43 | #if HAVE_MMAP |
| 44 | // Reading from a mmap'ed file |
| 45 | class KSycocaMmapDevice : public KSycocaAbstractDevice |
| 46 | { |
| 47 | public: |
| 48 | KSycocaMmapDevice(const char *sycoca_mmap, size_t sycoca_size); |
| 49 | ~KSycocaMmapDevice() override; |
| 50 | QIODevice *device() override; |
| 51 | |
| 52 | private: |
| 53 | QBuffer *m_buffer; |
| 54 | }; |
| 55 | #endif |
| 56 | |
| 57 | // Reading from a QFile |
| 58 | class KSycocaFileDevice : public KSycocaAbstractDevice |
| 59 | { |
| 60 | public: |
| 61 | explicit KSycocaFileDevice(const QString &path); |
| 62 | ~KSycocaFileDevice() override; |
| 63 | QIODevice *device() override; |
| 64 | |
| 65 | private: |
| 66 | QFile *m_database; |
| 67 | }; |
| 68 | |
| 69 | #ifndef QT_NO_SHAREDMEMORY |
| 70 | // Reading from a KMemFile |
| 71 | class KSycocaMemFileDevice : public KSycocaAbstractDevice |
| 72 | { |
| 73 | public: |
| 74 | explicit KSycocaMemFileDevice(const QString &path); |
| 75 | ~KSycocaMemFileDevice() override; |
| 76 | QIODevice *device() override; |
| 77 | |
| 78 | private: |
| 79 | KMemFile *m_database; |
| 80 | }; |
| 81 | #endif |
| 82 | |
| 83 | // Reading from a dummy memory buffer |
| 84 | class KSycocaBufferDevice : public KSycocaAbstractDevice |
| 85 | { |
| 86 | public: |
| 87 | KSycocaBufferDevice(); |
| 88 | ~KSycocaBufferDevice() override; |
| 89 | QIODevice *device() override; |
| 90 | |
| 91 | private: |
| 92 | QBuffer *m_buffer; |
| 93 | }; |
| 94 | |
| 95 | #endif /* KSYCOCADEVICES_P_H */ |
| 96 | |