#include "support/LAssert.h"
-GraphicsCache * GraphicsCache::singleton = 0;
-
-
-GraphicsCache *
+GraphicsCache &
GraphicsCache::getInstance()
{
- if (!singleton) {
- singleton = new GraphicsCache;
- Assert(singleton != 0);
- }
-
+ static GraphicsCache singleton;
return singleton;
}
GraphicsCache::~GraphicsCache()
{
- // The map elements should have already been eliminated.
- Assert(cache.empty());
-
- delete singleton;
+ // All elements are destroyed by the shared_ptr's in the map.
}
CacheType::iterator it = cache.find(filename);
if (it != cache.end()) {
- return (*it).second;
+ return it->second;
}
shared_ptr_item cacheItem(new GraphicsCacheItem(filename));