MyGUI_FactoryManager.h
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#ifndef MYGUI_FACTORY_MANAGER_H_
#define MYGUI_FACTORY_MANAGER_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_Singleton.h"
#include "MyGUI_IObject.h"
#include "MyGUI_GenericFactory.h"
namespace MyGUI
{
class MYGUI_EXPORT FactoryManager
{
MYGUI_SINGLETON_DECLARATION(FactoryManager);
public:
FactoryManager();
void initialise();
void shutdown();
using Delegate = delegates::Delegate<IObject*&>;
void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate* _delegate);
void unregisterFactory(std::string_view _category, std::string_view _type);
void unregisterFactory(std::string_view _category);
bool isFactoryExist(std::string_view _category, std::string_view _type);
template<typename Type>
void registerFactory(std::string_view _category)
{
registerFactory(_category, Type::getClassTypeName(), GenericFactory<Type>::getFactory());
}
template<typename Type>
void registerFactory(std::string_view _category, std::string_view _type)
{
registerFactory(_category, _type, GenericFactory<Type>::getFactory());
}
template<typename Type>
void unregisterFactory(std::string_view _category)
{
unregisterFactory(_category, Type::getClassTypeName());
}
IObject* createObject(std::string_view _category, std::string_view _type);
template<typename Type>
Type* createObject(std::string_view _category)
{
IObject* item = createObject(_category, Type::getClassTypeName());
if (item != nullptr)
return item->castType<Type>(false);
return nullptr;
}
void destroyObject(IObject* _object);
private:
using MapFactoryItem = std::map<std::string, Delegate, std::less<>>;
using MapRegisterFactoryItem = std::map<std::string, MapFactoryItem, std::less<>>;
MapRegisterFactoryItem mRegisterFactoryItems;
bool mIsInitialise{false};
};
} // namespace MyGUI
#endif // MYGUI_FACTORY_MANAGER_H_
MyGUI_GenericFactory.h
MyGUI_IObject.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MyGUI_Singleton.h
MYGUI_SINGLETON_DECLARATION
#define MYGUI_SINGLETON_DECLARATION(ClassName)
Definition MyGUI_Singleton.h:112
MyGUI::FactoryManager::Delegate
delegates::Delegate< IObject *& > Delegate
Definition MyGUI_FactoryManager.h:28
MyGUI::FactoryManager::registerFactory
void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate *_delegate)
Definition MyGUI_FactoryManager.cpp:39
MyGUI::FactoryManager::registerFactory
void registerFactory(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.h:48
MyGUI::FactoryManager::isFactoryExist
bool isFactoryExist(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:126
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:54
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(std::string_view _category)
Definition MyGUI_FactoryManager.h:55
MyGUI::FactoryManager::createObject
Type * createObject(std::string_view _category)
Definition MyGUI_FactoryManager.h:64
MyGUI::FactoryManager::shutdown
void shutdown()
Definition MyGUI_FactoryManager.cpp:30
MyGUI::FactoryManager::initialise
void initialise()
Definition MyGUI_FactoryManager.cpp:21
MyGUI::FactoryManager::registerFactory
void registerFactory(std::string_view _category)
Definition MyGUI_FactoryManager.h:41
MyGUI::FactoryManager::FactoryManager
FactoryManager(const FactoryManager &)=delete
MyGUI::FactoryManager::createObject
IObject * createObject(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:80
MyGUI::GenericFactory::getFactory
static Delegate::IDelegate * getFactory()
Definition MyGUI_GenericFactory.h:23
MyGUI::IObject
Definition MyGUI_IObject.h:17
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::delegates::Delegate
Definition MyGUI_Delegate.h:158
MyGUI::delegates::Delegate< IObject *& >::IDelegate
DelegateFunction< Args... > IDelegate
Definition MyGUI_Delegate.h:160
MyGUI
Definition MyGUI_ActionController.h:15