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 <SDL3/SDL_stdinc.h>
6#include "SDL3pp_callbackWrapper.h"
7#include "SDL3pp_error.h"
8#include "SDL3pp_optionalRef.h"
9#include "SDL3pp_ownPtr.h"
10#include "SDL3pp_spanRef.h"
11#include "SDL3pp_strings.h"
12
13namespace SDL {
14
42using TimeRaw = SDL_Time;
43
44// Forward decl
45struct Time;
46
47// Forward decl
48struct Environment;
49
51using EnvironmentRaw = SDL_Environment*;
52
53// Forward decl
54struct EnvironmentRef;
55
58{
60
63 : value(value)
64 {
65 }
66
68 constexpr EnvironmentParam(std::nullptr_t _ = nullptr)
69 : value(nullptr)
70 {
71 }
72
74 constexpr explicit operator bool() const { return !!value; }
75
77 constexpr auto operator<=>(const EnvironmentParam& other) const = default;
78
80 constexpr operator EnvironmentRaw() const { return value; }
81};
82
83// Forward decl
84struct IConv;
85
87using IConvRaw = SDL_iconv_t;
88
89// Forward decl
90struct IConvRef;
91
94{
96
99 : value(value)
100 {
101 }
102
104 constexpr IConvParam(std::nullptr_t _ = nullptr)
105 : value(nullptr)
106 {
107 }
108
110 constexpr explicit operator bool() const { return !!value; }
111
113 constexpr auto operator<=>(const IConvParam& other) const = default;
114
116 constexpr operator IConvRaw() const { return value; }
117};
118
119#ifdef SDL3PP_DOC
120
137#define SDL_NOLONGLONG 1
138
153#define SDL_SIZE_MAX SIZE_MAX
154
155#endif // SDL3PP_DOC
156
165template<class T, std::size_t N>
166constexpr std::size_t arraysize(const T (&array)[N])
167{
168 return SDL_arraysize(array);
169}
170
171#ifdef SDL3PP_DOC
172
187#define SDL_STRINGIFY_ARG(arg) #arg
188
189#endif // SDL3PP_DOC
190
205constexpr Uint32 FourCC(Uint8 a, Uint8 b, Uint8 c, Uint8 d)
206{
207 return SDL_FOURCC(a, b, c, d);
208}
209
210#ifdef SDL3PP_DOC
211
223#define SDL_SINT64_C(c) c##LL /* or whatever the current compiler uses. */
224
236#define SDL_UINT64_C(c) c##ULL /* or whatever the current compiler uses. */
237
243using Sint8 = Sint8;
244
245#endif // SDL3PP_DOC
246
248constexpr Sint8 MAX_SINT8 = SDL_MAX_SINT8;
249
251constexpr Sint8 MIN_SINT8 = SDL_MIN_SINT8;
252
253#ifdef SDL3PP_DOC
254
260using Uint8 = Uint8;
261
262#endif // SDL3PP_DOC
263
265constexpr Uint8 MAX_UINT8 = SDL_MAX_UINT8;
266
268constexpr Uint8 MIN_UINT8 = SDL_MIN_UINT8;
269
270#ifdef SDL3PP_DOC
271
278
279#endif // SDL3PP_DOC
280
282constexpr Sint16 MAX_SINT16 = SDL_MAX_SINT16;
283
285constexpr Sint16 MIN_SINT16 = SDL_MIN_SINT16;
286
287#ifdef SDL3PP_DOC
288
295
296#endif // SDL3PP_DOC
297
299constexpr Uint16 MAX_UINT16 = SDL_MAX_UINT16;
300
302constexpr Uint16 MIN_UINT16 = SDL_MIN_UINT16;
303
304#ifdef SDL3PP_DOC
305
312
313#endif // SDL3PP_DOC
314
316constexpr Sint32 MAX_SINT32 = SDL_MAX_SINT32;
317
319constexpr Sint32 MIN_SINT32 = SDL_MIN_SINT32;
320
321#ifdef SDL3PP_DOC
322
329
330#endif // SDL3PP_DOC
331
333constexpr Uint32 MAX_UINT32 = SDL_MAX_UINT32;
334
336constexpr Uint8 MIN_UINT32 = SDL_MIN_UINT32;
337
338#ifdef SDL3PP_DOC
339
348
349#endif // SDL3PP_DOC
350
352constexpr Sint64 MAX_SINT64 = SDL_MAX_SINT64;
353
355constexpr Sint64 MIN_SINT64 = SDL_MIN_SINT64;
356
357#ifdef SDL3PP_DOC
358
367
368#endif // SDL3PP_DOC
369
371constexpr Uint64 MAX_UINT64 = SDL_MAX_UINT64;
372
374constexpr Uint8 MIN_UINT64 = SDL_MIN_UINT64;
375
377using Seconds = std::chrono::duration<float>;
378
380using Nanoseconds = std::chrono::nanoseconds;
381
383using Milliseconds = std::chrono::milliseconds;
384
386constexpr float ToSeconds(Seconds duration) { return duration.count(); }
387
389constexpr Seconds FromSeconds(float duration) { return Seconds(duration); }
390
392constexpr Sint64 ToNS(Nanoseconds duration) { return duration.count(); }
393
395constexpr Nanoseconds FromNS(Sint64 duration) { return Nanoseconds{duration}; }
396
410class Time
411{
412 Nanoseconds m_time;
413
414public:
415 constexpr Time() = default;
416
422 constexpr explicit Time(TimeRaw time)
423 : m_time(time)
424 {
425 }
426
432 constexpr Time(std::chrono::nanoseconds time)
433 : m_time(time)
434 {
435 }
436
438 constexpr explicit operator bool() const
439 {
440 return m_time != std::chrono::nanoseconds{};
441 }
442
444 constexpr operator std::chrono::nanoseconds() const { return m_time; }
445
454 static Time Current();
455
457 static constexpr Time FromNS(Sint64 time)
458 {
459 return Time{std::chrono::nanoseconds{time}};
460 }
461
463 constexpr Sint64 ToNS() const { return m_time.count(); }
464
477 static constexpr Time FromPosix(Sint64 time);
478
490 constexpr Sint64 ToPosix() const;
491
505 static Time FromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime);
506
520 void ToWindows(Uint32* dwLowDateTime, Uint32* dwHighDateTime) const;
521
523 constexpr float ToSeconds() const { return Seconds(m_time).count(); }
524
526 static constexpr Time FromSeconds(float interval)
527 {
528 return std::chrono::duration_cast<std::chrono::nanoseconds>(
529 Seconds(interval));
530 }
531
533 constexpr Time& operator+=(std::chrono::nanoseconds interval)
534 {
535 m_time += interval;
536 return *this;
537 }
538
540 constexpr Time& operator-=(std::chrono::nanoseconds interval)
541 {
542 m_time -= interval;
543 return *this;
544 }
545};
546
548constexpr Time MAX_TIME = Time::FromNS(SDL_MAX_TIME);
549
551constexpr Time MIN_TIME = Time::FromNS(SDL_MIN_TIME);
552
553#ifdef SDL3PP_DOC
554
563#define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
564
603#define SDL_INIT_INTERFACE(iface) \
604 do { \
605 SDL_zerop(iface); \
606 (iface)->version = sizeof(*(iface)); \
607 } while (0)
608
609#endif // SDL3PP_DOC
610
637inline void* malloc(size_t size) { return SDL_malloc(size); }
638
662inline void* calloc(size_t nmemb, size_t size)
663{
664 return SDL_calloc(nmemb, size);
665}
666
705inline void* realloc(void* mem, size_t size) { return SDL_realloc(mem, size); }
706
725inline void free(void* mem) { SDL_free(mem); }
726
744using malloc_func = SDL_malloc_func;
745
765using calloc_func = SDL_calloc_func;
766
786using realloc_func = SDL_realloc_func;
787
804using free_func = SDL_free_func;
805
827{
828 SDL_GetOriginalMemoryFunctions(
830}
831
853{
854 SDL_GetMemoryFunctions(malloc_func, calloc_func, realloc_func, free_func);
855}
856
886{
888 SDL_SetMemoryFunctions(malloc_func, calloc_func, realloc_func, free_func));
889}
890
913inline void* aligned_alloc(size_t alignment, size_t size)
914{
915 return SDL_aligned_alloc(alignment, size);
916}
917
934inline void aligned_free(void* mem) { SDL_aligned_free(mem); }
935
946inline int GetNumAllocations() { return SDL_GetNumAllocations(); }
947
964{
965 EnvironmentRaw m_resource = nullptr;
966
967public:
969 constexpr Environment() = default;
970
978 constexpr explicit Environment(const EnvironmentRaw resource)
979 : m_resource(resource)
980 {
981 }
982
984 constexpr Environment(const Environment& other) = delete;
985
987 constexpr Environment(Environment&& other)
988 : Environment(other.release())
989 {
990 }
991
992 constexpr Environment(const EnvironmentRef& other) = delete;
993
994 constexpr Environment(EnvironmentRef&& other) = delete;
995
1016 Environment(bool populated)
1017 : m_resource(SDL_CreateEnvironment(populated))
1018 {
1019 }
1020
1022 ~Environment() { SDL_DestroyEnvironment(m_resource); }
1023
1026 {
1027 std::swap(m_resource, other.m_resource);
1028 return *this;
1029 }
1030
1032 constexpr EnvironmentRaw get() const { return m_resource; }
1033
1036 {
1037 auto r = m_resource;
1038 m_resource = nullptr;
1039 return r;
1040 }
1041
1043 constexpr auto operator<=>(const Environment& other) const = default;
1044
1046 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
1047
1049 constexpr explicit operator bool() const { return !!m_resource; }
1050
1052 constexpr operator EnvironmentParam() const { return {m_resource}; }
1053
1065 void Destroy();
1066
1084 const char* GetVariable(StringParam name);
1085
1106
1115 {
1116 Uint64 count = 0;
1117 for (auto& var : GetVariables()) count += 1;
1118 return count;
1119 }
1120
1141 void SetVariable(StringParam name, StringParam value, bool overwrite);
1142
1160 void UnsetVariable(StringParam name);
1161};
1162
1165{
1174 : Environment(resource.value)
1175 {
1176 }
1177
1180 : Environment(other.get())
1181 {
1182 }
1183
1186};
1187
1209inline EnvironmentRaw GetEnvironment() { return SDL_GetEnvironment(); }
1210
1231inline Environment CreateEnvironment(bool populated)
1232{
1233 return Environment(populated);
1234}
1235
1255 StringParam name)
1256{
1257 return SDL_GetEnvironmentVariable(env, name);
1258}
1259
1261{
1262 return SDL::GetEnvironmentVariable(m_resource, std::move(name));
1263}
1264
1285{
1286 return OwnArray<char*>{CheckError(SDL_GetEnvironmentVariables(env))};
1287}
1288
1290{
1291 return SDL::GetEnvironmentVariables(m_resource);
1292}
1293
1316 StringParam name,
1317 StringParam value,
1318 bool overwrite)
1319{
1320 CheckError(SDL_SetEnvironmentVariable(env, name, value, overwrite));
1321}
1322
1324 StringParam value,
1325 bool overwrite)
1326{
1328 m_resource, std::move(name), std::move(value), overwrite);
1329}
1330
1350{
1351 CheckError(SDL_UnsetEnvironmentVariable(env, name));
1352}
1353
1355{
1356 SDL::UnsetEnvironmentVariable(m_resource, std::move(name));
1357}
1358
1372{
1373 SDL_DestroyEnvironment(env);
1374}
1375
1377
1391inline const char* getenv(StringParam name) { return SDL_getenv(name); }
1392
1410inline const char* getenv_unsafe(StringParam name)
1411{
1412 return SDL_getenv_unsafe(name);
1413}
1414
1431inline int setenv_unsafe(StringParam name, StringParam value, int overwrite)
1432{
1433 return SDL_setenv_unsafe(name, value, overwrite);
1434}
1435
1450{
1451 return SDL_unsetenv_unsafe(name);
1452}
1453
1468using CompareCallback = SDL_CompareCallback;
1469
1514inline void qsort(void* base,
1515 size_t nmemb,
1516 size_t size,
1517 CompareCallback compare)
1518{
1519 SDL_qsort(base, nmemb, size, compare);
1520}
1521
1571inline void* bsearch(const void* key,
1572 const void* base,
1573 size_t nmemb,
1574 size_t size,
1575 CompareCallback compare)
1576{
1577 return SDL_bsearch(key, base, nmemb, size, compare);
1578}
1579
1595using CompareCallback_r = SDL_CompareCallback_r;
1596
1612using CompareCB = std::function<int(const void*, const void*)>;
1613
1666inline void qsort_r(void* base,
1667 size_t nmemb,
1668 size_t size,
1669 CompareCallback_r compare,
1670 void* userdata)
1671{
1672 SDL_qsort_r(base, nmemb, size, compare, userdata);
1673}
1674
1726inline void qsort_r(void* base, size_t nmemb, size_t size, CompareCB compare)
1727{
1728 return qsort_r(
1729 base,
1730 nmemb,
1731 size,
1732 [](void* userdata, const void* a, const void* b) {
1733 auto& cb = *static_cast<CompareCB*>(userdata);
1734 return cb(a, b);
1735 },
1736 &compare);
1737}
1738
1796inline void* bsearch_r(const void* key,
1797 const void* base,
1798 size_t nmemb,
1799 size_t size,
1800 CompareCallback_r compare,
1801 void* userdata)
1802{
1803 return SDL_bsearch_r(key, base, nmemb, size, compare, userdata);
1804}
1805
1862inline void* bsearch_r(const void* key,
1863 const void* base,
1864 size_t nmemb,
1865 size_t size,
1866 CompareCB compare)
1867{
1868 return bsearch_r(
1869 key,
1870 base,
1871 nmemb,
1872 size,
1873 [](void* userdata, const void* a, const void* b) {
1874 auto& cb = *static_cast<CompareCB*>(userdata);
1875 return cb(a, b);
1876 },
1877 &compare);
1878}
1879
1890inline int abs(int x) { return SDL_abs(x); }
1891
1911inline double abs(double x) { return SDL_fabs(x); }
1912
1932inline float abs(float x) { return SDL_fabsf(x); }
1933
1950template<class T, class U>
1951constexpr T min(T x, U y)
1952{
1953 return SDL_min(x, y);
1954}
1955
1972template<class T, class U>
1973constexpr T max(T x, U y)
1974{
1975 return SDL_max(x, y);
1976}
1977
2000template<class T, class U, class V>
2001constexpr T clamp(T x, U a, V b)
2002{
2003 return SDL_clamp(x, a, b);
2004}
2005
2019inline int isalpha(int x) { return SDL_isalpha(x); }
2020
2034inline int isalnum(int x) { return SDL_isalnum(x); }
2035
2049inline int isblank(int x) { return SDL_isblank(x); }
2050
2064inline int iscntrl(int x) { return SDL_iscntrl(x); }
2065
2079inline int isdigit(int x) { return SDL_isdigit(x); }
2080
2094inline int isxdigit(int x) { return SDL_isxdigit(x); }
2095
2112inline int ispunct(int x) { return SDL_ispunct(x); }
2113
2134inline int isspace(int x) { return SDL_isspace(x); }
2135
2149inline int isupper(int x) { return SDL_isupper(x); }
2150
2164inline int islower(int x) { return SDL_islower(x); }
2165
2183inline int isprint(int x) { return SDL_isprint(x); }
2184
2204inline int isgraph(int x) { return SDL_isgraph(x); }
2205
2222inline int toupper(int x) { return SDL_toupper(x); }
2223
2240inline int tolower(int x) { return SDL_tolower(x); }
2241
2261inline Uint16 crc16(Uint16 crc, const void* data, size_t len)
2262{
2263 return SDL_crc16(crc, data, len);
2264}
2265
2285inline Uint32 crc32(Uint32 crc, const void* data, size_t len)
2286{
2287 return SDL_crc32(crc, data, len);
2288}
2289
2314inline Uint32 murmur3_32(const void* data, size_t len, Uint32 seed)
2315{
2316 return SDL_murmur3_32(data, len, seed);
2317}
2318
2337inline void* memcpy(void* dst, const void* src, size_t len)
2338{
2339#ifdef SDL_SLOW_MEMCPY
2340 return SDL_memcpy(dst, src, len);
2341#else
2342 return ::memcpy(dst, src, len);
2343#endif // SDL_SLOW_MEMCPY
2344}
2345
2346#ifdef SDL3PP_DOC
2347
2372#define SDL_copyp(dst, src) \
2373 { \
2374 SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof(*(dst)) == sizeof(*(src))); \
2375 } \
2376 SDL_memcpy((dst), (src), sizeof(*(src)))
2377
2378#endif // SDL3PP_DOC
2379
2397inline void* memmove(void* dst, const void* src, size_t len)
2398{
2399#ifdef SDL_SLOW_MEMMOVE
2400 return SDL_memmove(dst, src, len);
2401#else
2402 return ::memmove(dst, src, len);
2403#endif // SDL_SLOW_MEMMOVE
2404}
2405
2424inline void* memset(void* dst, int c, size_t len)
2425{
2426#ifdef SDL_SLOW_MEMSET
2427 return SDL_memset(dst, c, len);
2428#else
2429 return ::memset(dst, c, len);
2430#endif // SDL_SLOW_MEMSET
2431}
2432
2451inline void* memset4(void* dst, Uint32 val, size_t dwords)
2452{
2453 return SDL_memset4(dst, val, dwords);
2454}
2455
2473template<class T>
2474inline void zero(T& x)
2475{
2476 SDL_zero(x);
2477}
2478
2496template<class T>
2497inline void zerop(T* x)
2498{
2499 SDL_zerop(x);
2500}
2501
2519template<class T, std::size_t N>
2520inline void zeroa(T (&x)[N])
2521{
2522 SDL_zeroa(x);
2523}
2524
2539inline int memcmp(const void* s1, const void* s2, size_t len)
2540{
2541 return SDL_memcmp(s1, s2, len);
2542}
2543
2569inline size_t wcslen(const wchar_t* wstr) { return SDL_wcslen(wstr); }
2570
2600inline size_t wcsnlen(const wchar_t* wstr, size_t maxlen)
2601{
2602 return SDL_wcsnlen(wstr, maxlen);
2603}
2604
2630inline size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t maxlen)
2631{
2632 return SDL_wcslcpy(dst, src, maxlen);
2633}
2634
2662inline size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t maxlen)
2663{
2664 return SDL_wcslcat(dst, src, maxlen);
2665}
2666
2683inline wchar_t* wcsdup(const wchar_t* wstr) { return SDL_wcsdup(wstr); }
2684
2703inline wchar_t* wcsstr(const wchar_t* haystack, const wchar_t* needle)
2704{
2705 return SDL_wcsstr(haystack, needle);
2706}
2707
2731inline wchar_t* wcsnstr(const wchar_t* haystack,
2732 const wchar_t* needle,
2733 size_t maxlen)
2734{
2735 return SDL_wcsnstr(haystack, needle, maxlen);
2736}
2737
2755inline int wcscmp(const wchar_t* str1, const wchar_t* str2)
2756{
2757 return SDL_wcscmp(str1, str2);
2758}
2759
2789inline int wcsncmp(const wchar_t* str1, const wchar_t* str2, size_t maxlen)
2790{
2791 return SDL_wcsncmp(str1, str2, maxlen);
2792}
2793
2822inline int wcscasecmp(const wchar_t* str1, const wchar_t* str2)
2823{
2824 return SDL_wcscasecmp(str1, str2);
2825}
2826
2867inline int wcsncasecmp(const wchar_t* str1, const wchar_t* str2, size_t maxlen)
2868{
2869 return SDL_wcsncasecmp(str1, str2, maxlen);
2870}
2871
2897inline long wcstol(const wchar_t* str, wchar_t** endp, int base)
2898{
2899 return SDL_wcstol(str, endp, base);
2900}
2901
2920inline size_t strlen(StringParam str) { return SDL_strlen(str); }
2921
2944inline size_t strnlen(StringParam str, size_t maxlen)
2945{
2946 return SDL_strnlen(str, maxlen);
2947}
2948
2976inline size_t strlcpy(char* dst, StringParam src, size_t maxlen)
2977{
2978 return SDL_strlcpy(dst, src, maxlen);
2979}
2980
3007inline size_t utf8strlcpy(char* dst, StringParam src, size_t dst_bytes)
3008{
3009 return SDL_utf8strlcpy(dst, src, dst_bytes);
3010}
3011
3038inline size_t strlcat(char* dst, StringParam src, size_t maxlen)
3039{
3040 return SDL_strlcat(dst, src, maxlen);
3041}
3042
3059inline char* strdup(StringParam str) { return SDL_strdup(str); }
3060
3084inline char* strndup(StringParam str, size_t maxlen)
3085{
3086 return SDL_strndup(str, maxlen);
3087}
3088
3108inline char* strrev(char* str) { return SDL_strrev(str); }
3109
3129inline char* strupr(char* str) { return SDL_strupr(str); }
3130
3150inline char* strlwr(char* str) { return SDL_strlwr(str); }
3151
3170inline char* strchr(StringParam str, int c) { return SDL_strchr(str, c); }
3171
3189inline char* strrchr(StringParam str, int c) { return SDL_strrchr(str, c); }
3190
3209inline char* strstr(StringParam haystack, StringParam needle)
3210{
3211 return SDL_strstr(haystack, needle);
3212}
3213
3235inline char* strnstr(StringParam haystack, StringParam needle, size_t maxlen)
3236{
3237 return SDL_strnstr(haystack, needle, maxlen);
3238}
3239
3266inline char* strcasestr(StringParam haystack, StringParam needle)
3267{
3268 return SDL_strcasestr(haystack, needle);
3269}
3270
3298inline char* strtok_r(char* str, StringParam delim, char** saveptr)
3299{
3300 return SDL_strtok_r(str, delim, saveptr);
3301}
3302
3329inline size_t utf8strlen(StringParam str) { return SDL_utf8strlen(str); }
3330
3362inline size_t utf8strnlen(StringParam str, size_t bytes)
3363{
3364 return SDL_utf8strnlen(str, bytes);
3365}
3366
3393inline char* itoa(int value, char* str, int radix)
3394{
3395 return SDL_itoa(value, str, radix);
3396}
3397
3424inline char* uitoa(unsigned int value, char* str, int radix)
3425{
3426 return SDL_uitoa(value, str, radix);
3427}
3428
3455inline char* ltoa(long value, char* str, int radix)
3456{
3457 return SDL_ltoa(value, str, radix);
3458}
3459
3486inline char* ultoa(unsigned long value, char* str, int radix)
3487{
3488 return SDL_ultoa(value, str, radix);
3489}
3490
3512inline int atoi(StringParam str) { return SDL_atoi(str); }
3513
3534inline double atof(StringParam str) { return SDL_atof(str); }
3535
3568inline long strtol(StringParam str, char** endp, int base)
3569{
3570 return SDL_strtol(str, endp, base);
3571}
3572
3604inline unsigned long strtoul(StringParam str, char** endp, int base)
3605{
3606 return SDL_strtoul(str, endp, base);
3607}
3608
3636inline double strtod(StringParam str, char** endp)
3637{
3638 return SDL_strtod(str, endp);
3639}
3640
3659inline int strcmp(StringParam str1, StringParam str2)
3660{
3661 return SDL_strcmp(str1, str2);
3662}
3663
3692inline int strncmp(StringParam str1, StringParam str2, size_t maxlen)
3693{
3694 return SDL_strncmp(str1, str2, maxlen);
3695}
3696
3723inline int strcasecmp(StringParam str1, StringParam str2)
3724{
3725 return SDL_strcasecmp(str1, str2);
3726}
3727
3765inline int strncasecmp(StringParam str1, StringParam str2, size_t maxlen)
3766{
3767 return SDL_strncasecmp(str1, str2, maxlen);
3768}
3769
3786inline char* strpbrk(StringParam str, StringParam breakset)
3787{
3788 return SDL_strpbrk(str, breakset);
3789}
3790
3804constexpr Uint32 INVALID_UNICODE_CODEPOINT = SDL_INVALID_UNICODE_CODEPOINT;
3805
3849inline Uint32 StepUTF8(const char** pstr, size_t* pslen)
3850{
3851 return SDL_StepUTF8(pstr, pslen);
3852}
3853
3883inline Uint32 StepBackUTF8(StringParam start, const char** pstr)
3884{
3885 return SDL_StepBackUTF8(start, pstr);
3886}
3887
3915inline char* UCS4ToUTF8(Uint32 codepoint, char* dst)
3916{
3917 return SDL_UCS4ToUTF8(codepoint, dst);
3918}
3919
3935inline int sscanf(StringParam text,
3936 SDL_SCANF_FORMAT_STRING const char* fmt,
3937 ...)
3938{
3939 int rc;
3940 va_list ap;
3941 va_start(ap, fmt);
3942 rc = SDL_vsscanf(text, fmt, ap);
3943 va_end(ap);
3944 return rc;
3945}
3946
3964inline int vsscanf(StringParam text,
3965 SDL_SCANF_FORMAT_STRING const char* fmt,
3966 va_list ap)
3967{
3968 return SDL_vsscanf(text, fmt, ap);
3969}
3970
4002inline int snprintf(char* text,
4003 size_t maxlen,
4004 SDL_PRINTF_FORMAT_STRING const char* fmt,
4005 ...)
4006{
4007 va_list ap;
4008 int result;
4009
4010 va_start(ap, fmt);
4011 result = SDL_vsnprintf(text, maxlen, fmt, ap);
4012 va_end(ap);
4013
4014 return result;
4015}
4016
4049inline int swprintf(wchar_t* text,
4050 size_t maxlen,
4051 SDL_PRINTF_FORMAT_STRING const wchar_t* fmt,
4052 ...)
4053{
4054 va_list ap;
4055 int result;
4056
4057 va_start(ap, fmt);
4058 result = SDL_vswprintf(text, maxlen, fmt, ap);
4059 va_end(ap);
4060
4061 return result;
4062}
4063
4082inline int vsnprintf(char* text,
4083 size_t maxlen,
4084 SDL_PRINTF_FORMAT_STRING const char* fmt,
4085 va_list ap)
4086{
4087 return SDL_vsnprintf(text, maxlen, fmt, ap);
4088}
4089
4109inline int vswprintf(wchar_t* text,
4110 size_t maxlen,
4111 SDL_PRINTF_FORMAT_STRING const wchar_t* fmt,
4112 va_list ap)
4113{
4114 return SDL_vswprintf(text, maxlen, fmt, ap);
4115}
4116
4144inline int asprintf(char** strp, SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
4145{
4146 va_list ap;
4147 int result;
4148
4149 va_start(ap, fmt);
4150 result = SDL_vasprintf(strp, fmt, ap);
4151 va_end(ap);
4152
4153 return result;
4154}
4155
4173inline int vasprintf(char** strp,
4174 SDL_PRINTF_FORMAT_STRING const char* fmt,
4175 va_list ap)
4176{
4177 return SDL_vasprintf(strp, fmt, ap);
4178}
4179
4198inline void srand(Uint64 seed) { SDL_srand(seed); }
4199
4232inline Sint32 rand(Sint32 n) { return SDL_rand(n); }
4233
4255inline float randf() { return SDL_randf(); }
4256
4278inline Uint32 rand_bits() { return SDL_rand_bits(); }
4279
4291{
4292 Uint64 m_state;
4293
4294public:
4295 constexpr Random()
4296 : m_state(0)
4297 {
4298 }
4299
4303 constexpr explicit Random(Uint64 state)
4304 : m_state(state)
4305 {
4306 }
4307
4309 constexpr operator Uint64() { return m_state; }
4310
4342 Sint32 rand(Sint32 n) { return SDL_rand_r(&m_state, n); }
4343
4367 float randf() { return SDL_randf_r(&m_state); }
4368
4390 Uint32 rand_bits() { return SDL_rand_bits_r(&m_state); }
4391};
4392
4426inline Sint32 rand_r(Uint64* state, Sint32 n) { return SDL_rand_r(state, n); }
4427
4453inline float randf_r(Uint64* state) { return SDL_randf_r(state); }
4454
4478inline Uint32 rand_bits_r(Uint64* state) { return SDL_rand_bits_r(state); }
4479
4487constexpr double PI_D = SDL_PI_D;
4488
4496constexpr float PI_F = SDL_PI_F;
4497
4526inline double acos(double x) { return SDL_acos(x); }
4527
4556inline float acos(float x) { return SDL_acosf(x); }
4557
4586inline double asin(double x) { return SDL_asin(x); }
4587
4616inline float asin(float x) { return SDL_asinf(x); }
4617
4648inline double atan(double x) { return SDL_atan(x); }
4649
4680inline float atan(float x) { return SDL_atanf(x); }
4681
4715inline double atan2(double y, double x) { return SDL_atan2(y, x); }
4716
4751inline float atan2(float y, float x) { return SDL_atan2f(y, x); }
4752
4779inline double ceil(double x) { return SDL_ceil(x); }
4780
4807inline float ceil(float x) { return SDL_ceilf(x); }
4808
4833inline double copysign(double x, double y) { return SDL_copysign(x, y); }
4834
4859inline float copysign(float x, float y) { return SDL_copysignf(x, y); }
4860
4887inline double cos(double x) { return SDL_cos(x); }
4888
4915inline float cos(float x) { return SDL_cosf(x); }
4916
4947inline double exp(double x) { return SDL_exp(x); }
4948
4979inline float exp(float x) { return SDL_expf(x); }
4980
5007inline double floor(double x) { return SDL_floor(x); }
5008
5035inline float floor(float x) { return SDL_floorf(x); }
5036
5064inline double trunc(double x) { return SDL_trunc(x); }
5065
5093inline float trunc(float x) { return SDL_truncf(x); }
5094
5123inline double fmod(double x, double y) { return SDL_fmod(x, y); }
5124
5153inline float fmod(float x, float y) { return SDL_fmodf(x, y); }
5154
5167inline int isinf(double x) { return SDL_isinf(x); }
5168
5181inline int isinf(float x) { return SDL_isinff(x); }
5182
5195inline int isnan(double x) { return SDL_isnan(x); }
5196
5209inline int isnan(float x) { return SDL_isnanf(x); }
5210
5239inline double log(double x) { return SDL_log(x); }
5240
5268inline float log(float x) { return SDL_logf(x); }
5269
5298inline double log10(double x) { return SDL_log10(x); }
5299
5328inline float log10(float x) { return SDL_log10f(x); }
5329
5348inline double modf(double x, double* y) { return SDL_modf(x, y); }
5349
5368inline float modf(float x, float* y) { return SDL_modff(x, y); }
5369
5400inline double pow(double x, double y) { return SDL_pow(x, y); }
5401
5432inline float pow(float x, float y) { return SDL_powf(x, y); }
5433
5461inline double round(double x) { return SDL_round(x); }
5462
5490inline float round(float x) { return SDL_roundf(x); }
5491
5519inline long lround(double x) { return SDL_lround(x); }
5520
5548inline long lround(float x) { return SDL_lroundf(x); }
5549
5573inline double scalbn(double x, int n) { return SDL_scalbn(x, n); }
5574
5598inline float scalbn(float x, int n) { return SDL_scalbnf(x, n); }
5599
5626inline double sin(double x) { return SDL_sin(x); }
5627
5654inline float sin(float x) { return SDL_sinf(x); }
5655
5680inline double sqrt(double x) { return SDL_sqrt(x); }
5681
5706inline float sqrt(float x) { return SDL_sqrtf(x); }
5707
5736inline double tan(double x) { return SDL_tan(x); }
5737
5766inline float tan(float x) { return SDL_tanf(x); }
5767
5779{
5780 IConvRaw m_resource = nullptr;
5781
5782public:
5784 constexpr IConv() = default;
5785
5793 constexpr explicit IConv(const IConvRaw resource)
5794 : m_resource(resource)
5795 {
5796 }
5797
5799 constexpr IConv(const IConv& other) = delete;
5800
5802 constexpr IConv(IConv&& other)
5803 : IConv(other.release())
5804 {
5805 }
5806
5807 constexpr IConv(const IConvRef& other) = delete;
5808
5809 constexpr IConv(IConvRef&& other) = delete;
5810
5826 : m_resource(SDL_iconv_open(tocode, fromcode))
5827 {
5828 }
5829
5831 ~IConv() { SDL_iconv_close(m_resource); }
5832
5835 {
5836 std::swap(m_resource, other.m_resource);
5837 return *this;
5838 }
5839
5841 constexpr IConvRaw get() const { return m_resource; }
5842
5844 constexpr IConvRaw release()
5845 {
5846 auto r = m_resource;
5847 m_resource = nullptr;
5848 return r;
5849 }
5850
5852 constexpr auto operator<=>(const IConv& other) const = default;
5853
5855 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
5856
5858 constexpr explicit operator bool() const
5859 {
5860 return m_resource != IConvRaw(SDL_ICONV_ERROR);
5861 }
5862
5864 constexpr operator IConvParam() const { return {m_resource}; }
5865
5877 int close();
5878
5914 size_t iconv(const char** inbuf,
5915 size_t* inbytesleft,
5916 char** outbuf,
5917 size_t* outbytesleft);
5918};
5919
5922{
5931 : IConv(resource.value)
5932 {
5933 }
5934
5936 IConvRef(const IConvRef& other)
5937 : IConv(other.get())
5938 {
5939 }
5940
5943};
5944
5960inline IConv iconv_open(StringParam tocode, StringParam fromcode)
5961{
5962 return IConv(SDL_iconv_open(tocode, fromcode));
5963}
5964
5978inline int iconv_close(IConvRaw cd) { return CheckError(SDL_iconv_close(cd)); }
5979
5980inline int IConv::close() { return iconv_close(release()); }
5981
6019inline size_t iconv(IConvRaw cd,
6020 const char** inbuf,
6021 size_t* inbytesleft,
6022 char** outbuf,
6023 size_t* outbytesleft)
6024{
6025 return CheckError(SDL_iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft));
6026}
6027
6028inline size_t IConv::iconv(const char** inbuf,
6029 size_t* inbytesleft,
6030 char** outbuf,
6031 size_t* outbytesleft)
6032{
6033 return SDL::iconv(m_resource, inbuf, inbytesleft, outbuf, outbytesleft);
6034}
6035
6036#ifdef SDL3PP_DOC
6037
6039#define SDL_ICONV_ERROR (size_t)-1
6040
6042#define SDL_ICONV_E2BIG (size_t)-2
6043
6045#define SDL_ICONV_EILSEQ (size_t)-3
6046
6048#define SDL_ICONV_EINVAL (size_t)-4
6049
6050#endif // SDL3PP_DOC
6051
6075 StringParam fromcode,
6076 StringParam inbuf,
6077 size_t inbytesleft)
6078{
6079 return OwnPtr<char>{SDL_iconv_string(tocode, fromcode, inbuf, inbytesleft)};
6080}
6081
6082#ifdef SDL3PP_DOC
6083
6096#define SDL_iconv_utf8_locale(S) \
6097 SDL_iconv_string("", "UTF-8", S, SDL_strlen(S) + 1)
6098
6111#define SDL_iconv_utf8_ucs2(S) \
6112 (Uint16*)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S) + 1)
6113
6126#define SDL_iconv_utf8_ucs4(S) \
6127 (Uint32*)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S) + 1)
6128
6141#define SDL_iconv_wchar_utf8(S) \
6142 SDL_iconv_string( \
6143 "UTF-8", "WCHAR_T", (char*)S, (SDL_wcslen(S) + 1) * sizeof(wchar_t))
6144
6145#endif // SDL3PP_DOC
6146
6164inline bool size_mul_check_overflow(size_t a, size_t b, size_t* ret)
6165{
6166 return SDL_size_mul_check_overflow(a, b, ret);
6167}
6168
6186inline bool size_add_check_overflow(size_t a, size_t b, size_t* ret)
6187{
6188 return SDL_size_add_check_overflow(a, b, ret);
6189}
6190
6206using FunctionPointer = SDL_FunctionPointer;
6207
6209
6210inline void PtrDeleter::operator()(void* ptr) const { SDL_free(ptr); }
6211
6212} // namespace SDL
6213
6214#endif /* SDL3PP_STDINC_H_ */
A thread-safe set of environment variables.
Definition: SDL3pp_stdinc.h:964
constexpr Environment(const EnvironmentRaw resource)
Constructs from EnvironmentParam.
Definition: SDL3pp_stdinc.h:978
constexpr auto operator<=>(const Environment &other) const =default
Comparison.
constexpr Environment(Environment &&other)
Move constructor.
Definition: SDL3pp_stdinc.h:987
Environment & operator=(Environment other)
Assignment operator.
Definition: SDL3pp_stdinc.h:1025
Uint64 GetVariableCount()
Get the Variables count.
Definition: SDL3pp_stdinc.h:1114
constexpr EnvironmentRaw release()
Retrieves underlying EnvironmentRaw and clear this.
Definition: SDL3pp_stdinc.h:1035
constexpr EnvironmentRaw get() const
Retrieves underlying EnvironmentRaw.
Definition: SDL3pp_stdinc.h:1032
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_stdinc.h:1046
Environment(bool populated)
Create a set of environment variables.
Definition: SDL3pp_stdinc.h:1016
constexpr Environment(const Environment &other)=delete
Copy constructor.
~Environment()
Destructor.
Definition: SDL3pp_stdinc.h:1022
constexpr Environment()=default
Default ctor.
An opaque handle representing string encoding conversion state.
Definition: SDL3pp_stdinc.h:5779
constexpr auto operator<=>(const IConv &other) const =default
Comparison.
~IConv()
Destructor.
Definition: SDL3pp_stdinc.h:5831
constexpr IConv(const IConv &other)=delete
Copy constructor.
constexpr IConvRaw get() const
Retrieves underlying IConvRaw.
Definition: SDL3pp_stdinc.h:5841
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_stdinc.h:5855
constexpr IConv()=default
Default ctor.
IConv(StringParam tocode, StringParam fromcode)
This function allocates a context for the specified character set conversion.
Definition: SDL3pp_stdinc.h:5825
constexpr IConv(const IConvRaw resource)
Constructs from IConvParam.
Definition: SDL3pp_stdinc.h:5793
constexpr IConv(IConv &&other)
Move constructor.
Definition: SDL3pp_stdinc.h:5802
IConv & operator=(IConv other)
Assignment operator.
Definition: SDL3pp_stdinc.h:5834
constexpr IConvRaw release()
Retrieves underlying IConvRaw and clear this.
Definition: SDL3pp_stdinc.h:5844
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
A independent pseudo random state.
Definition: SDL3pp_stdinc.h:4291
constexpr Random(Uint64 state)
Init state with the given value.
Definition: SDL3pp_stdinc.h:4303
float randf()
Generate a uniform pseudo-random floating point number less than 1.0.
Definition: SDL3pp_stdinc.h:4367
Uint32 rand_bits()
Generate 32 pseudo-random bits.
Definition: SDL3pp_stdinc.h:4390
Sint32 rand(Sint32 n)
Generate a pseudo-random number less than n for positive n.
Definition: SDL3pp_stdinc.h:4342
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:411
constexpr Sint64 ToNS() const
Converts to nanoseconds Sint64.
Definition: SDL3pp_stdinc.h:463
constexpr Time & operator+=(std::chrono::nanoseconds interval)
Increment time.
Definition: SDL3pp_stdinc.h:533
constexpr Time(TimeRaw time)
Wraps Time.
Definition: SDL3pp_stdinc.h:422
constexpr float ToSeconds() const
Converts a time to seconds (float) since epoch.
Definition: SDL3pp_stdinc.h:523
constexpr Time & operator-=(std::chrono::nanoseconds interval)
Decrement.
Definition: SDL3pp_stdinc.h:540
constexpr Time(std::chrono::nanoseconds time)
Wraps Time.
Definition: SDL3pp_stdinc.h:432
static constexpr Time FromNS(Sint64 time)
Create from a nanoseconds Sint64.
Definition: SDL3pp_stdinc.h:457
static constexpr Time FromSeconds(float interval)
Converts a time to seconds (float) since epoch.
Definition: SDL3pp_stdinc.h:526
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:198
std::unique_ptr< T, PtrDeleter > OwnPtr
Handle to an owned SDL memory allocated pointer.
Definition: SDL3pp_ownPtr.h:33
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:2789
double log(double x)
Compute the natural logarithm of x.
Definition: SDL3pp_stdinc.h:5239
Uint16 Uint16
An unsigned 16-bit integer type.
Definition: SDL3pp_stdinc.h:294
char * UCS4ToUTF8(Uint32 codepoint, char *dst)
Convert a single Unicode codepoint to UTF-8.
Definition: SDL3pp_stdinc.h:3915
long wcstol(const wchar_t *str, wchar_t **endp, int base)
Parse a long from a wide string.
Definition: SDL3pp_stdinc.h:2897
char * strdup(StringParam str)
Allocate a copy of a string.
Definition: SDL3pp_stdinc.h:3059
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:882
double strtod(StringParam str, char **endp)
Parse a double from a string.
Definition: SDL3pp_stdinc.h:3636
void SetVariable(StringParam name, StringParam value, bool overwrite)
Set the value of a variable in the environment.
Definition: SDL3pp_stdinc.h:1323
constexpr Sint8 MIN_SINT8
Min representable value.
Definition: SDL3pp_stdinc.h:251
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:3266
void UnsetVariable(StringParam name)
Clear a variable from the environment.
Definition: SDL3pp_stdinc.h:1354
double atan(double x)
Compute the arc tangent of x.
Definition: SDL3pp_stdinc.h:4648
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:4144
Sint8 Sint8
A signed 8-bit integer type.
Definition: SDL3pp_stdinc.h:243
double ceil(double x)
Compute the ceiling of x.
Definition: SDL3pp_stdinc.h:4779
char * strlwr(char *str)
Convert a string to lowercase.
Definition: SDL3pp_stdinc.h:3150
void * memmove(void *dst, const void *src, size_t len)
Copy memory ranges that might overlap.
Definition: SDL3pp_stdinc.h:2397
int memcmp(const void *s1, const void *s2, size_t len)
Compare two buffers of memory.
Definition: SDL3pp_stdinc.h:2539
constexpr Uint16 MIN_UINT16
Min representable value.
Definition: SDL3pp_stdinc.h:302
constexpr std::size_t arraysize(const T(&array)[N])
The number of elements in a static array.
Definition: SDL3pp_stdinc.h:166
SDL_malloc_func malloc_func
A callback used to implement malloc().
Definition: SDL3pp_stdinc.h:744
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:3235
int isnan(double x)
Return whether the value is NaN.
Definition: SDL3pp_stdinc.h:5195
constexpr Uint32 INVALID_UNICODE_CODEPOINT
The Unicode REPLACEMENT CHARACTER codepoint.
Definition: SDL3pp_stdinc.h:3804
double scalbn(double x, int n)
Scale x by an integer power of two.
Definition: SDL3pp_stdinc.h:5573
char * ultoa(unsigned long value, char *str, int radix)
Convert an unsigned long integer into a string.
Definition: SDL3pp_stdinc.h:3486
wchar_t * wcsdup(const wchar_t *wstr)
Allocate a copy of a wide string.
Definition: SDL3pp_stdinc.h:2683
int isgraph(int x)
Report if a character is any "printable" except space.
Definition: SDL3pp_stdinc.h:2204
constexpr Sint16 MIN_SINT16
Min representable value.
Definition: SDL3pp_stdinc.h:285
OwnArray< char * > GetVariables()
Get all variables in the environment.
Definition: SDL3pp_stdinc.h:1289
const char * GetEnvironmentVariable(EnvironmentParam env, StringParam name)
Get the value of a variable in the environment.
Definition: SDL3pp_stdinc.h:1254
int strncmp(StringParam str1, StringParam str2, size_t maxlen)
Compare two UTF-8 strings up to a number of bytes.
Definition: SDL3pp_stdinc.h:3692
size_t iconv(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:6028
Sint64 Sint64
A signed 64-bit integer type.
Definition: SDL3pp_stdinc.h:347
double asin(double x)
Compute the arc sine of x.
Definition: SDL3pp_stdinc.h:4586
Uint16 crc16(Uint16 crc, const void *data, size_t len)
Calculate a CRC-16 value.
Definition: SDL3pp_stdinc.h:2261
char * strrev(char *str)
Reverse a string's contents.
Definition: SDL3pp_stdinc.h:3108
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:3765
constexpr T min(T x, U y)
Return the lesser of two values.
Definition: SDL3pp_stdinc.h:1951
SDL_FunctionPointer FunctionPointer
A generic function pointer.
Definition: SDL3pp_stdinc.h:6206
unsigned long strtoul(StringParam str, char **endp, int base)
Parse an unsigned long from a string.
Definition: SDL3pp_stdinc.h:3604
int isdigit(int x)
Report if a character is a numeric digit.
Definition: SDL3pp_stdinc.h:2079
std::chrono::duration< float > Seconds
Duration in seconds (float).
Definition: SDL3pp_stdinc.h:377
double exp(double x)
Compute the exponential of x.
Definition: SDL3pp_stdinc.h:4947
char * strstr(StringParam haystack, StringParam needle)
Search a string for the first instance of a specific substring.
Definition: SDL3pp_stdinc.h:3209
constexpr Uint32 MAX_UINT32
Max representable value.
Definition: SDL3pp_stdinc.h:333
IConv iconv_open(StringParam tocode, StringParam fromcode)
This function allocates a context for the specified character set conversion.
Definition: SDL3pp_stdinc.h:5960
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:4082
char * strchr(StringParam str, int c)
Search a string for the first instance of a specific byte.
Definition: SDL3pp_stdinc.h:3170
double copysign(double x, double y)
Copy the sign of one floating-point value to another.
Definition: SDL3pp_stdinc.h:4833
Environment CreateEnvironment(bool populated)
Create a set of environment variables.
Definition: SDL3pp_stdinc.h:1231
void * malloc(size_t size)
Allocate uninitialized memory.
Definition: SDL3pp_stdinc.h:637
double modf(double x, double *y)
Split x into integer and fractional parts.
Definition: SDL3pp_stdinc.h:5348
void zero(T &x)
Clear an object's memory to zero.
Definition: SDL3pp_stdinc.h:2474
SDL_calloc_func calloc_func
A callback used to implement calloc().
Definition: SDL3pp_stdinc.h:765
size_t strlcat(char *dst, StringParam src, size_t maxlen)
Concatenate strings.
Definition: SDL3pp_stdinc.h:3038
void zeroa(T(&x)[N])
Clear an array's memory to zero.
Definition: SDL3pp_stdinc.h:2520
Sint32 Sint32
A signed 32-bit integer type.
Definition: SDL3pp_stdinc.h:311
char * strndup(StringParam str, size_t maxlen)
Allocate a copy of a string, up to n characters.
Definition: SDL3pp_stdinc.h:3084
constexpr Uint8 MIN_UINT64
Min representable value.
Definition: SDL3pp_stdinc.h:374
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:6019
std::chrono::milliseconds Milliseconds
Duration in Miliseconds (Uint32).
Definition: SDL3pp_stdinc.h:383
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:4002
double round(double x)
Round x to the nearest integer.
Definition: SDL3pp_stdinc.h:5461
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:3935
size_t strlcpy(char *dst, StringParam src, size_t maxlen)
Copy a string.
Definition: SDL3pp_stdinc.h:2976
void * memset(void *dst, int c, size_t len)
Initialize all bytes of buffer of memory to a specific value.
Definition: SDL3pp_stdinc.h:2424
void UnsetEnvironmentVariable(EnvironmentParam env, StringParam name)
Clear a variable from the environment.
Definition: SDL3pp_stdinc.h:1349
constexpr Uint64 MAX_UINT64
Max representable value.
Definition: SDL3pp_stdinc.h:371
bool size_mul_check_overflow(size_t a, size_t b, size_t *ret)
Multiply two integers, checking for overflow.
Definition: SDL3pp_stdinc.h:6164
Uint32 rand_bits_r(Uint64 *state)
Generate 32 pseudo-random bits.
Definition: SDL3pp_stdinc.h:4478
int iconv_close(IConvRaw cd)
This function frees a context used for character set conversion.
Definition: SDL3pp_stdinc.h:5978
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:823
int strcmp(StringParam str1, StringParam str2)
Compare two null-terminated UTF-8 strings.
Definition: SDL3pp_stdinc.h:3659
bool size_add_check_overflow(size_t a, size_t b, size_t *ret)
Add two integers, checking for overflow.
Definition: SDL3pp_stdinc.h:6186
float randf_r(Uint64 *state)
Generate a uniform pseudo-random floating point number less than 1.0.
Definition: SDL3pp_stdinc.h:4453
char * uitoa(unsigned int value, char *str, int radix)
Convert an unsigned integer into a string.
Definition: SDL3pp_stdinc.h:3424
double pow(double x, double y)
Raise x to the power y
Definition: SDL3pp_stdinc.h:5400
constexpr Sint32 MIN_SINT32
Min representable value.
Definition: SDL3pp_stdinc.h:319
EnvironmentRaw GetEnvironment()
Get the process environment.
Definition: SDL3pp_stdinc.h:1209
int isprint(int x)
Report if a character is "printable".
Definition: SDL3pp_stdinc.h:2183
long lround(double x)
Round x to the nearest integer representable as a long.
Definition: SDL3pp_stdinc.h:5519
std::chrono::nanoseconds Nanoseconds
Duration in Nanoseconds (Uint64).
Definition: SDL3pp_stdinc.h:380
int isxdigit(int x)
Report if a character is a hexadecimal digit.
Definition: SDL3pp_stdinc.h:2094
constexpr T max(T x, U y)
Return the greater of two values.
Definition: SDL3pp_stdinc.h:1973
int atoi(StringParam str)
Parse an int from a string.
Definition: SDL3pp_stdinc.h:3512
int tolower(int x)
Convert low-ASCII English letters to lowercase.
Definition: SDL3pp_stdinc.h:2240
int isalpha(int x)
Query if a character is alphabetic (a letter).
Definition: SDL3pp_stdinc.h:2019
std::function< int(const void *, const void *)> CompareCB
A callback used with SDL sorting and binary search functions.
Definition: SDL3pp_stdinc.h:1612
int unsetenv_unsafe(StringParam name)
Clear a variable from the environment.
Definition: SDL3pp_stdinc.h:1449
constexpr float ToSeconds(Seconds duration)
Converts a time duration to seconds (float).
Definition: SDL3pp_stdinc.h:386
char * strupr(char *str)
Convert a string to uppercase.
Definition: SDL3pp_stdinc.h:3129
SDL_free_func free_func
A callback used to implement free().
Definition: SDL3pp_stdinc.h:804
int close()
This function frees a context used for character set conversion.
Definition: SDL3pp_stdinc.h:5980
size_t utf8strlen(StringParam str)
Count the number of codepoints in a UTF-8 string.
Definition: SDL3pp_stdinc.h:3329
constexpr Seconds FromSeconds(float duration)
Converts a float to seconds representation.
Definition: SDL3pp_stdinc.h:389
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:3362
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:4109
int isupper(int x)
Report if a character is upper case.
Definition: SDL3pp_stdinc.h:2149
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:2600
double sqrt(double x)
Compute the square root of x.
Definition: SDL3pp_stdinc.h:5680
constexpr Sint16 MAX_SINT16
Max representable value.
Definition: SDL3pp_stdinc.h:282
void srand(Uint64 seed)
Seeds the pseudo-random number generator.
Definition: SDL3pp_stdinc.h:4198
constexpr Uint8 MAX_UINT8
Max representable value.
Definition: SDL3pp_stdinc.h:265
Sint32 rand_r(Uint64 *state, Sint32 n)
Generate a pseudo-random number less than n for positive n.
Definition: SDL3pp_stdinc.h:4426
double tan(double x)
Compute the tangent of x.
Definition: SDL3pp_stdinc.h:5736
double sin(double x)
Compute the sine of x.
Definition: SDL3pp_stdinc.h:5626
const char * getenv_unsafe(StringParam name)
Get the value of a variable in the environment.
Definition: SDL3pp_stdinc.h:1410
size_t utf8strlcpy(char *dst, StringParam src, size_t dst_bytes)
Copy an UTF-8 string.
Definition: SDL3pp_stdinc.h:3007
constexpr Sint64 MIN_SINT64
Min representable value.
Definition: SDL3pp_stdinc.h:355
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:3298
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:2451
int iscntrl(int x)
Report if a character is a control character.
Definition: SDL3pp_stdinc.h:2064
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:4049
constexpr double PI_D
The value of Pi, as a double-precision floating point literal.
Definition: SDL3pp_stdinc.h:4487
int islower(int x)
Report if a character is lower case.
Definition: SDL3pp_stdinc.h:2164
int isinf(double x)
Return whether the value is infinity.
Definition: SDL3pp_stdinc.h:5167
int isspace(int x)
Report if a character is whitespace.
Definition: SDL3pp_stdinc.h:2134
void DestroyEnvironment(EnvironmentRaw env)
Destroy a set of environment variables.
Definition: SDL3pp_stdinc.h:1371
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:2944
int strcasecmp(StringParam str1, StringParam str2)
Compare two null-terminated UTF-8 strings, case-insensitively.
Definition: SDL3pp_stdinc.h:3723
size_t strlen(StringParam str)
This works exactly like strlen() but doesn't require access to a C runtime.
Definition: SDL3pp_stdinc.h:2920
constexpr Uint16 MAX_UINT16
Max representable value.
Definition: SDL3pp_stdinc.h:299
const char * GetVariable(StringParam name)
Get the value of a variable in the environment.
Definition: SDL3pp_stdinc.h:1260
const char * getenv(StringParam name)
Get the value of a variable in the environment.
Definition: SDL3pp_stdinc.h:1391
int setenv_unsafe(StringParam name, StringParam value, int overwrite)
Set the value of a variable in the environment.
Definition: SDL3pp_stdinc.h:1431
int wcscmp(const wchar_t *str1, const wchar_t *str2)
Compare two null-terminated wide strings.
Definition: SDL3pp_stdinc.h:2755
double acos(double x)
Compute the arc cosine of x.
Definition: SDL3pp_stdinc.h:4526
Sint32 rand(Sint32 n)
Generate a pseudo-random number less than n for positive n.
Definition: SDL3pp_stdinc.h:4232
SDL_realloc_func realloc_func
A callback used to implement realloc().
Definition: SDL3pp_stdinc.h:786
constexpr Sint64 MAX_SINT64
Max representable value.
Definition: SDL3pp_stdinc.h:352
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:328
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:1666
double floor(double x)
Compute the floor of x.
Definition: SDL3pp_stdinc.h:5007
Uint32 StepUTF8(const char **pstr, size_t *pslen)
Decode a UTF-8 string, one Unicode codepoint at a time.
Definition: SDL3pp_stdinc.h:3849
int toupper(int x)
Convert low-ASCII English letters to uppercase.
Definition: SDL3pp_stdinc.h:2222
SDL_Time TimeRaw
Alias to raw representation for Time.
Definition: SDL3pp_stdinc.h:42
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:2314
constexpr Uint32 FourCC(Uint8 a, Uint8 b, Uint8 c, Uint8 d)
Define a four character code as a Uint32.
Definition: SDL3pp_stdinc.h:205
Uint32 StepBackUTF8(StringParam start, const char **pstr)
Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
Definition: SDL3pp_stdinc.h:3883
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
Copy a wide string.
Definition: SDL3pp_stdinc.h:2630
float randf()
Generate a uniform pseudo-random floating point number less than 1.0.
Definition: SDL3pp_stdinc.h:4255
constexpr T clamp(T x, U a, V b)
Return a value clamped to a range.
Definition: SDL3pp_stdinc.h:2001
constexpr Time MAX_TIME
Max allowed time representation.
Definition: SDL3pp_stdinc.h:548
constexpr Nanoseconds FromNS(Sint64 duration)
Converts a Sint64 to nanoseconds representation.
Definition: SDL3pp_stdinc.h:395
SDL_iconv_t IConvRaw
Alias to raw representation for IConv.
Definition: SDL3pp_stdinc.h:87
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:2867
void aligned_free(void *mem)
Free memory allocated by aligned_alloc().
Definition: SDL3pp_stdinc.h:934
void zerop(T *x)
Clear an object's memory to zero, using a pointer.
Definition: SDL3pp_stdinc.h:2497
int abs(int x)
Compute the absolute value of x.
Definition: SDL3pp_stdinc.h:1890
void * calloc(size_t nmemb, size_t size)
Allocate a zero-initialized array.
Definition: SDL3pp_stdinc.h:662
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:849
void qsort(void *base, size_t nmemb, size_t size, CompareCallback compare)
Sort an array.
Definition: SDL3pp_stdinc.h:1514
constexpr Time MIN_TIME
Min allowed time representation.
Definition: SDL3pp_stdinc.h:551
SDL_CompareCallback_r CompareCallback_r
A callback used with SDL sorting and binary search functions.
Definition: SDL3pp_stdinc.h:1595
constexpr Sint64 ToNS(Nanoseconds duration)
Converts a time duration to nanoseconds (Sint64);.
Definition: SDL3pp_stdinc.h:392
int isblank(int x)
Report if a character is blank (a space or tab).
Definition: SDL3pp_stdinc.h:2049
void * realloc(void *mem, size_t size)
Change the size of allocated memory.
Definition: SDL3pp_stdinc.h:705
SDL_CompareCallback CompareCallback
A callback used with SDL sorting and binary search functions.
Definition: SDL3pp_stdinc.h:1468
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:4173
char * itoa(int value, char *str, int radix)
Convert an integer into a string.
Definition: SDL3pp_stdinc.h:3393
int ispunct(int x)
Report if a character is a punctuation mark.
Definition: SDL3pp_stdinc.h:2112
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:3964
constexpr Uint8 MIN_UINT8
Min representable value.
Definition: SDL3pp_stdinc.h:268
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:2731
Uint32 crc32(Uint32 crc, const void *data, size_t len)
Calculate a CRC-32 value.
Definition: SDL3pp_stdinc.h:2285
double log10(double x)
Compute the base-10 logarithm of x.
Definition: SDL3pp_stdinc.h:5298
void SetEnvironmentVariable(EnvironmentParam env, StringParam name, StringParam value, bool overwrite)
Set the value of a variable in the environment.
Definition: SDL3pp_stdinc.h:1315
Uint64 Uint64
An unsigned 64-bit integer type.
Definition: SDL3pp_stdinc.h:366
constexpr float PI_F
The value of Pi, as a single-precision floating point literal.
Definition: SDL3pp_stdinc.h:4496
void Destroy()
Destroy a set of environment variables.
Definition: SDL3pp_stdinc.h:1376
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:2703
#define SDL_ICONV_ERROR
Generic error. Check GetError()?
Definition: SDL3pp_stdinc.h:6039
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:1571
Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:260
double cos(double x)
Compute the cosine of x.
Definition: SDL3pp_stdinc.h:4887
void free(void *mem)
Free allocated memory.
Definition: SDL3pp_stdinc.h:725
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:4715
int wcscasecmp(const wchar_t *str1, const wchar_t *str2)
Compare two null-terminated wide strings, case-insensitively.
Definition: SDL3pp_stdinc.h:2822
char * strpbrk(StringParam str, StringParam breakset)
Searches a string for the first occurrence of any character contained in a breakset,...
Definition: SDL3pp_stdinc.h:3786
void * aligned_alloc(size_t alignment, size_t size)
Allocate memory aligned to a specific alignment.
Definition: SDL3pp_stdinc.h:913
int GetNumAllocations()
Get the number of outstanding (unfreed) allocations.
Definition: SDL3pp_stdinc.h:946
Uint32 rand_bits()
Generate 32 pseudo-random bits.
Definition: SDL3pp_stdinc.h:4278
constexpr Sint8 MAX_SINT8
Max representable value.
Definition: SDL3pp_stdinc.h:248
OwnPtr< char > iconv_string(StringParam tocode, StringParam fromcode, StringParam inbuf, size_t inbytesleft)
Helper function to convert a string's encoding in one call.
Definition: SDL3pp_stdinc.h:6074
constexpr Uint8 MIN_UINT32
Min representable value.
Definition: SDL3pp_stdinc.h:336
double trunc(double x)
Truncate x to an integer.
Definition: SDL3pp_stdinc.h:5064
OwnArray< char * > GetEnvironmentVariables(EnvironmentParam env)
Get all variables in the environment.
Definition: SDL3pp_stdinc.h:1284
char * ltoa(long value, char *str, int radix)
Convert a long integer into a string.
Definition: SDL3pp_stdinc.h:3455
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
Concatenate wide strings.
Definition: SDL3pp_stdinc.h:2662
double atof(StringParam str)
Parse a double from a string.
Definition: SDL3pp_stdinc.h:3534
constexpr Sint32 MAX_SINT32
Max representable value.
Definition: SDL3pp_stdinc.h:316
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:1796
long strtol(StringParam str, char **endp, int base)
Parse a long from a string.
Definition: SDL3pp_stdinc.h:3568
Sint16 Sint16
A signed 16-bit integer type.
Definition: SDL3pp_stdinc.h:277
char * strrchr(StringParam str, int c)
Search a string for the last instance of a specific byte.
Definition: SDL3pp_stdinc.h:3189
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:2569
SDL_Environment * EnvironmentRaw
Alias to raw representation for Environment.
Definition: SDL3pp_stdinc.h:51
int isalnum(int x)
Query if a character is alphabetic (a letter) or a number.
Definition: SDL3pp_stdinc.h:2034
double fmod(double x, double y)
Return the floating-point remainder of x / y
Definition: SDL3pp_stdinc.h:5123
void * memcpy(void *dst, const void *src, size_t len)
Copy non-overlapping memory.
Definition: SDL3pp_stdinc.h:2337
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:400
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:395
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:349
constexpr Sint64 ToPosix() const
Convert nanoseconds to seconds.
Definition: SDL3pp_timer.h:32
static constexpr Time FromPosix(Sint64 time)
Convert seconds to nanoseconds.
Definition: SDL3pp_timer.h:27
Main include header for the SDL3pp library.
Safely wrap Environment for non owning parameters.
Definition: SDL3pp_stdinc.h:58
EnvironmentRaw value
parameter's EnvironmentRaw
Definition: SDL3pp_stdinc.h:59
constexpr EnvironmentParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_stdinc.h:68
constexpr EnvironmentParam(EnvironmentRaw value)
Constructs from EnvironmentRaw.
Definition: SDL3pp_stdinc.h:62
constexpr auto operator<=>(const EnvironmentParam &other) const =default
Comparison.
Semi-safe reference for Environment.
Definition: SDL3pp_stdinc.h:1165
EnvironmentRef(EnvironmentParam resource)
Constructs from EnvironmentParam.
Definition: SDL3pp_stdinc.h:1173
~EnvironmentRef()
Destructor.
Definition: SDL3pp_stdinc.h:1185
EnvironmentRef(const EnvironmentRef &other)
Copy constructor.
Definition: SDL3pp_stdinc.h:1179
Safely wrap IConv for non owning parameters.
Definition: SDL3pp_stdinc.h:94
constexpr IConvParam(IConvRaw value)
Constructs from IConvRaw.
Definition: SDL3pp_stdinc.h:98
constexpr IConvParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_stdinc.h:104
constexpr auto operator<=>(const IConvParam &other) const =default
Comparison.
IConvRaw value
parameter's IConvRaw
Definition: SDL3pp_stdinc.h:95
Semi-safe reference for IConv.
Definition: SDL3pp_stdinc.h:5922
IConvRef(IConvParam resource)
Constructs from IConvParam.
Definition: SDL3pp_stdinc.h:5930
~IConvRef()
Destructor.
Definition: SDL3pp_stdinc.h:5942
IConvRef(const IConvRef &other)
Copy constructor.
Definition: SDL3pp_stdinc.h:5936