-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsdl_ptrs.h
37 lines (29 loc) · 875 Bytes
/
sdl_ptrs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef SDL_PTRS_H_
#define SDL_PTRS_H_
/**
* @brief std::unique_ptr specializations for SDL types.
*/
#include <memory>
#include <type_traits>
#include <SDL.h>
/**
* @brief Deletes the SDL surface using `SDL_FreeSurface`.
*/
struct SDLSurfaceDeleter {
void operator()(SDL_Surface *surface) const { SDL_FreeSurface(surface); }
};
using SDLSurfaceUniquePtr = std::unique_ptr<SDL_Surface, SDLSurfaceDeleter>;
/**
* @brief Deletes the object using `SDL_free`.
*/
template <typename T> struct SDLFreeDeleter {
static_assert(!std::is_same<T, SDL_Surface>::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 <typename T>
using SDLUniquePtr = std::unique_ptr<T, SDLFreeDeleter<T>>;
#endif // SDL_PTRS_H_