diff --git a/include/openspace/util/factorymanager.h b/include/openspace/util/factorymanager.h index 50a45d3856..c085252382 100644 --- a/include/openspace/util/factorymanager.h +++ b/include/openspace/util/factorymanager.h @@ -88,12 +88,14 @@ public: /** * Adds the passed \p factory to the FactoryManager. Factories may only be added once. - * \param factory The ghoul::TemplateFactory to add to this FactoryManager * \param name A user-readable name for the registered factory. - * \pre \p factory must not be nullptr + * + * \tparam Factory The type for which a factory should be created and added + * + * \pre \p name must not be empty */ - void addFactory(std::unique_ptr factory, - std::string name = ""); + template + void addFactory(std::string name); /** * This method provides access to all registered ghoul::TemplateFactory%s through @@ -108,8 +110,8 @@ public: ghoul::TemplateFactory* factory() const; std::string generateJson() const override; -private: +private: /// Singleton member for the Factory Manager static FactoryManager* _manager; diff --git a/include/openspace/util/factorymanager.inl b/include/openspace/util/factorymanager.inl index f03bd16dd6..841f5661a4 100644 --- a/include/openspace/util/factorymanager.inl +++ b/include/openspace/util/factorymanager.inl @@ -26,9 +26,17 @@ namespace openspace { +template +void FactoryManager::addFactory(std::string name) { + ghoul_assert(!name.empty(), "Name must not be empty"); + auto f = std::make_unique>(); + _factories.push_back({ std::move(f), std::move(name) }); +} + + template ghoul::TemplateFactory* FactoryManager::factory() const { - for (auto& f : _factories) { + for (const FactoryInfo& f : _factories) { if (f.factory->baseClassType() == typeid(T)) return dynamic_cast*>(f.factory.get()); } diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index 0833f68966..b952604ea5 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -88,10 +88,7 @@ ghoul::opengl::TextureManager BaseModule::TextureManager; BaseModule::BaseModule() : OpenSpaceModule(BaseModule::Name) {} void BaseModule::internalInitialize(const ghoul::Dictionary&) { - FactoryManager::ref().addFactory( - std::make_unique>(), - "ScreenSpaceRenderable" - ); + FactoryManager::ref().addFactory("ScreenSpaceRenderable"); ghoul::TemplateFactory* fSsRenderable = FactoryManager::ref().factory(); diff --git a/modules/globebrowsing/globebrowsingmodule.cpp b/modules/globebrowsing/globebrowsingmodule.cpp index 65c8d87b70..8b0438741c 100644 --- a/modules/globebrowsing/globebrowsingmodule.cpp +++ b/modules/globebrowsing/globebrowsingmodule.cpp @@ -289,10 +289,7 @@ void GlobeBrowsingModule::internalInitialize(const ghoul::Dictionary& dict) { ghoul_assert(fRotation, "Rotation factory was not created"); fRotation->registerClass("GlobeRotation"); - FactoryManager::ref().addFactory( - std::make_unique>(), - _factoryName - ); + FactoryManager::ref().addFactory(_factoryName); ghoul::TemplateFactory* fTileProvider = FactoryManager::ref().factory(); diff --git a/modules/space/spacemodule.cpp b/modules/space/spacemodule.cpp index db9eae9b7f..52167897b0 100644 --- a/modules/space/spacemodule.cpp +++ b/modules/space/spacemodule.cpp @@ -73,10 +73,7 @@ SpaceModule::SpaceModule() } void SpaceModule::internalInitialize(const ghoul::Dictionary& dictionary) { - FactoryManager::ref().addFactory( - std::make_unique>(), - "PlanetGeometry" - ); + FactoryManager::ref().addFactory("PlanetGeometry"); ghoul::TemplateFactory* fRenderable = FactoryManager::ref().factory(); diff --git a/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp b/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp index 4081874cdf..7f662b701f 100644 --- a/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp +++ b/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp @@ -48,10 +48,7 @@ void SpacecraftInstrumentsModule::internalInitialize(const ghoul::Dictionary&) { ImageSequencer::initialize(); - FactoryManager::ref().addFactory( - std::make_unique>(), - "Decoder" - ); + FactoryManager::ref().addFactory("Decoder"); ghoul::TemplateFactory* fDashboard = FactoryManager::ref().factory(); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index dbeb3df936..80aaeb84ba 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -131,42 +131,15 @@ OpenSpaceEngine::OpenSpaceEngine() : _printEvents(PrintEventsInfo, false) { FactoryManager::initialize(); - FactoryManager::ref().addFactory( - std::make_unique>(), - "Renderable" - ); - FactoryManager::ref().addFactory( - std::make_unique>(), - "Translation" - ); - FactoryManager::ref().addFactory( - std::make_unique>(), - "Rotation" - ); - FactoryManager::ref().addFactory( - std::make_unique>(), - "Scale" - ); - FactoryManager::ref().addFactory( - std::make_unique>(), - "TimeFrame" - ); - FactoryManager::ref().addFactory( - std::make_unique>(), - "LightSource" - ); - FactoryManager::ref().addFactory( - std::make_unique>(), - "Task" - ); - FactoryManager::ref().addFactory( - std::make_unique>(), - "ResourceSynchronization" - ); - FactoryManager::ref().addFactory( - std::make_unique>(), - "DashboardItem" - ); + FactoryManager::ref().addFactory("Renderable"); + FactoryManager::ref().addFactory("Translation"); + FactoryManager::ref().addFactory("Rotation"); + FactoryManager::ref().addFactory("Scale"); + FactoryManager::ref().addFactory("TimeFrame"); + FactoryManager::ref().addFactory("LightSource"); + FactoryManager::ref().addFactory("Task"); + FactoryManager::ref().addFactory("ResourceSynchronization"); + FactoryManager::ref().addFactory("DashboardItem"); SpiceManager::initialize(); TransformationManager::initialize(); diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index abbab40de7..25ecea356f 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -70,14 +70,6 @@ FactoryManager& FactoryManager::ref() { return *_manager; } -void FactoryManager::addFactory(std::unique_ptr f, - std::string name) -{ - ghoul_assert(f, "Factory must not be nullptr"); - - _factories.push_back({ std::move(f), std::move(name) }); -} - std::string FactoryManager::generateJson() const { std::stringstream json;