34 const std::string
XML_TYPE(
"Resource");
37 template <> ResourceManager* Singleton<ResourceManager>::msInstance =
nullptr;
71 mMapLoadXmlDelegate.clear();
74 mIsInitialise =
false;
91 std::string type, name;
98 MapResource::iterator item = mResources.find(name);
99 if (item != mResources.end())
101 MYGUI_LOG(Warning,
"dublicate resource name '" << name <<
"'");
104 mRemovedResoures.push_back((*item).second);
105 mResources.erase(item);
109 if (
object ==
nullptr)
111 MYGUI_LOG(Error,
"resource type '" << type <<
"' not found");
118 mResources[name] = resource;
130 MYGUI_LOG(Info,
"Load ini file '" << source <<
"'");
137 MapLoadXmlDelegate::iterator iter = mMapLoadXmlDelegate.find(_key);
138 MYGUI_ASSERT(iter == mMapLoadXmlDelegate.end(),
"name delegate is exist");
144 MapLoadXmlDelegate::iterator iter = mMapLoadXmlDelegate.find(_key);
145 if (iter != mMapLoadXmlDelegate.end()) mMapLoadXmlDelegate.erase(iter);
148 bool ResourceManager::_loadImplement(
const std::string& _file,
bool _match,
const std::string& _type,
const std::string& _instance)
153 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', not found");
160 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', " << doc.getLastError());
165 if ( (
nullptr == root) || (root->getName() !=
"MyGUI") )
167 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', tag 'MyGUI' not found");
172 if (root->findAttribute(
"type", type))
175 MapLoadXmlDelegate::iterator iter = mMapLoadXmlDelegate.find(type);
176 if (iter != mMapLoadXmlDelegate.end())
178 if ((!_match) || (type == _type))
179 (*iter).second(root, _file, version);
182 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', type '" << _type <<
"' not found");
188 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', delegate for type '" << type <<
"'not found");
196 while (node.next(
"MyGUI"))
198 if (node->findAttribute(
"type", type))
201 MapLoadXmlDelegate::iterator iter = mMapLoadXmlDelegate.find(type);
202 if (iter != mMapLoadXmlDelegate.end())
204 (*iter).second(node.current(), _file, version);
208 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', delegate for type '" << type <<
"'not found");
213 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', tag 'type' not found");
229 if (_item ==
nullptr)
234 MapResource::iterator item = mResources.find(_item->
getResourceName());
235 if (item != mResources.end())
236 mResources.erase(item);
242 return mResources.find(_name) != mResources.end();
247 MapResource::const_iterator item = mResources.find(_name);
248 return (item == mResources.end()) ?
nullptr : item->second;
254 MYGUI_ASSERT(result || !_throw,
"Resource '" << _name <<
"' not found");
260 MapResource::const_iterator item = mResources.find(_name);
261 if (item != mResources.end())
264 mResources.erase(item->first);
272 for (MapResource::iterator item = mResources.begin(); item != mResources.end(); ++ item)
276 for (VectorResource::iterator item = mRemovedResoures.begin(); item != mRemovedResoures.end(); ++ item)
278 mRemovedResoures.clear();
288 return mResources.size();