| 
    rolmodl
    
   C++ API for the Simple Directmedia Library 2 (SDL2) 
   | 
 
 
 
 
    9     const char* 
name() noexcept {
 
   10       return SDL_GetPlatform();
 
   15       const char* str = 
name();
 
   17       if (strcmp(str, 
"AIX") == 0)
 
   19       if (strcmp(str, 
"Android") == 0)
 
   21       if (strcmp(str, 
"BSDI") == 0)
 
   23       if (strcmp(str, 
"Dreamcast") == 0)
 
   25       if (strcmp(str, 
"Emscripten") == 0)
 
   26         return Id::emscripten;
 
   27       if (strcmp(str, 
"FreeBSD") == 0)
 
   29       if (strcmp(str, 
"Haiku") == 0)
 
   31       if (strcmp(str, 
"HP-UX") == 0)
 
   33       if (strcmp(str, 
"Irix") == 0)
 
   35       if (strcmp(str, 
"Linux") == 0)
 
   37       if (strcmp(str, 
"Atari MiNT") == 0)
 
   39       if (strcmp(str, 
"MacOS Classic") == 0)
 
   40         return Id::macOSClassic;
 
   41       if (strcmp(str, 
"Mac OS X") == 0)
 
   43       if (strcmp(str, 
"NaCl") == 0)
 
   45       if (strcmp(str, 
"NetBSD") == 0)
 
   47       if (strcmp(str, 
"OpenBSD") == 0)
 
   49       if (strcmp(str, 
"OS/2") == 0)
 
   51       if (strcmp(str, 
"OSF/1") == 0)
 
   53       if (strcmp(str, 
"QNX Neutrino") == 0)
 
   54         return Id::QNXNeutrino;
 
   55       if (strcmp(str, 
"RISC OS") == 0)
 
   57       if (strcmp(str, 
"Solaris") == 0)
 
   59       if (strcmp(str, 
"Windows") == 0)
 
   61       if (strcmp(str, 
"WinRT") == 0)
 
   63       if (strcmp(str, 
"tvOS") == 0)
 
   65       if (strcmp(str, 
"iOS") == 0)
 
   67       if (strcmp(str, 
"PlayStation Portable") == 0)
 
   73     unsigned int ram() noexcept {
 
   74       return static_cast<unsigned int>(SDL_GetSystemRAM());
 
   77       return static_cast<unsigned int>(SDL_GetCPUCount());
 
   82         return static_cast<unsigned int>(SDL_GetCPUCacheLineSize());
 
   86         return SDL_Has3DNow() == SDL_TRUE;
 
   89         return SDL_HasAVX() == SDL_TRUE;
 
   92         return SDL_HasAVX2() == SDL_TRUE;
 
   95         return SDL_HasAltiVec() == SDL_TRUE;
 
   98         return SDL_HasMMX() == SDL_TRUE;
 
  101         return SDL_HasRDTSC() == SDL_TRUE;
 
  104         return SDL_HasSSE() == SDL_TRUE;
 
  107         return SDL_HasSSE2() == SDL_TRUE;
 
  110         return SDL_HasSSE3() == SDL_TRUE;
 
  113         return SDL_HasSSE41() == SDL_TRUE;
 
  116         return SDL_HasSSE42() == SDL_TRUE;
 
  122         state_(
State::unknown),
 
  126         int t = -1; 
int p = -1;
 
  127         int state = SDL_GetPowerInfo(&t, &p);
 
  133         if (
state == SDL_POWERSTATE_ON_BATTERY)
 
  134           state_ = State::onBattery;
 
  135         else if (
state == SDL_POWERSTATE_NO_BATTERY)
 
  136           state_ = State::noBattery;
 
  137         else if (
state == SDL_POWERSTATE_CHARGING)
 
  138           state_ = State::charging;
 
  139         else if (
state == SDL_POWERSTATE_CHARGED)
 
  140           state_ = State::charged;
 
  141         else if (
state == SDL_POWERSTATE_UNKNOWN)
 
  142           state_ = State::unknown;
 
  160     namespace clipboard {
 
  162         return SDL_HasClipboardText() == SDL_TRUE;
 
  165         char* x = SDL_GetClipboardText();
 
  176     namespace screensaver {
 
  178         SDL_EnableScreenSaver();
 
  181         SDL_DisableScreenSaver();
 
  184         return SDL_IsScreenSaverEnabled() == SDL_TRUE;
 
  190         int res = SDL_GetNumVideoDrivers();
 
  194         return static_cast<unsigned int>(res);
 
  196       const char* 
name(
const unsigned int i) {
 
  199         return SDL_GetVideoDriver(static_cast<int>(i));
 
  202         const char* p = SDL_GetCurrentVideoDriver();
 
  209     namespace display::unsafe {
 
  215         int res = SDL_GetNumVideoDisplays();
 
  219         return static_cast<unsigned int>(res);
 
  221       const char* 
name(
const unsigned int i) {
 
  224         return SDL_GetDisplayName(static_cast<int>(i));
 
  248      Display::Display(
const unsigned int i) :
 
  249       name_(display::unsafe::
name(i)),
 
  250       bounds_(display::unsafe::bounds(i)), usableBounds_(display::unsafe::usableBounds(i)),
 
  269       return usableBounds_;
 
  283     namespace display::mode::unsafe {
 
  286           throw std::out_of_range(
"rolmodl::sys::display::mode::unsafe::countForDisplayN");
 
  288         int res = SDL_GetNumDisplayModes(static_cast<int>(n));
 
  291         return static_cast<unsigned int>(res);
 
  294       DisplayMode fromSDL_DisplayMode(
const SDL_DisplayMode x);
 
  295       DisplayMode fromSDL_DisplayMode(
const SDL_DisplayMode x) {
 
  297           .
fmt = pixelfmt::id::unsafe::fromSDLEnum(x.format),
 
  300           .unsafeDriverData = x.driverdata
 
  306           throw std::out_of_range(
"rolmodl::sys::display::mode::unsafe::desktopForDisplayN");
 
  308         SDL_DisplayMode tmp{};
 
  311         return fromSDL_DisplayMode(tmp);
 
  315           throw std::out_of_range(
"rolmodl::sys::display::mode::unsafe::currentForDisplayN");
 
  317         SDL_DisplayMode tmp{};
 
  320         return fromSDL_DisplayMode(tmp);
 
  324           throw std::out_of_range(
"rolmodl::sys::display::mode::unsafe::forDisplayNByIndexI");
 
  327           throw std::out_of_range(
"rolmodl::sys::display::mode::unsafe::forDisplayNByIndexI");
 
  329         SDL_DisplayMode tmp{};
 
  330         detail::throwOnErr(SDL_GetDisplayMode(static_cast<int>(n), static_cast<int>(i), &tmp));
 
  332         return fromSDL_DisplayMode(tmp);
 
  337           throw std::out_of_range(
"rolmodl::sys::display::mode::unsafe::closestForDisplayN");
 
  339         const SDL_DisplayMode sdl_ideal{
 
  340           .format = pixelfmt::id::unsafe::toSDLEnum(ideal.
fmt),
 
  341           .w = ideal.
size.w, .h = ideal.
size.h,
 
  346         SDL_DisplayMode tmp{};
 
  347         if (SDL_GetClosestDisplayMode(static_cast<int>(n), &sdl_ideal, &tmp) == 
nullptr)
 
  350         return fromSDL_DisplayMode(tmp);
 
  377   SDLString::SDLString() noexcept :
 
  381    SDLString::SDLString(
char* x) noexcept :
 
  384     assert(raw_ != 
nullptr);
 
  408     swap(a.raw_, b.raw_);
 
  412     assert(raw_ != 
nullptr);
 
  416     assert(raw_ != 
nullptr);
 
  
std::optional< unsigned int > refreshRate
Display mode refresh rate, might be unspecified.
 
geom::Size size
Display mode size.
 
pixelfmt::Id fmt
Display mode format.
 
int throwOnErr(const int code)
Throw a rolmodl::sdlexception if code < 0.
 
bool hasRDTSC() noexcept
Query whether the CPU supports the RDTSC instruction.
 
unsigned int l1Size() noexcept
Get the CPU L1 cache line size in bytes.
 
SDLString & operator=(const SDLString &that)
Copying SDLStrings is not allowed as SDL does not provide a way to allocate a new string....
 
const char * name() noexcept
Human-readable OS name. Use rolmodl::sys::id() for OS identification purposes instead of this method.
 
std::optional< int > time() const noexcept
Get the recorded estimated remaining battery charge life time.
 
bool hasAltiVec() noexcept
Query whether the CPU supports the AltiVec instruction set.
 
unsigned int logicalCores() noexcept
Get the number of available logical CPU cores.
 
const char * name() const noexcept
Get recorded display name.
 
Display information snapshot.
 
bool has3DNow() noexcept
Query whether the CPU supports the 3DNow! extension.
 
const char * name(const unsigned int i)
Get the name of the ith display. Sample output: XF250Q for my Acer XF250Q. Unsafe because there is no...
 
float ddpi() const noexcept
Get recorded display diagonal DPI (dots per inch).
 
bool hasSSE42() noexcept
Query whether the CPU supports the SSE4.2 (Streaming SIMD Extensions) extenstion.
 
int dimensions data type. The value is in pixels. Semantically different from rolmodl::geom::Pos.
 
bool hasSSE() noexcept
Query whether the CPU supports the SSE1 extenstion.
 
const char * name(const unsigned int i)
Get the name of the ith video driver.
 
Status() noexcept
Initialize from the current system power status.
 
void enable() noexcept
Enable system screensaver.
 
Container for SDL-owned strings that must be freed with SDL_free.
 
float vdpi() const noexcept
Get recorded display vertical DPI (dots per inch).
 
SDLString getText()
Get clipboard text contents.
 
std::optional< int > percentage() const noexcept
Get the recorded remaining battery charge percentage.
 
DisplayMode currentForDisplayN(unsigned int n)
Get the current display mode for the nth display. Unsafe because there is no bounds checking on the i...
 
Display mode parameter plain old struct.
 
bool hasAVX() noexcept
Query whether the CPU supports the AVX1 extension.
 
State state() const noexcept
Get the recorded battery status/power state.
 
geom::RectWH usableBounds() const noexcept
Get recorded display usable bounds. Excludes system decorations such as the menu bar and the dock.
 
unsigned int ram() noexcept
Get the amount of system RAM in MB.
 
unsigned int count()
Get the number of displays. Unsafe because the return value is unreliable and may lead to out-of-boun...
 
int code() const noexcept
Get the recorded error code.
 
Rectangle represented by its top left corner coordinates, width, and height.
 
bool hasSSE41() noexcept
Query whether the CPU supports the SSE4.1 extenstion.
 
geom::RectWH bounds(const unsigned int i)
Get the resolution of the ith display. Unsafe because there is no bounds checking on the index.
 
geom::RectWH usableBounds(const unsigned int i)
Get the bounds of the usable space of the ith display. Excludes system decorations such as the menu b...
 
bool hasSSE2() noexcept
Query whether the CPU supports the SSE2 extenstion.
 
bool enabled() noexcept
Query whether the system screensaver is enabled.
 
DisplayMode desktopForDisplayN(unsigned int n)
Get the display mode used by the system desktop for the nth display. Unsafe because there is no bound...
 
void setText(const char *x)
Set clipboard text contents.
 
System power status snapshot.
 
State
Indicates battery status a.k.a. the system power state.
 
void * unsafeDriverData
Unspecified driver-specific data.
 
bool hasText() noexcept
Query whether thhe clipboard has text contents.
 
unsigned int countForDisplayN(unsigned int n)
Get the amount of display modes available for the nth display.
 
Exception type containing an error code and the last SDL error at the moment of creation.
 
unsigned int count()
Query the amount of available video drivers.
 
sdlexception() noexcept
Initialize with the error code arbitrarily set to 0 if one isn't available and the last SDL error mes...
 
bool hasSSE3() noexcept
Query whether the CPU supports the SSE3 extenstion.
 
Display byIndex(unsigned int i)
Get display information for the ith display. Unsafe because there is no bounds checking on the index.
 
DisplayMode closestForDisplayN(unsigned int n, const DisplayMode ideal)
Get the display mode closest to the one specified for the nth display. Unsafe because there is no bou...
 
std::optional< const char * > current() noexcept
Query the current video driver name.
 
bool hasMMX() noexcept
Query whether the CPU supports the MMX instruction set.
 
geom::RectWH bounds() const noexcept
Get recorded display resolution.
 
char * unsafeRaw() noexcept
Get the underlying char*. Unsafe because it allows invalidating the pointer by freeing it.
 
const char * what() const noexcept override
Get the recorded error message.
 
~SDLString() noexcept
SDL_free the underlying char*.
 
bool hasAVX2() noexcept
Query whether the CPU supports the AVX2 extension.
 
Status status() noexcept
Get a system power status snapshot.
 
Id id() noexcept
Get id of the OS on which the code is running. May differ from whatever operating system the code was...
 
void disable() noexcept
Disable system screensaver.
 
float hdpi() const noexcept
Get recorded display horizontal DPI (dots per inch).
 
DisplayMode forDisplayNByIndexI(unsigned int n, unsigned int i)
Get the ith display mode for the nth display. Unsafe because there is no bounds checking on either in...