libMesh
Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Private Member Functions | List of all members
libMesh::FactoryImp< Derived, Base > Class Template Reference

Factory implementation class. More...

#include <factory.h>

Inheritance diagram for libMesh::FactoryImp< Derived, Base >:
[legend]

Public Member Functions

 FactoryImp (const std::string &name)
 Constructor. More...
 
 ~FactoryImp ()
 Destructor. More...
 

Static Public Member Functions

static std::unique_ptr< Base > build (const std::string &name)
 Builds an object of type Base identified by name. More...
 

Static Protected Member Functions

static std::map< std::string, Factory< Base > * > & factory_map ()
 Map from a name to a Factory<Base> * pointer. More...
 

Private Member Functions

virtual std::unique_ptr< Base > create () override
 

Detailed Description

template<class Derived, class Base>
class libMesh::FactoryImp< Derived, Base >

Factory implementation class.

Definition at line 88 of file factory.h.

Constructor & Destructor Documentation

◆ FactoryImp()

template<class Derived , class Base >
libMesh::FactoryImp< Derived, Base >::FactoryImp ( const std::string &  name)

Constructor.

Takes a name as input.

Definition at line 95 of file factory.h.

95 : Factory<Base>(name) { }
std::string name(const ElemQuality q)

◆ ~FactoryImp()

template<class Derived , class Base >
libMesh::FactoryImp< Derived, Base >::~FactoryImp ( )

Destructor.

Empty.

Definition at line 100 of file factory.h.

100 {}

Member Function Documentation

◆ build()

template<class Base >
std::unique_ptr< Base > libMesh::Factory< Base >::build ( const std::string &  name)
staticinherited

Builds an object of type Base identified by name.

Definition at line 129 of file factory.h.

References libMesh::Factory< Base >::create(), libMesh::err, and libMesh::Quality::name().

130 {
131  // name not found in the map
132  if (!factory_map().count(name))
133  {
134  libMesh::err << "Tried to build an unknown type: " << name << std::endl;
135 
136  libMesh::err << "valid options are:" << std::endl;
137 
138  for (const auto & pr : factory_map())
139  libMesh::err << " " << pr.first << std::endl;
140 
141  libmesh_error_msg("Exiting...");
142  }
143 
144  Factory<Base> * f = factory_map()[name];
145  return std::unique_ptr<Base>(f->create());
146 }
std::string name(const ElemQuality q)
static std::map< std::string, Factory< Base > * > & factory_map()
Map from a name to a Factory<Base> * pointer.
OStreamProxy err

◆ create()

template<class Derived , class Base >
std::unique_ptr< Base > libMesh::FactoryImp< Derived, Base >::create ( )
overrideprivatevirtual
Returns
A new object of type Derived.

Implements libMesh::Factory< Base >.

Definition at line 152 of file factory.h.

153 {
154  return libmesh_make_unique<Derived>();
155 }

◆ factory_map()

template<class Base>
static std::map<std::string, Factory<Base> *>& libMesh::Factory< Base >::factory_map ( )
staticprotectedinherited

Map from a name to a Factory<Base> * pointer.


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