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_resource.h"
11#include "SDL3pp_spanRef.h"
12#include "SDL3pp_strings.h"
13
14namespace SDL {
15
41// Forward decl
42struct EnvironmentRef;
43
44// Forward decl
45struct Environment;
46
56
66
67// Forward decl
68struct IConvRef;
69
70// Forward decl
71struct IConv;
72
82
92
93#ifdef SDL3PP_DOC
94
111#define SDL_NOLONGLONG 1
112
127#define SDL_SIZE_MAX SIZE_MAX
128
129#endif // SDL3PP_DOC
130
139template<class T, std::size_t N>
140constexpr std::size_t arraysize(const T (&array)[N])
141{
142 return SDL_arraysize(array);
143}
144
145#ifdef SDL3PP_DOC
146
161#define SDL_STRINGIFY_ARG(arg) #arg
162
163#endif // SDL3PP_DOC
164
179constexpr Uint32 FourCC(Uint8 a, Uint8 b, Uint8 c, Uint8 d)
180{
181 return SDL_FOURCC(a, b, c, d);
182}
183
184#ifdef SDL3PP_DOC
185
197#define SDL_SINT64_C(c) c##LL /* or whatever the current compiler uses. */
198
210#define SDL_UINT64_C(c) c##ULL /* or whatever the current compiler uses. */
211
212#endif // SDL3PP_DOC
213
214constexpr Sint8 MAX_SINT8 = SDL_MAX_SINT8;
215
216constexpr Sint8 MIN_SINT8 = SDL_MIN_SINT8;
217
218constexpr Uint8 MAX_UINT8 = SDL_MAX_UINT8;
219
220constexpr Uint8 MIN_UINT8 = SDL_MIN_UINT8;
221
222constexpr Sint16 MAX_SINT16 = SDL_MAX_SINT16;
223
224constexpr Sint16 MIN_SINT16 = SDL_MIN_SINT16;
225
226constexpr Uint16 MAX_UINT16 = SDL_MAX_UINT16;
227
228constexpr Uint16 MIN_UINT16 = SDL_MIN_UINT16;
229
230constexpr Sint32 MAX_SINT32 = SDL_MAX_SINT32;
231
232constexpr Sint32 MIN_SINT32 = SDL_MIN_SINT32;
233
234constexpr Uint32 MAX_UINT32 = SDL_MAX_UINT32;
235
236constexpr Uint8 MIN_UINT32 = SDL_MIN_UINT32;
237
238constexpr Sint64 MAX_SINT64 = SDL_MAX_SINT64;
239
240constexpr Sint64 MIN_SINT64 = SDL_MIN_SINT64;
241
242constexpr Uint64 MAX_UINT64 = SDL_MAX_UINT64;
243
244constexpr Uint8 MIN_UINT64 = SDL_MIN_UINT64;
245
249using Seconds = std::chrono::duration<float>;
250
254using Nanoseconds = std::chrono::nanoseconds;
255
259constexpr float ToSeconds(Seconds duration) { return duration.count(); }
260
264constexpr Seconds FromSeconds(float duration) { return Seconds(duration); }
265
269constexpr Sint64 ToNS(std::chrono::nanoseconds duration)
270{
271 return duration.count();
272}
273
277constexpr Nanoseconds FromNS(Sint64 duration) { return Nanoseconds{duration}; }
278
292class Time
293{
294 std::chrono::nanoseconds m_value;
295
296public:
297 constexpr Time() = default;
298
300 constexpr Time(std::chrono::nanoseconds time)
301 : m_value(time)
302 {
303 }
304
306 constexpr explicit Time(SDL_Time time)
307 : m_value(FromNS(time))
308 {
309 }
310
312 constexpr explicit operator bool() const
313 {
314 return m_value != std::chrono::nanoseconds{};
315 }
316
318 constexpr operator std::chrono::nanoseconds() const { return m_value; }
319
320 static Time Current();
321
323 static constexpr Time FromNS(Sint64 time)
324 {
325 return Time{std::chrono::nanoseconds{time}};
326 }
327
329 constexpr Sint64 ToNS() const { return m_value.count(); }
330
331 static constexpr Time FromPosix(Sint64 time);
332
333 constexpr Sint64 ToPosix() const;
334
335 static Time FromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime);
336
337 void ToWindows(Uint32* dwLowDateTime, Uint32* dwHighDateTime) const;
338
342 constexpr float ToSeconds() const { return Seconds(m_value).count(); }
343
347 static constexpr Time FromSeconds(float interval)
348 {
349 return std::chrono::duration_cast<std::chrono::nanoseconds>(
350 Seconds(interval));
351 }
352
354 constexpr Time& operator+=(std::chrono::nanoseconds interval)
355 {
356 m_value += interval;
357 return *this;
358 }
359
361 constexpr Time& operator-=(std::chrono::nanoseconds interval)
362 {
363 m_value -= interval;
364 return *this;
365 }
366};
367
368constexpr Time MAX_TIME = Time::FromNS(SDL_MAX_TIME);
369
370constexpr Time MIN_TIME = Time::FromNS(SDL_MIN_TIME);
371
372#ifdef SDL3PP_DOC
373
382#define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
383
422#define SDL_INIT_INTERFACE(iface) \
423 do { \
424 SDL_zerop(iface); \
425 (iface)->version = sizeof(*(iface)); \
426 } while (0)
427
428#endif // SDL3PP_DOC
429
456inline void* malloc(size_t size) { return SDL_malloc(size); }
457
481inline void* calloc(size_t nmemb, size_t size)
482{
483 return SDL_calloc(nmemb, size);
484}
485
524inline void* realloc(void* mem, size_t size) { return SDL_realloc(mem, size); }
525
544inline void free(void* mem) { SDL_free(mem); }
545
563using malloc_func = SDL_malloc_func;
564
584using calloc_func = SDL_calloc_func;
585
605using realloc_func = SDL_realloc_func;
606
623using free_func = SDL_free_func;
624
650
675
709
732inline void* aligned_alloc(size_t alignment, size_t size)
733{
734 return SDL_aligned_alloc(alignment, size);
735}
736
753inline void aligned_free(void* mem) { SDL_aligned_free(mem); }
754
765inline int GetNumAllocations() { return SDL_GetNumAllocations(); }
766
783struct EnvironmentRef : Resource<SDL_Environment*>
784{
785 using Resource::Resource;
786
804 const char* GetVariable(StringParam name)
805 {
806 return SDL_GetEnvironmentVariable(get(), name);
807 }
808
829 {
830 return OwnArray<char*>{CheckError(SDL_GetEnvironmentVariables(get()))};
831 }
832
840 inline Uint64 GetVariableCount()
841 {
842 Uint64 count = 0;
843 for (auto& var : GetVariables()) count += 1;
844 return count;
845 }
846
867 void SetVariable(StringParam name, StringParam value, bool overwrite)
868 {
869 CheckError(SDL_SetEnvironmentVariable(get(), name, value, overwrite));
870 }
871
890 {
891 CheckError(SDL_UnsetEnvironmentVariable(get(), name));
892 }
893
906 static void reset(SDL_Environment* resource)
907 {
908 SDL_DestroyEnvironment(resource);
909 }
910};
911
919struct Environment : ResourceUnique<EnvironmentRef>
920{
922
943 static Environment Create(bool populated)
944 {
945 return Environment(CheckError(SDL_CreateEnvironment(populated)));
946 }
947
959 void Destroy() { reset(); }
964
965};
966
967
969{
970 return EnvironmentShared(std::move(*this));
971}
972
982struct EnvironmentUnsafe : ResourceUnsafe<EnvironmentRef>
983{
985
989 constexpr explicit EnvironmentUnsafe(Environment&& other)
990 : EnvironmentUnsafe(other.release())
991 {
992 }
993};
994
1016inline EnvironmentRef GetEnvironment() { return SDL_GetEnvironment(); }
1017
1031inline const char* getenv(StringParam name) { return SDL_getenv(name); }
1032
1050inline const char* getenv_unsafe(StringParam name)
1051{
1052 return SDL_getenv_unsafe(name);
1053}
1054
1071inline int setenv_unsafe(StringParam name, StringParam value, int overwrite)
1072{
1073 return SDL_setenv_unsafe(name, value, overwrite);
1074}
1075
1090{
1091 return SDL_unsetenv_unsafe(name);
1092}
1093
1108using CompareCallback = SDL_CompareCallback;
1109
1154inline void qsort(void* base,
1155 size_t nmemb,
1156 size_t size,
1157 CompareCallback compare)
1158{
1159 SDL_qsort(base, nmemb, size, compare);
1160}
1161
1211inline void* bsearch(const void* key,
1212 const void* base,
1213 size_t nmemb,
1214 size_t size,
1215 CompareCallback compare)
1216{
1217 return SDL_bsearch(key, base, nmemb, size, compare);
1218}
1219
1235using CompareCallback_r = SDL_CompareCallback_r;
1236
1252using CompareCB = std::function<int(const void*, const void*)>;
1253
1306inline void qsort_r(void* base,
1307 size_t nmemb,
1308 size_t size,
1309 CompareCallback_r compare,
1310 void* userdata)
1311{
1312 SDL_qsort_r(base, nmemb, size, compare, userdata);
1313}
1314
1366inline void qsort_r(void* base, size_t nmemb, size_t size, CompareCB compare)
1367{
1368 return qsort_r(
1369 base,
1370 nmemb,
1371 size,
1372 [](void* userdata, const void* a, const void* b) {
1373 auto& cb = *static_cast<CompareCB*>(userdata);
1374 return cb(a, b);
1375 },
1376 &compare);
1377}
1378
1436inline void* bsearch_r(const void* key,
1437 const void* base,
1438 size_t nmemb,
1439 size_t size,
1440 CompareCallback_r compare,
1441 void* userdata)
1442{
1443 return SDL_bsearch_r(key, base, nmemb, size, compare, userdata);
1444}
1445
1502inline void* bsearch_r(const void* key,
1503 const void* base,
1504 size_t nmemb,
1505 size_t size,
1506 CompareCB compare)
1507{
1508 return bsearch_r(
1509 key,
1510 base,
1511 nmemb,
1512 size,
1513 [](void* userdata, const void* a, const void* b) {
1514 auto& cb = *static_cast<CompareCB*>(userdata);
1515 return cb(a, b);
1516 },
1517 &compare);
1518}
1519
1530inline int abs(int x) { return SDL_abs(x); }
1531
1548inline double abs(double x) { return SDL_fabs(x); }
1549
1566inline float abs(float x) { return SDL_fabsf(x); }
1567
1584template<class T, class U>
1585constexpr T min(T x, U y)
1586{
1587 return SDL_min(x, y);
1588}
1589
1606template<class T, class U>
1607constexpr T max(T x, U y)
1608{
1609 return SDL_max(x, y);
1610}
1611
1634template<class T, class U, class V>
1635constexpr T clamp(T x, U a, V b)
1636{
1637 return SDL_clamp(x, a, b);
1638}
1639
1653inline int isalpha(int x) { return SDL_isalpha(x); }
1654
1668inline int isalnum(int x) { return SDL_isalnum(x); }
1669
1683inline int isblank(int x) { return SDL_isblank(x); }
1684
1698inline int iscntrl(int x) { return SDL_iscntrl(x); }
1699
1713inline int isdigit(int x) { return SDL_isdigit(x); }
1714
1728inline int isxdigit(int x) { return SDL_isxdigit(x); }
1729
1746inline int ispunct(int x) { return SDL_ispunct(x); }
1747
1768inline int isspace(int x) { return SDL_isspace(x); }
1769
1783inline int isupper(int x) { return SDL_isupper(x); }
1784
1798inline int islower(int x) { return SDL_islower(x); }
1799
1817inline int isprint(int x) { return SDL_isprint(x); }
1818
1838inline int isgraph(int x) { return SDL_isgraph(x); }
1839
1856inline int toupper(int x) { return SDL_toupper(x); }
1857
1874inline int tolower(int x) { return SDL_tolower(x); }
1875
1895inline Uint16 crc16(Uint16 crc, const void* data, size_t len)
1896{
1897 return SDL_crc16(crc, data, len);
1898}
1899
1919inline Uint32 crc32(Uint32 crc, const void* data, size_t len)
1920{
1921 return SDL_crc32(crc, data, len);
1922}
1923
1948inline Uint32 murmur3_32(const void* data, size_t len, Uint32 seed)
1949{
1950 return SDL_murmur3_32(data, len, seed);
1951}
1952
1971inline void* memcpy(void* dst, const void* src, size_t len)
1972{
1973#ifdef SDL_SLOW_MEMCPY
1974 return SDL_memcpy(dst, src, len);
1975#else
1976 return ::memcpy(dst, src, len);
1977#endif // SDL_SLOW_MEMCPY
1978}
1979
1980#ifdef SDL3PP_DOC
1981
2006#define SDL_copyp(dst, src) \
2007 { \
2008 SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof(*(dst)) == sizeof(*(src))); \
2009 } \
2010 SDL_memcpy((dst), (src), sizeof(*(src)))
2011
2012#endif // SDL3PP_DOC
2013
2031inline void* memmove(void* dst, const void* src, size_t len)
2032{
2033#ifdef SDL_SLOW_MEMMOVE
2034 return SDL_memmove(dst, src, len);
2035#else
2036 return ::memmove(dst, src, len);
2037#endif // SDL_SLOW_MEMMOVE
2038}
2039
2058inline void* memset(void* dst, int c, size_t len)
2059{
2060#ifdef SDL_SLOW_MEMSET
2061 return SDL_memset(dst, c, len);
2062#else
2063 return ::memset(dst, c, len);
2064#endif // SDL_SLOW_MEMSET
2065}
2066
2085inline void* memset4(void* dst, Uint32 val, size_t dwords)
2086{
2087 return SDL_memset4(dst, val, dwords);
2088}
2089
2107template<class T>
2108inline void zero(T& x)
2109{
2110 SDL_zero(x);
2111}
2112
2130template<class T>
2131inline void zerop(T* x)
2132{
2133 SDL_zerop(x);
2134}
2135
2153template<class T, std::size_t N>
2154inline void zeroa(T (&x)[N])
2155{
2156 SDL_zeroa(x);
2157}
2158
2173inline int memcmp(const void* s1, const void* s2, size_t len)
2174{
2175 return SDL_memcmp(s1, s2, len);
2176}
2177
2203inline size_t wcslen(const wchar_t* wstr) { return SDL_wcslen(wstr); }
2204
2234inline size_t wcsnlen(const wchar_t* wstr, size_t maxlen)
2235{
2236 return SDL_wcsnlen(wstr, maxlen);
2237}
2238
2264inline size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t maxlen)
2265{
2266 return SDL_wcslcpy(dst, src, maxlen);
2267}
2268
2296inline size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t maxlen)
2297{
2298 return SDL_wcslcat(dst, src, maxlen);
2299}
2300
2317inline wchar_t* wcsdup(const wchar_t* wstr) { return SDL_wcsdup(wstr); }
2318
2337inline wchar_t* wcsstr(const wchar_t* haystack, const wchar_t* needle)
2338{
2339 return SDL_wcsstr(haystack, needle);
2340}
2341
2365inline wchar_t* wcsnstr(const wchar_t* haystack,
2366 const wchar_t* needle,
2367 size_t maxlen)
2368{
2369 return SDL_wcsnstr(haystack, needle, maxlen);
2370}
2371
2389inline int wcscmp(const wchar_t* str1, const wchar_t* str2)
2390{
2391 return SDL_wcscmp(str1, str2);
2392}
2393
2423inline int wcsncmp(const wchar_t* str1, const wchar_t* str2, size_t maxlen)
2424{
2425 return SDL_wcsncmp(str1, str2, maxlen);
2426}
2427
2456inline int wcscasecmp(const wchar_t* str1, const wchar_t* str2)
2457{
2458 return SDL_wcscasecmp(str1, str2);
2459}
2460
2501inline int wcsncasecmp(const wchar_t* str1, const wchar_t* str2, size_t maxlen)
2502{
2503 return SDL_wcsncasecmp(str1, str2, maxlen);
2504}
2505
2531inline long wcstol(const wchar_t* str, wchar_t** endp, int base)
2532{
2533 return SDL_wcstol(str, endp, base);
2534}
2535
2554inline size_t strlen(StringParam str) { return SDL_strlen(str); }
2555
2578inline size_t strnlen(StringParam str, size_t maxlen)
2579{
2580 return SDL_strnlen(str, maxlen);
2581}
2582
2610inline size_t strlcpy(char* dst, StringParam src, size_t maxlen)
2611{
2612 return SDL_strlcpy(dst, src, maxlen);
2613}
2614
2641inline size_t utf8strlcpy(char* dst, StringParam src, size_t dst_bytes)
2642{
2643 return SDL_utf8strlcpy(dst, src, dst_bytes);
2644}
2645
2672inline size_t strlcat(char* dst, StringParam src, size_t maxlen)
2673{
2674 return SDL_strlcat(dst, src, maxlen);
2675}
2676
2693inline char* strdup(StringParam str) { return SDL_strdup(str); }
2694
2718inline char* strndup(StringParam str, size_t maxlen)
2719{
2720 return SDL_strndup(str, maxlen);
2721}
2722
2742inline char* strrev(char* str) { return SDL_strrev(str); }
2743
2763inline char* strupr(char* str) { return SDL_strupr(str); }
2764
2784inline char* strlwr(char* str) { return SDL_strlwr(str); }
2785
2804inline char* strchr(StringParam str, int c) { return SDL_strchr(str, c); }
2805
2823inline char* strrchr(StringParam str, int c) { return SDL_strrchr(str, c); }
2824
2843inline char* strstr(StringParam haystack, StringParam needle)
2844{
2845 return SDL_strstr(haystack, needle);
2846}
2847
2869inline char* strnstr(StringParam haystack, StringParam needle, size_t maxlen)
2870{
2871 return SDL_strnstr(haystack, needle, maxlen);
2872}
2873
2900inline char* strcasestr(StringParam haystack, StringParam needle)
2901{
2902 return SDL_strcasestr(haystack, needle);
2903}
2904
2932inline char* strtok_r(char* str, StringParam delim, char** saveptr)
2933{
2934 return SDL_strtok_r(str, delim, saveptr);
2935}
2936
2963inline size_t utf8strlen(StringParam str) { return SDL_utf8strlen(str); }
2964
2996inline size_t utf8strnlen(StringParam str, size_t bytes)
2997{
2998 return SDL_utf8strnlen(str, bytes);
2999}
3000
3027inline char* itoa(int value, char* str, int radix)
3028{
3029 return SDL_itoa(value, str, radix);
3030}
3031
3058inline char* uitoa(unsigned int value, char* str, int radix)
3059{
3060 return SDL_uitoa(value, str, radix);
3061}
3062
3089inline char* ltoa(long value, char* str, int radix)
3090{
3091 return SDL_ltoa(value, str, radix);
3092}
3093
3120inline char* ultoa(unsigned long value, char* str, int radix)
3121{
3122 return SDL_ultoa(value, str, radix);
3123}
3124
3146inline int atoi(StringParam str) { return SDL_atoi(str); }
3147
3168inline double atof(StringParam str) { return SDL_atof(str); }
3169
3202inline long strtol(StringParam str, char** endp, int base)
3203{
3204 return SDL_strtol(str, endp, base);
3205}
3206
3238inline unsigned long strtoul(StringParam str, char** endp, int base)
3239{
3240 return SDL_strtoul(str, endp, base);
3241}
3242
3270inline double strtod(StringParam str, char** endp)
3271{
3272 return SDL_strtod(str, endp);
3273}
3274
3293inline int strcmp(StringParam str1, StringParam str2)
3294{
3295 return SDL_strcmp(str1, str2);
3296}
3297
3326inline int strncmp(StringParam str1, StringParam str2, size_t maxlen)
3327{
3328 return SDL_strncmp(str1, str2, maxlen);
3329}
3330
3357inline int strcasecmp(StringParam str1, StringParam str2)
3358{
3359 return SDL_strcasecmp(str1, str2);
3360}
3361
3399inline int strncasecmp(StringParam str1, StringParam str2, size_t maxlen)
3400{
3401 return SDL_strncasecmp(str1, str2, maxlen);
3402}
3403
3420inline char* strpbrk(StringParam str, StringParam breakset)
3421{
3422 return SDL_strpbrk(str, breakset);
3423}
3424
3438constexpr Uint32 INVALID_UNICODE_CODEPOINT = SDL_INVALID_UNICODE_CODEPOINT;
3439
3483inline Uint32 StepUTF8(const char** pstr, size_t* pslen)
3484{
3485 return SDL_StepUTF8(pstr, pslen);
3486}
3487
3517inline Uint32 StepBackUTF8(StringParam start, const char** pstr)
3518{
3519 return SDL_StepBackUTF8(start, pstr);
3520}
3521
3549inline char* UCS4ToUTF8(Uint32 codepoint, char* dst)
3550{
3551 return SDL_UCS4ToUTF8(codepoint, dst);
3552}
3553
3569inline int sscanf(StringParam text,
3570 SDL_SCANF_FORMAT_STRING const char* fmt,
3571 ...)
3572{
3573 int rc;
3574 va_list ap;
3575 va_start(ap, fmt);
3576 rc = SDL_vsscanf(text, fmt, ap);
3577 va_end(ap);
3578 return rc;
3579}
3580
3598inline int vsscanf(StringParam text,
3599 SDL_SCANF_FORMAT_STRING const char* fmt,
3600 va_list ap)
3601{
3602 return SDL_vsscanf(text, fmt, ap);
3603}
3604
3636inline int snprintf(char* text,
3637 size_t maxlen,
3638 SDL_PRINTF_FORMAT_STRING const char* fmt,
3639 ...)
3640{
3641 va_list ap;
3642 int result;
3643
3644 va_start(ap, fmt);
3645 result = SDL_vsnprintf(text, maxlen, fmt, ap);
3646 va_end(ap);
3647
3648 return result;
3649}
3650
3683inline int swprintf(wchar_t* text,
3684 size_t maxlen,
3685 SDL_PRINTF_FORMAT_STRING const wchar_t* fmt,
3686 ...)
3687{
3688 va_list ap;
3689 int result;
3690
3691 va_start(ap, fmt);
3692 result = SDL_vswprintf(text, maxlen, fmt, ap);
3693 va_end(ap);
3694
3695 return result;
3696}
3697
3716inline int vsnprintf(char* text,
3717 size_t maxlen,
3718 SDL_PRINTF_FORMAT_STRING const char* fmt,
3719 va_list ap)
3720{
3721 return SDL_vsnprintf(text, maxlen, fmt, ap);
3722}
3723
3743inline int vswprintf(wchar_t* text,
3744 size_t maxlen,
3745 SDL_PRINTF_FORMAT_STRING const wchar_t* fmt,
3746 va_list ap)
3747{
3748 return SDL_vswprintf(text, maxlen, fmt, ap);
3749}
3750
3778inline int asprintf(char** strp, SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
3779{
3780 va_list ap;
3781 int result;
3782
3783 va_start(ap, fmt);
3784 result = SDL_vasprintf(strp, fmt, ap);
3785 va_end(ap);
3786
3787 return result;
3788}
3789
3807inline int vasprintf(char** strp,
3808 SDL_PRINTF_FORMAT_STRING const char* fmt,
3809 va_list ap)
3810{
3811 return SDL_vasprintf(strp, fmt, ap);
3812}
3813
3832inline void srand(Uint64 seed) { SDL_srand(seed); }
3833
3866inline Sint32 rand(Sint32 n) { return SDL_rand(n); }
3867
3888inline float randf() { return SDL_randf(); }
3889
3911inline Uint32 rand_bits() { return SDL_rand_bits(); }
3912
3924{
3925 Uint64 m_state;
3926
3927public:
3931 constexpr Random(Uint64 state)
3932 : m_state(state)
3933 {
3934 }
3935
3937 constexpr operator Uint64() { return m_state; }
3938
3970 Sint32 rand(Sint32 n) { return SDL_rand_r(&m_state, n); }
3971
3995 float randf() { return SDL_randf_r(&m_state); }
3996
4018 Uint32 rand_bits() { return SDL_rand_bits_r(&m_state); }
4019};
4020
4028constexpr double PI_D = SDL_PI_D;
4029
4037constexpr float PI_F = SDL_PI_F;
4038
4063inline double acos(double x) { return SDL_acos(x); }
4064
4089inline float acos(float x) { return SDL_acosf(x); }
4090
4115inline double asin(double x) { return SDL_asin(x); }
4116
4144inline float asin(float x) { return SDL_asinf(x); }
4145
4172inline double atan(double x) { return SDL_atan(x); }
4173
4199inline float atan(float x) { return SDL_atanf(x); }
4200
4232inline double atan2(double y, double x) { return SDL_atan2(y, x); }
4233
4265inline float atan2(float y, float x) { return SDL_atan2f(y, x); }
4266
4289inline double ceil(double x) { return SDL_ceil(x); }
4290
4313inline float ceil(float x) { return SDL_ceilf(x); }
4314
4335inline double copysign(double x, double y) { return SDL_copysign(x, y); }
4336
4357inline float copysign(float x, float y) { return SDL_copysignf(x, y); }
4358
4381inline double cos(double x) { return SDL_cos(x); }
4382
4405inline float cos(float x) { return SDL_cosf(x); }
4406
4433inline double exp(double x) { return SDL_exp(x); }
4434
4461inline float exp(float x) { return SDL_expf(x); }
4462
4485inline double floor(double x) { return SDL_floor(x); }
4486
4509inline float floor(float x) { return SDL_floorf(x); }
4510
4534inline double trunc(double x) { return SDL_trunc(x); }
4535
4559inline float trunc(float x) { return SDL_truncf(x); }
4560
4585inline double fmod(double x, double y) { return SDL_fmod(x, y); }
4586
4611inline float fmod(float x, float y) { return SDL_fmodf(x, y); }
4612
4623inline int isinf(double x) { return SDL_isinf(x); }
4624
4635inline int isinf(float x) { return SDL_isinff(x); }
4636
4647inline int isnan(double x) { return SDL_isnan(x); }
4648
4659inline int isnan(float x) { return SDL_isnanf(x); }
4660
4685inline double log(double x) { return SDL_log(x); }
4686
4711inline float log(float x) { return SDL_logf(x); }
4712
4737inline double log10(double x) { return SDL_log10(x); }
4738
4763inline float log10(float x) { return SDL_log10f(x); }
4764
4779inline double modf(double x, double* y) { return SDL_modf(x, y); }
4780
4795inline float modf(float x, float* y) { return SDL_modff(x, y); }
4796
4823inline double pow(double x, double y) { return SDL_pow(x, y); }
4824
4851inline float pow(float x, float y) { return SDL_powf(x, y); }
4852
4875inline double round(double x) { return SDL_round(x); }
4876
4899inline float round(float x) { return SDL_roundf(x); }
4900
4923inline long lround(double x) { return SDL_lround(x); }
4924
4947inline long lround(float x) { return SDL_lroundf(x); }
4948
4968inline double scalbn(double x, int n) { return SDL_scalbn(x, n); }
4969
4989inline float scalbn(float x, int n) { return SDL_scalbnf(x, n); }
4990
5013inline double sin(double x) { return SDL_sin(x); }
5014
5037inline float sin(float x) { return SDL_sinf(x); }
5038
5058inline double sqrt(double x) { return SDL_sqrt(x); }
5059
5079inline float sqrt(float x) { return SDL_sqrtf(x); }
5080
5105inline double tan(double x) { return SDL_tan(x); }
5106
5134inline float tan(float x) { return SDL_tanf(x); }
5135
5146struct IConvRef : Resource<SDL_iconv_data_t*>
5147{
5148 using Resource::Resource;
5149
5184 size_t iconv(const char** inbuf,
5185 size_t* inbytesleft,
5186 char** outbuf,
5187 size_t* outbytesleft)
5188 {
5189 return SDL_iconv(get(), inbuf, inbytesleft, outbuf, outbytesleft);
5190 }
5191
5204 static void reset(SDL_iconv_data_t* resource)
5205 {
5206 CheckError(SDL_iconv_close(resource) == 0);
5207 }
5208};
5209
5217struct IConv : ResourceUnique<IConvRef>
5218{
5220
5236 static IConv open(StringParam tocode, StringParam fromcode)
5237 {
5238 return IConv(SDL_iconv_open(tocode, fromcode));
5239 }
5240
5253 void close() { reset(); }
5258
5259};
5260
5261
5263{
5264 return IConvShared(std::move(*this));
5265}
5266
5276struct IConvUnsafe : ResourceUnsafe<IConvRef>
5277{
5279
5283 constexpr explicit IConvUnsafe(IConv&& other)
5284 : IConvUnsafe(other.release())
5285 {
5286 }
5287};
5288
5289#ifdef SDL3PP_DOC
5290
5294#define SDL_ICONV_ERROR (size_t)-1
5295
5299#define SDL_ICONV_E2BIG (size_t)-2
5300
5304#define SDL_ICONV_EILSEQ (size_t)-3
5305
5309#define SDL_ICONV_EINVAL (size_t)-4
5310
5311#endif // SDL3PP_DOC
5312
5336 StringParam fromcode,
5337 StringParam inbuf,
5338 size_t inbytesleft)
5339{
5340 return OwnPtr<char>{SDL_iconv_string(tocode, fromcode, inbuf, inbytesleft)};
5341}
5342
5343#ifdef SDL3PP_DOC
5344
5357#define SDL_iconv_utf8_locale(S) \
5358 SDL_iconv_string("", "UTF-8", S, SDL_strlen(S) + 1)
5359
5372#define SDL_iconv_utf8_ucs2(S) \
5373 (Uint16*)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S) + 1)
5374
5387#define SDL_iconv_utf8_ucs4(S) \
5388 (Uint32*)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S) + 1)
5389
5402#define SDL_iconv_wchar_utf8(S) \
5403 SDL_iconv_string( \
5404 "UTF-8", "WCHAR_T", (char*)S, (SDL_wcslen(S) + 1) * sizeof(wchar_t))
5405
5406#endif // SDL3PP_DOC
5407
5425inline bool size_mul_check_overflow(size_t a, size_t b, size_t* ret)
5426{
5427 return SDL_size_mul_check_overflow(a, b, ret);
5428}
5429
5447inline bool size_add_check_overflow(size_t a, size_t b, size_t* ret)
5448{
5449 return SDL_size_add_check_overflow(a, b, ret);
5450}
5451
5467using FunctionPointer = SDL_FunctionPointer;
5468
5469#pragma region impl
5471
5472inline void PtrDeleter::operator()(void* ptr) const { SDL_free(ptr); }
5473
5474#pragma endregion impl
5475
5476} // namespace SDL
5477
5478#endif /* SDL3PP_STDINC_H_ */
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:43
A independent pseudo random state.
Definition SDL3pp_stdinc.h:3924
constexpr Random(Uint64 state)
Init state with the given value.
Definition SDL3pp_stdinc.h:3931
float randf()
Generate a uniform pseudo-random floating point number less than 1.0.
Definition SDL3pp_stdinc.h:3995
Uint32 rand_bits()
Generate 32 pseudo-random bits.
Definition SDL3pp_stdinc.h:4018
Sint32 rand(Sint32 n)
Generate a pseudo-random number less than n for positive n.
Definition SDL3pp_stdinc.h:3970
RESOURCE release()
Returns reference and reset this.
Definition SDL3pp_resource.h:178
Implement shared ownership for a resource.
Definition SDL3pp_resource.h:283
Implement unique ownership for a resource.
Definition SDL3pp_resource.h:226
constexpr ResourceUnique(std::nullptr_t=nullptr)
Default constructor.
Definition SDL3pp_resource.h:231
void reset()
Resets the value, destroying the resource if not nullptr.
Definition SDL3pp_resource.h:265
A dumb pointer to resource.
Definition SDL3pp_resource.h:197
constexpr ResourceUnsafe()=default
Default constructor.
Implement weak ownership for a resource.
Definition SDL3pp_resource.h:328
A SDL managed resource.
Definition SDL3pp_resource.h:29
constexpr Resource(T resource={})
Constructs from the underlying resource.
Definition SDL3pp_resource.h:37
constexpr SDL_Environment * get() const
Return contained resource;.
Definition SDL3pp_resource.h:76
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:293
constexpr Sint64 ToNS() const
Converts to nanoseconds Sint64.
Definition SDL3pp_stdinc.h:329
constexpr Time & operator+=(std::chrono::nanoseconds interval)
Increment time.
Definition SDL3pp_stdinc.h:354
constexpr float ToSeconds() const
Converts a time to seconds (float) since epoch.
Definition SDL3pp_stdinc.h:342
constexpr Time & operator-=(std::chrono::nanoseconds interval)
Decrement.
Definition SDL3pp_stdinc.h:361
constexpr Time(SDL_Time time)
Constructs from SDL_Time.
Definition SDL3pp_stdinc.h:306
constexpr Time(std::chrono::nanoseconds time)
Constructs from a nanoseconds period.
Definition SDL3pp_stdinc.h:300
static constexpr Time FromNS(Sint64 time)
Create from a nanoseconds Sint64.
Definition SDL3pp_stdinc.h:323
static constexpr Time FromSeconds(float interval)
Converts a time to seconds (float) since epoch.
Definition SDL3pp_stdinc.h:347
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
std::unique_ptr< T, PtrDeleter > OwnPtr
Handle to an owned SDL memory allocated pointer.
Definition SDL3pp_ownPtr.h:32
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:2423
double log(double x)
Compute the natural logarithm of x.
Definition SDL3pp_stdinc.h:4685
char * UCS4ToUTF8(Uint32 codepoint, char *dst)
Convert a single Unicode codepoint to UTF-8.
Definition SDL3pp_stdinc.h:3549
long wcstol(const wchar_t *str, wchar_t **endp, int base)
Parse a long from a wide string.
Definition SDL3pp_stdinc.h:2531
char * strdup(StringParam str)
Allocate a copy of a string.
Definition SDL3pp_stdinc.h:2693
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:701
double strtod(StringParam str, char **endp)
Parse a double from a string.
Definition SDL3pp_stdinc.h:3270
ResourceShared< IConv > IConvShared
Handle to a shared iConv.
Definition SDL3pp_stdinc.h:81
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:2900
double atan(double x)
Compute the arc tangent of x.
Definition SDL3pp_stdinc.h:4172
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:3778
double ceil(double x)
Compute the ceiling of x.
Definition SDL3pp_stdinc.h:4289
char * strlwr(char *str)
Convert a string to lowercase.
Definition SDL3pp_stdinc.h:2784
void * memmove(void *dst, const void *src, size_t len)
Copy memory ranges that might overlap.
Definition SDL3pp_stdinc.h:2031
int memcmp(const void *s1, const void *s2, size_t len)
Compare two buffers of memory.
Definition SDL3pp_stdinc.h:2173
constexpr std::size_t arraysize(const T(&array)[N])
The number of elements in a static array.
Definition SDL3pp_stdinc.h:140
SDL_malloc_func malloc_func
A callback used to implement malloc().
Definition SDL3pp_stdinc.h:563
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:2869
int isnan(double x)
Return whether the value is NaN.
Definition SDL3pp_stdinc.h:4647
constexpr Uint32 INVALID_UNICODE_CODEPOINT
The Unicode REPLACEMENT CHARACTER codepoint.
Definition SDL3pp_stdinc.h:3438
double scalbn(double x, int n)
Scale x by an integer power of two.
Definition SDL3pp_stdinc.h:4968
char * ultoa(unsigned long value, char *str, int radix)
Convert an unsigned long integer into a string.
Definition SDL3pp_stdinc.h:3120
wchar_t * wcsdup(const wchar_t *wstr)
Allocate a copy of a wide string.
Definition SDL3pp_stdinc.h:2317
int isgraph(int x)
Report if a character is any "printable" except space.
Definition SDL3pp_stdinc.h:1838
int strncmp(StringParam str1, StringParam str2, size_t maxlen)
Compare two UTF-8 strings up to a number of bytes.
Definition SDL3pp_stdinc.h:3326
double asin(double x)
Compute the arc sine of x.
Definition SDL3pp_stdinc.h:4115
Uint16 crc16(Uint16 crc, const void *data, size_t len)
Calculate a CRC-16 value.
Definition SDL3pp_stdinc.h:1895
char * strrev(char *str)
Reverse a string's contents.
Definition SDL3pp_stdinc.h:2742
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:3399
constexpr T min(T x, U y)
Return the lesser of two values.
Definition SDL3pp_stdinc.h:1585
SDL_FunctionPointer FunctionPointer
A generic function pointer.
Definition SDL3pp_stdinc.h:5467
unsigned long strtoul(StringParam str, char **endp, int base)
Parse an unsigned long from a string.
Definition SDL3pp_stdinc.h:3238
int isdigit(int x)
Report if a character is a numeric digit.
Definition SDL3pp_stdinc.h:1713
std::chrono::duration< float > Seconds
Duration in seconds (float).
Definition SDL3pp_stdinc.h:249
double exp(double x)
Compute the exponential of x.
Definition SDL3pp_stdinc.h:4433
char * strstr(StringParam haystack, StringParam needle)
Search a string for the first instance of a specific substring.
Definition SDL3pp_stdinc.h:2843
EnvironmentShared share()
Move this environment into a EnvironmentShared.
Definition SDL3pp_stdinc.h:968
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:3716
char * strchr(StringParam str, int c)
Search a string for the first instance of a specific byte.
Definition SDL3pp_stdinc.h:2804
double copysign(double x, double y)
Copy the sign of one floating-point value to another.
Definition SDL3pp_stdinc.h:4335
void * malloc(size_t size)
Allocate uninitialized memory.
Definition SDL3pp_stdinc.h:456
double modf(double x, double *y)
Split x into integer and fractional parts.
Definition SDL3pp_stdinc.h:4779
void zero(T &x)
Clear an object's memory to zero.
Definition SDL3pp_stdinc.h:2108
SDL_calloc_func calloc_func
A callback used to implement calloc().
Definition SDL3pp_stdinc.h:584
size_t strlcat(char *dst, StringParam src, size_t maxlen)
Concatenate strings.
Definition SDL3pp_stdinc.h:2672
void zeroa(T(&x)[N])
Clear an array's memory to zero.
Definition SDL3pp_stdinc.h:2154
char * strndup(StringParam str, size_t maxlen)
Allocate a copy of a string, up to n characters.
Definition SDL3pp_stdinc.h:2718
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:3636
IConvShared share()
Move this iConv into a IConvShared.
Definition SDL3pp_stdinc.h:5262
double round(double x)
Round x to the nearest integer.
Definition SDL3pp_stdinc.h:4875
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:3569
size_t strlcpy(char *dst, StringParam src, size_t maxlen)
Copy a string.
Definition SDL3pp_stdinc.h:2610
void * memset(void *dst, int c, size_t len)
Initialize all bytes of buffer of memory to a specific value.
Definition SDL3pp_stdinc.h:2058
bool size_mul_check_overflow(size_t a, size_t b, size_t *ret)
Multiply two integers, checking for overflow.
Definition SDL3pp_stdinc.h:5425
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:642
int strcmp(StringParam str1, StringParam str2)
Compare two null-terminated UTF-8 strings.
Definition SDL3pp_stdinc.h:3293
bool size_add_check_overflow(size_t a, size_t b, size_t *ret)
Add two integers, checking for overflow.
Definition SDL3pp_stdinc.h:5447
char * uitoa(unsigned int value, char *str, int radix)
Convert an unsigned integer into a string.
Definition SDL3pp_stdinc.h:3058
double pow(double x, double y)
Raise x to the power y
Definition SDL3pp_stdinc.h:4823
int isprint(int x)
Report if a character is "printable".
Definition SDL3pp_stdinc.h:1817
long lround(double x)
Round x to the nearest integer representable as a long.
Definition SDL3pp_stdinc.h:4923
std::chrono::nanoseconds Nanoseconds
Duration in Nanoseconds (Uint64).
Definition SDL3pp_stdinc.h:254
int isxdigit(int x)
Report if a character is a hexadecimal digit.
Definition SDL3pp_stdinc.h:1728
constexpr T max(T x, U y)
Return the greater of two values.
Definition SDL3pp_stdinc.h:1607
int atoi(StringParam str)
Parse an int from a string.
Definition SDL3pp_stdinc.h:3146
int tolower(int x)
Convert low-ASCII English letters to lowercase.
Definition SDL3pp_stdinc.h:1874
int isalpha(int x)
Query if a character is alphabetic (a letter).
Definition SDL3pp_stdinc.h:1653
std::function< int(const void *, const void *)> CompareCB
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1252
int unsetenv_unsafe(StringParam name)
Clear a variable from the environment.
Definition SDL3pp_stdinc.h:1089
constexpr float ToSeconds(Seconds duration)
Converts a time duration to seconds (float).
Definition SDL3pp_stdinc.h:259
char * strupr(char *str)
Convert a string to uppercase.
Definition SDL3pp_stdinc.h:2763
SDL_free_func free_func
A callback used to implement free().
Definition SDL3pp_stdinc.h:623
size_t utf8strlen(StringParam str)
Count the number of codepoints in a UTF-8 string.
Definition SDL3pp_stdinc.h:2963
constexpr Seconds FromSeconds(float duration)
Converts a float to seconds representation.
Definition SDL3pp_stdinc.h:264
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:2996
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:3743
int isupper(int x)
Report if a character is upper case.
Definition SDL3pp_stdinc.h:1783
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:2234
double sqrt(double x)
Compute the square root of x.
Definition SDL3pp_stdinc.h:5058
void srand(Uint64 seed)
Seeds the pseudo-random number generator.
Definition SDL3pp_stdinc.h:3832
double tan(double x)
Compute the tangent of x.
Definition SDL3pp_stdinc.h:5105
double sin(double x)
Compute the sine of x.
Definition SDL3pp_stdinc.h:5013
const char * getenv_unsafe(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1050
size_t utf8strlcpy(char *dst, StringParam src, size_t dst_bytes)
Copy an UTF-8 string.
Definition SDL3pp_stdinc.h:2641
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:2932
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:2085
int iscntrl(int x)
Report if a character is a control character.
Definition SDL3pp_stdinc.h:1698
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:3683
constexpr double PI_D
The value of Pi, as a double-precision floating point literal.
Definition SDL3pp_stdinc.h:4028
int islower(int x)
Report if a character is lower case.
Definition SDL3pp_stdinc.h:1798
int isinf(double x)
Return whether the value is infinity.
Definition SDL3pp_stdinc.h:4623
int isspace(int x)
Report if a character is whitespace.
Definition SDL3pp_stdinc.h:1768
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:2578
int strcasecmp(StringParam str1, StringParam str2)
Compare two null-terminated UTF-8 strings, case-insensitively.
Definition SDL3pp_stdinc.h:3357
size_t strlen(StringParam str)
This works exactly like strlen() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:2554
const char * getenv(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1031
int setenv_unsafe(StringParam name, StringParam value, int overwrite)
Set the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1071
int wcscmp(const wchar_t *str1, const wchar_t *str2)
Compare two null-terminated wide strings.
Definition SDL3pp_stdinc.h:2389
double acos(double x)
Compute the arc cosine of x.
Definition SDL3pp_stdinc.h:4063
Sint32 rand(Sint32 n)
Generate a pseudo-random number less than n for positive n.
Definition SDL3pp_stdinc.h:3866
SDL_realloc_func realloc_func
A callback used to implement realloc().
Definition SDL3pp_stdinc.h:605
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:1306
double floor(double x)
Compute the floor of x.
Definition SDL3pp_stdinc.h:4485
Uint32 StepUTF8(const char **pstr, size_t *pslen)
Decode a UTF-8 string, one Unicode codepoint at a time.
Definition SDL3pp_stdinc.h:3483
int toupper(int x)
Convert low-ASCII English letters to uppercase.
Definition SDL3pp_stdinc.h:1856
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:1948
constexpr Uint32 FourCC(Uint8 a, Uint8 b, Uint8 c, Uint8 d)
Define a four character code as a Uint32.
Definition SDL3pp_stdinc.h:179
Uint32 StepBackUTF8(StringParam start, const char **pstr)
Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
Definition SDL3pp_stdinc.h:3517
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
Copy a wide string.
Definition SDL3pp_stdinc.h:2264
float randf()
Generate a uniform pseudo-random floating point number less than 1.0.
Definition SDL3pp_stdinc.h:3888
constexpr T clamp(T x, U a, V b)
Return a value clamped to a range.
Definition SDL3pp_stdinc.h:1635
constexpr Nanoseconds FromNS(Sint64 duration)
Converts a Sint64 to nanoseconds representation.
Definition SDL3pp_stdinc.h:277
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:2501
void aligned_free(void *mem)
Free memory allocated by aligned_alloc().
Definition SDL3pp_stdinc.h:753
void zerop(T *x)
Clear an object's memory to zero, using a pointer.
Definition SDL3pp_stdinc.h:2131
int abs(int x)
Compute the absolute value of x.
Definition SDL3pp_stdinc.h:1530
ResourceShared< Environment > EnvironmentShared
Handle to a shared environment.
Definition SDL3pp_stdinc.h:55
void * calloc(size_t nmemb, size_t size)
Allocate a zero-initialized array.
Definition SDL3pp_stdinc.h:481
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:668
void qsort(void *base, size_t nmemb, size_t size, CompareCallback compare)
Sort an array.
Definition SDL3pp_stdinc.h:1154
SDL_CompareCallback_r CompareCallback_r
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1235
int isblank(int x)
Report if a character is blank (a space or tab).
Definition SDL3pp_stdinc.h:1683
void * realloc(void *mem, size_t size)
Change the size of allocated memory.
Definition SDL3pp_stdinc.h:524
SDL_CompareCallback CompareCallback
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1108
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:3807
char * itoa(int value, char *str, int radix)
Convert an integer into a string.
Definition SDL3pp_stdinc.h:3027
int ispunct(int x)
Report if a character is a punctuation mark.
Definition SDL3pp_stdinc.h:1746
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:3598
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:2365
Uint32 crc32(Uint32 crc, const void *data, size_t len)
Calculate a CRC-32 value.
Definition SDL3pp_stdinc.h:1919
double log10(double x)
Compute the base-10 logarithm of x.
Definition SDL3pp_stdinc.h:4737
constexpr float PI_F
The value of Pi, as a single-precision floating point literal.
Definition SDL3pp_stdinc.h:4037
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:2337
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:1211
double cos(double x)
Compute the cosine of x.
Definition SDL3pp_stdinc.h:4381
void free(void *mem)
Free allocated memory.
Definition SDL3pp_stdinc.h:544
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:4232
int wcscasecmp(const wchar_t *str1, const wchar_t *str2)
Compare two null-terminated wide strings, case-insensitively.
Definition SDL3pp_stdinc.h:2456
char * strpbrk(StringParam str, StringParam breakset)
Searches a string for the first occurence of any character contained in a breakset,...
Definition SDL3pp_stdinc.h:3420
void * aligned_alloc(size_t alignment, size_t size)
Allocate memory aligned to a specific alignment.
Definition SDL3pp_stdinc.h:732
int GetNumAllocations()
Get the number of outstanding (unfreed) allocations.
Definition SDL3pp_stdinc.h:765
Uint32 rand_bits()
Generate 32 pseudo-random bits.
Definition SDL3pp_stdinc.h:3911
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:5335
double trunc(double x)
Truncate x to an integer.
Definition SDL3pp_stdinc.h:4534
char * ltoa(long value, char *str, int radix)
Convert a long integer into a string.
Definition SDL3pp_stdinc.h:3089
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
Concatenate wide strings.
Definition SDL3pp_stdinc.h:2296
double atof(StringParam str)
Parse a double from a string.
Definition SDL3pp_stdinc.h:3168
constexpr Sint64 ToNS(std::chrono::nanoseconds duration)
Converts a time duration to nanoseconds (Sint64);.
Definition SDL3pp_stdinc.h:269
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:1436
long strtol(StringParam str, char **endp, int base)
Parse a long from a string.
Definition SDL3pp_stdinc.h:3202
char * strrchr(StringParam str, int c)
Search a string for the last instance of a specific byte.
Definition SDL3pp_stdinc.h:2823
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:2203
int isalnum(int x)
Query if a character is alphabetic (a letter) or a number.
Definition SDL3pp_stdinc.h:1668
EnvironmentRef GetEnvironment()
Get the process environment.
Definition SDL3pp_stdinc.h:1016
double fmod(double x, double y)
Return the floating-point remainder of x / y
Definition SDL3pp_stdinc.h:4585
void * memcpy(void *dst, const void *src, size_t len)
Copy non-overlapping memory.
Definition SDL3pp_stdinc.h:1971
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:394
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:376
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:356
constexpr Sint64 ToPosix() const
Convert nanoseconds to seconds.
Definition SDL3pp_timer.h:58
static constexpr Time FromPosix(Sint64 time)
Convert seconds to nanoseconds.
Definition SDL3pp_timer.h:42
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
A thread-safe set of environment variables.
Definition SDL3pp_stdinc.h:784
void UnsetVariable(StringParam name)
Clear a variable from the environment.
Definition SDL3pp_stdinc.h:889
Uint64 GetVariableCount()
Get the Variables count.
Definition SDL3pp_stdinc.h:840
OwnArray< char * > GetVariables()
Get all variables in the environment.
Definition SDL3pp_stdinc.h:828
static void reset(SDL_Environment *resource)
Destroy a set of environment variables.
Definition SDL3pp_stdinc.h:906
void SetVariable(StringParam name, StringParam value, bool overwrite)
Set the value of a variable in the environment.
Definition SDL3pp_stdinc.h:867
const char * GetVariable(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:804
Unsafe Handle to environment.
Definition SDL3pp_stdinc.h:983
constexpr EnvironmentUnsafe(Environment &&other)
Constructs EnvironmentUnsafe from Environment.
Definition SDL3pp_stdinc.h:989
Handle to an owned environment.
Definition SDL3pp_stdinc.h:920
static Environment Create(bool populated)
Create a set of environment variables.
Definition SDL3pp_stdinc.h:943
void Destroy()
Destroy a set of environment variables.
Definition SDL3pp_stdinc.h:959
An opaque handle representing string encoding conversion state.
Definition SDL3pp_stdinc.h:5147
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:5184
static void reset(SDL_iconv_data_t *resource)
This function frees a context used for character set conversion.
Definition SDL3pp_stdinc.h:5204
Unsafe Handle to iConv.
Definition SDL3pp_stdinc.h:5277
constexpr IConvUnsafe(IConv &&other)
Constructs IConvUnsafe from IConv.
Definition SDL3pp_stdinc.h:5283
Handle to an owned iConv.
Definition SDL3pp_stdinc.h:5218
static IConv open(StringParam tocode, StringParam fromcode)
This function allocates a context for the specified character set conversion.
Definition SDL3pp_stdinc.h:5236
void close()
This function frees a context used for character set conversion.
Definition SDL3pp_stdinc.h:5253