KService

ksycocadevices.cpp
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#include "kmemfile_p.h"
9#include "ksycocadevices_p.h"
10#include <QBuffer>
11#include <QDataStream>
12#include <QFile>
13#include <fcntl.h>
14
15KSycocaAbstractDevice::~KSycocaAbstractDevice()
16{
17 delete m_stream;
18}
19
20QDataStream *&KSycocaAbstractDevice::stream()
21{
22 if (!m_stream) {
23 m_stream = new QDataStream(device());
24 m_stream->setVersion(QDataStream::Qt_5_3);
25 }
26 return m_stream;
27}
28
29#if HAVE_MMAP
30KSycocaMmapDevice::KSycocaMmapDevice(const char *sycoca_mmap, size_t sycoca_size)
31{
32 m_buffer = new QBuffer;
33 m_buffer->setData(QByteArray::fromRawData(sycoca_mmap, sycoca_size));
34}
35
36KSycocaMmapDevice::~KSycocaMmapDevice()
37{
38 delete m_buffer;
39}
40
41QIODevice *KSycocaMmapDevice::device()
42{
43 return m_buffer;
44}
45#endif
46
47KSycocaFileDevice::KSycocaFileDevice(const QString &path)
48{
49 m_database = new QFile(path);
50#ifndef Q_OS_WIN
51 (void)fcntl(m_database->handle(), F_SETFD, FD_CLOEXEC);
52#endif
53}
54
55KSycocaFileDevice::~KSycocaFileDevice()
56{
57 delete m_database;
58}
59
60QIODevice *KSycocaFileDevice::device()
61{
62 return m_database;
63}
64
65#ifndef QT_NO_SHAREDMEMORY
66KSycocaMemFileDevice::KSycocaMemFileDevice(const QString &path)
67{
68 m_database = new KMemFile(path);
69}
70
71KSycocaMemFileDevice::~KSycocaMemFileDevice()
72{
73 delete m_database;
74}
75
76QIODevice *KSycocaMemFileDevice::device()
77{
78 return m_database;
79}
80#endif
81
82KSycocaBufferDevice::KSycocaBufferDevice()
83{
84 m_buffer = new QBuffer;
85}
86
87KSycocaBufferDevice::~KSycocaBufferDevice()
88{
89 delete m_buffer;
90}
91
92QIODevice *KSycocaBufferDevice::device()
93{
94 return m_buffer;
95}
void setData(const QByteArray &data)
QByteArray fromRawData(const char *data, qsizetype size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 12:01:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.