FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
imagemanager.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_IMAGE_MANAGER_H
23 #define FIFE_IMAGE_MANAGER_H
24 
25 // Standard C++ library includes
26 #include <map>
27 #include <string>
28 #include <vector>
29 
30 // 3rd party library includes
31 
32 // FIFE includes
33 // These includes are split up in two parts, separated by one empty line
34 // First block: files included from the FIFE root src directory
35 // Second block: files included from the same folder
36 #include "util/base/singleton.h"
37 #include "util/resource/resource.h"
39 
40 #include "image.h"
41 
42 namespace FIFE {
43 
54  class ImageManager : public IResourceManager, public DynamicSingleton<ImageManager> {
55  public:
56 
60 
63  virtual ~ImageManager();
64 
65  virtual size_t getMemoryUsed() const;
66  virtual size_t getTotalResourcesCreated() const;
67  virtual size_t getTotalResourcesLoaded() const;
68  virtual size_t getTotalResources() const;
69 
83  virtual ImagePtr create(IResourceLoader* loader = 0);
84 
99  virtual ImagePtr create(const std::string& name, IResourceLoader* loader = 0);
100 
119  virtual ImagePtr load(const std::string& name, IResourceLoader* loader = 0);
120 
127  virtual ImagePtr loadBlank(uint32_t width, uint32_t height);
128 
136  virtual ImagePtr loadBlank(const std::string& name, uint32_t width, uint32_t height);
137 
150  virtual ImagePtr add(Image* res);
151 
161  virtual bool exists(const std::string& name);
162 
172  virtual bool exists(ResourceHandle handle);
173 
184  virtual void reload(const std::string& name);
185 
196  virtual void reload(ResourceHandle handle);
197 
207  virtual void reloadAll();
208 
215  virtual void loadUnreferenced();
216 
230  virtual void free(const std::string& name);
231 
245  virtual void free(ResourceHandle handle);
246 
256  virtual void freeAll();
257 
267  virtual void freeUnreferenced();
268 
285  virtual void remove(ImagePtr& resource);
286 
299  virtual void remove(const std::string& name);
300 
313  virtual void remove(ResourceHandle handle);
314 
324  virtual void removeAll();
325 
334  virtual void removeUnreferenced();
335 
346  virtual ImagePtr get(const std::string& name);
347 
360  virtual ImagePtr get(ResourceHandle handle);
361 
362  virtual ImagePtr getPtr(const std::string& name);
363  virtual ImagePtr getPtr(ResourceHandle handle);
364 
373  virtual ResourceHandle getResourceHandle(const std::string& name);
374 
375  virtual void invalidate(const std::string& name);
376  virtual void invalidate(ResourceHandle handle);
377  virtual void invalidateAll();
378 
379  private:
380  typedef std::map< ResourceHandle, ImagePtr > ImageHandleMap;
381  typedef std::map< ResourceHandle, ImagePtr >::iterator ImageHandleMapIterator;
382  typedef std::map< ResourceHandle, ImagePtr >::const_iterator ImageHandleMapConstIterator;
383  typedef std::pair< ResourceHandle, ImagePtr > ImageHandleMapPair;
384 
385  typedef std::map< std::string, ImagePtr > ImageNameMap;
386  typedef std::map< std::string, ImagePtr >::iterator ImageNameMapIterator;
387  typedef std::map< std::string, ImagePtr >::const_iterator ImageNameMapConstIterator;
388  typedef std::pair< std::string, ImagePtr > ImageNameMapPair;
389 
390  ImageHandleMap m_imgHandleMap;
391 
392  ImageNameMap m_imgNameMap;
393  };
394 
395 } //FIFE
396 
397 #endif //FIFE_IMAGE_MANAGER_H
virtual ImagePtr create(IResourceLoader *loader=0)
Creates a blank Image but does not load it immediately.
virtual ImagePtr loadBlank(uint32_t width, uint32_t height)
Loads a blank resource.
virtual bool exists(const std::string &name)
Checks to see if an Image exists.
ImageManager.
Definition: imagemanager.h:54
Base Class for Images.
Definition: image.h:48
std::pair< ResourceHandle, ImagePtr > ImageHandleMapPair
Definition: imagemanager.h:383
virtual ~ImageManager()
Destructor.
virtual size_t getTotalResourcesLoaded() const
Returns the number of loaded resources.
virtual void removeAll()
Removes all Images from the manager.
virtual size_t getMemoryUsed() const
Gets the total amount of memory used by resources.
virtual void reloadAll()
Reloads all Images.
std::size_t ResourceHandle
Definition: resource.h:38
virtual size_t getTotalResourcesCreated() const
Returns the number of unloaded resources.
std::map< ResourceHandle, ImagePtr > ImageHandleMap
Definition: imagemanager.h:380
virtual ImagePtr getPtr(const std::string &name)
virtual void removeUnreferenced()
Removes all unreferenced Images.
virtual void freeUnreferenced()
Frees all unreferenced Image.
std::map< std::string, ImagePtr >::const_iterator ImageNameMapConstIterator
Definition: imagemanager.h:387
Another Singleton.
Definition: singleton.h:82
std::map< ResourceHandle, ImagePtr >::iterator ImageHandleMapIterator
Definition: imagemanager.h:381
virtual void loadUnreferenced()
Loads all unreferenced Images.
ImageHandleMap m_imgHandleMap
Definition: imagemanager.h:390
virtual void invalidateAll()
std::map< std::string, ImagePtr >::iterator ImageNameMapIterator
Definition: imagemanager.h:386
virtual ResourceHandle getResourceHandle(const std::string &name)
Gets an Image handle by name.
virtual void free(const std::string &name)
Frees an Image from memory.
virtual void reload(const std::string &name)
Reloads an Image.
virtual void invalidate(const std::string &name)
virtual size_t getTotalResources() const
Returns the number of defined resources.
std::map< ResourceHandle, ImagePtr >::const_iterator ImageHandleMapConstIterator
Definition: imagemanager.h:382
unsigned int uint32_t
Definition: core.h:40
std::map< std::string, ImagePtr > ImageNameMap
Definition: imagemanager.h:385
ImageNameMap m_imgNameMap
Definition: imagemanager.h:392
virtual void freeAll()
Frees all Images.
std::pair< std::string, ImagePtr > ImageNameMapPair
Definition: imagemanager.h:388
virtual ImagePtr add(Image *res)
Add an Image to the manager.
virtual ImagePtr load(const std::string &name, IResourceLoader *loader=0)
Creates a blank resource and loads it from disk.
ImageManager()
Default constructor.
Definition: imagemanager.h:59
IResourceManager.