SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_stdinc.h
1#ifndef SDL3PP_STDINC_H_
2#define SDL3PP_STDINC_H_
3
4#include <chrono>
5#include <span>
6#include <SDL3/SDL_stdinc.h>
7#include "SDL3pp_callbackWrapper.h"
8#include "SDL3pp_error.h"
9#include "SDL3pp_optionalRef.h"
10#include "SDL3pp_ownPtr.h"
11#include "SDL3pp_resource.h"
12#include "SDL3pp_spanRef.h"
13#include "SDL3pp_strings.h"
14
15namespace SDL {
16
41
43using TimeRaw = SDL_Time;
44
45// Forward decl
46struct Time;
47
48// Forward decl
49struct Environment;
50
52using EnvironmentRaw = SDL_Environment*;
53
60
61// Forward decl
62struct IConv;
63
65using IConvRaw = SDL_iconv_t;
66
73
74#ifdef SDL3PP_DOC
75
92#define SDL_NOLONGLONG 1
93
108#define SDL_SIZE_MAX SIZE_MAX
109
141#define SDL_COMPILE_TIME_ASSERT(name, x) FailToCompileIf_x_IsFalse(x)
142
143#endif // SDL3PP_DOC
144
153template<class T, std::size_t N>
154constexpr std::size_t arraysize(const T (&array)[N])
155{
156 return std::size(array);
157}
158
159#ifdef SDL3PP_DOC
160
168#define SDL_STRINGIFY_ARG(arg) #arg
169
170#endif // SDL3PP_DOC
171
185constexpr Uint32 FourCC(Uint8 a, Uint8 b, Uint8 c, Uint8 d)
186{
187 return SDL_FOURCC(a, b, c, d);
188}
189
190#ifdef SDL3PP_DOC
191
203#define SDL_SINT64_C(c) c##LL /* or whatever the current compiler uses. */
204
216#define SDL_UINT64_C(c) c##ULL /* or whatever the current compiler uses. */
217
218#endif // SDL3PP_DOC
219
226
228constexpr Sint8 MAX_SINT8 = SDL_MAX_SINT8;
229
231constexpr Sint8 MIN_SINT8 = SDL_MIN_SINT8;
232
239
241constexpr Uint8 MAX_UINT8 = SDL_MAX_UINT8;
242
244constexpr Uint8 MIN_UINT8 = SDL_MIN_UINT8;
245
252
254constexpr Sint16 MAX_SINT16 = SDL_MAX_SINT16;
255
257constexpr Sint16 MIN_SINT16 = SDL_MIN_SINT16;
258
265
267constexpr Uint16 MAX_UINT16 = SDL_MAX_UINT16;
268
270constexpr Uint16 MIN_UINT16 = SDL_MIN_UINT16;
271
278
280constexpr Sint32 MAX_SINT32 = SDL_MAX_SINT32;
281
283constexpr Sint32 MIN_SINT32 = SDL_MIN_SINT32;
284
291
293constexpr Uint32 MAX_UINT32 = SDL_MAX_UINT32;
294
296constexpr Uint8 MIN_UINT32 = SDL_MIN_UINT32;
297
306
308constexpr Sint64 MAX_SINT64 = SDL_MAX_SINT64;
309
311constexpr Sint64 MIN_SINT64 = SDL_MIN_SINT64;
312
321
323constexpr Uint64 MAX_UINT64 = SDL_MAX_UINT64;
324
326constexpr Uint8 MIN_UINT64 = SDL_MIN_UINT64;
327
329using Seconds = std::chrono::duration<float>;
330
332using Nanoseconds = std::chrono::nanoseconds;
333
335using Milliseconds = std::chrono::milliseconds;
336
338constexpr float ToSeconds(Seconds duration) { return duration.count(); }
339
341constexpr Seconds FromSeconds(float duration) { return Seconds(duration); }
342
344constexpr Sint64 ToNS(Nanoseconds duration) { return duration.count(); }
345
347constexpr Nanoseconds FromNS(Sint64 duration) { return Nanoseconds{duration}; }
348
362class Time
363{
364 Nanoseconds m_time;
365
366public:
367 constexpr Time() = default;
368
374 constexpr explicit Time(TimeRaw time) noexcept
375 : m_time(time)
376 {
377 }
378
384 constexpr Time(std::chrono::nanoseconds time) noexcept
385 : m_time(time)
386 {
387 }
388
390 constexpr explicit operator bool() const
391 {
392 return m_time != std::chrono::nanoseconds{};
393 }
394
396 constexpr operator std::chrono::nanoseconds() const { return m_time; }
397
408 static Time Current();
409
411 static constexpr Time FromNS(Sint64 time)
412 {
413 return Time{std::chrono::nanoseconds{time}};
414 }
415
417 constexpr Sint64 ToNS() const { return m_time.count(); }
418
431 static constexpr Time FromPosix(Sint64 time);
432
444 constexpr Sint64 ToPosix() const;
445
461 static Time FromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime);
462
478 void ToWindows(Uint32* dwLowDateTime, Uint32* dwHighDateTime) const;
479
481 constexpr float ToSeconds() const { return Seconds(m_time).count(); }
482
484 static constexpr Time FromSeconds(float interval)
485 {
486 return std::chrono::duration_cast<std::chrono::nanoseconds>(
487 Seconds(interval));
488 }
489
491 constexpr Time& operator+=(std::chrono::nanoseconds interval)
492 {
493 m_time += interval;
494 return *this;
495 }
496
498 constexpr Time& operator-=(std::chrono::nanoseconds interval)
499 {
500 m_time -= interval;
501 return *this;
502 }
503};
504
506constexpr Time MAX_TIME = Time::FromNS(SDL_MAX_TIME);
507
509constexpr Time MIN_TIME = Time::FromNS(SDL_MIN_TIME);
510
511#ifndef FLT_EPSILON
512
521constexpr float FLT_EPSILON = 1.1920928955078125e-07F;
522
523#endif // FLT_EPSILON
524
530template<class I>
531concept Interface = requires(I* iface) { (iface)->version = sizeof(I); };
532
571template<Interface I>
572constexpr void InitInterface(I* iface)
573{
574 SDL_INIT_INTERFACE(iface);
575}
576
602inline void* malloc(size_t size) { return SDL_malloc(size); }
603
627inline void* calloc(size_t nmemb, size_t size)
628{
629 return SDL_calloc(nmemb, size);
630}
631
668inline void* realloc(void* mem, size_t size) { return SDL_realloc(mem, size); }
669
688inline void free(void* mem) { SDL_free(mem); }
689
707using malloc_func = void*(SDLCALL*)(size_t size);
708
728using calloc_func = void*(SDLCALL*)(size_t nmemb, size_t size);
729
749using realloc_func = void*(SDLCALL*)(void* mem, size_t size);
750
767using free_func = void(SDLCALL*)(void* mem);
768
794
819
853
876inline void* aligned_alloc(size_t alignment, size_t size)
877{
878 return SDL_aligned_alloc(alignment, size);
879}
880
897inline void aligned_free(void* mem) { SDL_aligned_free(mem); }
898
908inline int GetNumAllocations() { return SDL_GetNumAllocations(); }
909
925struct Environment : ResourceBase<EnvironmentRaw>
926{
928
936 constexpr explicit Environment(EnvironmentRaw resource) noexcept
937 : ResourceBase(resource)
938 {
939 }
940
942 constexpr Environment(const Environment& other) = delete;
943
945 constexpr Environment(Environment&& other) noexcept
946 : Environment(other.release())
947 {
948 }
949
950 constexpr Environment(const EnvironmentRef& other) = delete;
951
952 constexpr Environment(EnvironmentRef&& other) = delete;
953
974 Environment(bool populated);
975
977 ~Environment() { SDL_DestroyEnvironment(get()); }
978
980 constexpr Environment& operator=(Environment&& other) noexcept
981 {
982 swap(*this, other);
983 return *this;
984 }
985
987 Environment& operator=(const Environment& other) = delete;
988
999 void Destroy();
1000
1018 const char* GetVariable(StringParam name);
1019
1040
1048 Uint64 GetVariableCount() { return GetVariables().size(); }
1049
1070 void SetVariable(StringParam name, StringParam value, bool overwrite);
1071
1089 void UnsetVariable(StringParam name);
1090};
1091
1113inline EnvironmentRaw GetEnvironment() { return SDL_GetEnvironment(); }
1114
1135inline Environment CreateEnvironment(bool populated)
1136{
1137 return Environment(populated);
1138}
1139
1140inline Environment::Environment(bool populated)
1141 : Environment(SDL_CreateEnvironment(populated))
1142{
1143}
1144
1164{
1165 return SDL_GetEnvironmentVariable(env, name);
1166}
1167
1169{
1170 return SDL::GetEnvironmentVariable(get(), std::move(name));
1171}
1172
1193{
1194 return OwnArray<char*>{CheckError(SDL_GetEnvironmentVariables(env))};
1195}
1196
1201
1223 StringParam name,
1224 StringParam value,
1225 bool overwrite)
1226{
1227 CheckError(SDL_SetEnvironmentVariable(env, name, value, overwrite));
1228}
1229
1231 StringParam value,
1232 bool overwrite)
1233{
1235 get(), std::move(name), std::move(value), overwrite);
1236}
1237
1257{
1258 CheckError(SDL_UnsetEnvironmentVariable(env, name));
1259}
1260
1262{
1263 SDL::UnsetEnvironmentVariable(get(), std::move(name));
1264}
1265
1279{
1280 SDL_DestroyEnvironment(env);
1281}
1282
1284
1300inline const char* getenv(StringParam name) { return SDL_getenv(name); }
1301
1323inline const char* getenv_unsafe(StringParam name)
1324{
1325 return SDL_getenv_unsafe(name);
1326}
1327
1344inline int setenv_unsafe(StringParam name, StringParam value, int overwrite)
1345{
1346 return SDL_setenv_unsafe(name, value, overwrite);
1347}
1348
1363{
1364 return SDL_unsetenv_unsafe(name);
1365}
1366
1381using CompareCallback = int(SDLCALL*)(const void* a, const void* b);
1382
1427inline void qsort(void* base,
1428 size_t nmemb,
1429 size_t size,
1430 CompareCallback compare)
1431{
1432 SDL_qsort(base, nmemb, size, compare);
1433}
1434
1484inline void* bsearch(const void* key,
1485 const void* base,
1486 size_t nmemb,
1487 size_t size,
1488 CompareCallback compare)
1489{
1490 return SDL_bsearch(key, base, nmemb, size, compare);
1491}
1492
1508using CompareCallback_r = int(SDLCALL*)(void* userdata,
1509 const void* a,
1510 const void* b);
1511
1527using CompareCB = std::function<int(const void* a, const void* b)>;
1528
1581inline void qsort_r(void* base,
1582 size_t nmemb,
1583 size_t size,
1584 CompareCallback_r compare,
1585 void* userdata)
1586{
1587 SDL_qsort_r(base, nmemb, size, compare, userdata);
1588}
1589
1641inline void qsort_r(void* base, size_t nmemb, size_t size, CompareCB compare)
1642{
1643 return qsort_r(
1644 base,
1645 nmemb,
1646 size,
1647 [](void* userdata, const void* a, const void* b) {
1648 auto& cb = *static_cast<const CompareCB*>(userdata);
1649 return cb(a, b);
1650 },
1651 &compare);
1652}
1653
1711inline void* bsearch_r(const void* key,
1712 const void* base,
1713 size_t nmemb,
1714 size_t size,
1715 CompareCallback_r compare,
1716 void* userdata)
1717{
1718 return SDL_bsearch_r(key, base, nmemb, size, compare, userdata);
1719}
1720
1777inline void* bsearch_r(const void* key,
1778 const void* base,
1779 size_t nmemb,
1780 size_t size,
1781 CompareCB compare)
1782{
1783 return bsearch_r(
1784 key,
1785 base,
1786 nmemb,
1787 size,
1788 [](void* userdata, const void* a, const void* b) {
1789 auto& cb = *static_cast<const CompareCB*>(userdata);
1790 return cb(a, b);
1791 },
1792 &compare);
1793}
1794
1805inline int abs(int x) { return SDL_abs(x); }
1806
1826inline double abs(double x) { return SDL_fabs(x); }
1827
1847inline float abs(float x) { return SDL_fabsf(x); }
1848
1865template<class T, class U>
1866constexpr T min(T x, U y)
1867{
1868 return SDL_min(x, y);
1869}
1870
1887template<class T, class U>
1888constexpr T max(T x, U y)
1889{
1890 return SDL_max(x, y);
1891}
1892
1915template<class T, class U, class V>
1916constexpr T clamp(T x, U a, V b)
1917{
1918 return SDL_clamp(x, a, b);
1919}
1920
1934inline int isalpha(int x) { return SDL_isalpha(x); }
1935
1949inline int isalnum(int x) { return SDL_isalnum(x); }
1950
1964inline int isblank(int x) { return SDL_isblank(x); }
1965
1979inline int iscntrl(int x) { return SDL_iscntrl(x); }
1980
1994inline int isdigit(int x) { return SDL_isdigit(x); }
1995
2009inline int isxdigit(int x) { return SDL_isxdigit(x); }
2010
2027inline int ispunct(int x) { return SDL_ispunct(x); }
2028
2049inline int isspace(int x) { return SDL_isspace(x); }
2050
2064inline int isupper(int x) { return SDL_isupper(x); }
2065
2079inline int islower(int x) { return SDL_islower(x); }
2080
2098inline int isprint(int x) { return SDL_isprint(x); }
2099
2119inline int isgraph(int x) { return SDL_isgraph(x); }
2120
2137inline int toupper(int x) { return SDL_toupper(x); }
2138
2155inline int tolower(int x) { return SDL_tolower(x); }
2156
2176inline Uint16 crc16(Uint16 crc, const void* data, size_t len)
2177{
2178 return SDL_crc16(crc, data, len);
2179}
2180
2200inline Uint32 crc32(Uint32 crc, const void* data, size_t len)
2201{
2202 return SDL_crc32(crc, data, len);
2203}
2204
2229inline Uint32 murmur3_32(const void* data, size_t len, Uint32 seed)
2230{
2231 return SDL_murmur3_32(data, len, seed);
2232}
2233
2252inline void* memcpy(void* dst, const void* src, size_t len)
2253{
2254#ifdef SDL_SLOW_MEMCPY
2255 return SDL_memcpy(dst, src, len);
2256#else
2257 return ::memcpy(dst, src, len);
2258#endif // SDL_SLOW_MEMCPY
2259}
2260
2285template<typename T, typename U>
2286constexpr T* copyp(T* dst, const U* src)
2287{
2288 SDL_copyp(dst, src);
2289 return dst;
2290}
2291
2309inline void* memmove(void* dst, const void* src, size_t len)
2310{
2311#ifdef SDL_SLOW_MEMMOVE
2312 return SDL_memmove(dst, src, len);
2313#else
2314 return ::memmove(dst, src, len);
2315#endif // SDL_SLOW_MEMMOVE
2316}
2317
2336inline void* memset(void* dst, int c, size_t len)
2337{
2338#ifdef SDL_SLOW_MEMSET
2339 return SDL_memset(dst, c, len);
2340#else
2341 return ::memset(dst, c, len);
2342#endif // SDL_SLOW_MEMSET
2343}
2344
2363inline void* memset4(void* dst, Uint32 val, size_t dwords)
2364{
2365 return SDL_memset4(dst, val, dwords);
2366}
2367
2385template<class T>
2386inline void zero(T& x)
2387{
2388 SDL_zero(x);
2389}
2390
2408template<class T>
2409inline void zerop(T* x)
2410{
2411 SDL_zerop(x);
2412}
2413
2431template<class T, std::size_t N>
2432inline void zeroa(T (&x)[N])
2433{
2434 SDL_zeroa(x);
2435}
2436
2451inline int memcmp(const void* s1, const void* s2, size_t len)
2452{
2453 return SDL_memcmp(s1, s2, len);
2454}
2455
2480inline size_t wcslen(const wchar_t* wstr) { return SDL_wcslen(wstr); }
2481
2510inline size_t wcsnlen(const wchar_t* wstr, size_t maxlen)
2511{
2512 return SDL_wcsnlen(wstr, maxlen);
2513}
2514
2540inline size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t maxlen)
2541{
2542 return SDL_wcslcpy(dst, src, maxlen);
2543}
2544
2571inline size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t maxlen)
2572{
2573 return SDL_wcslcat(dst, src, maxlen);
2574}
2575
2592inline wchar_t* wcsdup(const wchar_t* wstr) { return SDL_wcsdup(wstr); }
2593
2612inline wchar_t* wcsstr(const wchar_t* haystack, const wchar_t* needle)
2613{
2614 return SDL_wcsstr(haystack, needle);
2615}
2616
2638inline wchar_t* wcsnstr(const wchar_t* haystack,
2639 const wchar_t* needle,
2640 size_t maxlen)
2641{
2642 return SDL_wcsnstr(haystack, needle, maxlen);
2643}
2644
2661inline int wcscmp(const wchar_t* str1, const wchar_t* str2)
2662{
2663 return SDL_wcscmp(str1, str2);
2664}
2665
2693inline int wcsncmp(const wchar_t* str1, const wchar_t* str2, size_t maxlen)
2694{
2695 return SDL_wcsncmp(str1, str2, maxlen);
2696}
2697
2725inline int wcscasecmp(const wchar_t* str1, const wchar_t* str2)
2726{
2727 return SDL_wcscasecmp(str1, str2);
2728}
2729
2769inline int wcsncasecmp(const wchar_t* str1, const wchar_t* str2, size_t maxlen)
2770{
2771 return SDL_wcsncasecmp(str1, str2, maxlen);
2772}
2773
2798inline long wcstol(const wchar_t* str, wchar_t** endp, int base)
2799{
2800 return SDL_wcstol(str, endp, base);
2801}
2802
2821inline size_t strlen(StringParam str) { return SDL_strlen(str); }
2822
2844inline size_t strnlen(StringParam str, size_t maxlen)
2845{
2846 return SDL_strnlen(str, maxlen);
2847}
2848
2874inline size_t strlcpy(char* dst, StringParam src, size_t maxlen)
2875{
2876 return SDL_strlcpy(dst, src, maxlen);
2877}
2878
2905inline size_t utf8strlcpy(char* dst, StringParam src, size_t dst_bytes)
2906{
2907 return SDL_utf8strlcpy(dst, src, dst_bytes);
2908}
2909
2936inline size_t strlcat(char* dst, StringParam src, size_t maxlen)
2937{
2938 return SDL_strlcat(dst, src, maxlen);
2939}
2940
2957inline char* strdup(StringParam str) { return SDL_strdup(str); }
2958
2982inline char* strndup(StringParam str, size_t maxlen)
2983{
2984 return SDL_strndup(str, maxlen);
2985}
2986
3006inline char* strrev(char* str) { return SDL_strrev(str); }
3007
3027inline char* strupr(char* str) { return SDL_strupr(str); }
3028
3048inline char* strlwr(char* str) { return SDL_strlwr(str); }
3049
3068inline char* strchr(StringParam str, int c) { return SDL_strchr(str, c); }
3069
3087inline char* strrchr(StringParam str, int c) { return SDL_strrchr(str, c); }
3088
3107inline char* strstr(StringParam haystack, StringParam needle)
3108{
3109 return SDL_strstr(haystack, needle);
3110}
3111
3133inline char* strnstr(StringParam haystack, StringParam needle, size_t maxlen)
3134{
3135 return SDL_strnstr(haystack, needle, maxlen);
3136}
3137
3164inline char* strcasestr(StringParam haystack, StringParam needle)
3165{
3166 return SDL_strcasestr(haystack, needle);
3167}
3168
3195inline char* strtok_r(char* str, StringParam delim, char** saveptr)
3196{
3197 return SDL_strtok_r(str, delim, saveptr);
3198}
3199
3224inline size_t utf8strlen(StringParam str) { return SDL_utf8strlen(str); }
3225
3256inline size_t utf8strnlen(StringParam str, size_t bytes)
3257{
3258 return SDL_utf8strnlen(str, bytes);
3259}
3260
3286inline char* itoa(int value, char* str, int radix)
3287{
3288 return SDL_itoa(value, str, radix);
3289}
3290
3316inline char* uitoa(unsigned int value, char* str, int radix)
3317{
3318 return SDL_uitoa(value, str, radix);
3319}
3320
3346inline char* ltoa(long value, char* str, int radix)
3347{
3348 return SDL_ltoa(value, str, radix);
3349}
3350
3376inline char* ultoa(unsigned long value, char* str, int radix)
3377{
3378 return SDL_ultoa(value, str, radix);
3379}
3380
3381#ifndef SDL_NOLONGLONG
3382
3408inline char* lltoa(long long value, char* str, int radix)
3409{
3410 return SDL_lltoa(value, str, radix);
3411}
3412
3438inline char* ulltoa(unsigned long long value, char* str, int radix)
3439{
3440 return SDL_ulltoa(value, str, radix);
3441}
3442
3443#endif // SDL_NOLONGLONG
3444
3466inline int atoi(StringParam str) { return SDL_atoi(str); }
3467
3487inline double atof(StringParam str) { return SDL_atof(str); }
3488
3520inline long strtol(StringParam str, char** endp, int base)
3521{
3522 return SDL_strtol(str, endp, base);
3523}
3524
3555inline unsigned long strtoul(StringParam str, char** endp, int base)
3556{
3557 return SDL_strtoul(str, endp, base);
3558}
3559
3560#ifndef SDL_NOLONGLONG
3561
3592inline long long strtoll(StringParam str, char** endp, int base)
3593{
3594 return SDL_strtoll(str, endp, base);
3595}
3596
3627inline unsigned long long strtoull(StringParam str, char** endp, int base)
3628{
3629 return SDL_strtoull(str, endp, base);
3630}
3631
3632#endif // SDL_NOLONGLONG
3633
3661inline double strtod(StringParam str, char** endp)
3662{
3663 return SDL_strtod(str, endp);
3664}
3665
3683inline int strcmp(StringParam str1, StringParam str2)
3684{
3685 return SDL_strcmp(str1, str2);
3686}
3687
3715inline int strncmp(StringParam str1, StringParam str2, size_t maxlen)
3716{
3717 return SDL_strncmp(str1, str2, maxlen);
3718}
3719
3745inline int strcasecmp(StringParam str1, StringParam str2)
3746{
3747 return SDL_strcasecmp(str1, str2);
3748}
3749
3786inline int strncasecmp(StringParam str1, StringParam str2, size_t maxlen)
3787{
3788 return SDL_strncasecmp(str1, str2, maxlen);
3789}
3790
3807inline char* strpbrk(StringParam str, StringParam breakset)
3808{
3809 return SDL_strpbrk(str, breakset);
3810}
3811
3825constexpr Uint32 INVALID_UNICODE_CODEPOINT = SDL_INVALID_UNICODE_CODEPOINT;
3826
3868inline Uint32 StepUTF8(const char** pstr, size_t* pslen)
3869{
3870 return SDL_StepUTF8(pstr, pslen);
3871}
3872
3900inline Uint32 StepBackUTF8(StringParam start, const char** pstr)
3901{
3902 return SDL_StepBackUTF8(start, pstr);
3903}
3904
3932inline char* UCS4ToUTF8(Uint32 codepoint, char* dst)
3933{
3934 return SDL_UCS4ToUTF8(codepoint, dst);
3935}
3936
3952inline int sscanf(StringParam text,
3953 SDL_SCANF_FORMAT_STRING const char* fmt,
3954 ...)
3955{
3956 int rc;
3957 va_list ap;
3958 va_start(ap, fmt);
3959 rc = SDL_vsscanf(text, fmt, ap);
3960 va_end(ap);
3961 return rc;
3962}
3963
3980inline int vsscanf(StringParam text,
3981 SDL_SCANF_FORMAT_STRING const char* fmt,
3982 va_list ap)
3983{
3984 return SDL_vsscanf(text, fmt, ap);
3985}
3986
4017inline int snprintf(char* text,
4018 size_t maxlen,
4019 SDL_PRINTF_FORMAT_STRING const char* fmt,
4020 ...)
4021{
4022 va_list ap;
4023 int result;
4024
4025 va_start(ap, fmt);
4026 result = SDL_vsnprintf(text, maxlen, fmt, ap);
4027 va_end(ap);
4028
4029 return result;
4030}
4031
4063inline int swprintf(wchar_t* text,
4064 size_t maxlen,
4065 SDL_PRINTF_FORMAT_STRING const wchar_t* fmt,
4066 ...)
4067{
4068 va_list ap;
4069 int result;
4070
4071 va_start(ap, fmt);
4072 result = SDL_vswprintf(text, maxlen, fmt, ap);
4073 va_end(ap);
4074
4075 return result;
4076}
4077
4096inline int vsnprintf(char* text,
4097 size_t maxlen,
4098 SDL_PRINTF_FORMAT_STRING const char* fmt,
4099 va_list ap)
4100{
4101 return SDL_vsnprintf(text, maxlen, fmt, ap);
4102}
4103
4123inline int vswprintf(wchar_t* text,
4124 size_t maxlen,
4125 SDL_PRINTF_FORMAT_STRING const wchar_t* fmt,
4126 va_list ap)
4127{
4128 return SDL_vswprintf(text, maxlen, fmt, ap);
4129}
4130
4157inline int asprintf(char** strp, SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
4158{
4159 va_list ap;
4160 int result;
4161
4162 va_start(ap, fmt);
4163 result = SDL_vasprintf(strp, fmt, ap);
4164 va_end(ap);
4165
4166 return result;
4167}
4168
4186inline int vasprintf(char** strp,
4187 SDL_PRINTF_FORMAT_STRING const char* fmt,
4188 va_list ap)
4189{
4190 return SDL_vasprintf(strp, fmt, ap);
4191}
4192
4210inline void srand(Uint64 seed) { SDL_srand(seed); }
4211
4223{
4224 Uint64 m_state;
4225
4226public:
4228 constexpr Random()
4229 : m_state(0)
4230 {
4231 }
4232
4234 constexpr explicit Random(Uint64 state)
4235 : m_state(state)
4236 {
4237 }
4238
4240 constexpr operator Uint64() const { return m_state; }
4241
4273 Sint32 rand(Sint32 n) { return SDL_rand_r(&m_state, n); }
4274
4297 float randf() { return SDL_randf_r(&m_state); }
4298
4320 Uint32 rand_bits() { return SDL_rand_bits_r(&m_state); }
4321};
4322
4353inline Sint32 rand(Sint32 n) { return SDL_rand(n); }
4354
4388inline Sint32 rand(Uint64* state, Sint32 n) { return SDL_rand_r(state, n); }
4389
4423inline Sint32 rand(Random& state, Sint32 n) { return state.rand(n); }
4424
4445inline float randf() { return SDL_randf(); }
4446
4471inline float randf(Uint64* state) { return SDL_randf_r(state); }
4472
4497inline float randf(Random& state) { return state.randf(); }
4498
4520inline Uint32 rand_bits() { return SDL_rand_bits(); }
4521
4545inline Uint32 rand_bits(Uint64* state) { return SDL_rand_bits_r(state); }
4546
4570inline Uint32 rand_bits(Random& state) { return state.rand_bits(); }
4571
4579constexpr double PI_D = SDL_PI_D;
4580
4588constexpr float PI_F = SDL_PI_F;
4589
4617inline double acos(double x) { return SDL_acos(x); }
4618
4646inline float acos(float x) { return SDL_acosf(x); }
4647
4675inline double asin(double x) { return SDL_asin(x); }
4676
4704inline float asin(float x) { return SDL_asinf(x); }
4705
4735inline double atan(double x) { return SDL_atan(x); }
4736
4766inline float atan(float x) { return SDL_atanf(x); }
4767
4800inline double atan2(double y, double x) { return SDL_atan2(y, x); }
4801
4835inline float atan2(float y, float x) { return SDL_atan2f(y, x); }
4836
4863inline double ceil(double x) { return SDL_ceil(x); }
4864
4891inline float ceil(float x) { return SDL_ceilf(x); }
4892
4916inline double copysign(double x, double y) { return SDL_copysign(x, y); }
4917
4941inline float copysign(float x, float y) { return SDL_copysignf(x, y); }
4942
4968inline double cos(double x) { return SDL_cos(x); }
4969
4995inline float cos(float x) { return SDL_cosf(x); }
4996
5026inline double exp(double x) { return SDL_exp(x); }
5027
5057inline float exp(float x) { return SDL_expf(x); }
5058
5085inline double floor(double x) { return SDL_floor(x); }
5086
5113inline float floor(float x) { return SDL_floorf(x); }
5114
5142inline double trunc(double x) { return SDL_trunc(x); }
5143
5171inline float trunc(float x) { return SDL_truncf(x); }
5172
5201inline double fmod(double x, double y) { return SDL_fmod(x, y); }
5202
5231inline float fmod(float x, float y) { return SDL_fmodf(x, y); }
5232
5245inline int isinf(double x) { return SDL_isinf(x); }
5246
5259inline int isinf(float x) { return SDL_isinff(x); }
5260
5273inline int isnan(double x) { return SDL_isnan(x); }
5274
5287inline int isnan(float x) { return SDL_isnanf(x); }
5288
5316inline double log(double x) { return SDL_log(x); }
5317
5344inline float log(float x) { return SDL_logf(x); }
5345
5373inline double log10(double x) { return SDL_log10(x); }
5374
5402inline float log10(float x) { return SDL_log10f(x); }
5403
5422inline double modf(double x, double* y) { return SDL_modf(x, y); }
5423
5442inline float modf(float x, float* y) { return SDL_modff(x, y); }
5443
5472inline double pow(double x, double y) { return SDL_pow(x, y); }
5473
5502inline float pow(float x, float y) { return SDL_powf(x, y); }
5503
5531inline double round(double x) { return SDL_round(x); }
5532
5560inline float round(float x) { return SDL_roundf(x); }
5561
5589inline long lround(double x) { return SDL_lround(x); }
5590
5618inline long lround(float x) { return SDL_lroundf(x); }
5619
5643inline double scalbn(double x, int n) { return SDL_scalbn(x, n); }
5644
5668inline float scalbn(float x, int n) { return SDL_scalbnf(x, n); }
5669
5695inline double sin(double x) { return SDL_sin(x); }
5696
5722inline float sin(float x) { return SDL_sinf(x); }
5723
5747inline double sqrt(double x) { return SDL_sqrt(x); }
5748
5772inline float sqrt(float x) { return SDL_sqrtf(x); }
5773
5801inline double tan(double x) { return SDL_tan(x); }
5802
5830inline float tan(float x) { return SDL_tanf(x); }
5831
5842struct IConv : ResourceBase<IConvRaw>
5843{
5845
5847 IConv(std::nullptr_t = nullptr) noexcept
5848 : IConv(IConvRaw(SDL_ICONV_ERROR))
5849 {
5850 }
5851
5859 constexpr explicit IConv(IConvRaw resource) noexcept
5860 : ResourceBase(resource)
5861 {
5862 }
5863
5865 constexpr IConv(const IConv& other) = delete;
5866
5868 constexpr IConv(IConv&& other) noexcept
5869 : IConv(other.release())
5870 {
5871 }
5872
5873 constexpr IConv(const IConvRef& other) = delete;
5874
5875 constexpr IConv(IConvRef&& other) = delete;
5876
5893 IConv(StringParam tocode, StringParam fromcode);
5894
5896 ~IConv() { SDL_iconv_close(get()); }
5897
5899 constexpr IConv& operator=(IConv&& other) noexcept
5900 {
5901 swap(*this, other);
5902 return *this;
5903 }
5904
5906 IConv& operator=(const IConv& other) = delete;
5907
5909 explicit operator bool() const noexcept
5910 {
5911 return reinterpret_cast<size_t>(get()) != SDL_ICONV_ERROR;
5912 }
5913
5927 int close();
5928
5965 size_t iconv(const char** inbuf,
5966 size_t* inbytesleft,
5967 char** outbuf,
5968 size_t* outbytesleft) const;
5969};
5970
5987inline IConv iconv_open(StringParam tocode, StringParam fromcode)
5988{
5989 return IConv(std::move(tocode), std::move(fromcode));
5990}
5991
5992inline IConv::IConv(StringParam tocode, StringParam fromcode)
5993 : IConv(SDL_iconv_open(tocode, fromcode))
5994{
5995}
5996
6012inline int iconv_close(IConvRaw cd) { return CheckError(SDL_iconv_close(cd)); }
6013
6014inline int IConv::close() { return iconv_close(release()); }
6015
6052inline size_t iconv(IConvRaw cd,
6053 const char** inbuf,
6054 size_t* inbytesleft,
6055 char** outbuf,
6056 size_t* outbytesleft)
6057{
6058 return CheckError(SDL_iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft));
6059}
6060
6061inline size_t IConv::iconv(const char** inbuf,
6062 size_t* inbytesleft,
6063 char** outbuf,
6064 size_t* outbytesleft) const
6065{
6066 return SDL::iconv(get(), inbuf, inbytesleft, outbuf, outbytesleft);
6067}
6068
6069constexpr size_t ICONV_ERROR =
6070 SDL_ICONV_ERROR;
6071
6072constexpr size_t ICONV_E2BIG =
6073 SDL_ICONV_E2BIG;
6074
6075constexpr size_t ICONV_EILSEQ =
6076 SDL_ICONV_EILSEQ;
6077
6078constexpr size_t ICONV_EINVAL =
6079 SDL_ICONV_EINVAL;
6080
6105 StringParam fromcode,
6106 SourceBytes inbuf)
6107{
6108 return OwnArray<char>{
6109 SDL_iconv_string(tocode, fromcode, inbuf.data(), inbuf.size_bytes())};
6110}
6111
6126inline OwnArray<char> iconv_utf8_locale(std::string_view S)
6127{
6128 return iconv_string("", "UTF-8", S);
6129}
6130
6145inline OwnArray<Uint16> iconv_utf8_ucs2(std::string_view S)
6146{
6147 auto data = SDL_iconv_string("UCS-2", "UTF-8", S.data(), S.size());
6148 return OwnArray<Uint16>(reinterpret_cast<Uint16*>(data));
6149}
6150
6165inline OwnArray<Uint32> iconv_utf8_ucs4(std::string_view S)
6166{
6167 auto data = SDL_iconv_string("UCS-4", "UTF-8", S.data(), S.size());
6168 return OwnArray<Uint32>(reinterpret_cast<Uint32*>(data));
6169}
6170
6185inline OwnArray<char> iconv_wchar_utf8(std::wstring_view S)
6186{
6187 return iconv_string("UTF-8", "WCHAR_T", S);
6188}
6189
6207inline bool size_mul_check_overflow(size_t a, size_t b, size_t* ret)
6208{
6209 return SDL_size_mul_check_overflow(a, b, ret);
6210}
6211
6229inline bool size_add_check_overflow(size_t a, size_t b, size_t* ret)
6230{
6231 return SDL_size_add_check_overflow(a, b, ret);
6232}
6233
6249using FunctionPointer = void(SDLCALL*)();
6250
6252
6253inline void PtrDeleter::operator()(void* ptr) const { SDL_free(ptr); }
6254
6256template<std::integral T>
6258{
6259 if constexpr (std::is_signed_v<T>) {
6260 SDL_assert_paranoid(value >= std::numeric_limits<Sint32>::min() &&
6261 value <= std::numeric_limits<Sint32>::max());
6262 } else {
6263 SDL_assert_paranoid(value <= std::numeric_limits<Sint32>::max());
6264 }
6265 return static_cast<Sint32>(value);
6266}
6267
6269template<std::integral T>
6271{
6272 SDL_assert_paranoid(value <= std::numeric_limits<Uint32>::max());
6273 return static_cast<Uint32>(value);
6274}
6275
6276} // namespace SDL
6277
6278#endif /* SDL3PP_STDINC_H_ */
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
A independent pseudo random state.
Definition SDL3pp_stdinc.h:4223
constexpr Random(Uint64 state)
Init state with the given value.
Definition SDL3pp_stdinc.h:4234
float randf()
Generate a uniform pseudo-random floating point number less than 1.0.
Definition SDL3pp_stdinc.h:4297
constexpr Random()
Default constructor initializes state to zero.
Definition SDL3pp_stdinc.h:4228
Uint32 rand_bits()
Generate 32 pseudo-random bits.
Definition SDL3pp_stdinc.h:4320
Sint32 rand(Sint32 n)
Generate a pseudo-random number less than n for positive n.
Definition SDL3pp_stdinc.h:4273
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
Source byte stream.
Definition SDL3pp_strings.h:237
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:301
constexpr const char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:304
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
SDL times are signed, 64-bit integers representing nanoseconds since the Unix epoch (Jan 1,...
Definition SDL3pp_stdinc.h:363
constexpr Sint64 ToNS() const
Converts to nanoseconds Sint64.
Definition SDL3pp_stdinc.h:417
constexpr Time & operator+=(std::chrono::nanoseconds interval)
Increment time.
Definition SDL3pp_stdinc.h:491
constexpr float ToSeconds() const
Converts a time to seconds (float) since epoch.
Definition SDL3pp_stdinc.h:481
constexpr Time & operator-=(std::chrono::nanoseconds interval)
Decrement.
Definition SDL3pp_stdinc.h:498
constexpr Time(std::chrono::nanoseconds time) noexcept
Wraps Time.
Definition SDL3pp_stdinc.h:384
constexpr Time(TimeRaw time) noexcept
Wraps Time.
Definition SDL3pp_stdinc.h:374
static constexpr Time FromNS(Sint64 time)
Create from a nanoseconds Sint64.
Definition SDL3pp_stdinc.h:411
static constexpr Time FromSeconds(float interval)
Converts a time to seconds (float) since epoch.
Definition SDL3pp_stdinc.h:484
Concept of interface.
Definition SDL3pp_stdinc.h:531
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:383
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
int wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
Compare two wide strings up to a number of wchar_t values.
Definition SDL3pp_stdinc.h:2693
double log(double x)
Compute the natural logarithm of x.
Definition SDL3pp_stdinc.h:5316
char * UCS4ToUTF8(Uint32 codepoint, char *dst)
Convert a single Unicode codepoint to UTF-8.
Definition SDL3pp_stdinc.h:3932
long wcstol(const wchar_t *str, wchar_t **endp, int base)
Parse a long from a wide string.
Definition SDL3pp_stdinc.h:2798
char * strdup(StringParam str)
Allocate a copy of a string.
Definition SDL3pp_stdinc.h:2957
void SetMemoryFunctions(malloc_func malloc_func, calloc_func calloc_func, realloc_func realloc_func, free_func free_func)
Replace SDL's memory allocation functions with a custom set.
Definition SDL3pp_stdinc.h:845
double strtod(StringParam str, char **endp)
Parse a double from a string.
Definition SDL3pp_stdinc.h:3661
void SetVariable(StringParam name, StringParam value, bool overwrite)
Set the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1230
constexpr Sint8 MIN_SINT8
Min representable value.
Definition SDL3pp_stdinc.h:231
char * strcasestr(StringParam haystack, StringParam needle)
Search a UTF-8 string for the first instance of a specific substring, case-insensitively.
Definition SDL3pp_stdinc.h:3164
void UnsetVariable(StringParam name)
Clear a variable from the environment.
Definition SDL3pp_stdinc.h:1261
double atan(double x)
Compute the arc tangent of x.
Definition SDL3pp_stdinc.h:4735
int asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt,...)
This works exactly like asprintf() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:4157
double ceil(double x)
Compute the ceiling of x.
Definition SDL3pp_stdinc.h:4863
void SetEnvironmentVariable(EnvironmentRef env, StringParam name, StringParam value, bool overwrite)
Set the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1222
char * strlwr(char *str)
Convert a string to lowercase.
Definition SDL3pp_stdinc.h:3048
void * memmove(void *dst, const void *src, size_t len)
Copy memory ranges that might overlap.
Definition SDL3pp_stdinc.h:2309
::Sint32 Sint32
A signed 32-bit integer type.
Definition SDL3pp_stdinc.h:277
int memcmp(const void *s1, const void *s2, size_t len)
Compare two buffers of memory.
Definition SDL3pp_stdinc.h:2451
constexpr Uint16 MIN_UINT16
Min representable value.
Definition SDL3pp_stdinc.h:270
std::chrono::nanoseconds Nanoseconds
Duration in Nanoseconds (Uint64).
Definition SDL3pp_stdinc.h:332
constexpr std::size_t arraysize(const T(&array)[N])
The number of elements in a static array.
Definition SDL3pp_stdinc.h:154
char * strnstr(StringParam haystack, StringParam needle, size_t maxlen)
Search a string, up to n bytes, for the first instance of a specific substring.
Definition SDL3pp_stdinc.h:3133
OwnArray< Uint16 > iconv_utf8_ucs2(std::string_view S)
Convert a UTF-8 string to UCS-2.
Definition SDL3pp_stdinc.h:6145
int isnan(double x)
Return whether the value is NaN.
Definition SDL3pp_stdinc.h:5273
constexpr Uint32 INVALID_UNICODE_CODEPOINT
The Unicode REPLACEMENT CHARACTER codepoint.
Definition SDL3pp_stdinc.h:3825
double scalbn(double x, int n)
Scale x by an integer power of two.
Definition SDL3pp_stdinc.h:5643
char * ultoa(unsigned long value, char *str, int radix)
Convert an unsigned long integer into a string.
Definition SDL3pp_stdinc.h:3376
wchar_t * wcsdup(const wchar_t *wstr)
Allocate a copy of a wide string.
Definition SDL3pp_stdinc.h:2592
int isgraph(int x)
Report if a character is any "printable" except space.
Definition SDL3pp_stdinc.h:2119
constexpr Sint16 MIN_SINT16
Min representable value.
Definition SDL3pp_stdinc.h:257
OwnArray< char * > GetVariables()
Get all variables in the environment.
Definition SDL3pp_stdinc.h:1197
int strncmp(StringParam str1, StringParam str2, size_t maxlen)
Compare two UTF-8 strings up to a number of bytes.
Definition SDL3pp_stdinc.h:3715
double asin(double x)
Compute the arc sine of x.
Definition SDL3pp_stdinc.h:4675
Uint16 crc16(Uint16 crc, const void *data, size_t len)
Calculate a CRC-16 value.
Definition SDL3pp_stdinc.h:2176
char * strrev(char *str)
Reverse a string's contents.
Definition SDL3pp_stdinc.h:3006
int strncasecmp(StringParam str1, StringParam str2, size_t maxlen)
Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
Definition SDL3pp_stdinc.h:3786
constexpr T min(T x, U y)
Return the lesser of two values.
Definition SDL3pp_stdinc.h:1866
unsigned long strtoul(StringParam str, char **endp, int base)
Parse an unsigned long from a string.
Definition SDL3pp_stdinc.h:3555
int isdigit(int x)
Report if a character is a numeric digit.
Definition SDL3pp_stdinc.h:1994
double exp(double x)
Compute the exponential of x.
Definition SDL3pp_stdinc.h:5026
char * strstr(StringParam haystack, StringParam needle)
Search a string for the first instance of a specific substring.
Definition SDL3pp_stdinc.h:3107
constexpr Uint32 MAX_UINT32
Max representable value.
Definition SDL3pp_stdinc.h:293
IConv iconv_open(StringParam tocode, StringParam fromcode)
This function allocates a context for the specified character set conversion.
Definition SDL3pp_stdinc.h:5987
int vsnprintf(char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
This works exactly like vsnprintf() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:4096
char * strchr(StringParam str, int c)
Search a string for the first instance of a specific byte.
Definition SDL3pp_stdinc.h:3068
double copysign(double x, double y)
Copy the sign of one floating-point value to another.
Definition SDL3pp_stdinc.h:4916
Environment CreateEnvironment(bool populated)
Create a set of environment variables.
Definition SDL3pp_stdinc.h:1135
void * malloc(size_t size)
Allocate uninitialized memory.
Definition SDL3pp_stdinc.h:602
constexpr float FLT_EPSILON
Epsilon constant, used for comparing floating-point numbers.
Definition SDL3pp_stdinc.h:521
double modf(double x, double *y)
Split x into integer and fractional parts.
Definition SDL3pp_stdinc.h:5422
void zero(T &x)
Clear an object's memory to zero.
Definition SDL3pp_stdinc.h:2386
size_t strlcat(char *dst, StringParam src, size_t maxlen)
Concatenate strings.
Definition SDL3pp_stdinc.h:2936
void zeroa(T(&x)[N])
Clear an array's memory to zero.
Definition SDL3pp_stdinc.h:2432
char * strndup(StringParam str, size_t maxlen)
Allocate a copy of a string, up to n characters.
Definition SDL3pp_stdinc.h:2982
constexpr Uint8 MIN_UINT64
Min representable value.
Definition SDL3pp_stdinc.h:326
size_t iconv(IConvRaw cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
This function converts text between encodings, reading from and writing to a buffer.
Definition SDL3pp_stdinc.h:6052
void(SDLCALL *)() FunctionPointer
A generic function pointer.
Definition SDL3pp_stdinc.h:6249
int snprintf(char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt,...)
This works exactly like snprintf() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:4017
double round(double x)
Round x to the nearest integer.
Definition SDL3pp_stdinc.h:5531
int sscanf(StringParam text, SDL_SCANF_FORMAT_STRING const char *fmt,...)
This works exactly like sscanf() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:3952
size_t strlcpy(char *dst, StringParam src, size_t maxlen)
Copy a string.
Definition SDL3pp_stdinc.h:2874
void * memset(void *dst, int c, size_t len)
Initialize all bytes of buffer of memory to a specific value.
Definition SDL3pp_stdinc.h:2336
constexpr Uint64 MAX_UINT64
Max representable value.
Definition SDL3pp_stdinc.h:323
bool size_mul_check_overflow(size_t a, size_t b, size_t *ret)
Multiply two integers, checking for overflow.
Definition SDL3pp_stdinc.h:6207
int iconv_close(IConvRaw cd)
This function frees a context used for character set conversion.
Definition SDL3pp_stdinc.h:6012
void GetOriginalMemoryFunctions(malloc_func *malloc_func, calloc_func *calloc_func, realloc_func *realloc_func, free_func *free_func)
Get the original set of SDL memory functions.
Definition SDL3pp_stdinc.h:786
int strcmp(StringParam str1, StringParam str2)
Compare two null-terminated UTF-8 strings.
Definition SDL3pp_stdinc.h:3683
::Sint64 Sint64
A signed 64-bit integer type.
Definition SDL3pp_stdinc.h:305
SDL_Time TimeRaw
Alias to raw representation for Time.
Definition SDL3pp_stdinc.h:43
bool size_add_check_overflow(size_t a, size_t b, size_t *ret)
Add two integers, checking for overflow.
Definition SDL3pp_stdinc.h:6229
void UnsetEnvironmentVariable(EnvironmentRef env, StringParam name)
Clear a variable from the environment.
Definition SDL3pp_stdinc.h:1256
SDL_iconv_t IConvRaw
Alias to raw representation for IConv.
Definition SDL3pp_stdinc.h:65
std::function< int(const void *a, const void *b)> CompareCB
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1527
char * uitoa(unsigned int value, char *str, int radix)
Convert an unsigned integer into a string.
Definition SDL3pp_stdinc.h:3316
double pow(double x, double y)
Raise x to the power y.
Definition SDL3pp_stdinc.h:5472
constexpr T * copyp(T *dst, const U *src)
A macro to copy memory between objects, with basic type checking.
Definition SDL3pp_stdinc.h:2286
constexpr Sint32 MIN_SINT32
Min representable value.
Definition SDL3pp_stdinc.h:283
EnvironmentRaw GetEnvironment()
Get the process environment.
Definition SDL3pp_stdinc.h:1113
int isprint(int x)
Report if a character is "printable".
Definition SDL3pp_stdinc.h:2098
long lround(double x)
Round x to the nearest integer representable as a long.
Definition SDL3pp_stdinc.h:5589
int isxdigit(int x)
Report if a character is a hexadecimal digit.
Definition SDL3pp_stdinc.h:2009
constexpr T max(T x, U y)
Return the greater of two values.
Definition SDL3pp_stdinc.h:1888
int atoi(StringParam str)
Parse an int from a string.
Definition SDL3pp_stdinc.h:3466
OwnArray< char > iconv_string(StringParam tocode, StringParam fromcode, SourceBytes inbuf)
Helper function to convert a string's encoding in one call.
Definition SDL3pp_stdinc.h:6104
int tolower(int x)
Convert low-ASCII English letters to lowercase.
Definition SDL3pp_stdinc.h:2155
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition SDL3pp_stdinc.h:264
int isalpha(int x)
Query if a character is alphabetic (a letter).
Definition SDL3pp_stdinc.h:1934
constexpr size_t ICONV_E2BIG
Output buffer was too small.
Definition SDL3pp_stdinc.h:6072
OwnArray< char > iconv_utf8_locale(std::string_view S)
Convert a UTF-8 string to the current locale's character encoding.
Definition SDL3pp_stdinc.h:6126
OwnArray< Uint32 > iconv_utf8_ucs4(std::string_view S)
Convert a UTF-8 string to UCS-4.
Definition SDL3pp_stdinc.h:6165
int unsetenv_unsafe(StringParam name)
Clear a variable from the environment.
Definition SDL3pp_stdinc.h:1362
constexpr float ToSeconds(Seconds duration)
Converts a time duration to seconds (float).
Definition SDL3pp_stdinc.h:338
char * strupr(char *str)
Convert a string to uppercase.
Definition SDL3pp_stdinc.h:3027
ResourceRef< Environment > EnvironmentRef
Reference for Environment.
Definition SDL3pp_stdinc.h:59
int close()
This function frees a context used for character set conversion.
Definition SDL3pp_stdinc.h:6014
size_t utf8strlen(StringParam str)
Count the number of codepoints in a UTF-8 string.
Definition SDL3pp_stdinc.h:3224
constexpr Seconds FromSeconds(float duration)
Converts a float to seconds representation.
Definition SDL3pp_stdinc.h:341
size_t utf8strnlen(StringParam str, size_t bytes)
Count the number of codepoints in a UTF-8 string, up to n bytes.
Definition SDL3pp_stdinc.h:3256
int vswprintf(wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap)
This works exactly like vswprintf() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:4123
int isupper(int x)
Report if a character is upper case.
Definition SDL3pp_stdinc.h:2064
size_t wcsnlen(const wchar_t *wstr, size_t maxlen)
This works exactly like wcsnlen() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:2510
double sqrt(double x)
Compute the square root of x.
Definition SDL3pp_stdinc.h:5747
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:290
void *(SDLCALL *)(size_t nmemb, size_t size) calloc_func
A callback used to implement calloc().
Definition SDL3pp_stdinc.h:728
constexpr Sint16 MAX_SINT16
Max representable value.
Definition SDL3pp_stdinc.h:254
void srand(Uint64 seed)
Seeds the pseudo-random number generator.
Definition SDL3pp_stdinc.h:4210
constexpr Uint8 MAX_UINT8
Max representable value.
Definition SDL3pp_stdinc.h:241
double tan(double x)
Compute the tangent of x.
Definition SDL3pp_stdinc.h:5801
double sin(double x)
Compute the sine of x.
Definition SDL3pp_stdinc.h:5695
constexpr size_t ICONV_EILSEQ
Invalid input sequence was encountered.
Definition SDL3pp_stdinc.h:6075
const char * getenv_unsafe(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1323
size_t utf8strlcpy(char *dst, StringParam src, size_t dst_bytes)
Copy an UTF-8 string.
Definition SDL3pp_stdinc.h:2905
constexpr Sint64 MIN_SINT64
Min representable value.
Definition SDL3pp_stdinc.h:311
char * strtok_r(char *str, StringParam delim, char **saveptr)
This works exactly like strtok_r() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:3195
void * memset4(void *dst, Uint32 val, size_t dwords)
Initialize all 32-bit words of buffer of memory to a specific value.
Definition SDL3pp_stdinc.h:2363
constexpr size_t ICONV_ERROR
Generic error. Check GetError()?
Definition SDL3pp_stdinc.h:6069
void(SDLCALL *)(void *mem) free_func
A callback used to implement free().
Definition SDL3pp_stdinc.h:767
int iscntrl(int x)
Report if a character is a control character.
Definition SDL3pp_stdinc.h:1979
int swprintf(wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt,...)
This works exactly like swprintf() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:4063
constexpr double PI_D
The value of Pi, as a double-precision floating point literal.
Definition SDL3pp_stdinc.h:4579
int islower(int x)
Report if a character is lower case.
Definition SDL3pp_stdinc.h:2079
int isinf(double x)
Return whether the value is infinity.
Definition SDL3pp_stdinc.h:5245
int isspace(int x)
Report if a character is whitespace.
Definition SDL3pp_stdinc.h:2049
void DestroyEnvironment(EnvironmentRaw env)
Destroy a set of environment variables.
Definition SDL3pp_stdinc.h:1278
size_t strnlen(StringParam str, size_t maxlen)
This works exactly like strnlen() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:2844
int strcasecmp(StringParam str1, StringParam str2)
Compare two null-terminated UTF-8 strings, case-insensitively.
Definition SDL3pp_stdinc.h:3745
size_t strlen(StringParam str)
This works exactly like strlen() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:2821
constexpr Uint16 MAX_UINT16
Max representable value.
Definition SDL3pp_stdinc.h:267
const char * GetVariable(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1168
const char * getenv(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1300
int setenv_unsafe(StringParam name, StringParam value, int overwrite)
Set the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1344
constexpr void InitInterface(I *iface)
A macro to initialize an SDL interface.
Definition SDL3pp_stdinc.h:572
::Sint16 Sint16
A signed 16-bit integer type.
Definition SDL3pp_stdinc.h:251
int wcscmp(const wchar_t *str1, const wchar_t *str2)
Compare two null-terminated wide strings.
Definition SDL3pp_stdinc.h:2661
double acos(double x)
Compute the arc cosine of x.
Definition SDL3pp_stdinc.h:4617
Sint32 rand(Sint32 n)
Generate a pseudo-random number less than n for positive n.
Definition SDL3pp_stdinc.h:4353
constexpr Sint64 MAX_SINT64
Max representable value.
Definition SDL3pp_stdinc.h:308
void qsort_r(void *base, size_t nmemb, size_t size, CompareCallback_r compare, void *userdata)
Sort an array, passing a userdata pointer to the compare function.
Definition SDL3pp_stdinc.h:1581
double floor(double x)
Compute the floor of x.
Definition SDL3pp_stdinc.h:5085
void *(SDLCALL *)(size_t size) malloc_func
A callback used to implement malloc().
Definition SDL3pp_stdinc.h:707
Uint32 StepUTF8(const char **pstr, size_t *pslen)
Decode a UTF-8 string, one Unicode codepoint at a time.
Definition SDL3pp_stdinc.h:3868
int toupper(int x)
Convert low-ASCII English letters to uppercase.
Definition SDL3pp_stdinc.h:2137
Uint32 murmur3_32(const void *data, size_t len, Uint32 seed)
Calculate a 32-bit MurmurHash3 value for a block of data.
Definition SDL3pp_stdinc.h:2229
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:238
std::chrono::duration< float > Seconds
Duration in seconds (float).
Definition SDL3pp_stdinc.h:329
constexpr Uint32 FourCC(Uint8 a, Uint8 b, Uint8 c, Uint8 d)
Define a four character code as a Uint32.
Definition SDL3pp_stdinc.h:185
Uint32 StepBackUTF8(StringParam start, const char **pstr)
Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
Definition SDL3pp_stdinc.h:3900
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
Copy a wide string.
Definition SDL3pp_stdinc.h:2540
float randf()
Generate a uniform pseudo-random floating point number less than 1.0.
Definition SDL3pp_stdinc.h:4445
constexpr T clamp(T x, U a, V b)
Return a value clamped to a range.
Definition SDL3pp_stdinc.h:1916
constexpr Time MAX_TIME
Max allowed time representation.
Definition SDL3pp_stdinc.h:506
constexpr Nanoseconds FromNS(Sint64 duration)
Converts a Sint64 to nanoseconds representation.
Definition SDL3pp_stdinc.h:347
int wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
Compare two wide strings, case-insensitively, up to a number of wchar_t.
Definition SDL3pp_stdinc.h:2769
void aligned_free(void *mem)
Free memory allocated by aligned_alloc().
Definition SDL3pp_stdinc.h:897
void zerop(T *x)
Clear an object's memory to zero, using a pointer.
Definition SDL3pp_stdinc.h:2409
int abs(int x)
Compute the absolute value of x.
Definition SDL3pp_stdinc.h:1805
void * calloc(size_t nmemb, size_t size)
Allocate a zero-initialized array.
Definition SDL3pp_stdinc.h:627
void GetMemoryFunctions(malloc_func *malloc_func, calloc_func *calloc_func, realloc_func *realloc_func, free_func *free_func)
Get the current set of SDL memory functions.
Definition SDL3pp_stdinc.h:812
OwnArray< char * > GetEnvironmentVariables(EnvironmentRef env)
Get all variables in the environment.
Definition SDL3pp_stdinc.h:1192
void qsort(void *base, size_t nmemb, size_t size, CompareCallback compare)
Sort an array.
Definition SDL3pp_stdinc.h:1427
constexpr Time MIN_TIME
Min allowed time representation.
Definition SDL3pp_stdinc.h:509
constexpr Sint64 ToNS(Nanoseconds duration)
Converts a time duration to nanoseconds (Sint64);.
Definition SDL3pp_stdinc.h:344
SDL_Environment * EnvironmentRaw
Alias to raw representation for Environment.
Definition SDL3pp_stdinc.h:52
int isblank(int x)
Report if a character is blank (a space or tab).
Definition SDL3pp_stdinc.h:1964
void * realloc(void *mem, size_t size)
Change the size of allocated memory.
Definition SDL3pp_stdinc.h:668
int vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
This works exactly like vasprintf() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:4186
::Sint8 Sint8
A signed 8-bit integer type.
Definition SDL3pp_stdinc.h:225
char * itoa(int value, char *str, int radix)
Convert an integer into a string.
Definition SDL3pp_stdinc.h:3286
int ispunct(int x)
Report if a character is a punctuation mark.
Definition SDL3pp_stdinc.h:2027
int vsscanf(StringParam text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap)
This works exactly like vsscanf() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:3980
constexpr Uint8 MIN_UINT8
Min representable value.
Definition SDL3pp_stdinc.h:244
ResourceRef< IConv > IConvRef
Reference for IConv.
Definition SDL3pp_stdinc.h:72
int(SDLCALL *)(const void *a, const void *b) CompareCallback
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1381
wchar_t * wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen)
Search a wide string, up to n wide chars, for the first instance of a specific substring.
Definition SDL3pp_stdinc.h:2638
Uint32 crc32(Uint32 crc, const void *data, size_t len)
Calculate a CRC-32 value.
Definition SDL3pp_stdinc.h:2200
double log10(double x)
Compute the base-10 logarithm of x.
Definition SDL3pp_stdinc.h:5373
const char * GetEnvironmentVariable(EnvironmentRef env, StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1163
constexpr float PI_F
The value of Pi, as a single-precision floating point literal.
Definition SDL3pp_stdinc.h:4588
void Destroy()
Destroy a set of environment variables.
Definition SDL3pp_stdinc.h:1283
wchar_t * wcsstr(const wchar_t *haystack, const wchar_t *needle)
Search a wide string for the first instance of a specific substring.
Definition SDL3pp_stdinc.h:2612
void * bsearch(const void *key, const void *base, size_t nmemb, size_t size, CompareCallback compare)
Perform a binary search on a previously sorted array.
Definition SDL3pp_stdinc.h:1484
std::chrono::milliseconds Milliseconds
Duration in Miliseconds (Uint32).
Definition SDL3pp_stdinc.h:335
double cos(double x)
Compute the cosine of x.
Definition SDL3pp_stdinc.h:4968
void free(void *mem)
Free allocated memory.
Definition SDL3pp_stdinc.h:688
double atan2(double y, double x)
Compute the arc tangent of y / x, using the signs of x and y to adjust the result's quadrant.
Definition SDL3pp_stdinc.h:4800
void *(SDLCALL *)(void *mem, size_t size) realloc_func
A callback used to implement realloc().
Definition SDL3pp_stdinc.h:749
int wcscasecmp(const wchar_t *str1, const wchar_t *str2)
Compare two null-terminated wide strings, case-insensitively.
Definition SDL3pp_stdinc.h:2725
char * strpbrk(StringParam str, StringParam breakset)
Searches a string for the first occurrence of any character contained in a breakset,...
Definition SDL3pp_stdinc.h:3807
void * aligned_alloc(size_t alignment, size_t size)
Allocate memory aligned to a specific alignment.
Definition SDL3pp_stdinc.h:876
int GetNumAllocations()
Get the number of outstanding (unfreed) allocations.
Definition SDL3pp_stdinc.h:908
Uint32 rand_bits()
Generate 32 pseudo-random bits.
Definition SDL3pp_stdinc.h:4520
constexpr Sint8 MAX_SINT8
Max representable value.
Definition SDL3pp_stdinc.h:228
constexpr Uint8 MIN_UINT32
Min representable value.
Definition SDL3pp_stdinc.h:296
double trunc(double x)
Truncate x to an integer.
Definition SDL3pp_stdinc.h:5142
int(SDLCALL *)(void *userdata, const void *a, const void *b) CompareCallback_r
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1508
char * ltoa(long value, char *str, int radix)
Convert a long integer into a string.
Definition SDL3pp_stdinc.h:3346
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
Concatenate wide strings.
Definition SDL3pp_stdinc.h:2571
double atof(StringParam str)
Parse a double from a string.
Definition SDL3pp_stdinc.h:3487
constexpr size_t ICONV_EINVAL
Incomplete input sequence was encountered.
Definition SDL3pp_stdinc.h:6078
constexpr Sint32 MAX_SINT32
Max representable value.
Definition SDL3pp_stdinc.h:280
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:320
void * bsearch_r(const void *key, const void *base, size_t nmemb, size_t size, CompareCallback_r compare, void *userdata)
Perform a binary search on a previously sorted array, passing a userdata pointer to the compare funct...
Definition SDL3pp_stdinc.h:1711
long strtol(StringParam str, char **endp, int base)
Parse a long from a string.
Definition SDL3pp_stdinc.h:3520
OwnArray< char > iconv_wchar_utf8(std::wstring_view S)
Convert a wchar_t string to UTF-8.
Definition SDL3pp_stdinc.h:6185
size_t iconv(const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) const
This function converts text between encodings, reading from and writing to a buffer.
Definition SDL3pp_stdinc.h:6061
char * strrchr(StringParam str, int c)
Search a string for the last instance of a specific byte.
Definition SDL3pp_stdinc.h:3087
size_t wcslen(const wchar_t *wstr)
This works exactly like wcslen() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:2480
int isalnum(int x)
Query if a character is alphabetic (a letter) or a number.
Definition SDL3pp_stdinc.h:1949
double fmod(double x, double y)
Return the floating-point remainder of x / y.
Definition SDL3pp_stdinc.h:5201
void * memcpy(void *dst, const void *src, size_t len)
Copy non-overlapping memory.
Definition SDL3pp_stdinc.h:2252
static Time FromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime)
Converts a Windows FILETIME (100-nanosecond intervals since January 1, 1601) to an SDL time.
Definition SDL3pp_time.h:411
void ToWindows(Uint32 *dwLowDateTime, Uint32 *dwHighDateTime) const
Converts an SDL time into a Windows FILETIME (100-nanosecond intervals since January 1,...
Definition SDL3pp_time.h:406
static Time Current()
Gets the current value of the system realtime clock in nanoseconds since Jan 1, 1970 in Universal Coo...
Definition SDL3pp_time.h:351
constexpr Sint64 ToPosix() const
Convert nanoseconds to seconds.
Definition SDL3pp_timer.h:31
static constexpr Time FromPosix(Sint64 time)
Convert seconds to nanoseconds.
Definition SDL3pp_timer.h:26
Main include header for the SDL3pp library.
Uint32 narrowU32(T value)
Narrows to Uint32.
Definition SDL3pp_stdinc.h:6270
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6257
A thread-safe set of environment variables.
Definition SDL3pp_stdinc.h:926
constexpr Environment(EnvironmentRaw resource) noexcept
Constructs from raw Environment.
Definition SDL3pp_stdinc.h:936
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
Uint64 GetVariableCount()
Get the Variables count.
Definition SDL3pp_stdinc.h:1048
constexpr Environment & operator=(Environment &&other) noexcept
Assignment operator.
Definition SDL3pp_stdinc.h:980
Environment & operator=(const Environment &other)=delete
Assignment operator.
constexpr Environment(const Environment &other)=delete
Copy constructor.
~Environment()
Destructor.
Definition SDL3pp_stdinc.h:977
constexpr Environment(Environment &&other) noexcept
Move constructor.
Definition SDL3pp_stdinc.h:945
An opaque handle representing string encoding conversion state.
Definition SDL3pp_stdinc.h:5843
IConv(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition SDL3pp_stdinc.h:5847
IConv & operator=(const IConv &other)=delete
Assignment operator.
constexpr IConv & operator=(IConv &&other) noexcept
Assignment operator.
Definition SDL3pp_stdinc.h:5899
~IConv()
Destructor.
Definition SDL3pp_stdinc.h:5896
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
constexpr IConv(const IConv &other)=delete
Copy constructor.
constexpr IConv(IConvRaw resource) noexcept
Constructs from raw IConv.
Definition SDL3pp_stdinc.h:5859
constexpr IConv(IConv &&other) noexcept
Move constructor.
Definition SDL3pp_stdinc.h:5868
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156