• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_ResourceHolder.h

Go to the documentation of this file.
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 #ifndef __MYGUI_RESOURCE_HOLDER_H__
00024 #define __MYGUI_RESOURCE_HOLDER_H__
00025 
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Enumerator.h"
00028 
00029 namespace MyGUI
00030 {
00031 
00032     template <typename Type>
00033     class /*MYGUI_EXPORT */ResourceHolder
00034     {
00035     public:
00036         typedef std::map<std::string, Type*> MapResource;
00037         typedef Enumerator<MapResource> EnumeratorPtr;
00038 
00039     public:
00041         bool isExist(const std::string& _name)
00042         {
00043             return mResources.find(_name) != mResources.end();
00044         }
00045 
00047         Type* findByName(const std::string& _name)
00048         {
00049             typename MapResource::const_iterator item = mResources.find(_name);
00050             return (item == mResources.end()) ? nullptr : item->second;
00051         }
00052 
00054         Type* getByName(const std::string& _name, bool _throw = true)
00055         {
00056             Type* result = findByName(_name);
00057             MYGUI_ASSERT(result || !_throw, "Resource '" << _name << "' not found");
00058             return result;
00059         }
00060 
00061         bool remove(const std::string& _name)
00062         {
00063             typename MapResource::const_iterator item = mResources.find(_name);
00064             if (item != mResources.end())
00065             {
00066                 delete item->second;
00067                 mResources.erase(item->first);
00068                 return true;
00069             }
00070             return false;
00071         }
00072 
00073         void clear()
00074         {
00075             for (typename MapResource::iterator item=mResources.begin(); item!=mResources.end(); ++item)
00076             {
00077                 delete item->second;
00078             }
00079             mResources.clear();
00080         }
00081 
00082         EnumeratorPtr getEnumerator()
00083         {
00084             return EnumeratorPtr(mResources);
00085         }
00086 
00087         size_t getCount() { return mResources.size(); }
00088 
00089     protected:
00090         MapResource mResources;
00091     };
00092 
00093 } // namespace MyGUI
00094 
00095 #endif // __MYGUI_RESOURCE_HOLDER_H__

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1