MyGUI 3.5.3
MyGUI_ResourceManager.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_RESOURCE_MANAGER_H_
8#define MYGUI_RESOURCE_MANAGER_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Singleton.h"
12#include "MyGUI_EventPair.h"
13#include "MyGUI_XmlDocument.h"
14#include "MyGUI_IResource.h"
15#include "MyGUI_Delegate.h"
17
18namespace MyGUI
19{
20
21 class MYGUI_EXPORT ResourceManager : public MemberObsolete<ResourceManager>
22 {
23 MYGUI_SINGLETON_DECLARATION(ResourceManager);
24
25 public:
26 ResourceManager();
27
28 void initialise();
29 void shutdown();
30
31 public:
33 bool load(const std::string& _file);
34
35 void loadFromXmlNode(xml::ElementPtr _node, std::string_view _file, Version _version);
36
38 void addResource(IResourcePtr _item);
39
41 void removeResource(IResourcePtr _item);
42
43 using LoadXmlDelegate = EventPairConvertStringView<
44 delegates::Delegate<xml::ElementPtr, const std::string&, Version>,
45 delegates::Delegate<xml::ElementPtr, std::string_view, Version>>;
46
48 LoadXmlDelegate& registerLoadXmlDelegate(std::string_view _key);
49
51 void unregisterLoadXmlDelegate(std::string_view _key);
52
54 bool isExist(std::string_view _name) const;
55
57 IResource* findByName(std::string_view _name) const;
58
60 IResource* getByName(std::string_view _name, bool _throw = true) const;
61
62 bool removeByName(std::string_view _name);
63
64 void clear();
65
66 using MapResource = std::map<std::string, IResource*, std::less<>>;
67
68 const MapResource& getResources() const;
69
70 size_t getCount() const;
71
72 const std::string& getCategoryName() const;
73
74 private:
75 void _loadList(xml::ElementPtr _node, std::string_view _file, Version _version);
76 bool _loadImplement(const std::string& _file, bool _match, std::string_view _type, std::string_view _instance);
77
78 private:
79 // Map of delegates for parsing XML blocks
80 using MapLoadXmlDelegate = std::map<std::string, LoadXmlDelegate, std::less<>>;
81 MapLoadXmlDelegate mMapLoadXmlDelegate;
82
83 MapResource mResources;
84
85 using VectorResource = std::vector<IResource*>;
86 VectorResource mRemovedResources;
87
88 bool mIsInitialise{false};
89 std::string mCategoryName;
90 std::string mXmlListTagName;
91 };
92
93} // namespace MyGUI
94
95#endif // MYGUI_RESOURCE_MANAGER_H_
#define MYGUI_EXPORT
#define MYGUI_SINGLETON_DECLARATION(ClassName)