MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #include "MyGUI_Precompiled.h" 00008 #include "MyGUI_FactoryManager.h" 00009 #include "MyGUI_BackwardCompatibility.h" 00010 00011 namespace MyGUI 00012 { 00013 00014 template <> FactoryManager* Singleton<FactoryManager>::msInstance = nullptr; 00015 template <> const char* Singleton<FactoryManager>::mClassTypeName = "FactoryManager"; 00016 00017 FactoryManager::FactoryManager() : 00018 mIsInitialise(false) 00019 { 00020 } 00021 00022 void FactoryManager::initialise() 00023 { 00024 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice"); 00025 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName()); 00026 00027 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized"); 00028 mIsInitialise = true; 00029 } 00030 00031 void FactoryManager::shutdown() 00032 { 00033 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised"); 00034 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName()); 00035 00036 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown"); 00037 mIsInitialise = false; 00038 } 00039 00040 void FactoryManager::registerFactory(const std::string& _category, const std::string& _type, Delegate::IDelegate* _delegate) 00041 { 00042 //FIXME 00043 mRegisterFactoryItems[_category][_type] = _delegate; 00044 } 00045 00046 void FactoryManager::unregisterFactory(const std::string& _category, const std::string& _type) 00047 { 00048 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category); 00049 if (category == mRegisterFactoryItems.end()) 00050 { 00051 return; 00052 } 00053 MapFactoryItem::iterator type = category->second.find(_type); 00054 if (type == category->second.end()) 00055 { 00056 return; 00057 } 00058 00059 category->second.erase(type); 00060 } 00061 00062 void FactoryManager::unregisterFactory(const std::string& _category) 00063 { 00064 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category); 00065 if (category == mRegisterFactoryItems.end()) 00066 { 00067 return; 00068 } 00069 mRegisterFactoryItems.erase(category); 00070 } 00071 00072 IObject* FactoryManager::createObject(const std::string& _category, const std::string& _type) 00073 { 00074 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category); 00075 if (category == mRegisterFactoryItems.end()) 00076 { 00077 return nullptr; 00078 } 00079 00080 std::string typeName = BackwardCompatibility::getFactoryRename(_category, _type); 00081 MapFactoryItem::iterator type = category->second.find(typeName); 00082 if (type == category->second.end()) 00083 { 00084 return nullptr; 00085 } 00086 if (type->second.empty()) 00087 { 00088 return nullptr; 00089 } 00090 00091 IObject* result = nullptr; 00092 type->second(result); 00093 return result; 00094 } 00095 00096 void FactoryManager::destroyObject(IObject* _object) 00097 { 00098 delete _object; 00099 00100 /*MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category); 00101 if (category == mRegisterFactoryItems.end()) 00102 { 00103 return; 00104 } 00105 MapFactoryItem::iterator type = category->second.find(_type); 00106 if (type == category->second.end()) 00107 { 00108 return; 00109 } 00110 if (type->second.empty()) 00111 { 00112 return; 00113 } 00114 00115 type->second(_object, nullptr, _version);*/ 00116 } 00117 00118 bool FactoryManager::isFactoryExist(const std::string& _category, const std::string& _type) 00119 { 00120 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category); 00121 if (category == mRegisterFactoryItems.end()) 00122 { 00123 return false; 00124 } 00125 MapFactoryItem::iterator type = category->second.find(_type); 00126 if (type == category->second.end()) 00127 { 00128 return false; 00129 } 00130 00131 return true; 00132 } 00133 00134 } // namespace MyGUI