Created
July 19, 2018 19:37
-
-
Save W4RH4WK/8f2cb979c2d28f6e3c53063348f59c22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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