• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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 /* @internal */
00033 template <class T>
00034 class KGenericFactoryBase : public KPluginFactory
00035 {
00036 public:
00037     explicit KGenericFactoryBase(const char *componentName, const char *catalogName)
00038         : KPluginFactory(componentName, catalogName)
00039     {
00040         s_self = this;
00041         s_createComponentDataCalled = false;
00042     }
00043 
00044     explicit KGenericFactoryBase( const KAboutData *data )
00045         : KPluginFactory(data)
00046     {
00047         s_self = this;
00048         s_createComponentDataCalled = false;
00049     }
00050 
00051     virtual ~KGenericFactoryBase()
00052     {
00053         s_self = 0;
00054     }
00055 
00056     static KComponentData componentData()
00057     {
00058         Q_ASSERT(s_self);
00059         if (!s_createComponentDataCalled) {
00060             s_createComponentDataCalled = true;
00061 
00062             KComponentData *kcd = s_self->createComponentData();
00063             Q_ASSERT(kcd);
00064             s_self->setComponentData(*kcd);
00065             delete kcd;
00066         }
00067         return static_cast<KPluginFactory *>(s_self)->componentData();
00068     }
00069 
00070 protected:
00071     virtual KComponentData *createComponentData()
00072     {
00073         return new KComponentData(componentData());
00074     }
00075 
00076 private:
00077     static bool s_createComponentDataCalled;
00078     static KGenericFactoryBase<T> *s_self;
00079 };
00080 
00081 /* @internal */
00082 template <class T>
00083 KGenericFactoryBase<T> *KGenericFactoryBase<T>::s_self = 0;
00084 
00085 /* @internal */
00086 template <class T>
00087 bool KGenericFactoryBase<T>::s_createComponentDataCalled = false;
00088 
00147 template <class Product, class ParentType = QObject>
00148 class KDE_DEPRECATED KGenericFactory : public KGenericFactoryBase<Product>
00149 {
00150 public:
00151     explicit KGenericFactory( const char *componentName = 0, const char *catalogName = 0 )
00152         : KGenericFactoryBase<Product>(componentName, catalogName)
00153     {}
00154 
00155     explicit KGenericFactory( const KAboutData *data )
00156         : KGenericFactoryBase<Product>(data)
00157     {}
00158 
00159 protected:
00160     virtual QObject *createObject( QObject *parent,
00161                                    const char *className, const QStringList &args )
00162     {
00163         return KDEPrivate::ConcreteFactory<Product, ParentType>
00164             ::create( 0, parent, className, args );
00165     }
00166 };
00167 
00237 template <class Product, class ProductListTail>
00238 class KGenericFactory< KTypeList<Product, ProductListTail>, QObject >
00239     : public KGenericFactoryBase<KTypeList<Product, ProductListTail> >
00240 {
00241 public:
00242     explicit KGenericFactory( const char *componentName  = 0, const char *catalogName  = 0 )
00243         : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(componentName, catalogName)
00244     {}
00245 
00246     explicit KGenericFactory( const KAboutData *data )
00247         : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(data)
00248     {}
00249 
00250 
00251 protected:
00252     virtual QObject *createObject( QObject *parent,
00253                                    const char *className, const QStringList &args )
00254     {
00255         return KDEPrivate::MultiFactory< KTypeList< Product, ProductListTail > >
00256             ::create( 0, parent, className, args );
00257     }
00258 };
00259 
00329 template <class Product, class ProductListTail,
00330           class ParentType, class ParentTypeListTail>
00331 class KGenericFactory< KTypeList<Product, ProductListTail>,
00332                        KTypeList<ParentType, ParentTypeListTail> >
00333     : public KGenericFactoryBase<KTypeList<Product, ProductListTail> >
00334 {
00335 public:
00336     explicit KGenericFactory( const char *componentName  = 0, const char *catalogName  = 0 )
00337         : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(componentName, catalogName)
00338     {}
00339     explicit KGenericFactory( const KAboutData *data )
00340         : KGenericFactoryBase<KTypeList<Product, ProductListTail> >(data)
00341     {}
00342 
00343 
00344 protected:
00345     virtual QObject *createObject( QObject *parent,
00346                                    const char *className, const QStringList &args )
00347     {
00348         return KDEPrivate::MultiFactory< KTypeList< Product, ProductListTail >,
00349                                          KTypeList< ParentType, ParentTypeListTail > >
00350                                        ::create( 0, 0, parent,
00351                                                  className, args );
00352     }
00353 };
00354 
00355 /*
00356  * vim: et sw=4
00357  */
00358 
00359 #endif
00360 
00361 

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal