#ifndef LVOX3_FACTORY_HPP #define LVOX3_FACTORY_HPP #include #include template class Factory { public: template void registerType(QString name) { static_assert(std::is_base_of::value, "Factory::registerType doesn't accept this type because doesn't derive from base class"); _createFuncs[name] = &createFunc; } T* create(QString name) { typename QMap::const_iterator it = _createFuncs.find(name); if (it != _createFuncs.end()) { return it.value()(); } return nullptr; } private: template static T* createFunc() { return new TDerived(); } typedef T* (*PCreateFunc)(); QMap _createFuncs; }; #endif // LVOX3_FACTORY_HPP