25 #ifndef GRINS_FACTORY_ABSTRACT_H
26 #define GRINS_FACTORY_ABSTRACT_H
34 #include "libmesh/libmesh_common.h"
35 #include "libmesh/auto_ptr.h"
44 template<
typename Base>
52 static libMesh::UniquePtr<Base>
build(
const std::string & name);
55 virtual libMesh::UniquePtr<Base>
create () = 0;
66 template<
typename DerivedType>
69 static std::map<std::string, FactoryAbstract<Base>*>&
factory_map();
79 libmesh_assert (!factory_map().count(name));
81 factory_map()[name] =
this;
96 if (!factory_map().count(name))
99 ss <<
"ERROR: Tried to build an unknown FactoryAbstract type: "
101 <<
"valid options are:" << std::endl;
104 it = factory_map().begin(); it != factory_map().end(); ++it )
105 ss <<
" " << it->first << std::endl;
107 libmesh_error_msg(ss.str());
114 template <
class Base>
115 template<
typename DerivedType>
120 DerivedType& factory = libMesh::cast_ref<DerivedType&>(raw_factory);
126 #endif // GRINS_FACTORY_ABSTRACT_H
virtual libMesh::UniquePtr< Base > create()=0
Subclasses implement the actual construction of the Base object in create().
FactoryAbstract(const std::string &name)
Constructor is protected. Use the build() method to construct Base objects.
virtual ~FactoryAbstract()
static std::map< std::string, FactoryAbstract< Base > * > & factory_map()
static libMesh::UniquePtr< Base > build(const std::string &name)
Use this method to build objects of type Base.
static FactoryAbstract< Base > & get_factory(const std::string &name)
Helper method that looks up the factory and returns it if present, or error if it's not...
static DerivedType & get_factory_subclass(const std::string &name)
Like get_factory, but will downcast to DerivedType.