libMesh
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
libMesh::Factory< Base > Class Template Referenceabstract

Factory class definition. More...

#include <factory.h>

Inheritance diagram for libMesh::Factory< Base >:
[legend]

Public Member Functions

virtual ~Factory ()=default
 Destructor. More...
 
virtual std::unique_ptr< Base > create ()=0
 Create a Base class. 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...
 

Protected Member Functions

 Factory (const std::string &name)
 Constructor. More...
 
template<>
std::map< std::string, Factory< FunctionBase< Number > > *> & factory_map ()
 
template<>
std::map< std::string, Factory< FunctionBase< Number > > *> & factory_map ()
 
template<>
std::map< std::string, Factory< Partitioner > *> & factory_map ()
 

Static Protected Member Functions

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

Detailed Description

template<class Base>
class libMesh::Factory< Base >

Factory class definition.

Author
Benjamin S. Kirk
Date
2002 Handles name-based creation of objects.

Definition at line 46 of file factory.h.

Constructor & Destructor Documentation

◆ Factory()

template<class Base >
libMesh::Factory< Base >::Factory ( const std::string &  name)
inlineprotected

Constructor.

Takes the name to be mapped.

Definition at line 116 of file factory.h.

References libMesh::libmesh_assert(), and libMesh::Quality::name().

117 {
118  // Make sure we haven't already added this name
119  // to the map
120  libmesh_assert (!factory_map().count(name));
121 
122  factory_map()[name] = this;
123 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
static std::map< std::string, Factory< Base > * > & factory_map()
Map from a name to a Factory<Base> * pointer.
libmesh_assert(ctx)

◆ ~Factory()

template<class Base>
virtual libMesh::Factory< Base >::~Factory ( )
virtualdefault

Destructor.

Member Function Documentation

◆ build()

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

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().

Referenced by main().

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)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
OStreamProxy err
static std::map< std::string, Factory< Base > * > & factory_map()
Map from a name to a Factory<Base> * pointer.

◆ create()

template<class Base>
virtual std::unique_ptr<Base> libMesh::Factory< Base >::create ( )
pure virtual

Create a Base class.

Force this to be implemented later.

Implemented in libMesh::FactoryImp< Derived, Base >.

Referenced by libMesh::Factory< Base >::build().

◆ factory_map() [1/4]

template<>
std::map< std::string, Factory< Partitioner > * > & libMesh::Factory< Partitioner >::factory_map ( )
protected

Definition at line 38 of file partitioner_factory.C.

39 {
40  static std::map<std::string, Factory<Partitioner> *> _map;
41  return _map;
42 }

◆ factory_map() [2/4]

template<>
std::map< std::string, Factory< FunctionBase< Number > > * > & libMesh::Factory< FunctionBase< Number > >::factory_map ( )
protected

Definition at line 64 of file factoryfunction.C.

65 {
66  static std::map<std::string, Factory<FunctionBase<Number>> *> _map;
67  return _map;
68 }

◆ factory_map() [3/4]

template<>
std::map< std::string, Factory< FunctionBase< Number > > * > & libMesh::Factory< FunctionBase< Number > >::factory_map ( )
protected

Definition at line 64 of file factoryfunction.C.

65 {
66  static std::map<std::string, Factory<FunctionBase<Number>> *> _map;
67  return _map;
68 }

◆ factory_map() [4/4]

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

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


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