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 55 56 57
|
/*!
@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:
FactoryManager();
~FactoryManager();
static FactoryManager* GetInstancePtr();
static FactoryManager& GetInstance();
bool ExistFactory(const std::string& _factoryName);
void RegisterFactory(IFactory* _factory, const std::string& _factoryName);
void UnregisterAllFactories();
IFactoryItem* CreateItem(const std::string& _factoryName);
template <typename Type>
Type* CreateItem(const std::string& _factoryName)
{
IFactoryItem* item = CreateItem(_factoryName);
if (item != nullptr)
{
Type* result = dynamic_cast<Type*>(item);
if (result != nullptr)
return result;
delete item;
}
return nullptr;
}
private:
typedef std::map<std::string, IFactory*> MapFactory;
MapFactory mFactories;
};
}
#endif
|