mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 03:29:44 -06:00
Simplify the function signature of the FactoryManager function
This commit is contained in:
@@ -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<ghoul::TemplateFactoryBase> factory,
|
||||
std::string name = "");
|
||||
template <typename T>
|
||||
void addFactory(std::string name);
|
||||
|
||||
/**
|
||||
* This method provides access to all registered ghoul::TemplateFactory%s through
|
||||
@@ -108,8 +110,8 @@ public:
|
||||
ghoul::TemplateFactory<T>* factory() const;
|
||||
|
||||
std::string generateJson() const override;
|
||||
private:
|
||||
|
||||
private:
|
||||
/// Singleton member for the Factory Manager
|
||||
static FactoryManager* _manager;
|
||||
|
||||
|
||||
@@ -26,9 +26,17 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
template <typename T>
|
||||
void FactoryManager::addFactory(std::string name) {
|
||||
ghoul_assert(!name.empty(), "Name must not be empty");
|
||||
auto f = std::make_unique<ghoul::TemplateFactory<T>>();
|
||||
_factories.push_back({ std::move(f), std::move(name) });
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
ghoul::TemplateFactory<T>* FactoryManager::factory() const {
|
||||
for (auto& f : _factories) {
|
||||
for (const FactoryInfo& f : _factories) {
|
||||
if (f.factory->baseClassType() == typeid(T))
|
||||
return dynamic_cast<ghoul::TemplateFactory<T>*>(f.factory.get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user