MyGUI
3.0.1
|
00001 00007 /* 00008 This file is part of MyGUI. 00009 00010 MyGUI is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 MyGUI is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 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 //FIXME 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 /*MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category); 00109 if (category == mRegisterFactoryItems.end()) 00110 { 00111 return; 00112 } 00113 MapFactoryItem::iterator type = category->second.find(_type); 00114 if (type == category->second.end()) 00115 { 00116 return; 00117 } 00118 if (type->second.empty()) 00119 { 00120 return; 00121 } 00122 00123 type->second(_object, nullptr, _version);*/ 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 } // namespace MyGUI