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_lockBase.h"
9#include "SDL3pp_optionalRef.h"
10#include "SDL3pp_ownPtr.h"
11#include "SDL3pp_resource.h"
12#include "SDL3pp_spanRef.h"
13#include "SDL3pp_strings.h"
14
15namespace SDL {
16
43// Forward decl
44struct EnvironmentBase;
45
46// Forward decl
47struct EnvironmentRef;
48
49// Forward decl
50struct Environment;
51
52// Forward decl
53struct IConvBase;
54
55// Forward decl
56struct IConvRef;
57
58// Forward decl
59struct IConv;
60
61#ifdef SDL3PP_DOC
62
79#define SDL_NOLONGLONG 1
80
95#define SDL_SIZE_MAX SIZE_MAX
96
97#endif // SDL3PP_DOC
98
107template<class T, std::size_t N>
108constexpr std::size_t arraysize(const T (&array)[N])
109{
110 return SDL_arraysize(array);
111}
112
113#ifdef SDL3PP_DOC
114
129#define SDL_STRINGIFY_ARG(arg) #arg
130
131#endif // SDL3PP_DOC
132
147constexpr Uint32 FourCC(Uint8 a, Uint8 b, Uint8 c, Uint8 d)
148{
149 return SDL_FOURCC(a, b, c, d);
150}
151
152#ifdef SDL3PP_DOC
153
165#define SDL_SINT64_C(c) c##LL /* or whatever the current compiler uses. */
166
178#define SDL_UINT64_C(c) c##ULL /* or whatever the current compiler uses. */
179
180#endif // SDL3PP_DOC
181
182constexpr Sint8 MAX_SINT8 = SDL_MAX_SINT8;
183
184constexpr Sint8 MIN_SINT8 = SDL_MIN_SINT8;
185
186constexpr Uint8 MAX_UINT8 = SDL_MAX_UINT8;
187
188constexpr Uint8 MIN_UINT8 = SDL_MIN_UINT8;
189
190constexpr Sint16 MAX_SINT16 = SDL_MAX_SINT16;
191
192constexpr Sint16 MIN_SINT16 = SDL_MIN_SINT16;
193
194constexpr Uint16 MAX_UINT16 = SDL_MAX_UINT16;
195
196constexpr Uint16 MIN_UINT16 = SDL_MIN_UINT16;
197
198constexpr Sint32 MAX_SINT32 = SDL_MAX_SINT32;
199
200constexpr Sint32 MIN_SINT32 = SDL_MIN_SINT32;
201
202constexpr Uint32 MAX_UINT32 = SDL_MAX_UINT32;
203
204constexpr Uint8 MIN_UINT32 = SDL_MIN_UINT32;
205
206constexpr Sint64 MAX_SINT64 = SDL_MAX_SINT64;
207
208constexpr Sint64 MIN_SINT64 = SDL_MIN_SINT64;
209
210constexpr Uint64 MAX_UINT64 = SDL_MAX_UINT64;
211
212constexpr Uint8 MIN_UINT64 = SDL_MIN_UINT64;
213
217using Seconds = std::chrono::duration<float>;
218
222using Nanoseconds = std::chrono::nanoseconds;
223
227constexpr float ToSeconds(Seconds duration) { return duration.count(); }
228
232constexpr Seconds FromSeconds(float duration) { return Seconds(duration); }
233
237constexpr Sint64 ToNS(std::chrono::nanoseconds duration)
238{
239 return duration.count();
240}
241
245constexpr Nanoseconds FromNS(Sint64 duration) { return Nanoseconds{duration}; }
246
260class Time
261{
262 std::chrono::nanoseconds m_value;
263
264public:
265 constexpr Time() = default;
266
268 constexpr Time(std::chrono::nanoseconds time)
269 : m_value(time)
270 {
271 }
272
274 constexpr explicit Time(SDL_Time time)
275 : m_value(FromNS(time))
276 {
277 }
278
280 constexpr explicit operator bool() const
281 {
282 return m_value != std::chrono::nanoseconds{};
283 }
284
286 constexpr operator std::chrono::nanoseconds() const { return m_value; }
287
288 static Time Current();
289
291 static constexpr Time FromNS(Sint64 time)
292 {
293 return Time{std::chrono::nanoseconds{time}};
294 }
295
297 constexpr Sint64 ToNS() const { return m_value.count(); }
298
299 static constexpr Time FromPosix(Sint64 time);
300
301 constexpr Sint64 ToPosix() const;
302
303 static Time FromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime);
304
305 void ToWindows(Uint32* dwLowDateTime, Uint32* dwHighDateTime) const;
306
310 constexpr float ToSeconds() const { return Seconds(m_value).count(); }
311
315 static constexpr Time FromSeconds(float interval)
316 {
317 return std::chrono::duration_cast<std::chrono::nanoseconds>(
318 Seconds(interval));
319 }
320
322 constexpr Time& operator+=(std::chrono::nanoseconds interval)
323 {
324 m_value += interval;
325 return *this;
326 }
327
329 constexpr Time& operator-=(std::chrono::nanoseconds interval)
330 {
331 m_value -= interval;
332 return *this;
333 }
334};
335
336constexpr Time MAX_TIME = Time::FromNS(SDL_MAX_TIME);
337
338constexpr Time MIN_TIME = Time::FromNS(SDL_MIN_TIME);
339
340#ifdef SDL3PP_DOC
341
350#define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
351
390#define SDL_INIT_INTERFACE(iface) \
391 do { \
392 SDL_zerop(iface); \
393 (iface)->version = sizeof(*(iface)); \
394 } while (0)
395
396#endif // SDL3PP_DOC
397
424inline void* malloc(size_t size) { return SDL_malloc(size); }
425
449inline void* calloc(size_t nmemb, size_t size)
450{
451 return SDL_calloc(nmemb, size);
452}
453
492inline void* realloc(void* mem, size_t size) { return SDL_realloc(mem, size); }
493
512inline void free(void* mem) { SDL_free(mem); }
513
531using malloc_func = SDL_malloc_func;
532
552using calloc_func = SDL_calloc_func;
553
573using realloc_func = SDL_realloc_func;
574
591using free_func = SDL_free_func;
592
618
643
677
700inline void* aligned_alloc(size_t alignment, size_t size)
701{
702 return SDL_aligned_alloc(alignment, size);
703}
704
721inline void aligned_free(void* mem) { SDL_aligned_free(mem); }
722
733inline int GetNumAllocations() { return SDL_GetNumAllocations(); }
734
751struct EnvironmentBase : Resource<SDL_Environment*>
752{
753 using Resource::Resource;
754
774 EnvironmentBase(bool populated)
775 : Resource(CheckError(SDL_CreateEnvironment(populated)))
776 {
777 }
778
796 const char* GetVariable(StringParam name)
797 {
798 return SDL_GetEnvironmentVariable(get(), name);
799 }
800
821 {
822 return OwnArray<char*>{CheckError(SDL_GetEnvironmentVariables(get()))};
823 }
824
832 inline Uint64 GetVariableCount()
833 {
834 Uint64 count = 0;
835 for (auto& var : GetVariables()) count += 1;
836 return count;
837 }
838
859 void SetVariable(StringParam name, StringParam value, bool overwrite)
860 {
861 CheckError(SDL_SetEnvironmentVariable(get(), name, value, overwrite));
862 }
863
882 {
883 CheckError(SDL_UnsetEnvironmentVariable(get(), name));
884 }
885};
886
896{
898
902 constexpr EnvironmentRef(const EnvironmentRef& other)
903 : EnvironmentBase(other.get())
904 {
905 }
906
911 : EnvironmentBase(other.release())
912 {
913 }
914
918 constexpr ~EnvironmentRef() = default;
919
924 {
925 release(other.release());
926 return *this;
927 }
928
941 void reset(SDL_Environment* newResource = {})
942 {
943 SDL_DestroyEnvironment(release(newResource));
944 }
945};
946
956{
958
962 constexpr explicit Environment(SDL_Environment* resource = {})
963 : EnvironmentRef(resource)
964 {
965 }
966
967 constexpr Environment(const Environment& other) = delete;
968
972 constexpr Environment(Environment&& other) = default;
973
978
983 {
984 reset(other.release());
985 return *this;
986 }
987};
988
1010inline EnvironmentRef GetEnvironment() { return SDL_GetEnvironment(); }
1011
1025inline const char* getenv(StringParam name) { return SDL_getenv(name); }
1026
1044inline const char* getenv_unsafe(StringParam name)
1045{
1046 return SDL_getenv_unsafe(name);
1047}
1048
1065inline int setenv_unsafe(StringParam name, StringParam value, int overwrite)
1066{
1067 return SDL_setenv_unsafe(name, value, overwrite);
1068}
1069
1084{
1085 return SDL_unsetenv_unsafe(name);
1086}
1087
1102using CompareCallback = SDL_CompareCallback;
1103
1148inline void qsort(void* base,
1149 size_t nmemb,
1150 size_t size,
1151 CompareCallback compare)
1152{
1153 SDL_qsort(base, nmemb, size, compare);
1154}
1155
1205inline void* bsearch(const void* key,
1206 const void* base,
1207 size_t nmemb,
1208 size_t size,
1209 CompareCallback compare)
1210{
1211 return SDL_bsearch(key, base, nmemb, size, compare);
1212}
1213
1229using CompareCallback_r = SDL_CompareCallback_r;
1230
1246using CompareCB = std::function<int(const void*, const void*)>;
1247
1300inline void qsort_r(void* base,
1301 size_t nmemb,
1302 size_t size,
1303 CompareCallback_r compare,
1304 void* userdata)
1305{
1306 SDL_qsort_r(base, nmemb, size, compare, userdata);
1307}
1308
1360inline void qsort_r(void* base, size_t nmemb, size_t size, CompareCB compare)
1361{
1362 return qsort_r(
1363 base,
1364 nmemb,
1365 size,
1366 [](void* userdata, const void* a, const void* b) {
1367 auto& cb = *static_cast<CompareCB*>(userdata);
1368 return cb(a, b);
1369 },
1370 &compare);
1371}
1372
1430inline void* bsearch_r(const void* key,
1431 const void* base,
1432 size_t nmemb,
1433 size_t size,
1434 CompareCallback_r compare,
1435 void* userdata)
1436{
1437 return SDL_bsearch_r(key, base, nmemb, size, compare, userdata);
1438}
1439
1496inline void* bsearch_r(const void* key,
1497 const void* base,
1498 size_t nmemb,
1499 size_t size,
1500 CompareCB compare)
1501{
1502 return bsearch_r(
1503 key,
1504 base,
1505 nmemb,
1506 size,
1507 [](void* userdata, const void* a, const void* b) {
1508 auto& cb = *static_cast<CompareCB*>(userdata);
1509 return cb(a, b);
1510 },
1511 &compare);
1512}
1513
1524inline int abs(int x) { return SDL_abs(x); }
1525
1542inline double abs(double x) { return SDL_fabs(x); }
1543
1560inline float abs(float x) { return SDL_fabsf(x); }
1561
1578template<class T, class U>
1579constexpr T min(T x, U y)
1580{
1581 return SDL_min(x, y);
1582}
1583
1600template<class T, class U>
1601constexpr T max(T x, U y)
1602{
1603 return SDL_max(x, y);
1604}
1605
1628template<class T, class U, class V>
1629constexpr T clamp(T x, U a, V b)
1630{
1631 return SDL_clamp(x, a, b);
1632}
1633
1647inline int isalpha(int x) { return SDL_isalpha(x); }
1648
1662inline int isalnum(int x) { return SDL_isalnum(x); }
1663
1677inline int isblank(int x) { return SDL_isblank(x); }
1678
1692inline int iscntrl(int x) { return SDL_iscntrl(x); }
1693
1707inline int isdigit(int x) { return SDL_isdigit(x); }
1708
1722inline int isxdigit(int x) { return SDL_isxdigit(x); }
1723
1740inline int ispunct(int x) { return SDL_ispunct(x); }
1741
1762inline int isspace(int x) { return SDL_isspace(x); }
1763
1777inline int isupper(int x) { return SDL_isupper(x); }
1778
1792inline int islower(int x) { return SDL_islower(x); }
1793
1811inline int isprint(int x) { return SDL_isprint(x); }
1812
1832inline int isgraph(int x) { return SDL_isgraph(x); }
1833
1850inline int toupper(int x) { return SDL_toupper(x); }
1851
1868inline int tolower(int x) { return SDL_tolower(x); }
1869
1889inline Uint16 crc16(Uint16 crc, const void* data, size_t len)
1890{
1891 return SDL_crc16(crc, data, len);
1892}
1893
1913inline Uint32 crc32(Uint32 crc, const void* data, size_t len)
1914{
1915 return SDL_crc32(crc, data, len);
1916}
1917
1942inline Uint32 murmur3_32(const void* data, size_t len, Uint32 seed)
1943{
1944 return SDL_murmur3_32(data, len, seed);
1945}
1946
1965inline void* memcpy(void* dst, const void* src, size_t len)
1966{
1967#ifdef SDL_SLOW_MEMCPY
1968 return SDL_memcpy(dst, src, len);
1969#else
1970 return ::memcpy(dst, src, len);
1971#endif // SDL_SLOW_MEMCPY
1972}
1973
1974#ifdef SDL3PP_DOC
1975
2000#define SDL_copyp(dst, src) \
2001 { \
2002 SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof(*(dst)) == sizeof(*(src))); \
2003 } \
2004 SDL_memcpy((dst), (src), sizeof(*(src)))
2005
2006#endif // SDL3PP_DOC
2007
2025inline void* memmove(void* dst, const void* src, size_t len)
2026{
2027#ifdef SDL_SLOW_MEMMOVE
2028 return SDL_memmove(dst, src, len);
2029#else
2030 return ::memmove(dst, src, len);
2031#endif // SDL_SLOW_MEMMOVE
2032}
2033
2052inline void* memset(void* dst, int c, size_t len)
2053{
2054#ifdef SDL_SLOW_MEMSET
2055 return SDL_memset(dst, c, len);
2056#else
2057 return ::memset(dst, c, len);
2058#endif // SDL_SLOW_MEMSET
2059}
2060
2079inline void* memset4(void* dst, Uint32 val, size_t dwords)
2080{
2081 return SDL_memset4(dst, val, dwords);
2082}
2083
2101template<class T>
2102inline void zero(T& x)
2103{
2104 SDL_zero(x);
2105}
2106
2124template<class T>
2125inline void zerop(T* x)
2126{
2127 SDL_zerop(x);
2128}
2129
2147template<class T, std::size_t N>
2148inline void zeroa(T (&x)[N])
2149{
2150 SDL_zeroa(x);
2151}
2152
2167inline int memcmp(const void* s1, const void* s2, size_t len)
2168{
2169 return SDL_memcmp(s1, s2, len);
2170}
2171
2197inline size_t wcslen(const wchar_t* wstr) { return SDL_wcslen(wstr); }
2198
2228inline size_t wcsnlen(const wchar_t* wstr, size_t maxlen)
2229{
2230 return SDL_wcsnlen(wstr, maxlen);
2231}
2232
2258inline size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t maxlen)
2259{
2260 return SDL_wcslcpy(dst, src, maxlen);
2261}
2262
2290inline size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t maxlen)
2291{
2292 return SDL_wcslcat(dst, src, maxlen);
2293}
2294
2311inline wchar_t* wcsdup(const wchar_t* wstr) { return SDL_wcsdup(wstr); }
2312
2331inline wchar_t* wcsstr(const wchar_t* haystack, const wchar_t* needle)
2332{
2333 return SDL_wcsstr(haystack, needle);
2334}
2335
2359inline wchar_t* wcsnstr(const wchar_t* haystack,
2360 const wchar_t* needle,
2361 size_t maxlen)
2362{
2363 return SDL_wcsnstr(haystack, needle, maxlen);
2364}
2365
2383inline int wcscmp(const wchar_t* str1, const wchar_t* str2)
2384{
2385 return SDL_wcscmp(str1, str2);
2386}
2387
2417inline int wcsncmp(const wchar_t* str1, const wchar_t* str2, size_t maxlen)
2418{
2419 return SDL_wcsncmp(str1, str2, maxlen);
2420}
2421
2450inline int wcscasecmp(const wchar_t* str1, const wchar_t* str2)
2451{
2452 return SDL_wcscasecmp(str1, str2);
2453}
2454
2495inline int wcsncasecmp(const wchar_t* str1, const wchar_t* str2, size_t maxlen)
2496{
2497 return SDL_wcsncasecmp(str1, str2, maxlen);
2498}
2499
2525inline long wcstol(const wchar_t* str, wchar_t** endp, int base)
2526{
2527 return SDL_wcstol(str, endp, base);
2528}
2529
2548inline size_t strlen(StringParam str) { return SDL_strlen(str); }
2549
2572inline size_t strnlen(StringParam str, size_t maxlen)
2573{
2574 return SDL_strnlen(str, maxlen);
2575}
2576
2604inline size_t strlcpy(char* dst, StringParam src, size_t maxlen)
2605{
2606 return SDL_strlcpy(dst, src, maxlen);
2607}
2608
2635inline size_t utf8strlcpy(char* dst, StringParam src, size_t dst_bytes)
2636{
2637 return SDL_utf8strlcpy(dst, src, dst_bytes);
2638}
2639
2666inline size_t strlcat(char* dst, StringParam src, size_t maxlen)
2667{
2668 return SDL_strlcat(dst, src, maxlen);
2669}
2670
2687inline char* strdup(StringParam str) { return SDL_strdup(str); }
2688
2712inline char* strndup(StringParam str, size_t maxlen)
2713{
2714 return SDL_strndup(str, maxlen);
2715}
2716
2736inline char* strrev(char* str) { return SDL_strrev(str); }
2737
2757inline char* strupr(char* str) { return SDL_strupr(str); }
2758
2778inline char* strlwr(char* str) { return SDL_strlwr(str); }
2779
2798inline char* strchr(StringParam str, int c) { return SDL_strchr(str, c); }
2799
2817inline char* strrchr(StringParam str, int c) { return SDL_strrchr(str, c); }
2818
2837inline char* strstr(StringParam haystack, StringParam needle)
2838{
2839 return SDL_strstr(haystack, needle);
2840}
2841
2863inline char* strnstr(StringParam haystack, StringParam needle, size_t maxlen)
2864{
2865 return SDL_strnstr(haystack, needle, maxlen);
2866}
2867
2894inline char* strcasestr(StringParam haystack, StringParam needle)
2895{
2896 return SDL_strcasestr(haystack, needle);
2897}
2898
2926inline char* strtok_r(char* str, StringParam delim, char** saveptr)
2927{
2928 return SDL_strtok_r(str, delim, saveptr);
2929}
2930
2957inline size_t utf8strlen(StringParam str) { return SDL_utf8strlen(str); }
2958
2990inline size_t utf8strnlen(StringParam str, size_t bytes)
2991{
2992 return SDL_utf8strnlen(str, bytes);
2993}
2994
3021inline char* itoa(int value, char* str, int radix)
3022{
3023 return SDL_itoa(value, str, radix);
3024}
3025
3052inline char* uitoa(unsigned int value, char* str, int radix)
3053{
3054 return SDL_uitoa(value, str, radix);
3055}
3056
3083inline char* ltoa(long value, char* str, int radix)
3084{
3085 return SDL_ltoa(value, str, radix);
3086}
3087
3114inline char* ultoa(unsigned long value, char* str, int radix)
3115{
3116 return SDL_ultoa(value, str, radix);
3117}
3118
3140inline int atoi(StringParam str) { return SDL_atoi(str); }
3141
3162inline double atof(StringParam str) { return SDL_atof(str); }
3163
3196inline long strtol(StringParam str, char** endp, int base)
3197{
3198 return SDL_strtol(str, endp, base);
3199}
3200
3232inline unsigned long strtoul(StringParam str, char** endp, int base)
3233{
3234 return SDL_strtoul(str, endp, base);
3235}
3236
3264inline double strtod(StringParam str, char** endp)
3265{
3266 return SDL_strtod(str, endp);
3267}
3268
3287inline int strcmp(StringParam str1, StringParam str2)
3288{
3289 return SDL_strcmp(str1, str2);
3290}
3291
3320inline int strncmp(StringParam str1, StringParam str2, size_t maxlen)
3321{
3322 return SDL_strncmp(str1, str2, maxlen);
3323}
3324
3351inline int strcasecmp(StringParam str1, StringParam str2)
3352{
3353 return SDL_strcasecmp(str1, str2);
3354}
3355
3393inline int strncasecmp(StringParam str1, StringParam str2, size_t maxlen)
3394{
3395 return SDL_strncasecmp(str1, str2, maxlen);
3396}
3397
3414inline char* strpbrk(StringParam str, StringParam breakset)
3415{
3416 return SDL_strpbrk(str, breakset);
3417}
3418
3432constexpr Uint32 INVALID_UNICODE_CODEPOINT = SDL_INVALID_UNICODE_CODEPOINT;
3433
3477inline Uint32 StepUTF8(const char** pstr, size_t* pslen)
3478{
3479 return SDL_StepUTF8(pstr, pslen);
3480}
3481
3511inline Uint32 StepBackUTF8(StringParam start, const char** pstr)
3512{
3513 return SDL_StepBackUTF8(start, pstr);
3514}
3515
3543inline char* UCS4ToUTF8(Uint32 codepoint, char* dst)
3544{
3545 return SDL_UCS4ToUTF8(codepoint, dst);
3546}
3547
3563inline int sscanf(StringParam text,
3564 SDL_SCANF_FORMAT_STRING const char* fmt,
3565 ...)
3566{
3567 int rc;
3568 va_list ap;
3569 va_start(ap, fmt);
3570 rc = SDL_vsscanf(text, fmt, ap);
3571 va_end(ap);
3572 return rc;
3573}
3574
3592inline int vsscanf(StringParam text,
3593 SDL_SCANF_FORMAT_STRING const char* fmt,
3594 va_list ap)
3595{
3596 return SDL_vsscanf(text, fmt, ap);
3597}
3598
3630inline int snprintf(char* text,
3631 size_t maxlen,
3632 SDL_PRINTF_FORMAT_STRING const char* fmt,
3633 ...)
3634{
3635 va_list ap;
3636 int result;
3637
3638 va_start(ap, fmt);
3639 result = SDL_vsnprintf(text, maxlen, fmt, ap);
3640 va_end(ap);
3641
3642 return result;
3643}
3644
3677inline int swprintf(wchar_t* text,
3678 size_t maxlen,
3679 SDL_PRINTF_FORMAT_STRING const wchar_t* fmt,
3680 ...)
3681{
3682 va_list ap;
3683 int result;
3684
3685 va_start(ap, fmt);
3686 result = SDL_vswprintf(text, maxlen, fmt, ap);
3687 va_end(ap);
3688
3689 return result;
3690}
3691
3710inline int vsnprintf(char* text,
3711 size_t maxlen,
3712 SDL_PRINTF_FORMAT_STRING const char* fmt,
3713 va_list ap)
3714{
3715 return SDL_vsnprintf(text, maxlen, fmt, ap);
3716}
3717
3737inline int vswprintf(wchar_t* text,
3738 size_t maxlen,
3739 SDL_PRINTF_FORMAT_STRING const wchar_t* fmt,
3740 va_list ap)
3741{
3742 return SDL_vswprintf(text, maxlen, fmt, ap);
3743}
3744
3772inline int asprintf(char** strp, SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
3773{
3774 va_list ap;
3775 int result;
3776
3777 va_start(ap, fmt);
3778 result = SDL_vasprintf(strp, fmt, ap);
3779 va_end(ap);
3780
3781 return result;
3782}
3783
3801inline int vasprintf(char** strp,
3802 SDL_PRINTF_FORMAT_STRING const char* fmt,
3803 va_list ap)
3804{
3805 return SDL_vasprintf(strp, fmt, ap);
3806}
3807
3826inline void srand(Uint64 seed) { SDL_srand(seed); }
3827
3860inline Sint32 rand(Sint32 n) { return SDL_rand(n); }
3861
3882inline float randf() { return SDL_randf(); }
3883
3905inline Uint32 rand_bits() { return SDL_rand_bits(); }
3906
3918{
3919 Uint64 m_state;
3920
3921public:
3925 constexpr Random(Uint64 state)
3926 : m_state(state)
3927 {
3928 }
3929
3931 constexpr operator Uint64() { return m_state; }
3932
3964 Sint32 rand(Sint32 n) { return SDL_rand_r(&m_state, n); }
3965
3989 float randf() { return SDL_randf_r(&m_state); }
3990
4012 Uint32 rand_bits() { return SDL_rand_bits_r(&m_state); }
4013};
4014
4022constexpr double PI_D = SDL_PI_D;
4023
4031constexpr float PI_F = SDL_PI_F;
4032
4057inline double acos(double x) { return SDL_acos(x); }
4058
4083inline float acos(float x) { return SDL_acosf(x); }
4084
4109inline double asin(double x) { return SDL_asin(x); }
4110
4138inline float asin(float x) { return SDL_asinf(x); }
4139
4166inline double atan(double x) { return SDL_atan(x); }
4167
4193inline float atan(float x) { return SDL_atanf(x); }
4194
4226inline double atan2(double y, double x) { return SDL_atan2(y, x); }
4227
4259inline float atan2(float y, float x) { return SDL_atan2f(y, x); }
4260
4283inline double ceil(double x) { return SDL_ceil(x); }
4284
4307inline float ceil(float x) { return SDL_ceilf(x); }
4308
4329inline double copysign(double x, double y) { return SDL_copysign(x, y); }
4330
4351inline float copysign(float x, float y) { return SDL_copysignf(x, y); }
4352
4375inline double cos(double x) { return SDL_cos(x); }
4376
4399inline float cos(float x) { return SDL_cosf(x); }
4400
4427inline double exp(double x) { return SDL_exp(x); }
4428
4455inline float exp(float x) { return SDL_expf(x); }
4456
4479inline double floor(double x) { return SDL_floor(x); }
4480
4503inline float floor(float x) { return SDL_floorf(x); }
4504
4528inline double trunc(double x) { return SDL_trunc(x); }
4529
4553inline float trunc(float x) { return SDL_truncf(x); }
4554
4579inline double fmod(double x, double y) { return SDL_fmod(x, y); }
4580
4605inline float fmod(float x, float y) { return SDL_fmodf(x, y); }
4606
4617inline int isinf(double x) { return SDL_isinf(x); }
4618
4629inline int isinf(float x) { return SDL_isinff(x); }
4630
4641inline int isnan(double x) { return SDL_isnan(x); }
4642
4653inline int isnan(float x) { return SDL_isnanf(x); }
4654
4679inline double log(double x) { return SDL_log(x); }
4680
4705inline float log(float x) { return SDL_logf(x); }
4706
4731inline double log10(double x) { return SDL_log10(x); }
4732
4757inline float log10(float x) { return SDL_log10f(x); }
4758
4773inline double modf(double x, double* y) { return SDL_modf(x, y); }
4774
4789inline float modf(float x, float* y) { return SDL_modff(x, y); }
4790
4817inline double pow(double x, double y) { return SDL_pow(x, y); }
4818
4845inline float pow(float x, float y) { return SDL_powf(x, y); }
4846
4869inline double round(double x) { return SDL_round(x); }
4870
4893inline float round(float x) { return SDL_roundf(x); }
4894
4917inline long lround(double x) { return SDL_lround(x); }
4918
4941inline long lround(float x) { return SDL_lroundf(x); }
4942
4962inline double scalbn(double x, int n) { return SDL_scalbn(x, n); }
4963
4983inline float scalbn(float x, int n) { return SDL_scalbnf(x, n); }
4984
5007inline double sin(double x) { return SDL_sin(x); }
5008
5031inline float sin(float x) { return SDL_sinf(x); }
5032
5052inline double sqrt(double x) { return SDL_sqrt(x); }
5053
5073inline float sqrt(float x) { return SDL_sqrtf(x); }
5074
5099inline double tan(double x) { return SDL_tan(x); }
5100
5128inline float tan(float x) { return SDL_tanf(x); }
5129
5141struct IConvBase : Resource<SDL_iconv_data_t*>
5142{
5143 using Resource::Resource;
5144
5160 : Resource(SDL_iconv_open(tocode, fromcode))
5161 {
5162 }
5163
5197 size_t iconv(const char** inbuf,
5198 size_t* inbytesleft,
5199 char** outbuf,
5200 size_t* outbytesleft)
5201 {
5202 return SDL_iconv(get(), inbuf, inbytesleft, outbuf, outbytesleft);
5203 }
5204};
5205
5215{
5217
5221 constexpr IConvRef(const IConvRef& other)
5222 : IConvBase(other.get())
5223 {
5224 }
5225
5229 constexpr IConvRef(IConvRef&& other)
5230 : IConvBase(other.release())
5231 {
5232 }
5233
5237 constexpr ~IConvRef() = default;
5238
5243 {
5244 release(other.release());
5245 return *this;
5246 }
5247
5259 int reset(SDL_iconv_data_t* newResource = {})
5260 {
5261 return SDL_iconv_close(release(newResource));
5262 }
5263};
5264
5274{
5275 using IConvRef::IConvRef;
5276
5280 constexpr explicit IConv(SDL_iconv_data_t* resource = {})
5281 : IConvRef(resource)
5282 {
5283 }
5284
5285 constexpr IConv(const IConv& other) = delete;
5286
5290 constexpr IConv(IConv&& other) = default;
5291
5295 ~IConv() { reset(); }
5296
5301 {
5302 reset(other.release());
5303 return *this;
5304 }
5305};
5306
5307#ifdef SDL3PP_DOC
5308
5312#define SDL_ICONV_ERROR (size_t)-1
5313
5317#define SDL_ICONV_E2BIG (size_t)-2
5318
5322#define SDL_ICONV_EILSEQ (size_t)-3
5323
5327#define SDL_ICONV_EINVAL (size_t)-4
5328
5329#endif // SDL3PP_DOC
5330
5353 StringParam fromcode,
5354 StringParam inbuf,
5355 size_t inbytesleft)
5356{
5357 return OwnPtr<char>{SDL_iconv_string(tocode, fromcode, inbuf, inbytesleft)};
5358}
5359
5360#ifdef SDL3PP_DOC
5361
5374#define SDL_iconv_utf8_locale(S) \
5375 SDL_iconv_string("", "UTF-8", S, SDL_strlen(S) + 1)
5376
5389#define SDL_iconv_utf8_ucs2(S) \
5390 (Uint16*)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S) + 1)
5391
5404#define SDL_iconv_utf8_ucs4(S) \
5405 (Uint32*)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S) + 1)
5406
5419#define SDL_iconv_wchar_utf8(S) \
5420 SDL_iconv_string( \
5421 "UTF-8", "WCHAR_T", (char*)S, (SDL_wcslen(S) + 1) * sizeof(wchar_t))
5422
5423#endif // SDL3PP_DOC
5424
5442inline bool size_mul_check_overflow(size_t a, size_t b, size_t* ret)
5443{
5444 return SDL_size_mul_check_overflow(a, b, ret);
5445}
5446
5464inline bool size_add_check_overflow(size_t a, size_t b, size_t* ret)
5465{
5466 return SDL_size_add_check_overflow(a, b, ret);
5467}
5468
5484using FunctionPointer = SDL_FunctionPointer;
5485
5486#pragma region impl
5488
5489inline void PtrDeleter::operator()(void* ptr) const { SDL_free(ptr); }
5490
5491#pragma endregion impl
5492
5493} // namespace SDL
5494
5495#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:3918
constexpr Random(Uint64 state)
Init state with the given value.
Definition SDL3pp_stdinc.h:3925
float randf()
Generate a uniform pseudo-random floating point number less than 1.0.
Definition SDL3pp_stdinc.h:3989
Uint32 rand_bits()
Generate 32 pseudo-random bits.
Definition SDL3pp_stdinc.h:4012
Sint32 rand(Sint32 n)
Generate a pseudo-random number less than n for positive n.
Definition SDL3pp_stdinc.h:3964
A SDL managed resource.
Definition SDL3pp_resource.h:17
constexpr SDL_Environment * release(SDL_Environment * newResource={})
Return contained resource and empties or replace value.
Definition SDL3pp_resource.h:60
constexpr Resource(T resource={})
Constructs the underlying resource.
Definition SDL3pp_resource.h:22
constexpr SDL_Environment * get() const
Return contained resource;.
Definition SDL3pp_resource.h:57
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:261
constexpr Sint64 ToNS() const
Converts to nanoseconds Sint64.
Definition SDL3pp_stdinc.h:297
constexpr Time & operator+=(std::chrono::nanoseconds interval)
Increment time.
Definition SDL3pp_stdinc.h:322
constexpr float ToSeconds() const
Converts a time to seconds (float) since epoch.
Definition SDL3pp_stdinc.h:310
constexpr Time & operator-=(std::chrono::nanoseconds interval)
Decrement.
Definition SDL3pp_stdinc.h:329
constexpr Time(SDL_Time time)
Constructs from SDL_Time.
Definition SDL3pp_stdinc.h:274
constexpr Time(std::chrono::nanoseconds time)
Constructs from a nanoseconds period.
Definition SDL3pp_stdinc.h:268
static constexpr Time FromNS(Sint64 time)
Create from a nanoseconds Sint64.
Definition SDL3pp_stdinc.h:291
static constexpr Time FromSeconds(float interval)
Converts a time to seconds (float) since epoch.
Definition SDL3pp_stdinc.h:315
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:2417
double log(double x)
Compute the natural logarithm of x.
Definition SDL3pp_stdinc.h:4679
char * UCS4ToUTF8(Uint32 codepoint, char *dst)
Convert a single Unicode codepoint to UTF-8.
Definition SDL3pp_stdinc.h:3543
long wcstol(const wchar_t *str, wchar_t **endp, int base)
Parse a long from a wide string.
Definition SDL3pp_stdinc.h:2525
char * strdup(StringParam str)
Allocate a copy of a string.
Definition SDL3pp_stdinc.h:2687
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:669
double strtod(StringParam str, char **endp)
Parse a double from a string.
Definition SDL3pp_stdinc.h:3264
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:2894
double atan(double x)
Compute the arc tangent of x.
Definition SDL3pp_stdinc.h:4166
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:3772
double ceil(double x)
Compute the ceiling of x.
Definition SDL3pp_stdinc.h:4283
char * strlwr(char *str)
Convert a string to lowercase.
Definition SDL3pp_stdinc.h:2778
void * memmove(void *dst, const void *src, size_t len)
Copy memory ranges that might overlap.
Definition SDL3pp_stdinc.h:2025
int memcmp(const void *s1, const void *s2, size_t len)
Compare two buffers of memory.
Definition SDL3pp_stdinc.h:2167
constexpr std::size_t arraysize(const T(&array)[N])
The number of elements in a static array.
Definition SDL3pp_stdinc.h:108
SDL_malloc_func malloc_func
A callback used to implement malloc().
Definition SDL3pp_stdinc.h:531
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:2863
int isnan(double x)
Return whether the value is NaN.
Definition SDL3pp_stdinc.h:4641
constexpr Uint32 INVALID_UNICODE_CODEPOINT
The Unicode REPLACEMENT CHARACTER codepoint.
Definition SDL3pp_stdinc.h:3432
double scalbn(double x, int n)
Scale x by an integer power of two.
Definition SDL3pp_stdinc.h:4962
char * ultoa(unsigned long value, char *str, int radix)
Convert an unsigned long integer into a string.
Definition SDL3pp_stdinc.h:3114
wchar_t * wcsdup(const wchar_t *wstr)
Allocate a copy of a wide string.
Definition SDL3pp_stdinc.h:2311
int isgraph(int x)
Report if a character is any "printable" except space.
Definition SDL3pp_stdinc.h:1832
int strncmp(StringParam str1, StringParam str2, size_t maxlen)
Compare two UTF-8 strings up to a number of bytes.
Definition SDL3pp_stdinc.h:3320
double asin(double x)
Compute the arc sine of x.
Definition SDL3pp_stdinc.h:4109
Uint16 crc16(Uint16 crc, const void *data, size_t len)
Calculate a CRC-16 value.
Definition SDL3pp_stdinc.h:1889
char * strrev(char *str)
Reverse a string's contents.
Definition SDL3pp_stdinc.h:2736
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:3393
constexpr T min(T x, U y)
Return the lesser of two values.
Definition SDL3pp_stdinc.h:1579
SDL_FunctionPointer FunctionPointer
A generic function pointer.
Definition SDL3pp_stdinc.h:5484
unsigned long strtoul(StringParam str, char **endp, int base)
Parse an unsigned long from a string.
Definition SDL3pp_stdinc.h:3232
int isdigit(int x)
Report if a character is a numeric digit.
Definition SDL3pp_stdinc.h:1707
std::chrono::duration< float > Seconds
Duration in seconds (float).
Definition SDL3pp_stdinc.h:217
double exp(double x)
Compute the exponential of x.
Definition SDL3pp_stdinc.h:4427
char * strstr(StringParam haystack, StringParam needle)
Search a string for the first instance of a specific substring.
Definition SDL3pp_stdinc.h:2837
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:3710
char * strchr(StringParam str, int c)
Search a string for the first instance of a specific byte.
Definition SDL3pp_stdinc.h:2798
double copysign(double x, double y)
Copy the sign of one floating-point value to another.
Definition SDL3pp_stdinc.h:4329
void * malloc(size_t size)
Allocate uninitialized memory.
Definition SDL3pp_stdinc.h:424
double modf(double x, double *y)
Split x into integer and fractional parts.
Definition SDL3pp_stdinc.h:4773
void zero(T &x)
Clear an object's memory to zero.
Definition SDL3pp_stdinc.h:2102
SDL_calloc_func calloc_func
A callback used to implement calloc().
Definition SDL3pp_stdinc.h:552
size_t strlcat(char *dst, StringParam src, size_t maxlen)
Concatenate strings.
Definition SDL3pp_stdinc.h:2666
void zeroa(T(&x)[N])
Clear an array's memory to zero.
Definition SDL3pp_stdinc.h:2148
char * strndup(StringParam str, size_t maxlen)
Allocate a copy of a string, up to n characters.
Definition SDL3pp_stdinc.h:2712
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:3630
double round(double x)
Round x to the nearest integer.
Definition SDL3pp_stdinc.h:4869
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:3563
size_t strlcpy(char *dst, StringParam src, size_t maxlen)
Copy a string.
Definition SDL3pp_stdinc.h:2604
void * memset(void *dst, int c, size_t len)
Initialize all bytes of buffer of memory to a specific value.
Definition SDL3pp_stdinc.h:2052
bool size_mul_check_overflow(size_t a, size_t b, size_t *ret)
Multiply two integers, checking for overflow.
Definition SDL3pp_stdinc.h:5442
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:610
int strcmp(StringParam str1, StringParam str2)
Compare two null-terminated UTF-8 strings.
Definition SDL3pp_stdinc.h:3287
bool size_add_check_overflow(size_t a, size_t b, size_t *ret)
Add two integers, checking for overflow.
Definition SDL3pp_stdinc.h:5464
char * uitoa(unsigned int value, char *str, int radix)
Convert an unsigned integer into a string.
Definition SDL3pp_stdinc.h:3052
double pow(double x, double y)
Raise x to the power y
Definition SDL3pp_stdinc.h:4817
int isprint(int x)
Report if a character is "printable".
Definition SDL3pp_stdinc.h:1811
long lround(double x)
Round x to the nearest integer representable as a long.
Definition SDL3pp_stdinc.h:4917
std::chrono::nanoseconds Nanoseconds
Duration in Nanoseconds (Sint64).
Definition SDL3pp_stdinc.h:222
int isxdigit(int x)
Report if a character is a hexadecimal digit.
Definition SDL3pp_stdinc.h:1722
constexpr T max(T x, U y)
Return the greater of two values.
Definition SDL3pp_stdinc.h:1601
int atoi(StringParam str)
Parse an int from a string.
Definition SDL3pp_stdinc.h:3140
int tolower(int x)
Convert low-ASCII English letters to lowercase.
Definition SDL3pp_stdinc.h:1868
int isalpha(int x)
Query if a character is alphabetic (a letter).
Definition SDL3pp_stdinc.h:1647
std::function< int(const void *, const void *)> CompareCB
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1246
int unsetenv_unsafe(StringParam name)
Clear a variable from the environment.
Definition SDL3pp_stdinc.h:1083
constexpr float ToSeconds(Seconds duration)
Converts a time duration to seconds (float).
Definition SDL3pp_stdinc.h:227
char * strupr(char *str)
Convert a string to uppercase.
Definition SDL3pp_stdinc.h:2757
SDL_free_func free_func
A callback used to implement free().
Definition SDL3pp_stdinc.h:591
size_t utf8strlen(StringParam str)
Count the number of codepoints in a UTF-8 string.
Definition SDL3pp_stdinc.h:2957
constexpr Seconds FromSeconds(float duration)
Converts a float to seconds representation.
Definition SDL3pp_stdinc.h:232
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:2990
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:3737
int isupper(int x)
Report if a character is upper case.
Definition SDL3pp_stdinc.h:1777
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:2228
double sqrt(double x)
Compute the square root of x.
Definition SDL3pp_stdinc.h:5052
void srand(Uint64 seed)
Seeds the pseudo-random number generator.
Definition SDL3pp_stdinc.h:3826
double tan(double x)
Compute the tangent of x.
Definition SDL3pp_stdinc.h:5099
double sin(double x)
Compute the sine of x.
Definition SDL3pp_stdinc.h:5007
const char * getenv_unsafe(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1044
size_t utf8strlcpy(char *dst, StringParam src, size_t dst_bytes)
Copy an UTF-8 string.
Definition SDL3pp_stdinc.h:2635
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:2926
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:2079
int iscntrl(int x)
Report if a character is a control character.
Definition SDL3pp_stdinc.h:1692
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:3677
constexpr double PI_D
The value of Pi, as a double-precision floating point literal.
Definition SDL3pp_stdinc.h:4022
int islower(int x)
Report if a character is lower case.
Definition SDL3pp_stdinc.h:1792
int isinf(double x)
Return whether the value is infinity.
Definition SDL3pp_stdinc.h:4617
int isspace(int x)
Report if a character is whitespace.
Definition SDL3pp_stdinc.h:1762
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:2572
int strcasecmp(StringParam str1, StringParam str2)
Compare two null-terminated UTF-8 strings, case-insensitively.
Definition SDL3pp_stdinc.h:3351
size_t strlen(StringParam str)
This works exactly like strlen() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:2548
const char * getenv(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1025
int setenv_unsafe(StringParam name, StringParam value, int overwrite)
Set the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1065
int wcscmp(const wchar_t *str1, const wchar_t *str2)
Compare two null-terminated wide strings.
Definition SDL3pp_stdinc.h:2383
double acos(double x)
Compute the arc cosine of x.
Definition SDL3pp_stdinc.h:4057
Sint32 rand(Sint32 n)
Generate a pseudo-random number less than n for positive n.
Definition SDL3pp_stdinc.h:3860
SDL_realloc_func realloc_func
A callback used to implement realloc().
Definition SDL3pp_stdinc.h:573
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:1300
double floor(double x)
Compute the floor of x.
Definition SDL3pp_stdinc.h:4479
Uint32 StepUTF8(const char **pstr, size_t *pslen)
Decode a UTF-8 string, one Unicode codepoint at a time.
Definition SDL3pp_stdinc.h:3477
int toupper(int x)
Convert low-ASCII English letters to uppercase.
Definition SDL3pp_stdinc.h:1850
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:1942
constexpr Uint32 FourCC(Uint8 a, Uint8 b, Uint8 c, Uint8 d)
Define a four character code as a Uint32.
Definition SDL3pp_stdinc.h:147
Uint32 StepBackUTF8(StringParam start, const char **pstr)
Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
Definition SDL3pp_stdinc.h:3511
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
Copy a wide string.
Definition SDL3pp_stdinc.h:2258
float randf()
Generate a uniform pseudo-random floating point number less than 1.0.
Definition SDL3pp_stdinc.h:3882
constexpr T clamp(T x, U a, V b)
Return a value clamped to a range.
Definition SDL3pp_stdinc.h:1629
constexpr Nanoseconds FromNS(Sint64 duration)
Converts a Sint64 to nanoseconds representation.
Definition SDL3pp_stdinc.h:245
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:2495
void aligned_free(void *mem)
Free memory allocated by aligned_alloc().
Definition SDL3pp_stdinc.h:721
void zerop(T *x)
Clear an object's memory to zero, using a pointer.
Definition SDL3pp_stdinc.h:2125
int abs(int x)
Compute the absolute value of x.
Definition SDL3pp_stdinc.h:1524
void * calloc(size_t nmemb, size_t size)
Allocate a zero-initialized array.
Definition SDL3pp_stdinc.h:449
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:636
void qsort(void *base, size_t nmemb, size_t size, CompareCallback compare)
Sort an array.
Definition SDL3pp_stdinc.h:1148
SDL_CompareCallback_r CompareCallback_r
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1229
int isblank(int x)
Report if a character is blank (a space or tab).
Definition SDL3pp_stdinc.h:1677
void * realloc(void *mem, size_t size)
Change the size of allocated memory.
Definition SDL3pp_stdinc.h:492
SDL_CompareCallback CompareCallback
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1102
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:3801
char * itoa(int value, char *str, int radix)
Convert an integer into a string.
Definition SDL3pp_stdinc.h:3021
int ispunct(int x)
Report if a character is a punctuation mark.
Definition SDL3pp_stdinc.h:1740
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:3592
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:2359
Uint32 crc32(Uint32 crc, const void *data, size_t len)
Calculate a CRC-32 value.
Definition SDL3pp_stdinc.h:1913
double log10(double x)
Compute the base-10 logarithm of x.
Definition SDL3pp_stdinc.h:4731
constexpr float PI_F
The value of Pi, as a single-precision floating point literal.
Definition SDL3pp_stdinc.h:4031
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:2331
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:1205
double cos(double x)
Compute the cosine of x.
Definition SDL3pp_stdinc.h:4375
void free(void *mem)
Free allocated memory.
Definition SDL3pp_stdinc.h:512
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:4226
int wcscasecmp(const wchar_t *str1, const wchar_t *str2)
Compare two null-terminated wide strings, case-insensitively.
Definition SDL3pp_stdinc.h:2450
char * strpbrk(StringParam str, StringParam breakset)
Searches a string for the first occurence of any character contained in a breakset,...
Definition SDL3pp_stdinc.h:3414
void * aligned_alloc(size_t alignment, size_t size)
Allocate memory aligned to a specific alignment.
Definition SDL3pp_stdinc.h:700
int GetNumAllocations()
Get the number of outstanding (unfreed) allocations.
Definition SDL3pp_stdinc.h:733
Uint32 rand_bits()
Generate 32 pseudo-random bits.
Definition SDL3pp_stdinc.h:3905
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:5352
double trunc(double x)
Truncate x to an integer.
Definition SDL3pp_stdinc.h:4528
char * ltoa(long value, char *str, int radix)
Convert a long integer into a string.
Definition SDL3pp_stdinc.h:3083
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
Concatenate wide strings.
Definition SDL3pp_stdinc.h:2290
double atof(StringParam str)
Parse a double from a string.
Definition SDL3pp_stdinc.h:3162
constexpr Sint64 ToNS(std::chrono::nanoseconds duration)
Converts a time duration to nanoseconds (Sint64);.
Definition SDL3pp_stdinc.h:237
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:1430
long strtol(StringParam str, char **endp, int base)
Parse a long from a string.
Definition SDL3pp_stdinc.h:3196
char * strrchr(StringParam str, int c)
Search a string for the last instance of a specific byte.
Definition SDL3pp_stdinc.h:2817
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:2197
int isalnum(int x)
Query if a character is alphabetic (a letter) or a number.
Definition SDL3pp_stdinc.h:1662
EnvironmentRef GetEnvironment()
Get the process environment.
Definition SDL3pp_stdinc.h:1010
double fmod(double x, double y)
Return the floating-point remainder of x / y
Definition SDL3pp_stdinc.h:4579
void * memcpy(void *dst, const void *src, size_t len)
Copy non-overlapping memory.
Definition SDL3pp_stdinc.h:1965
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:393
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:375
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:355
constexpr Sint64 ToPosix() const
Convert nanoseconds to seconds.
Definition SDL3pp_timer.h:59
static constexpr Time FromPosix(Sint64 time)
Convert seconds to nanoseconds.
Definition SDL3pp_timer.h:43
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:752
void UnsetVariable(StringParam name)
Clear a variable from the environment.
Definition SDL3pp_stdinc.h:881
const char * GetVariable(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:796
OwnArray< char * > GetVariables()
Get all variables in the environment.
Definition SDL3pp_stdinc.h:820
void SetVariable(StringParam name, StringParam value, bool overwrite)
Set the value of a variable in the environment.
Definition SDL3pp_stdinc.h:859
Uint64 GetVariableCount()
Get the Variables count.
Definition SDL3pp_stdinc.h:832
EnvironmentBase(bool populated)
Create a set of environment variables.
Definition SDL3pp_stdinc.h:774
Handle to a non owned environment.
Definition SDL3pp_stdinc.h:896
constexpr EnvironmentRef(EnvironmentRef &&other)
Move constructor.
Definition SDL3pp_stdinc.h:910
EnvironmentRef & operator=(EnvironmentRef other)
Assignment operator.
Definition SDL3pp_stdinc.h:923
constexpr ~EnvironmentRef()=default
Default constructor.
void reset(SDL_Environment *newResource={})
Destroy a set of environment variables.
Definition SDL3pp_stdinc.h:941
constexpr EnvironmentRef(const EnvironmentRef &other)
Copy constructor.
Definition SDL3pp_stdinc.h:902
Handle to an owned environment.
Definition SDL3pp_stdinc.h:956
constexpr Environment(Environment &&other)=default
Move constructor.
Environment & operator=(Environment other)
Assignment operator.
Definition SDL3pp_stdinc.h:982
constexpr Environment(SDL_Environment *resource={})
Constructs from the underlying resource.
Definition SDL3pp_stdinc.h:962
~Environment()
Frees up resource when object goes out of scope.
Definition SDL3pp_stdinc.h:977
An opaque handle representing string encoding conversion state.
Definition SDL3pp_stdinc.h:5142
IConvBase(StringParam tocode, StringParam fromcode)
This function allocates a context for the specified character set conversion.
Definition SDL3pp_stdinc.h:5159
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:5197
Handle to a non owned iConv.
Definition SDL3pp_stdinc.h:5215
int reset(SDL_iconv_data_t *newResource={})
This function frees a context used for character set conversion.
Definition SDL3pp_stdinc.h:5259
constexpr IConvRef(IConvRef &&other)
Move constructor.
Definition SDL3pp_stdinc.h:5229
constexpr IConvRef(const IConvRef &other)
Copy constructor.
Definition SDL3pp_stdinc.h:5221
IConvRef & operator=(IConvRef other)
Assignment operator.
Definition SDL3pp_stdinc.h:5242
constexpr ~IConvRef()=default
Default constructor.
Handle to an owned iConv.
Definition SDL3pp_stdinc.h:5274
constexpr IConv(IConv &&other)=default
Move constructor.
~IConv()
Frees up resource when object goes out of scope.
Definition SDL3pp_stdinc.h:5295
constexpr IConv(SDL_iconv_data_t *resource={})
Constructs from the underlying resource.
Definition SDL3pp_stdinc.h:5280
IConv & operator=(IConv other)
Assignment operator.
Definition SDL3pp_stdinc.h:5300