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