#include "ResourceHandler.h"

ResourceHandler::ResourceHandler()
{
}

ResourceHandler::~ResourceHandler()
{
}

//adds or overwrites a resource.
void ResourceHandler::addResource (const string & key, const string & resourceName, int type)
{
  StringInt value;
  value.setString(resourceName);
  value.setInt(type);
  resources[key]=value;
}

//returns the name of the resource
void ResourceHandler::getResourceName (const string & key, string & answer)
{
  map <string, StringInt> :: iterator iter2;
  iter2 = resources.find (key);

  if (iter2 == resources.end())
    answer="NULL_INDEX";
  else
    answer=iter2->second.getString();
}

//returns the type of resource.
int ResourceHandler::getResourceType (const string & key)
{
  map <string, StringInt> :: iterator iter2;
  iter2 = resources.find (key);

  if (iter2 == resources.end())
    return RESOURCE_TYPE_UNKNOWN;
  else
    return iter2->second.getInt();
}

//removes the resouce key from the ResourceHandler.
//Returns true when completed.
//Returns false if this key does not exist.
//This does not unload the actual resource.
bool ResourceHandler::removeResource (const string & key)
{
  map <string, StringInt> :: iterator iter2;
  iter2 = resources.find (key);

  if (iter2==resources.end())
    return false;

  resources.erase(iter2);
  return true;
}
