3#include "spark/patterns/details/Creators.h"
6#include <unordered_map>
9namespace spark::patterns
17 template <
typename Key,
typename BaseType,
typename... Args>
21 using BasePtr = std::unique_ptr<BaseType>;
40 template <
typename TypeToRegister>
51 [[nodiscard]] BasePtr
create(
const Key& key, Args&&... args)
const;
59 [[nodiscard]] BasePtr
createOrFail(
const Key& key, Args&&... args)
const noexcept;
68 std::unordered_map<Key, CreatorPtr> m_creators;
72#include "spark/patterns/impl/Factory.h"
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
A base class for all creators.
Definition Creators.h:14