1#ifndef SDL3PP_STDINC_H_
2#define SDL3PP_STDINC_H_
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"
44struct EnvironmentBase;
79#define SDL_NOLONGLONG 1
95#define SDL_SIZE_MAX SIZE_MAX
107template<
class T, std::
size_t N>
110 return SDL_arraysize(array);
129#define SDL_STRINGIFY_ARG(arg) #arg
147constexpr Uint32
FourCC(Uint8 a, Uint8 b, Uint8 c, Uint8 d)
149 return SDL_FOURCC(a, b, c, d);
165#define SDL_SINT64_C(c) c##LL
178#define SDL_UINT64_C(c) c##ULL
182constexpr Sint8 MAX_SINT8 = SDL_MAX_SINT8;
184constexpr Sint8 MIN_SINT8 = SDL_MIN_SINT8;
186constexpr Uint8 MAX_UINT8 = SDL_MAX_UINT8;
188constexpr Uint8 MIN_UINT8 = SDL_MIN_UINT8;
190constexpr Sint16 MAX_SINT16 = SDL_MAX_SINT16;
192constexpr Sint16 MIN_SINT16 = SDL_MIN_SINT16;
194constexpr Uint16 MAX_UINT16 = SDL_MAX_UINT16;
196constexpr Uint16 MIN_UINT16 = SDL_MIN_UINT16;
198constexpr Sint32 MAX_SINT32 = SDL_MAX_SINT32;
200constexpr Sint32 MIN_SINT32 = SDL_MIN_SINT32;
202constexpr Uint32 MAX_UINT32 = SDL_MAX_UINT32;
204constexpr Uint8 MIN_UINT32 = SDL_MIN_UINT32;
206constexpr Sint64 MAX_SINT64 = SDL_MAX_SINT64;
208constexpr Sint64 MIN_SINT64 = SDL_MIN_SINT64;
210constexpr Uint64 MAX_UINT64 = SDL_MAX_UINT64;
212constexpr Uint8 MIN_UINT64 = SDL_MIN_UINT64;
237constexpr Sint64
ToNS(std::chrono::nanoseconds duration)
239 return duration.count();
262 std::chrono::nanoseconds m_value;
265 constexpr Time() =
default;
268 constexpr Time(std::chrono::nanoseconds time)
274 constexpr explicit Time(SDL_Time time)
280 constexpr explicit operator bool()
const
282 return m_value != std::chrono::nanoseconds{};
286 constexpr operator std::chrono::nanoseconds()
const {
return m_value; }
293 return Time{std::chrono::nanoseconds{time}};
297 constexpr Sint64
ToNS()
const {
return m_value.count(); }
301 constexpr Sint64
ToPosix()
const;
305 void ToWindows(Uint32* dwLowDateTime, Uint32* dwHighDateTime)
const;
317 return std::chrono::duration_cast<std::chrono::nanoseconds>(
350#define SDL_FLT_EPSILON 1.1920928955078125e-07F
390#define SDL_INIT_INTERFACE(iface) \
393 (iface)->version = sizeof(*(iface)); \
424inline void*
malloc(
size_t size) {
return SDL_malloc(size); }
449inline void*
calloc(
size_t nmemb,
size_t size)
451 return SDL_calloc(nmemb, size);
492inline void*
realloc(
void* mem,
size_t size) {
return SDL_realloc(mem, size); }
512inline void free(
void* mem) { SDL_free(mem); }
615 SDL_GetOriginalMemoryFunctions(
702 return SDL_aligned_alloc(alignment, size);
798 return SDL_GetEnvironmentVariable(
get(), name);
861 CheckError(SDL_SetEnvironmentVariable(
get(), name, value, overwrite));
941 void reset(SDL_Environment* newResource = {})
943 SDL_DestroyEnvironment(
release(newResource));
967 constexpr Environment(
const Environment& other) =
delete;
1046 return SDL_getenv_unsafe(name);
1067 return SDL_setenv_unsafe(name, value, overwrite);
1085 return SDL_unsetenv_unsafe(name);
1153 SDL_qsort(base, nmemb, size, compare);
1211 return SDL_bsearch(key, base, nmemb, size, compare);
1246using CompareCB = std::function<int(
const void*,
const void*)>;
1306 SDL_qsort_r(base, nmemb, size, compare, userdata);
1366 [](
void* userdata,
const void* a,
const void* b) {
1367 auto& cb = *
static_cast<CompareCB*
>(userdata);
1437 return SDL_bsearch_r(key, base, nmemb, size, compare, userdata);
1507 [](
void* userdata,
const void* a,
const void* b) {
1508 auto& cb = *
static_cast<CompareCB*
>(userdata);
1524inline int abs(
int x) {
return SDL_abs(x); }
1542inline double abs(
double x) {
return SDL_fabs(x); }
1560inline float abs(
float x) {
return SDL_fabsf(x); }
1578template<
class T,
class U>
1581 return SDL_min(x, y);
1600template<
class T,
class U>
1603 return SDL_max(x, y);
1628template<
class T,
class U,
class V>
1631 return SDL_clamp(x, a, b);
1647inline int isalpha(
int x) {
return SDL_isalpha(x); }
1662inline int isalnum(
int x) {
return SDL_isalnum(x); }
1677inline int isblank(
int x) {
return SDL_isblank(x); }
1692inline int iscntrl(
int x) {
return SDL_iscntrl(x); }
1707inline int isdigit(
int x) {
return SDL_isdigit(x); }
1740inline int ispunct(
int x) {
return SDL_ispunct(x); }
1762inline int isspace(
int x) {
return SDL_isspace(x); }
1777inline int isupper(
int x) {
return SDL_isupper(x); }
1792inline int islower(
int x) {
return SDL_islower(x); }
1811inline int isprint(
int x) {
return SDL_isprint(x); }
1832inline int isgraph(
int x) {
return SDL_isgraph(x); }
1850inline int toupper(
int x) {
return SDL_toupper(x); }
1868inline int tolower(
int x) {
return SDL_tolower(x); }
1889inline Uint16
crc16(Uint16 crc,
const void* data,
size_t len)
1891 return SDL_crc16(crc, data, len);
1913inline Uint32
crc32(Uint32 crc,
const void* data,
size_t len)
1915 return SDL_crc32(crc, data, len);
1942inline Uint32
murmur3_32(
const void* data,
size_t len, Uint32 seed)
1944 return SDL_murmur3_32(data, len, seed);
1965inline void*
memcpy(
void* dst,
const void* src,
size_t len)
1967#ifdef SDL_SLOW_MEMCPY
1968 return SDL_memcpy(dst, src, len);
1970 return ::memcpy(dst, src, len);
2000#define SDL_copyp(dst, src) \
2002 SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof(*(dst)) == sizeof(*(src))); \
2004 SDL_memcpy((dst), (src), sizeof(*(src)))
2025inline void*
memmove(
void* dst,
const void* src,
size_t len)
2027#ifdef SDL_SLOW_MEMMOVE
2028 return SDL_memmove(dst, src, len);
2030 return ::memmove(dst, src, len);
2052inline void*
memset(
void* dst,
int c,
size_t len)
2054#ifdef SDL_SLOW_MEMSET
2055 return SDL_memset(dst, c, len);
2057 return ::memset(dst, c, len);
2079inline void*
memset4(
void* dst, Uint32 val,
size_t dwords)
2081 return SDL_memset4(dst, val, dwords);
2147template<
class T, std::
size_t N>
2167inline int memcmp(
const void* s1,
const void* s2,
size_t len)
2169 return SDL_memcmp(s1, s2, len);
2197inline size_t wcslen(
const wchar_t* wstr) {
return SDL_wcslen(wstr); }
2228inline size_t wcsnlen(
const wchar_t* wstr,
size_t maxlen)
2230 return SDL_wcsnlen(wstr, maxlen);
2258inline size_t wcslcpy(
wchar_t* dst,
const wchar_t* src,
size_t maxlen)
2260 return SDL_wcslcpy(dst, src, maxlen);
2290inline size_t wcslcat(
wchar_t* dst,
const wchar_t* src,
size_t maxlen)
2292 return SDL_wcslcat(dst, src, maxlen);
2311inline wchar_t*
wcsdup(
const wchar_t* wstr) {
return SDL_wcsdup(wstr); }
2331inline wchar_t*
wcsstr(
const wchar_t* haystack,
const wchar_t* needle)
2333 return SDL_wcsstr(haystack, needle);
2360 const wchar_t* needle,
2363 return SDL_wcsnstr(haystack, needle, maxlen);
2383inline int wcscmp(
const wchar_t* str1,
const wchar_t* str2)
2385 return SDL_wcscmp(str1, str2);
2417inline int wcsncmp(
const wchar_t* str1,
const wchar_t* str2,
size_t maxlen)
2419 return SDL_wcsncmp(str1, str2, maxlen);
2452 return SDL_wcscasecmp(str1, str2);
2495inline int wcsncasecmp(
const wchar_t* str1,
const wchar_t* str2,
size_t maxlen)
2497 return SDL_wcsncasecmp(str1, str2, maxlen);
2525inline long wcstol(
const wchar_t* str,
wchar_t** endp,
int base)
2527 return SDL_wcstol(str, endp, base);
2574 return SDL_strnlen(str, maxlen);
2606 return SDL_strlcpy(dst, src, maxlen);
2637 return SDL_utf8strlcpy(dst, src, dst_bytes);
2668 return SDL_strlcat(dst, src, maxlen);
2714 return SDL_strndup(str, maxlen);
2736inline char*
strrev(
char* str) {
return SDL_strrev(str); }
2757inline char*
strupr(
char* str) {
return SDL_strupr(str); }
2778inline char*
strlwr(
char* str) {
return SDL_strlwr(str); }
2839 return SDL_strstr(haystack, needle);
2865 return SDL_strnstr(haystack, needle, maxlen);
2896 return SDL_strcasestr(haystack, needle);
2928 return SDL_strtok_r(str, delim, saveptr);
2992 return SDL_utf8strnlen(str, bytes);
3021inline char*
itoa(
int value,
char* str,
int radix)
3023 return SDL_itoa(value, str, radix);
3052inline char*
uitoa(
unsigned int value,
char* str,
int radix)
3054 return SDL_uitoa(value, str, radix);
3083inline char*
ltoa(
long value,
char* str,
int radix)
3085 return SDL_ltoa(value, str, radix);
3114inline char*
ultoa(
unsigned long value,
char* str,
int radix)
3116 return SDL_ultoa(value, str, radix);
3198 return SDL_strtol(str, endp, base);
3234 return SDL_strtoul(str, endp, base);
3266 return SDL_strtod(str, endp);
3289 return SDL_strcmp(str1, str2);
3322 return SDL_strncmp(str1, str2, maxlen);
3353 return SDL_strcasecmp(str1, str2);
3395 return SDL_strncasecmp(str1, str2, maxlen);
3416 return SDL_strpbrk(str, breakset);
3477inline Uint32
StepUTF8(
const char** pstr,
size_t* pslen)
3479 return SDL_StepUTF8(pstr, pslen);
3513 return SDL_StepBackUTF8(start, pstr);
3545 return SDL_UCS4ToUTF8(codepoint, dst);
3564 SDL_SCANF_FORMAT_STRING
const char* fmt,
3570 rc = SDL_vsscanf(text, fmt, ap);
3593 SDL_SCANF_FORMAT_STRING
const char* fmt,
3596 return SDL_vsscanf(text, fmt, ap);
3632 SDL_PRINTF_FORMAT_STRING
const char* fmt,
3639 result = SDL_vsnprintf(text, maxlen, fmt, ap);
3679 SDL_PRINTF_FORMAT_STRING
const wchar_t* fmt,
3686 result = SDL_vswprintf(text, maxlen, fmt, ap);
3712 SDL_PRINTF_FORMAT_STRING
const char* fmt,
3715 return SDL_vsnprintf(text, maxlen, fmt, ap);
3739 SDL_PRINTF_FORMAT_STRING
const wchar_t* fmt,
3742 return SDL_vswprintf(text, maxlen, fmt, ap);
3772inline int asprintf(
char** strp, SDL_PRINTF_FORMAT_STRING
const char* fmt, ...)
3778 result = SDL_vasprintf(strp, fmt, ap);
3802 SDL_PRINTF_FORMAT_STRING
const char* fmt,
3805 return SDL_vasprintf(strp, fmt, ap);
3826inline void srand(Uint64 seed) { SDL_srand(seed); }
3860inline Sint32
rand(Sint32 n) {
return SDL_rand(n); }
3882inline float randf() {
return SDL_randf(); }
3931 constexpr operator Uint64() {
return m_state; }
3964 Sint32
rand(Sint32 n) {
return SDL_rand_r(&m_state, n); }
3989 float randf() {
return SDL_randf_r(&m_state); }
4057inline double acos(
double x) {
return SDL_acos(x); }
4083inline float acos(
float x) {
return SDL_acosf(x); }
4109inline double asin(
double x) {
return SDL_asin(x); }
4138inline float asin(
float x) {
return SDL_asinf(x); }
4166inline double atan(
double x) {
return SDL_atan(x); }
4193inline float atan(
float x) {
return SDL_atanf(x); }
4226inline double atan2(
double y,
double x) {
return SDL_atan2(y, x); }
4259inline float atan2(
float y,
float x) {
return SDL_atan2f(y, x); }
4283inline double ceil(
double x) {
return SDL_ceil(x); }
4307inline float ceil(
float x) {
return SDL_ceilf(x); }
4329inline double copysign(
double x,
double y) {
return SDL_copysign(x, y); }
4351inline float copysign(
float x,
float y) {
return SDL_copysignf(x, y); }
4375inline double cos(
double x) {
return SDL_cos(x); }
4399inline float cos(
float x) {
return SDL_cosf(x); }
4427inline double exp(
double x) {
return SDL_exp(x); }
4455inline float exp(
float x) {
return SDL_expf(x); }
4479inline double floor(
double x) {
return SDL_floor(x); }
4503inline float floor(
float x) {
return SDL_floorf(x); }
4528inline double trunc(
double x) {
return SDL_trunc(x); }
4553inline float trunc(
float x) {
return SDL_truncf(x); }
4579inline double fmod(
double x,
double y) {
return SDL_fmod(x, y); }
4605inline float fmod(
float x,
float y) {
return SDL_fmodf(x, y); }
4617inline int isinf(
double x) {
return SDL_isinf(x); }
4629inline int isinf(
float x) {
return SDL_isinff(x); }
4641inline int isnan(
double x) {
return SDL_isnan(x); }
4653inline int isnan(
float x) {
return SDL_isnanf(x); }
4679inline double log(
double x) {
return SDL_log(x); }
4705inline float log(
float x) {
return SDL_logf(x); }
4731inline double log10(
double x) {
return SDL_log10(x); }
4757inline float log10(
float x) {
return SDL_log10f(x); }
4773inline double modf(
double x,
double* y) {
return SDL_modf(x, y); }
4789inline float modf(
float x,
float* y) {
return SDL_modff(x, y); }
4817inline double pow(
double x,
double y) {
return SDL_pow(x, y); }
4845inline float pow(
float x,
float y) {
return SDL_powf(x, y); }
4869inline double round(
double x) {
return SDL_round(x); }
4893inline float round(
float x) {
return SDL_roundf(x); }
4917inline long lround(
double x) {
return SDL_lround(x); }
4941inline long lround(
float x) {
return SDL_lroundf(x); }
4962inline double scalbn(
double x,
int n) {
return SDL_scalbn(x, n); }
4983inline float scalbn(
float x,
int n) {
return SDL_scalbnf(x, n); }
5007inline double sin(
double x) {
return SDL_sin(x); }
5031inline float sin(
float x) {
return SDL_sinf(x); }
5052inline double sqrt(
double x) {
return SDL_sqrt(x); }
5073inline float sqrt(
float x) {
return SDL_sqrtf(x); }
5099inline double tan(
double x) {
return SDL_tan(x); }
5128inline float tan(
float x) {
return SDL_tanf(x); }
5160 :
Resource(SDL_iconv_open(tocode, fromcode))
5198 size_t* inbytesleft,
5200 size_t* outbytesleft)
5202 return SDL_iconv(
get(), inbuf, inbytesleft, outbuf, outbytesleft);
5259 int reset(SDL_iconv_data_t* newResource = {})
5261 return SDL_iconv_close(
release(newResource));
5280 constexpr explicit IConv(SDL_iconv_data_t* resource = {})
5285 constexpr IConv(
const IConv& other) =
delete;
5312#define SDL_ICONV_ERROR (size_t)-1
5317#define SDL_ICONV_E2BIG (size_t)-2
5322#define SDL_ICONV_EILSEQ (size_t)-3
5327#define SDL_ICONV_EINVAL (size_t)-4
5357 return OwnPtr<char>{SDL_iconv_string(tocode, fromcode, inbuf, inbytesleft)};
5374#define SDL_iconv_utf8_locale(S) \
5375 SDL_iconv_string("", "UTF-8", S, SDL_strlen(S) + 1)
5389#define SDL_iconv_utf8_ucs2(S) \
5390 (Uint16*)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S) + 1)
5404#define SDL_iconv_utf8_ucs4(S) \
5405 (Uint32*)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S) + 1)
5419#define SDL_iconv_wchar_utf8(S) \
5421 "UTF-8", "WCHAR_T", (char*)S, (SDL_wcslen(S) + 1) * sizeof(wchar_t))
5444 return SDL_size_mul_check_overflow(a, b, ret);
5466 return SDL_size_add_check_overflow(a, b, ret);
5489inline void PtrDeleter::operator()(
void* ptr)
const { SDL_free(ptr); }
5491#pragma endregion impl
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