| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > > Class Template Reference

This template provides a generic implementation of a KLibFactory , for use with shared library components. More...

`#include <kgenericfactory.h>`

Inheritance diagram for KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >:

[legend]
Collaboration diagram for KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >:

[legend]
List of all members.

## Public Member Functions
| KGenericFactory (const char *instanceName=0)
| KGenericFactory (const KAboutData *data)
## Protected Member Functions
virtual QObject * | createObject (QObject *parent, const char *name, const char *className, const QStringList &args)

## Detailed Description

### template<class Product, class ProductListTail, class ParentType, class ParentTypeListTail>
class KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >

This template provides a generic implementation of a KLibFactory , for use with shared library components.

It implements the pure virtual createObject method of KLibFactory and instantiates objects of the specified classes in the given typelist template argument when the class name argument of createObject matches a class names in the given hierarchy of classes.

Note that each class in the specified in the typelist template argument needs to provide a certain constructor:

- If the class is derived from QObject then it needs to have a constructor like: `MyClass( QObject *parent, const char *name, const QStringList &args );`
- If the class is derived from QWidget then it needs to have a constructor like: `MyWidget( QWidget *parent, const char *name, const QStringList &args);`
- If the class is derived from KParts::Part then it needs to have a constructor like: `MyPart( QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, const QStringList &args );`

The args QStringList passed to the constructor is the args string list that the caller passed to KLibFactory's create method.

In addition upon instantiation this template provides a central KInstance object for your component, accessible through the static instance() method. The instanceName argument of the KGenericFactory constructor is passed to the KInstance object.

The creation of the KInstance object can be customized by inheriting from this template class and re-implementing the virtual createInstance method. For example it could look like this:

         KInstance *MyFactory::createInstance()
         {
             return new KInstance( myAboutData );
         }

Example of usage of the whole template:

         class MyPlugin : public KParts::Plugin
         {
             Q_ OBJECT
         public:
             MyPlugin( QObject *parent, const char *name,
                       const QStringList &args );
             ...
         };

         class MyDialogComponent : public KDialogBase
         {
             Q_ OBJECT
         public:
             MyDialogComponent( QWidget *parentWidget, const char *name,
                                const QStringList &args );
             ...
         };

         typedef K_TYPELIST_2( MyPlugin, MyDialogComponent ) Products;
         K_EXPORT_COMPONENT_FACTORY( libmyplugin, KGenericFactory&lt;Products&gt; )

Definition at line 362 of file kgenericfactory.h.

## Member Function Documentation

template<class Product, class ProductListTail, class ParentType, class ParentTypeListTail>
KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >::KGenericFactory | ( | const KAboutData * | data | ) | `[inline]`

| Since: 3.3 Definition at line 374 of file kgenericfactory.h.

template<class Product, class ProductListTail, class ParentType, class ParentTypeListTail>
virtual QObject* KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >::createObject | ( | QObject * | parent,
|  | const char * | name,
|  | const char * | className,
|  | const QStringList & | args
| ) | `[inline, protected, virtual]`

  | Creates a new object. The returned object has to be derived from the requested classname. It is valid behavior to create different kinds of objects depending on the requested `className`. For example a koffice library may usually return a pointer to KoDocument. But if asked for a "QWidget", it could create a wrapper widget, that encapsulates the Koffice specific features. This function is called by create() Parameters:
  | parent | the parent of the QObject, 0 for no parent
  | name | the name of the QObject, 0 for no name
  | className | the name of the class
  | args | a list of arguments
Implements KLibFactory. Definition at line 380 of file kgenericfactory.h.

The documentation for this class was generated from the following file:

- kgenericfactory.h

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:37 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003