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

KDECore

  • kdecore
  • util
kgenericfactory.h
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * Copyright (C) 2001 Simon Hausmann <hausmann@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 as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19#ifndef kgenericfactory_h
20#define kgenericfactory_h
21
22#include <klibloader.h>
23#include <kpluginfactory.h>
24#include <kpluginloader.h>
25#include <ktypelist.h>
26#include <kcomponentdata.h>
27#include <kgenericfactory.tcc>
28#include <kglobal.h>
29#include <klocale.h>
30#include <kdebug.h>
31
32#ifndef KDE_NO_DEPRECATED
33
34/* @internal */
35template <class T>
36class KGenericFactoryBase : public KPluginFactory
37{
38public:
39 explicit KGenericFactoryBase(const char *componentName, const char *catalogName)
40 : KPluginFactory(componentName, catalogName)
41 {
42 s_self = this;
43 s_createComponentDataCalled = false;
44 }
45
46 explicit KGenericFactoryBase( const KAboutData *data )
47 : KPluginFactory(data)
48 {
49 s_self = this;
50 s_createComponentDataCalled = false;
51 }
52
53 virtual ~KGenericFactoryBase()
54 {
55 s_self = 0;
56 }
57
58 static KComponentData componentData()
59 {
60 Q_ASSERT(s_self);
61 if (!s_createComponentDataCalled) {
62 s_createComponentDataCalled = true;
63
64 KComponentData *kcd = s_self->createComponentData();
65 Q_ASSERT(kcd);
66 s_self->setComponentData(*kcd);
67 delete kcd;
68 }
69 return static_cast<KPluginFactory *>(s_self)->componentData();
70 }
71
72protected:
73 virtual KComponentData *createComponentData()
74 {
75 return new KComponentData(componentData());
76 }
77
78private:
79 static bool s_createComponentDataCalled;
80 static KGenericFactoryBase<T> *s_self;
81};
82
83/* @internal */
84template <class T>
85KGenericFactoryBase<T> *KGenericFactoryBase<T>::s_self = 0;
86
87/* @internal */
88template <class T>
89bool KGenericFactoryBase<T>::s_createComponentDataCalled = false;
90
151template <class Product, class ParentType = QObject>
152class KDE_DEPRECATED KGenericFactory : public KGenericFactoryBase<Product>
153{
154public:
155 explicit KGenericFactory( const char *componentName = 0, const char *catalogName = 0 )
156 : KGenericFactoryBase<Product>(componentName, catalogName)
157 {}
158
159 explicit KGenericFactory( const KAboutData *data )
160 : KGenericFactoryBase<Product>(data)
161 {}
162
163protected:
164 virtual QObject *createObject( QObject *parent,
165 const char *className, const QStringList &args )
166 {
167 return KDEPrivate::ConcreteFactory<Product, ParentType>
168 ::create( 0, parent, className, args );
169 }
170};
171
241template <class Product, class ProductListTail>
242class KGenericFactory< KTypeList<Product, ProductListTail>, QObject >
243 : public KGenericFactoryBase<KTypeList<Product, ProductListTail> >
244{
245public:
246 explicit KGenericFactory( const char *componentName = 0, const char *catalogName = 0 )
247 : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(componentName, catalogName)
248 {}
249
250 explicit KGenericFactory( const KAboutData *data )
251 : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(data)
252 {}
253
254
255protected:
256 virtual QObject *createObject( QObject *parent,
257 const char *className, const QStringList &args )
258 {
259 return KDEPrivate::MultiFactory< KTypeList< Product, ProductListTail > >
260 ::create( 0, parent, className, args );
261 }
262};
263
333template <class Product, class ProductListTail,
334 class ParentType, class ParentTypeListTail>
335class KGenericFactory< KTypeList<Product, ProductListTail>,
336 KTypeList<ParentType, ParentTypeListTail> >
337 : public KGenericFactoryBase<KTypeList<Product, ProductListTail> >
338{
339public:
340 explicit KGenericFactory( const char *componentName = 0, const char *catalogName = 0 )
341 : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(componentName, catalogName)
342 {}
343 explicit KGenericFactory( const KAboutData *data )
344 : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(data)
345 {}
346
347
348protected:
349 virtual QObject *createObject( QObject *parent,
350 const char *className, const QStringList &args )
351 {
352 return KDEPrivate::MultiFactory< KTypeList< Product, ProductListTail >,
353 KTypeList< ParentType, ParentTypeListTail > >
354 ::create( 0, 0, parent,
355 className, args );
356 }
357};
358
359#endif
360#endif
361
362
KAboutData
This class is used to store information about a program.
Definition kaboutdata.h:193
KComponentData
Per component data.
Definition kcomponentdata.h:47
KGenericFactoryBase
Definition kgenericfactory.h:37
KGenericFactoryBase::KGenericFactoryBase
KGenericFactoryBase(const KAboutData *data)
Definition kgenericfactory.h:46
KGenericFactoryBase::~KGenericFactoryBase
virtual ~KGenericFactoryBase()
Definition kgenericfactory.h:53
KGenericFactoryBase::createComponentData
virtual KComponentData * createComponentData()
Definition kgenericfactory.h:73
KGenericFactoryBase::KGenericFactoryBase
KGenericFactoryBase(const char *componentName, const char *catalogName)
Definition kgenericfactory.h:39
KGenericFactoryBase::componentData
static KComponentData componentData()
Definition kgenericfactory.h:58
KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >::KGenericFactory
KGenericFactory(const KAboutData *data)
Definition kgenericfactory.h:343
KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >::KGenericFactory
KGenericFactory(const char *componentName=0, const char *catalogName=0)
Definition kgenericfactory.h:340
KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >::createObject
virtual QObject * createObject(QObject *parent, const char *className, const QStringList &args)
Definition kgenericfactory.h:349
KGenericFactory< KTypeList< Product, ProductListTail >, QObject >::KGenericFactory
KGenericFactory(const char *componentName=0, const char *catalogName=0)
Definition kgenericfactory.h:246
KGenericFactory< KTypeList< Product, ProductListTail >, QObject >::createObject
virtual QObject * createObject(QObject *parent, const char *className, const QStringList &args)
Definition kgenericfactory.h:256
KGenericFactory< KTypeList< Product, ProductListTail >, QObject >::KGenericFactory
KGenericFactory(const KAboutData *data)
Definition kgenericfactory.h:250
KGenericFactory::createObject
virtual QObject * createObject(QObject *parent, const char *className, const QStringList &args)
Definition kgenericfactory.h:164
KGenericFactory::KGenericFactory
KGenericFactory(const char *componentName=0, const char *catalogName=0)
Definition kgenericfactory.h:155
KGenericFactory::KGenericFactory
KGenericFactory(const KAboutData *data)
Definition kgenericfactory.h:159
KPluginFactory::create
T * create(QObject *parent=0, const QVariantList &args=QVariantList())
Use this method to create an object.
Definition kpluginfactory.h:505
KPluginFactory::KPluginFactory
KPluginFactory(const char *componentName=0, const char *catalogName=0, QObject *parent=0)
This constructor creates a factory for a plugin with the given componentName and catalogName.
Definition kpluginfactory.cpp:33
QObject
QStringList
kcomponentdata.h
kdebug.h
s_createComponentDataCalled
bool KGenericFactoryBase< T >::s_createComponentDataCalled
Definition kgenericfactory.h:89
s_self
KGenericFactoryBase< T > * KGenericFactoryBase< T >::s_self
Definition kgenericfactory.h:85
kglobal.h
klibloader.h
klocale.h
kpluginfactory.h
kpluginloader.h
ktypelist.h
This file defines typelist structures as well as convenience macros to create typelists.
KTypeList
The building block of typelists of any length.
Definition ktypelist.h:454
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Tue Mar 25 2025 00:00:00 by doxygen 1.13.2 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
  • 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