initializer.cpp 826 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "simple/support/enum.hpp"
  2. #include "initializer.h"
  3. #include "utils.hpp"
  4. using namespace simple::sdlcore;
  5. using simple::support::to_integer;
  6. bool initializer::exists(system_flag system) noexcept
  7. {
  8. auto sdl_system = to_integer(system);
  9. return SDL_WasInit(sdl_system) == sdl_system;
  10. }
  11. initializer::~initializer() noexcept
  12. {
  13. SDL_QuitSubSystem(to_integer(system));
  14. if(exists(system_flag::nothing))
  15. SDL_Quit();
  16. }
  17. initializer::initializer(system_flag system) : system(system)
  18. {
  19. utils::throw_error( SDL_InitSubSystem(to_integer(system)) );
  20. }
  21. initializer::initializer(initializer&& other) noexcept : system(other.system)
  22. {
  23. other.system = system_flag::nothing;
  24. }
  25. initializer & initializer::operator=(initializer&& other) noexcept
  26. {
  27. system = other.system;
  28. other.system = system_flag::nothing;
  29. return *this;
  30. }