KDECore
ksycocadevices_p.h
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 00003 Copyright 2009 David Faure <faure@kde.org> 00004 00005 This library is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU Library General Public License as published 00007 by the Free Software Foundation; either version 2 of the License or 00008 ( at your option ) version 3 or, at the discretion of KDE e.V. 00009 ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef KSYCOCADEVICES_P_H 00023 #define KSYCOCADEVICES_P_H 00024 00025 class KSycocaAbstractDevice 00026 { 00027 public: 00028 KSycocaAbstractDevice() : m_stream(0) 00029 { 00030 } 00031 00032 virtual ~KSycocaAbstractDevice() { delete m_stream; } 00033 00034 virtual QIODevice* device() = 0; 00035 00036 QDataStream* & stream() { 00037 if (!m_stream) { 00038 m_stream = new QDataStream(device()); 00039 m_stream->setVersion(QDataStream::Qt_3_1); 00040 } 00041 return m_stream; 00042 } 00043 00044 private: 00045 QDataStream* m_stream; 00046 }; 00047 00048 #ifdef HAVE_MMAP 00049 // Reading from a mmap'ed file 00050 class KSycocaMmapDevice : public KSycocaAbstractDevice 00051 { 00052 public: 00053 KSycocaMmapDevice(const char* sycoca_mmap, size_t sycoca_size) { 00054 m_buffer = new QBuffer; 00055 m_buffer->setData(QByteArray::fromRawData(sycoca_mmap, sycoca_size)); 00056 } 00057 ~KSycocaMmapDevice() { 00058 delete m_buffer; 00059 } 00060 virtual QIODevice* device() { 00061 return m_buffer; 00062 } 00063 private: 00064 QBuffer* m_buffer; 00065 }; 00066 #endif 00067 00068 // Reading from a QFile 00069 class KSycocaFileDevice : public KSycocaAbstractDevice 00070 { 00071 public: 00072 KSycocaFileDevice(const QString& path) { 00073 m_database = new QFile(path); 00074 #ifndef Q_OS_WIN 00075 fcntl(m_database->handle(), F_SETFD, FD_CLOEXEC); 00076 #endif 00077 } 00078 ~KSycocaFileDevice() { 00079 delete m_database; 00080 } 00081 virtual QIODevice* device() { 00082 return m_database; 00083 } 00084 private: 00085 QFile* m_database; 00086 }; 00087 00088 #ifndef QT_NO_SHAREDMEMORY 00089 // Reading from a KMemFile 00090 class KSycocaMemFileDevice : public KSycocaAbstractDevice 00091 { 00092 public: 00093 KSycocaMemFileDevice(const QString& path) { 00094 m_database = new KMemFile(path); 00095 } 00096 ~KSycocaMemFileDevice() { 00097 delete m_database; 00098 } 00099 virtual QIODevice* device() { 00100 return m_database; 00101 } 00102 private: 00103 KMemFile* m_database; 00104 }; 00105 #endif 00106 00107 // Reading from a dummy memory buffer 00108 class KSycocaBufferDevice : public KSycocaAbstractDevice 00109 { 00110 public: 00111 KSycocaBufferDevice() { 00112 m_buffer = new QBuffer; 00113 } 00114 ~KSycocaBufferDevice() { 00115 delete m_buffer; 00116 } 00117 virtual QIODevice* device() { 00118 return m_buffer; 00119 } 00120 private: 00121 QBuffer* m_buffer; 00122 }; 00123 00124 #endif /* KSYCOCADEVICES_P_H */ 00125
KDE 4.6 API Reference