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

KDECore

ksycocafactory.h

Go to the documentation of this file.
00001 /*  This file is part of the KDE libraries
00002  *  Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
00003  *
00004  *  This library is free software; you can redistribute it and/or
00005  *  modify it under the terms of the GNU Library General Public
00006  *  License version 2 as published by the Free Software Foundation;
00007  *
00008  *  This library is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  *  Library General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU Library General Public License
00014  *  along with this library; see the file COPYING.LIB.  If not, write to
00015  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016  *  Boston, MA 02110-1301, USA.
00017  **/
00018 
00019 #ifndef KSYCOCAFACTORY_H
00020 #define KSYCOCAFACTORY_H
00021 
00022 #include <ksycocaentry.h>
00023 
00024 class QString;
00025 class KSycocaDict;
00026 class KSycocaResourceList;
00027 template <typename T> class QList;
00028 template <typename KT, typename VT> class QHash;
00029 
00030 typedef QHash<QString, KSycocaEntry::Ptr> KSycocaEntryDict;
00031 
00036 class KDECORE_EXPORT KSycocaFactory
00037 {
00038 public:
00039     virtual KSycocaFactoryId factoryId() const = 0;
00040 
00041 protected: // virtual class
00046     explicit KSycocaFactory( KSycocaFactoryId factory_id );
00047 
00048 public:
00049     virtual ~KSycocaFactory();
00050 
00054     int offset() const;
00055 
00059     KSycocaEntryDict * entryDict() { return m_entryDict; }
00060 
00065     virtual KSycocaEntry *createEntry(const QString &file, const char *resource) const = 0;
00066 
00070     virtual void addEntry(const KSycocaEntry::Ptr& newEntry);
00071 
00076     void removeEntry(const QString& entryName);
00077 
00081     virtual KSycocaEntry *createEntry(int offset) const = 0;
00082 
00086     virtual KSycocaEntry::List allEntries() const;
00087 
00099     virtual void save(QDataStream &str);
00100 
00108     virtual void saveHeader(QDataStream &str);
00109 
00114     const KSycocaResourceList * resourceList() const;
00115 
00119     const KSycocaDict *sycocaDict() const;
00120 
00124     bool isEmpty() const;
00125 
00126 protected:
00127     QDataStream* stream() const;
00128 
00129     KSycocaResourceList *m_resourceList;
00130     KSycocaEntryDict *m_entryDict;
00131 
00132 private:
00133     QDataStream *m_str;
00134     class Private;
00135     Private* const d;
00136 
00137 protected:
00141     virtual void virtual_hook( int id, void* data );
00142 };
00143 
00148 class KDECORE_EXPORT KSycocaFactoryList : public QList<KSycocaFactory*> //krazy:exclude=dpointer (acts as a typedef)
00149 {
00150 public:
00151     KSycocaFactoryList() { }
00152 };
00153 
00154 #include <QThreadStorage>
00159 template <typename F> class KSycocaFactoryContainer
00160 {
00161 public:
00162     KSycocaFactoryContainer(F* factory) : m_factory(factory) {}
00163     F* factory() { return m_factory; }
00164 private:
00165     F* m_factory;
00166 };
00167 
00176 template <typename F> class KSycocaFactorySingleton
00177 {
00178 public:
00179     typedef KSycocaFactoryContainer<F> C;
00180     KSycocaFactorySingleton() {
00181     }
00182     ~KSycocaFactorySingleton() {
00183         // Do not delete the factory here.
00184         // All factories are owned by KSycoca, and deleted by it.
00185     }
00186     void instanceCreated(F* newFactory) {
00187         // This can also register a subclass created by kbuildsycoca
00188         Q_ASSERT(!m_factories.hasLocalData());
00189         Q_ASSERT(newFactory);
00190         m_factories.setLocalData(new C(newFactory));
00191     }
00192     void instanceDestroyed(F* factory) {
00193         if (m_factories.hasLocalData()) { // could be false on thread exit
00194             Q_ASSERT(m_factories.localData()->factory() == factory);
00195             m_factories.setLocalData(0);
00196         }
00197     }
00198     F* self() {
00199         if (!m_factories.hasLocalData()) {
00200             new F; // calls instanceCreated, which calls setLocalData
00201             Q_ASSERT(m_factories.hasLocalData());
00202         }
00203         return m_factories.localData()->factory();
00204     }
00205 private:
00206     QThreadStorage<C*> m_factories;
00207 };
00208 
00209 #endif

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal