summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--src/resources/resource.cpp6
-rw-r--r--src/resources/resource.h4
-rw-r--r--src/resources/resourcemanager.cpp27
-rw-r--r--src/resources/resourcemanager.h4
5 files changed, 27 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 7f2a81c1..bffc727f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,11 @@
-2006-01-39 Björn Steinbrink <B.Steinbrink@gmx.de>
+2006-01-31 Björn Steinbrink <B.Steinbrink@gmx.de>
+
+ * src/resources/resource.cpp, src/resources/resourcemanager.cpp,
+ src/resources/resource.h, src/resources/resourcemanager.h: Made
+ ResourceManager a friend of Resource to avoid looping over decRef,
+ which returns void now.
+
+2006-01-30 Björn Steinbrink <B.Steinbrink@gmx.de>
* src/gui/char_select.cpp, src/gui/confirm_dialog.cpp,
src/gui/confirm_dialog.h, src/gui/error.cpp, src/gui/error.h,
diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp
index 5c1df52d..bd8cd437 100644
--- a/src/resources/resource.cpp
+++ b/src/resources/resource.cpp
@@ -43,7 +43,7 @@ Resource::incRef()
mRefCount++;
}
-bool
+void
Resource::decRef()
{
// Reference may not already have reached zero
@@ -56,9 +56,5 @@ Resource::decRef()
ResourceManager *resman = ResourceManager::getInstance();
resman->release(mIdPath);
delete this;
- return true;
- }
- else {
- return false;
}
}
diff --git a/src/resources/resource.h b/src/resources/resource.h
index fe534606..d8b93e2d 100644
--- a/src/resources/resource.h
+++ b/src/resources/resource.h
@@ -31,6 +31,8 @@
*/
class Resource
{
+ friend class ResourceManager;
+
public:
/**
* Constructor
@@ -50,7 +52,7 @@ class Resource
* @return <code>true</code> if the object was deleted
* <code>false</code> otherwise.
*/
- bool
+ void
decRef();
/**
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index e2839416..09102d2e 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -45,19 +45,18 @@ ResourceManager::ResourceManager()
ResourceManager::~ResourceManager()
{
// Create our resource iterator.
- std::map<std::string, Resource*>::iterator iter = resources.begin();
+ ResourceIterator iter = mResources.begin();
// Iterate through and release references until objects are deleted.
- while (!resources.empty())
+ while (!mResources.empty())
{
- Resource *res = resources.begin()->second;
+ Resource *res = mResources.begin()->second;
std::string id = res->getIdPath();
int references = 0;
- do {
- references++;
- }
- while (!res->decRef());
+ references += res->mRefCount;
+ release(res->mIdPath);
+ delete res;
logger->log("ResourceManager::~ResourceManager() cleaned up %d "
"references to %s", references, id.c_str());
@@ -126,10 +125,9 @@ Resource*
ResourceManager::get(const E_RESOURCE_TYPE &type, const std::string &idPath)
{
// Check if the id exists, and return the value if it does.
- std::map<std::string, Resource*>::iterator resIter =
- resources.find(idPath);
+ ResourceIterator resIter = mResources.find(idPath);
- if (resIter != resources.end() && resIter->second) {
+ if (resIter != mResources.end() && resIter->second) {
resIter->second->incRef();
return resIter->second;
}
@@ -177,7 +175,7 @@ ResourceManager::get(const E_RESOURCE_TYPE &type, const std::string &idPath)
if (resource) {
resource->incRef();
- resources[idPath] = resource;
+ mResources[idPath] = resource;
}
// Return NULL if the object could not be created.
@@ -223,13 +221,12 @@ ResourceManager::release(const std::string &idPath)
{
logger->log("ResourceManager::release(%s)", idPath.c_str());
- std::map<std::string, Resource*>::iterator resIter =
- resources.find(idPath);
+ ResourceIterator resIter = mResources.find(idPath);
// The resource has to exist
- assert(resIter != resources.end() && resIter->second);
+ assert(resIter != mResources.end() && resIter->second);
- resources.erase(idPath);
+ mResources.erase(idPath);
}
ResourceManager*
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 6ebcd590..37fbe213 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -184,7 +184,9 @@ class ResourceManager
private:
static ResourceManager *instance;
- std::map<std::string, Resource*> resources;
+ typedef std::map<std::string, Resource*> Resources;
+ typedef Resources::iterator ResourceIterator;
+ Resources mResources;
};
#endif