#include "pvr.h"
#include <string>

/// <summary>
/// 
/// </summary>
PVR::cTextureRepository::cTextureRepository()
{
	for (int index = 0; index < 512; index++)
	{
		m_Textures[index] = nullptr;
	}
}

/// <summary>
/// 
/// </summary>
PVR::cTextureRepository::~cTextureRepository()
{
	Clear();
}

/// <summary>
/// 
/// </summary>
/*PVR::cTexture *PVR::cTextureRepository::Add(const string& index, PVR::cTexture* tex)
{
	m_mTaggedTextures.insert(TexPair(index, tex));
	tex->m_bIsLocked = true;
	return tex;	
}*/

/// <summary>
/// 
/// </summary>
PVR::cTexture *PVR::cTextureRepository::Add(uint16_t id, PVR::cTexture* tex)
{
	if (Get(id) != nullptr)
	{		
		Delete(id);
	}
	
	tex->m_szId = id;
	m_Textures[id] = tex;
	tex->m_bIsLocked = true;	
	// todo: unneccessary
	return tex;
}

/// <summary>
///
/// </summary>
void PVR::cTextureRepository::Clear()
{
	// todo: ????
}

/// <summary>
///
/// </summary>
/*void PVR::cTextureRepository::Delete(const string & index)
{
	cTexture *pTexture = Get(index);
	if (pTexture != nullptr)
	{
		m_mTaggedTextures.erase(index);
		delete pTexture;
	}	
}*/

/// <summary>
///
/// </summary>
PVR::cTexture* PVR::cTextureRepository::Get(uint16_t index)
{
	return m_Textures[index];	
}

/// <summary>
///
/// </summary>
/*PVR::cTexture* PVR::cTextureRepository::Get(const string & index)
{	
	//if (mTaggedTextures.at(index) != nullptr)	
	if (m_mTaggedTextures.find(index) != m_mTaggedTextures.end())
	{
		cTexture *text = m_mTaggedTextures.at(index);
		return text;
	}
	else {
		return nullptr;
	}	
}*/

/// <summary>
///
/// </summary>
void PVR::cTextureRepository::Delete(uint16_t index)
{
	cTexture *pTexture = Get(index);
	if (pTexture != nullptr)
	{				
		delete pTexture;
		m_Textures[index] = nullptr;
	}
}
