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