File indexing completed on 2025-05-04 05:18:38

0001 /* This file is part of the KDE project
0002 
0003    Copyright 2009 David Faure <faure@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or modify
0006    it under the terms of the GNU Library General Public License as published
0007    by the Free Software Foundation; either version 2 of the License or
0008    ( at your option ) version 3 or, at the discretion of KDE e.V.
0009    ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version.
0010 
0011    This library is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.LIB.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019    Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #ifndef KSYCOCADEVICES_P_H
0023 #define KSYCOCADEVICES_P_H
0024 
0025 #include <config-ksycoca.h>
0026 #include <stdlib.h>
0027 // TODO: remove mmap() from kdewin32 and use QFile::mmap() when needed
0028 #ifdef Q_OS_WIN
0029 #undef HAVE_MMAP
0030 #endif
0031 
0032 class QString;
0033 class QDataStream;
0034 class QBuffer;
0035 class QFile;
0036 class QIODevice;
0037 class KMemFile;
0038 
0039 class KSycocaAbstractDevice
0040 {
0041 public:
0042     KSycocaAbstractDevice() : m_stream(nullptr)
0043     {
0044     }
0045 
0046     virtual ~KSycocaAbstractDevice();
0047 
0048     virtual QIODevice *device() = 0;
0049 
0050     QDataStream *&stream();
0051 
0052 private:
0053     QDataStream *m_stream;
0054 };
0055 
0056 #if HAVE_MMAP
0057 // Reading from a mmap'ed file
0058 class KSycocaMmapDevice : public KSycocaAbstractDevice
0059 {
0060 public:
0061     KSycocaMmapDevice(const char *sycoca_mmap, size_t sycoca_size);
0062     ~KSycocaMmapDevice() override;
0063     QIODevice *device() override;
0064 private:
0065     QBuffer *m_buffer;
0066 };
0067 #endif
0068 
0069 // Reading from a QFile
0070 class KSycocaFileDevice : public KSycocaAbstractDevice
0071 {
0072 public:
0073     explicit KSycocaFileDevice(const QString &path);
0074     ~KSycocaFileDevice() override;
0075     QIODevice *device() override;
0076 private:
0077     QFile *m_database;
0078 };
0079 
0080 #ifndef QT_NO_SHAREDMEMORY
0081 // Reading from a KMemFile
0082 class KSycocaMemFileDevice : public KSycocaAbstractDevice
0083 {
0084 public:
0085     explicit KSycocaMemFileDevice(const QString &path);
0086     ~KSycocaMemFileDevice() override;
0087     QIODevice *device() override;
0088 private:
0089     KMemFile *m_database;
0090 };
0091 #endif
0092 
0093 // Reading from a dummy memory buffer
0094 class KSycocaBufferDevice : public KSycocaAbstractDevice
0095 {
0096 public:
0097     KSycocaBufferDevice();
0098     ~KSycocaBufferDevice() override;
0099     QIODevice *device() override;
0100 private:
0101     QBuffer *m_buffer;
0102 };
0103 
0104 #endif /* KSYCOCADEVICES_P_H */