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

KDECore

  • kdecore
  • sycoca
ksycocafactory.h
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 * Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License version 2 as published by the Free Software Foundation;
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU Library General Public License
14 * along with this library; see the file COPYING.LIB. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 **/
18
19#ifndef KSYCOCAFACTORY_H
20#define KSYCOCAFACTORY_H
21
22#include <ksycocaentry.h>
23
24class QString;
25class KSycocaDict;
26class KSycocaResourceList;
27template <typename T> class QList;
28template <typename KT, typename VT> class QHash;
29
30typedef QHash<QString, KSycocaEntry::Ptr> KSycocaEntryDict;
31
36class KDECORE_EXPORT KSycocaFactory
37{
38public:
39 virtual KSycocaFactoryId factoryId() const = 0;
40
41protected: // virtual class
46 explicit KSycocaFactory( KSycocaFactoryId factory_id );
47
48public:
49 virtual ~KSycocaFactory();
50
54 int offset() const;
55
59 KSycocaEntryDict * entryDict() { return m_entryDict; }
60
65 virtual KSycocaEntry *createEntry(const QString &file, const char *resource) const = 0;
66
70 virtual void addEntry(const KSycocaEntry::Ptr& newEntry);
71
76 void removeEntry(const QString& entryName);
77
81 virtual KSycocaEntry *createEntry(int offset) const = 0;
82
86 virtual KSycocaEntry::List allEntries() const;
87
99 virtual void save(QDataStream &str);
100
108 virtual void saveHeader(QDataStream &str);
109
114 const KSycocaResourceList * resourceList() const;
115
119 const KSycocaDict *sycocaDict() const;
120
124 bool isEmpty() const;
125
126protected:
127 QDataStream* stream() const;
128
129 KSycocaResourceList *m_resourceList;
130 KSycocaEntryDict *m_entryDict;
131
132private:
133 QDataStream *m_str;
134 class Private;
135 Private* const d;
136
137protected:
141 virtual void virtual_hook( int id, void* data );
142};
143
148class KDECORE_EXPORT KSycocaFactoryList : public QList<KSycocaFactory*> //krazy:exclude=dpointer (acts as a typedef)
149{
150public:
151 KSycocaFactoryList() { }
152};
153
154#include <QThreadStorage>
159template <typename F> class KSycocaFactoryContainer
160{
161public:
162 KSycocaFactoryContainer(F* factory) : m_factory(factory) {}
163 F* factory() { return m_factory; }
164private:
165 F* m_factory;
166};
167
176template <typename F> class KSycocaFactorySingleton
177{
178public:
179 typedef KSycocaFactoryContainer<F> C;
180 KSycocaFactorySingleton() {
181 }
182 ~KSycocaFactorySingleton() {
183 // Do not delete the factory here.
184 // All factories are owned by KSycoca, and deleted by it.
185 }
186 void instanceCreated(F* newFactory) {
187 // This can also register a subclass created by kbuildsycoca
188 Q_ASSERT(!m_factories.hasLocalData());
189 Q_ASSERT(newFactory);
190 m_factories.setLocalData(new C(newFactory));
191 }
192 void instanceDestroyed(F* factory) {
193 if (m_factories.hasLocalData()) { // could be false on thread exit
194 Q_ASSERT(m_factories.localData()->factory() == factory); Q_UNUSED(factory)
195 m_factories.setLocalData(0);
196 }
197 }
198 F* self() {
199 if (!m_factories.hasLocalData()) {
200 new F; // calls instanceCreated, which calls setLocalData
201 Q_ASSERT(m_factories.hasLocalData());
202 }
203 return m_factories.localData()->factory();
204 }
205private:
206 QThreadStorage<C*> m_factories;
207};
208
209#endif
KSharedPtr
Can be used to control the lifetime of an object that has derived QSharedData.
Definition: ksharedptr.h:64
KSycocaDict
Definition: ksycocadict_p.h:37
KSycocaEntry
Base class for all Sycoca entries.
Definition: ksycocaentry.h:42
KSycocaFactoryContainer
Workaround for the lack of QThreadStorage::setAutoDelete(false).
Definition: ksycocafactory.h:160
KSycocaFactoryContainer::KSycocaFactoryContainer
KSycocaFactoryContainer(F *factory)
Definition: ksycocafactory.h:162
KSycocaFactoryContainer::factory
F * factory()
Definition: ksycocafactory.h:163
KSycocaFactoryList
This, instead of a typedef, allows to declare "class ..." in header files.
Definition: ksycocafactory.h:149
KSycocaFactoryList::KSycocaFactoryList
KSycocaFactoryList()
Definition: ksycocafactory.h:151
KSycocaFactorySingleton
Template for making it easier to define a threadsafe singleton for each factory, with support for kbu...
Definition: ksycocafactory.h:177
KSycocaFactorySingleton::C
KSycocaFactoryContainer< F > C
Definition: ksycocafactory.h:179
KSycocaFactorySingleton::instanceDestroyed
void instanceDestroyed(F *factory)
Definition: ksycocafactory.h:192
KSycocaFactorySingleton::instanceCreated
void instanceCreated(F *newFactory)
Definition: ksycocafactory.h:186
KSycocaFactorySingleton::~KSycocaFactorySingleton
~KSycocaFactorySingleton()
Definition: ksycocafactory.h:182
KSycocaFactorySingleton::self
F * self()
Definition: ksycocafactory.h:198
KSycocaFactorySingleton::KSycocaFactorySingleton
KSycocaFactorySingleton()
Definition: ksycocafactory.h:180
KSycocaFactory
Definition: ksycocafactory.h:37
KSycocaFactory::m_entryDict
KSycocaEntryDict * m_entryDict
Definition: ksycocafactory.h:130
KSycocaFactory::createEntry
virtual KSycocaEntry * createEntry(int offset) const =0
Read an entry from the database.
KSycocaFactory::entryDict
KSycocaEntryDict * entryDict()
Definition: ksycocafactory.h:59
KSycocaFactory::m_resourceList
KSycocaResourceList * m_resourceList
Definition: ksycocafactory.h:129
KSycocaFactory::createEntry
virtual KSycocaEntry * createEntry(const QString &file, const char *resource) const =0
Construct an entry from a config file.
KSycocaFactory::KSycocaFactoryId
KSycocaFactoryId
A KSycocaFactoryId is a code (out of the KSycocaFactoryId enum) assigned to each class type derived f...
Definition: ksycocatype.h:44
KSycocaFactory::factoryId
virtual KSycocaFactoryId factoryId() const =0
QHash
Definition: ksycocafactory.h:28
QList
Definition: kaboutdata.h:33
QString
F
#define F
ksycocaentry.h
KSycocaEntryDict
QHash< QString, KSycocaEntry::Ptr > KSycocaEntryDict
Definition: ksycocafactory.h:30
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