13 template<
class TYPE,
class CTX>
17 virtual std::shared_ptr<TYPE> create (
const CTX* ctx)
const = 0;
20 template<
class KEY,
class TYPE,
class CTX>
23 typedef std::map<const KEY, const IFactory<TYPE, CTX>*> FactoryMap;
24 typedef typename FactoryMap::const_iterator FactoryMapConstIter;
25 typedef typename FactoryMap::iterator FactoryMapIter;
26 FactoryMap _factories;
30 FactoryMapConstIter i = _factories.find(type);
31 if (i != _factories.end()) {
35 _factories[type] = &factory;
39 bool unregisterFactory (
const KEY& type)
41 FactoryMapIter i = _factories.find(type);
42 if (i == _factories.end()) {
50 std::shared_ptr<TYPE> create (
const KEY& type,
const CTX* ctx =
nullptr)
const
52 FactoryMapConstIter i = _factories.find(type);
53 if (i == _factories.end()) {
54 return std::shared_ptr<TYPE>();
62 return factory->create(ctx);
65 ai_log_error(
"Exception while trying to create a factory");
67 return std::shared_ptr<TYPE>();
#define ai_log_error(...)
Logging macro to provide your own loggers.
Definition: Types.h:23
Definition: IFactoryRegistry.h:14
Definition: NonCopyable.h:8
Definition: IFactoryRegistry.h:21