00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_FactoryManager.h"
00025
00026 namespace MyGUI
00027 {
00028
00029 MYGUI_INSTANCE_IMPLEMENT( FactoryManager )
00030
00031 void FactoryManager::initialise()
00032 {
00033 MYGUI_ASSERT(!mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice");
00034 MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME);
00035
00036
00037 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized");
00038 mIsInitialise = true;
00039 }
00040
00041 void FactoryManager::shutdown()
00042 {
00043 if (!mIsInitialise) return;
00044 MYGUI_LOG(Info, "* Shutdown: " << INSTANCE_TYPE_NAME);
00045
00046 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully shutdown");
00047 mIsInitialise = false;
00048 }
00049
00050 void FactoryManager::registerFactory(const std::string& _category, const std::string& _type, Delegate::IDelegate* _delegate)
00051 {
00052
00053 mRegisterFactoryItems[_category][_type] = _delegate;
00054 }
00055
00056 void FactoryManager::unregisterFactory(const std::string& _category, const std::string& _type)
00057 {
00058 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
00059 if (category == mRegisterFactoryItems.end())
00060 {
00061 return;
00062 }
00063 MapFactoryItem::iterator type = category->second.find(_type);
00064 if (type == category->second.end())
00065 {
00066 return;
00067 }
00068
00069 category->second.erase(type);
00070 }
00071
00072 void FactoryManager::unregisterFactory(const std::string& _category)
00073 {
00074 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
00075 if (category == mRegisterFactoryItems.end())
00076 {
00077 return;
00078 }
00079 mRegisterFactoryItems.erase(category);
00080 }
00081
00082 IObject* FactoryManager::createObject(const std::string& _category, const std::string& _type)
00083 {
00084 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
00085 if (category == mRegisterFactoryItems.end())
00086 {
00087 return nullptr;
00088 }
00089 MapFactoryItem::iterator type = category->second.find(_type);
00090 if (type == category->second.end())
00091 {
00092 return nullptr;
00093 }
00094 if (type->second.empty())
00095 {
00096 return nullptr;
00097 }
00098
00099 IObject* result = nullptr;
00100 type->second(result);
00101 return result;
00102 }
00103
00104 void FactoryManager::destroyObject(IObject* _object)
00105 {
00106 delete _object;
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 }
00125
00126 bool FactoryManager::isFactoryExist(const std::string& _category, const std::string& _type)
00127 {
00128 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
00129 if (category == mRegisterFactoryItems.end())
00130 {
00131 return false;
00132 }
00133 MapFactoryItem::iterator type = category->second.find(_type);
00134 if (type == category->second.end())
00135 {
00136 return false;
00137 }
00138
00139 return true;
00140 }
00141
00142 }