Guest User

Untitled

a guest
Jul 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. /* SDL RAII
  2. *
  3. * This file provides RAII wrappers for SDL objects.
  4. *
  5. */
  6.  
  7. #include <memory>
  8.  
  9. #include <SDL2/SDL.h>
  10. #include <SDL2/SDL_image.h>
  11.  
  12. namespace SDL {
  13.  
  14. namespace detail {
  15.  
  16. struct Deleter {
  17. // clang-format off
  18.  
  19. void operator()(SDL_Renderer *p) const { if (p) SDL_DestroyRenderer(p); }
  20. void operator()(SDL_Texture *p) const { if (p) SDL_DestroyTexture(p); }
  21. void operator()(SDL_Window *p) const { if (p) SDL_DestroyWindow(p); }
  22.  
  23. // clang-format on
  24. };
  25.  
  26. template <typename T>
  27. using Resource = std::unique_ptr<T, Deleter>;
  28.  
  29. } // namespace detail
  30.  
  31. using Renderer = detail::Resource<SDL_Renderer>;
  32. using Texture = detail::Resource<SDL_Texture>;
  33. using Window = detail::Resource<SDL_Window>;
  34.  
  35. } // namespace SDL
Add Comment
Please, Sign In to add comment