Mark most single argument constructors explicit

Fixes #91
This commit is contained in:
Dmitry Marakasov 2017-02-14 14:14:26 +03:00
parent 3c5b2e2fb5
commit 89ea96d008
21 changed files with 43 additions and 25 deletions

View File

@ -102,7 +102,7 @@ public:
/// \see http://wiki.libsdl.org/SDL_LockAudioDevice
///
////////////////////////////////////////////////////////////
LockHandle(AudioDevice* device);
explicit LockHandle(AudioDevice* device);
public:
////////////////////////////////////////////////////////////

View File

@ -19,6 +19,8 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include <cassert>
#include <SDL2pp/Chunk.hh>
#include <SDL2pp/RWops.hh>
#include <SDL2pp/Exception.hh>
@ -26,6 +28,7 @@
namespace SDL2pp {
Chunk::Chunk(Mix_Chunk* chunk) : chunk_(chunk) {
assert(chunk);
}
Chunk::Chunk(const std::string& file) {

View File

@ -51,7 +51,7 @@ public:
/// \param[in] chunk Existing Mix_Chunk to manage
///
////////////////////////////////////////////////////////////
Chunk(Mix_Chunk* chunk);
explicit Chunk(Mix_Chunk* chunk);
////////////////////////////////////////////////////////////
/// \brief Load file for use as a sample
@ -63,7 +63,7 @@ public:
/// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC19
///
////////////////////////////////////////////////////////////
Chunk(const std::string& file);
explicit Chunk(const std::string& file);
////////////////////////////////////////////////////////////
/// \brief Load sample using RWops
@ -75,7 +75,7 @@ public:
/// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC20
///
////////////////////////////////////////////////////////////
Chunk(RWops& rwops);
explicit Chunk(RWops& rwops);
////////////////////////////////////////////////////////////
/// \brief Destructor

View File

@ -83,7 +83,7 @@ public:
/// \param[in] function Name of SDL function which generated an error
///
////////////////////////////////////////////////////////////
Exception(const char* function);
explicit Exception(const char* function);
////////////////////////////////////////////////////////////
/// \brief Copy constructor

View File

@ -19,6 +19,7 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include <cassert>
#include <vector>
#include <SDL2/SDL_ttf.h>
@ -29,8 +30,8 @@
namespace SDL2pp {
Font::Font(TTF_Font* font) {
font_ = font;
Font::Font(TTF_Font* font) : font_(font) {
assert(font);
}
Font::Font(const std::string& file, int ptsize, long index) {

View File

@ -60,7 +60,7 @@ public:
/// \param[in] font Existing TTF_Font to manage
///
////////////////////////////////////////////////////////////
Font(TTF_Font* font);
explicit Font(TTF_Font* font);
////////////////////////////////////////////////////////////
/// \brief Loads font from .ttf or .fon file

View File

@ -19,12 +19,15 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include <cassert>
#include <SDL2pp/Music.hh>
#include <SDL2pp/Exception.hh>
namespace SDL2pp {
Music::Music(Mix_Music* music) : music_(music) {
assert(music);
}
Music::Music(const std::string& file) {

View File

@ -49,7 +49,7 @@ public:
/// \param[in] music Existing Mix_Music to manage
///
////////////////////////////////////////////////////////////
Music(Mix_Music* music);
explicit Music(Mix_Music* music);
////////////////////////////////////////////////////////////
/// \brief Load music file
@ -61,7 +61,7 @@ public:
/// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC55
///
////////////////////////////////////////////////////////////
Music(const std::string& file);
explicit Music(const std::string& file);
////////////////////////////////////////////////////////////
/// \brief Destructor

View File

@ -130,6 +130,8 @@ RWops RWops::FromFile(const std::string& file, const std::string& mode) {
}
RWops::RWops(SDL_RWops* rwops) {
assert(rwops);
rwops_ = SDL_AllocRW();
if (rwops_ == nullptr)
throw Exception("SDL_AllocRW");

View File

@ -220,7 +220,7 @@ public:
/// \param[in] rwops Pointer to SDL_RWops to use
///
////////////////////////////////////////////////////////////
RWops(SDL_RWops* rwops);
explicit RWops(SDL_RWops* rwops);
////////////////////////////////////////////////////////////
/// \brief Move constructor
@ -267,7 +267,7 @@ public:
///
////////////////////////////////////////////////////////////
template<class C>
RWops(C&& custom_rwops) {
explicit RWops(C&& custom_rwops) {
rwops_ = SDL_AllocRW();
if (rwops_ == nullptr)
throw Exception("SDL_AllocRW");

View File

@ -20,6 +20,7 @@
*/
#include <vector>
#include <cassert>
#include <SDL2/SDL.h>
@ -31,6 +32,7 @@
namespace SDL2pp {
Renderer::Renderer(SDL_Renderer* renderer) : renderer_(renderer) {
assert(renderer);
}
Renderer::Renderer(Window& window, int index, Uint32 flags) {

View File

@ -59,7 +59,7 @@ public:
/// \param[in] renderer Existing SDL_Renderer to manage
///
////////////////////////////////////////////////////////////
Renderer(SDL_Renderer* renderer);
explicit Renderer(SDL_Renderer* renderer);
////////////////////////////////////////////////////////////
/// \brief Create renderer

View File

@ -67,7 +67,7 @@ public:
/// \see https://www.libsdl.org/projects/SDL_image/docs/SDL_image.html#SEC8
///
////////////////////////////////////////////////////////////
SDLImage(int flags = 0);
explicit SDLImage(int flags = 0);
////////////////////////////////////////////////////////////
/// \brief Destructor, deinitializes SDL_image library

View File

@ -58,7 +58,7 @@ public:
/// \see https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC9
///
////////////////////////////////////////////////////////////
SDLMixer(int flags = 0);
explicit SDLMixer(int flags = 0);
////////////////////////////////////////////////////////////
/// \brief Destructor, deinitializes SDL_mixer library

View File

@ -20,6 +20,7 @@
*/
#include <vector>
#include <cassert>
#include <SDL2pp/Config.hh>
@ -37,6 +38,7 @@
namespace SDL2pp {
Surface::Surface(SDL_Surface* surface) : surface_(surface) {
assert(surface);
}
Surface::Surface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) {
@ -88,14 +90,14 @@ Surface Surface::Convert(const SDL_PixelFormat& format) {
SDL_Surface* surface = SDL_ConvertSurface(surface_, &format, 0);
if (surface == nullptr)
throw Exception("SDL_ConvertSurface");
return surface;
return SDL2pp::Surface(surface);
}
Surface Surface::Convert(Uint32 pixel_format) {
SDL_Surface* surface = SDL_ConvertSurfaceFormat(surface_, pixel_format, 0);
if (surface == nullptr)
throw Exception("SDL_ConvertSurfaceFormat");
return surface;
return SDL2pp::Surface(surface);
}
void Surface::Blit(const Optional<Rect>& srcrect, Surface& dst, const Rect& dstrect) {

View File

@ -80,7 +80,7 @@ public:
/// \see http://wiki.libsdl.org/SDL_LockSurface
///
////////////////////////////////////////////////////////////
LockHandle(Surface* surface);
explicit LockHandle(Surface* surface);
public:
////////////////////////////////////////////////////////////
@ -169,7 +169,7 @@ public:
/// \param[in] surface Existing SDL_Surface to manage
///
////////////////////////////////////////////////////////////
Surface(SDL_Surface* surface);
explicit Surface(SDL_Surface* surface);
////////////////////////////////////////////////////////////
/// \brief Create RGB surface
@ -217,7 +217,7 @@ public:
/// \param[in] rwops RWops used to access an image file
///
////////////////////////////////////////////////////////////
Surface(RWops& rwops);
explicit Surface(RWops& rwops);
////////////////////////////////////////////////////////////
/// \brief Create surface loading it from file
@ -225,7 +225,7 @@ public:
/// \param[in] filename Path to an image file
///
////////////////////////////////////////////////////////////
Surface(const std::string& filename);
explicit Surface(const std::string& filename);
#endif
////////////////////////////////////////////////////////////

View File

@ -21,6 +21,7 @@
#include <utility>
#include <algorithm>
#include <cassert>
#include <SDL2pp/Config.hh>
@ -42,6 +43,7 @@
namespace SDL2pp {
Texture::Texture(SDL_Texture* texture) : texture_(texture) {
assert(texture);
}
Texture::Texture(Renderer& renderer, Uint32 format, int access, int w, int h) {

View File

@ -191,7 +191,7 @@ public:
/// \param[in] texture Existing SDL_Texture to manage
///
////////////////////////////////////////////////////////////
Texture(SDL_Texture* texture);
explicit Texture(SDL_Texture* texture);
////////////////////////////////////////////////////////////
/// \brief Create empty texture

View File

@ -67,7 +67,7 @@ public:
/// \see http://wiki.libsdl.org/SDL_LoadWAV
///
////////////////////////////////////////////////////////////
Wav(const std::string& file);
explicit Wav(const std::string& file);
////////////////////////////////////////////////////////////
/// \brief Load audio using RWops
@ -79,7 +79,7 @@ public:
/// \see http://wiki.libsdl.org/SDL_LoadWAV_RW
///
////////////////////////////////////////////////////////////
Wav(RWops& rwops);
explicit Wav(RWops& rwops);
////////////////////////////////////////////////////////////
/// \brief Destructor

View File

@ -19,6 +19,8 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include <cassert>
#include <SDL2/SDL.h>
#include <SDL2pp/Window.hh>
@ -28,6 +30,7 @@
namespace SDL2pp {
Window::Window(SDL_Window* window) : window_(window) {
assert(window);
}
Window::Window(const std::string& title, int x, int y, int w, int h, Uint32 flags) {

View File

@ -75,7 +75,7 @@ public:
/// \param[in] window Existing SDL_Window to manage
///
////////////////////////////////////////////////////////////
Window(SDL_Window* window);
explicit Window(SDL_Window* window);
////////////////////////////////////////////////////////////
/// \brief Create window with specified title and dimensions