5 template <
typename BaseType,
typename KeyType,
typename... CtorArgs>
8 using SharedCreator = std::function<std::shared_ptr<BaseType>(CtorArgs...)>;
9 using UniqueCreator = std::function<std::unique_ptr<BaseType>(CtorArgs...)>;
23 if (m_SharedCreators.count(key)) {
27 m_SharedCreators.insert({ key, creator });
32 if (m_UniqueCreators.count(key)) {
36 m_UniqueCreators.insert({ key, creator });
40 static std::shared_ptr<BaseType>
CreateShared(
const KeyType& key, CtorArgs... ctorArgs) {
41 if (!
Instance().m_SharedCreators.contains(key)) {
45 return Instance().m_SharedCreators.at(key)(std::forward<CtorArgs>(ctorArgs)...);
48 static std::unique_ptr<BaseType>
CreateUnique(
const KeyType& key, CtorArgs... ctorArgs) {
49 if (!
Instance().m_UniqueCreators.contains(key)) {
53 return Instance().m_UniqueCreators.at(key)(std::forward<CtorArgs>(ctorArgs)...);
61 std::unordered_map<KeyType, SharedCreator> m_SharedCreators;
62 std::unordered_map<KeyType, UniqueCreator> m_UniqueCreators;
66 template <
typename BaseType,
typename DerivedType,
typename KeyType, KeyType KeyValue,
typename... CtorArgs>
78 static std::shared_ptr<BaseType> CreateShared(CtorArgs&&... ctorArgs) {
79 if (DerivedType::PreCreateHook(std::forward<CtorArgs>(ctorArgs)...)) {
80 return std::make_shared<DerivedType>(std::forward<CtorArgs>(ctorArgs)...);
86 static std::unique_ptr<BaseType> CreateUnique(CtorArgs&&... ctorArgs) {
87 if (DerivedType::PreCreateHook(std::forward<CtorArgs>(ctorArgs)...)) {
88 return std::make_unique<DerivedType>(std::forward<CtorArgs>(ctorArgs)...);
102#define CORI_REGISTERED_FACTORY_INIT \
104 struct StaticInitHelper { \
105 StaticInitHelper() { \
106 (void)RegisterShared; \
107 (void)RegisterUnique; \
110 inline static StaticInitHelper s_InitHelper
#define CORI_CLEAN_TYPE_NAME(tn)
#define CORI_CORE_ERROR_TAGGED(...)
static std::shared_ptr< BaseType > CreateShared(const KeyType &key, CtorArgs... ctorArgs)
bool RegisterShared(const KeyType &key, SharedCreator creator)
std::function< std::unique_ptr< BaseType >(CtorArgs...)> UniqueCreator
Factory(Factory &&)=delete
static Factory & Instance()
bool RegisterUnique(const KeyType &key, UniqueCreator creator)
static std::unique_ptr< BaseType > CreateUnique(const KeyType &key, CtorArgs... ctorArgs)
Factory(const Factory &)=delete
Factory & operator=(Factory &&)=delete
std::function< std::shared_ptr< BaseType >(CtorArgs...)> SharedCreator
Factory & operator=(const Factory &)=delete
virtual ~RegisterInFactory()=default
RegisterInFactory & operator=(const RegisterInFactory &)=delete
RegisterInFactory(RegisterInFactory &&)=delete
RegisterInFactory & operator=(RegisterInFactory &&)=delete
static bool RegisterUnique
RegisterInFactory(const RegisterInFactory &)=delete
RegisterInFactory()=default
static bool RegisterShared
Core systems of the engine are here.