26 #ifndef UTILIB_FACTORY_HPP__
27 #define UTILIB_FACTORY_HPP__
38 template <
typename IdentifierType,
typename ProductType>
46 throw std::bad_typeid();
53 template <
typename IdentifierType,
typename ProductType>
106 class AbstractProduct,
107 typename IdentifierType,
109 class>
class FactoryErrorPolicy = ErrorPolicyThrowException,
110 typename ProductCreatorSignature = AbstractProduct* (*)()
123 const IdentifierType&
id,
124 ProductCreatorSignature creator) {
125 return productMap_.insert(
typename ProductMap::value_type(
id,
134 return (productMap_.erase(
id) == 1);
144 typename ProductMap::const_iterator i = productMap_.find(
id);
145 if (i != productMap_.end()) {
146 return (*i).second();
148 return this->onUnknownType(
id);
155 typedef std::map<IdentifierType, ProductCreatorSignature> ProductMap;
159 ProductMap productMap_;
bool unregisterType(const IdentifierType &id)
static ProductType * onUnknownType(const IdentifierType &id)
AbstractProduct * createObject(const IdentifierType &id) const
bool registerType(const IdentifierType &id, ProductCreatorSignature creator)
static ProductType * onUnknownType(const IdentifierType &id)