diff --git a/SourceX/sdl_ptrs.h b/SourceX/sdl_ptrs.h new file mode 100644 index 000000000..1f68f841f --- /dev/null +++ b/SourceX/sdl_ptrs.h @@ -0,0 +1,45 @@ +#pragma once +/** + * @brief std::unique_ptr specializations for SDL types. + */ + +#include +#include + +#include + +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; + +/** + * @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