14 #ifndef FACTORY_INCLUDED
15 #define FACTORY_INCLUDED
41 template<
class AbstractProduct,
typename ProductCreator>
45 typedef std::map<IdentifierType, ProductCreator>
Map;
61 typename Map::const_iterator i =
m_map.find(subtype);
62 if (i !=
m_map.end()) {
65 fprintf(stderr,
"Factory::find: unknown type \"%s\"\n", subtype.c_str());
76 m_map.insert(
typename Map::value_type(subtype, creator)).second) {
79 fprintf(stderr,
"Factory::append: duplicate key \"%s\"\n", subtype.c_str());
118 void show_entries(
const char *tag)
123 for (
typename Map::const_iterator p =
m_map.begin(); p !=
m_map.end(); ++p) {
129 static void print(
const char *tag = NULL)
131 return Instance().show_entries(tag);
136 template<
class AbstractProduct,
typename ProductCreator>
static FactoryTemplate & Instance()
static bool Register(const IdentifierType &subtype, ProductCreator creator)
static void create_instance()
void general(const char *format,...)
static ProductCreator Find(const IdentifierType &subtype)
static FactoryTemplate * s_instance
bool append(const IdentifierType &subtype, ProductCreator creator)
virtual ~FactoryTemplate()
std::map< IdentifierType, ProductCreator > Map
ProductCreator find(const IdentifierType &subtype)
FactoryTemplate & operator=(const FactoryTemplate &)
FactoryTemplate(const FactoryTemplate &)
std::string IdentifierType
Factory template class.