1
/* This file is part of the KDE libraries
2
* Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
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;
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.
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.
19
#ifndef KSYCOCAFACTORY_H
20
#define KSYCOCAFACTORY_H
22
#include <ksycocaentry.h>
27
class KSycocaResourceList;
28
template <typename T> class QList;
29
template <typename KT, typename VT> class QHash;
31
typedef QHash<QString, KSycocaEntry::Ptr> KSycocaEntryDict;
35
* Base class for sycoca factories
37
class KDECORE_EXPORT KSycocaFactory
40
virtual KSycocaFactoryId factoryId() const = 0;
42
protected: // virtual class
44
* Create a factory which can be used to lookup from/create a database
45
* (depending on KSycoca::isBuilding())
47
explicit KSycocaFactory( KSycocaFactoryId factory_id );
50
virtual ~KSycocaFactory();
53
* @return the position of the factory in the sycoca file
58
* @return the dict, for special use by KBuildSycoca
60
KSycocaEntryDict * entryDict() { return m_entryDict; }
63
* Construct an entry from a config file.
64
* To be implemented in the real factories.
66
virtual KSycocaEntry *createEntry(const QString &file, const char *resource) const = 0;
71
virtual void addEntry(const KSycocaEntry::Ptr& newEntry);
74
* Remove all entries with the given name.
75
* Not very fast (O(N)), use with care.
77
void removeEntry(const QString& entryName);
80
* Read an entry from the database
82
virtual KSycocaEntry *createEntry(int offset) const = 0;
85
* Get a list of all entries from the database.
87
virtual KSycocaEntry::List allEntries() const;
90
* Saves all entries it maintains as well as index files
91
* for these entries to the stream 'str'.
93
* Also sets mOffset to the starting position.
95
* The stream is positioned at the end of the last index.
97
* Don't forget to call the parent first when you override
100
virtual void save(QDataStream &str);
103
* Writes out a header to the stream 'str'.
104
* The baseclass positions the stream correctly.
106
* Don't forget to call the parent first when you override
109
virtual void saveHeader(QDataStream &str);
112
* @return the resources for which this factory is responsible.
113
* @internal to kbuildsycoca
115
const KSycocaResourceList * resourceList() const;
118
* @return the sycoca dict, for factories to find entries by name.
120
const KSycocaDict *sycocaDict() const;
123
* @return true if the factory is completely empty - no entries defined
125
bool isEmpty() const;
130
KSycocaResourceList *m_resourceList;
131
KSycocaEntryDict *m_entryDict;
138
/** Virtual hook, used to add new "virtual" functions while maintaining
139
binary compatibility. Unused in this class.
141
virtual void virtual_hook( int id, void* data );
144
/** This, instead of a typedef, allows to declare "class ..." in header files
147
class KDECORE_EXPORT KSycocaFactoryList : public QList<KSycocaFactory*> //krazy:exclude=dpointer (acts as a typedef)
150
KSycocaFactoryList() { }