imagemanager.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_IMAGE_MANAGER_H
00023 #define FIFE_IMAGE_MANAGER_H
00024 
00025 // Standard C++ library includes
00026 #include <map>
00027 #include <string>
00028 #include <vector>
00029 
00030 // 3rd party library includes
00031 
00032 // FIFE includes
00033 // These includes are split up in two parts, separated by one empty line
00034 // First block: files included from the FIFE root src directory
00035 // Second block: files included from the same folder
00036 #include "util/base/singleton.h"
00037 #include "util/resource/resource.h"
00038 #include "util/resource/resourcemanager.h"
00039 
00040 #include "image.h"
00041 
00042 namespace FIFE {
00043 
00054     class ImageManager : public IResourceManager, public DynamicSingleton<ImageManager> {
00055     public:
00056 
00059         ImageManager() : IResourceManager() { }
00060 
00063         virtual ~ImageManager();
00064 
00065         virtual size_t getMemoryUsed() const;
00066         virtual size_t getTotalResourcesCreated() const;
00067         virtual size_t getTotalResourcesLoaded() const;
00068         virtual size_t getTotalResources() const;
00069 
00083         virtual ImagePtr create(IResourceLoader* loader = 0);
00084 
00099         virtual ImagePtr create(const std::string& name, IResourceLoader* loader = 0);
00100 
00119         virtual ImagePtr load(const std::string& name, IResourceLoader* loader = 0);
00120 
00127         virtual ImagePtr loadBlank(uint32_t width, uint32_t height);
00128 
00136         virtual ImagePtr loadBlank(const std::string& name, uint32_t width, uint32_t height);
00137 
00150         virtual ImagePtr add(Image* res);
00151 
00161         virtual bool exists(const std::string& name);
00162 
00172         virtual bool exists(ResourceHandle handle);
00173 
00184         virtual void reload(const std::string& name);
00185 
00196         virtual void reload(ResourceHandle handle);
00197 
00207         virtual void reloadAll();
00208 
00215         virtual void loadUnreferenced();
00216 
00230         virtual void free(const std::string& name);
00231 
00245         virtual void free(ResourceHandle handle);
00246 
00256         virtual void freeAll();
00257 
00267         virtual void freeUnreferenced();
00268 
00285         virtual void remove(ImagePtr& resource);
00286 
00299         virtual void remove(const std::string& name);
00300 
00313         virtual void remove(ResourceHandle handle);
00314 
00324         virtual void removeAll();
00325 
00334         virtual void removeUnreferenced();
00335 
00346         virtual ImagePtr get(const std::string& name);
00347 
00360         virtual ImagePtr get(ResourceHandle handle);
00361 
00362         virtual ImagePtr getPtr(const std::string& name);
00363         virtual ImagePtr getPtr(ResourceHandle handle);
00364 
00373         virtual ResourceHandle getResourceHandle(const std::string& name);
00374 
00375         virtual void invalidate(const std::string& name);
00376         virtual void invalidate(ResourceHandle handle);
00377         virtual void invalidateAll();
00378 
00379     private:
00380         typedef std::map< ResourceHandle, ImagePtr > ImageHandleMap;
00381         typedef std::map< ResourceHandle, ImagePtr >::iterator ImageHandleMapIterator;
00382         typedef std::map< ResourceHandle, ImagePtr >::const_iterator ImageHandleMapConstIterator;
00383         typedef std::pair< ResourceHandle, ImagePtr > ImageHandleMapPair;
00384 
00385         typedef std::map< std::string, ImagePtr > ImageNameMap;
00386         typedef std::map< std::string, ImagePtr >::iterator ImageNameMapIterator;
00387         typedef std::map< std::string, ImagePtr >::const_iterator ImageNameMapConstIterator;
00388         typedef std::pair< std::string, ImagePtr > ImageNameMapPair;
00389 
00390         ImageHandleMap m_imgHandleMap;
00391 
00392         ImageNameMap m_imgNameMap;
00393     };
00394 
00395 } //FIFE
00396 
00397 #endif //FIFE_IMAGE_MANAGER_H