KDELibs4Support

kgenericfactory.h
1 /* This file is part of the KDE project
2  * Copyright (C) 2001 Simon Hausmann <[email protected]>
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 <klocalizedstring.h>
29 #include <kdebug.h>
30 
31 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
32 
33 /* @internal */
34 template <class T>
35 class KGenericFactoryBase : public KPluginFactory
36 {
37 public:
38  KDELIBS4SUPPORT_DEPRECATED explicit KGenericFactoryBase(const char *componentName)
39  : KPluginFactory()
40  {
41  s_self = this;
42  s_createComponentDataCalled = false;
43  }
44 
45  KDELIBS4SUPPORT_DEPRECATED explicit KGenericFactoryBase(const KAboutData *data)
46  : KPluginFactory()
47  {
49  s_self = this;
50  s_createComponentDataCalled = false;
51  }
52 
53  virtual ~KGenericFactoryBase()
54  {
55  s_self = 0;
56  }
57 
58 #if 0 // not available anymore. Port away from KGenericFactory!
59  static KComponentData componentData()
60  {
61  Q_ASSERT(s_self);
62  if (!s_createComponentDataCalled) {
63  s_createComponentDataCalled = true;
64 
65  KComponentData *kcd = s_self->createComponentData();
66  Q_ASSERT(kcd);
67  s_self->setComponentData(*kcd);
68  delete kcd;
69  }
70  return static_cast<KPluginFactory *>(s_self)->componentData();
71  }
72 
73 protected:
74  virtual KComponentData *createComponentData()
75  {
76  return new KComponentData(componentData());
77  }
78 #endif
79 private:
80  static bool s_createComponentDataCalled;
81  static KGenericFactoryBase<T> *s_self;
82 };
83 
84 /* @internal */
85 template <class T>
86 KGenericFactoryBase<T> *KGenericFactoryBase<T>::s_self = 0;
87 
88 /* @internal */
89 template <class T>
90 bool KGenericFactoryBase<T>::s_createComponentDataCalled = false;
91 
152 template <class Product, class ParentType = QObject>
153 class KDELIBS4SUPPORT_DEPRECATED KGenericFactory : public KGenericFactoryBase<Product>
154 {
155 public:
156  KDELIBS4SUPPORT_DEPRECATED explicit KGenericFactory(const char *componentName = nullptr)
157  : KGenericFactoryBase<Product>(componentName)
158  {}
159 
160  KDELIBS4SUPPORT_DEPRECATED explicit KGenericFactory(const KAboutData *data)
161  : KGenericFactoryBase<Product>(data)
162  {}
163 
164 protected:
165  virtual QObject *createObject(QObject *parent,
166  const char *className, const QStringList &args)
167  {
168  return KDEPrivate::ConcreteFactory<Product, ParentType>
169  ::create(0, parent, className, args);
170  }
171 };
172 
242 template <class Product, class ProductListTail>
243 class KGenericFactory< KTypeList<Product, ProductListTail>, QObject >
244  : public KGenericFactoryBase<KTypeList<Product, ProductListTail> >
245 {
246 public:
247  KDELIBS4SUPPORT_DEPRECATED explicit KGenericFactory(const char *componentName = nullptr)
248  : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(componentName)
249  {}
250 
251  KDELIBS4SUPPORT_DEPRECATED explicit KGenericFactory(const KAboutData *data)
252  : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(data)
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  KDELIBS4SUPPORT_DEPRECATED explicit KGenericFactory(const char *componentName = nullptr)
341  : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(componentName)
342  {}
343  KDELIBS4SUPPORT_DEPRECATED explicit KGenericFactory(const KAboutData *data)
344  : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(data)
345  {}
346 
347 protected:
348  virtual QObject *createObject(QObject *parent,
349  const char *className, const QStringList &args)
350  {
351  return KDEPrivate::MultiFactory< KTypeList< Product, ProductListTail >,
353  ::create(0, 0, parent,
354  className, args);
355  }
356 };
357 
358 #endif
359 #endif
360 
This file defines typelist structures as well as convenience macros to create typelists.
This template provides a generic implementation of a KLibFactory , for use with shared library compon...
static void registerPluginData(const KAboutData &aboutData)
The building block of typelists of any length.
Definition: ktypelist.h:453
Per component data.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 14 2020 22:58:20 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.