summaryrefslogtreecommitdiff
path: root/src/resources/resourcemanager/resourcemanager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources/resourcemanager/resourcemanager.h')
-rw-r--r--src/resources/resourcemanager/resourcemanager.h155
1 files changed, 63 insertions, 92 deletions
diff --git a/src/resources/resourcemanager/resourcemanager.h b/src/resources/resourcemanager/resourcemanager.h
index 6fff83df0..f279b2b7c 100644
--- a/src/resources/resourcemanager/resourcemanager.h
+++ b/src/resources/resourcemanager/resourcemanager.h
@@ -23,8 +23,6 @@
#ifndef RESOURCES_RESOURCEMANAGER_RESOURCEMANAGER_H
#define RESOURCES_RESOURCEMANAGER_RESOURCEMANAGER_H
-#include "resources/memorycounter.h"
-
#include <map>
#include <set>
@@ -35,124 +33,97 @@ class Resource;
struct SDL_Surface;
struct SDL_RWops;
-/**
- * A class for loading and managing resources.
- */
-class ResourceManager final : public MemoryCounter
+namespace ResourceManager
{
- friend class Resource;
-
- public:
- typedef Resource *(*loader)(SDL_RWops *rw,
- const std::string &name);
- typedef Resource *(&generator)(const void *const data);
-
- ResourceManager();
-
- A_DELETE_COPY(ResourceManager)
-
- /**
- * Destructor. Cleans up remaining resources, warning about resources
- * that were still referenced.
- */
- ~ResourceManager();
+ typedef Resource *(*loader)(SDL_RWops *rw,
+ const std::string &name);
+ typedef Resource *(&generator)(const void *const data);
- /**
- * Creates a resource and adds it to the resource map.
- *
- * @param idPath The resource identifier path.
- * @param fun A function for generating the resource.
- * @param data Extra parameters for the generator.
- * @return A valid resource or <code>NULL</code> if the resource could
- * not be generated.
- */
- Resource *get(const std::string &idPath,
- generator fun,
- const void *const data) A_WARN_UNUSED;
+ typedef std::map<std::string, Resource*> Resources;
+ typedef Resources::iterator ResourceIterator;
+ typedef Resources::const_iterator ResourceCIterator;
- Resource *getFromCache(const std::string &idPath) A_WARN_UNUSED;
+ /**
+ * Cleans up remaining resources, warning about resources
+ * that were still referenced.
+ */
+ void deleteResourceManager();
- Resource *getFromCache(const std::string &filename,
- const int variant) A_WARN_UNUSED;
+ /**
+ * Creates a resource and adds it to the resource map.
+ *
+ * @param idPath The resource identifier path.
+ * @param fun A function for generating the resource.
+ * @param data Extra parameters for the generator.
+ * @return A valid resource or <code>NULL</code> if the resource could
+ * not be generated.
+ */
+ Resource *get(const std::string &idPath,
+ generator fun,
+ const void *const data) A_WARN_UNUSED;
- bool addResource(const std::string &idPath,
- Resource *const resource);
+ Resource *getFromCache(const std::string &idPath) A_WARN_UNUSED;
- /**
- * Releases a resource, placing it in the set of orphaned resources.
- */
- void release(Resource *const res);
+ Resource *getFromCache(const std::string &filename,
+ const int variant) A_WARN_UNUSED;
- void clearDeleted(const bool full = true);
+ bool addResource(const std::string &idPath,
+ Resource *const resource);
- void decRefDelete(Resource *const res);
+ /**
+ * Releases a resource, placing it in the set of orphaned resources.
+ */
+ void release(Resource *const res);
- /**
- * Move resource to deleted resources list.
- */
- void moveToDeleted(Resource *const res);
+ void clearDeleted(const bool full = true);
- void scheduleDelete(SDL_Surface *const surface);
+ void decRefDelete(Resource *const res);
- void clearScheduled();
+ /**
+ * Move resource to deleted resources list.
+ */
+ void moveToDeleted(Resource *const res);
- /**
- * Deletes the class instance if it exists.
- */
- static void deleteInstance();
+ void scheduleDelete(SDL_Surface *const surface);
- int size() const noexcept2 A_WARN_UNUSED
- { return CAST_S32(mResources.size()); }
+ void clearScheduled();
- typedef std::map<std::string, Resource*> Resources;
- typedef Resources::iterator ResourceIterator;
- typedef Resources::const_iterator ResourceCIterator;
+ /**
+ * Deletes the class instance if it exists.
+ */
+ void deleteInstance();
-#ifdef DEBUG_DUMP_LEAKS
- Resources* getResources() A_WARN_UNUSED
- { return &mResources; }
+ int size() noexcept2 A_WARN_UNUSED;
- Resources* getOrphanedResources() A_WARN_UNUSED
- { return &mOrphanedResources; }
-#endif // DEBUG_DUMP_LEAKS
+#if defined(DEBUG_DUMP_LEAKS) || defined(UNITTESTS)
+ Resources &getResources() A_WARN_UNUSED;
- bool cleanOrphans(const bool always = false);
+ Resources &getOrphanedResources() A_WARN_UNUSED;
- void cleanProtected();
+ const std::set<Resource*> &getDeletedResources() A_WARN_UNUSED;
+#endif // defined(DEBUG_DUMP_LEAKS) || defined(UNITTESTS)
- bool isInCache(const std::string &idPath) const A_WARN_UNUSED;
+ bool cleanOrphans(const bool always = false);
- Resource *getTempResource(const std::string &idPath) A_WARN_UNUSED;
+ void cleanProtected();
- void clearCache();
+ bool isInCache(const std::string &idPath) A_WARN_UNUSED;
- int calcMemoryLocal() const override final;
+ Resource *getTempResource(const std::string &idPath) A_WARN_UNUSED;
- int calcMemoryChilds(const int level) const override final;
+ void clearCache();
- std::string getCounterName() const override final
- { return "ResourceManager"; }
+ int calcMemoryLocal();
- static void init();
+ int calcMemoryChilds(const int level);
-#ifndef UNITTESTS
- private:
-#endif // UNITTESTS
- /**
- * Deletes the resource after logging a cleanup message.
- */
- static void cleanUp(Resource *const resource);
+ int calcMemory(const int level);
- static void logResource(const Resource *const res);
+ void cleanUp(Resource *const resource);
- std::set<SDL_Surface*> deletedSurfaces;
- Resources mResources;
- Resources mOrphanedResources;
- std::set<Resource*> mDeletedResources;
- time_t mOldestOrphan;
- bool mDestruction;
-};
+ void logResource(const Resource *const res);
-extern ResourceManager *resourceManager;
+ void logResources(const std::string &msg);
+} // namespace ResourceManager
#endif // RESOURCES_RESOURCEMANAGER_RESOURCEMANAGER_H