Alsvinn  0.5.3
The fast FVM simulator with UQ support
Public Types | Static Public Member Functions | List of all members
alsutils::base::Factory< T, Args > Class Template Reference

#include <alsutils/base/Factory.hpp>

Public Types

typedef impl::FactoryRegistry< T, Args... >::PointerType PointerType
 
typedef impl::FactoryRegistry< T, Args... >::CreatorType CreatorType
 

Static Public Member Functions

static PointerType createInstance (const std::string &name, Args... args)
 Creates a new instance of the class with the given name and arguments. More...
 
static bool registerClass (const std::string &name, CreatorType creator)
 
template<class C >
static bool registerClassWithOnlyConstructor (const std::string &name)
 

Detailed Description

template<class T, class ... Args>
class alsutils::base::Factory< T, Args >

This is the base class for all "automatic factories"

The way this class is meant to be used, is to subclass this class specializing the templates

Example

class A {
public:
virtual void f() = 0;
static std::string getClassName() { return "namespace::A"; }
};
class AFactory : public alsutils::base::Factory<A, const std::string&>
class B : public A {
public:
B(const std::string & a) : a(a) {}
virtual void f() override {
std::cout << a << std::endl;
}
private:
const static bool initialized;
};
// This is usually in the .cpp file
const bool B::initialized = AFactory::registerClassWithOnlyConstructor("B");

Member Typedef Documentation

◆ CreatorType

template<class T, class ... Args>
typedef impl::FactoryRegistry<T, Args...>::CreatorType alsutils::base::Factory< T, Args >::CreatorType

◆ PointerType

template<class T, class ... Args>
typedef impl::FactoryRegistry<T, Args...>::PointerType alsutils::base::Factory< T, Args >::PointerType

Member Function Documentation

◆ createInstance()

template<class T, class ... Args>
static PointerType alsutils::base::Factory< T, Args >::createInstance ( const std::string &  name,
Args...  args 
)
inlinestatic

Creates a new instance of the class with the given name and arguments.

◆ registerClass()

template<class T, class ... Args>
static bool alsutils::base::Factory< T, Args >::registerClass ( const std::string &  name,
CreatorType  creator 
)
inlinestatic

Registers a new class to the registry.

Parameters
namethe name of the class
creatorthe creator/constructor

◆ registerClassWithOnlyConstructor()

template<class T, class ... Args>
template<class C >
static bool alsutils::base::Factory< T, Args >::registerClassWithOnlyConstructor ( const std::string &  name)
inlinestatic

Registers a new class to the registry, in this case, we assume the class has a constructor that takes all the default arguments

Parameters
namethe name of the class

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