\section{KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, KType\-List$<$ Parent\-Type, Parent\-Type\-List\-Tail $>$ $>$ Class Template Reference}
\label{classKGenericFactory_3_01KTypeList_3_01Product_00_01ProductListTail_01_4_00_01KTypeList_3_01ParentType_00_01ParentTypeListTail_01_4_01_4}\index{KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >@{KGenericFactory$<$ KTypeList$<$ Product, ProductListTail $>$, KTypeList$<$ ParentType, ParentTypeListTail $>$ $>$}}
This template provides a generic implementation of a {\bf KLib\-Factory}{\rm (p.\,\pageref{classKLibFactory})} , for use with shared library components.  


{\tt \#include $<$kgenericfactory.h$>$}

Inheritance diagram for KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, KType\-List$<$ Parent\-Type, Parent\-Type\-List\-Tail $>$ $>$:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=260pt]{classKGenericFactory_3_01KTypeList_3_01Product_00_01ProductListTail_01_4_00_01KTypeList_3_01ParentType_00_01ParentTypeListTail_01_4_01_4__inherit__graph}
\end{center}
\end{figure}
Collaboration diagram for KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, KType\-List$<$ Parent\-Type, Parent\-Type\-List\-Tail $>$ $>$:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=260pt]{classKGenericFactory_3_01KTypeList_3_01Product_00_01ProductListTail_01_4_00_01KTypeList_3_01ParentType_00_01ParentTypeListTail_01_4_01_4__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KGeneric\-Factory} (const char $\ast$instance\-Name=0)\label{classKGenericFactory_3_01KTypeList_3_01Product_00_01ProductListTail_01_4_00_01KTypeList_3_01ParentType_00_01ParentTypeListTail_01_4_01_4_a0}

\item 
{\bf KGeneric\-Factory} (const {\bf KAbout\-Data} $\ast$data)
\end{CompactItemize}
\subsection*{Protected Member Functions}
\begin{CompactItemize}
\item 
virtual {\bf QObject} $\ast$ {\bf create\-Object} ({\bf QObject} $\ast${\bf parent}, const char $\ast${\bf name}, const char $\ast${\bf class\-Name}, const {\bf QString\-List} \&args)
\end{CompactItemize}


\subsection{Detailed Description}
\subsubsection*{template$<$class Product, class Product\-List\-Tail, class Parent\-Type, class Parent\-Type\-List\-Tail$>$ class KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, KType\-List$<$ Parent\-Type, Parent\-Type\-List\-Tail $>$ $>$}

This template provides a generic implementation of a {\bf KLib\-Factory}{\rm (p.\,\pageref{classKLibFactory})} , for use with shared library components. 

It implements the pure virtual create\-Object method of {\bf KLib\-Factory}{\rm (p.\,\pageref{classKLibFactory})} and instantiates objects of the specified classes in the given typelist template argument when the class name argument of create\-Object 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: \begin{itemize}
\item If the class is derived from {\bf QObject} then it needs to have a constructor like: {\tt My\-Class( {\bf QObject} $\ast$parent, const char $\ast$name, const {\bf QString\-List} \&args );} \item If the class is derived from {\bf QWidget} then it needs to have a constructor like: {\tt My\-Widget( {\bf QWidget} $\ast$parent, const char $\ast$name, const {\bf QString\-List} \&args);} \item If the class is derived from {\bf KParts::Part} then it needs to have a constructor like: {\tt My\-Part( {\bf QWidget} $\ast$parent\-Widget, const char $\ast$widget\-Name, {\bf QObject} $\ast$parent, const char $\ast$name, const {\bf QString\-List} \&args );} \end{itemize}
The args {\bf QString\-List} passed to the constructor is the args string list that the caller passed to KLib\-Factory's create method.

In addition upon instantiation this template provides a central {\bf KInstance}{\rm (p.\,\pageref{classKInstance})} object for your component, accessible through the static instance() method. The instance\-Name argument of the {\bf KGeneric\-Factory}{\rm (p.\,\pageref{classKGenericFactory})} constructor is passed to the {\bf KInstance}{\rm (p.\,\pageref{classKInstance})} object.

