6 #include "ISceneModelResourceProvider.h"
11 #define LOG_SCENEMODEL_RESOURCE_REPO_DEBUG_MESSAGES
13 #if defined (LOG_SCENEMODEL_RESOURCE_REPO_DEBUG_MESSAGES)
14 #define DEBUG_LOG Eegeo_TTY
16 #define DEBUG_LOG if (1) {} else Eegeo_TTY
25 template <
typename TResourceType,
typename TResourceInternalType>
31 ReleaseUnusedResources();
34 void Insert(
const std::string& name, TResourceInternalType* pMesh)
36 typename std::map<std::string, TResourceType*>::iterator value = m_resourceMap.find(name);
37 Eegeo_ASSERT(value == m_resourceMap.end(),
"Already have a mesh resource: %s", name.c_str());
38 if (value == m_resourceMap.end())
40 TResourceType* sceneMeshResoure = Eegeo_NEW(TResourceType)(name, pMesh);
41 m_resourceMap[name] = sceneMeshResoure;
45 TResourceType& UseResource(
const std::string& name)
47 typename std::map<std::string, TResourceType*>::iterator value = m_resourceMap.find(name);
48 Eegeo_ASSERT(value != m_resourceMap.end(),
"Cannot find resource: %s", name.c_str());
49 value->second->IncrementReferenceCount();
50 return *value->second;
53 bool HasResource(
const std::string& name)
const
55 typename std::map<std::string, TResourceType*>::const_iterator value = m_resourceMap.find(name);
56 return value != m_resourceMap.end();
59 void ReleaseUnusedResources()
61 std::vector<std::string> resourcesToErase;
62 for(
typename std::map<std::string, TResourceType*>::iterator it = m_resourceMap.begin(); it != m_resourceMap.end(); it++)
64 if (!it->second->IsReferenced())
66 Eegeo_DELETE it->second;
67 resourcesToErase.push_back(it->first);
71 for(std::vector<std::string>::iterator it = resourcesToErase.begin(); it != resourcesToErase.end(); ++it)
73 DEBUG_LOG(
"Deleting scene model resource: %s\n", (*it).c_str());
74 m_resourceMap.erase(*it);
81 std::map<std::string, TResourceType*> m_resourceMap;