22 mCategoryName(
"Resource"),
23 mXmlListTagName(
"List"),
24 mSingletonHolder(this)
54 mMapLoadXmlDelegate.clear();
57 mIsInitialise =
false;
71 while (root.
next(mCategoryName))
83 if (
object ==
nullptr)
85 MYGUI_LOG(Error,
"resource type '" << type <<
"' not found");
89 MapResource::iterator item = mResources.find(name);
90 if (item != mResources.end())
92 MYGUI_LOG(Warning,
"duplicate resource name '" << name <<
"'");
95 mRemovedResources.push_back((*item).second);
96 mResources.erase(item);
102 mResources[name] = resource;
110 while (node.
next(mXmlListTagName))
115 MYGUI_LOG(Info,
"Load ini file '" << source <<
"'");
122 MapLoadXmlDelegate::iterator iter = mMapLoadXmlDelegate.find(_key);
123 MYGUI_ASSERT(iter == mMapLoadXmlDelegate.end(),
"name delegate is exist");
124 return mMapLoadXmlDelegate.emplace(_key,
LoadXmlDelegate()).first->second;
129 MapLoadXmlDelegate::iterator iter = mMapLoadXmlDelegate.find(_key);
130 if (iter != mMapLoadXmlDelegate.end())
131 mMapLoadXmlDelegate.erase(iter);
134 bool ResourceManager::_loadImplement(
135 const std::string& _file,
137 std::string_view _type,
138 std::string_view _instance)
143 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', not found");
150 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', " << doc.getLastError());
155 if ((
nullptr == root) || (root->getName() !=
"MyGUI"))
157 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', tag 'MyGUI' not found");
162 if (root->findAttribute(
"type", type))
165 MapLoadXmlDelegate::iterator iter = mMapLoadXmlDelegate.find(type);
166 if (iter != mMapLoadXmlDelegate.end())
168 if ((!_match) || (type == _type))
169 (*iter).second(root, _file, version);
172 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', type '" << _type <<
"' not found");
178 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', delegate for type '" << type <<
"'not found");
186 while (node.next(
"MyGUI"))
188 if (node->findAttribute(
"type", type))
191 MapLoadXmlDelegate::iterator iter = mMapLoadXmlDelegate.find(type);
192 if (iter != mMapLoadXmlDelegate.end())
194 (*iter).second(node.current(), _file, version);
200 _instance <<
" : '" << _file <<
"', delegate for type '" << type <<
"'not found");
205 MYGUI_LOG(Error, _instance <<
" : '" << _file <<
"', tag 'type' not found");
221 if (_item ==
nullptr)
226 MapResource::iterator item = mResources.find(_item->
getResourceName());
227 if (item != mResources.end())
228 mResources.erase(item);
234 return mResources.find(_name) != mResources.end();
239 MapResource::const_iterator item = mResources.find(_name);
240 return (item == mResources.end()) ? nullptr : item->second;
246 MYGUI_ASSERT(result || !_throw,
"Resource '" << _name <<
"' not found");
252 MapResource::const_iterator item = mResources.find(_name);
253 if (item != mResources.end())
256 mResources.erase(item->first);
264 for (
auto& resource : mResources)
265 delete resource.second;
268 for (
auto& removedResource : mRemovedResources)
269 delete removedResource;
270 mRemovedResources.clear();
280 return mResources.size();
285 return mCategoryName;
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
#define MYGUI_SINGLETON_DEFINITION(ClassName)
virtual IDataStream * getData(const std::string &_name) const =0
static DataManager & getInstance()
void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate *_delegate)
static FactoryManager & getInstance()
void unregisterFactory(std::string_view _category, std::string_view _type)
IObject * createObject(std::string_view _category, std::string_view _type)
Type * castType(bool _throw=true)
void deserialization(xml::ElementPtr _node, Version) override
const std::string & getResourceName() const
void unregisterLoadXmlDelegate(std::string_view _key)
const std::string & getCategoryName() const
bool isExist(std::string_view _name) const
void removeResource(IResourcePtr _item)
LoadXmlDelegate & registerLoadXmlDelegate(std::string_view _key)
void loadFromXmlNode(xml::ElementPtr _node, std::string_view _file, Version _version)
IResource * getByName(std::string_view _name, bool _throw=true) const
static std::string_view getClassTypeName()
EnumeratorPtr getEnumerator() const
Enumerator< MapResource > EnumeratorPtr
bool load(const std::string &_file)
IResource * findByName(std::string_view _name) const
bool removeByName(std::string_view _name)
EventPairConvertStringView< delegates::Delegate< xml::ElementPtr, const std::string &, Version >, delegates::Delegate< xml::ElementPtr, std::string_view, Version > > LoadXmlDelegate
void addResource(IResourcePtr _item)
static Version parse(std::string_view _value)
bool findAttribute(std::string_view _name, std::string &_value)
ElementEnumerator getElementEnumerator()
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))