The creation of the {\bf KInstance}{\rm (p.\,\pageref{classKInstance})} object can be customized by inheriting from this template class and re-implementing the virtual create\-Instance method. For example it could look like this: 

\footnotesize\begin{verbatim}     KInstance *MyFactory::createInstance()
     {
         return new KInstance( myAboutData );
     }
\end{verbatim}
\normalsize


Example of usage of the whole template: 

\footnotesize\begin{verbatim}     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; )
\end{verbatim}
\normalsize
 



Definition at line 362 of file kgenericfactory.h.

\subsection{Member Function Documentation}
\index{KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >@{KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, KType\-List$<$ Parent\-Type, Parent\-Type\-List\-Tail $>$ $>$}!KGenericFactory@{KGenericFactory}}
\index{KGenericFactory@{KGenericFactory}!KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >@{KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, KType\-List$<$ Parent\-Type, Parent\-Type\-List\-Tail $>$ $>$}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class Product, class Product\-List\-Tail, class Parent\-Type, class Parent\-Type\-List\-Tail$>$ {\bf KGeneric\-Factory}$<$ {\bf KType\-List}$<$ Product, Product\-List\-Tail $>$, {\bf KType\-List}$<$ Parent\-Type, Parent\-Type\-List\-Tail $>$ $>$::{\bf KGeneric\-Factory} (const {\bf KAbout\-Data} $\ast$ {\em data})\hspace{0.3cm}{\tt  [inline]}}\label{classKGenericFactory_3_01KTypeList_3_01Product_00_01ProductListTail_01_4_00_01KTypeList_3_01ParentType_00_01ParentTypeListTail_01_4_01_4_a1}


\begin{Desc}
\item[Since:]3.3 \end{Desc}




Definition at line 374 of file kgenericfactory.h.\index{KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >@{KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, KType\-List$<$ Parent\-Type, Parent\-Type\-List\-Tail $>$ $>$}!createObject@{createObject}}
\index{createObject@{createObject}!KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >@{KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, KType\-List$<$ Parent\-Type, Parent\-Type\-List\-Tail $>$ $>$}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class Product, class Product\-List\-Tail, class Parent\-Type, class Parent\-Type\-List\-Tail$>$ virtual {\bf QObject}$\ast$ {\bf KGeneric\-Factory}$<$ {\bf KType\-List}$<$ Product, Product\-List\-Tail $>$, {\bf KType\-List}$<$ Parent\-Type, Parent\-Type\-List\-Tail $>$ $>$::create\-Object ({\bf QObject} $\ast$ {\em parent}, const char $\ast$ {\em name}, const char $\ast$ {\em class\-Name}, const {\bf QString\-List} \& {\em args})\hspace{0.3cm}{\tt  [inline, protected, virtual]}}\label{classKGenericFactory_3_01KTypeList_3_01Product_00_01ProductListTail_01_4_00_01KTypeList_3_01ParentType_00_01ParentTypeListTail_01_4_01_4_b0}


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 {\tt class\-Name}. For example a koffice library may usually return a pointer to Ko\-Document. But if asked for a \char`\"{}QWidget\char`\"{}, it could create a wrapper widget, that encapsulates the Koffice specific features.

This function is called by {\bf create()}{\rm (p.\,\pageref{classKLibFactory_a2})} \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em parent}]the parent of the {\bf QObject}, 0 for no parent \item[{\em name}]the name of the {\bf QObject}, 0 for no name \item[{\em class\-Name}]the name of the class \item[{\em args}]a list of arguments \end{description}
\end{Desc}


Implements {\bf KLib\-Factory} {\rm (p.\,\pageref{classKLibFactory_b0})}.

Definition at line 380 of file kgenericfactory.h.

The documentation for this class was generated from the following file:\begin{CompactItemize}
\item 
kgenericfactory.h\end{CompactItemize}
