comparison engine/core/util/resource/pool.cpp @ 644:b84dbc4665b0

loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made! Fixed a small redundancy in the guimanager. Added clearResourceLoaders() to the Pool class. This can be used if different resourceloaders have to be added at a later point in time (running editor for example, a plugin might want to have it's own loader added)
author nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 11 Oct 2010 22:20:00 +0000
parents a46368b3d8a0
children
comparison
equal deleted inserted replaced
643:edf6dcfe8cd4 644:b84dbc4665b0
32 32
33 #include "pool.h" 33 #include "pool.h"
34 34
35 namespace FIFE { 35 namespace FIFE {
36 static Logger _log(LM_POOL); 36 static Logger _log(LM_POOL);
37 37
38 Pool::Pool(const std::string& name): 38 Pool::Pool(const std::string& name):
39 m_entries(), 39 m_entries(),
40 m_location_to_entry(), 40 m_location_to_entry(),
41 m_loaders(), 41 m_loaders(),
42 m_name(name) 42 m_name(name)
43 { 43 {
52 std::vector<ResourceLoader*>::iterator loader; 52 std::vector<ResourceLoader*>::iterator loader;
53 for (loader = m_loaders.begin(); loader != m_loaders.end(); loader++) { 53 for (loader = m_loaders.begin(); loader != m_loaders.end(); loader++) {
54 delete (*loader); 54 delete (*loader);
55 } 55 }
56 } 56 }
57 57
58 void Pool::reset() { 58 void Pool::reset() {
59 std::vector<PoolEntry*>::iterator entry; 59 std::vector<PoolEntry*>::iterator entry;
60 for (entry = m_entries.begin(); entry != m_entries.end(); entry++) { 60 for (entry = m_entries.begin(); entry != m_entries.end(); entry++) {
61 // Warn about leaks, but at least display ALL of them 61 // Warn about leaks, but at least display ALL of them
62 // Instead of bailing out with an exception in the FifeClass destructor. 62 // Instead of bailing out with an exception in the FifeClass destructor.
86 86
87 void Pool::addResourceLoader(ResourceLoader* loader) { 87 void Pool::addResourceLoader(ResourceLoader* loader) {
88 m_loaders.push_back(loader); 88 m_loaders.push_back(loader);
89 } 89 }
90 90
91 void Pool::clearResourceLoaders() {
92 m_loaders.clear();
93 }
94
91 int Pool::addResourceFromLocation(ResourceLocation* loc) { 95 int Pool::addResourceFromLocation(ResourceLocation* loc) {
92 ResourceLocationToEntry::const_iterator it = m_location_to_entry.find(loc); 96 ResourceLocationToEntry::const_iterator it = m_location_to_entry.find(loc);
93 if (it != m_location_to_entry.end()) { 97 if (it != m_location_to_entry.end()) {
94 return it->second; 98 return it->second;
95 } 99 }
96 100
97 PoolEntry* entry = new PoolEntry(); 101 PoolEntry* entry = new PoolEntry();
98 entry->location = loc->clone(); 102 entry->location = loc->clone();
99 m_entries.push_back(entry); 103 m_entries.push_back(entry);
100 size_t index = m_entries.size() - 1; 104 size_t index = m_entries.size() - 1;
101 m_location_to_entry[entry->location] = index; 105 m_location_to_entry[entry->location] = index;
126 if (!entry->loader) { 130 if (!entry->loader) {
127 LMsg msg("No suitable loader was found for resource "); 131 LMsg msg("No suitable loader was found for resource ");
128 msg << "#" << index << "<" << entry->location->getFilename() 132 msg << "#" << index << "<" << entry->location->getFilename()
129 << "> in pool " << m_name; 133 << "> in pool " << m_name;
130 FL_ERR(_log, msg); 134 FL_ERR(_log, msg);
131 135
132 throw NotFound(msg.str); 136 throw NotFound(msg.str);
133 } 137 }
134 138
135 // This branch will only be relevant if the resource has been 139 // This branch will only be relevant if the resource has been
136 // loaded successfully before, but for some reason the loader 140 // loaded successfully before, but for some reason the loader
222 } 226 }
223 227
224 void Pool::sanityCheck() { 228 void Pool::sanityCheck() {
225 // It is easy to mess up the important consistent 229 // It is easy to mess up the important consistent
226 // less-than operator for the location classes. 230 // less-than operator for the location classes.
227 // This will check if according to the '==' operator 231 // This will check if according to the '==' operator
228 // entries are duplicate (=memory leaks). 232 // entries are duplicate (=memory leaks).
229 // Slow and inaccurate. But should barf at real messups. 233 // Slow and inaccurate. But should barf at real messups.
230 for(unsigned i = 0; i != m_entries.size(); ++i) { 234 for(unsigned i = 0; i != m_entries.size(); ++i) {
231 int count = 0; 235 int count = 0;
232 for(unsigned j = i+1; j < m_entries.size(); ++j) { 236 for(unsigned j = i+1; j < m_entries.size(); ++j) {