25 #ifndef QUESO_FACTORY_H
26 #define QUESO_FACTORY_H
28 #include <queso/asserts.h>
29 #include <queso/SharedPtr.h>
49 Factory(
const std::string & name);
72 static std::map<std::string, Factory<Base> *> &
factory_map();
78 template <
class Derived,
class Base>
101 template <
class Base>
107 queso_assert(!factory_map().count(name));
109 factory_map()[name] =
this;
112 template <
class Base>
117 if (!factory_map().count(name))
119 std::cerr <<
"Tried to build an unknown type: " << name << std::endl;
121 std::cerr <<
"valid options are:" << std::endl;
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;
127 queso_error_msg(
"Exiting...");
146 template <
class Derived,
class Base>
155 #endif // QUESO_FACTORY_H
std::shared_ptr< T > Type
FactoryImp(const std::string &name)
virtual SharedPtr< Base >::Type create()
static SharedPtr< Base >::Type build(const std::string &name)
Factory(const std::string &name)
static std::map< std::string, Factory< Base > * > & factory_map()
virtual SharedPtr< Base >::Type create()=0