ResourceManager.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   ResourceManager.cpp
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006 
00007    @brief
00008       Static resource manager synchronized across all Milton threads, 
00009    containing references to loaded images, global logging utilities, and 
00010    user-definable options which may be used to affect Milton functionality.
00011    Many user-definable options that are supported are aimed at dynamic, 
00012    on-the-fly debugging changes (whether or not to preview kd-Trees built 
00013    from Meshes, for instance)
00014    <!-------------------------------------------------------------------->**/
00015 
00016 #include "ResourceManager.h"
00017 #include <SharedLibraryManager.h>
00018 #include <SharedLibraryPlatform.h>
00019 #include <QtCore>
00020 
00021 // initialize static members of ResourceManager
00022 Log ResourceManager::log;
00023 
00024 ImagePtrMap             ResourceManager::s_imagePtrMap;
00025 ThreadLocalStorage      ResourceManager::s_threadLocalStorage;
00026 PropertyMap             ResourceManager::s_propertyMap;
00027 QMutex                  ResourceManager::s_mutex;
00028 SharedLibraryPlatform  *ResourceManager::s_sharedLibraryPlatform = 
00029    new SharedLibraryPlatformPosix();
00030 SharedLibraryManager   *ResourceManager::manager = 
00031    new SharedLibraryManager(ResourceManager::s_sharedLibraryPlatform);
00032 
00033 
00034 void ResourceManager::cleanup() {
00035    QMutexLocker lock(&s_mutex);
00036    
00037    std::vector<std::string> toRemove;
00038    
00039    FOREACH(ImagePtrMapIter, s_imagePtrMap, iter) {
00040       if (iter->second.use_count() <= 1)
00041          toRemove.push_back(iter->first);
00042    }
00043    
00044    FOREACH(std::vector<std::string>::iterator, toRemove, iter) {
00045       s_imagePtrMap.erase(*iter);
00046    }
00047    
00048    // note s_threadLocalStorage takes care of itself as QThreadStorage takes 
00049    // ownership of all thread-specific data
00050 }
00051 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6