• 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
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 
24 class QString;
25 class KSycocaDict;
26 class KSycocaResourceList;
27 template <typename T> class QList;
28 template <typename KT, typename VT> class QHash;
29 
30 typedef QHash<QString, KSycocaEntry::Ptr> KSycocaEntryDict;
31 
36 class KDECORE_EXPORT KSycocaFactory
37 {
38 public:
39  virtual KSycocaFactoryId factoryId() const = 0;
40 
41 protected: // virtual class
46  explicit KSycocaFactory( KSycocaFactoryId factory_id );
47 
48 public:
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 
126 protected:
127  QDataStream* stream() const;
128 
129  KSycocaResourceList *m_resourceList;
130  KSycocaEntryDict *m_entryDict;
131 
132 private:
133  QDataStream *m_str;
134  class Private;
135  Private* const d;
136 
137 protected:
141  virtual void virtual_hook( int id, void* data );
142 };
143 
148 class KDECORE_EXPORT KSycocaFactoryList : public QList<KSycocaFactory*> //krazy:exclude=dpointer (acts as a typedef)
149 {
150 public:
151  KSycocaFactoryList() { }
152 };
153 
154 #include <QThreadStorage>
159 template <typename F> class KSycocaFactoryContainer
160 {
161 public:
162  KSycocaFactoryContainer(F* factory) : m_factory(factory) {}
163  F* factory() { return m_factory; }
164 private:
165  F* m_factory;
166 };
167 
176 template <typename F> class KSycocaFactorySingleton
177 {
178 public:
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  }
205 private:
206  QThreadStorage<C*> m_factories;
207 };
208 
209 #endif
KSycocaDict
Definition: ksycocadict_p.h:36
KSycocaFactoryList
This, instead of a typedef, allows to declare "class ..." in header files.
Definition: ksycocafactory.h:148
KSharedPtr
Can be used to control the lifetime of an object that has derived QSharedData.
Definition: kconfiggroup.h:38
KSycocaFactory::m_entryDict
KSycocaEntryDict * m_entryDict
Definition: ksycocafactory.h:130
KSycocaFactorySingleton::instanceDestroyed
void instanceDestroyed(F *factory)
Definition: ksycocafactory.h:192
QDataStream
KSycocaFactory::m_resourceList
KSycocaResourceList * m_resourceList
Definition: ksycocafactory.h:129
KSycocaFactory
Definition: ksycocafactory.h:36
KSycocaFactorySingleton::KSycocaFactorySingleton
KSycocaFactorySingleton()
Definition: ksycocafactory.h:180
KSycocaEntryDict
QHash< QString, KSycocaEntry::Ptr > KSycocaEntryDict
Definition: ksycocafactory.h:28
KSycocaFactoryContainer
Workaround for the lack of QThreadStorage::setAutoDelete(false).
Definition: ksycocafactory.h:159
KSycocaFactorySingleton::C
KSycocaFactoryContainer< F > C
Definition: ksycocafactory.h:179
F
#define F
KSycocaFactoryContainer::KSycocaFactoryContainer
KSycocaFactoryContainer(F *factory)
Definition: ksycocafactory.h:162
QHash
Definition: ksycocafactory.h:28
KSycocaEntry
Base class for all Sycoca entries.
Definition: ksycocaentry.h:41
KSycocaFactory::KSycocaFactoryId
KSycocaFactoryId
Definition: ksycocatype.h:44
KSycocaFactorySingleton::~KSycocaFactorySingleton
~KSycocaFactorySingleton()
Definition: ksycocafactory.h:182
QString
QList
Definition: kaboutdata.h:33
ksycocaentry.h
QThreadStorage
KSycocaFactory::entryDict
KSycocaEntryDict * entryDict()
Definition: ksycocafactory.h:59
KSycocaFactorySingleton::instanceCreated
void instanceCreated(F *newFactory)
Definition: ksycocafactory.h:186
KSycocaFactoryContainer::factory
F * factory()
Definition: ksycocafactory.h:163
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:176
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