• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • sycoca
ksycocadevices_p.h
Go to the documentation of this file.
1/* This file is part of the KDE project
2
3 Copyright 2009 David Faure <faure@kde.org>
4
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Library General Public License as published
7 by the Free Software Foundation; either version 2 of the License or
8 ( at your option ) version 3 or, at the discretion of KDE e.V.
9 ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#ifndef KSYCOCADEVICES_P_H
23#define KSYCOCADEVICES_P_H
24
25class KSycocaAbstractDevice
26{
27public:
28 KSycocaAbstractDevice() : m_stream(0)
29 {
30 }
31
32 virtual ~KSycocaAbstractDevice() { delete m_stream; }
33
34 virtual QIODevice* device() = 0;
35
36 QDataStream* & stream() {
37 if (!m_stream) {
38 m_stream = new QDataStream(device());
39 m_stream->setVersion(QDataStream::Qt_3_1);
40 }
41 return m_stream;
42 }
43
44private:
45 QDataStream* m_stream;
46};
47
48#ifdef HAVE_MMAP
49// Reading from a mmap'ed file
50class KSycocaMmapDevice : public KSycocaAbstractDevice
51{
52public:
53 KSycocaMmapDevice(const char* sycoca_mmap, size_t sycoca_size) {
54 m_buffer = new QBuffer;
55 m_buffer->setData(QByteArray::fromRawData(sycoca_mmap, sycoca_size));
56 }
57 ~KSycocaMmapDevice() {
58 delete m_buffer;
59 }
60 virtual QIODevice* device() {
61 return m_buffer;
62 }
63private:
64 QBuffer* m_buffer;
65};
66#endif
67
68// Reading from a QFile
69class KSycocaFileDevice : public KSycocaAbstractDevice
70{
71public:
72 KSycocaFileDevice(const QString& path) {
73 m_database = new QFile(path);
74#ifndef Q_OS_WIN
75 (void)fcntl(m_database->handle(), F_SETFD, FD_CLOEXEC);
76#endif
77 }
78 ~KSycocaFileDevice() {
79 delete m_database;
80 }
81 virtual QIODevice* device() {
82 return m_database;
83 }
84private:
85 QFile* m_database;
86};
87
88#ifndef QT_NO_SHAREDMEMORY
89// Reading from a KMemFile
90class KSycocaMemFileDevice : public KSycocaAbstractDevice
91{
92public:
93 KSycocaMemFileDevice(const QString& path) {
94 m_database = new KMemFile(path);
95 }
96 ~KSycocaMemFileDevice() {
97 delete m_database;
98 }
99 virtual QIODevice* device() {
100 return m_database;
101 }
102private:
103 KMemFile* m_database;
104};
105#endif
106
107// Reading from a dummy memory buffer
108class KSycocaBufferDevice : public KSycocaAbstractDevice
109{
110public:
111 KSycocaBufferDevice() {
112 m_buffer = new QBuffer;
113 }
114 ~KSycocaBufferDevice() {
115 delete m_buffer;
116 }
117 virtual QIODevice* device() {
118 return m_buffer;
119 }
120private:
121 QBuffer* m_buffer;
122};
123
124#endif /* KSYCOCADEVICES_P_H */
125
KMemFile
Definition: kmemfile.h:40
KSycocaAbstractDevice
Definition: ksycocadevices_p.h:26
KSycocaAbstractDevice::device
virtual QIODevice * device()=0
KSycocaAbstractDevice::stream
QDataStream *& stream()
Definition: ksycocadevices_p.h:36
KSycocaAbstractDevice::KSycocaAbstractDevice
KSycocaAbstractDevice()
Definition: ksycocadevices_p.h:28
KSycocaAbstractDevice::~KSycocaAbstractDevice
virtual ~KSycocaAbstractDevice()
Definition: ksycocadevices_p.h:32
KSycocaBufferDevice
Definition: ksycocadevices_p.h:109
KSycocaBufferDevice::KSycocaBufferDevice
KSycocaBufferDevice()
Definition: ksycocadevices_p.h:111
KSycocaBufferDevice::~KSycocaBufferDevice
~KSycocaBufferDevice()
Definition: ksycocadevices_p.h:114
KSycocaBufferDevice::device
virtual QIODevice * device()
Definition: ksycocadevices_p.h:117
KSycocaFileDevice
Definition: ksycocadevices_p.h:70
KSycocaFileDevice::device
virtual QIODevice * device()
Definition: ksycocadevices_p.h:81
KSycocaFileDevice::~KSycocaFileDevice
~KSycocaFileDevice()
Definition: ksycocadevices_p.h:78
KSycocaFileDevice::KSycocaFileDevice
KSycocaFileDevice(const QString &path)
Definition: ksycocadevices_p.h:72
KSycocaMemFileDevice
Definition: ksycocadevices_p.h:91
KSycocaMemFileDevice::~KSycocaMemFileDevice
~KSycocaMemFileDevice()
Definition: ksycocadevices_p.h:96
KSycocaMemFileDevice::device
virtual QIODevice * device()
Definition: ksycocadevices_p.h:99
KSycocaMemFileDevice::KSycocaMemFileDevice
KSycocaMemFileDevice(const QString &path)
Definition: ksycocadevices_p.h:93
QIODevice
QString
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal