I'm a little confused at the usage of a shared_ptr.. this code works but i'm not sure if a) it's safe or b) it's correct
Decleration:
std::map<const std::string, std::shared_ptr<ALLEGRO_BITMAP>> BitmapList;
Code:
const std::shared_ptr<ALLEGRO_BITMAP> BitmapManager::AddBitmap(const std::string filePath)
{
std::string fullPath = "Assets/Images/";
fullPath += filePath.c_str();
BitmapList[filePath] = std::shared_ptr<ALLEGRO_BITMAP>(al_load_bitmap(fullPath.c_str()));
if(BitmapList[filePath] != nullptr)
return BitmapList[filePath];
else
return nullptr;
}
Usage:
std::shared_ptr<ALLEGRO_BITMAP> b = Bitmap->AddBitmap("test.bmp")
al_draw_bitmap(b.get(), 30, 30, 0)
and when compiling in MSVC++ 10 I get these build warnings:
1>c:\program files\microsoft visual studio 10.0\vc\include\memory(1664): warning C4150: deletion of pointer to incomplete type 'ALLEGRO_BITMAP'; no destructor called
1> c:\allegro\include\allegro5\mouse.h(99) : see declaration of 'ALLEGRO_BITMAP'
1> c:\program files\microsoft visual studio 10.0\vc\include\memory(1448) : see reference to function template instantiation 'void std::tr1::shared_ptr<_Ty>::_Resetp<_Ty>(_Ux *)' being compiled
1> with
1> [
1> _Ty=ALLEGRO_BITMAP,
1> _Ux=ALLEGRO_BITMAP
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\memory(1446) : while compiling class template member function 'std::tr1::shared_ptr<_Ty>::shared_ptr(std::nullptr_t)'
1> with
1> [
1> _Ty=ALLEGRO_BITMAP
1> ]
1> \\b-all-data03\data03\2\10544082\documents\visual studio 2010\projects\allegrotest\allegrotest\bitmapmanager.cpp(14) : see reference to class template instantiation 'std::tr1::shared_ptr<_Ty>' being compiled
1> with
1> [
1> _Ty=ALLEGRO_BITMAP
1> ]
1>c:\program files\microsoft visual studio 10.0\vc\include\memory(1107): warning C4150: deletion of pointer to incomplete type 'ALLEGRO_BITMAP'; no destructor called
1> c:\allegro\include\allegro5\mouse.h(99) : see declaration of 'ALLEGRO_BITMAP'
1> c:\program files\microsoft visual studio 10.0\vc\include\memory(1106) : while compiling class template member function 'void std::tr1::_Ref_count<_Ty>::_Destroy(void)'
1> with
1> [
1> _Ty=ALLEGRO_BITMAP
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\memory(1662) : see reference to class template instantiation 'std::tr1::_Ref_count<_Ty>' being compiled
1> with
1> [
1> _Ty=ALLEGRO_BITMAP
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\memory(1448) : see reference to function template instantiation 'void std::tr1::shared_ptr<_Ty>::_Resetp<_Ty>(_Ux *)' being compiled
1> with
1> [
1> _Ty=ALLEGRO_BITMAP,
1> _Ux=ALLEGRO_BITMAP
1> ]