Mercurial > fife-parpg
annotate engine/core/util/resource/pool.cpp @ 147:fb6ccb367dd1
Added just some docs and a sanityCheck against the
difficult to find bugs of the location classes.
So if memory usage/load time goes through the
roof, try logging 'pool' messages.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 09 Oct 2008 13:36:13 +0000 |
parents | 54b3984e1afc |
children | 72c25cc27d8b |
rev | line source |
---|---|
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 /*************************************************************************** |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 * Copyright (C) 2005-2008 by the FIFE team * |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 * http://www.fifengine.de * |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 * This file is part of FIFE. * |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 * * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
6 * FIFE is free software; you can redistribute it and/or * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
8 * License as published by the Free Software Foundation; either * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 * * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
11 * This library is distributed in the hope that it will be useful, * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
14 * Lesser General Public License for more details. * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 * * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
17 * License along with this library; if not, write to the * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 * Free Software Foundation, Inc., * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 ***************************************************************************/ |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 // Standard C++ library includes |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 // 3rd party library includes |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 // FIFE includes |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 // These includes are split up in two parts, separated by one empty line |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 // First block: files included from the FIFE root src directory |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 // Second block: files included from the same folder |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 #include "util/base/exception.h" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 #include "util/log/logger.h" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 #include "pool.h" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 namespace FIFE { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 static Logger _log(LM_POOL); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
38 Pool::Pool(const std::string& name): |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 m_entries(), |
100
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
40 m_location_to_entry(), |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 m_listeners(), |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 m_loaders(), |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
43 m_curind(0), |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
44 m_name(name) |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 Pool::~Pool() { |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
49 FL_LOG(_log, LMsg("Pool destroyed: ") << m_name); |
144
d2f1e81fbe2c
* Fixed a scons issue, where libraries checked for C instead of C++
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
100
diff
changeset
|
50 printStatistics(); |
147
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
51 sanityCheck(); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 clear(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 std::vector<ResourceLoader*>::iterator loader; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 for (loader = m_loaders.begin(); loader != m_loaders.end(); loader++) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 delete (*loader); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 void Pool::clear() { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 std::vector<IPoolListener*>::iterator listener; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 for (listener = m_listeners.begin(); listener != m_listeners.end(); listener++) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 (*listener)->poolCleared(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 std::vector<PoolEntry*>::iterator entry; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 for (entry = m_entries.begin(); entry != m_entries.end(); entry++) { |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
66 // Warn about leaks, but at least display ALL of them |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
67 // Instead of bailing out with an exception in the FifeClass destructor. |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
68 if( (*entry)->resource && (*entry)->resource->getRefCount() > 0 ) { |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
69 FL_WARN(_log, LMsg(m_name + " leak: ") << (*entry)->location->getFilename()); |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
70 (*entry)->resource = 0; |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
71 } |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 delete (*entry); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 m_entries.clear(); |
100
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
75 m_location_to_entry.clear(); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 void Pool::addResourceLoader(ResourceLoader* loader) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 m_loaders.push_back(loader); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 int Pool::addResourceFromLocation(const ResourceLocation& loc) { |
100
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
83 ResourceLocationToEntry::const_iterator it = m_location_to_entry.find(loc); |
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
84 if (it != m_location_to_entry.end()) { |
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
85 return (*it).second; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 PoolEntry* entry = new PoolEntry(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 entry->location = loc.clone(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 m_entries.push_back(entry); |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
91 size_t index = m_entries.size() - 1; |
100
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
92 m_location_to_entry[loc] = index; |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
93 return index; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
95 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 int Pool::addResourceFromFile(const std::string& filename) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 return addResourceFromLocation(ResourceLocation(filename)); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 IResource& Pool::get(unsigned int index, bool inc) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 if (index >= m_entries.size()) { |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
102 FL_ERR(_log, LMsg("Tried to get with index ") << index << ", only " << m_entries.size() << " items in pool " + m_name); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 throw IndexOverflow( __FUNCTION__ ); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 IResource* res = NULL; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 PoolEntry* entry = m_entries[index]; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 if (entry->resource) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 res = entry->resource; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
109 } else { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 if (!entry->loader) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 findAndSetProvider(*entry); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 } else { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
113 entry->resource = entry->loader->loadResource(*entry->location); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
114 } |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
115 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
116 if (!entry->loader) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 LMsg msg("No suitable loader was found for resource "); |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
118 msg << "#" << index << "<" << entry->location->getFilename() |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
119 << "> in pool " << m_name; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
120 FL_ERR(_log, msg); |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
121 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 throw NotFound(msg.str); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
123 } |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
124 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
125 if (!entry->resource) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
126 LMsg msg("No loader was able to load the requested resource "); |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
127 msg << "#" << index << "<" << entry->location->getFilename() |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
128 << "> in pool " << m_name; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
129 FL_ERR(_log, msg); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
130 throw NotFound(msg.str); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
131 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
132 res = entry->resource; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
133 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
134 if (inc) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
135 res->addRef(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
136 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
137 res->setPoolId(index); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
138 return *res; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
139 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
140 |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
141 int Pool::getIndex(const std::string& filename) { |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
142 // create resource |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
143 return addResourceFromFile(filename); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
144 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
145 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
146 void Pool::release(unsigned int index, bool dec) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
147 if (index >= m_entries.size()) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
148 throw IndexOverflow( __FUNCTION__ ); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
149 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
150 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
151 IResource* res = NULL; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
152 PoolEntry* entry = m_entries[index]; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
153 if (entry->resource) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
154 res = entry->resource; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
155 if (dec) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
156 res->decRef(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
157 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
158 if(res->getRefCount() == 0) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
159 delete entry->resource; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
160 entry->resource = 0; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
161 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
162 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
163 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
165 int Pool::getResourceCount(int status) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
166 int amount = 0; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
167 std::vector<PoolEntry*>::iterator entry; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 for (entry = m_entries.begin(); entry != m_entries.end(); entry++) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 if (status & RES_LOADED) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 if ((*entry)->resource) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
171 amount++; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
172 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
173 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
174 if (status & RES_NON_LOADED) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
175 if (!(*entry)->resource) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
176 amount++; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
177 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
178 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
179 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
180 return amount; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
181 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
182 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
183 void Pool::addPoolListener(IPoolListener* listener) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
184 m_listeners.push_back(listener); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
185 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
186 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
187 void Pool::removePoolListener(IPoolListener* listener) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
188 std::vector<IPoolListener*>::iterator i = m_listeners.begin(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
189 while (i != m_listeners.end()) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
190 if ((*i) == listener) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
191 m_listeners.erase(i); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
192 return; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
193 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
194 ++i; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
195 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
196 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
197 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
198 void Pool::findAndSetProvider(PoolEntry& entry) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
199 std::vector<ResourceLoader*>::iterator it = m_loaders.begin(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
200 std::vector<ResourceLoader*>::iterator end = m_loaders.end(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
201 if( it == end ) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
202 FL_PANIC(_log, "no loader constructors given for resource pool"); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
203 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
204 for(; it != end; ++it) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
205 IResource* res = (*it)->loadResource(*entry.location); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
206 if (res) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
207 entry.resource = res; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
208 entry.loader = *it; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
209 return; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
210 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
211 }; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
212 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
213 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
214 void Pool::printStatistics() { |
144
d2f1e81fbe2c
* Fixed a scons issue, where libraries checked for C instead of C++
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
100
diff
changeset
|
215 FL_LOG(_log, LMsg("Pool not loaded =") << getResourceCount(RES_NON_LOADED)); |
d2f1e81fbe2c
* Fixed a scons issue, where libraries checked for C instead of C++
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
100
diff
changeset
|
216 FL_LOG(_log, LMsg("Pool loaded =") << getResourceCount(RES_LOADED)); |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
217 int amount = 0; |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
218 std::vector<PoolEntry*>::iterator entry; |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
219 for (entry = m_entries.begin(); entry != m_entries.end(); entry++) { |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
220 if ((*entry)->resource) { |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
221 if ((*entry)->resource->getRefCount() > 0) { |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
222 amount++; |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
223 } |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
224 } |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
225 } |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
226 FL_LOG(_log, LMsg("Pool locked =") << amount); |
144
d2f1e81fbe2c
* Fixed a scons issue, where libraries checked for C instead of C++
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
100
diff
changeset
|
227 FL_LOG(_log, LMsg("Pool total size =") << m_entries.size()); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
228 } |
147
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
229 |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
230 void Pool::sanityCheck() { |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
231 // It is easy to mess up the important consistent |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
232 // less-than operator for the location classes. |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
233 // This will check if according to the '==' operator |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
234 // entries are duplicate (=memory leaks). |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
235 // Slow and inaccurate. But should barf at real messups. |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
236 for(unsigned i = 0; i != m_entries.size(); ++i) { |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
237 int count = 0; |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
238 for(unsigned j = i+1; j < m_entries.size(); ++j) { |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
239 if( *m_entries[i]->location == *m_entries[j]->location ) |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
240 count ++; |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
241 } |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
242 if( 0 == count ) |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
243 continue; |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
244 FL_WARN(_log, LMsg("Multiple entries: ") << m_entries[i]->location->getFilename() |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
245 << " #entries = " << (count+1) ); |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
246 } |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
247 } |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
248 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
249 } |