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

KDECore

  • sources
  • kde-4.12
  • kdelibs
  • 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 */
35 template <class T>
36 class KGenericFactoryBase : public KPluginFactory
37 {
38 public:
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 
72 protected:
73  virtual KComponentData *createComponentData()
74  {
75  return new KComponentData(componentData());
76  }
77 
78 private:
79  static bool s_createComponentDataCalled;
80  static KGenericFactoryBase<T> *s_self;
81 };
82 
83 /* @internal */
84 template <class T>
85 KGenericFactoryBase<T> *KGenericFactoryBase<T>::s_self = 0;
86 
87 /* @internal */
88 template <class T>
89 bool KGenericFactoryBase<T>::s_createComponentDataCalled = false;
90 
151 template <class Product, class ParentType = QObject>
152 class KDE_DEPRECATED KGenericFactory : public KGenericFactoryBase<Product>
153 {
154 public:
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 
163 protected:
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 
241 template <class Product, class ProductListTail>
242 class KGenericFactory< KTypeList<Product, ProductListTail>, QObject >
243  : public KGenericFactoryBase<KTypeList<Product, ProductListTail> >
244 {
245 public:
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 
255 protected:
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 
333 template <class Product, class ProductListTail,
334  class ParentType, class ParentTypeListTail>
335 class KGenericFactory< KTypeList<Product, ProductListTail>,
336  KTypeList<ParentType, ParentTypeListTail> >
337  : public KGenericFactoryBase<KTypeList<Product, ProductListTail> >
338 {
339 public:
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 
348 protected:
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 
ktypelist.h
This file defines typelist structures as well as convenience macros to create typelists.
kdebug.h
KPluginFactory::create
T * create(QObject *parent=0, const QVariantList &args=QVariantList())
Use this method to create an object.
Definition: kpluginfactory.h:505
KGenericFactory::KGenericFactory
KGenericFactory(const KAboutData *data)
Definition: kgenericfactory.h:159
KGenericFactoryBase::createComponentData
virtual KComponentData * createComponentData()
Definition: kgenericfactory.h:73
KGenericFactoryBase::KGenericFactoryBase
KGenericFactoryBase(const char *componentName, const char *catalogName)
Definition: kgenericfactory.h:39
KGenericFactoryBase::KGenericFactoryBase
KGenericFactoryBase(const KAboutData *data)
Definition: kgenericfactory.h:46
KGenericFactory
This template provides a generic implementation of a KLibFactory , for use with shared library compon...
Definition: kgenericfactory.h:152
QObject
klocale.h
KGenericFactory< KTypeList< Product, ProductListTail >, QObject >::KGenericFactory
KGenericFactory(const char *componentName=0, const char *catalogName=0)
Definition: kgenericfactory.h:246
KGenericFactoryBase
Definition: kgenericfactory.h:36
KGenericFactory::KGenericFactory
KGenericFactory(const char *componentName=0, const char *catalogName=0)
Definition: kgenericfactory.h:155
kglobal.h
KTypeList
The building block of typelists of any length.
Definition: ktypelist.h:453
KGenericFactoryBase::~KGenericFactoryBase
virtual ~KGenericFactoryBase()
Definition: kgenericfactory.h:53
KGenericFactoryBase::componentData
static KComponentData componentData()
Definition: kgenericfactory.h:58
kpluginloader.h
QStringList
KAboutData
This class is used to store information about a program.
Definition: kaboutdata.h:192
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 >::createObject
virtual QObject * createObject(QObject *parent, const char *className, const QStringList &args)
Definition: kgenericfactory.h:256
KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >::KGenericFactory
KGenericFactory(const KAboutData *data)
Definition: kgenericfactory.h:343
kpluginfactory.h
KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >::KGenericFactory
KGenericFactory(const char *componentName=0, const char *catalogName=0)
Definition: kgenericfactory.h:340
klibloader.h
KGenericFactory< KTypeList< Product, ProductListTail >, QObject >::KGenericFactory
KGenericFactory(const KAboutData *data)
Definition: kgenericfactory.h:250
kcomponentdata.h
KPluginFactory
If you develop a library that is to be loaded dynamically at runtime, then you should return a pointe...
Definition: kpluginfactory.h:232
KGenericFactory::createObject
virtual QObject * createObject(QObject *parent, const char *className, const QStringList &args)
Definition: kgenericfactory.h:164
KComponentData
Per component data.
Definition: kcomponentdata.h:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:08 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • 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