Load GUI from XML
This commit is contained in:
33
ImageProvider.cc
Normal file
33
ImageProvider.cc
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <SDL2/SDL_image.h>
|
||||
|
||||
#include "ImageProvider.hh"
|
||||
|
||||
template<>
|
||||
std::unique_ptr<ImageProvider> Singleton<ImageProvider>::instance{nullptr};
|
||||
|
||||
template<>
|
||||
std::once_flag Singleton<ImageProvider>::instance_flag{};
|
||||
|
||||
ImageProvider::ImageProvider()
|
||||
{
|
||||
}
|
||||
|
||||
SDL_Surface *ImageProvider::getImage(std::string const& name)
|
||||
{
|
||||
auto it = imageCache_.find(name);
|
||||
|
||||
if(it == imageCache_.end()) {
|
||||
SDLSurfaceUPtr image{IMG_Load(name.c_str())};
|
||||
if (!image)
|
||||
throw SDLException{};
|
||||
tie(it, std::ignore) = imageCache_.insert(make_pair(name, std::move(image)));
|
||||
}
|
||||
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
|
||||
void ImageProvider::cleanup()
|
||||
{
|
||||
imageCache_.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user