SDL.hxx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #ifndef SNAKE_SDL_HXX
  3. #define SNAKE_SDL_HXX
  4. #include <SDL.h>
  5. #include <cstdint>
  6. #include <source_location>
  7. #include <stdexcept>
  8. #include <string_view>
  9. #include "NonCopyable.hxx"
  10. /**
  11. * @class SDLError
  12. * @brief Represents an SDL error.
  13. *
  14. * This class is a subclass of std::runtime_error and represents an error that occurred
  15. * during an SDL operation. It provides additional information such as the context where
  16. * the error occurred and the source location.
  17. */
  18. class SDLError final : public std::runtime_error {
  19. public:
  20. explicit SDLError(
  21. std::string_view message,
  22. std::source_location location = std::source_location::current()
  23. );
  24. };
  25. /**
  26. * @class SDL
  27. * @brief The SDL class is used to initialize and clean up the SDL library.
  28. *
  29. * This class provides a convenient way to initialize SDL and clean up resources when they are no longer needed.
  30. * Only one instance of this class can exist at a time.
  31. */
  32. class SDL final : private NonCopyable {
  33. public:
  34. explicit SDL(std::uint32_t flags = SDL_INIT_EVERYTHING);
  35. ~SDL() noexcept;
  36. static SDL& instance() noexcept;
  37. static SDL& require(std::uint32_t flags) noexcept;
  38. private:
  39. static SDL* instance_;
  40. };
  41. #endif // SNAKE_SDL_HXX