Browse Source

Simplify SDLWrap with NonNull

pull/2867/head
Vladimir Olteanu 5 years ago committed by Anders Jenbo
parent
commit
3cb70f5042
  1. 48
      Source/utils/sdl_wrap.h

48
Source/utils/sdl_wrap.h

@ -14,31 +14,27 @@ namespace devilution {
namespace SDLWrap {
inline SDLSurfaceUniquePtr CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
template <typename T>
T NonNull(T x)
{
SDLSurfaceUniquePtr ret { SDL_CreateRGBSurface(flags, width, height, depth, Rmask, Gmask, Bmask, Amask) };
if (ret == nullptr)
if (x == nullptr)
ErrSdl();
return x;
}
return ret;
inline SDLSurfaceUniquePtr CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurface(flags, width, height, depth, Rmask, Gmask, Bmask, Amask)) };
}
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format)
{
SDLSurfaceUniquePtr ret { SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format) };
if (ret == nullptr)
ErrSdl();
return ret;
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format)) };
}
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 format)
{
SDLSurfaceUniquePtr ret { SDL_CreateRGBSurfaceWithFormatFrom(pixels, width, height, depth, pitch, format) };
if (ret == nullptr)
ErrSdl();
return ret;
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurfaceWithFormatFrom(pixels, width, height, depth, pitch, format)) };
}
#ifndef USE_SDL1
@ -47,42 +43,26 @@ inline SDLSurfaceUniquePtr ConvertSurface(SDL_Surface *src, const SDL_PixelForma
inline SDLSurfaceUniquePtr ConvertSurface(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags)
#endif
{
SDLSurfaceUniquePtr ret { SDL_ConvertSurface(src, fmt, flags) };
if (ret == nullptr)
ErrSdl();
return ret;
return SDLSurfaceUniquePtr { NonNull(SDL_ConvertSurface(src, fmt, flags)) };
}
#ifndef USE_SDL1
inline SDLSurfaceUniquePtr ConvertSurfaceFormat(SDL_Surface *src, Uint32 pixel_format, Uint32 flags)
{
SDLSurfaceUniquePtr ret { SDL_ConvertSurfaceFormat(src, pixel_format, flags) };
if (ret == nullptr)
ErrSdl();
return ret;
return SDLSurfaceUniquePtr { NonNull(SDL_ConvertSurfaceFormat(src, pixel_format, flags)) };
}
#endif
#ifndef USE_SDL1
inline SDLTextureUniquePtr CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int h)
{
SDLTextureUniquePtr ret { SDL_CreateTexture(renderer, format, access, w, h) };
if (ret == nullptr)
ErrSdl();
return ret;
return SDLTextureUniquePtr { NonNull(SDL_CreateTexture(renderer, format, access, w, h)) };
}
#endif
inline SDLPaletteUniquePtr AllocPalette(int ncolors)
{
SDLPaletteUniquePtr ret { SDL_AllocPalette(ncolors) };
if (ret == nullptr)
ErrSdl();
return ret;
return SDLPaletteUniquePtr { NonNull(SDL_AllocPalette(ncolors)) };
}
} //namespace SDLWrap

Loading…
Cancel
Save