Skip to content

Instantly share code, notes, and snippets.

@W4RH4WK
Created July 19, 2018 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save W4RH4WK/8f2cb979c2d28f6e3c53063348f59c22 to your computer and use it in GitHub Desktop.
Save W4RH4WK/8f2cb979c2d28f6e3c53063348f59c22 to your computer and use it in GitHub Desktop.
/* SDL RAII
*
* This file provides RAII wrappers for SDL objects.
*
*/
#include <memory>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
namespace SDL {
namespace detail {
struct Deleter {
// clang-format off
void operator()(SDL_Renderer *p) const { if (p) SDL_DestroyRenderer(p); }
void operator()(SDL_Texture *p) const { if (p) SDL_DestroyTexture(p); }
void operator()(SDL_Window *p) const { if (p) SDL_DestroyWindow(p); }
// clang-format on
};
template <typename T>
using Resource = std::unique_ptr<T, Deleter>;
} // namespace detail
using Renderer = detail::Resource<SDL_Renderer>;
using Texture = detail::Resource<SDL_Texture>;
using Window = detail::Resource<SDL_Window>;
} // namespace SDL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment