From 3c5b2e2fb56df83eb108abddff58cac825797a1f Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Tue, 14 Feb 2017 14:09:28 +0300 Subject: [PATCH 1/2] Whitespace fix --- SDL2pp/Window.cc | 10 +++++----- tests/live_window.cc | 30 +++++++++++++++--------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/SDL2pp/Window.cc b/SDL2pp/Window.cc index ae2b4bd..2289193 100644 --- a/SDL2pp/Window.cc +++ b/SDL2pp/Window.cc @@ -244,17 +244,17 @@ Window& Window::SetBordered(bool bordered) { #if SDL_VERSION_ATLEAST(2, 0, 5) Window& Window::SetOpacity(float opacity) { - if (SDL_SetWindowOpacity(window_, opacity)) + if (SDL_SetWindowOpacity(window_, opacity)) throw SDL2pp::Exception("SDL_SetWindowOpacity"); - return *this; + return *this; } float Window::GetOpacity() const { - float opacity; - if (SDL_GetWindowOpacity(window_, &opacity) == -1) + float opacity; + if (SDL_GetWindowOpacity(window_, &opacity) == -1) throw SDL2pp::Exception("SDL_GetWindowOpacity"); - return opacity; + return opacity; } #endif diff --git a/tests/live_window.cc b/tests/live_window.cc index 03985db..937323e 100644 --- a/tests/live_window.cc +++ b/tests/live_window.cc @@ -194,23 +194,23 @@ BEGIN_TEST(int, char*[]) #if SDL_VERSION_ATLEAST(2, 0, 5) { // Opacity - bool has_opacity = true; - try { - window.SetOpacity(0.5f); - } catch (...) { - has_opacity = false; - std::cerr << "Setting window opacity is not supported on this platform" << std::endl; - } + bool has_opacity = true; + try { + window.SetOpacity(0.5f); + } catch (...) { + has_opacity = false; + std::cerr << "Setting window opacity is not supported on this platform" << std::endl; + } - if (has_opacity) { - EXPECT_TRUE(window.GetOpacity() > 0.49f); - EXPECT_TRUE(window.GetOpacity() < 0.51f); - EventSleep(1000); + if (has_opacity) { + EXPECT_TRUE(window.GetOpacity() > 0.49f); + EXPECT_TRUE(window.GetOpacity() < 0.51f); + EventSleep(1000); - window.SetOpacity(); - EXPECT_TRUE(window.GetOpacity() > 0.99f); - EventSleep(1000); - } + window.SetOpacity(); + EXPECT_TRUE(window.GetOpacity() > 0.99f); + EventSleep(1000); + } } #endif From 89ea96d0080788c06fbd49cd3c50b01c6ce21ff5 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Tue, 14 Feb 2017 14:14:26 +0300 Subject: [PATCH 2/2] Mark most single argument constructors explicit Fixes #91 --- SDL2pp/AudioDevice.hh | 2 +- SDL2pp/Chunk.cc | 3 +++ SDL2pp/Chunk.hh | 6 +++--- SDL2pp/Exception.hh | 2 +- SDL2pp/Font.cc | 5 +++-- SDL2pp/Font.hh | 2 +- SDL2pp/Music.cc | 3 +++ SDL2pp/Music.hh | 4 ++-- SDL2pp/RWops.cc | 2 ++ SDL2pp/RWops.hh | 4 ++-- SDL2pp/Renderer.cc | 2 ++ SDL2pp/Renderer.hh | 2 +- SDL2pp/SDLImage.hh | 2 +- SDL2pp/SDLMixer.hh | 2 +- SDL2pp/Surface.cc | 6 ++++-- SDL2pp/Surface.hh | 8 ++++---- SDL2pp/Texture.cc | 2 ++ SDL2pp/Texture.hh | 2 +- SDL2pp/Wav.hh | 4 ++-- SDL2pp/Window.cc | 3 +++ SDL2pp/Window.hh | 2 +- 21 files changed, 43 insertions(+), 25 deletions(-) diff --git a/SDL2pp/AudioDevice.hh b/SDL2pp/AudioDevice.hh index a224078..72a2e6d 100644 --- a/SDL2pp/AudioDevice.hh +++ b/SDL2pp/AudioDevice.hh @@ -102,7 +102,7 @@ public: /// \see http://wiki.libsdl.org/SDL_LockAudioDevice /// //////////////////////////////////////////////////////////// - LockHandle(AudioDevice* device); + explicit LockHandle(AudioDevice* device); public: //////////////////////////////////////////////////////////// diff --git a/SDL2pp/Chunk.cc b/SDL2pp/Chunk.cc index d32ee38..d0572e7 100644 --- a/SDL2pp/Chunk.cc +++ b/SDL2pp/Chunk.cc @@ -19,6 +19,8 @@ 3. This notice may not be removed or altered from any source distribution. */ +#include + #include #include #include @@ -26,6 +28,7 @@ namespace SDL2pp { Chunk::Chunk(Mix_Chunk* chunk) : chunk_(chunk) { + assert(chunk); } Chunk::Chunk(const std::string& file) { diff --git a/SDL2pp/Chunk.hh b/SDL2pp/Chunk.hh index bed45fb..4e9b4ca 100644 --- a/SDL2pp/Chunk.hh +++ b/SDL2pp/Chunk.hh @@ -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 diff --git a/SDL2pp/Exception.hh b/SDL2pp/Exception.hh index fe6b73c..8b090ae 100644 --- a/SDL2pp/Exception.hh +++ b/SDL2pp/Exception.hh @@ -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 diff --git a/SDL2pp/Font.cc b/SDL2pp/Font.cc index 5d2a181..e5841ed 100644 --- a/SDL2pp/Font.cc +++ b/SDL2pp/Font.cc @@ -19,6 +19,7 @@ 3. This notice may not be removed or altered from any source distribution. */ +#include #include #include @@ -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) { diff --git a/SDL2pp/Font.hh b/SDL2pp/Font.hh index 32abb8f..69dee05 100644 --- a/SDL2pp/Font.hh +++ b/SDL2pp/Font.hh @@ -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 diff --git a/SDL2pp/Music.cc b/SDL2pp/Music.cc index 8dd2206..f6cbd79 100644 --- a/SDL2pp/Music.cc +++ b/SDL2pp/Music.cc @@ -19,12 +19,15 @@ 3. This notice may not be removed or altered from any source distribution. */ +#include + #include #include namespace SDL2pp { Music::Music(Mix_Music* music) : music_(music) { + assert(music); } Music::Music(const std::string& file) { diff --git a/SDL2pp/Music.hh b/SDL2pp/Music.hh index 3a1a7b5..8959bc7 100644 --- a/SDL2pp/Music.hh +++ b/SDL2pp/Music.hh @@ -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 diff --git a/SDL2pp/RWops.cc b/SDL2pp/RWops.cc index 67fd0be..b691e37 100644 --- a/SDL2pp/RWops.cc +++ b/SDL2pp/RWops.cc @@ -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"); diff --git a/SDL2pp/RWops.hh b/SDL2pp/RWops.hh index 4b8c3e2..a8a18e7 100644 --- a/SDL2pp/RWops.hh +++ b/SDL2pp/RWops.hh @@ -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 - RWops(C&& custom_rwops) { + explicit RWops(C&& custom_rwops) { rwops_ = SDL_AllocRW(); if (rwops_ == nullptr) throw Exception("SDL_AllocRW"); diff --git a/SDL2pp/Renderer.cc b/SDL2pp/Renderer.cc index f1f198b..28c31a3 100644 --- a/SDL2pp/Renderer.cc +++ b/SDL2pp/Renderer.cc @@ -20,6 +20,7 @@ */ #include +#include #include @@ -31,6 +32,7 @@ namespace SDL2pp { Renderer::Renderer(SDL_Renderer* renderer) : renderer_(renderer) { + assert(renderer); } Renderer::Renderer(Window& window, int index, Uint32 flags) { diff --git a/SDL2pp/Renderer.hh b/SDL2pp/Renderer.hh index 4635bfc..c226403 100644 --- a/SDL2pp/Renderer.hh +++ b/SDL2pp/Renderer.hh @@ -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 diff --git a/SDL2pp/SDLImage.hh b/SDL2pp/SDLImage.hh index 9e645a1..62b3067 100644 --- a/SDL2pp/SDLImage.hh +++ b/SDL2pp/SDLImage.hh @@ -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 diff --git a/SDL2pp/SDLMixer.hh b/SDL2pp/SDLMixer.hh index 9b45134..4262681 100644 --- a/SDL2pp/SDLMixer.hh +++ b/SDL2pp/SDLMixer.hh @@ -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 diff --git a/SDL2pp/Surface.cc b/SDL2pp/Surface.cc index 214d92c..6fd992a 100644 --- a/SDL2pp/Surface.cc +++ b/SDL2pp/Surface.cc @@ -20,6 +20,7 @@ */ #include +#include #include @@ -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& srcrect, Surface& dst, const Rect& dstrect) { diff --git a/SDL2pp/Surface.hh b/SDL2pp/Surface.hh index 4eb1620..2cc891b 100644 --- a/SDL2pp/Surface.hh +++ b/SDL2pp/Surface.hh @@ -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 //////////////////////////////////////////////////////////// diff --git a/SDL2pp/Texture.cc b/SDL2pp/Texture.cc index f7e5711..79d2ee0 100644 --- a/SDL2pp/Texture.cc +++ b/SDL2pp/Texture.cc @@ -21,6 +21,7 @@ #include #include +#include #include @@ -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) { diff --git a/SDL2pp/Texture.hh b/SDL2pp/Texture.hh index bf27aa2..8869dfe 100644 --- a/SDL2pp/Texture.hh +++ b/SDL2pp/Texture.hh @@ -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 diff --git a/SDL2pp/Wav.hh b/SDL2pp/Wav.hh index 1ec79f5..83f90a5 100644 --- a/SDL2pp/Wav.hh +++ b/SDL2pp/Wav.hh @@ -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 diff --git a/SDL2pp/Window.cc b/SDL2pp/Window.cc index 2289193..3ed1e03 100644 --- a/SDL2pp/Window.cc +++ b/SDL2pp/Window.cc @@ -19,6 +19,8 @@ 3. This notice may not be removed or altered from any source distribution. */ +#include + #include #include @@ -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) { diff --git a/SDL2pp/Window.hh b/SDL2pp/Window.hh index 5c76256..a234e54 100644 --- a/SDL2pp/Window.hh +++ b/SDL2pp/Window.hh @@ -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