#ifndef ComponentFactory_h__ #define ComponentFactory_h__ #include #include #include #include template class Factory { public: /*void Register(std::string name, std::function factoryFunction) { m_FactoryFunctions[name] = factoryFunction; }*/ template void Register(std::function factoryFunction) { m_FactoryFunctions[typeid(T2).name()] = factoryFunction; } /*T Create(std::string name) { auto it = m_FactoryFunctions.find(name); if (it != m_FactoryFunctions.end()) { return it->second(); } else { return nullptr; } }*/ template T Create() { auto it = m_FactoryFunctions.find(typeid(T2).name()); if (it != m_FactoryFunctions.end()) { return it->second(); } else { return nullptr; } } private: std::map> m_FactoryFunctions; }; #endif // ComponentFactory_h__