20 #ifndef LIBMESH_FACTORY_H
21 #define LIBMESH_FACTORY_H
25 #include "libmesh/libmesh_common.h"
53 Factory (
const std::string & name);
65 static std::unique_ptr<Base>
build (
const std::string & name);
71 virtual std::unique_ptr<Base>
create () = 0;
79 static std::map<std::string, Factory<Base> *> &
factory_map();
87 template <
class Derived,
class Base>
107 virtual std::unique_ptr<Base>
create ()
override;
114 template <
class Base>
120 libmesh_assert (!factory_map().count(name));
122 factory_map()[name] =
this;
127 template <
class Base>
132 if (!factory_map().count(name))
134 libMesh::err <<
"Tried to build an unknown type: " << name << std::endl;
138 for (
const auto & pr : factory_map())
141 libmesh_error_msg(
"Exiting...");
145 return std::unique_ptr<Base>(f->
create());
150 template <
class Derived,
class Base>
154 return std::make_unique<Derived>();
160 #endif // LIBMESH_FACTORY_H
~FactoryImp()=default
Destructor.
static std::map< std::string, Factory< Base > * > & factory_map()
Map from a name to a Factory<Base> * pointer.
virtual ~Factory()=default
Destructor.
Factory implementation class.
Factory class definition.
virtual std::unique_ptr< Base > create()=0
Create a Base class.
FactoryImp(const std::string &name)
Constructor.
virtual std::unique_ptr< Base > create() override
Factory(const std::string &name)
Constructor.
static std::unique_ptr< Base > build(const std::string &name)
Builds an object of type Base identified by name.