Hey everyone, I'm trying to create a simple resource management system and I would look someone to look over this small snippet of code to make sure I coded this correctly, as it is my first time using boost::shared_ptr. I would also like to know when I would use SDL_FreeSurface() or how would I pass it to the shared pointer to do it for me in regards to resource management. I know I need to somehow make it so I can load any resource but for now I want to test everything using just SDL_Surface*. Thanks!
//In the ResourceController.h file, this private variable is declared
std::map<std::string, std::shared_ptr<SDL_Surface*>> textures;
//////////////////////////////////////////////////////////////////////////////////////////////////////
bool ResourceController::LoadResource(std::string filePath, std::string keyName)
{
SDL_Surface* temp = SDL_LoadBMP(filePath.c_str());
std::shared_ptr<SDL_Surface*> foo(&temp); //I think this is correct. I'm pointing to the address of the temp pointer which points to the resource in memory
if (temp)
{
textures.insert(std::make_pair(keyName, foo));
return true;
}
return false;
}
std::shared_ptr<SDL_Surface*> ResourceController::GetResource(std::string keyName)
{
return textures[keyName];
}
Edited by SonicD007, 11 March 2013 - 08:20 AM.






