\section{KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, QObject $>$ Class Template Reference}
\label{classKGenericFactory_3_01KTypeList_3_01Product_00_01ProductListTail_01_4_00_01QObject_01_4}\index{KGenericFactory< KTypeList< Product, ProductListTail >, QObject >@{KGenericFactory$<$ KTypeList$<$ Product, ProductListTail $>$, QObject $>$}}
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 $>$, QObject $>$:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=196pt]{classKGenericFactory_3_01KTypeList_3_01Product_00_01ProductListTail_01_4_00_01QObject_01_4__inherit__graph}
\end{center}
\end{figure}
Collaboration diagram for KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, QObject $>$:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=196pt]{classKGenericFactory_3_01KTypeList_3_01Product_00_01ProductListTail_01_4_00_01QObject_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_01QObject_01_4_a0}

\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)
\begin{CompactList}\small\item\em Creates a new object. \item\end{CompactList}\end{CompactItemize}


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

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: \small\begin{alltt}
     {\bf KInstance}{\rm (p.\,\pageref{classKInstance})} *MyFactory::createInstance()
     \{
         return new KInstance( myAboutData );
     \}
 \end{alltt}\normalsize 


Example of usage of the whole template: \small\begin{alltt}
     class MyPlugin : public {\bf KParts::Plugin}
     \{
         Q\_ OBJECT
     public:
         MyPlugin( {\bf QObject} *parent, const char *name,
                   const {\bf QStringList} \&args );
         ...
     \};\end{alltt}\normalsize 


\small\begin{alltt}     class MyDialogComponent : public {\bf KDialogBase}
     \{
         Q\_ OBJECT
     public:
         MyDialogComponent( {\bf QWidget} *parentWidget, const char *name,
                            const {\bf QStringList} \&args );
         ...
     \};\end{alltt}\normalsize 


\small\begin{alltt}     typedef K\_TYPELIST\_2( MyPlugin, MyDialogComponent ) Products;
     K\_EXPORT\_COMPONENT\_FACTORY( libmyplugin, {\bf KGenericFactory}{\rm (p.\,\pageref{classKGenericFactory})}$<$Products$>$ );
 \end{alltt}\normalsize 
 



Definition at line 243 of file kgenericfactory.h.

\subsection{Member Function Documentation}
\index{KGenericFactory< KTypeList< Product, ProductListTail >, QObject >@{KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, QObject $>$}!createObject@{createObject}}
\index{createObject@{createObject}!KGenericFactory< KTypeList< Product, ProductListTail >, QObject >@{KGeneric\-Factory$<$ KType\-List$<$ Product, Product\-List\-Tail $>$, QObject $>$}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class Product, class Product\-List\-Tail$>$ virtual {\bf QObject}$\ast$ {\bf KGeneric\-Factory}$<$ {\bf KType\-List}$<$ Product, Product\-List\-Tail $>$, {\bf QObject} $>$::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_01QObject_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 classname}. 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 classname}]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 253 of file kgenericfactory.h.

References KStd\-Action::name().

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