#pragma once /** * @brief std::unique_ptr specializations for SDL types. */ #include #include #include #ifdef USE_SDL1 #include "utils/sdl2_to_1_2_backports.h" #else #include "utils/sdl2_backports.h" #endif namespace devilution { /** * @brief Deletes the SDL surface using `SDL_FreeSurface`. */ struct SDLSurfaceDeleter { void operator()(SDL_Surface *surface) const { SDL_FreeSurface(surface); } }; using SDLSurfaceUniquePtr = std::unique_ptr; #if SDL_VERSION_ATLEAST(2, 0, 0) struct SDLCursorDeleter { void operator()(SDL_Cursor *cursor) const { SDL_FreeCursor(cursor); } }; using SDLCursorUniquePtr = std::unique_ptr; #endif #ifndef USE_SDL1 struct SDLTextureDeleter { void operator()(SDL_Texture *texture) const { SDL_DestroyTexture(texture); } }; using SDLTextureUniquePtr = std::unique_ptr; #endif struct SDLPaletteDeleter { void operator()(SDL_Palette *palette) const { SDL_FreePalette(palette); } }; using SDLPaletteUniquePtr = std::unique_ptr; /** * @brief Deletes the object using `SDL_free`. */ template struct SDLFreeDeleter { static_assert(!std::is_same::value, "SDL_Surface should use SDLSurfaceUniquePtr instead."); void operator()(T *obj) const { SDL_free(obj); } }; /** * @brief A unique pointer to T that is deleted with SDL_free. */ template using SDLUniquePtr = std::unique_ptr>; } // namespace devilution