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

KDECore

kgenericfactory.h
Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  * Copyright (C) 2001 Simon Hausmann <hausmann@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 as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this library; see the file COPYING.LIB.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 #ifndef kgenericfactory_h
00020 #define kgenericfactory_h
00021 
00022 #include <klibloader.h>
00023 #include <kpluginfactory.h>
00024 #include <kpluginloader.h>
00025 #include <ktypelist.h>
00026 #include <kcomponentdata.h>
00027 #include <kgenericfactory.tcc>
00028 #include <kglobal.h>
00029 #include <klocale.h>
00030 #include <kdebug.h>
00031 
00032 #ifndef KDE_NO_DEPRECATED
00033 
00034 /* @internal */
00035 template <class T>
00036 class KGenericFactoryBase : public KPluginFactory
00037 {
00038 public:
00039     explicit KGenericFactoryBase(const char *componentName, const char *catalogName)
00040         : KPluginFactory(componentName, catalogName)
00041     {
00042         s_self = this;
00043         s_createComponentDataCalled = false;
00044     }
00045 
00046     explicit KGenericFactoryBase( const KAboutData *data )
00047         : KPluginFactory(data)
00048     {
00049         s_self = this;
00050         s_createComponentDataCalled = false;
00051     }
00052 
00053     virtual ~KGenericFactoryBase()
00054     {
00055         s_self = 0;
00056     }
00057 
00058     static KComponentData componentData()
00059     {
00060         Q_ASSERT(s_self);
00061         if (!s_createComponentDataCalled) {
00062             s_createComponentDataCalled = true;
00063 
00064             KComponentData *kcd = s_self->createComponentData();
00065             Q_ASSERT(kcd);
00066             s_self->setComponentData(*kcd);
00067             delete kcd;
00068         }
00069         return static_cast<KPluginFactory *>(s_self)->componentData();
00070     }
00071 
00072 protected:
00073     virtual KComponentData *createComponentData()
00074     {
00075         return new KComponentData(componentData());
00076     }
00077 
00078 private:
00079     static bool s_createComponentDataCalled;
00080     static KGenericFactoryBase<T> *s_self;
00081 };
00082 
00083 /* @internal */
00084 template <class T>
00085 KGenericFactoryBase<T> *KGenericFactoryBase<T>::s_self = 0;
00086 
00087 /* @internal */
00088 template <class T>
00089 bool KGenericFactoryBase<T>::s_createComponentDataCalled = false;
00090 
00151 template <class Product, class ParentType = QObject>
00152 class KDE_DEPRECATED KGenericFactory : public KGenericFactoryBase<Product>
00153 {
00154 public:
00155     explicit KGenericFactory( const char *componentName = 0, const char *catalogName = 0 )
00156         : KGenericFactoryBase<Product>(componentName, catalogName)
00157     {}
00158 
00159     explicit KGenericFactory( const KAboutData *data )
00160         : KGenericFactoryBase<Product>(data)
00161     {}
00162 
00163 protected:
00164     virtual QObject *createObject( QObject *parent,
00165                                    const char *className, const QStringList &args )
00166     {
00167         return KDEPrivate::ConcreteFactory<Product, ParentType>
00168             ::create( 0, parent, className, args );
00169     }
00170 };
00171 
00241 template <class Product, class ProductListTail>
00242 class KGenericFactory< KTypeList<Product, ProductListTail>, QObject >
00243     : public KGenericFactoryBase<KTypeList<Product, ProductListTail> >
00244 {
00245 public:
00246     explicit KGenericFactory( const char *componentName  = 0, const char *catalogName  = 0 )
00247         : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(componentName, catalogName)
00248     {}
00249 
00250     explicit KGenericFactory( const KAboutData *data )
00251         : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(data)
00252     {}
00253 
00254 
00255 protected:
00256     virtual QObject *createObject( QObject *parent,
00257                                    const char *className, const QStringList &args )
00258     {
00259         return KDEPrivate::MultiFactory< KTypeList< Product, ProductListTail > >
00260             ::create( 0, parent, className, args );
00261     }
00262 };
00263 
00333 template <class Product, class ProductListTail,
00334           class ParentType, class ParentTypeListTail>
00335 class KGenericFactory< KTypeList<Product, ProductListTail>,
00336                        KTypeList<ParentType, ParentTypeListTail> >
00337     : public KGenericFactoryBase<KTypeList<Product, ProductListTail> >
00338 {
00339 public:
00340     explicit KGenericFactory( const char *componentName  = 0, const char *catalogName  = 0 )
00341         : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(componentName, catalogName)
00342     {}
00343     explicit KGenericFactory( const KAboutData *data )
00344         : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(data)
00345     {}
00346 
00347 
00348 protected:
00349     virtual QObject *createObject( QObject *parent,
00350                                    const char *className, const QStringList &args )
00351     {
00352         return KDEPrivate::MultiFactory< KTypeList< Product, ProductListTail >,
00353                                          KTypeList< ParentType, ParentTypeListTail > >
00354                                        ::create( 0, 0, parent,
00355                                                  className, args );
00356     }
00357 };
00358 
00359 #endif
00360 #endif
00361 
00362 
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:49:31 by doxygen 1.8.0 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-4.8.3 API Reference

Skip menu "kdelibs-4.8.3 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