MyGUI 3.4.1
MyGUI_FactoryManager.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_FACTORY_MANAGER_H_
8#define MYGUI_FACTORY_MANAGER_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Singleton.h"
12#include "MyGUI_IObject.h"
14
15namespace MyGUI
16{
17
19 {
21 public:
23
24 void initialise();
25 void shutdown();
26
29 void registerFactory(const std::string& _category, const std::string& _type, Delegate::IDelegate* _delegate);
31 void unregisterFactory(const std::string& _category, const std::string& _type);
33 void unregisterFactory(const std::string& _category);
34
36 bool isFactoryExist(const std::string& _category, const std::string& _type);
37
39 template<typename Type>
40 void registerFactory(const std::string& _category)
41 {
42 registerFactory(_category, Type::getClassTypeName(), GenericFactory<Type>::getFactory());
43 }
44
46 template<typename Type>
47 void registerFactory(const std::string& _category, const std::string& _type)
48 {
49 registerFactory(_category, _type, GenericFactory<Type>::getFactory());
50 }
51
53 template<typename Type>
54 void unregisterFactory(const std::string& _category)
55 {
56 unregisterFactory(_category, Type::getClassTypeName());
57 }
58
60 IObject* createObject(const std::string& _category, const std::string& _type);
62 template<typename Type>
63 Type* createObject(const std::string& _category)
64 {
65 IObject* item = createObject(_category, Type::getClassTypeName());
66 if (item != nullptr)
67 return item->castType<Type>(false);
68 return nullptr;
69 }
70
72 void destroyObject(IObject* _object);
73
74 private:
75 typedef std::map<std::string, Delegate> MapFactoryItem;
76 typedef std::map<std::string, MapFactoryItem> MapRegisterFactoryItem;
77 MapRegisterFactoryItem mRegisterFactoryItems;
78
79 bool mIsInitialise;
80 };
81
82} // namespace MyGUI
83
84#endif // MYGUI_FACTORY_MANAGER_H_
#define MYGUI_EXPORT
#define MYGUI_SINGLETON_DECLARATION(ClassName)
void registerFactory(const std::string &_category)
delegates::CDelegate1< IObject *& > Delegate
void registerFactory(const std::string &_category, const std::string &_type)
Type * createObject(const std::string &_category)
void unregisterFactory(const std::string &_category)
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18