3#include "spark/patterns/details/Creators.h"
5#include "spark/base/Exception.h"
9namespace spark::patterns
11 template <
typename Key,
typename BaseType,
typename... Args>
12 template <
typename TypeToRegister>
15 if (m_creators.contains(key))
20 template <
typename Key,
typename BaseType,
typename... Args>
23 if (!m_creators.contains(key))
25 return m_creators.at(key)->create(std::forward<Args>(args)...);
28 template <
typename Key,
typename BaseType,
typename... Args>
31 if (!m_creators.contains(key))
33 return m_creators.at(key)->
create(std::forward<Args>(args)...);
36 template <
typename Key,
typename BaseType,
typename... Args>
39 std::vector<Key> keys;
40 keys.reserve(m_creators.size());
41 for (
const auto& [key, ptr] : m_creators)
Exception thrown when an argument is not valid.
Definition Exception.h:32
A factory class that creates objects of type BaseType.
Definition Factory.h:19
BasePtr createOrFail(const Key &key, Args &&... args) const noexcept
Creates an object of type BaseType.
Definition Factory.h:29
void registerType(const Key &key)
Registers a type the factory can create.
Definition Factory.h:13
std::vector< Key > registeredTypes() const noexcept
Gets a vector of all registered types in the factory.
Definition Factory.h:37
BasePtr create(const Key &key, Args &&... args) const
Creates an object of type BaseType. Throws an exception if the type is not registered.
Definition Factory.h:21
The creator for a derived class.
Definition Creators.h:31