Switch remaining CMaps to std::map.

This commit is contained in:
Glenn Maynard
2002-09-07 08:20:10 +00:00
parent 5041ee2159
commit 2e3cde821b
4 changed files with 55 additions and 83 deletions
+22 -37
View File
@@ -32,19 +32,13 @@ FontManager::FontManager()
FontManager::~FontManager()
{
// delete all textures
POSITION pos = m_mapPathToFont.GetStartPosition();
CString sFontFilePath;
Font* pFont;
while( pos != NULL ) // iterate over all k/v pairs in map
for( std::map<CString, Font*>::iterator i = m_mapPathToFont.begin();
i != m_mapPathToFont.end(); ++i)
{
m_mapPathToFont.GetNextAssoc( pos, sFontFilePath, pFont );
LOG->Trace( "FONT LEAK: '%s', RefCount = %d.", sFontFilePath, pFont->m_iRefCount );
Font* pFont = i->second;
LOG->Trace( "FONT LEAK: '%s', RefCount = %d.", i->first, pFont->m_iRefCount );
SAFE_DELETE( pFont );
}
m_mapPathToFont.RemoveAll();
}
@@ -65,9 +59,10 @@ Font* FontManager::LoadFont( CString sFontOrTextureFilePath, CString sChars )
Font* pFont = NULL;
if( m_mapPathToFont.Lookup( sFontOrTextureFilePath, pFont ) ) // if the texture already exists in the map
{
std::map<CString, Font*>::iterator p = m_mapPathToFont.find(sFontOrTextureFilePath);
if(p != m_mapPathToFont.end()) {
// LOG->Trace( ssprintf("FontManager: The Font '%s' now has %d references.", sFontFilePath, pFont->m_iRefCount) );
pFont=p->second;
pFont->m_iRefCount++;
}
else // the texture is not already loaded
@@ -82,7 +77,7 @@ Font* FontManager::LoadFont( CString sFontOrTextureFilePath, CString sChars )
// LOG->Trace( "FontManager: Loading '%s' from disk.", sFontFilePath);
m_mapPathToFont.SetAt( sFontOrTextureFilePath, pFont );
m_mapPathToFont[sFontOrTextureFilePath] = pFont;
}
return pFont;
@@ -93,12 +88,7 @@ bool FontManager::IsFontLoaded( CString sFontFilePath )
{
sFontFilePath.MakeLower();
Font* pFont;
if( m_mapPathToFont.Lookup( sFontFilePath, pFont ) ) // if the texture exists in the map
return true;
else
return false;
return m_mapPathToFont.find(sFontFilePath) != m_mapPathToFont.end();
}
void FontManager::UnloadFont( CString sFontFilePath )
@@ -114,25 +104,20 @@ void FontManager::UnloadFont( CString sFontFilePath )
}
Font* pFont;
if( m_mapPathToFont.Lookup( sFontFilePath, pFont ) ) // if the texture exists in the map
{
pFont->m_iRefCount--;
if( pFont->m_iRefCount == 0 ) // there are no more references to this texture
{
// LOG->Trace( "FontManager: '%s' will be deleted. It has %d references.", sFontFilePath, pFont->m_iRefCount );
SAFE_DELETE( pFont ); // free the texture
m_mapPathToFont.RemoveKey( sFontFilePath ); // and remove the key in the map
}
else
{
// LOG->Trace( ssprintf("FontManager: '%s' will not be deleted. It still has %d references.", sFontFilePath, pFont->m_iRefCount) );
}
}
else // lookup failed
{
std::map<CString, Font*>::iterator p = m_mapPathToFont.find(sFontFilePath);
if(p == m_mapPathToFont.end())
throw RageException( ssprintf("Tried to Unload a font that wasn't loaded. '%s'", sFontFilePath) );
pFont=p->second;
pFont->m_iRefCount--;
if( pFont->m_iRefCount != 0 )
{
// LOG->Trace( ssprintf("FontManager: '%s' will not be deleted. It still has %d references.", sFontFilePath, pFont->m_iRefCount) );
return;
}
// There are no more references to this texture.
// LOG->Trace( "FontManager: '%s' will be deleted. It has %d references.", sFontFilePath, pFont->m_iRefCount );
SAFE_DELETE( pFont ); // free the texture
m_mapPathToFont.erase( p ); // and remove the key in the map
}