MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #include "MyGUI_Precompiled.h" 00023 #include "MyGUI_FactoryManager.h" 00024 #include "MyGUI_BackwardCompatibility.h" 00025 00026 namespace MyGUI 00027 { 00028 00029 template <> FactoryManager* Singleton<FactoryManager>::msInstance = nullptr; 00030 template <> const char* Singleton<FactoryManager>::mClassTypeName("FactoryManager"); 00031 00032 FactoryManager::FactoryManager() : 00033 mIsInitialise(false) 00034 { 00035 } 00036 00037 void FactoryManager::initialise() 00038 { 00039 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice"); 00040 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName()); 00041 00042 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized"); 00043 mIsInitialise = true; 00044 } 00045 00046 void FactoryManager::shutdown() 00047 { 00048 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised"); 00049 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName()); 00050 00051 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown"); 00052 mIsInitialise = false; 00053 } 00054 00055 void FactoryManager::registerFactory(const std::string& _category, const std::string& _type, Delegate::IDelegate* _delegate) 00056 { 00057 //FIXME 00058 mRegisterFactoryItems[_category][_type] = _delegate; 00059 } 00060 00061 void FactoryManager::unregisterFactory(const std::string& _category, const std::string& _type) 00062 { 00063 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category); 00064 if (category == mRegisterFactoryItems.end()) 00065 { 00066 return; 00067 } 00068 MapFactoryItem::iterator type = category->second.find(_type); 00069 if (type == category->second.end()) 00070 { 00071 return; 00072 } 00073 00074 category->second.erase(type); 00075 } 00076 00077 void FactoryManager::unregisterFactory(const std::string& _category) 00078 { 00079 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category); 00080 if (category == mRegisterFactoryItems.end()) 00081 { 00082 return; 00083 } 00084 mRegisterFactoryItems.erase(category); 00085 } 00086 00087 IObject* FactoryManager::createObject(const std::string& _category, const std::string& _type) 00088 { 00089 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category); 00090 if (category == mRegisterFactoryItems.end()) 00091 { 00092 return nullptr; 00093 } 00094 00095 std::string typeName = BackwardCompatibility::getFactoryRename(_category, _type); 00096 MapFactoryItem::iterator type = category->second.find(typeName); 00097 if (type == category->second.end()) 00098 { 00099 return nullptr; 00100 } 00101 if (type->second.empty()) 00102 { 00103 return nullptr; 00104 } 00105 00106 IObject* result = nullptr; 00107 type->second(result); 00108 return result; 00109 } 00110 00111 void FactoryManager::destroyObject(IObject* _object) 00112 { 00113 delete _object; 00114 00115 /*MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category); 00116 if (category == mRegisterFactoryItems.end()) 00117 { 00118 return; 00119 } 00120 MapFactoryItem::iterator type = category->second.find(_type); 00121 if (type == category->second.end()) 00122 { 00123 return; 00124 } 00125 if (type->second.empty()) 00126 { 00127 return; 00128 } 00129 00130 type->second(_object, nullptr, _version);*/ 00131 } 00132 00133 bool FactoryManager::isFactoryExist(const std::string& _category, const std::string& _type) 00134 { 00135 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category); 00136 if (category == mRegisterFactoryItems.end()) 00137 { 00138 return false; 00139 } 00140 MapFactoryItem::iterator type = category->second.find(_type); 00141 if (type == category->second.end()) 00142 { 00143 return false; 00144 } 00145 00146 return true; 00147 } 00148 00149 } // namespace MyGUI