From 5c1bf3e6cf47bd3ed5134614ec63ab13b41059b4 Mon Sep 17 00:00:00 2001 From: Vladimir Gamalian Date: Tue, 14 Jul 2015 14:15:18 +0700 Subject: [PATCH] Create SDLMixer class skeleton --- SDL2pp/SDLMixer.cc | 49 +++++++++++++++++ SDL2pp/SDLMixer.hh | 132 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 SDL2pp/SDLMixer.cc create mode 100644 SDL2pp/SDLMixer.hh diff --git a/SDL2pp/SDLMixer.cc b/SDL2pp/SDLMixer.cc new file mode 100644 index 0000000..b9c0b0f --- /dev/null +++ b/SDL2pp/SDLMixer.cc @@ -0,0 +1,49 @@ +/* + libSDL2pp - C++11 bindings/wrapper for SDL2 + Copyright (C) 2014-2015 Dmitry Marakasov + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include + +#include +#include + +namespace SDL2pp { + +SDLMixer::SDLMixer(int flags) { + if ((IMG_Init(flags) & flags) != flags) + throw Exception("IMG_Init"); +} + +SDLMixer::~SDLMixer() { + IMG_Quit(); +} + +int SDLMixer::InitMore(int flags) { + int ret; + if (((ret = IMG_Init(flags)) & flags) != flags) + throw Exception("IMG_Init"); + return ret; +} + +int SDLMixer::GetInitFlags() { + return IMG_Init(0); +} + +} diff --git a/SDL2pp/SDLMixer.hh b/SDL2pp/SDLMixer.hh new file mode 100644 index 0000000..91fd2b0 --- /dev/null +++ b/SDL2pp/SDLMixer.hh @@ -0,0 +1,132 @@ +/* + libSDL2pp - C++11 bindings/wrapper for SDL2 + Copyright (C) 2014-2015 Dmitry Marakasov + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef SDL2PP_SDLMIXER_HH +#define SDL2PP_SDLMIXER_HH + +namespace SDL2pp { + +//////////////////////////////////////////////////////////// +/// \brief Object taking care of SDL_mixer library initialization and deinitialization +/// +/// \ingroup mixer +/// +/// \headerfile SDL2pp/SDLMixer.hh +/// +/// Though it's possible to use SDL_mixer without initializing it, +/// library provides initialization/deinitialization functions to +/// be able to preload libraries for specific file format support +/// (png, jpeg or tiff) beforehand. In SDL2pp, this is handled by +/// this class. +/// +/// Usage example: +/// \code +/// int main() { +/// SDL2pp::SDL sdl(SDL_INIT_VIDEO); +/// SDL2pp::SDLMixer mixer(IMG_INIT_PNG); +/// +/// // use SDL_mixer functions +/// SDL2pp::Texture t("/path/to/file.png"); +/// +/// // SDL_mixer library is automatically deinitialized before exit +/// return 0; +/// } +/// \endcode +/// +//////////////////////////////////////////////////////////// +class SDLMixer { +public: + //////////////////////////////////////////////////////////// + /// \brief Initializes SDL_mixer library + /// + /// \param[in] flags Flags to pass to IMG_Init() + /// + /// \throws SDL2pp::Exception + /// + /// \see TODO: + /// + //////////////////////////////////////////////////////////// + SDLMixer(int flags = 0); + + //////////////////////////////////////////////////////////// + /// \brief Destructor, deinitializes SDL_mixer library + /// + /// \see TODO: + /// + //////////////////////////////////////////////////////////// + virtual ~SDLMixer(); + + //////////////////////////////////////////////////////////// + /// \brief Try to init more SDL_mixer formats + /// + /// \param[in] flags Flags to pass to IMG_Init() + /// + /// \throws SDL2pp::Exception + /// + /// \see TODO: + /// + //////////////////////////////////////////////////////////// + int InitMore(int flags); + + //////////////////////////////////////////////////////////// + /// \brief Get mask of initialized SDL_mixer formats + /// + /// \see TODO: + /// + //////////////////////////////////////////////////////////// + int GetInitFlags(); + + //////////////////////////////////////////////////////////// + /// \brief Deleted copy constructor + /// + /// This class is not copyable + /// + //////////////////////////////////////////////////////////// + SDLMixer(const SDLMixer& other) = delete; + + //////////////////////////////////////////////////////////// + /// \brief Deleted assignment operator + /// + /// This class is not copyable + /// + //////////////////////////////////////////////////////////// + SDLMixer& operator=(const SDLMixer& other) = delete; + + //////////////////////////////////////////////////////////// + /// \brief Deleted move constructor + /// + /// This class is not movable + /// + //////////////////////////////////////////////////////////// + SDLMixer(SDLMixer&& other) = delete; + + //////////////////////////////////////////////////////////// + /// \brief Deleted move assignment operator + /// + /// This class is not movable + /// + //////////////////////////////////////////////////////////// + SDLMixer& operator=(SDLMixer&& other) = delete; +}; + +} + +#endif