MyGUI  3.2.1
MyGUI_ResourceManager.h
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #ifndef __MYGUI_RESOURCE_MANAGER_H__
00008 #define __MYGUI_RESOURCE_MANAGER_H__
00009 
00010 #include "MyGUI_Prerequest.h"
00011 #include "MyGUI_Singleton.h"
00012 #include "MyGUI_Enumerator.h"
00013 #include "MyGUI_XmlDocument.h"
00014 #include "MyGUI_IResource.h"
00015 #include "MyGUI_Delegate.h"
00016 #include "MyGUI_BackwardCompatibility.h"
00017 
00018 namespace MyGUI
00019 {
00020 
00021     class MYGUI_EXPORT ResourceManager :
00022         public Singleton<ResourceManager>,
00023         public MemberObsolete<ResourceManager>
00024     {
00025     public:
00026         ResourceManager();
00027 
00028         void initialise();
00029         void shutdown();
00030 
00031     public:
00033         bool load(const std::string& _file);
00034 
00035         void loadFromXmlNode(xml::ElementPtr _node, const std::string& _file, Version _version);
00036 
00038         void addResource(IResourcePtr _item);
00039 
00041         void removeResource(IResourcePtr _item);
00042 
00043         typedef delegates::CDelegate3<xml::ElementPtr, const std::string&, Version> LoadXmlDelegate;
00044 
00046         LoadXmlDelegate& registerLoadXmlDelegate(const std::string& _key);
00047 
00049         void unregisterLoadXmlDelegate(const std::string& _key);
00050 
00052         bool isExist(const std::string& _name) const;
00053 
00055         IResource* findByName(const std::string& _name) const;
00056 
00058         IResource* getByName(const std::string& _name, bool _throw = true) const;
00059 
00060         bool removeByName(const std::string& _name);
00061 
00062         void clear();
00063 
00064         typedef std::map<std::string, IResource*> MapResource;
00065         typedef Enumerator<MapResource> EnumeratorPtr;
00066 
00067         EnumeratorPtr getEnumerator() const;
00068 
00069         size_t getCount() const;
00070 
00071         const std::string& getCategoryName() const;
00072 
00073     private:
00074         void _loadList(xml::ElementPtr _node, const std::string& _file, Version _version);
00075         bool _loadImplement(const std::string& _file, bool _match, const std::string& _type, const std::string& _instance);
00076 
00077     private:
00078         // карта с делегатами для парсинга хмл блоков
00079         typedef std::map<std::string, LoadXmlDelegate> MapLoadXmlDelegate;
00080         MapLoadXmlDelegate mMapLoadXmlDelegate;
00081 
00082         MapResource mResources;
00083 
00084         typedef std::vector<IResource*> VectorResource;
00085         VectorResource mRemovedResoures;
00086 
00087         bool mIsInitialise;
00088         std::string mCategoryName;
00089         std::string mXmlListTagName;
00090     };
00091 
00092 } // namespace MyGUI
00093 
00094 #endif // __MYGUI_RESOURCE_MANAGER_H__