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

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • 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 
25 class KSycocaAbstractDevice
26 {
27 public:
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 
44 private:
45  QDataStream* m_stream;
46 };
47 
48 #ifdef HAVE_MMAP
49 // Reading from a mmap'ed file
50 class KSycocaMmapDevice : public KSycocaAbstractDevice
51 {
52 public:
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  }
63 private:
64  QBuffer* m_buffer;
65 };
66 #endif
67 
68 // Reading from a QFile
69 class KSycocaFileDevice : public KSycocaAbstractDevice
70 {
71 public:
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  }
84 private:
85  QFile* m_database;
86 };
87 
88 #ifndef QT_NO_SHAREDMEMORY
89 // Reading from a KMemFile
90 class KSycocaMemFileDevice : public KSycocaAbstractDevice
91 {
92 public:
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  }
102 private:
103  KMemFile* m_database;
104 };
105 #endif
106 
107 // Reading from a dummy memory buffer
108 class KSycocaBufferDevice : public KSycocaAbstractDevice
109 {
110 public:
111  KSycocaBufferDevice() {
112  m_buffer = new QBuffer;
113  }
114  ~KSycocaBufferDevice() {
115  delete m_buffer;
116  }
117  virtual QIODevice* device() {
118  return m_buffer;
119  }
120 private:
121  QBuffer* m_buffer;
122 };
123 
124 #endif /* KSYCOCADEVICES_P_H */
125 
QIODevice
KSycocaMemFileDevice::~KSycocaMemFileDevice
~KSycocaMemFileDevice()
Definition: ksycocadevices_p.h:96
KSycocaAbstractDevice::~KSycocaAbstractDevice
virtual ~KSycocaAbstractDevice()
Definition: ksycocadevices_p.h:32
KSycocaFileDevice
Definition: ksycocadevices_p.h:69
KSycocaAbstractDevice::KSycocaAbstractDevice
KSycocaAbstractDevice()
Definition: ksycocadevices_p.h:28
QDataStream
QFile::handle
int handle() const
KSycocaBufferDevice::KSycocaBufferDevice
KSycocaBufferDevice()
Definition: ksycocadevices_p.h:111
QBuffer::setData
void setData(const QByteArray &data)
QByteArray::fromRawData
QByteArray fromRawData(const char *data, int size)
KSycocaMemFileDevice::device
virtual QIODevice * device()
Definition: ksycocadevices_p.h:99
QBuffer
QFile
KSycocaBufferDevice
Definition: ksycocadevices_p.h:108
KSycocaFileDevice::KSycocaFileDevice
KSycocaFileDevice(const QString &path)
Definition: ksycocadevices_p.h:72
KSycocaFileDevice::device
virtual QIODevice * device()
Definition: ksycocadevices_p.h:81
KSycocaBufferDevice::device
virtual QIODevice * device()
Definition: ksycocadevices_p.h:117
KSycocaFileDevice::~KSycocaFileDevice
~KSycocaFileDevice()
Definition: ksycocadevices_p.h:78
KSycocaAbstractDevice::stream
QDataStream *& stream()
Definition: ksycocadevices_p.h:36
QString
KSycocaMemFileDevice
Definition: ksycocadevices_p.h:90
KMemFile
Definition: kmemfile.h:39
KSycocaMemFileDevice::KSycocaMemFileDevice
KSycocaMemFileDevice(const QString &path)
Definition: ksycocadevices_p.h:93
QDataStream::setVersion
void setVersion(int v)
KSycocaBufferDevice::~KSycocaBufferDevice
~KSycocaBufferDevice()
Definition: ksycocadevices_p.h:114
KSycocaAbstractDevice::device
virtual QIODevice * device()=0
KSycocaAbstractDevice
Definition: ksycocadevices_p.h:25
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:11 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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