ManaPlus
resourcemanager.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef RESOURCES_RESOURCEMANAGER_RESOURCEMANAGER_H
25 #define RESOURCES_RESOURCEMANAGER_RESOURCEMANAGER_H
26 
28 
29 #if defined(DEBUG_DUMP_LEAKS) || defined(UNITTESTS)
31 
32 #include <set>
33 #endif // defined(DEBUG_DUMP_LEAKS) || defined(UNITTESTS)
34 
35 #include "localconsts.h"
36 
37 class Resource;
38 
39 struct SDL_Surface;
40 
41 namespace ResourceManager
42 {
47  void deleteResourceManager();
48 
58  Resource *get(const std::string &idPath,
59  generator fun,
60  const void *const data) A_WARN_UNUSED;
61 
62  Resource *getFromCache(const std::string &idPath) A_WARN_UNUSED;
63 
64  Resource *getFromCache(const std::string &filename,
65  const int variant) A_WARN_UNUSED;
66 
67  bool addResource(const std::string &idPath,
68  Resource *const resource);
69 
73  void release(Resource *const res);
74 
75  void clearDeleted(const bool full);
76 
77  void decRefDelete(Resource *const res);
78 
82  void moveToDeleted(Resource *const res);
83 
84  void scheduleDelete(SDL_Surface *const surface);
85 
86  void clearScheduled();
87 
91  void deleteInstance();
92 
94 
95 #if defined(DEBUG_DUMP_LEAKS) || defined(UNITTESTS)
96  Resources &getResources() A_WARN_UNUSED;
97 
98  Resources &getOrphanedResources() A_WARN_UNUSED;
99 
100  const std::set<Resource*> &getDeletedResources() A_WARN_UNUSED;
101 #endif // defined(DEBUG_DUMP_LEAKS) || defined(UNITTESTS)
102 
103  bool cleanOrphans(const bool always);
104 
105  void cleanProtected();
106 
107  bool isInCache(const std::string &idPath) A_WARN_UNUSED;
108 
109  Resource *getTempResource(const std::string &idPath) A_WARN_UNUSED;
110 
111  void clearCache();
112 
113  int calcMemoryLocal();
114 
115  int calcMemoryChilds(const int level);
116 
117  int calcMemory(const int level);
118 
119  void cleanUp(Resource *const resource);
120 
121  void logResource(const Resource *const res);
122 
123  void logResources(const std::string &msg);
124 } // namespace ResourceManager
125 
126 #endif // RESOURCES_RESOURCEMANAGER_RESOURCEMANAGER_H
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define noexcept2
Definition: localconsts.h:50
uint32_t data
bool msg(InputEvent &event)
Definition: chat.cpp:39
void deleteResourceManager()
Resource *(&) generator(const void *const data)
void release(Resource *const res)
void logResources(const std::string &msg)
void clearDeleted(const bool full)
bool isInCache(const std::string &idPath)
Resource * getFromCache(const std::string &filename, const int variant)
void decRefDelete(Resource *const res)
void scheduleDelete(SDL_Surface *const surface)
int calcMemory(const int level)
void logResource(const Resource *const res)
bool cleanOrphans(const bool always)
void moveToDeleted(Resource *const res)
std::map< std::string, Resource * > Resources
Definition: resourcetypes.h:36
int calcMemoryChilds(const int level)
Resource * get(const std::string &idPath, generator fun, const void *const data)
bool addResource(const std::string &idPath, Resource *const resource)
void cleanUp(Resource *const res)
Resource * getTempResource(const std::string &idPath)