#include "factory.h"

void CFactory::Init()
{

}

void CFactory::Register( std::string name, IManufacturer* manufacturer )
{
    //ManufacturerDictionary.insert( std::pair<std::string, IManufacturer*>(name, manufacturer));
    m_ManufacturerDictionary[name] = manufacturer;
}

IEntity* CFactory::Create ( std::string name )
{
    //check recycle bin first
    m_RecycleItor = m_RecycledEntityDictionary.find(name);
    if (m_RecycleItor != m_RecycledEntityDictionary.end())
    {
        IEntity* temp = m_RecycleItor->second;
        m_RecycledEntityDictionary.erase(m_RecycleItor);
        return temp;
    }

    //if not in recycle bin make new
    m_ManuItor = m_ManufacturerDictionary.find(name);
    if (m_ManuItor != NULL)
        return m_ManuItor->second->Create();


    return NULL;

}

void CFactory::Recycle(std::string name, IEntity* entity)
{
    delete entity->m_Sprite;
    m_RecycledEntityDictionary.insert( std::pair<std::string, IEntity*>(name, entity));
}
