queso-0.56.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
QUESO::Factory< Base > Class Template Referenceabstract

#include <Factory.h>

Inheritance diagram for QUESO::Factory< Base >:
Inheritance graph
[legend]

Public Member Functions

virtual ~Factory ()
 
virtual SharedPtr< Base >::Type create ()=0
 

Static Public Member Functions

static SharedPtr< Base >::Type build (const std::string &name)
 

Protected Member Functions

 Factory (const std::string &name)
 
template<>
std::map< std::string, Factory
< Algorithm< GslVector,
GslMatrix > > * > & 
factory_map ()
 
template<>
std::map< std::string, Factory
< BaseTKGroup< GslVector,
GslMatrix > > * > & 
factory_map ()
 

Static Protected Member Functions

static std::map< std::string,
Factory< Base > * > & 
factory_map ()
 

Detailed Description

template<class Base>
class QUESO::Factory< Base >

Factory class defintion.

Definition at line 43 of file Factory.h.

Constructor & Destructor Documentation

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

Constructor. Takes the name to be mapped.

Definition at line 103 of file Factory.h.

References queso_assert.

104 {
105  // Make sure we haven't already added this name
106  // to the map
107  queso_assert(!factory_map().count(name));
108 
109  factory_map()[name] = this;
110 }
static std::map< std::string, Factory< Base > * > & factory_map()
#define queso_assert(asserted)
Definition: asserts.h:132
template<class Base>
virtual QUESO::Factory< Base >::~Factory ( )
inlinevirtual

Destructor. (Empty.)

Definition at line 55 of file Factory.h.

55 {}

Member Function Documentation

template<class Base >
SharedPtr< Base >::Type QUESO::Factory< Base >::build ( const std::string &  name)
inlinestatic

Builds an object of type Base identified by name.

Definition at line 114 of file Factory.h.

References QUESO::Factory< Base >::create(), it, and queso_error_msg.

115 {
116  // name not found in the map
117  if (!factory_map().count(name))
118  {
119  std::cerr << "Tried to build an unknown type: " << name << std::endl;
120 
121  std::cerr << "valid options are:" << std::endl;
122 
123  for (typename std::map<std::string,Factory<Base> *>::const_iterator
124  it = factory_map().begin(); it != factory_map().end(); ++it)
125  std::cerr << " " << it->first << std::endl;
126 
127  queso_error_msg("Exiting...");
128 
129  // We'll never get here
130  return typename SharedPtr<Base>::Type();
131  }
132 
133  Factory<Base> * f = factory_map()[name];
134  return typename SharedPtr<Base>::Type(f->create());
135 }
static std::map< std::string, Factory< Base > * > & factory_map()
that you receive source code or can get it if you want it
Definition: License.txt:41
#define queso_error_msg(msg)
Definition: asserts.h:47
template<class Base>
virtual SharedPtr<Base>::Type QUESO::Factory< Base >::create ( )
pure virtual

Create a Base class. Force this to be implemented later.

Implemented in QUESO::TransitionKernelFactory, QUESO::FactoryImp< Derived, Base >, and QUESO::AlgorithmFactory.

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

template<>
std::map< std::string, Factory< Algorithm< GslVector, GslMatrix > > * > & QUESO::Factory< Algorithm< GslVector, GslMatrix > >::factory_map ( )
protected

Definition at line 34 of file AlgorithmFactory.C.

35 {
36  static std::map<std::string, Factory<Algorithm<GslVector, GslMatrix> > *> _factory_map;
37 
38  return _factory_map;
39 }
template<>
std::map< std::string, Factory< BaseTKGroup< GslVector, GslMatrix > > * > & QUESO::Factory< BaseTKGroup< GslVector, GslMatrix > >::factory_map ( )
protected

Definition at line 37 of file TransitionKernelFactory.C.

38 {
39  static std::map<std::string, Factory<BaseTKGroup<GslVector, GslMatrix> > *> _factory_map;
40 
41  return _factory_map;
42 }
template<class Base>
static std::map<std::string, Factory<Base> *>& QUESO::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:

Generated on Tue Nov 29 2016 10:53:13 for queso-0.56.0 by  doxygen 1.8.5