Generalized static factory that can deliver instances of T, when a variable is needed in the creation.
More...
template<class T, class P>
class Factory1Param< T, P >
Generalized static factory that can deliver instances of T, when a variable is needed in the creation.
Usage. Each implementation of the base class T must add themselves to the factory when application starts up, e.g. in an initClass() function:
class A
{
public:
virtual int myFunc() = 0;
};
class B : public A
{
public:
static A* createFunc(C* param)
{
A* res = new B;
if ( res->setParam( param ) );
return res;
thefactory.errMsg() = "Could not set param";
delete res;
return 0;
}
static void initClass()
{ thefactory.addCreator(createFunc,"MyKeyword","My Name"); }
int myFunc();
};
Two macros are available to make a static accessfuncion for the factory:
mDefineFactory1Param( Module, ClassName, ParamExpClass, FunctionName );
that will create a static function that returns an instance to Factory1Param<ClassName,ParamExpClass>. The static function must be implemented in a src-file with the macro.
mImplFactory1Param( ClassName, ParamExpClass, FunctionName );
<>