1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
/*!
@file
@author Albert Semenov
@date 07/2012
*/
#ifndef _60e2a077_d22d_435e_866e_ac48372e1eed_
#define _60e2a077_d22d_435e_866e_ac48372e1eed_
#include <string>
#include <map>
#include "IFactory.h"
#include "FactoryTemplate.h"
#include "FactoryItemRegistrator.h"
#include "FactoryItemAttribute.h"
namespace components
{
class MYGUI_EXPORT_DLL FactoryManager
{
public:
static FactoryManager* GetInstancePtr();
static FactoryManager& GetInstance();
bool ExistFactory(std::string_view _factoryName);
void RegisterFactory(IFactory* _factory, std::string_view _factoryName);
void UnregisterAllFactories();
IFactoryItem* CreateItem(std::string_view _factoryName);
template<typename Type>
Type* CreateItem(std::string_view _factoryName)
{
IFactoryItem* item = CreateItem(_factoryName);
if (item != nullptr)
{
Type* result = dynamic_cast<Type*>(item);
if (result != nullptr)
return result;
delete item;
}
return nullptr;
}
private:
using MapFactory = std::map<std::string, IFactory*, std::less<>>;
MapFactory mFactories;
};
}
#endif
|