SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_stdinc.h
1#ifndef SDL3PP_STDINC_H_
2#define SDL3PP_STDINC_H_
3
4#include <chrono>
5#include <span>
6#include <SDL3/SDL_stdinc.h>
7#include "SDL3pp_callbackWrapper.h"
8#include "SDL3pp_error.h"
9#include "SDL3pp_optionalRef.h"
10#include "SDL3pp_ownPtr.h"
11#include "SDL3pp_resource.h"
12#include "SDL3pp_spanRef.h"
13#include "SDL3pp_strings.h"
14
15namespace SDL {
16
41
43using TimeRaw = SDL_Time;
44
45// Forward decl
46struct Time;
47
48// Forward decl
49struct EnvironmentBase;
50
51// Forward decl
52struct Environment;
53
55using EnvironmentRaw = SDL_Environment*;
56
63
64// Forward decl
65struct IConvBase;
66
67// Forward decl
68struct IConv;
69
71using IConvRaw = SDL_iconv_t;
72
79
80#ifdef SDL3PP_DOC
81
98#define SDL_NOLONGLONG 1
99
114#define SDL_SIZE_MAX SIZE_MAX
115
147#define SDL_COMPILE_TIME_ASSERT(name, x) FailToCompileIf_x_IsFalse(x)
148
149#endif // SDL3PP_DOC
150
159template<class T, std::size_t N>
160constexpr std::size_t arraysize(const T (&array)[N])
161{
162 return std::size(array);
163}
164
165#ifdef SDL3PP_DOC
166
174#define SDL_STRINGIFY_ARG(arg) #arg
175
176#endif // SDL3PP_DOC
177
191constexpr Uint32 FourCC(Uint8 a, Uint8 b, Uint8 c, Uint8 d)
192{
193 return SDL_FOURCC(a, b, c, d);
194}
195
196#ifdef SDL3PP_DOC
197
209#define SDL_SINT64_C(c) c##LL /* or whatever the current compiler uses. */
210
222#define SDL_UINT64_C(c) c##ULL /* or whatever the current compiler uses. */
223
224#endif // SDL3PP_DOC
225
232
234constexpr Sint8 MAX_SINT8 = SDL_MAX_SINT8;
235
237constexpr Sint8 MIN_SINT8 = SDL_MIN_SINT8;
238
245
247constexpr Uint8 MAX_UINT8 = SDL_MAX_UINT8;
248
250constexpr Uint8 MIN_UINT8 = SDL_MIN_UINT8;
251
258
260constexpr Sint16 MAX_SINT16 = SDL_MAX_SINT16;
261
263constexpr Sint16 MIN_SINT16 = SDL_MIN_SINT16;
264
271
273constexpr Uint16 MAX_UINT16 = SDL_MAX_UINT16;
274
276constexpr Uint16 MIN_UINT16 = SDL_MIN_UINT16;
277
284
286constexpr Sint32 MAX_SINT32 = SDL_MAX_SINT32;
287
289constexpr Sint32 MIN_SINT32 = SDL_MIN_SINT32;
290
297
299constexpr Uint32 MAX_UINT32 = SDL_MAX_UINT32;
300
302constexpr Uint8 MIN_UINT32 = SDL_MIN_UINT32;
303
312
314constexpr Sint64 MAX_SINT64 = SDL_MAX_SINT64;
315
317constexpr Sint64 MIN_SINT64 = SDL_MIN_SINT64;
318
327
329constexpr Uint64 MAX_UINT64 = SDL_MAX_UINT64;
330
332constexpr Uint8 MIN_UINT64 = SDL_MIN_UINT64;
333
335using Seconds = std::chrono::duration<float>;
336
338using Nanoseconds = std::chrono::nanoseconds;
339
341using Milliseconds = std::chrono::milliseconds;
342
344constexpr float ToSeconds(Seconds duration) { return duration.count(); }
345
347constexpr Seconds FromSeconds(float duration) { return Seconds(duration); }
348
350constexpr Sint64 ToNS(Nanoseconds duration) { return duration.count(); }
351
353constexpr Nanoseconds FromNS(Sint64 duration) { return Nanoseconds{duration}; }
354
368class Time
369{
370 Nanoseconds m_time;
371
372public:
373 constexpr Time() = default;
374
380 constexpr explicit Time(TimeRaw time) noexcept
381 : m_time(time)
382 {
383 }
384
390 constexpr Time(std::chrono::nanoseconds time) noexcept
391 : m_time(time)
392 {
393 }
394
396 constexpr explicit operator bool() const
397 {
398 return m_time != std::chrono::nanoseconds{};
399 }
400
402 constexpr operator std::chrono::nanoseconds() const { return m_time; }
403
414 static Time Current();
415
417 static constexpr Time FromNS(Sint64 time)
418 {
419 return Time{std::chrono::nanoseconds{time}};
420 }
421
423 constexpr Sint64 ToNS() const { return m_time.count(); }
424
437 static constexpr Time FromPosix(Sint64 time);
438
450 constexpr Sint64 ToPosix() const;
451
467 static Time FromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime);
468
484 void ToWindows(Uint32* dwLowDateTime, Uint32* dwHighDateTime) const;
485
487 constexpr float ToSeconds() const { return Seconds(m_time).count(); }
488
490 static constexpr Time FromSeconds(float interval)
491 {
492 return std::chrono::duration_cast<std::chrono::nanoseconds>(
493 Seconds(interval));
494 }
495
497 constexpr Time& operator+=(std::chrono::nanoseconds interval)
498 {
499 m_time += interval;
500 return *this;
501 }
502
504 constexpr Time& operator-=(std::chrono::nanoseconds interval)
505 {
506 m_time -= interval;
507 return *this;
508 }
509};
510
512constexpr Time MAX_TIME = Time::FromNS(SDL_MAX_TIME);
513
515constexpr Time MIN_TIME = Time::FromNS(SDL_MIN_TIME);
516
517#ifndef FLT_EPSILON
518
527constexpr float FLT_EPSILON = 1.1920928955078125e-07F;
528
529#endif // FLT_EPSILON
530
536template<class I>
537concept Interface = requires(I* iface) { (iface)->version = sizeof(I); };
538
577template<Interface I>
578constexpr void InitInterface(I* iface)
579{
580 SDL_INIT_INTERFACE(iface);
581}
582
608inline void* malloc(size_t size) { return SDL_malloc(size); }
609
633inline void* calloc(size_t nmemb, size_t size)
634{
635 return SDL_calloc(nmemb, size);
636}
637
674inline void* realloc(void* mem, size_t size) { return SDL_realloc(mem, size); }
675
694inline void free(void* mem) { SDL_free(mem); }
695
713using malloc_func = void*(SDLCALL*)(size_t size);
714
734using calloc_func = void*(SDLCALL*)(size_t nmemb, size_t size);
735
755using realloc_func = void*(SDLCALL*)(void* mem, size_t size);
756
773using free_func = void(SDLCALL*)(void* mem);
774
800
825
859
882inline void* aligned_alloc(size_t alignment, size_t size)
883{
884 return SDL_aligned_alloc(alignment, size);
885}
886
903inline void aligned_free(void* mem) { SDL_aligned_free(mem); }
904
914inline int GetNumAllocations() { return SDL_GetNumAllocations(); }
915
921struct EnvironmentBase : ResourceBaseT<EnvironmentRaw>
922{
924
935 void Destroy();
936
954 const char* GetVariable(StringParam name);
955
976
984 Uint64 GetVariableCount() { return GetVariables().size(); }
985
1006 void SetVariable(StringParam name, StringParam value, bool overwrite);
1007
1025 void UnsetVariable(StringParam name);
1026};
1027
1044{
1045 using EnvironmentBase::EnvironmentBase;
1046
1054 constexpr explicit Environment(EnvironmentRaw resource) noexcept
1055 : EnvironmentBase(resource)
1056 {
1057 }
1058
1060 constexpr Environment(Environment&& other) noexcept
1061 : Environment(other.release())
1062 {
1063 }
1064
1085 Environment(bool populated);
1086
1088 ~Environment() { SDL_DestroyEnvironment(get()); }
1089
1091 constexpr Environment& operator=(Environment&& other) noexcept
1092 {
1093 swap(*this, other);
1094 return *this;
1095 }
1096};
1097
1119inline EnvironmentRaw GetEnvironment() { return SDL_GetEnvironment(); }
1120
1141inline Environment CreateEnvironment(bool populated)
1142{
1143 return Environment(populated);
1144}
1145
1146inline Environment::Environment(bool populated)
1147 : Environment(SDL_CreateEnvironment(populated))
1148{
1149}
1150
1170{
1171 return SDL_GetEnvironmentVariable(env, name);
1172}
1173
1175{
1176 return SDL::GetEnvironmentVariable(get(), std::move(name));
1177}
1178
1199{
1200 return OwnArray<char*>{CheckError(SDL_GetEnvironmentVariables(env))};
1201}
1202
1207
1229 StringParam name,
1230 StringParam value,
1231 bool overwrite)
1232{
1233 CheckError(SDL_SetEnvironmentVariable(env, name, value, overwrite));
1234}
1235
1237 StringParam value,
1238 bool overwrite)
1239{
1241 get(), std::move(name), std::move(value), overwrite);
1242}
1243
1263{
1264 CheckError(SDL_UnsetEnvironmentVariable(env, name));
1265}
1266
1268{
1269 SDL::UnsetEnvironmentVariable(get(), std::move(name));
1270}
1271
1285{
1286 SDL_DestroyEnvironment(env);
1287}
1288
1290
1306inline const char* getenv(StringParam name) { return SDL_getenv(name); }
1307
1329inline const char* getenv_unsafe(StringParam name)
1330{
1331 return SDL_getenv_unsafe(name);
1332}
1333
1350inline int setenv_unsafe(StringParam name, StringParam value, int overwrite)
1351{
1352 return SDL_setenv_unsafe(name, value, overwrite);
1353}
1354
1369{
1370 return SDL_unsetenv_unsafe(name);
1371}
1372
1387using CompareCallback = int(SDLCALL*)(const void* a, const void* b);
1388
1433inline void qsort(void* base,
1434 size_t nmemb,
1435 size_t size,
1436 CompareCallback compare)
1437{
1438 SDL_qsort(base, nmemb, size, compare);
1439}
1440
1490inline void* bsearch(const void* key,
1491 const void* base,
1492 size_t nmemb,
1493 size_t size,
1494 CompareCallback compare)
1495{
1496 return SDL_bsearch(key, base, nmemb, size, compare);
1497}
1498
1514using CompareCallback_r = int(SDLCALL*)(void* userdata,
1515 const void* a,
1516 const void* b);
1517
1533using CompareCB = std::function<int(const void* a, const void* b)>;
1534
1587inline void qsort_r(void* base,
1588 size_t nmemb,
1589 size_t size,
1590 CompareCallback_r compare,
1591 void* userdata)
1592{
1593 SDL_qsort_r(base, nmemb, size, compare, userdata);
1594}
1595
1647inline void qsort_r(void* base, size_t nmemb, size_t size, CompareCB compare)
1648{
1649 return qsort_r(
1650 base,
1651 nmemb,
1652 size,
1653 [](void* userdata, const void* a, const void* b) {
1654 auto& cb = *static_cast<const CompareCB*>(userdata);
1655 return cb(a, b);
1656 },
1657 &compare);
1658}
1659
1717inline void* bsearch_r(const void* key,
1718 const void* base,
1719 size_t nmemb,
1720 size_t size,
1721 CompareCallback_r compare,
1722 void* userdata)
1723{
1724 return SDL_bsearch_r(key, base, nmemb, size, compare, userdata);
1725}
1726
1783inline void* bsearch_r(const void* key,
1784 const void* base,
1785 size_t nmemb,
1786 size_t size,
1787 CompareCB compare)
1788{
1789 return bsearch_r(
1790 key,
1791 base,
1792 nmemb,
1793 size,
1794 [](void* userdata, const void* a, const void* b) {
1795 auto& cb = *static_cast<const CompareCB*>(userdata);
1796 return cb(a, b);
1797 },
1798 &compare);
1799}
1800
1811inline int abs(int x) { return SDL_abs(x); }
1812
1832inline double abs(double x) { return SDL_fabs(x); }
1833
1853inline float abs(float x) { return SDL_fabsf(x); }
1854
1871template<class T, class U>
1872constexpr T min(T x, U y)
1873{
1874 return SDL_min(x, y);
1875}
1876
1893template<class T, class U>
1894constexpr T max(T x, U y)
1895{
1896 return SDL_max(x, y);
1897}
1898
1921template<class T, class U, class V>
1922constexpr T clamp(T x, U a, V b)
1923{
1924 return SDL_clamp(x, a, b);
1925}
1926
1940inline int isalpha(int x) { return SDL_isalpha(x); }
1941
1955inline int isalnum(int x) { return SDL_isalnum(x); }
1956
1970inline int isblank(int x) { return SDL_isblank(x); }
1971
1985inline int iscntrl(int x) { return SDL_iscntrl(x); }
1986
2000inline int isdigit(int x) { return SDL_isdigit(x); }
2001
2015inline int isxdigit(int x) { return SDL_isxdigit(x); }
2016
2033inline int ispunct(int x) { return SDL_ispunct(x); }
2034
2055inline int isspace(int x) { return SDL_isspace(x); }
2056
2070inline int isupper(int x) { return SDL_isupper(x); }
2071
2085inline int islower(int x) { return SDL_islower(x); }
2086
2104inline int isprint(int x) { return SDL_isprint(x); }
2105
2125inline int isgraph(int x) { return SDL_isgraph(x); }
2126
2143inline int toupper(int x) { return SDL_toupper(x); }
2144
2161inline int tolower(int x) { return SDL_tolower(x); }
2162
2182inline Uint16 crc16(Uint16 crc, const void* data, size_t len)
2183{
2184 return SDL_crc16(crc, data, len);
2185}
2186
2206inline Uint32 crc32(Uint32 crc, const void* data, size_t len)
2207{
2208 return SDL_crc32(crc, data, len);
2209}
2210
2235inline Uint32 murmur3_32(const void* data, size_t len, Uint32 seed)
2236{
2237 return SDL_murmur3_32(data, len, seed);
2238}
2239
2258inline void* memcpy(void* dst, const void* src, size_t len)
2259{
2260#ifdef SDL_SLOW_MEMCPY
2261 return SDL_memcpy(dst, src, len);
2262#else
2263 return ::memcpy(dst, src, len);
2264#endif // SDL_SLOW_MEMCPY
2265}
2266
2291template<typename T, typename U>
2292constexpr T* copyp(T* dst, const U* src)
2293{
2294 SDL_copyp(dst, src);
2295 return dst;
2296}
2297
2315inline void* memmove(void* dst, const void* src, size_t len)
2316{
2317#ifdef SDL_SLOW_MEMMOVE
2318 return SDL_memmove(dst, src, len);
2319#else
2320 return ::memmove(dst, src, len);
2321#endif // SDL_SLOW_MEMMOVE
2322}
2323
2342inline void* memset(void* dst, int c, size_t len)
2343{
2344#ifdef SDL_SLOW_MEMSET
2345 return SDL_memset(dst, c, len);
2346#else
2347 return ::memset(dst, c, len);
2348#endif // SDL_SLOW_MEMSET
2349}
2350
2369inline void* memset4(void* dst, Uint32 val, size_t dwords)
2370{
2371 return SDL_memset4(dst, val, dwords);
2372}
2373
2391template<class T>
2392inline void zero(T& x)
2393{
2394 SDL_zero(x);
2395}
2396
2414template<class T>
2415inline void zerop(T* x)
2416{
2417 SDL_zerop(x);
2418}
2419
2437template<class T, std::size_t N>
2438inline void zeroa(T (&x)[N])
2439{
2440 SDL_zeroa(x);
2441}
2442
2457inline int memcmp(const void* s1, const void* s2, size_t len)
2458{
2459 return SDL_memcmp(s1, s2, len);
2460}
2461
2486inline size_t wcslen(const wchar_t* wstr) { return SDL_wcslen(wstr); }
2487
2516inline size_t wcsnlen(const wchar_t* wstr, size_t maxlen)
2517{
2518 return SDL_wcsnlen(wstr, maxlen);
2519}
2520
2546inline size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t maxlen)
2547{
2548 return SDL_wcslcpy(dst, src, maxlen);
2549}
2550
2577inline size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t maxlen)
2578{
2579 return SDL_wcslcat(dst, src, maxlen);
2580}
2581
2598inline wchar_t* wcsdup(const wchar_t* wstr) { return SDL_wcsdup(wstr); }
2599
2618inline wchar_t* wcsstr(const wchar_t* haystack, const wchar_t* needle)
2619{
2620 return SDL_wcsstr(haystack, needle);
2621}
2622
2644inline wchar_t* wcsnstr(const wchar_t* haystack,
2645 const wchar_t* needle,
2646 size_t maxlen)
2647{
2648 return SDL_wcsnstr(haystack, needle, maxlen);
2649}
2650
2667inline int wcscmp(const wchar_t* str1, const wchar_t* str2)
2668{
2669 return SDL_wcscmp(str1, str2);
2670}
2671
2699inline int wcsncmp(const wchar_t* str1, const wchar_t* str2, size_t maxlen)
2700{
2701 return SDL_wcsncmp(str1, str2, maxlen);
2702}
2703
2731inline int wcscasecmp(const wchar_t* str1, const wchar_t* str2)
2732{
2733 return SDL_wcscasecmp(str1, str2);
2734}
2735
2775inline int wcsncasecmp(const wchar_t* str1, const wchar_t* str2, size_t maxlen)
2776{
2777 return SDL_wcsncasecmp(str1, str2, maxlen);
2778}
2779
2804inline long wcstol(const wchar_t* str, wchar_t** endp, int base)
2805{
2806 return SDL_wcstol(str, endp, base);
2807}
2808
2827inline size_t strlen(StringParam str) { return SDL_strlen(str); }
2828
2850inline size_t strnlen(StringParam str, size_t maxlen)
2851{
2852 return SDL_strnlen(str, maxlen);
2853}
2854
2880inline size_t strlcpy(char* dst, StringParam src, size_t maxlen)
2881{
2882 return SDL_strlcpy(dst, src, maxlen);
2883}
2884
2911inline size_t utf8strlcpy(char* dst, StringParam src, size_t dst_bytes)
2912{
2913 return SDL_utf8strlcpy(dst, src, dst_bytes);
2914}
2915
2942inline size_t strlcat(char* dst, StringParam src, size_t maxlen)
2943{
2944 return SDL_strlcat(dst, src, maxlen);
2945}
2946
2963inline char* strdup(StringParam str) { return SDL_strdup(str); }
2964
2988inline char* strndup(StringParam str, size_t maxlen)
2989{
2990 return SDL_strndup(str, maxlen);
2991}
2992
3012inline char* strrev(char* str) { return SDL_strrev(str); }
3013
3033inline char* strupr(char* str) { return SDL_strupr(str); }
3034
3054inline char* strlwr(char* str) { return SDL_strlwr(str); }
3055
3074inline char* strchr(StringParam str, int c) { return SDL_strchr(str, c); }
3075
3093inline char* strrchr(StringParam str, int c) { return SDL_strrchr(str, c); }
3094
3113inline char* strstr(StringParam haystack, StringParam needle)
3114{
3115 return SDL_strstr(haystack, needle);
3116}
3117
3139inline char* strnstr(StringParam haystack, StringParam needle, size_t maxlen)
3140{
3141 return SDL_strnstr(haystack, needle, maxlen);
3142}
3143
3170inline char* strcasestr(StringParam haystack, StringParam needle)
3171{
3172 return SDL_strcasestr(haystack, needle);
3173}
3174
3201inline char* strtok_r(char* str, StringParam delim, char** saveptr)
3202{
3203 return SDL_strtok_r(str, delim, saveptr);
3204}
3205
3230inline size_t utf8strlen(StringParam str) { return SDL_utf8strlen(str); }
3231
3262inline size_t utf8strnlen(StringParam str, size_t bytes)
3263{
3264 return SDL_utf8strnlen(str, bytes);
3265}
3266
3292inline char* itoa(int value, char* str, int radix)
3293{
3294 return SDL_itoa(value, str, radix);
3295}
3296
3322inline char* uitoa(unsigned int value, char* str, int radix)
3323{
3324 return SDL_uitoa(value, str, radix);
3325}
3326
3352inline char* ltoa(long value, char* str, int radix)
3353{
3354 return SDL_ltoa(value, str, radix);
3355}
3356
3382inline char* ultoa(unsigned long value, char* str, int radix)
3383{
3384 return SDL_ultoa(value, str, radix);
3385}
3386
3387#ifndef SDL_NOLONGLONG
3388
3414inline char* lltoa(long long value, char* str, int radix)
3415{
3416 return SDL_lltoa(value, str, radix);
3417}
3418
3444inline char* ulltoa(unsigned long long value, char* str, int radix)
3445{
3446 return SDL_ulltoa(value, str, radix);
3447}
3448
3449#endif // SDL_NOLONGLONG
3450
3472inline int atoi(StringParam str) { return SDL_atoi(str); }
3473
3493inline double atof(StringParam str) { return SDL_atof(str); }
3494
3526inline long strtol(StringParam str, char** endp, int base)
3527{
3528 return SDL_strtol(str, endp, base);
3529}
3530
3561inline unsigned long strtoul(StringParam str, char** endp, int base)
3562{
3563 return SDL_strtoul(str, endp, base);
3564}
3565
3566#ifndef SDL_NOLONGLONG
3567
3598inline long long strtoll(StringParam str, char** endp, int base)
3599{
3600 return SDL_strtoll(str, endp, base);
3601}
3602
3633inline unsigned long long strtoull(StringParam str, char** endp, int base)
3634{
3635 return SDL_strtoull(str, endp, base);
3636}
3637
3638#endif // SDL_NOLONGLONG
3639
3667inline double strtod(StringParam str, char** endp)
3668{
3669 return SDL_strtod(str, endp);
3670}
3671
3689inline int strcmp(StringParam str1, StringParam str2)
3690{
3691 return SDL_strcmp(str1, str2);
3692}
3693
3721inline int strncmp(StringParam str1, StringParam str2, size_t maxlen)
3722{
3723 return SDL_strncmp(str1, str2, maxlen);
3724}
3725
3751inline int strcasecmp(StringParam str1, StringParam str2)
3752{
3753 return SDL_strcasecmp(str1, str2);
3754}
3755
3792inline int strncasecmp(StringParam str1, StringParam str2, size_t maxlen)
3793{
3794 return SDL_strncasecmp(str1, str2, maxlen);
3795}
3796
3813inline char* strpbrk(StringParam str, StringParam breakset)
3814{
3815 return SDL_strpbrk(str, breakset);
3816}
3817
3831constexpr Uint32 INVALID_UNICODE_CODEPOINT = SDL_INVALID_UNICODE_CODEPOINT;
3832
3874inline Uint32 StepUTF8(const char** pstr, size_t* pslen)
3875{
3876 return SDL_StepUTF8(pstr, pslen);
3877}
3878
3906inline Uint32 StepBackUTF8(StringParam start, const char** pstr)
3907{
3908 return SDL_StepBackUTF8(start, pstr);
3909}
3910
3938inline char* UCS4ToUTF8(Uint32 codepoint, char* dst)
3939{
3940 return SDL_UCS4ToUTF8(codepoint, dst);
3941}
3942
3958inline int sscanf(StringParam text,
3959 SDL_SCANF_FORMAT_STRING const char* fmt,
3960 ...)
3961{
3962 int rc;
3963 va_list ap;
3964 va_start(ap, fmt);
3965 rc = SDL_vsscanf(text, fmt, ap);
3966 va_end(ap);
3967 return rc;
3968}
3969
3986inline int vsscanf(StringParam text,
3987 SDL_SCANF_FORMAT_STRING const char* fmt,
3988 va_list ap)
3989{
3990 return SDL_vsscanf(text, fmt, ap);
3991}
3992
4023inline int snprintf(char* text,
4024 size_t maxlen,
4025 SDL_PRINTF_FORMAT_STRING const char* fmt,
4026 ...)
4027{
4028 va_list ap;
4029 int result;
4030
4031 va_start(ap, fmt);
4032 result = SDL_vsnprintf(text, maxlen, fmt, ap);
4033 va_end(ap);
4034
4035 return result;
4036}
4037
4069inline int swprintf(wchar_t* text,
4070 size_t maxlen,
4071 SDL_PRINTF_FORMAT_STRING const wchar_t* fmt,
4072 ...)
4073{
4074 va_list ap;
4075 int result;
4076
4077 va_start(ap, fmt);
4078 result = SDL_vswprintf(text, maxlen, fmt, ap);
4079 va_end(ap);
4080
4081 return result;
4082}
4083
4102inline int vsnprintf(char* text,
4103 size_t maxlen,
4104 SDL_PRINTF_FORMAT_STRING const char* fmt,
4105 va_list ap)
4106{
4107 return SDL_vsnprintf(text, maxlen, fmt, ap);
4108}
4109
4129inline int vswprintf(wchar_t* text,
4130 size_t maxlen,
4131 SDL_PRINTF_FORMAT_STRING const wchar_t* fmt,
4132 va_list ap)
4133{
4134 return SDL_vswprintf(text, maxlen, fmt, ap);
4135}
4136
4163inline int asprintf(char** strp, SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
4164{
4165 va_list ap;
4166 int result;
4167
4168 va_start(ap, fmt);
4169 result = SDL_vasprintf(strp, fmt, ap);
4170 va_end(ap);
4171
4172 return result;
4173}
4174
4192inline int vasprintf(char** strp,
4193 SDL_PRINTF_FORMAT_STRING const char* fmt,
4194 va_list ap)
4195{
4196 return SDL_vasprintf(strp, fmt, ap);
4197}
4198
4216inline void srand(Uint64 seed) { SDL_srand(seed); }
4217
4229{
4230 Uint64 m_state;
4231
4232public:
4234 constexpr Random()
4235 : m_state(0)
4236 {
4237 }
4238
4240 constexpr explicit Random(Uint64 state)
4241 : m_state(state)
4242 {
4243 }
4244
4246 constexpr operator Uint64() const { return m_state; }
4247
4279 Sint32 rand(Sint32 n) { return SDL_rand_r(&m_state, n); }
4280
4303 float randf() { return SDL_randf_r(&m_state); }
4304
4326 Uint32 rand_bits() { return SDL_rand_bits_r(&m_state); }
4327};
4328
4359inline Sint32 rand(Sint32 n) { return SDL_rand(n); }
4360
4394inline Sint32 rand(Uint64* state, Sint32 n) { return SDL_rand_r(state, n); }
4395
4429inline Sint32 rand(Random& state, Sint32 n) { return state.rand(n); }
4430
4451inline float randf() { return SDL_randf(); }
4452
4477inline float randf(Uint64* state) { return SDL_randf_r(state); }
4478
4503inline float randf(Random& state) { return state.randf(); }
4504
4526inline Uint32 rand_bits() { return SDL_rand_bits(); }
4527
4551inline Uint32 rand_bits(Uint64* state) { return SDL_rand_bits_r(state); }
4552
4576inline Uint32 rand_bits(Random& state) { return state.rand_bits(); }
4577
4585constexpr double PI_D = SDL_PI_D;
4586
4594constexpr float PI_F = SDL_PI_F;
4595
4623inline double acos(double x) { return SDL_acos(x); }
4624
4652inline float acos(float x) { return SDL_acosf(x); }
4653
4681inline double asin(double x) { return SDL_asin(x); }
4682
4710inline float asin(float x) { return SDL_asinf(x); }
4711
4741inline double atan(double x) { return SDL_atan(x); }
4742
4772inline float atan(float x) { return SDL_atanf(x); }
4773
4806inline double atan2(double y, double x) { return SDL_atan2(y, x); }
4807
4841inline float atan2(float y, float x) { return SDL_atan2f(y, x); }
4842
4869inline double ceil(double x) { return SDL_ceil(x); }
4870
4897inline float ceil(float x) { return SDL_ceilf(x); }
4898
4922inline double copysign(double x, double y) { return SDL_copysign(x, y); }
4923
4947inline float copysign(float x, float y) { return SDL_copysignf(x, y); }
4948
4974inline double cos(double x) { return SDL_cos(x); }
4975
5001inline float cos(float x) { return SDL_cosf(x); }
5002
5032inline double exp(double x) { return SDL_exp(x); }
5033
5063inline float exp(float x) { return SDL_expf(x); }
5064
5091inline double floor(double x) { return SDL_floor(x); }
5092
5119inline float floor(float x) { return SDL_floorf(x); }
5120
5148inline double trunc(double x) { return SDL_trunc(x); }
5149
5177inline float trunc(float x) { return SDL_truncf(x); }
5178
5207inline double fmod(double x, double y) { return SDL_fmod(x, y); }
5208
5237inline float fmod(float x, float y) { return SDL_fmodf(x, y); }
5238
5251inline int isinf(double x) { return SDL_isinf(x); }
5252
5265inline int isinf(float x) { return SDL_isinff(x); }
5266
5279inline int isnan(double x) { return SDL_isnan(x); }
5280
5293inline int isnan(float x) { return SDL_isnanf(x); }
5294
5322inline double log(double x) { return SDL_log(x); }
5323
5350inline float log(float x) { return SDL_logf(x); }
5351
5379inline double log10(double x) { return SDL_log10(x); }
5380
5408inline float log10(float x) { return SDL_log10f(x); }
5409
5428inline double modf(double x, double* y) { return SDL_modf(x, y); }
5429
5448inline float modf(float x, float* y) { return SDL_modff(x, y); }
5449
5478inline double pow(double x, double y) { return SDL_pow(x, y); }
5479
5508inline float pow(float x, float y) { return SDL_powf(x, y); }
5509
5537inline double round(double x) { return SDL_round(x); }
5538
5566inline float round(float x) { return SDL_roundf(x); }
5567
5595inline long lround(double x) { return SDL_lround(x); }
5596
5624inline long lround(float x) { return SDL_lroundf(x); }
5625
5649inline double scalbn(double x, int n) { return SDL_scalbn(x, n); }
5650
5674inline float scalbn(float x, int n) { return SDL_scalbnf(x, n); }
5675
5701inline double sin(double x) { return SDL_sin(x); }
5702
5728inline float sin(float x) { return SDL_sinf(x); }
5729
5753inline double sqrt(double x) { return SDL_sqrt(x); }
5754
5778inline float sqrt(float x) { return SDL_sqrtf(x); }
5779
5807inline double tan(double x) { return SDL_tan(x); }
5808
5836inline float tan(float x) { return SDL_tanf(x); }
5837
5843struct IConvBase : ResourceBaseT<IConvRaw>
5844{
5846
5848 explicit operator bool() const noexcept
5849 {
5850 return reinterpret_cast<size_t>(get()) != SDL_ICONV_ERROR;
5851 }
5852
5866 int close();
5867
5904 size_t iconv(const char** inbuf,
5905 size_t* inbytesleft,
5906 char** outbuf,
5907 size_t* outbytesleft) const;
5908};
5909
5921{
5922 using IConvBase::IConvBase;
5923
5925 IConv(std::nullptr_t = nullptr) noexcept
5926 : IConv(IConvRaw(SDL_ICONV_ERROR))
5927 {
5928 }
5929
5937 constexpr explicit IConv(IConvRaw resource) noexcept
5938 : IConvBase(resource)
5939 {
5940 }
5941
5943 constexpr IConv(IConv&& other) noexcept
5944 : IConv(other.release())
5945 {
5946 }
5947
5964 IConv(StringParam tocode, StringParam fromcode);
5965
5967 ~IConv() { SDL_iconv_close(get()); }
5968
5970 constexpr IConv& operator=(IConv&& other) noexcept
5971 {
5972 swap(*this, other);
5973 return *this;
5974 }
5975};
5976
5993inline IConv iconv_open(StringParam tocode, StringParam fromcode)
5994{
5995 return IConv(std::move(tocode), std::move(fromcode));
5996}
5997
5998inline IConv::IConv(StringParam tocode, StringParam fromcode)
5999 : IConv(SDL_iconv_open(tocode, fromcode))
6000{
6001}
6002
6018inline int iconv_close(IConvRaw cd) { return CheckError(SDL_iconv_close(cd)); }
6019
6020inline int IConvBase::close() { return iconv_close(release()); }
6021
6058inline size_t iconv(IConvRef cd,
6059 const char** inbuf,
6060 size_t* inbytesleft,
6061 char** outbuf,
6062 size_t* outbytesleft)
6063{
6064 return CheckError(SDL_iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft));
6065}
6066
6067inline size_t IConvBase::iconv(const char** inbuf,
6068 size_t* inbytesleft,
6069 char** outbuf,
6070 size_t* outbytesleft) const
6071{
6072 return SDL::iconv(get(), inbuf, inbytesleft, outbuf, outbytesleft);
6073}
6074
6075constexpr size_t ICONV_ERROR =
6076 SDL_ICONV_ERROR;
6077
6078constexpr size_t ICONV_E2BIG =
6079 SDL_ICONV_E2BIG;
6080
6081constexpr size_t ICONV_EILSEQ =
6082 SDL_ICONV_EILSEQ;
6083
6084constexpr size_t ICONV_EINVAL =
6085 SDL_ICONV_EINVAL;
6086
6111 StringParam fromcode,
6112 SourceBytes inbuf)
6113{
6114 return OwnArray<char>{
6115 SDL_iconv_string(tocode, fromcode, inbuf.data(), inbuf.size_bytes())};
6116}
6117
6132inline OwnArray<char> iconv_utf8_locale(std::string_view S)
6133{
6134 return iconv_string("", "UTF-8", S);
6135}
6136
6151inline OwnArray<Uint16> iconv_utf8_ucs2(std::string_view S)
6152{
6153 auto data = SDL_iconv_string("UCS-2", "UTF-8", S.data(), S.size());
6154 return OwnArray<Uint16>(reinterpret_cast<Uint16*>(data));
6155}
6156
6171inline OwnArray<Uint32> iconv_utf8_ucs4(std::string_view S)
6172{
6173 auto data = SDL_iconv_string("UCS-4", "UTF-8", S.data(), S.size());
6174 return OwnArray<Uint32>(reinterpret_cast<Uint32*>(data));
6175}
6176
6191inline OwnArray<char> iconv_wchar_utf8(std::wstring_view S)
6192{
6193 return iconv_string("UTF-8", "WCHAR_T", S);
6194}
6195
6213inline bool size_mul_check_overflow(size_t a, size_t b, size_t* ret)
6214{
6215 return SDL_size_mul_check_overflow(a, b, ret);
6216}
6217
6235inline bool size_add_check_overflow(size_t a, size_t b, size_t* ret)
6236{
6237 return SDL_size_add_check_overflow(a, b, ret);
6238}
6239
6255using FunctionPointer = void(SDLCALL*)();
6256
6258
6259inline void PtrDeleter::operator()(void* ptr) const { SDL_free(ptr); }
6260
6262template<std::integral T>
6264{
6265 if constexpr (std::is_signed_v<T>) {
6266 SDL_assert_paranoid(value >= std::numeric_limits<Sint32>::min() &&
6267 value <= std::numeric_limits<Sint32>::max());
6268 } else {
6269 SDL_assert_paranoid(value <= std::numeric_limits<Sint32>::max());
6270 }
6271 return static_cast<Sint32>(value);
6272}
6273
6275template<std::integral T>
6277{
6278 SDL_assert_paranoid(value <= std::numeric_limits<Uint32>::max());
6279 return static_cast<Uint32>(value);
6280}
6281
6282} // namespace SDL
6283
6284#endif /* SDL3PP_STDINC_H_ */
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
A independent pseudo random state.
Definition SDL3pp_stdinc.h:4229
constexpr Random(Uint64 state)
Init state with the given value.
Definition SDL3pp_stdinc.h:4240
float randf()
Generate a uniform pseudo-random floating point number less than 1.0.
Definition SDL3pp_stdinc.h:4303
constexpr Random()
Default constructor initializes state to zero.
Definition SDL3pp_stdinc.h:4234
Uint32 rand_bits()
Generate 32 pseudo-random bits.
Definition SDL3pp_stdinc.h:4326
Sint32 rand(Sint32 n)
Generate a pseudo-random number less than n for positive n.
Definition SDL3pp_stdinc.h:4279
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Source byte stream.
Definition SDL3pp_strings.h:237
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:301
constexpr const char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:304
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
SDL times are signed, 64-bit integers representing nanoseconds since the Unix epoch (Jan 1,...
Definition SDL3pp_stdinc.h:369
constexpr Sint64 ToNS() const
Converts to nanoseconds Sint64.
Definition SDL3pp_stdinc.h:423
constexpr Time & operator+=(std::chrono::nanoseconds interval)
Increment time.
Definition SDL3pp_stdinc.h:497
constexpr float ToSeconds() const
Converts a time to seconds (float) since epoch.
Definition SDL3pp_stdinc.h:487
constexpr Time & operator-=(std::chrono::nanoseconds interval)
Decrement.
Definition SDL3pp_stdinc.h:504
constexpr Time(std::chrono::nanoseconds time) noexcept
Wraps Time.
Definition SDL3pp_stdinc.h:390
constexpr Time(TimeRaw time) noexcept
Wraps Time.
Definition SDL3pp_stdinc.h:380
static constexpr Time FromNS(Sint64 time)
Create from a nanoseconds Sint64.
Definition SDL3pp_stdinc.h:417
static constexpr Time FromSeconds(float interval)
Converts a time to seconds (float) since epoch.
Definition SDL3pp_stdinc.h:490
Concept of interface.
Definition SDL3pp_stdinc.h:537
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:383
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
int wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
Compare two wide strings up to a number of wchar_t values.
Definition SDL3pp_stdinc.h:2699
double log(double x)
Compute the natural logarithm of x.
Definition SDL3pp_stdinc.h:5322
char * UCS4ToUTF8(Uint32 codepoint, char *dst)
Convert a single Unicode codepoint to UTF-8.
Definition SDL3pp_stdinc.h:3938
long wcstol(const wchar_t *str, wchar_t **endp, int base)
Parse a long from a wide string.
Definition SDL3pp_stdinc.h:2804
char * strdup(StringParam str)
Allocate a copy of a string.
Definition SDL3pp_stdinc.h:2963
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:851
double strtod(StringParam str, char **endp)
Parse a double from a string.
Definition SDL3pp_stdinc.h:3667
constexpr Sint8 MIN_SINT8
Min representable value.
Definition SDL3pp_stdinc.h:237
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:3170
void UnsetVariable(StringParam name)
Clear a variable from the environment.
Definition SDL3pp_stdinc.h:1267
double atan(double x)
Compute the arc tangent of x.
Definition SDL3pp_stdinc.h:4741
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:4163
double ceil(double x)
Compute the ceiling of x.
Definition SDL3pp_stdinc.h:4869
void SetEnvironmentVariable(EnvironmentRef env, StringParam name, StringParam value, bool overwrite)
Set the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1228
char * strlwr(char *str)
Convert a string to lowercase.
Definition SDL3pp_stdinc.h:3054
void * memmove(void *dst, const void *src, size_t len)
Copy memory ranges that might overlap.
Definition SDL3pp_stdinc.h:2315
::Sint32 Sint32
A signed 32-bit integer type.
Definition SDL3pp_stdinc.h:283
int memcmp(const void *s1, const void *s2, size_t len)
Compare two buffers of memory.
Definition SDL3pp_stdinc.h:2457
constexpr Uint16 MIN_UINT16
Min representable value.
Definition SDL3pp_stdinc.h:276
std::chrono::nanoseconds Nanoseconds
Duration in Nanoseconds (Uint64).
Definition SDL3pp_stdinc.h:338
constexpr std::size_t arraysize(const T(&array)[N])
The number of elements in a static array.
Definition SDL3pp_stdinc.h:160
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:3139
OwnArray< Uint16 > iconv_utf8_ucs2(std::string_view S)
Convert a UTF-8 string to UCS-2.
Definition SDL3pp_stdinc.h:6151
int isnan(double x)
Return whether the value is NaN.
Definition SDL3pp_stdinc.h:5279
constexpr Uint32 INVALID_UNICODE_CODEPOINT
The Unicode REPLACEMENT CHARACTER codepoint.
Definition SDL3pp_stdinc.h:3831
double scalbn(double x, int n)
Scale x by an integer power of two.
Definition SDL3pp_stdinc.h:5649
char * ultoa(unsigned long value, char *str, int radix)
Convert an unsigned long integer into a string.
Definition SDL3pp_stdinc.h:3382
wchar_t * wcsdup(const wchar_t *wstr)
Allocate a copy of a wide string.
Definition SDL3pp_stdinc.h:2598
int isgraph(int x)
Report if a character is any "printable" except space.
Definition SDL3pp_stdinc.h:2125
const char * GetVariable(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1174
constexpr Sint16 MIN_SINT16
Min representable value.
Definition SDL3pp_stdinc.h:263
int strncmp(StringParam str1, StringParam str2, size_t maxlen)
Compare two UTF-8 strings up to a number of bytes.
Definition SDL3pp_stdinc.h:3721
double asin(double x)
Compute the arc sine of x.
Definition SDL3pp_stdinc.h:4681
Uint16 crc16(Uint16 crc, const void *data, size_t len)
Calculate a CRC-16 value.
Definition SDL3pp_stdinc.h:2182
char * strrev(char *str)
Reverse a string's contents.
Definition SDL3pp_stdinc.h:3012
OwnArray< char * > GetVariables()
Get all variables in the environment.
Definition SDL3pp_stdinc.h:1203
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:3792
constexpr T min(T x, U y)
Return the lesser of two values.
Definition SDL3pp_stdinc.h:1872
unsigned long strtoul(StringParam str, char **endp, int base)
Parse an unsigned long from a string.
Definition SDL3pp_stdinc.h:3561
int isdigit(int x)
Report if a character is a numeric digit.
Definition SDL3pp_stdinc.h:2000
double exp(double x)
Compute the exponential of x.
Definition SDL3pp_stdinc.h:5032
char * strstr(StringParam haystack, StringParam needle)
Search a string for the first instance of a specific substring.
Definition SDL3pp_stdinc.h:3113
constexpr Uint32 MAX_UINT32
Max representable value.
Definition SDL3pp_stdinc.h:299
IConv iconv_open(StringParam tocode, StringParam fromcode)
This function allocates a context for the specified character set conversion.
Definition SDL3pp_stdinc.h:5993
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:4102
char * strchr(StringParam str, int c)
Search a string for the first instance of a specific byte.
Definition SDL3pp_stdinc.h:3074
int close()
This function frees a context used for character set conversion.
Definition SDL3pp_stdinc.h:6020
double copysign(double x, double y)
Copy the sign of one floating-point value to another.
Definition SDL3pp_stdinc.h:4922
Environment CreateEnvironment(bool populated)
Create a set of environment variables.
Definition SDL3pp_stdinc.h:1141
void * malloc(size_t size)
Allocate uninitialized memory.
Definition SDL3pp_stdinc.h:608
constexpr float FLT_EPSILON
Epsilon constant, used for comparing floating-point numbers.
Definition SDL3pp_stdinc.h:527
double modf(double x, double *y)
Split x into integer and fractional parts.
Definition SDL3pp_stdinc.h:5428
void zero(T &x)
Clear an object's memory to zero.
Definition SDL3pp_stdinc.h:2392
size_t strlcat(char *dst, StringParam src, size_t maxlen)
Concatenate strings.
Definition SDL3pp_stdinc.h:2942
void zeroa(T(&x)[N])
Clear an array's memory to zero.
Definition SDL3pp_stdinc.h:2438
char * strndup(StringParam str, size_t maxlen)
Allocate a copy of a string, up to n characters.
Definition SDL3pp_stdinc.h:2988
constexpr Uint8 MIN_UINT64
Min representable value.
Definition SDL3pp_stdinc.h:332
void(SDLCALL *)() FunctionPointer
A generic function pointer.
Definition SDL3pp_stdinc.h:6255
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:4023
double round(double x)
Round x to the nearest integer.
Definition SDL3pp_stdinc.h:5537
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:3958
size_t strlcpy(char *dst, StringParam src, size_t maxlen)
Copy a string.
Definition SDL3pp_stdinc.h:2880
void * memset(void *dst, int c, size_t len)
Initialize all bytes of buffer of memory to a specific value.
Definition SDL3pp_stdinc.h:2342
constexpr Uint64 MAX_UINT64
Max representable value.
Definition SDL3pp_stdinc.h:329
bool size_mul_check_overflow(size_t a, size_t b, size_t *ret)
Multiply two integers, checking for overflow.
Definition SDL3pp_stdinc.h:6213
int iconv_close(IConvRaw cd)
This function frees a context used for character set conversion.
Definition SDL3pp_stdinc.h:6018
ResourceRefT< EnvironmentBase > EnvironmentRef
Reference for Environment.
Definition SDL3pp_stdinc.h:62
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:792
int strcmp(StringParam str1, StringParam str2)
Compare two null-terminated UTF-8 strings.
Definition SDL3pp_stdinc.h:3689
::Sint64 Sint64
A signed 64-bit integer type.
Definition SDL3pp_stdinc.h:311
SDL_Time TimeRaw
Alias to raw representation for Time.
Definition SDL3pp_stdinc.h:43
bool size_add_check_overflow(size_t a, size_t b, size_t *ret)
Add two integers, checking for overflow.
Definition SDL3pp_stdinc.h:6235
void UnsetEnvironmentVariable(EnvironmentRef env, StringParam name)
Clear a variable from the environment.
Definition SDL3pp_stdinc.h:1262
SDL_iconv_t IConvRaw
Alias to raw representation for IConv.
Definition SDL3pp_stdinc.h:71
std::function< int(const void *a, const void *b)> CompareCB
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1533
char * uitoa(unsigned int value, char *str, int radix)
Convert an unsigned integer into a string.
Definition SDL3pp_stdinc.h:3322
double pow(double x, double y)
Raise x to the power y.
Definition SDL3pp_stdinc.h:5478
constexpr T * copyp(T *dst, const U *src)
A macro to copy memory between objects, with basic type checking.
Definition SDL3pp_stdinc.h:2292
constexpr Sint32 MIN_SINT32
Min representable value.
Definition SDL3pp_stdinc.h:289
EnvironmentRaw GetEnvironment()
Get the process environment.
Definition SDL3pp_stdinc.h:1119
int isprint(int x)
Report if a character is "printable".
Definition SDL3pp_stdinc.h:2104
long lround(double x)
Round x to the nearest integer representable as a long.
Definition SDL3pp_stdinc.h:5595
int isxdigit(int x)
Report if a character is a hexadecimal digit.
Definition SDL3pp_stdinc.h:2015
constexpr T max(T x, U y)
Return the greater of two values.
Definition SDL3pp_stdinc.h:1894
int atoi(StringParam str)
Parse an int from a string.
Definition SDL3pp_stdinc.h:3472
OwnArray< char > iconv_string(StringParam tocode, StringParam fromcode, SourceBytes inbuf)
Helper function to convert a string's encoding in one call.
Definition SDL3pp_stdinc.h:6110
int tolower(int x)
Convert low-ASCII English letters to lowercase.
Definition SDL3pp_stdinc.h:2161
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition SDL3pp_stdinc.h:270
int isalpha(int x)
Query if a character is alphabetic (a letter).
Definition SDL3pp_stdinc.h:1940
constexpr size_t ICONV_E2BIG
Output buffer was too small.
Definition SDL3pp_stdinc.h:6078
OwnArray< char > iconv_utf8_locale(std::string_view S)
Convert a UTF-8 string to the current locale's character encoding.
Definition SDL3pp_stdinc.h:6132
OwnArray< Uint32 > iconv_utf8_ucs4(std::string_view S)
Convert a UTF-8 string to UCS-4.
Definition SDL3pp_stdinc.h:6171
int unsetenv_unsafe(StringParam name)
Clear a variable from the environment.
Definition SDL3pp_stdinc.h:1368
constexpr float ToSeconds(Seconds duration)
Converts a time duration to seconds (float).
Definition SDL3pp_stdinc.h:344
char * strupr(char *str)
Convert a string to uppercase.
Definition SDL3pp_stdinc.h:3033
size_t utf8strlen(StringParam str)
Count the number of codepoints in a UTF-8 string.
Definition SDL3pp_stdinc.h:3230
constexpr Seconds FromSeconds(float duration)
Converts a float to seconds representation.
Definition SDL3pp_stdinc.h:347
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:3262
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:4129
int isupper(int x)
Report if a character is upper case.
Definition SDL3pp_stdinc.h:2070
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:2516
double sqrt(double x)
Compute the square root of x.
Definition SDL3pp_stdinc.h:5753
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:296
void *(SDLCALL *)(size_t nmemb, size_t size) calloc_func
A callback used to implement calloc().
Definition SDL3pp_stdinc.h:734
constexpr Sint16 MAX_SINT16
Max representable value.
Definition SDL3pp_stdinc.h:260
void srand(Uint64 seed)
Seeds the pseudo-random number generator.
Definition SDL3pp_stdinc.h:4216
constexpr Uint8 MAX_UINT8
Max representable value.
Definition SDL3pp_stdinc.h:247
double tan(double x)
Compute the tangent of x.
Definition SDL3pp_stdinc.h:5807
double sin(double x)
Compute the sine of x.
Definition SDL3pp_stdinc.h:5701
constexpr size_t ICONV_EILSEQ
Invalid input sequence was encountered.
Definition SDL3pp_stdinc.h:6081
const char * getenv_unsafe(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1329
size_t utf8strlcpy(char *dst, StringParam src, size_t dst_bytes)
Copy an UTF-8 string.
Definition SDL3pp_stdinc.h:2911
constexpr Sint64 MIN_SINT64
Min representable value.
Definition SDL3pp_stdinc.h:317
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:3201
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:2369
constexpr size_t ICONV_ERROR
Generic error. Check GetError()?
Definition SDL3pp_stdinc.h:6075
ResourceRefT< IConvBase > IConvRef
Reference for IConv.
Definition SDL3pp_stdinc.h:78
void(SDLCALL *)(void *mem) free_func
A callback used to implement free().
Definition SDL3pp_stdinc.h:773
int iscntrl(int x)
Report if a character is a control character.
Definition SDL3pp_stdinc.h:1985
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:4069
constexpr double PI_D
The value of Pi, as a double-precision floating point literal.
Definition SDL3pp_stdinc.h:4585
int islower(int x)
Report if a character is lower case.
Definition SDL3pp_stdinc.h:2085
int isinf(double x)
Return whether the value is infinity.
Definition SDL3pp_stdinc.h:5251
int isspace(int x)
Report if a character is whitespace.
Definition SDL3pp_stdinc.h:2055
void DestroyEnvironment(EnvironmentRaw env)
Destroy a set of environment variables.
Definition SDL3pp_stdinc.h:1284
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:2850
int strcasecmp(StringParam str1, StringParam str2)
Compare two null-terminated UTF-8 strings, case-insensitively.
Definition SDL3pp_stdinc.h:3751
size_t strlen(StringParam str)
This works exactly like strlen() but doesn't require access to a C runtime.
Definition SDL3pp_stdinc.h:2827
constexpr Uint16 MAX_UINT16
Max representable value.
Definition SDL3pp_stdinc.h:273
const char * getenv(StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1306
int setenv_unsafe(StringParam name, StringParam value, int overwrite)
Set the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1350
constexpr void InitInterface(I *iface)
A macro to initialize an SDL interface.
Definition SDL3pp_stdinc.h:578
::Sint16 Sint16
A signed 16-bit integer type.
Definition SDL3pp_stdinc.h:257
size_t iconv(IConvRef cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
This function converts text between encodings, reading from and writing to a buffer.
Definition SDL3pp_stdinc.h:6058
int wcscmp(const wchar_t *str1, const wchar_t *str2)
Compare two null-terminated wide strings.
Definition SDL3pp_stdinc.h:2667
double acos(double x)
Compute the arc cosine of x.
Definition SDL3pp_stdinc.h:4623
void SetVariable(StringParam name, StringParam value, bool overwrite)
Set the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1236
Sint32 rand(Sint32 n)
Generate a pseudo-random number less than n for positive n.
Definition SDL3pp_stdinc.h:4359
constexpr Sint64 MAX_SINT64
Max representable value.
Definition SDL3pp_stdinc.h:314
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:1587
double floor(double x)
Compute the floor of x.
Definition SDL3pp_stdinc.h:5091
void *(SDLCALL *)(size_t size) malloc_func
A callback used to implement malloc().
Definition SDL3pp_stdinc.h:713
Uint32 StepUTF8(const char **pstr, size_t *pslen)
Decode a UTF-8 string, one Unicode codepoint at a time.
Definition SDL3pp_stdinc.h:3874
int toupper(int x)
Convert low-ASCII English letters to uppercase.
Definition SDL3pp_stdinc.h:2143
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:2235
size_t iconv(const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) const
This function converts text between encodings, reading from and writing to a buffer.
Definition SDL3pp_stdinc.h:6067
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:244
std::chrono::duration< float > Seconds
Duration in seconds (float).
Definition SDL3pp_stdinc.h:335
constexpr Uint32 FourCC(Uint8 a, Uint8 b, Uint8 c, Uint8 d)
Define a four character code as a Uint32.
Definition SDL3pp_stdinc.h:191
Uint32 StepBackUTF8(StringParam start, const char **pstr)
Decode a UTF-8 string in reverse, one Unicode codepoint at a time.
Definition SDL3pp_stdinc.h:3906
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
Copy a wide string.
Definition SDL3pp_stdinc.h:2546
float randf()
Generate a uniform pseudo-random floating point number less than 1.0.
Definition SDL3pp_stdinc.h:4451
constexpr T clamp(T x, U a, V b)
Return a value clamped to a range.
Definition SDL3pp_stdinc.h:1922
constexpr Time MAX_TIME
Max allowed time representation.
Definition SDL3pp_stdinc.h:512
constexpr Nanoseconds FromNS(Sint64 duration)
Converts a Sint64 to nanoseconds representation.
Definition SDL3pp_stdinc.h:353
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:2775
void aligned_free(void *mem)
Free memory allocated by aligned_alloc().
Definition SDL3pp_stdinc.h:903
void zerop(T *x)
Clear an object's memory to zero, using a pointer.
Definition SDL3pp_stdinc.h:2415
int abs(int x)
Compute the absolute value of x.
Definition SDL3pp_stdinc.h:1811
void * calloc(size_t nmemb, size_t size)
Allocate a zero-initialized array.
Definition SDL3pp_stdinc.h:633
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:818
OwnArray< char * > GetEnvironmentVariables(EnvironmentRef env)
Get all variables in the environment.
Definition SDL3pp_stdinc.h:1198
void qsort(void *base, size_t nmemb, size_t size, CompareCallback compare)
Sort an array.
Definition SDL3pp_stdinc.h:1433
constexpr Time MIN_TIME
Min allowed time representation.
Definition SDL3pp_stdinc.h:515
constexpr Sint64 ToNS(Nanoseconds duration)
Converts a time duration to nanoseconds (Sint64);.
Definition SDL3pp_stdinc.h:350
SDL_Environment * EnvironmentRaw
Alias to raw representation for Environment.
Definition SDL3pp_stdinc.h:55
int isblank(int x)
Report if a character is blank (a space or tab).
Definition SDL3pp_stdinc.h:1970
void * realloc(void *mem, size_t size)
Change the size of allocated memory.
Definition SDL3pp_stdinc.h:674
void Destroy()
Destroy a set of environment variables.
Definition SDL3pp_stdinc.h:1289
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:4192
::Sint8 Sint8
A signed 8-bit integer type.
Definition SDL3pp_stdinc.h:231
char * itoa(int value, char *str, int radix)
Convert an integer into a string.
Definition SDL3pp_stdinc.h:3292
int ispunct(int x)
Report if a character is a punctuation mark.
Definition SDL3pp_stdinc.h:2033
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:3986
constexpr Uint8 MIN_UINT8
Min representable value.
Definition SDL3pp_stdinc.h:250
int(SDLCALL *)(const void *a, const void *b) CompareCallback
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1387
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:2644
Uint32 crc32(Uint32 crc, const void *data, size_t len)
Calculate a CRC-32 value.
Definition SDL3pp_stdinc.h:2206
double log10(double x)
Compute the base-10 logarithm of x.
Definition SDL3pp_stdinc.h:5379
const char * GetEnvironmentVariable(EnvironmentRef env, StringParam name)
Get the value of a variable in the environment.
Definition SDL3pp_stdinc.h:1169
constexpr float PI_F
The value of Pi, as a single-precision floating point literal.
Definition SDL3pp_stdinc.h:4594
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:2618
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:1490
std::chrono::milliseconds Milliseconds
Duration in Miliseconds (Uint32).
Definition SDL3pp_stdinc.h:341
double cos(double x)
Compute the cosine of x.
Definition SDL3pp_stdinc.h:4974
void free(void *mem)
Free allocated memory.
Definition SDL3pp_stdinc.h:694
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:4806
void *(SDLCALL *)(void *mem, size_t size) realloc_func
A callback used to implement realloc().
Definition SDL3pp_stdinc.h:755
int wcscasecmp(const wchar_t *str1, const wchar_t *str2)
Compare two null-terminated wide strings, case-insensitively.
Definition SDL3pp_stdinc.h:2731
char * strpbrk(StringParam str, StringParam breakset)
Searches a string for the first occurrence of any character contained in a breakset,...
Definition SDL3pp_stdinc.h:3813
void * aligned_alloc(size_t alignment, size_t size)
Allocate memory aligned to a specific alignment.
Definition SDL3pp_stdinc.h:882
int GetNumAllocations()
Get the number of outstanding (unfreed) allocations.
Definition SDL3pp_stdinc.h:914
Uint32 rand_bits()
Generate 32 pseudo-random bits.
Definition SDL3pp_stdinc.h:4526
constexpr Sint8 MAX_SINT8
Max representable value.
Definition SDL3pp_stdinc.h:234
constexpr Uint8 MIN_UINT32
Min representable value.
Definition SDL3pp_stdinc.h:302
double trunc(double x)
Truncate x to an integer.
Definition SDL3pp_stdinc.h:5148
int(SDLCALL *)(void *userdata, const void *a, const void *b) CompareCallback_r
A callback used with SDL sorting and binary search functions.
Definition SDL3pp_stdinc.h:1514
char * ltoa(long value, char *str, int radix)
Convert a long integer into a string.
Definition SDL3pp_stdinc.h:3352
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
Concatenate wide strings.
Definition SDL3pp_stdinc.h:2577
double atof(StringParam str)
Parse a double from a string.
Definition SDL3pp_stdinc.h:3493
constexpr size_t ICONV_EINVAL
Incomplete input sequence was encountered.
Definition SDL3pp_stdinc.h:6084
constexpr Sint32 MAX_SINT32
Max representable value.
Definition SDL3pp_stdinc.h:286
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:326
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:1717
long strtol(StringParam str, char **endp, int base)
Parse a long from a string.
Definition SDL3pp_stdinc.h:3526
OwnArray< char > iconv_wchar_utf8(std::wstring_view S)
Convert a wchar_t string to UTF-8.
Definition SDL3pp_stdinc.h:6191
char * strrchr(StringParam str, int c)
Search a string for the last instance of a specific byte.
Definition SDL3pp_stdinc.h:3093
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:2486
int isalnum(int x)
Query if a character is alphabetic (a letter) or a number.
Definition SDL3pp_stdinc.h:1955
double fmod(double x, double y)
Return the floating-point remainder of x / y.
Definition SDL3pp_stdinc.h:5207
void * memcpy(void *dst, const void *src, size_t len)
Copy non-overlapping memory.
Definition SDL3pp_stdinc.h:2258
static Time FromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime)
Converts a Windows FILETIME (100-nanosecond intervals since January 1, 1601) to an SDL time.
Definition SDL3pp_time.h:411
void ToWindows(Uint32 *dwLowDateTime, Uint32 *dwHighDateTime) const
Converts an SDL time into a Windows FILETIME (100-nanosecond intervals since January 1,...
Definition SDL3pp_time.h:406
static Time Current()
Gets the current value of the system realtime clock in nanoseconds since Jan 1, 1970 in Universal Coo...
Definition SDL3pp_time.h:351
constexpr Sint64 ToPosix() const
Convert nanoseconds to seconds.
Definition SDL3pp_timer.h:31
static constexpr Time FromPosix(Sint64 time)
Convert seconds to nanoseconds.
Definition SDL3pp_timer.h:26
Main include header for the SDL3pp library.
Uint32 narrowU32(T value)
Narrows to Uint32.
Definition SDL3pp_stdinc.h:6276
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6263
Base class to Environment.
Definition SDL3pp_stdinc.h:922
Uint64 GetVariableCount()
Get the Variables count.
Definition SDL3pp_stdinc.h:984
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
A thread-safe set of environment variables.
Definition SDL3pp_stdinc.h:1044
constexpr Environment(EnvironmentRaw resource) noexcept
Constructs from raw Environment.
Definition SDL3pp_stdinc.h:1054
constexpr Environment & operator=(Environment &&other) noexcept
Assignment operator.
Definition SDL3pp_stdinc.h:1091
~Environment()
Destructor.
Definition SDL3pp_stdinc.h:1088
constexpr Environment(Environment &&other) noexcept
Move constructor.
Definition SDL3pp_stdinc.h:1060
Base class to IConv.
Definition SDL3pp_stdinc.h:5844
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An opaque handle representing string encoding conversion state.
Definition SDL3pp_stdinc.h:5921
IConv(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition SDL3pp_stdinc.h:5925
constexpr IConv & operator=(IConv &&other) noexcept
Assignment operator.
Definition SDL3pp_stdinc.h:5970
~IConv()
Destructor.
Definition SDL3pp_stdinc.h:5967
constexpr IConv(IConvRaw resource) noexcept
Constructs from raw IConv.
Definition SDL3pp_stdinc.h:5937
constexpr IConv(IConv &&other) noexcept
Move constructor.
Definition SDL3pp_stdinc.h:5943
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93