OpendTect  6.6
Public Types | Public Member Functions | Protected Attributes | List of all members
Factory1Param< T, P > Class Template Reference

Generalized static factory that can deliver instances of T, when a variable is needed in the creation. More...

Inheritance diagram for Factory1Param< T, P >:
[legend]

Public Types

typedef T *(* Creator) (P)
 

Public Member Functions

void addCreator (Creator, const char *nm=nullptr, const uiString &usernm=uiString::emptyString())
 
T * create (const char *nm, P, bool chknm=true) const
 
- Public Member Functions inherited from FactoryBase
virtual ~FactoryBase ()
 
const char * currentName () const
 
BufferStringerrMsg () const
 
const char * getDefaultName () const
 
const BufferStringSetgetNames () const
 
const uiStringSetgetUserNames () const
 
bool hasName (const char *n)
 
bool isEmpty () const
 
void setDefaultName (int idx)
 
int size () const
 

Protected Attributes

TypeSet< Creatorcreators_
 
- Protected Attributes inherited from FactoryBase
StaticStringManager currentname_
 
StaticStringManager errmsgs_
 

Additional Inherited Members

- Static Public Member Functions inherited from FactoryBase
static char cSeparator ()
 
- Protected Member Functions inherited from FactoryBase
void addNames (const char *, const uiString &)
 
int indexOf (const char *) const
 
void setNames (int, const char *, const uiString &)
 

Detailed Description

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 );

<>

Member Typedef Documentation

◆ Creator

template<class T , class P >
typedef T*(* Factory1Param< T, P >::Creator) (P)

Member Function Documentation

◆ addCreator()

template<class T , class P >
void Factory1Param< T, P >::addCreator ( Creator  cr,
const char *  nm = nullptr,
const uiString usernm = uiString::emptyString() 
)
inline

Name may be be null If nm is found, old creator is replaced. nm can be a SeparString, separated by cSeparator(), allowing multiple names, where the first name will be the main name that is returned in getNames.

◆ create()

template<class T , class P >
T * Factory1Param< T, P >::create ( const char *  nm,
data,
bool  chknm = true 
) const
inline

Name may be be null, if null name is given chknm will be forced to false

Member Data Documentation

◆ creators_

template<class T , class P >
TypeSet<Creator> Factory1Param< T, P >::creators_
protected

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2022