From bfda589b2c04a0bb3d29b2722c312f738639e8c4 Mon Sep 17 00:00:00 2001 From: doyle Date: Wed, 12 Oct 2022 19:17:51 +1100 Subject: [PATCH] dqn: Change convention to __ for consistency --- build.bat | 2 +- dqn.h | 3205 ++++++++++++++++++++--------------------- dqn_keccak.h | 2 +- dqn_tests.cpp | 618 ++++---- dqn_tests_helpers.cpp | 21 +- 5 files changed, 1910 insertions(+), 1938 deletions(-) diff --git a/build.bat b/build.bat index 0a0efe0..b6ed166 100644 --- a/build.bat +++ b/build.bat @@ -16,7 +16,7 @@ pushd Build REM Tp Treat header file as CPP source file set compile_flags=-MT -EHa -GR- -Od -Oi -Z7 -wd4201 -D DQN_TEST_WITH_MAIN -nologo set linker_flags=-link -nologo - set msvc_flags=-fsanitize=address -D STBSP__ASAN=__declspec(no_sanitize_address) + set msvc_flags= set clang_flags=-fsanitize=address -fsanitize=undefined REM Compiler: MSVC cl diff --git a/dqn.h b/dqn.h index 9165cf4..a97a8ce 100644 --- a/dqn.h +++ b/dqn.h @@ -13,11 +13,11 @@ // #define DQN_WITH_DSMAP // Dqn_DSMap // #define DQN_WITH_FIXED_ARRAY // Dqn_FixedArray // #define DQN_WITH_FIXED_STRING // Dqn_FixedString -// #define DQN_WITH_HEX // Dqn_Hex and friends ... -// #define DQN_WITH_JSON_WRITER // Dqn_JSONWriter +// #define DQN_WITH_HEX // Dqn_Hex_ and friends ... +// #define DQN_WITH_JSON_WRITER // Dqn_JSONWriter_ // #define DQN_WITH_MAP // Dqn_Map // #define DQN_WITH_MATH // Dqn_V2/3/4/Mat4 and friends ... -// #define DQN_WITH_WIN_NET // Dqn_WinNet +// #define DQN_WITH_WIN_NET // Dqn_Win_Net // // NOTE: Configuration // ----------------------------------------------------------------------------- @@ -53,8 +53,8 @@ // When defined to 1, some allocating calls in the library will automatically // get passed in the file name, function name, line number and an optional tag. // -// For data structures that have a 'Dqn_AllocationTracer' member, the caller -// can set the 'Dqn_AllocationTracer' to log allocations every time they are +// For data structures that have a 'Dqn_AllocationTracer_' member, the caller +// can set the 'Dqn_AllocationTracer_' to log allocations every time they are // made in the data structure. // // 'Tagged' variants of functions accept as the last parameter, a 'tag' that is @@ -64,7 +64,7 @@ // #define DQN_DEBUG_THREAD_CONTEXT // Define this macro to record allocation stats for arenas used in the // thread context. The thread context arena stats can be printed by using -// Dqn_LibDumpThreadContextArenaStat. +// Dqn_Lib_DumpThreadContextArenaStat. // // NOTE: Compiler // ------------------------------------------------------------------------------------------------- @@ -99,10 +99,11 @@ #include // va_list #include // fprintf, FILE, stdout, stderr +#include // [u]int_*, ... +#include // [U]INT_MAX, ... // NOTE: Macros // ------------------------------------------------------------------------------------------------- -#include #if !defined(DQN_CALLOC) #include @@ -182,7 +183,7 @@ b = temp; \ } while (0) -// NOTE: Prefer the templated Dqn_Array/CharCount function for type-safety. I prefer +// NOTE: Prefer the templated Dqn_Array/CString8ArrayCount function for type-safety. I prefer // the macro version for embedding within macros for debuggers. When we step // into a function call using the macro like, DQN_STRING8("...") which is very // common, the debugger jumps into the templated functions which is a waste of @@ -250,11 +251,10 @@ // NOTE: Assert Macro // ------------------------------------------------------------------------------------------------ #define DQN_HARD_ASSERT(expr) DQN_HARD_ASSERT_MSG(expr, "") -#define DQN_HARD_ASSERT_MSG(expr, fmt, ...) \ - if (!(expr)) \ - { \ - DQN_LOG_E("Assert: [" #expr "] " fmt, ##__VA_ARGS__); \ - DQN_DEBUG_BREAK; \ +#define DQN_HARD_ASSERT_MSG(expr, fmt, ...) \ + if (!(expr)) { \ + DQN_LOG_E("Assert: [" #expr "] " fmt, ##__VA_ARGS__); \ + DQN_DEBUG_BREAK; \ } #if defined(__cplusplus__) @@ -279,72 +279,17 @@ // NOTE: Typedefs // ------------------------------------------------------------------------------------------------ -// Use compiler builtins and define our own constants to avoid a dependency on stdint.h - -typedef double Dqn_f64; +typedef intptr_t Dqn_isize; +typedef uintptr_t Dqn_usize; +typedef intptr_t Dqn_isize; typedef float Dqn_f32; -typedef signed char Dqn_i8; -typedef unsigned char Dqn_u8; -typedef signed short Dqn_i16; -typedef unsigned short Dqn_u16; -typedef signed int Dqn_i32; -typedef unsigned int Dqn_u32; +typedef double Dqn_f64; typedef unsigned int Dqn_uint; -#if defined(DQN_COMPILER_W32_MSVC) || defined(DQN_COMPILER_W32_CLANG) -typedef signed __int64 Dqn_i64; -typedef unsigned __int64 Dqn_u64; -#else -typedef signed long long Dqn_i64; -typedef unsigned long long Dqn_u64; -#endif -typedef Dqn_i32 Dqn_b32; -typedef Dqn_i8 Dqn_b8; +typedef int32_t Dqn_b32; -#if defined(__ppc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) - typedef Dqn_u64 Dqn_uintptr; - typedef Dqn_i64 Dqn_intptr; - typedef Dqn_u64 Dqn_usize; - typedef Dqn_i64 Dqn_isize; -#else - typedef Dqn_u32 Dqn_uintptr; - typedef Dqn_i32 Dqn_intptr; - typedef Dqn_u32 Dqn_usize; - typedef Dqn_i32 Dqn_isize; -#endif +#define DQN_USIZE_MAX UINTPTR_MAX +#define DQN_ISIZE_MAX INTPTR_MAX -Dqn_f32 const DQN_F32_MAX = 3.402823466e+38F; -Dqn_f64 const DQN_F64_MAX = 1.7976931348623158e+308; - -Dqn_i8 const DQN_I8_MAX = 127; -Dqn_i8 const DQN_I8_MIN = -DQN_I8_MAX - 1; -Dqn_i16 const DQN_I16_MAX = 32767; -Dqn_i16 const DQN_I16_MIN = -DQN_I16_MAX - 1; -Dqn_i32 const DQN_I32_MAX = 2147483647; -Dqn_i32 const DQN_I32_MIN = -DQN_I32_MAX - 1; -Dqn_i64 const DQN_I64_MAX = 9223372036854775807; -Dqn_i64 const DQN_I64_MIN = -DQN_I64_MAX - 1; - -Dqn_u8 const DQN_U8_MAX = 255; -Dqn_u16 const DQN_U16_MAX = 65535; -Dqn_u32 const DQN_U32_MAX = 4294967295; -Dqn_u64 const DQN_U64_MAX = 18446744073709551615ULL; - -#if defined(__ppc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) -typedef Dqn_u64 Dqn_usize; -typedef Dqn_i64 Dqn_isize; -Dqn_isize const DQN_ISIZE_MAX = DQN_I64_MAX; -Dqn_usize const DQN_USIZE_MAX = DQN_U64_MAX; -#else -typedef Dqn_u32 Dqn_usize; -typedef Dqn_i32 Dqn_isize; -Dqn_isize const DQN_ISIZE_MAX = DQN_I32_MAX; -Dqn_usize const DQN_USIZE_MAX = DQN_U32_MAX; -#endif - -static_assert(sizeof(int) == sizeof(Dqn_i32), "Sanity check int typedef is correct"); -static_assert(sizeof(void *) == sizeof(Dqn_usize), "Require: Pointer can be held in usize (size_t)"); -static_assert(sizeof(Dqn_u64) == 8, "Sanity check u64 is 8 bytes"); -static_assert(sizeof(Dqn_f64) == 8, "Sanity check f64 is 8 bytes"); // NOTE: Win32 Minimal Header // ------------------------------------------------------------------------------------------------ @@ -369,20 +314,11 @@ static_assert(sizeof(Dqn_f64) == 8, "Sanity check f64 is 8 bytes unsigned long LowPart; long HighPart; } u; - Dqn_i64 QuadPart; + uint64_t QuadPart; } LARGE_INTEGER; #endif // !defined(DQN_NO_WIN32_MINIMAL_HEADER) #endif // !defined(DQN_OS_WIN32) -// NOTE: Compile Time Utilities -// ------------------------------------------------------------------------------------------------ -template constexpr Dqn_usize Dqn_ArrayCount (T const (&)[N]) { return N; } -template constexpr Dqn_isize Dqn_ArrayCountI (T const (&)[N]) { return N; } -template constexpr Dqn_isize Dqn_ArrayCountInt(T const (&)[N]) { return N; } -template constexpr Dqn_usize Dqn_CharCount (char const (&)[N]) { return N - 1; } -template constexpr Dqn_isize Dqn_CharCountI (char const (&)[N]) { return N - 1; } -template constexpr Dqn_isize Dqn_CharCountInt (char const (&)[N]) { return N - 1; } - // NOTE: Defer Macro // ------------------------------------------------------------------------------------------------ /* @@ -433,24 +369,24 @@ typedef enum Dqn_ZeroMem { // NOTE: Intrinsics // ------------------------------------------------------------------------------------------------- -// NOTE: Dqn_AtomicAdd/Exchange return the previous value store in the target +// NOTE: Dqn_Atomic_Add/Exchange return the previous value store in the target #if defined(DQN_COMPILER_W32_MSVC) || defined(DQN_COMPILER_W32_CLANG) #include - #define Dqn_AtomicAddU32(target, value) _InterlockedExchangeAdd(DQN_CAST(long volatile *)target, value) - #define Dqn_AtomicAddU64(target, value) _InterlockedExchangeAdd64(DQN_CAST(__int64 volatile *)target, value) - #define Dqn_AtomicSubU32(target, value) DQN_CAST(unsigned)Dqn_AtomicAddU32(DQN_CAST(long volatile *)target, -DQN_CAST(long)value) - #define Dqn_AtomicSubU64(target, value) DQN_CAST(Dqn_u64)Dqn_AtomicAddU64(target, -DQN_CAST(Dqn_i64)value) - #define Dqn_AtomicCompareExchange64(dest, desired_val, prev_val) _InterlockedCompareExchange64(DQN_CAST(__int64 volatile *)dest, desired_val, prev_val) - #define Dqn_AtomicCompareExchange32(dest, desired_val, prev_val) _InterlockedCompareExchange(DQN_CAST(long volatile *)dest, desired_val, prev_val) + #define Dqn_Atomic_AddU32(target, value) _InterlockedExchangeAdd(DQN_CAST(long volatile *)target, value) + #define Dqn_Atomic_AddU64(target, value) _InterlockedExchangeAdd64(DQN_CAST(__int64 volatile *)target, value) + #define Dqn_Atomic_SubU32(target, value) DQN_CAST(unsigned)Dqn_Atomic_AddU32(DQN_CAST(long volatile *)target, -DQN_CAST(long)value) + #define Dqn_Atomic_SubU64(target, value) DQN_CAST(uint64_t)Dqn_Atomic_AddU64(target, -DQN_CAST(uint64_t)value) + #define Dqn_Atomic_CompareExchange64(dest, desired_val, prev_val) _InterlockedCompareExchange64(DQN_CAST(__int64 volatile *)dest, desired_val, prev_val) + #define Dqn_Atomic_CompareExchange32(dest, desired_val, prev_val) _InterlockedCompareExchange(DQN_CAST(long volatile *)dest, desired_val, prev_val) #define Dqn_CPUClockCycle() __rdtsc() #define Dqn_CompilerReadBarrierAndCPUReadFence _ReadBarrier(); _mm_lfence() #define Dqn_CompilerWriteBarrierAndCPUWriteFence _WriteBarrier(); _mm_sfence() #elif defined(DQN_COMPILER_GCC) || defined(DQN_COMPILER_CLANG) #include - #define Dqn_AtomicAddU32(target, value) __atomic_fetch_add(target, value, __ATOMIC_ACQ_REL) - #define Dqn_AtomicAddU64(target, value) __atomic_fetch_add(target, value, __ATOMIC_ACQ_REL) - #define Dqn_AtomicSubU32(target, value) __atomic_fetch_sub(target, value, __ATOMIC_ACQ_REL) - #define Dqn_AtomicSubU64(target, value) __atomic_fetch_sub(target, value, __ATOMIC_ACQ_REL) + #define Dqn_Atomic_AddU32(target, value) __atomic_fetch_add(target, value, __ATOMIC_ACQ_REL) + #define Dqn_Atomic_AddU64(target, value) __atomic_fetch_add(target, value, __ATOMIC_ACQ_REL) + #define Dqn_Atomic_SubU32(target, value) __atomic_fetch_sub(target, value, __ATOMIC_ACQ_REL) + #define Dqn_Atomic_SubU64(target, value) __atomic_fetch_sub(target, value, __ATOMIC_ACQ_REL) #if defined(DQN_COMPILER_GCC) #define Dqn_CPUClockCycle() __rdtsc() #else @@ -467,16 +403,16 @@ typedef enum Dqn_ZeroMem { /// @param[in,out] target The target pointer to set atomically /// @param[in] value The value to set atomically into the target /// @return The value that was last stored in the target -inline Dqn_i64 Dqn_AtomicSetValue64(Dqn_i64 volatile *target, Dqn_i64 value) +inline uint64_t Dqn_Atomic_SetValue64(uint64_t volatile *target, uint64_t value) { #if defined(DQN_COMPILER_W32_MSVC) || defined(DQN_COMPILER_W32_CLANG) - Dqn_i64 result; + uint64_t result; do { result = *target; - } while (Dqn_AtomicCompareExchange64(target, value, result) != result); + } while (Dqn_Atomic_CompareExchange64(target, value, result) != result); return result; #elif defined(DQN_COMPILER_GCC) || defined(DQN_COMPILER_CLANG) - Dqn_i64 result = __sync_lock_test_and_set(target, value); + uint64_t result = __sync_lock_test_and_set(target, value); return result; #else #error Unsupported compiler @@ -488,13 +424,13 @@ inline Dqn_i64 Dqn_AtomicSetValue64(Dqn_i64 volatile *target, Dqn_i64 value) /// @param[in,out] target The target pointer to set atomically /// @param[in] value The value to set atomically into the target /// @return The value that was last stored in the target -inline long Dqn_AtomicSetValue32(long volatile *target, long value) +inline long Dqn_Atomic_SetValue32(long volatile *target, long value) { #if defined(DQN_COMPILER_W32_MSVC) || defined(DQN_COMPILER_W32_CLANG) long result; do { result = *target; - } while (Dqn_AtomicCompareExchange32(target, value, result) != result); + } while (Dqn_Atomic_CompareExchange32(target, value, result) != result); return result; #elif defined(DQN_COMPILER_GCC) || defined(DQN_COMPILER_CLANG) long result = __sync_lock_test_and_set(target, value); @@ -506,7 +442,7 @@ inline long Dqn_AtomicSetValue32(long volatile *target, long value) struct Dqn_CPUIDRegisters { - unsigned int array[4]; ///< Values from 'CPUID' instruction for each register (EAX, EBX, ECX, EDX) + Dqn_uint array[4]; ///< Values from 'CPUID' instruction for each register (EAX, EBX, ECX, EDX) }; /// Execute 'CPUID' instruction to query the capabilities of the current CPU. @@ -532,30 +468,39 @@ struct Dqn_TicketMutex }; /// Lock the mutex -void Dqn_TicketMutexBegin(Dqn_TicketMutex *mutex); +void Dqn_TicketMutex_Begin(Dqn_TicketMutex *mutex); /// Unlock the mutex -void Dqn_TicketMutexEnd(Dqn_TicketMutex *mutex); +void Dqn_TicketMutex_End(Dqn_TicketMutex *mutex); /// Allocate the next available ticket from the mutex for locking using -/// Dqn_TicketMutexBeginTicket(). +/// Dqn_TicketMutex_BeginTicket(). /// /// @param[in] mutex The mutex /// /// @code /// Dqn_TicketMutex mutex = {}; -/// unsigned int ticket = Dqn_TicketMutexMakeTicket(&mutex); -/// Dqn_TicketMutexBeginTicket(&mutex, ticket); // Blocking call until we attain the lock -/// Dqn_TicketMutexEnd(&mutex); +/// unsigned int ticket = Dqn_TicketMutex_MakeTicket(&mutex); +/// Dqn_TicketMutex_BeginTicket(&mutex, ticket); // Blocking call until we attain the lock +/// Dqn_TicketMutex_End(&mutex); /// @endcode -unsigned int Dqn_TicketMutexMakeTicket(Dqn_TicketMutex *mutex); +Dqn_uint Dqn_TicketMutex_MakeTicket(Dqn_TicketMutex *mutex); /// Lock the mutex using the given ticket if possible, otherwise block /// waiting until the mutex can be locked. -void Dqn_TicketMutexBeginTicket(Dqn_TicketMutex const *mutex, unsigned int ticket); +void Dqn_TicketMutex_BeginTicket(Dqn_TicketMutex const *mutex, Dqn_uint ticket); /// Determine if the mutex can be locked using the given ticket number. -bool Dqn_TicketMutexCanLock(Dqn_TicketMutex const *mutex, unsigned int ticket); +bool Dqn_TicketMutex_CanLock(Dqn_TicketMutex const *mutex, Dqn_uint ticket); + +// NOTE: Dqn_CArray +// ------------------------------------------------------------------------------------------------ +/// Calculate the size of a C-array at compile time +/// @param array The C-array to calculate the size for +/// @return The size of the c-array buffer +template constexpr Dqn_usize Dqn_CArray_Count (T const (&array)[N]) { (void)array; return N; } +template constexpr Dqn_isize Dqn_CArray_CountI (T const (&array)[N]) { (void)array; return N; } +template constexpr Dqn_isize Dqn_CArray_CountInt(T const (&array)[N]) { (void)array; return N; } /// @cond NO_DOXYYGEN // NOTE: stb_sprintf @@ -784,43 +729,41 @@ STBSP__PUBLICDEC void STB_SPRINTF_DECORATE(set_separators)(char comma, char peri /// @param size The number of bytes to allocate /// @param zero_mem Flag to indicate if the allocated memory should be zero-ed out /// @param user_context The user assigned pointer in the allocator -typedef void *Dqn_AllocatorAllocProc(DQN_CALL_SITE_ARGS size_t size, uint8_t align, Dqn_ZeroMem zero_mem, void *user_context); +typedef void *Dqn_Allocator_AllocProc(DQN_CALL_SITE_ARGS size_t size, uint8_t align, Dqn_ZeroMem zero_mem, void *user_context); /// Deallocate memory /// @param ptr The pointer to deallocate memory for /// @param size The number of bytes to deallocate /// @param user_context The user assigned pointer in the allocator -typedef void Dqn_AllocatorDeallocProc(DQN_CALL_SITE_ARGS void *ptr, size_t size, void *user_context); +typedef void Dqn_Allocator_DeallocProc(DQN_CALL_SITE_ARGS void *ptr, size_t size, void *user_context); typedef struct Dqn_Allocator { void *user_context; ///< User assigned pointer that is passed into the allocator functions - Dqn_AllocatorAllocProc *alloc; ///< Memory allocating routine - Dqn_AllocatorDeallocProc *dealloc; ///< Memory deallocating routine + Dqn_Allocator_AllocProc *alloc; ///< Memory allocating routine + Dqn_Allocator_DeallocProc *dealloc; ///< Memory deallocating routine } Dqn_Allocator; /// Allocate bytes from the given allocator -/// @param allocator The allocator to allocate bytes from -/// @param size The amount of bytes to allocator -/// @param zero_mem Flag to indicate if the allocated must be zero-ed out -void *Dqn_AllocatorAlloc(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, size_t size, uint8_t align, Dqn_ZeroMem zero_mem); -void Dqn_AllocatorDealloc(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, void *ptr, size_t size); +/// @param[in] allocator The allocator to allocate bytes from +/// @param[in] size The amount of bytes to allocator +/// @param[in] zero_mem Flag to indicate if the allocated must be zero-ed out +void *Dqn_Allocator_Alloc(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, size_t size, uint8_t align, Dqn_ZeroMem zero_mem); -#define Dqn_AllocatorNewArray(allocator, Type, count, zero_mem) Dqn_AllocatorNewArrayTagged("", allocator, Type, count, zero_mem) -#define Dqn_AllocatorNewArrayTagged(tag, allocator, Type, count, zero_mem) (Type *)Dqn_AllocatorAlloc(DQN_CALL_SITE(tag) allocator, sizeof(Type) * count, alignof(Type), zero_mem) +/// Deallocate the memory from the pointer using the allocator +/// +/// The pointer must originally have been allocated from the passed in +/// allocator. The size must also match the size that was originally allocated. +/// +/// @param[in] allocator The allocator to allocate bytes from +/// @param[in] ptr The pointer to deallocate +/// @param[in] size The amount of bytes to deallocate. +void Dqn_Allocator_Dealloc(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, void *ptr, size_t size); -#define Dqn_AllocatorNew(allocator, Type, zero_mem) Dqn_AllocatorNewTagged(nullptr, allocator, Type, zero_mem) -#define Dqn_AllocatorNewTagged(tag, allocator, Type, zero_mem) Dqn_AllocatorNewArrayTagged(tag, allocator, Type, 1 /*count*/, zero_mem) +#define Dqn_Allocator_NewArray(allocator, Type, count, zero_mem) Dqn_Allocator_NewArrayTagged("", allocator, Type, count, zero_mem) +#define Dqn_Allocator_NewArrayTagged(tag, allocator, Type, count, zero_mem) (Type *)Dqn_Allocator_Alloc(DQN_CALL_SITE(tag) allocator, sizeof(Type) * count, alignof(Type), zero_mem) -// NOTE: Dqn_Fmt -// ------------------------------------------------------------------------------------------------- -// Utility functions for calculating the size of format strings. Uses stb_sprintf internally. -// return: The length of the format string without a null terminating byte, i.e. "hi" = 2 -DQN_API Dqn_isize Dqn_FmtVLenNoNullTerminator(char const *fmt, va_list args); -DQN_API Dqn_isize Dqn_FmtLenNoNullTerminator (char const *fmt, ...); - -// return: The length including 1 byte for the null terminating byte, i.e. "hi" = 3 -DQN_API Dqn_isize Dqn_FmtVLen (char const *fmt, va_list args); -DQN_API Dqn_isize Dqn_FmtLen (char const *fmt, ...); +#define Dqn_Allocator_New(allocator, Type, zero_mem) Dqn_Allocator_NewTagged(nullptr, allocator, Type, zero_mem) +#define Dqn_Allocator_NewTagged(tag, allocator, Type, zero_mem) Dqn_Allocator_NewArrayTagged(tag, allocator, Type, 1 /*count*/, zero_mem) // NOTE: Dqn_String8 // ------------------------------------------------------------------------------------------------- @@ -847,10 +790,10 @@ struct Dqn_String8 /// A pointer and length style string that holds slices to UT char *end () { return data + size; } ///< End iterator for range-for loops }; -typedef struct Dqn_String8Link { +struct Dqn_String8_Link { Dqn_String8 string; ///< The string - Dqn_String8Link *next; ///< The next string in the linked list -} Dqn_String8Link; + Dqn_String8_Link *next; ///< The next string in the linked list +}; struct Dqn_String16 /// A pointer and length style string that holds slices to UTF16 bytes. { @@ -864,20 +807,20 @@ struct Dqn_String16 /// A pointer and length style string that holds slices to U }; /// Initialise a string from a pointer and length -/// The string is invalid (i.e. Dqn_String8IsValid() returns false) if size is +/// The string is invalid (i.e. Dqn_String8_IsValid() returns false) if size is /// negative or the string is null. -DQN_API Dqn_String8 Dqn_String8Init(char const *string, Dqn_isize size); +DQN_API Dqn_String8 Dqn_String8_Init(char const *string, Dqn_isize size); /// Initialise a string from a cstring /// The cstring must be null-terminated as its length is evaluated using -/// strlen. The string is invalid (i.e. Dqn_String8IsValid() returns false) if +/// strlen. The string is invalid (i.e. Dqn_String8_IsValid() returns false) if /// size is negative or the string is null. -DQN_API Dqn_String8 Dqn_String8InitCString(char const *string); +DQN_API Dqn_String8 Dqn_String8_InitCString(char const *string); /// Determine if the values of the given string are valid /// A string is invalid if size is negative or the string is null. /// @return True if the string is valid, false otherwise. -DQN_API bool Dqn_String8IsValid(Dqn_String8 string); +DQN_API bool Dqn_String8_IsValid(Dqn_String8 string); /// Create a slice from a pre-existing string. /// The requested slice is clamped to within the bounds of the original string. @@ -885,115 +828,125 @@ DQN_API bool Dqn_String8IsValid(Dqn_String8 string); /// @param[in] offset The starting byte to slice from /// @param[in] size The size of the slice /// @return The sliced string -DQN_API Dqn_String8 Dqn_String8Slice(Dqn_String8 string, Dqn_isize offset, Dqn_isize size); +DQN_API Dqn_String8 Dqn_String8_Slice(Dqn_String8 string, Dqn_isize offset, Dqn_isize size); /// Create a string from a printf style format string /// @param[in] allocator The allocator the string will be allocated from /// @param[in] fmt The printf style format cstring -#define Dqn_String8Fmt(allocator, fmt, ...) Dqn_String8FmtTagged(nullptr, allocator, fmt, ## __VA_ARGS__) +#define Dqn_String8_Fmt(allocator, fmt, ...) Dqn_String8_FmtTagged(nullptr, allocator, fmt, ## __VA_ARGS__) -/// @copybrief Dqn_String8Fmt The tagged variant takes a cstring to describe the -/// purpose of the allocation. +/// @copybrief Dqn_String8_Fmt The tagged variant takes a cstring to describe +/// the purpose of the allocation. /// Tagged variants can be used to describe the nature of the allocation for /// allocation tracking purposes in the leak tracker or memory analytics. /// @param[in] tag A cstring to describe the nature of the allocation -/// @copydetails Dqn_String8Fmt -#define Dqn_String8FmtTagged(tag, allocator, fmt, ...) Dqn_String8Fmt_(DQN_CALL_SITE(tag) allocator, fmt, ## __VA_ARGS__) +/// @copydetails Dqn_String8_Fmt +#define Dqn_String8_FmtTagged(tag, allocator, fmt, ...) Dqn_String8_Fmt_(DQN_CALL_SITE(tag) allocator, fmt, ## __VA_ARGS__) -/// @copybrief Dqn_String8Fmt Internal function, prefer Dqn_String8Fmt() +/// @copybrief Dqn_String8_Fmt Internal function, prefer Dqn_String8_Fmt() /// @param[in] DQN_CALL_SITE_ARGS Call site macro that is compiled out if call /// site information is not enabled. Exposes call site information on /// allocation. -/// @copydetails Dqn_String8Fmt -DQN_API Dqn_String8 Dqn_String8Fmt_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, ...); +/// @copydetails Dqn_String8_Fmt +DQN_API Dqn_String8 Dqn_String8_Fmt_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, ...); /// Create a string from a printf style format string using a va_list /// @param[in] arena The allocator the string will be allocated from /// @param[in] fmt The printf style format cstring /// @param[in] va The variable argument list -#define Dqn_String8FmtV(allocator, fmt, va) Dqn_String8FmtVTagged(nullptr, allocator, fmt, va) +#define Dqn_String8_FmtV(allocator, fmt, va) Dqn_String8_FmtVTagged(nullptr, allocator, fmt, va) -/// @copybrief Dqn_String8FmtV The tagged variant takes a cstring to describe the +/// @copybrief Dqn_String8_FmtV The tagged variant takes a cstring to describe the /// purpose of the allocation. /// @param[in] tag A cstring to describe the nature of the allocation -/// @copydetails Dqn_String8FmtV -#define Dqn_String8FmtVTagged(tag, allocator, fmt, va) Dqn_String8FmtV_(DQN_CALL_SITE(tag) allocator, fmt, va) +/// @copydetails Dqn_String8_FmtV +#define Dqn_String8_FmtVTagged(tag, allocator, fmt, va) Dqn_String8_FmtV_(DQN_CALL_SITE(tag) allocator, fmt, va) -/// @copybrief Dqn_String8FmtV Internal function, prefer Dqn_String8FmtV() +/// @copybrief Dqn_String8_FmtV Internal function, prefer Dqn_String8_FmtV() /// @param[in] DQN_CALL_SITE_ARGS Call site macro that is compiled out if call /// site information is not enabled. Exposes call site information on /// allocation. -/// @copydetails Dqn_String8FmtV -DQN_API Dqn_String8 Dqn_String8FmtV_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, va_list va); +/// @copydetails Dqn_String8_FmtV +DQN_API Dqn_String8 Dqn_String8_FmtV_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, va_list va); + +/// Calculate the required size to format the given format string. +/// @param[in] fmt The format string to calculate the size for +/// @return The size required to format the string, not including the null +/// terminator. +DQN_API Dqn_isize Dqn_String8_FmtSize(char const *fmt, ...); + +/// @copybrief Dqn_String8_FmtSize +/// @param[in] args The variable argument list to use to format the string +DQN_API Dqn_isize Dqn_String8_FmtSizeV(char const *fmt, va_list args); /// Create an empty string with the requested size /// @param[in] allocator The allocator the string will be allocated from /// @param[in] size The size in bytes of the string to allocate /// @param[in] zero_mem Enum to indicate if the string's memory should be cleared -#define Dqn_String8Allocate(allocator, size, zero_mem) Dqn_String8AllocateTagged(nullptr, allocator, size, zero_mem) +#define Dqn_String8_Allocate(allocator, size, zero_mem) Dqn_String8_AllocateTagged(nullptr, allocator, size, zero_mem) -/// @copybrief Dqn_String8Allocate The tagged variant takes a cstring to +/// @copybrief Dqn_String8_Allocate The tagged variant takes a cstring to /// describe the purpose of the allocation. /// Tagged variants can be used to describe the nature of the allocation for /// allocation tracking purposes in the leak tracker or memory analytics. /// @param[in] tag A cstring to describe the nature of the allocation -/// @copydetails Dqn_String8Allocate -#define Dqn_String8AllocateTagged(tag, allocator, size, zero_mem) Dqn_String8Allocate_(DQN_CALL_SITE(tag) allocator, size, zero_mem) +/// @copydetails Dqn_String8_Allocate +#define Dqn_String8_AllocateTagged(tag, allocator, size, zero_mem) Dqn_String8_Allocate_(DQN_CALL_SITE(tag) allocator, size, zero_mem) -/// @copybrief Dqn_String8Allocate Internal function, prefer -/// Dqn_String8Allocate() +/// @copybrief Dqn_String8_Allocate Internal function, prefer +/// Dqn_String8_Allocate() /// @param[in] DQN_CALL_SITE_ARGS Call site macro that is compiled out if call /// site information is not enabled. Exposes call site information on /// allocation. -/// @copydetails Dqn_String8Allocate -DQN_API Dqn_String8 Dqn_String8Allocate_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, Dqn_isize size, Dqn_ZeroMem zero_mem); +/// @copydetails Dqn_String8_Allocate +DQN_API Dqn_String8 Dqn_String8_Allocate_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, Dqn_isize size, Dqn_ZeroMem zero_mem); /// Create a copy of the given cstring /// @param[in] allocator The allocator the string will be allocated from /// @param[in] string The cstring to copy /// @param[in] size The size of the cstring to copy. This cannot be <= 0 /// @return A copy of the string, invalid string if any argument was invalid. -#define Dqn_String8CopyCString(allocator, string, size) Dqn_String8CopyCStringTagged(nullptr, allocator, string, size) +#define Dqn_String8_CopyCString(allocator, string, size) Dqn_String8_CopyCStringTagged(nullptr, allocator, string, size) -/// @copybrief Dqn_String8CopyCString The tagged variant takes a cstring to +/// @copybrief Dqn_String8_CopyCString The tagged variant takes a cstring to /// describe the purpose of the allocation. /// Tagged variants can be used to describe the nature of the allocation for /// allocation tracking purposes in the leak tracker or memory analytics. /// @param[in] tag A cstring to describe the nature of the allocation -/// @copydetails Dqn_String8CopyCString -#define Dqn_String8CopyCStringTagged(tag, allocator, string, size) Dqn_String8CopyCString_(DQN_CALL_SITE(tag) allocator, string, size) +/// @copydetails Dqn_String8_CopyCString +#define Dqn_String8_CopyCStringTagged(tag, allocator, string, size) Dqn_String8_CopyCString_(DQN_CALL_SITE(tag) allocator, string, size) -/// @copybrief Dqn_String8CopyCString Internal function, prefer -/// Dqn_String8CopyCString() +/// @copybrief Dqn_String8_CopyCString Internal function, prefer +/// Dqn_String8_CopyCString() /// @param[in] DQN_CALL_SITE_ARGS Call site macro that is compiled out if call /// site information is not enabled. Exposes call site information on /// allocation. -/// @copydetails Dqn_String8CopyCString -DQN_API Dqn_String8 Dqn_String8CopyCString_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *string, Dqn_isize size); +/// @copydetails Dqn_String8_CopyCString +DQN_API Dqn_String8 Dqn_String8_CopyCString_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *string, Dqn_isize size); /// Create a copy of the given string /// @param[in] allocator The allocator the string will be allocated from /// @param[in] string The string to copy /// @return A copy of the string, invalid string if any argument was invalid. -#define Dqn_String8Copy(allocator, string) Dqn_String8CopyTagged(nullptr, allocator, string) +#define Dqn_String8_Copy(allocator, string) Dqn_String8_CopyTagged(nullptr, allocator, string) -/// @copybrief Dqn_String8Copy The tagged variant takes a cstring to +/// @copybrief Dqn_String8_Copy The tagged variant takes a cstring to /// describe the purpose of the allocation. /// Tagged variants can be used to describe the nature of the allocation for /// allocation tracking purposes in the leak tracker or memory analytics. /// @param[in] tag A cstring to describe the nature of the allocation -/// @copydetails Dqn_String8Copy -#define Dqn_String8CopyTagged(tag, allocator, string) Dqn_String8Copy_(DQN_CALL_SITE(tag) allocator, string) +/// @copydetails Dqn_String8_Copy +#define Dqn_String8_CopyTagged(tag, allocator, string) Dqn_String8_Copy_(DQN_CALL_SITE(tag) allocator, string) -/// @copybrief Dqn_String8Copy Internal function, prefer -/// Dqn_String8Copy() +/// @copybrief Dqn_String8_Copy Internal function, prefer +/// Dqn_String8_Copy() /// @param[in] DQN_CALL_SITE_ARGS Call site macro that is compiled out if call /// site information is not enabled. Exposes call site information on /// allocation. -/// @copydetails Dqn_String8Copy -DQN_API Dqn_String8 Dqn_String8Copy_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, Dqn_String8 string); +/// @copydetails Dqn_String8_Copy +DQN_API Dqn_String8 Dqn_String8_Copy_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, Dqn_String8 string); -enum struct Dqn_String8EqCase +enum struct Dqn_String8_EqCase { Sensitive, Insensitive, @@ -1004,12 +957,39 @@ enum struct Dqn_String8EqCase // @param[in] rhs The second string to compare equality with // @param[in] eq_case Set the comparison to be case sensitive or insensitive // @return True if the strings are equal, false otherwise. -DQN_API bool Dqn_String8Eq(Dqn_String8 lhs, Dqn_String8 rhs, Dqn_String8EqCase eq_case = Dqn_String8EqCase::Sensitive); -DQN_API bool Dqn_String8EqInsensitive(Dqn_String8 lhs, Dqn_String8 rhs); -DQN_API bool Dqn_String8StartsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8EqCase eq_case = Dqn_String8EqCase::Sensitive); -DQN_API bool Dqn_String8StartsWithInsensitive(Dqn_String8 string, Dqn_String8 prefix); -DQN_API bool Dqn_String8EndsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8EqCase eq_case = Dqn_String8EqCase::Sensitive); -DQN_API bool Dqn_String8EndsWithInsensitive(Dqn_String8 string, Dqn_String8 prefix); +DQN_API bool Dqn_String8_Eq(Dqn_String8 lhs, Dqn_String8 rhs, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); + +// Compare a string for equality, case insensitive +// @param[in] lhs The first string to compare equality with +// @param[in] rhs The second string to compare equality with +// @return True if the strings are equal, false otherwise. +DQN_API bool Dqn_String8_EqInsensitive(Dqn_String8 lhs, Dqn_String8 rhs); + +// Check if a string starts with the specified prefix +// @param[in] string The string to check for the prefix +// @param[in] prefix The prefix to check against the string +// @param[in] eq_case Set the comparison to be case sensitive or insensitive +// @return True if the string has the specified prefix, false otherwise +DQN_API bool Dqn_String8_StartsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); + +// Check if a string starts with the specified prefix, case insensitive +// @param[in] string The string to check for the prefix +// @param[in] prefix The prefix to check against the string +// @return True if the string has the specified prefix, false otherwise +DQN_API bool Dqn_String8_StartsWithInsensitive(Dqn_String8 string, Dqn_String8 prefix); + +// Check if a string ends with the specified suffix +// @param[in] string The string to check for the suffix +// @param[in] suffix The suffix to check against the string +// @param[in] eq_case Set the comparison to be case sensitive or insensitive +// @return True if the string has the specified suffix, false otherwise +DQN_API bool Dqn_String8_EndsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); + +// Check if a string ends with the specified suffix, case insensitive +// @param[in] string The string to check for the suffix +// @param[in] suffix The suffix to check against the string +// @return True if the string has the specified suffix, false otherwise +DQN_API bool Dqn_String8_EndsWithInsensitive(Dqn_String8 string, Dqn_String8 prefix); /// Split a string by the delimiting character. /// This function can evaluate the number of splits required in the return value @@ -1024,41 +1004,42 @@ DQN_API bool Dqn_String8EndsWithInsensitive(Dqn_String8 string, Dqn_String8 pref /// to the `splits` array. The number of splits written is capped to the /// capacity given by the caller, i.e. `splits_count`. This function should be /// called again with a sufficiently sized array if all splits are desired. -DQN_API Dqn_isize Dqn_String8Split(Dqn_String8 string, char delimiter, Dqn_String8 *splits, Dqn_isize splits_count); -DQN_API Dqn_String8 Dqn_String8TrimPrefix(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8EqCase eq_case = Dqn_String8EqCase::Sensitive); -DQN_API Dqn_String8 Dqn_String8TrimSuffix(Dqn_String8 string, Dqn_String8 suffix, Dqn_String8EqCase eq_case = Dqn_String8EqCase::Sensitive); -DQN_API Dqn_String8 Dqn_String8TrimWhitespaceAround(Dqn_String8 string); +DQN_API Dqn_isize Dqn_String8_Split(Dqn_String8 string, char delimiter, Dqn_String8 *splits, Dqn_isize splits_count); +DQN_API Dqn_String8 Dqn_String8_TrimPrefix(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); +DQN_API Dqn_String8 Dqn_String8_TrimSuffix(Dqn_String8 string, Dqn_String8 suffix, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); +DQN_API Dqn_String8 Dqn_String8_TrimWhitespaceAround(Dqn_String8 string); -// Trim UTF8, UTF16 BE/LE, UTF32 BE/LE byte order mark in the string. -DQN_API Dqn_String8 Dqn_String8TrimByteOrderMark(Dqn_String8 string); -DQN_API bool Dqn_String8IsAllDigits(Dqn_String8 string); -DQN_API bool Dqn_String8IsAllHex(Dqn_String8 string); -DQN_API bool Dqn_String8HasChar(Dqn_String8 string, char ch); +/// Trim UTF8, UTF16 BE/LE, UTF32 BE/LE byte order mark in the string. +DQN_API Dqn_String8 Dqn_String8_TrimByteOrderMark(Dqn_String8 string); +DQN_API bool Dqn_String8_IsAllDigits(Dqn_String8 string); +DQN_API bool Dqn_String8_IsAllHex(Dqn_String8 string); +DQN_API bool Dqn_String8_HasChar(Dqn_String8 string, char ch); -// Remove the substring denoted by the begin index and the size from the string -// string in-place using MEMMOVE to shift the string back. -DQN_API void Dqn_String8Remove(Dqn_String8 *string, Dqn_isize begin, Dqn_isize size); +/// Remove the substring denoted by the begin index and the size from the string +/// string in-place using MEMMOVE to shift the string back. +DQN_API void Dqn_String8_Remove(Dqn_String8 *string, Dqn_isize begin, Dqn_isize size); -// start_index: Set an index within the string string to start the search from, if not desired, set to 0 -// return: The index of the matching find, -1 if it is not found -DQN_API Dqn_isize Dqn_String8FindOffset(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8EqCase eq_case = Dqn_String8EqCase::Sensitive); +/// @param[in] start_index Set an index within the string string to start the +/// search from, if not desired, set to 0 +/// @return The index of the matching find, -1 if it is not found +DQN_API Dqn_isize Dqn_String8_FindOffset(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); -// start_index: Set an index within the string string to start the search from, if not desired, set to 0 -// return: A string that points to the matching find, otherwise a 0 length string. -DQN_API Dqn_String8 Dqn_String8Find(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8EqCase eq_case = Dqn_String8EqCase::Sensitive); -DQN_API Dqn_String8 Dqn_String8Replace(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Allocator allocator, Dqn_String8EqCase eq_case = Dqn_String8EqCase::Sensitive); -DQN_API Dqn_String8 Dqn_String8ReplaceInsensitive(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Allocator allocator); - -// @info Get the file name from a file path by searching from the end of the -// string backwards to the first occurring path separator '/' or '\'. If -// no path separator is found, the original string is returned. -// @in path: A file path on the disk -// @return The file name of the file path, if none is found, the path string -// is returned. -DQN_API Dqn_String8 Dqn_String8FileNameFromPath(Dqn_String8 path); -DQN_API Dqn_u64 Dqn_String8ToU64(Dqn_String8 string); -DQN_API Dqn_i64 Dqn_String8ToI64(Dqn_String8 string); +/// @param start_index Set an index within the string string to start the search +/// from, if not desired, set to 0 +/// @return A string that points to the matching find, otherwise a 0 length string. +DQN_API Dqn_String8 Dqn_String8_Find(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); +DQN_API Dqn_String8 Dqn_String8_Replace(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Allocator allocator, Dqn_String8_EqCase eq_case = Dqn_String8_EqCase::Sensitive); +DQN_API Dqn_String8 Dqn_String8_ReplaceInsensitive(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Allocator allocator); +/// Get the file name from a file path by searching from the end of the string +/// backwards to the first occurring path separator '/' or '\'. If no path +/// separator is found, the original string is returned. +/// @param[in] path A file path on the disk +/// @return The file name of the file path, if none is found, the path string is +/// returned. +DQN_API Dqn_String8 Dqn_String8_FileNameFromPath(Dqn_String8 path); +DQN_API uint64_t Dqn_String8_ToU64(Dqn_String8 string); +DQN_API uint64_t Dqn_String8_ToI64(Dqn_String8 string); // NOTE: Dqn_Log // ------------------------------------------------------------------------------------------------- @@ -1077,7 +1058,7 @@ enum struct Dqn_LogType #undef X_ENTRY }; -inline Dqn_String8 Dqn_LogTypeString8(Dqn_LogType type) +inline Dqn_String8 Dqn_Log_TypeString8(Dqn_LogType type) { switch (type) { #define X_ENTRY(enum_val, string) case Dqn_LogType::enum_val: return DQN_STRING8(string); @@ -1113,14 +1094,14 @@ DQN_API void Dqn_LogVDefault(Dqn_LogType type, void *user_data, Dqn_String8 file DQN_API void Dqn_LogV(Dqn_LogType type, void *user_data, Dqn_String8 file, Dqn_String8 func, Dqn_uint line, char const *fmt, va_list va); DQN_API void Dqn_Log(Dqn_LogType type, void *user_data, Dqn_String8 file, Dqn_String8 func, Dqn_uint line, char const *fmt, ...); -// NOTE: Dqn_Virtual +// NOTE: Dqn_VirtualMem_ // ------------------------------------------------------------------------------------------------- -DQN_API void *Dqn_VirtualReserve(Dqn_usize size, bool commit); -DQN_API bool Dqn_VirtualCommit(void *ptr, Dqn_usize size); -DQN_API void Dqn_VirtualDecommit(void *ptr, Dqn_usize size); -DQN_API void Dqn_VirtualRelease(void *ptr, Dqn_usize size); +DQN_API void *Dqn_VirtualMem_Reserve(Dqn_usize size, bool commit); +DQN_API bool Dqn_VirtualMem_Commit(void *ptr, Dqn_usize size); +DQN_API void Dqn_VirtualMem_Decommit(void *ptr, Dqn_usize size); +DQN_API void Dqn_VirtualMem_Release(void *ptr, Dqn_usize size); -// NOTE: Dqn_AllocationTracer +// NOTE: Dqn_AllocationTracer_ // ------------------------------------------------------------------------------------------------- struct Dqn_AllocationTrace { @@ -1132,27 +1113,28 @@ struct Dqn_AllocationTrace char const *msg; }; -struct Dqn_AllocationTracer +struct Dqn_AllocationTracer_ { // NOTE: Read only fields Dqn_TicketMutex mutex; // Dqn_Map map; }; -void Dqn_AllocationTracerAdd (Dqn_AllocationTracer *tracer, void *ptr, Dqn_usize size DQN_CALL_SITE_ARGS); -void Dqn_AllocationTracerRemove(Dqn_AllocationTracer *tracer, void *ptr); +void Dqn_AllocationTracer_Add (Dqn_AllocationTracer *tracer, void *ptr, Dqn_usize size DQN_CALL_SITE_ARGS); +void Dqn_AllocationTracer_Remove(Dqn_AllocationTracer *tracer, void *ptr); // NOTE: Dqn_Arena // ------------------------------------------------------------------------------------------------- Dqn_isize const DQN_ARENA_MIN_BLOCK_SIZE = DQN_KILOBYTES(4); -struct Dqn_ArenaBlock + +struct Dqn_Arena_Block { - void *memory; // The backing memory of the block - Dqn_isize size; // The size of the block - Dqn_isize used; // The number of bytes used up in the block. Always less than the committed amount. - Dqn_isize committed; // The number of physically backed bytes by the OS. - Dqn_ArenaBlock *prev; // The previous linked block - Dqn_ArenaBlock *next; // The next linked block + void *memory; ///< The backing memory of the block + Dqn_isize size; ///< The size of the block + Dqn_isize used; ///< The number of bytes used up in the block. Always less than the committed amount. + Dqn_isize committed; ///< The number of physically backed bytes by the OS. + Dqn_Arena_Block *prev; ///< The previous linked block + Dqn_Arena_Block *next; ///< The next linked block }; struct Dqn_ArenaStatString @@ -1163,33 +1145,33 @@ struct Dqn_ArenaStatString struct Dqn_ArenaStat { - Dqn_isize capacity; // Total allocating capacity of the arena in bytes - Dqn_isize used; // Total amount of bytes used in the arena - Dqn_isize wasted; // Orphaned space in blocks due to allocations requiring more space than available in the active block - Dqn_u32 blocks; // Number of memory blocks in the arena - Dqn_isize syscalls; // Number of memory allocation syscalls into the OS + Dqn_isize capacity; ///< Total allocating capacity of the arena in bytes + Dqn_isize used; ///< Total amount of bytes used in the arena + Dqn_isize wasted; ///< Orphaned space in blocks due to allocations requiring more space than available in the active block + uint32_t blocks; ///< Number of memory blocks in the arena + Dqn_isize syscalls; ///< Number of memory allocation syscalls into the OS - Dqn_isize capacity_hwm; // High-water mark for 'capacity' - Dqn_isize used_hwm; // High-water mark for 'used' - Dqn_isize wasted_hwm; // High-water mark for 'wasted' - Dqn_u32 blocks_hwm; // High-water mark for 'blocks' + Dqn_isize capacity_hwm; ///< High-water mark for 'capacity' + Dqn_isize used_hwm; ///< High-water mark for 'used' + Dqn_isize wasted_hwm; ///< High-water mark for 'wasted' + uint32_t blocks_hwm; ///< High-water mark for 'blocks' }; struct Dqn_Arena { Dqn_isize min_block_size; - Dqn_ArenaBlock *curr; // The current memory block of the arena - Dqn_ArenaBlock *tail; // The tail memory block of the arena - Dqn_ArenaStat stats; // Current arena stats, reset when reset usage is invoked. + Dqn_Arena_Block *curr; ///< The current memory block of the arena + Dqn_Arena_Block *tail; ///< The tail memory block of the arena + Dqn_ArenaStat stats; ///< Current arena stats, reset when reset usage is invoked. }; struct Dqn_ArenaTempMemory { - Dqn_Arena *arena; // The arena the scope is for - Dqn_ArenaBlock *curr; // The current block of the arena at the beginning of the scope - Dqn_ArenaBlock *tail; // The tail block of the arena at the beginning of the scope - Dqn_isize curr_used; // The current used amount of the current block - Dqn_ArenaStat stats; // The stats of the arena at the beginning of the scope + Dqn_Arena *arena; ///< The arena the scope is for + Dqn_Arena_Block *curr; ///< The current block of the arena at the beginning of the scope + Dqn_Arena_Block *tail; ///< The tail block of the arena at the beginning of the scope + Dqn_isize curr_used; ///< The current used amount of the current block + Dqn_ArenaStat stats; ///< The stats of the arena at the beginning of the scope }; // Automatically begin and end a temporary memory scope on object construction @@ -1201,84 +1183,88 @@ struct Dqn_ArenaTempMemoryScope Dqn_ArenaTempMemory temp_memory; }; -// @info Grow the arena's capacity by the requested size -// @in size: The size in bytes to expand the capacity of the arena -// @in commit: The amount of bytes to request to be physically backed by -// pages from the OS. -// @return True if the arena was successfully grown. False otherwise. -#define Dqn_ArenaGrowTagged(tag, arena, size, commit) Dqn_ArenaGrow_(DQN_CALL_SITE(tag) arena, size, commit) -#define Dqn_ArenaGrow(arena, size, commit) Dqn_ArenaGrowTagged(nullptr, arena, size, commit) -DQN_API bool Dqn_ArenaGrow_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize size, Dqn_isize commit); +/// Grow the arena's capacity by the requested size +/// @param[in] size The size in bytes to expand the capacity of the arena +/// @param[in] commit The amount of bytes to request to be physically backed by +/// pages from the OS. +/// @return True if the arena was successfully grown, false otherwise. +#define Dqn_Arena_GrowTagged(tag, arena, size, commit) Dqn_Arena_Grow_(DQN_CALL_SITE(tag) arena, size, commit) +#define Dqn_Arena_Grow(arena, size, commit) Dqn_Arena_GrowTagged(nullptr, arena, size, commit) +DQN_API bool Dqn_Arena_Grow_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize size, Dqn_isize commit); -// @info Allocate bytes from the given arena -// @return A pointer to the allocated bytes. Null if the arena failed to -// allocate memory -#define Dqn_ArenaAllocateTagged(tag, arena, size, align, zero_mem) Dqn_ArenaAllocate_(DQN_CALL_SITE(tag) arena, size, align, zero_mem) -#define Dqn_ArenaAllocate(arena, size, align, zero_mem) Dqn_ArenaAllocateTagged(nullptr, arena, size, align, zero_mem) -DQN_API void *Dqn_ArenaAllocate_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize size, Dqn_u8 align, Dqn_ZeroMem zero_mem); +/// Allocate bytes from the given arena +/// @return A pointer to the allocated bytes. Null if the arena failed to +/// allocate memory +#define Dqn_Arena_AllocateTagged(tag, arena, size, align, zero_mem) Dqn_Arena_Allocate_(DQN_CALL_SITE(tag) arena, size, align, zero_mem) +#define Dqn_Arena_Allocate(arena, size, align, zero_mem) Dqn_Arena_AllocateTagged(nullptr, arena, size, align, zero_mem) +DQN_API void *Dqn_Arena_Allocate_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize size, uint8_t align, Dqn_ZeroMem zero_mem); -// @info Allocate a single object from the arena. No constructor is called. -// @return A pointer to the allocated object. Null if the arena failed to -// allocate memory -#define Dqn_ArenaNew(arena, Type, zero_mem) Dqn_ArenaNewTagged(nullptr, arena, Type, zero_mem) -#define Dqn_ArenaNewTagged(tag, arena, Type, zero_mem) (Type *)Dqn_ArenaAllocate_(DQN_CALL_SITE(tag) arena, sizeof(Type), alignof(Type), zero_mem) +/// Allocate a single object from the arena. No constructor is called. +/// @return A pointer to the allocated object. Null if the arena failed to +/// allocate memory +#define Dqn_Arena_New(arena, Type, zero_mem) Dqn_Arena_NewTagged(nullptr, arena, Type, zero_mem) +#define Dqn_Arena_NewTagged(tag, arena, Type, zero_mem) (Type *)Dqn_Arena_Allocate_(DQN_CALL_SITE(tag) arena, sizeof(Type), alignof(Type), zero_mem) -// @info Allocate an array of objects from the arena. -// @return A pointer to the allocated object. Null if the arena failed to -// allocate memory -#define Dqn_ArenaNewArray(arena, Type, count, zero_mem) Dqn_ArenaNewArrayTagged(nullptr, arena, Type, count, zero_mem) -#define Dqn_ArenaNewArrayTagged(tag, arena, Type, count, zero_mem) (Type *)Dqn_ArenaAllocate_(DQN_CALL_SITE(tag) arena, sizeof(Type) * count, alignof(Type), zero_mem) +/// Allocate an array of objects from the arena. +/// @return A pointer to the allocated object. Null if the arena failed to +/// allocate memory +#define Dqn_Arena_NewArray(arena, Type, count, zero_mem) Dqn_Arena_NewArrayTagged(nullptr, arena, Type, count, zero_mem) +#define Dqn_Arena_NewArrayTagged(tag, arena, Type, count, zero_mem) (Type *)Dqn_Arena_Allocate_(DQN_CALL_SITE(tag) arena, sizeof(Type) * count, alignof(Type), zero_mem) -// @info Copy an object by allocating memory for the copy from the arena -// @return A pointer to the allocated object. Null if the arena failed to -// allocate memory -#define Dqn_ArenaCopy(arena, Type, src, count) Dqn_ArenaCopyTagged(nullptr, arena, Type, src, count) -#define Dqn_ArenaCopyTagged(tag, arena, Type, src, count) (Type *)Dqn_ArenaCopy_(DQN_CALL_SITE_TAG(tag) arena, src, sizeof(*src) * count, alignof(Type)) -DQN_API void *Dqn_ArenaCopy_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, void *src, Dqn_isize size, Dqn_u8 alignment); +/// Copy an object by allocating memory for the copy from the arena +/// @return A pointer to the allocated object. Null if the arena failed to +/// allocate memory +#define Dqn_Arena_Copy(arena, Type, src, count) Dqn_Arena_CopyTagged(nullptr, arena, Type, src, count) +#define Dqn_Arena_CopyTagged(tag, arena, Type, src, count) (Type *)Dqn_Arena_Copy_(DQN_CALL_SITE_TAG(tag) arena, src, sizeof(*src) * count, alignof(Type)) +DQN_API void *Dqn_Arena_Copy_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, void *src, Dqn_isize size, uint8_t alignment); -// @info Copy an object by allocating memory for the copy from the arena. The -// object has a null-terminating byte at the end of the stream. -// @return A pointer to the allocated object. Null if the arena failed to -// allocate memory -#define Dqn_ArenaCopyZ(arena, Type, src, count) Dqn_ArenaCopyZTagged(nullptr, arena, Type, src, count) -#define Dqn_ArenaCopyZTagged(tag, arena, Type, src, count) (Type *)Dqn_ArenaCopyZ_(DQN_CALL_SITE(tag) arena, src, sizeof(*src) * count, alignof(Type)) -DQN_API void *Dqn_ArenaCopyZ_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, void *src, Dqn_isize size, Dqn_u8 alignment); +/// Copy an object by allocating memory for the copy from the arena. The object +/// has a null-terminating byte at the end of the stream. +/// @return A pointer to the allocated object. Null if the arena failed to +/// allocate memory +#define Dqn_Arena_CopyZ(arena, Type, src, count) Dqn_Arena_CopyZTagged(nullptr, arena, Type, src, count) +#define Dqn_Arena_CopyZTagged(tag, arena, Type, src, count) (Type *)Dqn_Arena_CopyZ_(DQN_CALL_SITE(tag) arena, src, sizeof(*src) * count, alignof(Type)) +DQN_API void *Dqn_Arena_CopyZ_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, void *src, Dqn_isize size, uint8_t alignment); -// @info Set the arena's current block to the first block in the linked list -// of blocks and mark all blocks free. -// @in zero_mem: When yes, the memory is cleared using DQN_MEMSET with the -// value of DQN_MEMSET_BYTE -DQN_API void Dqn_ArenaReset(Dqn_Arena *arena, Dqn_ZeroMem zero_mem); +/// Set the arena's current block to the first block in the linked list of blocks +/// and mark all blocks free. +/// @param[in] zero_mem When yes, the memory is cleared using DQN_MEMSET with the +/// value of DQN_MEMSET_BYTE +DQN_API void Dqn_Arena_Reset(Dqn_Arena *arena, Dqn_ZeroMem zero_mem); -// @info Free the arena returning all memory back to the OS -// @in zero_mem: When true, the memory is cleared using DQN_MEMSET with the -// value of DQN_MEMSET_BYTE -DQN_API void Dqn_ArenaFree(Dqn_Arena *arena, bool zero_mem); +/// Free the arena returning all memory back to the OS +/// @param[in] zero_mem: When true, the memory is cleared using DQN_MEMSET with +/// the value of DQN_MEMSET_BYTE +DQN_API void Dqn_Arena_Free(Dqn_Arena *arena, bool zero_mem); -DQN_API Dqn_Allocator Dqn_ArenaAllocator(Dqn_Arena *arena); +DQN_API Dqn_Allocator Dqn_Arena_Allocator(Dqn_Arena *arena); -// @info Begin an allocation scope where all allocations between begin and end -// calls will be reverted. Useful for short-lived or highly defined -// lifetime allocations. An allocation scope is invalidated if the arena -// is freed between the begin and end call. -DQN_API Dqn_ArenaTempMemory Dqn_ArenaBeginTempMemory(Dqn_Arena *arena); +/// Begin an allocation scope where all allocations between begin and end calls +/// will be reverted. Useful for short-lived or highly defined lifetime +/// allocations. An allocation scope is invalidated if the arena is freed +/// between the begin and end call. +DQN_API Dqn_ArenaTempMemory Dqn_Arena_BeginTempMemory(Dqn_Arena *arena); -// @info End an allocation scope previously begun by calling begin scope. -DQN_API void Dqn_ArenaEndTempMemory(Dqn_ArenaTempMemory arena_temp_memory); +/// End an allocation scope previously begun by calling begin scope. +DQN_API void Dqn_Arena_EndTempMemory(Dqn_ArenaTempMemory arena_temp_memory); -DQN_API Dqn_ArenaStatString Dqn_ArenaStatToString(Dqn_ArenaStat const *stat); -DQN_API void Dqn_ArenaLogStats(Dqn_Arena const *arena); +/// Dump the stats of the given arena to a string +/// @param[in] arena The arena to dump stats for +/// @return A stack allocated string containing the stats of the arena +DQN_API Dqn_ArenaStatString Dqn_Arena_StatString(Dqn_ArenaStat const *stat); + +/// Dump the stats of the given arena to the memory log-stream. +/// @param[in] arena The arena to dump stats for +DQN_API void Dqn_Arena_LogStats(Dqn_Arena const *arena); #if defined(DQN_WITH_MAP) // NOTE: Dqn_Map // ------------------------------------------------------------------------------------------------- -// A hash-table implementation that uses a linked-list for collisions. -struct Dqn_Arena; // Foward declare - +/// A hash-table implementation that uses a linked-list for collisions. template struct Dqn_MapEntry { - Dqn_u64 hash; + uint64_t hash; T value; Dqn_MapEntry *next; }; @@ -1288,11 +1274,11 @@ struct Dqn_Map { Dqn_Arena *arena; Dqn_MapEntry **slots; - Dqn_isize size; // The number of slots + Dqn_isize size; ///< The number of slots // NOTE: Sum count and chain_count for total items in the list. - Dqn_isize count; // The total number of top-level slots in the 'values' list occupied - Dqn_isize chain_count; // The total number of chained elements in 'values' + Dqn_isize count; ///< The total number of top-level slots in the 'values' list occupied + Dqn_isize chain_count; ///< The total number of chained elements in 'values' Dqn_MapEntry *free_list; }; @@ -1304,22 +1290,22 @@ enum struct Dqn_MapCollideRule }; template -Dqn_Map Dqn_MapInitWithArena(Dqn_Arena *arena, Dqn_isize size = 0); +Dqn_Map Dqn_Map_InitWithArena(Dqn_Arena *arena, Dqn_isize size = 0); template -Dqn_MapEntry *Dqn_MapFindOrAdd(Dqn_Map *map, Dqn_u64 hash, Dqn_MapCollideRule rule); +Dqn_MapEntry *Dqn_Map_FindOrAdd(Dqn_Map *map, uint64_t hash, Dqn_MapCollideRule rule); template -Dqn_MapEntry *Dqn_MapAdd(Dqn_Map *map, Dqn_u64 hash, T *value, Dqn_MapCollideRule rule); +Dqn_MapEntry *Dqn_Map_Add(Dqn_Map *map, uint64_t hash, T *value, Dqn_MapCollideRule rule); template -Dqn_MapEntry *Dqn_MapAddCopy(Dqn_Map *map, Dqn_u64 hash, const T &value, Dqn_MapCollideRule rule); +Dqn_MapEntry *Dqn_Map_AddCopy(Dqn_Map *map, uint64_t hash, const T &value, Dqn_MapCollideRule rule); template -Dqn_MapEntry *Dqn_MapGet(Dqn_Map *map, Dqn_u64 hash); +Dqn_MapEntry *Dqn_Map_Get(Dqn_Map *map, uint64_t hash); template -void Dqn_MapErase(Dqn_Map *map, Dqn_u64 hash, Dqn_ZeroMem zero_mem); +void Dqn_Map_Erase(Dqn_Map *map, uint64_t hash, Dqn_ZeroMem zero_mem); #endif // DQN_WITH_MAP #if defined(DQN_WITH_DSMAP) @@ -1333,9 +1319,9 @@ void Dqn_MapErase(Dqn_Map *map, Dqn_u64 hash, Dqn_ZeroMem zero_mem); template struct Dqn_DSMapEntry { - Dqn_u64 hash; - T value; - Dqn_u8 occupied; + uint64_t hash; + T value; + uint8_t occupied; }; template @@ -1347,35 +1333,34 @@ struct Dqn_DSMap Dqn_isize count; // The number of slots occupied in the list }; -// @info Initialise a hash table with a given size. The given size must be -// a power of two. Initialisation is optional and the map can be -// zero-initialised in which the hash table will default to the size -// specified in DQN_DS_MAP_MIN_SIZE. -// @in size: The number of slots in the hash-table. This value must be -// a power of two. +/// Initialise a hash table with a given size. The given size must be a power of +/// two. Initialisation is optional and the map can be zero-initialised in which +/// the hash table will default to the size specified in DQN_DS_MAP_MIN_SIZE. +/// @param[in] size The number of slots in the hash-table. This value must be +/// a power of two. template -Dqn_DSMap Dqn_DSMapInit(Dqn_isize size); +Dqn_DSMap Dqn_DSMap_Init(Dqn_isize size); template -void Dqn_DSMapFree(Dqn_DSMap *map, Dqn_ZeroMem zero_mem); +void Dqn_DSMap_Free(Dqn_DSMap *map, Dqn_ZeroMem zero_mem); template -Dqn_DSMapEntry *Dqn_DSMapFind(Dqn_DSMap *map, Dqn_u64 hash); +Dqn_DSMapEntry *Dqn_DSMap_Find(Dqn_DSMap *map, uint64_t hash); template -Dqn_DSMapEntry *Dqn_DSMapFindOrAdd(Dqn_DSMap *map, Dqn_u64 hash, bool find_only); +Dqn_DSMapEntry *Dqn_DSMap_FindOrAdd(Dqn_DSMap *map, uint64_t hash, bool find_only); template -Dqn_DSMapEntry *Dqn_DSMapAdd(Dqn_DSMap *map, Dqn_u64 hash, T &value); +Dqn_DSMapEntry *Dqn_DSMap_Add(Dqn_DSMap *map, uint64_t hash, T &value); template -Dqn_DSMapEntry *Dqn_DSMapAddCopy(Dqn_DSMap *map, Dqn_u64 hash, T const &value); +Dqn_DSMapEntry *Dqn_DSMap_AddCopy(Dqn_DSMap *map, uint64_t hash, T const &value); template -Dqn_DSMapEntry *Dqn_DSMapGet(Dqn_DSMap *map, Dqn_u64 hash); +Dqn_DSMapEntry *Dqn_DSMap_Get(Dqn_DSMap *map, uint64_t hash); template -void Dqn_DSMapErase(Dqn_DSMap *map, Dqn_u64 hash, Dqn_ZeroMem zero_mem); +void Dqn_DSMap_Erase(Dqn_DSMap *map, uint64_t hash, Dqn_ZeroMem zero_mem); #endif // DQN_WITH_DSMAP // NOTE: Dqn_Array @@ -1394,30 +1379,30 @@ template struct Dqn_Array }; template -DQN_API Dqn_Array Dqn_ArrayInitWithMemory(T *memory, Dqn_isize max, Dqn_isize size = 0); +DQN_API Dqn_Array Dqn_Array_InitWithMemory(T *memory, Dqn_isize max, Dqn_isize size = 0); -#define Dqn_ArrayInitWithArenaNoGrow(arena, Type, max, size, zero_mem) Dqn_Array_InitWithArenaNoGrow(arena, max, size, zero_mem DQN_CALL_SITE("")) -#define Dqn_ArrayReserve(array, size) Dqn_ArrayReserve_(array, size DQN_CALL_SITE("")) -#define Dqn_ArrayAddArray(array, items, num) Dqn_ArrayAddArray_(array, items, num DQN_CALL_SITE("")) -#define Dqn_ArrayAdd(array, item) Dqn_ArrayAdd_(array, item DQN_CALL_SITE("")) -#define Dqn_ArrayMake(array, num) Dqn_ArrayMake_(array, num DQN_CALL_SITE("")) +#define Dqn_Array_InitWithArenaNoGrow(arena, Type, max, size, zero_mem) Dqn_Array__InitWithArenaNoGrow(arena, max, size, zero_mem DQN_CALL_SITE("")) +#define Dqn_Array_Reserve(array, size) Dqn_Array_Reserve_(array, size DQN_CALL_SITE("")) +#define Dqn_Array_AddArray(array, items, num) Dqn_Array_AddArray_(array, items, num DQN_CALL_SITE("")) +#define Dqn_Array_Add(array, item) Dqn_Array_Add_(array, item DQN_CALL_SITE("")) +#define Dqn_Array_Make(array, num) Dqn_Array_Make_(array, num DQN_CALL_SITE("")) template -DQN_API void Dqn_ArrayClear(Dqn_Array *a, Dqn_ZeroMem zero_mem = Dqn_ZeroMem_No); +DQN_API void Dqn_Array_Clear(Dqn_Array *a, Dqn_ZeroMem zero_mem = Dqn_ZeroMem_No); template -DQN_API void Dqn_ArrayEraseStable(Dqn_Array *a, Dqn_isize index); +DQN_API void Dqn_Array_EraseStable(Dqn_Array *a, Dqn_isize index); template -DQN_API void Dqn_ArrayEraseUnstable(Dqn_Array *a, Dqn_isize index); +DQN_API void Dqn_Array_EraseUnstable(Dqn_Array *a, Dqn_isize index); template -DQN_API void Dqn_ArrayPop(Dqn_Array *a, Dqn_isize num, Dqn_ZeroMem zero_mem = Dqn_ZeroMem_No); +DQN_API void Dqn_Array_Pop(Dqn_Array *a, Dqn_isize num, Dqn_ZeroMem zero_mem = Dqn_ZeroMem_No); template -DQN_API T * Dqn_ArrayPeek(Dqn_Array *a); +DQN_API T * Dqn_Array_Peek(Dqn_Array *a); -// NOTE: Dqn_Lib: Library book-keeping +// NOTE: Dqn_Lib_: Library book-keeping // ------------------------------------------------------------------------------------------------ -struct Dqn_Lib +struct Dqn_Lib_ { Dqn_LogProc *LogCallback; void * log_user_data; @@ -1434,21 +1419,21 @@ struct Dqn_Lib #if defined(DQN_DEBUG_THREAD_CONTEXT) Dqn_TicketMutex thread_context_mutex; Dqn_ArenaStat thread_context_arena_stats[256]; - Dqn_u8 thread_context_arena_stats_count; + uint8_t thread_context_arena_stats_count; #endif }; -extern Dqn_Lib dqn_lib_; +extern Dqn_Lib_ dqn_lib_; // Update the default logging function, all logging functions will run through this callback // proc: The new logging function, set to nullptr to revert back to the default logger. // user_data: A user defined parameter to pass to the callback -DQN_API void Dqn_LibSetLogCallback(Dqn_LogProc *proc, void *user_data); +DQN_API void Dqn_Lib_SetLogCallback(Dqn_LogProc *proc, void *user_data); // file: Pass in nullptr to turn off writing logs to disk, otherwise point it to // the FILE that you wish to write to. -DQN_API void Dqn_LibSetLogFile(void *file); -DQN_API void Dqn_LibDumpThreadContextArenaStat(Dqn_String8 file_path); +DQN_API void Dqn_Lib_SetLogFile(void *file); +DQN_API void Dqn_Lib_DumpThreadContextArenaStat(Dqn_String8 file_path); #if defined(DQN_WITH_FIXED_STRING) // NOTE: Dqn_FixedString @@ -1475,25 +1460,25 @@ struct Dqn_FixedString char *end () { return data + size; } }; -template DQN_API Dqn_FixedString Dqn_FixedStringFmt(char const *fmt, ...); -template DQN_API Dqn_isize Dqn_FixedStringMax(Dqn_FixedString *); -template DQN_API void Dqn_FixedStringClear(Dqn_FixedString *str); -template DQN_API bool Dqn_FixedStringAppendFmtV(Dqn_FixedString *str, char const *fmt, va_list va); -template DQN_API bool Dqn_FixedStringAppendFmt(Dqn_FixedString *str, char const *fmt, ...); -template DQN_API bool Dqn_FixedStringAppend(Dqn_FixedString *str, char const *src, Dqn_isize size = -1); -template DQN_API bool Dqn_FixedStringAppend(Dqn_FixedString *str, Dqn_String8 src); -template DQN_API Dqn_String8 Dqn_FixedStringToString(Dqn_FixedString const *str); +template DQN_API Dqn_FixedString Dqn_FixedString_Fmt(char const *fmt, ...); +template DQN_API Dqn_isize Dqn_FixedString_Max(Dqn_FixedString *); +template DQN_API void Dqn_FixedString_Clear(Dqn_FixedString *str); +template DQN_API bool Dqn_FixedString_AppendFmtV(Dqn_FixedString *str, char const *fmt, va_list va); +template DQN_API bool Dqn_FixedString_AppendFmt(Dqn_FixedString *str, char const *fmt, ...); +template DQN_API bool Dqn_FixedString_Append(Dqn_FixedString *str, char const *src, Dqn_isize size = -1); +template DQN_API bool Dqn_FixedString_Append(Dqn_FixedString *str, Dqn_String8 src); +template DQN_API Dqn_String8 Dqn_FixedString_ToString(Dqn_FixedString const *str); #endif // DQN_WITH_FIXED_STRING // NOTE: Dqn_String8Builder API // ----------------------------------------------------------------------------- -typedef struct Dqn_String8Builder { +struct Dqn_String8Builder { Dqn_Allocator allocator; ///< Allocator to use to back the string list - Dqn_String8Link *head; ///< First string in the linked list of strings - Dqn_String8Link *tail; ///< Last string in the linked list of strings + Dqn_String8_Link *head; ///< First string in the linked list of strings + Dqn_String8_Link *tail; ///< Last string in the linked list of strings ptrdiff_t string_size; ///< The size in bytes necessary to construct the current string ptrdiff_t count; ///< The number of links in the linked list of strings -} Dqn_String8Builder; +}; /// Append a string to the list of strings in the builder by reference. /// The string's data must persist whilst the string builder is being used. @@ -1501,7 +1486,7 @@ typedef struct Dqn_String8Builder { /// @param string The string to append to the builder /// @return True if append was successful, false if parameters are invalid /// or memory allocation failure. -bool Dqn_String8BuilderAppendString8Ref(Dqn_String8Builder *builder, Dqn_String8 string); +bool Dqn_String8Builder_AppendString8Ref(Dqn_String8Builder *builder, Dqn_String8 string); /// Append a string to the list of strings in the builder by copy. /// The string is copied using the builder's allocator before appending. @@ -1509,18 +1494,18 @@ bool Dqn_String8BuilderAppendString8Ref(Dqn_String8Builder *builder, Dqn_String8 /// @param string The string to append to the builder /// @return True if append was successful, false if parameters are invalid /// or memory allocation failure. -bool Dqn_String8BuilderAppendString8Copy(Dqn_String8Builder *builder, Dqn_String8 string); +bool Dqn_String8Builder_AppendString8Copy(Dqn_String8Builder *builder, Dqn_String8 string); -/// @copydoc Dqn_String8BuilderAppendFmtArgs +/// @copydoc Dqn_String8Builder_AppendFmtArgs /// @param args The variable argument list to use in the format string -bool Dqn_String8BuilderAppendFmtVArgs(Dqn_String8Builder *builder, char const *fmt, va_list args); +bool Dqn_String8Builder_AppendFmtVArgs(Dqn_String8Builder *builder, char const *fmt, va_list args); /// Append a printf-style format string to the list of strings in the builder. /// @param builder The builder to append the string to /// @param fmt The format string to use /// @return True if append was successful, false if parameters are invalid /// or memory allocation failure. -bool Dqn_String8BuilderAppendFmtArgs(Dqn_String8Builder *builder, char const *fmt, ...); +bool Dqn_String8Builder_AppendFmtArgs(Dqn_String8Builder *builder, char const *fmt, ...); /// Build the list of strings into the final composite string from the string /// builder @@ -1528,7 +1513,7 @@ bool Dqn_String8BuilderAppendFmtArgs(Dqn_String8Builder *builder, char const *fm /// @param allocator The allocator to use to build the string /// @return The string if build was successful, empty string if parameters are /// invalid or memory allocation failure. -Dqn_String8 Dqn_String8BuilderBuild(Dqn_String8Builder const *builder, Dqn_Allocator allocator); +Dqn_String8 Dqn_String8Builder_Build(Dqn_String8Builder const *builder, Dqn_Allocator allocator); #if defined(DQN_WITH_FIXED_ARRAY) // NOTE: Dqn_FixedArray @@ -1551,27 +1536,27 @@ DQN_FIXED_ARRAY_TEMPLATE struct Dqn_FixedArray T const *operator+ (Dqn_isize i) const { DQN_ASSERT_MSG(i >= 0 && i <= size, "%I64d >= 0 && %I64d < %I64d", i, size); return data + i; } }; -DQN_FIXED_ARRAY_TEMPLATE DQN_API DQN_FIXED_ARRAY_TEMPLATE_DECL Dqn_FixedArrayInit(T const *item, int num); -DQN_FIXED_ARRAY_TEMPLATE DQN_API Dqn_isize Dqn_FixedArrayMax(DQN_FIXED_ARRAY_TEMPLATE_DECL const *); +DQN_FIXED_ARRAY_TEMPLATE DQN_API DQN_FIXED_ARRAY_TEMPLATE_DECL Dqn_FixedArray_Init(T const *item, int num); +DQN_FIXED_ARRAY_TEMPLATE DQN_API Dqn_isize Dqn_FixedArray_Max(DQN_FIXED_ARRAY_TEMPLATE_DECL const *); // Calculate the index of a item from the its pointer -DQN_FIXED_ARRAY_TEMPLATE DQN_API Dqn_isize Dqn_FixedArrayGetIndex(DQN_FIXED_ARRAY_TEMPLATE_DECL const *a, T const *entry); +DQN_FIXED_ARRAY_TEMPLATE DQN_API Dqn_isize Dqn_FixedArray_GetIndex(DQN_FIXED_ARRAY_TEMPLATE_DECL const *a, T const *entry); // return: The newly added item, nullptr if failed -DQN_FIXED_ARRAY_TEMPLATE DQN_API T *Dqn_FixedArrayAdd(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T const *items, Dqn_isize num); -DQN_FIXED_ARRAY_TEMPLATE DQN_API T *Dqn_FixedArrayAdd(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T const &item); +DQN_FIXED_ARRAY_TEMPLATE DQN_API T *Dqn_FixedArray_Add(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T const *items, Dqn_isize num); +DQN_FIXED_ARRAY_TEMPLATE DQN_API T *Dqn_FixedArray_Add(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T const &item); // Bump the size of the array and return a pointer to 'num' uninitialised elements -DQN_FIXED_ARRAY_TEMPLATE DQN_API T *Dqn_FixedArrayMake(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize num); -DQN_FIXED_ARRAY_TEMPLATE DQN_API void Dqn_FixedArrayClear(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_ZeroMem zero_mem = Dqn_ZeroMem_No); -DQN_FIXED_ARRAY_TEMPLATE DQN_API void Dqn_FixedArrayEraseStable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index); -DQN_FIXED_ARRAY_TEMPLATE DQN_API void Dqn_FixedArrayEraseUnstable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index); -DQN_FIXED_ARRAY_TEMPLATE DQN_API void Dqn_FixedArrayPop(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize num = 1, Dqn_ZeroMem zero_mem = Dqn_ZeroMem_No); -DQN_FIXED_ARRAY_TEMPLATE DQN_API T *Dqn_FixedArrayPeek(DQN_FIXED_ARRAY_TEMPLATE_DECL *a); -DQN_FIXED_ARRAY_TEMPLATE DQN_API T Dqn_FixedArrayPeekCopy(DQN_FIXED_ARRAY_TEMPLATE_DECL const *a); -template DQN_API T *Dqn_FixedArrayFind(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, IsEqual IsEqualProc); -template DQN_API bool Dqn_FixedArrayFindElseMake(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T **entry, IsEqual IsEqualProc); -DQN_FIXED_ARRAY_TEMPLATE DQN_API T *Dqn_FixedArrayFind(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T *find); +DQN_FIXED_ARRAY_TEMPLATE DQN_API T *Dqn_FixedArray_Make(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize num); +DQN_FIXED_ARRAY_TEMPLATE DQN_API void Dqn_FixedArray_Clear(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_ZeroMem zero_mem = Dqn_ZeroMem_No); +DQN_FIXED_ARRAY_TEMPLATE DQN_API void Dqn_FixedArray_EraseStable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index); +DQN_FIXED_ARRAY_TEMPLATE DQN_API void Dqn_FixedArray_EraseUnstable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index); +DQN_FIXED_ARRAY_TEMPLATE DQN_API void Dqn_FixedArray_Pop(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize num = 1, Dqn_ZeroMem zero_mem = Dqn_ZeroMem_No); +DQN_FIXED_ARRAY_TEMPLATE DQN_API T *Dqn_FixedArray_Peek(DQN_FIXED_ARRAY_TEMPLATE_DECL *a); +DQN_FIXED_ARRAY_TEMPLATE DQN_API T Dqn_FixedArray_PeekCopy(DQN_FIXED_ARRAY_TEMPLATE_DECL const *a); +template DQN_API T *Dqn_FixedArray_Find(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, IsEqual IsEqualProc); +template DQN_API bool Dqn_FixedArray_FindElseMake(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T **entry, IsEqual IsEqualProc); +DQN_FIXED_ARRAY_TEMPLATE DQN_API T *Dqn_FixedArray_Find(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T *find); #endif // DQN_WITH_FIXED_ARRAY // NOTE: Dqn_List - Chunked Linked Lists @@ -1589,7 +1574,7 @@ struct Dqn_ListChunk template struct Dqn_ListIterator { - Dqn_b32 init; // (Internal): True if Dqn_ListIterate has been called at-least once on this iterator + Dqn_b32 init; // (Internal): True if Dqn_List_Iterate has been called at-least once on this iterator Dqn_ListChunk *chunk; // (Internal): The chunk that the iterator is reading from Dqn_isize chunk_data_index; // (Internal): The index in the chunk the iterator is referencing T *data; // (Read): Pointer to the data the iterator is referencing. Nullptr if invalid. @@ -1605,38 +1590,38 @@ struct Dqn_List Dqn_ListChunk *tail; }; -template DQN_API Dqn_List Dqn_ListInitWithArena(Dqn_Arena *arena, Dqn_isize chunk_size = 128); +template DQN_API Dqn_List Dqn_List_InitWithArena(Dqn_Arena *arena, Dqn_isize chunk_size = 128); // Produce an iterator for the data in the list /* Dqn_List list = {}; - for (Dqn_ListIterator it = {}; Dqn_ListIterate(&list, &it, 0);) + for (Dqn_ListIterator it = {}; Dqn_List_Iterate(&list, &it, 0);) { int *item = it.data; } */ // start_index: The index to start iterating from -template DQN_API bool Dqn_ListIterate(Dqn_List *list, Dqn_ListIterator *iterator, Dqn_isize start_index); +template DQN_API bool Dqn_List_Iterate(Dqn_List *list, Dqn_ListIterator *iterator, Dqn_isize start_index); // at_chunk: (Optional) The chunk that the index belongs to will be set in this parameter if given // return: The element, or null pointer if it is not a valid index. -template DQN_API T *Dqn_ListAt(Dqn_List *list, Dqn_isize index, Dqn_ListChunk *at_chunk); +template DQN_API T *Dqn_List_At(Dqn_List *list, Dqn_isize index, Dqn_ListChunk *at_chunk); -#define Dqn_ListTaggedMake(list, count, tag) Dqn__ListMake(list, count DQN_CALL_SITE(tag)) -#define Dqn_ListMake(list, count) Dqn__ListMake(list, count DQN_CALL_SITE("")) -template DQN_API T *Dqn__ListMake(Dqn_List *list, Dqn_isize count DQN_CALL_SITE_ARGS); +#define Dqn_List_TaggedMake(list, count, tag) Dqn_List_Make_(list, count DQN_CALL_SITE(tag)) +#define Dqn_List_Make(list, count) Dqn_List_Make_(list, count DQN_CALL_SITE("")) +template DQN_API T *Dqn_List_Make_(Dqn_List *list, Dqn_isize count DQN_CALL_SITE_ARGS); #if defined(DQN_WITH_MATH) // NOTE: Math // ------------------------------------------------------------------------------------------------- struct Dqn_V2I { - Dqn_i32 x, y; + int32_t x, y; Dqn_V2I() = default; - Dqn_V2I(Dqn_f32 x_, Dqn_f32 y_): x((Dqn_i32)x_), y((Dqn_i32)y_) {} - Dqn_V2I(Dqn_i32 x_, Dqn_i32 y_): x(x_), y(y_) {} - Dqn_V2I(Dqn_i32 xy): x(xy), y(xy) {} + Dqn_V2I(Dqn_f32 x_, Dqn_f32 y_): x((int32_t)x_), y((int32_t)y_) {} + Dqn_V2I(int32_t x_, int32_t y_): x(x_), y(y_) {} + Dqn_V2I(int32_t xy): x(xy), y(xy) {} bool operator!=(Dqn_V2I other) const { return !(*this == other); } bool operator==(Dqn_V2I other) const { return (x == other.x) && (y == other.y); } @@ -1648,13 +1633,13 @@ struct Dqn_V2I Dqn_V2I operator+ (Dqn_V2I other) const { Dqn_V2I result(x + other.x, y + other.y); return result; } Dqn_V2I operator* (Dqn_V2I other) const { Dqn_V2I result(x * other.x, y * other.y); return result; } Dqn_V2I operator* (Dqn_f32 other) const { Dqn_V2I result(x * other, y * other); return result; } - Dqn_V2I operator* (Dqn_i32 other) const { Dqn_V2I result(x * other, y * other); return result; } + Dqn_V2I operator* (int32_t other) const { Dqn_V2I result(x * other, y * other); return result; } Dqn_V2I operator/ (Dqn_V2I other) const { Dqn_V2I result(x / other.x, y / other.y); return result; } Dqn_V2I operator/ (Dqn_f32 other) const { Dqn_V2I result(x / other, y / other); return result; } - Dqn_V2I operator/ (Dqn_i32 other) const { Dqn_V2I result(x / other, y / other); return result; } + Dqn_V2I operator/ (int32_t other) const { Dqn_V2I result(x / other, y / other); return result; } Dqn_V2I &operator*=(Dqn_V2I other) { *this = *this * other; return *this; } Dqn_V2I &operator*=(Dqn_f32 other) { *this = *this * other; return *this; } - Dqn_V2I &operator*=(Dqn_i32 other) { *this = *this * other; return *this; } + Dqn_V2I &operator*=(int32_t other) { *this = *this * other; return *this; } Dqn_V2I &operator-=(Dqn_V2I other) { *this = *this - other; return *this; } Dqn_V2I &operator+=(Dqn_V2I other) { *this = *this + other; return *this; } }; @@ -1665,9 +1650,9 @@ struct Dqn_V2 Dqn_V2() = default; Dqn_V2(Dqn_f32 a) : x(a), y(a) {} - Dqn_V2(Dqn_i32 a) : x((Dqn_f32)a), y((Dqn_f32)a) {} + Dqn_V2(int32_t a) : x((Dqn_f32)a), y((Dqn_f32)a) {} Dqn_V2(Dqn_f32 x, Dqn_f32 y): x(x), y(y) {} - Dqn_V2(Dqn_i32 x, Dqn_i32 y): x((Dqn_f32)x), y((Dqn_f32)y) {} + Dqn_V2(int32_t x, int32_t y): x((Dqn_f32)x), y((Dqn_f32)y) {} Dqn_V2(Dqn_V2I a) : x((Dqn_f32)a.x),y((Dqn_f32)a.y){} bool operator!=(Dqn_V2 other) const { return !(*this == other); } @@ -1680,16 +1665,16 @@ struct Dqn_V2 Dqn_V2 operator+ (Dqn_V2 other) const { Dqn_V2 result(x + other.x, y + other.y); return result; } Dqn_V2 operator* (Dqn_V2 other) const { Dqn_V2 result(x * other.x, y * other.y); return result; } Dqn_V2 operator* (Dqn_f32 other) const { Dqn_V2 result(x * other, y * other); return result; } - Dqn_V2 operator* (Dqn_i32 other) const { Dqn_V2 result(x * other, y * other); return result; } + Dqn_V2 operator* (int32_t other) const { Dqn_V2 result(x * other, y * other); return result; } Dqn_V2 operator/ (Dqn_V2 other) const { Dqn_V2 result(x / other.x, y / other.y); return result; } Dqn_V2 operator/ (Dqn_f32 other) const { Dqn_V2 result(x / other, y / other); return result; } - Dqn_V2 operator/ (Dqn_i32 other) const { Dqn_V2 result(x / other, y / other); return result; } + Dqn_V2 operator/ (int32_t other) const { Dqn_V2 result(x / other, y / other); return result; } Dqn_V2 &operator*=(Dqn_V2 other) { *this = *this * other; return *this; } Dqn_V2 &operator*=(Dqn_f32 other) { *this = *this * other; return *this; } - Dqn_V2 &operator*=(Dqn_i32 other) { *this = *this * other; return *this; } + Dqn_V2 &operator*=(int32_t other) { *this = *this * other; return *this; } Dqn_V2 &operator/=(Dqn_V2 other) { *this = *this / other; return *this; } Dqn_V2 &operator/=(Dqn_f32 other) { *this = *this / other; return *this; } - Dqn_V2 &operator/=(Dqn_i32 other) { *this = *this / other; return *this; } + Dqn_V2 &operator/=(int32_t other) { *this = *this / other; return *this; } Dqn_V2 &operator-=(Dqn_V2 other) { *this = *this - other; return *this; } Dqn_V2 &operator+=(Dqn_V2 other) { *this = *this + other; return *this; } }; @@ -1700,9 +1685,9 @@ struct Dqn_V3 Dqn_V3() = default; Dqn_V3(Dqn_f32 a) : x(a), y(a), z(a) {} - Dqn_V3(Dqn_i32 a) : x(DQN_CAST(Dqn_f32)a), y(DQN_CAST(Dqn_f32)a), z(DQN_CAST(Dqn_f32)a) {} + Dqn_V3(int32_t a) : x(DQN_CAST(Dqn_f32)a), y(DQN_CAST(Dqn_f32)a), z(DQN_CAST(Dqn_f32)a) {} Dqn_V3(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z): x(x), y(y), z(z) {} - Dqn_V3(Dqn_i32 x, Dqn_i32 y, Dqn_f32 z): x(DQN_CAST(Dqn_f32)x), y(DQN_CAST(Dqn_f32)y), z(DQN_CAST(Dqn_f32)z) {} + Dqn_V3(int32_t x, int32_t y, Dqn_f32 z): x(DQN_CAST(Dqn_f32)x), y(DQN_CAST(Dqn_f32)y), z(DQN_CAST(Dqn_f32)z) {} Dqn_V3(Dqn_V2 xy, Dqn_f32 z) : x(xy.x), y(xy.y), z(z) {} bool operator!= (Dqn_V3 other) const { return !(*this == other); } @@ -1715,16 +1700,16 @@ struct Dqn_V3 Dqn_V3 operator+ (Dqn_V3 other) const { Dqn_V3 result(x + other.x, y + other.y, z + other.z); return result; } Dqn_V3 operator* (Dqn_V3 other) const { Dqn_V3 result(x * other.x, y * other.y, z * other.z); return result; } Dqn_V3 operator* (Dqn_f32 other) const { Dqn_V3 result(x * other, y * other, z * other); return result; } - Dqn_V3 operator* (Dqn_i32 other) const { Dqn_V3 result(x * other, y * other, z * other); return result; } + Dqn_V3 operator* (int32_t other) const { Dqn_V3 result(x * other, y * other, z * other); return result; } Dqn_V3 operator/ (Dqn_V3 other) const { Dqn_V3 result(x / other.x, y / other.y, z / other.z); return result; } Dqn_V3 operator/ (Dqn_f32 other) const { Dqn_V3 result(x / other, y / other, z / other); return result; } - Dqn_V3 operator/ (Dqn_i32 other) const { Dqn_V3 result(x / other, y / other, z / other); return result; } + Dqn_V3 operator/ (int32_t other) const { Dqn_V3 result(x / other, y / other, z / other); return result; } Dqn_V3 &operator*=(Dqn_V3 other) { *this = *this * other; return *this; } Dqn_V3 &operator*=(Dqn_f32 other) { *this = *this * other; return *this; } - Dqn_V3 &operator*=(Dqn_i32 other) { *this = *this * other; return *this; } + Dqn_V3 &operator*=(int32_t other) { *this = *this * other; return *this; } Dqn_V3 &operator/=(Dqn_V3 other) { *this = *this / other; return *this; } Dqn_V3 &operator/=(Dqn_f32 other) { *this = *this / other; return *this; } - Dqn_V3 &operator/=(Dqn_i32 other) { *this = *this / other; return *this; } + Dqn_V3 &operator/=(int32_t other) { *this = *this / other; return *this; } Dqn_V3 &operator-=(Dqn_V3 other) { *this = *this - other; return *this; } Dqn_V3 &operator+=(Dqn_V3 other) { *this = *this + other; return *this; } }; @@ -1740,7 +1725,7 @@ union Dqn_V4 Dqn_V4() = default; Dqn_V4(Dqn_f32 xyzw) : x(xyzw), y(xyzw), z(xyzw), w(xyzw) {} Dqn_V4(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z, Dqn_f32 w): x(x), y(y), z(z), w(w) {} - Dqn_V4(Dqn_i32 x, Dqn_i32 y, Dqn_i32 z, Dqn_i32 w): x(DQN_CAST(Dqn_f32)x), y(DQN_CAST(Dqn_f32)y), z(DQN_CAST(Dqn_f32)z), w(DQN_CAST(Dqn_f32)w) {} + Dqn_V4(int32_t x, int32_t y, int32_t z, int32_t w): x(DQN_CAST(Dqn_f32)x), y(DQN_CAST(Dqn_f32)y), z(DQN_CAST(Dqn_f32)z), w(DQN_CAST(Dqn_f32)w) {} Dqn_V4(Dqn_V3 xyz, Dqn_f32 w) : x(xyz.x), y(xyz.y), z(xyz.z), w(w) {} Dqn_V4(Dqn_V2 v2) : x(v2.x), y(v2.y), z(v2.x), w(v2.y) {} @@ -1754,11 +1739,11 @@ union Dqn_V4 Dqn_V4 operator+ (Dqn_V4 other) const { Dqn_V4 result(x + other.x, y + other.y, z + other.z, w + other.w); return result; } Dqn_V4 operator* (Dqn_V4 other) const { Dqn_V4 result(x * other.x, y * other.y, z * other.z, w * other.w); return result; } Dqn_V4 operator* (Dqn_f32 other) const { Dqn_V4 result(x * other, y * other, z * other, w * other); return result; } - Dqn_V4 operator* (Dqn_i32 other) const { Dqn_V4 result(x * other, y * other, z * other, w * other); return result; } + Dqn_V4 operator* (int32_t other) const { Dqn_V4 result(x * other, y * other, z * other, w * other); return result; } Dqn_V4 operator/ (Dqn_f32 other) const { Dqn_V4 result(x / other, y / other, z / other, w / other); return result; } Dqn_V4 &operator*=(Dqn_V4 other) { *this = *this * other; return *this; } Dqn_V4 &operator*=(Dqn_f32 other) { *this = *this * other; return *this; } - Dqn_V4 &operator*=(Dqn_i32 other) { *this = *this * other; return *this; } + Dqn_V4 &operator*=(int32_t other) { *this = *this * other; return *this; } Dqn_V4 &operator-=(Dqn_V4 other) { *this = *this - other; return *this; } Dqn_V4 &operator+=(Dqn_V4 other) { *this = *this + other; return *this; } }; @@ -1784,26 +1769,26 @@ DQN_API Dqn_V3 Dqn_V3Normalise(Dqn_V3 a); DQN_API Dqn_f32 Dqn_V4Dot(Dqn_V4 a, Dqn_V4 b); -DQN_API Dqn_M4 Dqn_M4Identity(); -DQN_API Dqn_M4 Dqn_M4ScaleF(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z); -DQN_API Dqn_M4 Dqn_M4Scale(Dqn_V3 xyz); -DQN_API Dqn_M4 Dqn_M4TranslateF(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z); -DQN_API Dqn_M4 Dqn_M4Translate(Dqn_V3 xyz); -DQN_API Dqn_M4 Dqn_M4Transpose(Dqn_M4 mat); -DQN_API Dqn_M4 Dqn_M4Rotate(Dqn_V3 axis, Dqn_f32 radians); -DQN_API Dqn_M4 Dqn_M4Orthographic(Dqn_f32 left, Dqn_f32 right, Dqn_f32 bottom, Dqn_f32 top, Dqn_f32 z_near, Dqn_f32 z_far); -DQN_API Dqn_M4 Dqn_M4Perspective(Dqn_f32 fov /*radians*/, Dqn_f32 aspect, Dqn_f32 z_near, Dqn_f32 z_far); -DQN_API Dqn_M4 Dqn_M4Add(Dqn_M4 lhs, Dqn_M4 rhs); -DQN_API Dqn_M4 Dqn_M4Sub(Dqn_M4 lhs, Dqn_M4 rhs); -DQN_API Dqn_M4 Dqn_M4Mul(Dqn_M4 lhs, Dqn_M4 rhs); -DQN_API Dqn_M4 Dqn_M4Div(Dqn_M4 lhs, Dqn_M4 rhs); -DQN_API Dqn_M4 Dqn_M4AddF(Dqn_M4 lhs, Dqn_f32 rhs); -DQN_API Dqn_M4 Dqn_M4SubF(Dqn_M4 lhs, Dqn_f32 rhs); -DQN_API Dqn_M4 Dqn_M4MulF(Dqn_M4 lhs, Dqn_f32 rhs); -DQN_API Dqn_M4 Dqn_M4DivF(Dqn_M4 lhs, Dqn_f32 rhs); +DQN_API Dqn_M4 Dqn_M4_Identity(); +DQN_API Dqn_M4 Dqn_M4_ScaleF(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z); +DQN_API Dqn_M4 Dqn_M4_Scale(Dqn_V3 xyz); +DQN_API Dqn_M4 Dqn_M4_TranslateF(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z); +DQN_API Dqn_M4 Dqn_M4_Translate(Dqn_V3 xyz); +DQN_API Dqn_M4 Dqn_M4_Transpose(Dqn_M4 mat); +DQN_API Dqn_M4 Dqn_M4_Rotate(Dqn_V3 axis, Dqn_f32 radians); +DQN_API Dqn_M4 Dqn_M4_Orthographic(Dqn_f32 left, Dqn_f32 right, Dqn_f32 bottom, Dqn_f32 top, Dqn_f32 z_near, Dqn_f32 z_far); +DQN_API Dqn_M4 Dqn_M4_Perspective(Dqn_f32 fov /*radians*/, Dqn_f32 aspect, Dqn_f32 z_near, Dqn_f32 z_far); +DQN_API Dqn_M4 Dqn_M4_Add(Dqn_M4 lhs, Dqn_M4 rhs); +DQN_API Dqn_M4 Dqn_M4_Sub(Dqn_M4 lhs, Dqn_M4 rhs); +DQN_API Dqn_M4 Dqn_M4_Mul(Dqn_M4 lhs, Dqn_M4 rhs); +DQN_API Dqn_M4 Dqn_M4_Div(Dqn_M4 lhs, Dqn_M4 rhs); +DQN_API Dqn_M4 Dqn_M4_AddF(Dqn_M4 lhs, Dqn_f32 rhs); +DQN_API Dqn_M4 Dqn_M4_SubF(Dqn_M4 lhs, Dqn_f32 rhs); +DQN_API Dqn_M4 Dqn_M4_MulF(Dqn_M4 lhs, Dqn_f32 rhs); +DQN_API Dqn_M4 Dqn_M4_DivF(Dqn_M4 lhs, Dqn_f32 rhs); #if defined(DQN_WITH_FIXED_STRING) -DQN_API Dqn_FixedString<256> Dqn_M4ColumnMajorString(Dqn_M4 mat); +DQN_API Dqn_FixedString<256> Dqn_M4_ColumnMajorString(Dqn_M4 mat); #endif struct Dqn_Rect @@ -1823,253 +1808,264 @@ struct Dqn_RectI32 Dqn_RectI32(Dqn_V2I min, Dqn_V2I max) : min(min), max(max) {} }; -DQN_API Dqn_Rect Dqn_RectInitFromPosAndSize(Dqn_V2 pos, Dqn_V2 size); -DQN_API Dqn_V2 Dqn_RectCenter(Dqn_Rect rect); -DQN_API bool Dqn_RectContainsPoint(Dqn_Rect rect, Dqn_V2 p); -DQN_API bool Dqn_RectContainsRect(Dqn_Rect a, Dqn_Rect b); -DQN_API Dqn_V2 Dqn_RectSize(Dqn_Rect rect); -DQN_API Dqn_Rect Dqn_RectMove(Dqn_Rect src, Dqn_V2 move_amount); -DQN_API Dqn_Rect Dqn_RectMoveTo(Dqn_Rect src, Dqn_V2 dest); -DQN_API bool Dqn_RectIntersects(Dqn_Rect a, Dqn_Rect b); -DQN_API Dqn_Rect Dqn_RectIntersection(Dqn_Rect a, Dqn_Rect b); -DQN_API Dqn_Rect Dqn_RectUnion(Dqn_Rect a, Dqn_Rect b); -DQN_API Dqn_Rect Dqn_RectFromRectI32(Dqn_RectI32 a); +DQN_API Dqn_Rect Dqn_Rect_InitFromPosAndSize(Dqn_V2 pos, Dqn_V2 size); +DQN_API Dqn_V2 Dqn_Rect_Center(Dqn_Rect rect); +DQN_API bool Dqn_Rect_ContainsPoint(Dqn_Rect rect, Dqn_V2 p); +DQN_API bool Dqn_Rect_ContainsRect(Dqn_Rect a, Dqn_Rect b); +DQN_API Dqn_V2 Dqn_Rect_Size(Dqn_Rect rect); +DQN_API Dqn_Rect Dqn_Rect_Move(Dqn_Rect src, Dqn_V2 move_amount); +DQN_API Dqn_Rect Dqn_Rect_MoveTo(Dqn_Rect src, Dqn_V2 dest); +DQN_API bool Dqn_Rect_Intersects(Dqn_Rect a, Dqn_Rect b); +DQN_API Dqn_Rect Dqn_Rect_Intersection(Dqn_Rect a, Dqn_Rect b); +DQN_API Dqn_Rect Dqn_Rect_Union(Dqn_Rect a, Dqn_Rect b); +DQN_API Dqn_Rect Dqn_Rect_FromRectI32(Dqn_RectI32 a); DQN_API Dqn_V2I Dqn_RectI32_Size(Dqn_RectI32 rect); // NOTE: Math Utils // ------------------------------------------------------------------------------------------------- -DQN_API Dqn_V2 Dqn_LerpV2(Dqn_V2 a, Dqn_f32 t, Dqn_V2 b); -DQN_API Dqn_f32 Dqn_LerpF32(Dqn_f32 a, Dqn_f32 t, Dqn_f32 b); +DQN_API Dqn_V2 Dqn_Lerp_V2(Dqn_V2 a, Dqn_f32 t, Dqn_V2 b); +DQN_API Dqn_f32 Dqn_Lerp_F32(Dqn_f32 a, Dqn_f32 t, Dqn_f32 b); #endif // DQN_WITH_MATH -// NOTE: Dqn_Bit +// NOTE: Dqn_Bit_ // ------------------------------------------------------------------------------------------------- -DQN_API void Dqn_BitUnsetInplace(Dqn_u32 *flags, Dqn_u32 bitfield); -DQN_API void Dqn_BitSetInplace(Dqn_u32 *flags, Dqn_u32 bitfield); -DQN_API bool Dqn_BitIsSet(Dqn_u32 bits, Dqn_u32 bits_to_set); -DQN_API bool Dqn_BitIsNotSet(Dqn_u32 bits, Dqn_u32 bits_to_check); +DQN_API void Dqn_Bit_UnsetInplace(uint32_t *flags, uint32_t bitfield); +DQN_API void Dqn_Bit_SetInplace(uint32_t *flags, uint32_t bitfield); +DQN_API bool Dqn_Bit_IsSet(uint32_t bits, uint32_t bits_to_set); +DQN_API bool Dqn_Bit_IsNotSet(uint32_t bits, uint32_t bits_to_check); // NOTE: Safe Arithmetic // ------------------------------------------------------------------------------------------------- -DQN_API Dqn_i64 Dqn_SafeAddI64 (Dqn_i64 a, Dqn_i64 b); -DQN_API Dqn_i64 Dqn_SafeMulI64 (Dqn_i64 a, Dqn_i64 b); -DQN_API Dqn_u64 Dqn_SafeAddU64 (Dqn_u64 a, Dqn_u64 b); -DQN_API Dqn_u64 Dqn_SafeSubU64 (Dqn_u64 a, Dqn_u64 b); -DQN_API Dqn_u32 Dqn_SafeSubU32 (Dqn_u32 a, Dqn_u32 b); -DQN_API Dqn_u64 Dqn_SafeMulU64 (Dqn_u64 a, Dqn_u64 b); -DQN_API int Dqn_SafeTruncateISizeToInt (Dqn_isize val); -DQN_API Dqn_i32 Dqn_SafeTruncateISizeToI32 (Dqn_isize val); -DQN_API Dqn_i8 Dqn_SafeTruncateISizeToI8 (Dqn_isize val); -DQN_API Dqn_u32 Dqn_SafeTruncateUSizeToU32 (Dqn_usize val); -DQN_API int Dqn_SafeTruncateUSizeToI32 (Dqn_usize val); -DQN_API int Dqn_SafeTruncateUSizeToInt (Dqn_usize val); -DQN_API Dqn_isize Dqn_SafeTruncateUSizeToISize(Dqn_usize val); -DQN_API Dqn_isize Dqn_SafeTruncateI64ToISize (Dqn_i64 val); -DQN_API Dqn_u32 Dqn_SafeTruncateU64ToU32 (Dqn_u64 val); -DQN_API Dqn_u16 Dqn_SafeTruncateU64ToU16 (Dqn_u64 val); -DQN_API Dqn_u8 Dqn_SafeTruncateU64ToU8 (Dqn_u64 val); -DQN_API Dqn_i64 Dqn_SafeTruncateU64ToI64 (Dqn_u64 val); -DQN_API Dqn_i32 Dqn_SafeTruncateU64ToI32 (Dqn_u64 val); -DQN_API Dqn_i16 Dqn_SafeTruncateU64ToI16 (Dqn_u64 val); -DQN_API Dqn_i8 Dqn_SafeTruncateU64ToI8 (Dqn_u64 val); -DQN_API int Dqn_SafeTruncateU64ToInt (Dqn_u64 val); +DQN_API int64_t Dqn_Safe_AddI64 (int64_t a, int64_t b); +DQN_API int64_t Dqn_Safe_MulI64 (int64_t a, int64_t b); +DQN_API uint64_t Dqn_Safe_AddU64 (uint64_t a, uint64_t b); +DQN_API uint64_t Dqn_Safe_SubU64 (uint64_t a, uint64_t b); +DQN_API uint32_t Dqn_Safe_SubU32 (uint32_t a, uint32_t b); +DQN_API uint64_t Dqn_Safe_MulU64 (uint64_t a, uint64_t b); +DQN_API int Dqn_Safe_TruncateISizeToInt (Dqn_isize val); +DQN_API int32_t Dqn_Safe_TruncateISizeToI32 (Dqn_isize val); +DQN_API uint8_t Dqn_Safe_TruncateISizeToI8 (Dqn_isize val); +DQN_API uint32_t Dqn_Safe_TruncateUSizeToU32 (Dqn_usize val); +DQN_API int32_t Dqn_Safe_TruncateUSizeToI32 (Dqn_usize val); +DQN_API int Dqn_Safe_TruncateUSizeToInt (Dqn_usize val); +DQN_API Dqn_isize Dqn_Safe_TruncateUSizeToISize(Dqn_usize val); +DQN_API Dqn_isize Dqn_Safe_TruncateI64ToISize (uint64_t val); +DQN_API uint32_t Dqn_Safe_TruncateU64ToU32 (uint64_t val); +DQN_API uint16_t Dqn_Safe_TruncateU64ToU16 (uint64_t val); +DQN_API uint8_t Dqn_Safe_TruncateU64ToU8 (uint64_t val); +DQN_API uint64_t Dqn_Safe_TruncateU64ToI64 (uint64_t val); +DQN_API int32_t Dqn_Safe_TruncateU64ToI32 (uint64_t val); +DQN_API int16_t Dqn_Safe_TruncateU64ToI16 (uint64_t val); +DQN_API uint8_t Dqn_Safe_TruncateU64ToI8 (uint64_t val); +DQN_API int Dqn_Safe_TruncateU64ToInt (uint64_t val); -// NOTE: Dqn_Char +// NOTE: Dqn_Char_ // ------------------------------------------------------------------------------------------------- -DQN_API bool Dqn_CharIsAlpha (char ch); -DQN_API bool Dqn_CharIsDigit (char ch); -DQN_API bool Dqn_CharIsAlphaNum (char ch); -DQN_API bool Dqn_CharIsWhitespace (char ch); -DQN_API bool Dqn_CharIsHex (char ch); -DQN_API Dqn_u8 Dqn_CharHexToU8 (char ch); -DQN_API char Dqn_CharToHex (char ch); -DQN_API char Dqn_CharToHexUnchecked(char ch); -DQN_API char Dqn_CharToLower (char ch); +DQN_API bool Dqn_Char_IsAlpha (char ch); +DQN_API bool Dqn_Char_IsDigit (char ch); +DQN_API bool Dqn_Char_IsAlphaNum (char ch); +DQN_API bool Dqn_Char_IsWhitespace (char ch); +DQN_API bool Dqn_Char_IsHex (char ch); +DQN_API uint8_t Dqn_Char_HexToU8 (char ch); +DQN_API char Dqn_Char_ToHex (char ch); +DQN_API char Dqn_Char_ToHexUnchecked(char ch); +DQN_API char Dqn_Char_ToLower (char ch); -// NOTE: Dqn_Char +// NOTE: Dqn_UTF // ------------------------------------------------------------------------------------------------- -DQN_API int Dqn_UTF8EncodeCodepoint(Dqn_u8 utf8[4], Dqn_u32 codepoint); -DQN_API int Dqn_UTF16EncodeCodepoint(Dqn_u16 utf16[2], Dqn_u32 codepoint); +DQN_API int Dqn_UTF8_EncodeCodepoint(uint8_t utf8[4], uint32_t codepoint); +DQN_API int Dqn_UTF16_EncodeCodepoint(uint16_t utf16[2], uint32_t codepoint); #if defined(DQN_WITH_HEX) -// NOTE: Dqn_Hex +// NOTE: Dqn_Hex_ // ------------------------------------------------------------------------------------------------- -DQN_API char const *Dqn_HexCStringTrimSpaceAnd0xPrefix(char const *hex, Dqn_isize size, Dqn_isize *real_size); -DQN_API Dqn_String8 Dqn_HexStringTrimSpaceAnd0xPrefix (Dqn_String8 const string); +DQN_API char const *Dqn_Hex_CStringTrimSpaceAnd0xPrefix(char const *hex, Dqn_isize size, Dqn_isize *real_size); +DQN_API Dqn_String8 Dqn_Hex_StringTrimSpaceAnd0xPrefix (Dqn_String8 const string); // Convert a hexadecimal string a 64 bit value. Asserts if the hex string is too // big to be converted into a 64 bit number. -DQN_API Dqn_u64 Dqn_HexCStringToU64(char const *hex, Dqn_isize size); -DQN_API Dqn_u64 Dqn_HexStringToU64(Dqn_String8 hex); +DQN_API uint64_t Dqn_Hex_CStringToU64(char const *hex, Dqn_isize size); +DQN_API uint64_t Dqn_Hex_StringToU64(Dqn_String8 hex); // Convert a binary buffer into its hex representation into dest. The dest // buffer must be large enough to contain the hex representation, i.e. // atleast src_size * 2). -DQN_API void Dqn_HexBytesToHex(void const *src, int src_size, char *dest, int dest_size); +DQN_API void Dqn_Hex_BytesToHex(void const *src, int src_size, char *dest, int dest_size); // Convert a hex buffer into its binary representation into dest. The dest // buffer must be large enough to contain the binary representation, i.e. // atleast ceil(hex_size / 2). // hex_size: The size of the hex buffer. This function can handle an odd size // hex string i.e. parsing "fff" works. -DQN_API void Dqn_HexToBytes(char const *hex, int hex_size, void *dest, int dest_size); +DQN_API void Dqn_Hex_ToBytes(char const *hex, int hex_size, void *dest, int dest_size); // Convert a series of bytes into a string. The CString variant returns a string // with length (size * 2) with 1 extra byte for the null-terminator. The // return: nullptr/invalid Dqn_String8 if the allocation failed, otherwise the hex string in ASCII. -DQN_API char *Dqn_HexBytesToHexCStringArena(void const *bytes, Dqn_isize size, Dqn_Arena *arena); -DQN_API Dqn_String8 Dqn_HexBytesToHexStringArena(void const *bytes, Dqn_isize size, Dqn_Arena *arena); -DQN_API char *Dqn_HexU8ArrayToHexCStringArena(Dqn_Array const array, Dqn_Arena *arena); -DQN_API Dqn_String8 Dqn_HexU8ArrayToHexStringArena(Dqn_Array const array, Dqn_Arena *arena); +DQN_API char *Dqn_Hex_BytesToHexCStringArena(void const *bytes, Dqn_isize size, Dqn_Arena *arena); +DQN_API Dqn_String8 Dqn_Hex_BytesToHexStringArena(void const *bytes, Dqn_isize size, Dqn_Arena *arena); +DQN_API char *Dqn_Hex_U8ArrayToHexCStringArena(Dqn_Array const array, Dqn_Arena *arena); +DQN_API Dqn_String8 Dqn_Hex_U8ArrayToHexStringArena(Dqn_Array const array, Dqn_Arena *arena); // Convert a char string to a binary representation without any checks except assertions in debug. // A leading "0x" is permitted and will be skipped as well as odd-sized strings. -DQN_API Dqn_u8 *Dqn_HexCStringToU8Bytes(char const *hex, Dqn_isize size, Dqn_isize *real_size, Dqn_Arena *arena); -DQN_API Dqn_Array Dqn_HexCStringToU8Array(char const *hex, Dqn_isize size, Dqn_Arena *arena); -DQN_API Dqn_Array Dqn_HexStringToU8Array(Dqn_String8 const hex, Dqn_Arena *arena); +DQN_API uint8_t *Dqn_Hex_CStringToU8Bytes(char const *hex, Dqn_isize size, Dqn_isize *real_size, Dqn_Arena *arena); +DQN_API Dqn_Array Dqn_Hex_CStringToU8Array(char const *hex, Dqn_isize size, Dqn_Arena *arena); +DQN_API Dqn_Array Dqn_Hex_StringToU8Array(Dqn_String8 const hex, Dqn_Arena *arena); #endif // DQN_WITH_HEX -// NOTE: Dqn_Str +// NOTE: Dqn_CString8 // ------------------------------------------------------------------------------------------------- -DQN_API bool Dqn_CStringEquals(char const *a, char const *b, Dqn_isize a_size = -1, Dqn_isize b_size = -1); -DQN_API char const *Dqn_CStringFindMulti(char const *buf, char const *find_list[], Dqn_isize const *find_string_sizes, Dqn_isize find_size, Dqn_isize *match_index, Dqn_isize buf_size = -1); -DQN_API char const *Dqn_CStringFind(char const *buf, char const *find, Dqn_isize buf_size = -1, Dqn_isize find_size = -1, bool case_insensitive = false); -DQN_API char const *Dqn_CStringFileNameFromPath(char const *path, Dqn_isize size = -1, Dqn_isize *file_name_size = nullptr); -DQN_API Dqn_isize Dqn_CStringSize(char const *a); -DQN_API bool Dqn_CStringMatch(char const *src, char const *find, int find_size); -DQN_API char const *Dqn_CStringSkipToChar(char const *src, char ch); -DQN_API char const *Dqn_CStringSkipToNextAlphaNum(char const *src); -DQN_API char const *Dqn_CStringSkipToNextDigit(char const *src); -DQN_API char const *Dqn_CStringSkipToNextChar(char const *src); -DQN_API char const *Dqn_CStringSkipToNextWord(char const *src); -DQN_API char const *Dqn_CStringSkipToNextWhitespace(char const *src); -DQN_API char const *Dqn_CStringSkipWhitespace(char const *src); -DQN_API char const *Dqn_CStringSkipToCharInPlace(char const **src, char ch); -DQN_API char const *Dqn_CStringSkipToNextAlphaNumInPlace(char const **src); -DQN_API char const *Dqn_CStringSkipToNextCharInPlace(char const **src); -DQN_API char const *Dqn_CStringSkipToNextWhitespaceInPlace(char const **src); -DQN_API char const *Dqn_CStringSkipToNextWordInPlace(char const **src); -DQN_API char const *Dqn_CStringSkipWhitespaceInPlace(char const **src); -DQN_API char const *Dqn_CStringTrimWhitespaceAround(char const *src, Dqn_isize size, Dqn_isize *new_size); -DQN_API char const *Dqn_CStringTrimPrefix(char const *src, Dqn_isize size, char const *prefix, Dqn_isize prefix_size, Dqn_isize *trimmed_size); -DQN_API bool Dqn_CStringIsAllDigits(char const *src, Dqn_isize size); +/// Calculate the size of a cstring literal/array at compile time +/// @param literal The cstring literal/array to calculate the size for +/// @return The size of the cstring not including the null-terminating byte +template constexpr Dqn_usize Dqn_CString8_ArrayCount(char const (&literal)[N]) { (void)literal; return N - 1; } + +/// @copybrief Dqn_CString8_ArrayCount +template constexpr Dqn_isize Dqn_CString8_ArrayCountI(char const (&literal)[N]) { (void)literal; return N - 1; } + +/// @copybrief Dqn_CString8_ArrayCount +template constexpr Dqn_isize Dqn_CString8_ArrayCountInt(char const (&literal)[N]) { (void)literal; return N - 1; } + +DQN_API bool Dqn_CString8_Equals(char const *a, char const *b, Dqn_isize a_size = -1, Dqn_isize b_size = -1); +DQN_API char const *Dqn_CString8_FindMulti(char const *buf, char const *find_list[], Dqn_isize const *find_string_sizes, Dqn_isize find_size, Dqn_isize *match_index, Dqn_isize buf_size = -1); +DQN_API char const *Dqn_CString8_Find(char const *buf, char const *find, Dqn_isize buf_size = -1, Dqn_isize find_size = -1, bool case_insensitive = false); +DQN_API char const *Dqn_CString8_FileNameFromPath(char const *path, Dqn_isize size = -1, Dqn_isize *file_name_size = nullptr); +DQN_API Dqn_isize Dqn_CString8_Size(char const *a); +DQN_API bool Dqn_CString8_Match(char const *src, char const *find, int find_size); +DQN_API char const *Dqn_CString8_SkipToChar(char const *src, char ch); +DQN_API char const *Dqn_CString8_SkipToNextAlphaNum(char const *src); +DQN_API char const *Dqn_CString8_SkipToNextDigit(char const *src); +DQN_API char const *Dqn_CString8_SkipToNextChar(char const *src); +DQN_API char const *Dqn_CString8_SkipToNextWord(char const *src); +DQN_API char const *Dqn_CString8_SkipToNextWhitespace(char const *src); +DQN_API char const *Dqn_CString8_SkipWhitespace(char const *src); +DQN_API char const *Dqn_CString8_SkipToCharInPlace(char const **src, char ch); +DQN_API char const *Dqn_CString8_SkipToNextAlphaNumInPlace(char const **src); +DQN_API char const *Dqn_CString8_SkipToNextCharInPlace(char const **src); +DQN_API char const *Dqn_CString8_SkipToNextWhitespaceInPlace(char const **src); +DQN_API char const *Dqn_CString8_SkipToNextWordInPlace(char const **src); +DQN_API char const *Dqn_CString8_SkipWhitespaceInPlace(char const **src); +DQN_API char const *Dqn_CString8_TrimWhitespaceAround(char const *src, Dqn_isize size, Dqn_isize *new_size); +DQN_API char const *Dqn_CString8_TrimPrefix(char const *src, Dqn_isize size, char const *prefix, Dqn_isize prefix_size, Dqn_isize *trimmed_size); +DQN_API bool Dqn_CString8_IsAllDigits(char const *src, Dqn_isize size); // separator: The separator between the thousand-th digits, i.e. separator = ',' converts '1,234' to '1234'. -DQN_API Dqn_u64 Dqn_CStringToU64(char const *buf, Dqn_isize size = -1, char separator = ','); -DQN_API Dqn_i64 Dqn_CStringToI64(char const *buf, Dqn_isize size = -1, char separator = ','); +DQN_API uint64_t Dqn_CString8_ToU64(char const *buf, Dqn_isize size = -1, char separator = ','); +DQN_API uint64_t Dqn_CString8_ToI64(char const *buf, Dqn_isize size = -1, char separator = ','); -DQN_API Dqn_isize Dqn_LStringSize(wchar_t const *a); +DQN_API Dqn_isize Dqn_CString16_Size(wchar_t const *a); -// NOTE: Dqn_Fs +// NOTE: Dqn_Fs_ // ------------------------------------------------------------------------------------------------- -struct Dqn_FsInfo +struct Dqn_Fs_Info { - Dqn_u64 create_time_in_s; - Dqn_u64 last_write_time_in_s; - Dqn_u64 last_access_time_in_s; - Dqn_u64 size; + uint64_t create_time_in_s; + uint64_t last_write_time_in_s; + uint64_t last_access_time_in_s; + uint64_t size; operator bool() const { return size > 0; } }; // TODO(dqn): We should have a Dqn_String8 interface and a CString interface -DQN_API bool Dqn_FsExists(Dqn_String8 path); -DQN_API bool Dqn_FsDirExists(Dqn_String8 path); -DQN_API Dqn_FsInfo Dqn_FsGetInfo(Dqn_String8 path); -DQN_API bool Dqn_FsCopy(Dqn_String8 src, Dqn_String8 dest, bool overwrite); +DQN_API bool Dqn_Fs_Exists(Dqn_String8 path); +DQN_API bool Dqn_Fs_DirExists(Dqn_String8 path); +DQN_API Dqn_Fs_Info Dqn_Fs_GetInfo(Dqn_String8 path); +DQN_API bool Dqn_Fs_Copy(Dqn_String8 src, Dqn_String8 dest, bool overwrite); -DQN_API bool Dqn_FsMakeDir(Dqn_String8 path); -DQN_API bool Dqn_FsMove(Dqn_String8 src, Dqn_String8 dest, bool overwrite); +DQN_API bool Dqn_Fs_MakeDir(Dqn_String8 path); +DQN_API bool Dqn_Fs_Move(Dqn_String8 src, Dqn_String8 dest, bool overwrite); // TODO(dqn): This doesn't work on directories unless you delete the files // in that directory first. -DQN_API bool Dqn_FsDelete(Dqn_String8 path); +DQN_API bool Dqn_Fs_Delete(Dqn_String8 path); // file_size: (Optional) The size of the file in bytes, the allocated buffer is (file_size + 1 [null terminator]) in bytes. // allocator: (Optional) When null, the buffer is allocated with DQN_MALLOC, result should be freed with DQN_FREE. // return: nullptr if allocation failed. -DQN_API bool Dqn_FsWriteFileCString8(char const *path, Dqn_isize path_size, char const *buffer, Dqn_isize buffer_size); -DQN_API bool Dqn_FsWriteFileString8(Dqn_String8 path, Dqn_String8 buffer); +DQN_API bool Dqn_Fs_WriteCString8ToFileCString8(char const *file_path, Dqn_isize file_path_size, char const *buffer, Dqn_isize buffer_size); +DQN_API bool Dqn_Fs_WriteString8ToFileString8(Dqn_String8 file_path, Dqn_String8 buffer); -#define Dqn_FsReadFileCString8ToCString8Arena(path, path_size, file_size, arena) Dqn_FsReadFileCString8ToCString8ArenaTagged(nullptr, path, path_size, file_size, arena) -#define Dqn_FsReadFileCString8ToCString8ArenaTagged(tag, path, path_size, arena) Dqn_FsReadFileCString8ToCString8Arena_(DQN_CALL_SITE(tag) path, path_size, arena) -DQN_API char *Dqn_FsReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS char const *path, Dqn_isize path_size, Dqn_isize *file_size, Dqn_Arena *arena); +#define Dqn_Fs_ReadFileCString8ToCString8Arena(file_path, file_path_size, file_size, arena) Dqn_Fs_ReadFileCString8ToCString8ArenaTagged(nullptr, file_path, file_path_size, file_size, arena) +#define Dqn_Fs_ReadFileCString8ToCString8ArenaTagged(tag, path, file_path_size, arena) Dqn_Fs_ReadFileCString8ToCString8Arena_(DQN_CALL_SITE(tag) file_path, file_path_size, arena) +DQN_API char *Dqn_Fs_ReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS char const *file_path, Dqn_isize path_size, Dqn_isize *file_size, Dqn_Arena *arena); -#define Dqn_FsReadFileCString8ToString8Arena(path, path_size, arena) Dqn_FsReadFileCString8ToString8ArenaTagged(nullptr, path, path_size, arena) -#define Dqn_FsReadFileCString8ToString8ArenaTagged(tag, path, path_size, arena) Dqn_FsReadFileCString8ToString8Arena_(DQN_CALL_SITE(tag) path, path_size, arena) -DQN_API Dqn_String8 Dqn_FsReadFileCString8ToString8Arena_(DQN_CALL_SITE_ARGS char const *path, Dqn_isize path_size, Dqn_Arena *arena); +#define Dqn_Fs_ReadFileCString8ToString8Arena(file_path, file_path_size, arena) Dqn_Fs_ReadFileCString8ToString8ArenaTagged(nullptr, file_path, file_path_size, arena) +#define Dqn_Fs_ReadFileCString8ToString8ArenaTagged(tag, file_path, file_path_size, arena) Dqn_Fs_ReadFileCString8ToString8Arena_(DQN_CALL_SITE(tag) file_path, file_path_size, arena) +DQN_API Dqn_String8 Dqn_Fs_ReadFileCString8ToString8Arena_(DQN_CALL_SITE_ARGS char const *file_path, Dqn_isize path_size, Dqn_Arena *arena); -#define Dqn_FsReadFileString8ToString8Arena(path, arena) Dqn_FsReadFileString8ToString8ArenaTagged(nullptr, path, arena) -#define Dqn_FsReadFileString8ToString8ArenaTagged(tag, path, arena) Dqn_FsReadFileString8ToString8Arena_(DQN_CALL_SITE(tag) path, arena) -DQN_API Dqn_String8 Dqn_FsReadFileString8ToString8Arena_(DQN_CALL_SITE_ARGS Dqn_String8 path, Dqn_Arena *arena); +#define Dqn_Fs_ReadFileString8ToString8Arena(file_path, arena) Dqn_Fs_ReadFileString8ToString8ArenaTagged(nullptr, file_path, arena) +#define Dqn_Fs_ReadFileString8ToString8ArenaTagged(tag, file_path, arena) Dqn_Fs_ReadFileString8ToString8Arena_(DQN_CALL_SITE(tag) file_path, arena) +DQN_API Dqn_String8 Dqn_Fs_ReadFileString8ToString8Arena_(DQN_CALL_SITE_ARGS Dqn_String8 file_path, Dqn_Arena *arena); // NOTE: Date // ------------------------------------------------------------------------------------------------- struct Dqn_DateHMSTimeString { - char date[DQN_ARRAY_UCOUNT("YYYY-MM-SS")]; - Dqn_i8 date_size; + char date[DQN_ARRAY_UCOUNT("YYYY-MM-SS")]; + uint8_t date_size; - char hms[DQN_ARRAY_UCOUNT("HH:MM:SS")]; - Dqn_i8 hms_size; + char hms[DQN_ARRAY_UCOUNT("HH:MM:SS")]; + uint8_t hms_size; }; struct Dqn_DateHMSTime { - Dqn_i8 day; - Dqn_i8 month; - Dqn_i16 year; + uint8_t day; + uint8_t month; + int16_t year; - Dqn_i8 hour; - Dqn_i8 minutes; - Dqn_i8 seconds; + uint8_t hour; + uint8_t minutes; + uint8_t seconds; }; // @return The current time at the point of invocation -DQN_API Dqn_DateHMSTime Dqn_DateHMSLocalTimeNow(); -DQN_API Dqn_DateHMSTimeString Dqn_DateHMSLocalTimeStringNow(char date_separator = '-', char hms_separator = ':'); -DQN_API Dqn_DateHMSTimeString Dqn_DateHMSLocalTimeString(Dqn_DateHMSTime time, char date_separator = '-', char hms_separator = ':'); +DQN_API Dqn_DateHMSTime Dqn_Date_HMSLocalTimeNow(); +DQN_API Dqn_DateHMSTimeString Dqn_Date_HMSLocalTimeStringNow(char date_separator = '-', char hms_separator = ':'); +DQN_API Dqn_DateHMSTimeString Dqn_Date_HMSLocalTimeString(Dqn_DateHMSTime time, char date_separator = '-', char hms_separator = ':'); // return: The time elapsed since Unix epoch (1970-01-01T00:00:00Z) in seconds -DQN_API Dqn_u64 Dqn_DateEpochTime(); +DQN_API uint64_t Dqn_Date_EpochTime(); // NOTE: OS // ------------------------------------------------------------------------------------------------- // Generate cryptographically secure bytes -DQN_API bool Dqn_OSSecureRNGBytes(void *buffer, Dqn_u32 size); +DQN_API bool Dqn_OS_SecureRNGBytes(void *buffer, uint32_t size); // return: The directory without the trailing '/' or ('\' for windows). Empty // string with a nullptr if it fails. -DQN_API Dqn_String8 Dqn_OSEXEDir(Dqn_Allocator allocator); +DQN_API Dqn_String8 Dqn_OS_EXEDir(Dqn_Allocator allocator); // NOTE: Utiltiies // ------------------------------------------------------------------------------------------------- DQN_API void Dqn_SleepMs(Dqn_uint milliseconds); -DQN_API Dqn_u64 Dqn_PerfCounterNow (); -DQN_API Dqn_f64 Dqn_PerfCounterS (Dqn_u64 begin, Dqn_u64 end); -DQN_API Dqn_f64 Dqn_PerfCounterMs (Dqn_u64 begin, Dqn_u64 end); -DQN_API Dqn_f64 Dqn_PerfCounterMicroS(Dqn_u64 begin, Dqn_u64 end); -DQN_API Dqn_f64 Dqn_PerfCounterNs (Dqn_u64 begin, Dqn_u64 end); +DQN_API uint64_t Dqn_Perf_CounterNow (); +DQN_API Dqn_f64 Dqn_Perf_CounterS (uint64_t begin, uint64_t end); +DQN_API Dqn_f64 Dqn_Perf_CounterMs (uint64_t begin, uint64_t end); +DQN_API Dqn_f64 Dqn_Perf_CounterMicroS(uint64_t begin, uint64_t end); +DQN_API Dqn_f64 Dqn_Perf_CounterNs (uint64_t begin, uint64_t end); struct Dqn_Timer // NOTE: Uses the PerfCounter API { - Dqn_u64 start; - Dqn_u64 end; + uint64_t start; + uint64_t end; }; -DQN_API Dqn_Timer Dqn_TimerBegin (); -DQN_API void Dqn_TimerEnd (Dqn_Timer *timer); -DQN_API Dqn_f64 Dqn_TimerS (Dqn_Timer timer); -DQN_API Dqn_f64 Dqn_TimerMs (Dqn_Timer timer); -DQN_API Dqn_f64 Dqn_TimerMicroS(Dqn_Timer timer); -DQN_API Dqn_f64 Dqn_TimerNs (Dqn_Timer timer); +DQN_API Dqn_Timer Dqn_Timer_Begin (); +DQN_API void Dqn_Timer_End (Dqn_Timer *timer); +DQN_API Dqn_f64 Dqn_Timer_S (Dqn_Timer timer); +DQN_API Dqn_f64 Dqn_Timer_Ms (Dqn_Timer timer); +DQN_API Dqn_f64 Dqn_Timer_MicroS(Dqn_Timer timer); +DQN_API Dqn_f64 Dqn_Timer_Ns (Dqn_Timer timer); struct Dqn_U64Str { // Points to the start of the str in the buffer, not necessarily buf since // we write into the buffer in reverse char *str; - char buf[27]; // NOTE(dqn): 27 is the maximum size of Dqn_u64 including commas + char buf[27]; // NOTE(dqn): 27 is the maximum size of uint64_t including commas int len; }; @@ -2079,8 +2075,8 @@ struct Dqn_U64Str // into the string buffer backwards and return a the char pointer to it, we // should just write it in and memory copy it back so that it's at the start of // the buffer. See Dqn_MoneyString for an example of this. -DQN_API char *Dqn_U64ToStr (Dqn_u64 val, Dqn_U64Str *result, bool comma_sep); -DQN_API char *Dqn_U64ToTempStr(Dqn_u64 val, bool comma_sep = true); +DQN_API char *Dqn_U64ToStr (uint64_t val, Dqn_U64Str *result, bool comma_sep); +DQN_API char *Dqn_U64ToTempStr(uint64_t val, bool comma_sep = true); // NOTE: Dqn_ThreadContext // ------------------------------------------------------------------------------------------------- @@ -2091,37 +2087,36 @@ DQN_API char *Dqn_U64ToTempStr(Dqn_u64 val, bool comma_sep = true); #define DQN_THREAD_CONTEXT_ARENAS 2 #endif -struct Dqn_ThreadScratchData +struct Dqn_ThreadArena { - Dqn_Arena arena; // The arena for this thread's scratch arena - Dqn_u8 arena_stats_index; // Index into the library's thread context array + Dqn_Arena arena; ///< The arena for this thread's scratch arena + uint8_t arena_stats_index; ///< Index into the library's thread context array }; struct Dqn_ThreadContext { - Dqn_b32 init; - // Thread data that is handed out when the thread context is requested. - Dqn_ThreadScratchData scratch_data[DQN_THREAD_CONTEXT_ARENAS]; + Dqn_b32 init; + Dqn_ThreadArena temp_arenas[DQN_THREAD_CONTEXT_ARENAS]; ///< Temporary arena's for the calling thread }; -struct Dqn_ThreadScratch +struct Dqn_ThreadTempArena { - Dqn_ThreadScratch(Dqn_ThreadScratchData *data) + Dqn_ThreadTempArena(Dqn_ThreadArena *data) { destructed = false; arena = &data->arena; arena_stats_index = data->arena_stats_index; - arena_temp_memory = Dqn_ArenaBeginTempMemory(arena); + arena_temp_memory = Dqn_Arena_BeginTempMemory(arena); } - ~Dqn_ThreadScratch() + ~Dqn_ThreadTempArena() { #if defined(DQN_DEBUG_THREAD_CONTEXT) dqn_lib_.thread_context_arena_stats[arena_stats_index] = arena->stats; #endif DQN_ASSERT(destructed == false); - Dqn_ArenaEndTempMemory(arena_temp_memory); + Dqn_Arena_EndTempMemory(arena_temp_memory); destructed = true; } @@ -2142,84 +2137,84 @@ struct Dqn_ThreadScratch /// /// @param[in] conflict_arena A pointer to the arena currently being used in the /// function -DQN_API Dqn_ThreadScratch Dqn_ThreadGetScratch(const void *conflict_arena = nullptr); +DQN_API Dqn_ThreadTempArena Dqn_Thread_TempArena(const void *conflict_arena = nullptr); // Get the current thread's context- this contains all the metadata for managing -// the thread scratch data. In general you probably want Dqn_ThreadGetScratch() +// the thread scratch data. In general you probably want Dqn_Thread_TempArena() // which ensures you get a usable scratch arena for temporary allocations // without having to worry about selecting the right arena from the state. -DQN_API Dqn_ThreadContext *Dqn_ThreadGetContext(); +DQN_API Dqn_ThreadContext *Dqn_Thread_Context(); #if defined(DQN_WITH_JSON_WRITER) -// NOTE: Dqn_JSONWriter +// NOTE: Dqn_JSONWriter_ // ------------------------------------------------------------------------------------------------- // TODO(dqn): We need to write tests for this -struct Dqn_JSONWriter +struct Dqn_JSONWriter_ { - Dqn_u16 parent_field_count_stack[32]; + uint16_t parent_field_count_stack[32]; int parent_field_count_stack_size; Dqn_String8Builder builder; int indent_level; int spaces_per_indent; }; -#define Dqn_JSONWriterObject(writer) \ - DQN_DEFER_LOOP(Dqn_JSONWriterObjectBegin(writer), \ - Dqn_JSONWriterObjectEnd(writer)) +#define Dqn_JSONWriter_Object(writer) \ + DQN_DEFER_LOOP(Dqn_JSONWriter_ObjectBegin(writer), \ + Dqn_JSONWriter_ObjectEnd(writer)) -#define Dqn_JSONWriterObjectNamed(writer, name) \ - DQN_DEFER_LOOP(Dqn_JSONWriterObjectBeginNamed(writer, name), \ - Dqn_JSONWriterObjectEnd(writer)) +#define Dqn_JSONWriter_ObjectNamed(writer, name) \ + DQN_DEFER_LOOP(Dqn_JSONWriter_ObjectBeginNamed(writer, name), \ + Dqn_JSONWriter_ObjectEnd(writer)) -#define Dqn_JSONWriterArray(writer) \ - DQN_DEFER_LOOP(Dqn_JSONWriterArrayBegin(writer), \ - Dqn_JSONWriterArrayEnd(writer)) +#define Dqn_JSONWriter_Array(writer) \ + DQN_DEFER_LOOP(Dqn_JSONWriter_ArrayBegin(writer), \ + Dqn_JSONWriter_ArrayEnd(writer)) -#define Dqn_JSONWriterArrayNamed(writer, name) \ - DQN_DEFER_LOOP(Dqn_JSONWriterArrayBeginNamed(writer, name), \ - Dqn_JSONWriterArrayEnd(writer)) +#define Dqn_JSONWriter_ArrayNamed(writer, name) \ + DQN_DEFER_LOOP(Dqn_JSONWriter_ArrayBeginNamed(writer, name), \ + Dqn_JSONWriter_ArrayEnd(writer)) -DQN_API Dqn_JSONWriter Dqn_JSONWriterInit(Dqn_Arena *arena, int spaces_per_indent); -DQN_API Dqn_String8 Dqn_JSONWriterBuild(Dqn_JSONWriter *writer, Dqn_Arena *arena); +DQN_API Dqn_JSONWriter_ Dqn_JSONWriter_Init(Dqn_Arena *arena, int spaces_per_indent); +DQN_API Dqn_String8 Dqn_JSONWriter_Build(Dqn_JSONWriter_ *writer, Dqn_Arena *arena); -DQN_API void Dqn_JSONWriterObjectBeginNamed(Dqn_JSONWriter *writer, Dqn_String8 name); -DQN_API void Dqn_JSONWriterObjectBegin(Dqn_JSONWriter *writer); -DQN_API void Dqn_JSONWriterObjectEnd(Dqn_JSONWriter *writer); +DQN_API void Dqn_JSONWriter_ObjectBeginNamed(Dqn_JSONWriter_ *writer, Dqn_String8 name); +DQN_API void Dqn_JSONWriter_ObjectBegin(Dqn_JSONWriter_ *writer); +DQN_API void Dqn_JSONWriter_ObjectEnd(Dqn_JSONWriter_ *writer); -DQN_API void Dqn_JSONWriterArrayBeginNamed(Dqn_JSONWriter *writer, Dqn_String8 name); -DQN_API void Dqn_JSONWriterArrayBegin(Dqn_JSONWriter *writer, Dqn_String8 name); -DQN_API void Dqn_JSONWriterArrayEnd(Dqn_JSONWriter *writer); +DQN_API void Dqn_JSONWriter_ArrayBeginNamed(Dqn_JSONWriter_ *writer, Dqn_String8 name); +DQN_API void Dqn_JSONWriter_ArrayBegin(Dqn_JSONWriter_ *writer, Dqn_String8 name); +DQN_API void Dqn_JSONWriter_ArrayEnd(Dqn_JSONWriter_ *writer); -DQN_API void Dqn_JSONWriterStringNamed(Dqn_JSONWriter *writer, Dqn_String8 key, Dqn_String8 value); -DQN_API void Dqn_JSONWriterString(Dqn_JSONWriter *writer, Dqn_String8 value); +DQN_API void Dqn_JSONWriter_StringNamed(Dqn_JSONWriter_ *writer, Dqn_String8 key, Dqn_String8 value); +DQN_API void Dqn_JSONWriter_String(Dqn_JSONWriter_ *writer, Dqn_String8 value); -DQN_API void Dqn_JSONWriterU64Named(Dqn_JSONWriter *writer, Dqn_String8 key, Dqn_u64 value); -DQN_API void Dqn_JSONWriterU64(Dqn_JSONWriter *writer, Dqn_u64 value); +DQN_API void Dqn_JSONWriter_U64Named(Dqn_JSONWriter_ *writer, Dqn_String8 key, uint64_t value); +DQN_API void Dqn_JSONWriter_U64(Dqn_JSONWriter_ *writer, uint64_t value); -DQN_API void Dqn_JSONWriterI64Named(Dqn_JSONWriter *writer, Dqn_String8 key, Dqn_i64 value); -DQN_API void Dqn_JSONWriterI64(Dqn_JSONWriter *writer, Dqn_i64 value); +DQN_API void Dqn_JSONWriter_I64Named(Dqn_JSONWriter_ *writer, Dqn_String8 key, uint64_t value); +DQN_API void Dqn_JSONWriter_I64(Dqn_JSONWriter_ *writer, uint64_t value); // decimal_places: When < 0 show the default number of decimal places // When >=0 show the specified amount of decimal places -DQN_API void Dqn_JSONWriterF64Named(Dqn_JSONWriter *writer, Dqn_String8 key, Dqn_f64 value, int decimal_places = -1); -DQN_API void Dqn_JSONWriterF64(Dqn_JSONWriter *writer, Dqn_f64 value, int decimal_places = -1); +DQN_API void Dqn_JSONWriter_F64Named(Dqn_JSONWriter_ *writer, Dqn_String8 key, Dqn_f64 value, int decimal_places = -1); +DQN_API void Dqn_JSONWriter_F64(Dqn_JSONWriter_ *writer, Dqn_f64 value, int decimal_places = -1); #endif // DQN_WITH_JSON_WRITER #if defined(DQN_OS_WIN32) -// NOTE: Dqn_Win +// NOTE: Dqn_Win_ // ------------------------------------------------------------------------------------------------- -struct Dqn_WinErrorMsg +struct Dqn_Win_ErrorMsg { unsigned long code; char data[DQN_KILOBYTES(64) - 1]; // Maximum error size unsigned long size; }; -DQN_API Dqn_WinErrorMsg Dqn_WinLastError(); +DQN_API Dqn_Win_ErrorMsg Dqn_Win_LastError(); // Call once at application start-up to ensure that the application is DPI aware // on Windows and ensure that application UI is scaled up appropriately for the // monitor. -DQN_API void Dqn_WinMakeProcessDPIAware(); +DQN_API void Dqn_Win_MakeProcessDPIAware(); // NOTE: Windows String8 To String16 // ----------------------------------------------------------------------------- @@ -2229,10 +2224,10 @@ DQN_API void Dqn_WinMakeProcessDPIAware(); // size required for conversion including space for the null-terminator. // This function *always* null-terminates the input buffer. // @return The number of u16's written/required for conversion. 0 if there was -// a conversion error and can be queried using 'Dqn_WinLastError' -DQN_API int Dqn_WinCString8ToCString16(const char *src, int src_size, wchar_t *dest, int dest_size); -DQN_API int Dqn_WinString8ToCString16(Dqn_String8 src, wchar_t* dest, int dest_size); -DQN_API Dqn_String16 Dqn_WinString8ToString16Allocator(Dqn_String8 src, Dqn_Allocator allocator); +// a conversion error and can be queried using 'Dqn_Win_LastError' +DQN_API int Dqn_Win_CString8ToCString16(const char *src, int src_size, wchar_t *dest, int dest_size); +DQN_API int Dqn_Win_String8ToCString16(Dqn_String8 src, wchar_t* dest, int dest_size); +DQN_API Dqn_String16 Dqn_Win_String8ToString16Allocator(Dqn_String8 src, Dqn_Allocator allocator); // NOTE: Windows String16 To String8 // ----------------------------------------------------------------------------- @@ -2242,11 +2237,11 @@ DQN_API Dqn_String16 Dqn_WinString8ToString16Allocator(Dqn_String8 src, Dqn_Allo // size required for conversion including space for the null-terminator. // This function *always* null-terminates the input buffer. // @return The number of u8's written/required for conversion. 0 if there was -// a conversion error and can be queried using 'Dqn_WinLastError' -DQN_API int Dqn_WinCString16ToCString8(const wchar_t *src, int src_size, char *dest, int dest_size); -DQN_API Dqn_String8 Dqn_WinCString16ToString8Allocator(const wchar_t *src, int src_size, Dqn_Allocator allocator); -DQN_API int Dqn_WinString16ToCString8(Dqn_String16 src, char *dest, int dest_size); -DQN_API Dqn_String8 Dqn_WinString16ToString8Allocator(Dqn_String16 src, Dqn_Allocator allocator); +// a conversion error and can be queried using 'Dqn_Win_LastError' +DQN_API int Dqn_Win_CString16ToCString8(const wchar_t *src, int src_size, char *dest, int dest_size); +DQN_API Dqn_String8 Dqn_Win_CString16ToString8Allocator(const wchar_t *src, int src_size, Dqn_Allocator allocator); +DQN_API int Dqn_Win_String16ToCString8(Dqn_String16 src, char *dest, int dest_size); +DQN_API Dqn_String8 Dqn_Win_String16ToString8Allocator(Dqn_String16 src, Dqn_Allocator allocator); // NOTE: Windows Executable Directory // ----------------------------------------------------------------------------- @@ -2258,34 +2253,34 @@ DQN_API Dqn_String8 Dqn_WinString16ToString8Allocator(Dqn_String16 src, Dqn_Allo // required buffer size for the directory. // @return The length of the executable directory string. If this return value // exceeds the capacity of the 'buffer', the 'buffer' is untouched. -DQN_API Dqn_isize Dqn_WinEXEDirW(wchar_t *buffer, Dqn_isize size); -DQN_API Dqn_String16 Dqn_WinEXEDirWArena(Dqn_Arena *arena); +DQN_API Dqn_isize Dqn_Win_EXEDirW(wchar_t *buffer, Dqn_isize size); +DQN_API Dqn_String16 Dqn_Win_EXEDirWArena(Dqn_Arena *arena); // size: (Optional) The size of the current directory string returned // suffix: (Optional) A suffix to append to the current working directory // suffix_size: (Optional) The size of the suffix to append -DQN_API Dqn_String8 Dqn_WinWorkingDir(Dqn_Allocator allocator, Dqn_String8 suffix); -DQN_API Dqn_String16 Dqn_WinWorkingDirW(Dqn_Allocator allocator, Dqn_String16 suffix); +DQN_API Dqn_String8 Dqn_Win_WorkingDir(Dqn_Allocator allocator, Dqn_String8 suffix); +DQN_API Dqn_String16 Dqn_Win_WorkingDirW(Dqn_Allocator allocator, Dqn_String16 suffix); -struct Dqn_WinFolderIteratorW +struct Dqn_Win_FolderIteratorW { void *handle; Dqn_String16 file_name; wchar_t file_name_buf[512]; }; -struct Dqn_WinFolderIterator +struct Dqn_Win_FolderIterator { void *handle; Dqn_String8 file_name; char file_name_buf[512]; }; -DQN_API bool Dqn_WinFolderIterate(Dqn_String8 path, Dqn_WinFolderIterator *it); -DQN_API bool Dqn_WinFolderWIterate(Dqn_String16 path, Dqn_WinFolderIteratorW *it); +DQN_API bool Dqn_Win_FolderIterate(Dqn_String8 path, Dqn_Win_FolderIterator *it); +DQN_API bool Dqn_Win_FolderWIterate(Dqn_String16 path, Dqn_Win_FolderIteratorW *it); #if defined(DQN_WITH_WIN_NET) -enum struct Dqn_WinNetHandleState +enum struct Dqn_Win_NetHandleState { Invalid, Initialised, @@ -2299,7 +2294,7 @@ enum struct Dqn_WinNetHandleState #define DQN_WIN_NET_HANDLE_DOWNLOAD_SIZE 4096 #endif -struct Dqn_WinNetHandle +struct Dqn_Win_NetHandle { // NOTE: We copy out the host name because it needs to be null-terminated. // Luckily, we can assume a DNS domain won't exceed 256 characters so this @@ -2328,7 +2323,7 @@ struct Dqn_WinNetHandle void *internet_open_handle; void *internet_connect_handle; void *http_handle; - Dqn_WinNetHandleState state; + Dqn_Win_NetHandleState state; }; // TODO(dqn): Useful options to expose in the handle @@ -2341,19 +2336,19 @@ struct Dqn_WinNetHandle // Initialise a new networking handle that is pointing to the specified URL. // The URL string must be null-terminated because Windows is a C API and // requires null-termination. -DQN_API Dqn_WinNetHandle Dqn_WinNetHandleInitCString(char const *url, int url_size); -DQN_API Dqn_WinNetHandle Dqn_WinNetHandleInitString(Dqn_String8 url); +DQN_API Dqn_Win_NetHandle Dqn_Win_NetHandleInitCString(char const *url, int url_size); +DQN_API Dqn_Win_NetHandle Dqn_Win_NetHandleInitString(Dqn_String8 url); -DQN_API void Dqn_WinNetHandleFinish(Dqn_WinNetHandle *handle); -DQN_API bool Dqn_WinNetHandleIsValid(Dqn_WinNetHandle const *handle); -DQN_API void Dqn_WinNetHandleSetUserAgentCString(Dqn_WinNetHandle *handle, char const *user_agent, int user_agent_size); -DQN_API bool Dqn_WinNetHandlePump(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size, char *dest, int dest_size, size_t *download_size); -DQN_API char * Dqn_WinNetHandlePumpToCString(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size, Dqn_Arena *arena, size_t *download_size); -DQN_API Dqn_String8 Dqn_WinNetHandlePumpToString(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size, Dqn_Arena *arena); +DQN_API void Dqn_Win_NetHandleFinish(Dqn_Win_NetHandle *handle); +DQN_API bool Dqn_Win_NetHandleIsValid(Dqn_Win_NetHandle const *handle); +DQN_API void Dqn_Win_NetHandleSetUserAgentCString(Dqn_Win_NetHandle *handle, char const *user_agent, int user_agent_size); +DQN_API bool Dqn_Win_NetHandlePump(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size, char *dest, int dest_size, size_t *download_size); +DQN_API char * Dqn_Win_NetHandlePumpToCString(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size, Dqn_Arena *arena, size_t *download_size); +DQN_API Dqn_String8 Dqn_Win_NetHandlePumpToString(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size, Dqn_Arena *arena); -DQN_API void Dqn_WinNetHandlePumpToCRTFile(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size, FILE *file); -DQN_API char *Dqn_WinNetHandlePumpToMallocCString(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size, size_t *download_size); -DQN_API Dqn_String8 Dqn_WinNetHandlePumpToMallocString(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size); +DQN_API void Dqn_Win_NetHandlePumpToCRTFile(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size, FILE *file); +DQN_API char *Dqn_Win_NetHandlePumpToMallocCString(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size, size_t *download_size); +DQN_API Dqn_String8 Dqn_Win_NetHandlePumpToMallocString(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size); #endif // DQN_WITH_WIN_NET #endif // DQN_OS_WIN32 @@ -2385,7 +2380,7 @@ DQN_API Dqn_String8 Dqn_WinNetHandlePumpToMallocString(Dqn_WinNetHandle *h struct Dqn_TimedBlock { char const *label; - Dqn_u64 tick; + uint64_t tick; }; // Initialise a timing block region, @@ -2398,7 +2393,7 @@ struct Dqn_TimedBlock // DQN_TIMED_BLOCK_INIT must have been called in a scope visible to the macro // prior. // label: The label to give to the timing record -#define DQN_TIMED_BLOCK_RECORD(label) timings_[timings_size_++] = {label, Dqn_PerfCounterNow()} +#define DQN_TIMED_BLOCK_RECORD(label) timings_[timings_size_++] = {label, Dqn_Perf_CounterNow()} // Dump the timing block via Dqn_Log #define DQN_TIMED_BLOCK_DUMP \ @@ -2408,14 +2403,14 @@ struct Dqn_TimedBlock { \ Dqn_TimedBlock t1 = timings_[timings_index_ + 0]; \ Dqn_TimedBlock t2 = timings_[timings_index_ + 1]; \ - DQN_LOG_P("%s -> %s: %fms", t1.label, t2.label, Dqn_PerfCounterMs(t1.tick, t2.tick)); \ + DQN_LOG_P("%s -> %s: %fms", t1.label, t2.label, Dqn_Perf_CounterMs(t1.tick, t2.tick)); \ } \ \ if (timings_size_ >= 1) \ { \ Dqn_TimedBlock t1 = timings_[0]; \ Dqn_TimedBlock t2 = timings_[timings_size_ - 1]; \ - DQN_LOG_P("%s -> %s (total): %fms", t1.label, t2.label, Dqn_PerfCounterMs(t1.tick, t2.tick)); \ + DQN_LOG_P("%s -> %s (total): %fms", t1.label, t2.label, Dqn_Perf_CounterMs(t1.tick, t2.tick)); \ } // NOTE: Hashing - Dqn_FNV1A[32|64] @@ -2425,8 +2420,8 @@ struct Dqn_TimedBlock // // char buffer1[128] = {random bytes}; // char buffer2[128] = {random bytes}; -// Dqn_u64 hash = Dqn_FNV1A64Hash(buffer1, sizeof(buffer1)); -// hash = Dqn_FNV1A64Iterate(buffer2, sizeof(buffer2), hash); // subsequent hashing +// uint64_t hash = Dqn_FNV1A64_Hash(buffer1, sizeof(buffer1)); +// hash = Dqn_FNV1A64_Iterate(buffer2, sizeof(buffer2), hash); // subsequent hashing // #ifndef DQN_FNV1A32_SEED #define DQN_FNV1A32_SEED 2166136261U @@ -2436,10 +2431,10 @@ struct Dqn_TimedBlock #define DQN_FNV1A64_SEED 14695981039346656037ULL #endif -DQN_API Dqn_u32 Dqn_FNV1A32Hash (void const *bytes, Dqn_isize size); -DQN_API Dqn_u64 Dqn_FNV1A64Hash (void const *bytes, Dqn_isize size); -DQN_API Dqn_u32 Dqn_FNV1A32Iterate (void const *bytes, Dqn_isize size, Dqn_u32 hash); -DQN_API Dqn_u64 Dqn_FNV1A64Iterate (void const *bytes, Dqn_isize size, Dqn_u64 hash); +DQN_API uint32_t Dqn_FNV1A32_Hash (void const *bytes, Dqn_isize size); +DQN_API uint64_t Dqn_FNV1A64_Hash (void const *bytes, Dqn_isize size); +DQN_API uint32_t Dqn_FNV1A32_Iterate (void const *bytes, Dqn_isize size, uint32_t hash); +DQN_API uint64_t Dqn_FNV1A64_Iterate (void const *bytes, Dqn_isize size, uint64_t hash); // NOTE: Hashing - Dqn_MurmurHash3 // ------------------------------------------------------------------------------------------------- @@ -2453,10 +2448,10 @@ DQN_API Dqn_u64 Dqn_FNV1A64Iterate (void const *bytes, Dqn_isize size, Dqn_u6 // compile and run any of them on any platform, but your performance with the // non-native version will be less than optimal. -struct Dqn_MurmurHash3128 { Dqn_u64 e[2]; }; +struct Dqn_MurmurHash3128 { uint64_t e[2]; }; -DQN_API Dqn_u32 Dqn_MurmurHash3x86_32 (void const *key, int len, Dqn_u32 seed); -DQN_API Dqn_MurmurHash3128 Dqn_MurmurHash3x64_128(void const *key, int len, Dqn_u32 seed); +DQN_API uint32_t Dqn_MurmurHash3x86_32 (void const *key, int len, uint32_t seed); +DQN_API Dqn_MurmurHash3128 Dqn_MurmurHash3x64_128(void const *key, int len, uint32_t seed); #define DQN_MURMUR_HASH3_U128_AS_U64(key, len, seed) (Dqn_MurmurHash3x64_128(key, len, seed).e[0]) // NOTE: Template Implementation @@ -2466,19 +2461,19 @@ DQN_API Dqn_MurmurHash3128 Dqn_MurmurHash3x64_128(void const *key, int len, Dqn_ // NOTE: Dqn_Map Template Implementation // ------------------------------------------------------------------------------------------------- template -Dqn_Map Dqn_MapInitWithArena(Dqn_Arena *arena, Dqn_isize size) +Dqn_Map Dqn_Map_InitWithArena(Dqn_Arena *arena, Dqn_isize size) { Dqn_Map result = {}; result.arena = arena; Dqn_isize final_size = size == 0 ? 4096 : size; - result.slots = Dqn_ArenaNewArray(arena, Dqn_MapEntry *, final_size, Dqn_ZeroMem_Yes); + result.slots = Dqn_Arena_NewArray(arena, Dqn_MapEntry *, final_size, Dqn_ZeroMem_Yes); if (result.slots) result.size = final_size; return result; } template -Dqn_MapEntry *Dqn_MapFindOrAdd(Dqn_Map *map, Dqn_u64 hash, Dqn_MapCollideRule rule) +Dqn_MapEntry *Dqn_Map_FindOrAdd(Dqn_Map *map, uint64_t hash, Dqn_MapCollideRule rule) { Dqn_isize index = hash % map->size; Dqn_MapEntry *result = map->slots[index]; @@ -2490,7 +2485,7 @@ Dqn_MapEntry *Dqn_MapFindOrAdd(Dqn_Map *map, Dqn_u64 hash, Dqn_MapCollideR result = result->next; else { map->chain_count++; - result->next = Dqn_ArenaNew(map->arena, Dqn_MapEntry, Dqn_ZeroMem_Yes); + result->next = Dqn_Arena_New(map->arena, Dqn_MapEntry, Dqn_ZeroMem_Yes); result = result->next; break; } @@ -2499,7 +2494,7 @@ Dqn_MapEntry *Dqn_MapFindOrAdd(Dqn_Map *map, Dqn_u64 hash, Dqn_MapCollideR result = nullptr; } } else { - result = Dqn_ArenaNew(map->arena, Dqn_MapEntry, Dqn_ZeroMem_Yes); + result = Dqn_Arena_New(map->arena, Dqn_MapEntry, Dqn_ZeroMem_Yes); map->count++; map->slots[index] = result; } @@ -2511,9 +2506,9 @@ Dqn_MapEntry *Dqn_MapFindOrAdd(Dqn_Map *map, Dqn_u64 hash, Dqn_MapCollideR } template -Dqn_MapEntry *Dqn_MapAdd(Dqn_Map *map, Dqn_u64 hash, T &value, Dqn_MapCollideRule rule) +Dqn_MapEntry *Dqn_Map_Add(Dqn_Map *map, uint64_t hash, T &value, Dqn_MapCollideRule rule) { - Dqn_MapEntry *result = Dqn_MapFindOrAdd(map, hash, rule); + Dqn_MapEntry *result = Dqn_Map_FindOrAdd(map, hash, rule); if (result) result->value = value; @@ -2521,9 +2516,9 @@ Dqn_MapEntry *Dqn_MapAdd(Dqn_Map *map, Dqn_u64 hash, T &value, Dqn_MapColl } template -Dqn_MapEntry *Dqn_MapAddCopy(Dqn_Map *map, Dqn_u64 hash, T const &value, Dqn_MapCollideRule rule) +Dqn_MapEntry *Dqn_Map_AddCopy(Dqn_Map *map, uint64_t hash, T const &value, Dqn_MapCollideRule rule) { - Dqn_MapEntry *result = Dqn_MapFindOrAdd(map, hash, rule); + Dqn_MapEntry *result = Dqn_Map_FindOrAdd(map, hash, rule); if (result) result->value = value; @@ -2531,7 +2526,7 @@ Dqn_MapEntry *Dqn_MapAddCopy(Dqn_Map *map, Dqn_u64 hash, T const &value, D } template -Dqn_MapEntry *Dqn_MapGet(Dqn_Map *map, Dqn_u64 hash) +Dqn_MapEntry *Dqn_Map_Get(Dqn_Map *map, uint64_t hash) { Dqn_isize index = hash % map->size; Dqn_MapEntry *result = nullptr; @@ -2546,7 +2541,7 @@ Dqn_MapEntry *Dqn_MapGet(Dqn_Map *map, Dqn_u64 hash) } template -void Dqn_MapErase(Dqn_Map *map, Dqn_u64 hash, Dqn_ZeroMem zero_mem) +void Dqn_Map_Erase(Dqn_Map *map, uint64_t hash, Dqn_ZeroMem zero_mem) { Dqn_isize index = hash % map->size; Dqn_MapEntry **entry = &(map->slots[index]); @@ -2558,7 +2553,7 @@ void Dqn_MapErase(Dqn_Map *map, Dqn_u64 hash, Dqn_ZeroMem zero_mem) if ((*entry) && (*entry)->hash == hash) { Dqn_MapEntry *erase_entry = *entry; Dqn_MapEntry *next = erase_entry->next; - (*entry) = next; + (*entry) = next; if (zero_mem == Dqn_ZeroMem_Yes) DQN_MEMSET(erase_entry, DQN_MEMSET_BYTE, sizeof(*erase_entry)); @@ -2576,12 +2571,12 @@ void Dqn_MapErase(Dqn_Map *map, Dqn_u64 hash, Dqn_ZeroMem zero_mem) // NOTE: Dqn_DSMap Template Implementation // ------------------------------------------------------------------------------------------------- template -Dqn_DSMap Dqn_DSMapInit(Dqn_isize size) +Dqn_DSMap Dqn_DSMap_Init(Dqn_isize size) { DQN_ASSERT_MSG(((size & (size - 1)) == 0), "Require non-zero power of 2 table size"); Dqn_DSMap result = {}; if (size > 0) { - result.slots = Dqn_ArenaNewArray(&result.arena, Dqn_DSMapEntry, size, Dqn_ZeroMem_Yes); + result.slots = Dqn_Arena_NewArray(&result.arena, Dqn_DSMapEntry, size, Dqn_ZeroMem_Yes); if (result.slots) result.size = size; } @@ -2589,21 +2584,21 @@ Dqn_DSMap Dqn_DSMapInit(Dqn_isize size) } template -void Dqn_DSMapFree(Dqn_DSMap *map, Dqn_ZeroMem zero_mem) +void Dqn_DSMap_Free(Dqn_DSMap *map, Dqn_ZeroMem zero_mem) { - Dqn_ArenaFree(&map->arena, zero_mem); + Dqn_Arena_Free(&map->arena, zero_mem); *map = {}; } template -Dqn_DSMapEntry *Dqn_DSMapFind(Dqn_DSMap *map, Dqn_u64 hash) +Dqn_DSMapEntry *Dqn_DSMap_Find(Dqn_DSMap *map, uint64_t hash) { - Dqn_DSMapEntry *result = Dqn_DSMapFindOrAdd(map, hash, true /*find_only*/); + Dqn_DSMapEntry *result = Dqn_DSMap_FindOrAdd(map, hash, true /*find_only*/); return result; } template -Dqn_DSMapEntry *Dqn_DSMapFindOrAdd(Dqn_DSMap *map, Dqn_u64 hash, bool find_only) +Dqn_DSMapEntry *Dqn_DSMap_FindOrAdd(Dqn_DSMap *map, uint64_t hash, bool find_only) { if (!map) return nullptr; @@ -2612,7 +2607,7 @@ Dqn_DSMapEntry *Dqn_DSMapFindOrAdd(Dqn_DSMap *map, Dqn_u64 hash, bool find if (find_only) return nullptr; else - *map = Dqn_DSMapInit(DQN_DS_MAP_MIN_SIZE); + *map = Dqn_DSMap_Init(DQN_DS_MAP_MIN_SIZE); } Dqn_isize index = hash % map->size; @@ -2634,17 +2629,17 @@ Dqn_DSMapEntry *Dqn_DSMapFindOrAdd(Dqn_DSMap *map, Dqn_u64 hash, bool find Dqn_f32 load_factor = ++map->count / DQN_CAST(Dqn_f32)map->size; if (load_factor >= 0.7f) { - auto new_map = Dqn_DSMapInit(map->size << 1); + auto new_map = Dqn_DSMap_Init(map->size << 1); for (Dqn_isize map_index = 0; map_index < map->size; map_index++) { Dqn_DSMapEntry *entry = map->slots + map_index; if (entry->occupied) { - Dqn_DSMapEntry *new_entry = Dqn_DSMapAddCopy(&new_map, entry->hash, entry->value); + Dqn_DSMapEntry *new_entry = Dqn_DSMap_AddCopy(&new_map, entry->hash, entry->value); if (new_entry->hash == hash) result = new_entry; } } - Dqn_DSMapFree(map, Dqn_ZeroMem_No); + Dqn_DSMap_Free(map, Dqn_ZeroMem_No); *map = new_map; } } @@ -2653,9 +2648,9 @@ Dqn_DSMapEntry *Dqn_DSMapFindOrAdd(Dqn_DSMap *map, Dqn_u64 hash, bool find } template -Dqn_DSMapEntry *Dqn_DSMapAdd(Dqn_DSMap *map, Dqn_u64 hash, T &value) +Dqn_DSMapEntry *Dqn_DSMap_Add(Dqn_DSMap *map, uint64_t hash, T &value) { - Dqn_DSMapEntry *result = Dqn_DSMapFindOrAdd(map, hash, false /*find_only*/); + Dqn_DSMapEntry *result = Dqn_DSMap_FindOrAdd(map, hash, false /*find_only*/); if (result) result->value = value; @@ -2663,9 +2658,9 @@ Dqn_DSMapEntry *Dqn_DSMapAdd(Dqn_DSMap *map, Dqn_u64 hash, T &value) } template -Dqn_DSMapEntry *Dqn_DSMapAddCopy(Dqn_DSMap *map, Dqn_u64 hash, T const &value) +Dqn_DSMapEntry *Dqn_DSMap_AddCopy(Dqn_DSMap *map, uint64_t hash, T const &value) { - Dqn_DSMapEntry *result = Dqn_DSMapFindOrAdd(map, hash, false /*find_only*/); + Dqn_DSMapEntry *result = Dqn_DSMap_FindOrAdd(map, hash, false /*find_only*/); if (result) result->value = value; @@ -2673,14 +2668,14 @@ Dqn_DSMapEntry *Dqn_DSMapAddCopy(Dqn_DSMap *map, Dqn_u64 hash, T const &va } template -Dqn_DSMapEntry *Dqn_DSMapGet(Dqn_DSMap *map, Dqn_u64 hash) +Dqn_DSMapEntry *Dqn_DSMap_Get(Dqn_DSMap *map, uint64_t hash) { - Dqn_DSMapEntry *result = Dqn_DSMapFindOrAdd(map, hash, true /*find_only*/); + Dqn_DSMapEntry *result = Dqn_DSMap_FindOrAdd(map, hash, true /*find_only*/); return result; } template -void Dqn_DSMapErase(Dqn_DSMap *map, Dqn_u64 hash, Dqn_ZeroMem zero_mem) +void Dqn_DSMap_Erase(Dqn_DSMap *map, uint64_t hash, Dqn_ZeroMem zero_mem) { if (!map) return; @@ -2720,28 +2715,28 @@ void Dqn_DSMapErase(Dqn_DSMap *map, Dqn_u64 hash, Dqn_ZeroMem zero_mem) // NOTE: Dqn_FixedString Template Implementation // ------------------------------------------------------------------------------------------------- template -DQN_API Dqn_FixedString Dqn_FixedStringFmt(char const *fmt, ...) +DQN_API Dqn_FixedString Dqn_FixedString_Fmt(char const *fmt, ...) { Dqn_FixedString result = {}; va_list va; va_start(va, fmt); - Dqn_FixedStringAppendFmtV(&result, fmt, va); + Dqn_FixedString_AppendFmtV(&result, fmt, va); va_end(va); return result; } template -DQN_API Dqn_isize Dqn_FixedStringMax(Dqn_FixedString *) +DQN_API Dqn_isize Dqn_FixedString_Max(Dqn_FixedString *) { Dqn_isize result = MAX_; return result; } template -DQN_API void Dqn_FixedStringClear(Dqn_FixedString *str) { *str = {}; } +DQN_API void Dqn_FixedString_Clear(Dqn_FixedString *str) { *str = {}; } template -DQN_API bool Dqn_FixedStringAppendFmtV(Dqn_FixedString *str, char const *fmt, va_list va) +DQN_API bool Dqn_FixedString_AppendFmtV(Dqn_FixedString *str, char const *fmt, va_list va) { va_list va2; va_copy(va2, va); @@ -2761,19 +2756,19 @@ DQN_API bool Dqn_FixedStringAppendFmtV(Dqn_FixedString *str, char const *f } template -DQN_API bool Dqn_FixedStringAppendFmt(Dqn_FixedString *str, char const *fmt, ...) +DQN_API bool Dqn_FixedString_AppendFmt(Dqn_FixedString *str, char const *fmt, ...) { va_list va; va_start(va, fmt); - bool result = Dqn_FixedStringAppendFmtV(str, fmt, va); + bool result = Dqn_FixedString_AppendFmtV(str, fmt, va); va_end(va); return result; } template -DQN_API bool Dqn_FixedStringAppend(Dqn_FixedString *str, char const *src, Dqn_isize size) +DQN_API bool Dqn_FixedString_Append(Dqn_FixedString *str, char const *src, Dqn_isize size) { - if (size == -1) size = DQN_CAST(Dqn_isize)Dqn_CStringSize(src); + if (size == -1) size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(src); Dqn_isize space = (MAX_ - 1 /*reserve byte for null terminator*/) - str->size; bool result = size <= space; @@ -2790,16 +2785,16 @@ DQN_API bool Dqn_FixedStringAppend(Dqn_FixedString *str, char const *src, } template -DQN_API bool Dqn_FixedStringAppend(Dqn_FixedString *str, Dqn_String8 src) +DQN_API bool Dqn_FixedString_Append(Dqn_FixedString *str, Dqn_String8 src) { - bool result = Dqn_FixedStringAppend(str, src.data, src.size); + bool result = Dqn_FixedString_Append(str, src.data, src.size); return result; } template -DQN_API Dqn_String8 Dqn_FixedStringToString(Dqn_FixedString const *str) +DQN_API Dqn_String8 Dqn_FixedString_ToString(Dqn_FixedString const *str) { - auto result = Dqn_String8Init(str->str, str->size); + auto result = Dqn_String8_Init(str->str, str->size); return result; } #endif // DQN_WITH_FIXED_STRING @@ -2817,22 +2812,22 @@ template void Dqn__EraseStableFromCArray(T *array, Dqn_isize size, // NOTE: Dqn_FixedArray Template Implementation // ------------------------------------------------------------------------------------------------- DQN_FIXED_ARRAY_TEMPLATE -DQN_API DQN_FIXED_ARRAY_TEMPLATE_DECL Dqn_FixedArrayInit(T const *item, int num) +DQN_API DQN_FIXED_ARRAY_TEMPLATE_DECL Dqn_FixedArray_Init(T const *item, int num) { DQN_FIXED_ARRAY_TEMPLATE_DECL result = {}; - Dqn_FixedArrayAdd(&result, item, num); + Dqn_FixedArray_Add(&result, item, num); return result; } DQN_FIXED_ARRAY_TEMPLATE -DQN_API Dqn_isize Dqn_FixedArrayMax(DQN_FIXED_ARRAY_TEMPLATE_DECL const *) +DQN_API Dqn_isize Dqn_FixedArray_Max(DQN_FIXED_ARRAY_TEMPLATE_DECL const *) { Dqn_isize result = MAX_; return result; } DQN_FIXED_ARRAY_TEMPLATE -DQN_API Dqn_isize Dqn_FixedArrayGetIndex(DQN_FIXED_ARRAY_TEMPLATE_DECL const *a, T const *entry) +DQN_API Dqn_isize Dqn_FixedArray_GetIndex(DQN_FIXED_ARRAY_TEMPLATE_DECL const *a, T const *entry) { DQN_ASSERT(entry >= a->begin() && entry <= a->end()); Dqn_isize result = a->end() - entry; @@ -2840,7 +2835,7 @@ DQN_API Dqn_isize Dqn_FixedArrayGetIndex(DQN_FIXED_ARRAY_TEMPLATE_DECL const *a, } DQN_FIXED_ARRAY_TEMPLATE -DQN_API T *Dqn_FixedArrayAdd(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T const *items, Dqn_isize num) +DQN_API T *Dqn_FixedArray_Add(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T const *items, Dqn_isize num) { DQN_ASSERT(a->size + num <= MAX_); T *result = static_cast(DQN_MEMCOPY(a->data + a->size, items, sizeof(T) * num)); @@ -2849,7 +2844,7 @@ DQN_API T *Dqn_FixedArrayAdd(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T const *items, D } DQN_FIXED_ARRAY_TEMPLATE -DQN_API T *Dqn_FixedArrayAdd(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T const &item) +DQN_API T *Dqn_FixedArray_Add(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T const &item) { DQN_ASSERT(a->size < MAX_); a->data[a->size++] = item; @@ -2857,7 +2852,7 @@ DQN_API T *Dqn_FixedArrayAdd(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T const &item) } DQN_FIXED_ARRAY_TEMPLATE -DQN_API T *Dqn_FixedArrayMake(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize num) +DQN_API T *Dqn_FixedArray_Make(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize num) { DQN_ASSERT(a->size + num <= MAX_); T *result = a->data + a->size; @@ -2866,7 +2861,7 @@ DQN_API T *Dqn_FixedArrayMake(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize num) } DQN_FIXED_ARRAY_TEMPLATE -DQN_API void Dqn_FixedArrayClear(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_ZeroMem zero_mem) +DQN_API void Dqn_FixedArray_Clear(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_ZeroMem zero_mem) { a->size = 0; if (zero_mem == Dqn_ZeroMem_Yes) @@ -2874,13 +2869,13 @@ DQN_API void Dqn_FixedArrayClear(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_ZeroMem z } DQN_FIXED_ARRAY_TEMPLATE -DQN_API void Dqn_FixedArrayEraseStable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index) +DQN_API void Dqn_FixedArray_EraseStable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index) { Dqn__EraseStableFromCArray(a->data, a->size--, MAX_, index); } DQN_FIXED_ARRAY_TEMPLATE -DQN_API void Dqn_FixedArrayEraseUnstable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index) +DQN_API void Dqn_FixedArray_EraseUnstable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index) { DQN_ASSERT(index >= 0 && index < a->size); if (--a->size == 0) return; @@ -2888,7 +2883,7 @@ DQN_API void Dqn_FixedArrayEraseUnstable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_i } DQN_FIXED_ARRAY_TEMPLATE -DQN_API void Dqn_FixedArrayPop(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize num, Dqn_ZeroMem zero_mem) +DQN_API void Dqn_FixedArray_Pop(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize num, Dqn_ZeroMem zero_mem) { DQN_ASSERT(a->size - num >= 0); a->size -= num; @@ -2900,14 +2895,14 @@ DQN_API void Dqn_FixedArrayPop(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize num, } DQN_FIXED_ARRAY_TEMPLATE -DQN_API T *Dqn_FixedArrayPeek(DQN_FIXED_ARRAY_TEMPLATE_DECL *a) +DQN_API T *Dqn_FixedArray_Peek(DQN_FIXED_ARRAY_TEMPLATE_DECL *a) { T *result = (a->size == 0) ? nullptr : a->data + (a->size - 1); return result; } DQN_FIXED_ARRAY_TEMPLATE -DQN_API T Dqn_FixedArrayPeekCopy(DQN_FIXED_ARRAY_TEMPLATE_DECL const *a) +DQN_API T Dqn_FixedArray_PeekCopy(DQN_FIXED_ARRAY_TEMPLATE_DECL const *a) { DQN_ASSERT(a->size > 0); T const *result = a->data + (a->size - 1); @@ -2915,7 +2910,7 @@ DQN_API T Dqn_FixedArrayPeekCopy(DQN_FIXED_ARRAY_TEMPLATE_DECL const *a) } template -DQN_API T *Dqn_FixedArrayFind(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, IsEqual IsEqualProc) +DQN_API T *Dqn_FixedArray_Find(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, IsEqual IsEqualProc) { for (T &entry : (*a)) { @@ -2925,15 +2920,15 @@ DQN_API T *Dqn_FixedArrayFind(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, IsEqual IsEqualP return nullptr; } -// return: True if the entry was found, false if not- the entry is made using Dqn_FixedArrayMake() in this case +// return: True if the entry was found, false if not- the entry is made using Dqn_FixedArray_Make() in this case template -DQN_API bool Dqn_FixedArrayFindElseMake(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T **entry, IsEqual IsEqualProc) +DQN_API bool Dqn_FixedArray_FindElseMake(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T **entry, IsEqual IsEqualProc) { bool result = true; - T *search = Dqn_FixedArrayFind(a, IsEqualProc); + T *search = Dqn_FixedArray_Find(a, IsEqualProc); if (!search) { result = false; - search = Dqn_FixedArrayMake(a, 1); + search = Dqn_FixedArray_Make(a, 1); } *entry = search; @@ -2941,7 +2936,7 @@ DQN_API bool Dqn_FixedArrayFindElseMake(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T **en } DQN_FIXED_ARRAY_TEMPLATE -DQN_API T *Dqn_FixedArrayFind(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T *find) +DQN_API T *Dqn_FixedArray_Find(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T *find) { for (T &entry : (*a)) { @@ -2955,7 +2950,7 @@ DQN_API T *Dqn_FixedArrayFind(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, T *find) // NOTE: Dqn_Array Template Implementation // ------------------------------------------------------------------------------------------------- template -DQN_API Dqn_Array Dqn_ArrayInitWithMemory(T *memory, Dqn_isize max, Dqn_isize size) +DQN_API Dqn_Array Dqn_Array_InitWithMemory(T *memory, Dqn_isize max, Dqn_isize size) { Dqn_Array result = {}; result.data = memory; @@ -2965,23 +2960,23 @@ DQN_API Dqn_Array Dqn_ArrayInitWithMemory(T *memory, Dqn_isize max, Dqn_isize } template -DQN_API Dqn_Array Dqn_Array_InitWithArenaNoGrow(Dqn_Arena *arena, Dqn_isize max, Dqn_isize size, Dqn_ZeroMem zero_mem DQN_CALL_SITE_ARGS) +DQN_API Dqn_Array Dqn_Array__InitWithArenaNoGrow(Dqn_Arena *arena, Dqn_isize max, Dqn_isize size, Dqn_ZeroMem zero_mem DQN_CALL_SITE_ARGS) { Dqn_Array result = {}; if (max && arena) { - auto *memory = DQN_CAST(T *)Dqn_ArenaAllocate_(arena, sizeof(T) * max, alignof(T), zero_mem DQN_CALL_SITE_ARGS_INPUT); - result = Dqn_ArrayInitWithMemory(memory, max, size); + auto *memory = DQN_CAST(T *)Dqn_Arena_Allocate_(arena, sizeof(T) * max, alignof(T), zero_mem DQN_CALL_SITE_ARGS_INPUT); + result = Dqn_Array_InitWithMemory(memory, max, size); } return result; } template -DQN_API bool Dqn_ArrayReserve_(Dqn_Array *a, Dqn_isize size DQN_CALL_SITE_ARGS) +DQN_API bool Dqn_Array_Reserve_(Dqn_Array *a, Dqn_isize size DQN_CALL_SITE_ARGS) { if (size <= a->size) return true; if (!a->arena) return false; - T *new_ptr = DQN_CAST(T *)Dqn_ArenaAllocate_(a->arena, sizeof(T) * size, alignof(T), Dqn_ZeroMem_Yes DQN_CALL_SITE_ARGS_INPUT); + T *new_ptr = DQN_CAST(T *)Dqn_Arena_Allocate_(a->arena, sizeof(T) * size, alignof(T), Dqn_ZeroMem_Yes DQN_CALL_SITE_ARGS_INPUT); if (!new_ptr) return false; if (a->data) @@ -2996,22 +2991,22 @@ DQN_API bool Dqn_ArrayReserve_(Dqn_Array *a, Dqn_isize size DQN_CALL_SITE_ARG } template -DQN_API bool Dqn_Array_GrowIfNeeded(Dqn_Array *a, Dqn_isize num_to_add DQN_CALL_SITE_ARGS) +DQN_API bool Dqn_Array__GrowIfNeeded(Dqn_Array *a, Dqn_isize num_to_add DQN_CALL_SITE_ARGS) { Dqn_isize new_size = a->size + num_to_add; bool result = true; if (new_size > a->max) { Dqn_isize num_items = DQN_MAX(4, DQN_MAX(new_size, (a->max * 2))); - result = Dqn_ArrayReserve_(a, num_items DQN_CALL_SITE_ARGS_INPUT); + result = Dqn_Array_Reserve_(a, num_items DQN_CALL_SITE_ARGS_INPUT); } return result; } template -DQN_API T *Dqn_ArrayAddArray_(Dqn_Array *a, T const *items, Dqn_isize num DQN_CALL_SITE_ARGS) +DQN_API T *Dqn_Array_AddArray_(Dqn_Array *a, T const *items, Dqn_isize num DQN_CALL_SITE_ARGS) { - if (!Dqn_Array_GrowIfNeeded(a, num DQN_CALL_SITE_ARGS_INPUT)) + if (!Dqn_Array__GrowIfNeeded(a, num DQN_CALL_SITE_ARGS_INPUT)) return nullptr; T *result = static_cast(DQN_MEMCOPY(a->data + a->size, items, sizeof(T) * num)); a->size += num; @@ -3019,17 +3014,17 @@ DQN_API T *Dqn_ArrayAddArray_(Dqn_Array *a, T const *items, Dqn_isize num DQN } template -DQN_API T *Dqn_ArrayAdd_(Dqn_Array *a, T const &item DQN_CALL_SITE_ARGS) +DQN_API T *Dqn_Array_Add_(Dqn_Array *a, T const &item DQN_CALL_SITE_ARGS) { - if (!Dqn_Array_GrowIfNeeded(a, 1 DQN_CALL_SITE_ARGS_INPUT)) + if (!Dqn_Array__GrowIfNeeded(a, 1 DQN_CALL_SITE_ARGS_INPUT)) return nullptr; a->data[a->size++] = item; return &a->data[a->size - 1]; } template -DQN_API T *Dqn_ArrayMake_(Dqn_Array *a, Dqn_isize num DQN_CALL_SITE_ARGS) +DQN_API T *Dqn_Array_Make_(Dqn_Array *a, Dqn_isize num DQN_CALL_SITE_ARGS) { - if (!Dqn_Array_GrowIfNeeded(a, num DQN_CALL_SITE_ARGS_INPUT)) + if (!Dqn_Array__GrowIfNeeded(a, num DQN_CALL_SITE_ARGS_INPUT)) return nullptr; T *result = a->data + a->size; a->size += num; @@ -3037,7 +3032,7 @@ DQN_API T *Dqn_ArrayMake_(Dqn_Array *a, Dqn_isize num DQN_CALL_SITE_ARGS) } template -DQN_API void Dqn_ArrayClear(Dqn_Array *a, Dqn_ZeroMem zero_mem) +DQN_API void Dqn_Array_Clear(Dqn_Array *a, Dqn_ZeroMem zero_mem) { a->size = 0; if (zero_mem == Dqn_ZeroMem_Yes) @@ -3045,13 +3040,13 @@ DQN_API void Dqn_ArrayClear(Dqn_Array *a, Dqn_ZeroMem zero_mem) } template -DQN_API void Dqn_ArrayEraseStable(Dqn_Array *a, Dqn_isize index) +DQN_API void Dqn_Array_EraseStable(Dqn_Array *a, Dqn_isize index) { Dqn__EraseStableFromCArray(a->data, a->size--, a->max, index); } template -DQN_API void Dqn_ArrayEraseUnstable(Dqn_Array *a, Dqn_isize index) +DQN_API void Dqn_Array_EraseUnstable(Dqn_Array *a, Dqn_isize index) { DQN_ASSERT(index >= 0 && index < a->size); if (--a->size == 0) return; @@ -3059,7 +3054,7 @@ DQN_API void Dqn_ArrayEraseUnstable(Dqn_Array *a, Dqn_isize index) } template -DQN_API void Dqn_ArrayPop(Dqn_Array *a, Dqn_isize num, Dqn_ZeroMem zero_mem) +DQN_API void Dqn_Array_Pop(Dqn_Array *a, Dqn_isize num, Dqn_ZeroMem zero_mem) { DQN_ASSERT(a->size - num >= 0); a->size -= num; @@ -3072,7 +3067,7 @@ DQN_API void Dqn_ArrayPop(Dqn_Array *a, Dqn_isize num, Dqn_ZeroMem zero_mem) } template -DQN_API T *Dqn_ArrayPeek(Dqn_Array *a) +DQN_API T *Dqn_Array_Peek(Dqn_Array *a) { T *result = (a->size == 0) ? nullptr : a->data + (a->size - 1); return result; @@ -3081,7 +3076,7 @@ DQN_API T *Dqn_ArrayPeek(Dqn_Array *a) // NOTE: Dqn_List Template Implementation // ------------------------------------------------------------------------------------------------- template -DQN_API Dqn_List Dqn_ListInitWithArena(Dqn_Arena *arena, Dqn_isize chunk_size) +DQN_API Dqn_List Dqn_List_InitWithArena(Dqn_Arena *arena, Dqn_isize chunk_size) { Dqn_List result = {}; result.arena = arena; @@ -3090,19 +3085,19 @@ DQN_API Dqn_List Dqn_ListInitWithArena(Dqn_Arena *arena, Dqn_isize chunk_size } template -DQN_API T *Dqn__ListMake(Dqn_List *list, Dqn_isize count DQN_CALL_SITE_ARGS) +DQN_API T *Dqn_List_Make_(Dqn_List *list, Dqn_isize count DQN_CALL_SITE_ARGS) { if (list->chunk_size == 0) list->chunk_size = 128; if (!list->tail || (list->tail->count + count) > list->tail->size) { - auto *tail = (Dqn_ListChunk * )Dqn_ArenaAllocate_(list->arena, sizeof(Dqn_ListChunk), alignof(Dqn_ListChunk), Dqn_ZeroMem_Yes DQN_CALL_SITE_ARGS_INPUT); + auto *tail = (Dqn_ListChunk * )Dqn_Arena_Allocate_(list->arena, sizeof(Dqn_ListChunk), alignof(Dqn_ListChunk), Dqn_ZeroMem_Yes DQN_CALL_SITE_ARGS_INPUT); if (!tail) return nullptr; Dqn_isize items = DQN_MAX(list->chunk_size, count); - tail->data = (T * )Dqn_ArenaAllocate_(list->arena, sizeof(T) * items, alignof(T), Dqn_ZeroMem_Yes DQN_CALL_SITE_ARGS_INPUT); + tail->data = (T * )Dqn_Arena_Allocate_(list->arena, sizeof(T) * items, alignof(T), Dqn_ZeroMem_Yes DQN_CALL_SITE_ARGS_INPUT); tail->size = items; if (!tail->data) @@ -3127,7 +3122,7 @@ DQN_API T *Dqn__ListMake(Dqn_List *list, Dqn_isize count DQN_CALL_SITE_ARGS) } template -DQN_API bool Dqn_ListIterateFrom(Dqn_List *list, Dqn_ListIterator *iterator, Dqn_isize start_index) +DQN_API bool Dqn_List_IterateFrom(Dqn_List *list, Dqn_ListIterator *iterator, Dqn_isize start_index) { bool result = false; if (!list || !iterator || start_index < 0 || list->chunk_size <= 0) @@ -3138,7 +3133,7 @@ DQN_API bool Dqn_ListIterateFrom(Dqn_List *list, Dqn_ListIterator *iterato if (start_index == 0) { iterator->chunk = list->head; } else { - Dqn_ListAt(list, start_index, &iterator->chunk); + Dqn_List_At(list, start_index, &iterator->chunk); if (list->chunk_size > 0) iterator->chunk_data_index = start_index % list->chunk_size; } @@ -3164,7 +3159,7 @@ DQN_API bool Dqn_ListIterateFrom(Dqn_List *list, Dqn_ListIterator *iterato } template -DQN_API T *Dqn_ListAt(Dqn_List *list, Dqn_isize index, Dqn_ListChunk **at_chunk) +DQN_API T *Dqn_List_At(Dqn_List *list, Dqn_isize index, Dqn_ListChunk **at_chunk) { if (!list || !list->chunk_size || index < 0 || index >= list->count) return nullptr; @@ -3225,10 +3220,10 @@ DQN_API T *Dqn_ListAt(Dqn_List *list, Dqn_isize index, Dqn_ListChunk **at_ #pragma comment(lib, "wininet") #if defined(DQN_NO_WIN32_MINIMAL_HEADER) - #include // Dqn_OSSecureRNGBytes -> BCryptOpenAlgorithmProvider ... etc - #include // Dqn_WinMakeProcessDPIAware -> SetProcessDpiAwareProc + #include // Dqn_OS_SecureRNGBytes -> BCryptOpenAlgorithmProvider ... etc + #include // Dqn_Win_MakeProcessDPIAware -> SetProcessDpiAwareProc #if defined(DQN_WITH_WIN_NET) - #include // Dqn_WinNet -> InternetConnect ... etc + #include // Dqn_Win_Net -> InternetConnect ... etc #endif // DQN_WITH_WIN_NET #else // Taken from Windows.h @@ -3317,7 +3312,7 @@ DQN_API T *Dqn_ListAt(Dqn_List *list, Dqn_isize index, Dqn_ListChunk **at_ unsigned long LowPart; unsigned long HighPart; } u; - Dqn_u64 QuadPart; + uint64_t QuadPart; } ULARGE_INTEGER; typedef struct @@ -3352,8 +3347,8 @@ DQN_API T *Dqn_ListAt(Dqn_List *list, Dqn_isize index, Dqn_ListChunk **at_ union { unsigned long dwOemId; // Obsolete field...do not use struct { - Dqn_u16 wProcessorArchitecture; - Dqn_u16 wReserved; + uint16_t wProcessorArchitecture; + uint16_t wReserved; } DUMMYSTRUCTNAME; } DUMMYUNIONNAME; unsigned long dwPageSize; @@ -3363,8 +3358,8 @@ DQN_API T *Dqn_ListAt(Dqn_List *list, Dqn_isize index, Dqn_ListChunk **at_ unsigned long dwNumberOfProcessors; unsigned long dwProcessorType; unsigned long dwAllocationGranularity; - Dqn_u16 wProcessorLevel; - Dqn_u16 wProcessorRevision; + uint16_t wProcessorLevel; + uint16_t wProcessorRevision; } SYSTEM_INFO; typedef struct { @@ -3526,7 +3521,7 @@ DQN_API T *Dqn_ListAt(Dqn_List *list, Dqn_isize index, Dqn_ListChunk **at_ #include // access #endif -Dqn_Lib dqn_lib_; +Dqn_Lib_ dqn_lib_; // NOTE: Intrinsics // ------------------------------------------------------------------------------------------------- @@ -3549,26 +3544,26 @@ Dqn_CPUIDRegisters Dqn_CPUID(int function_id) return result; } -// NOTE: Dqn_TicketMutex +// NOTE: Dqn_TicketMutex_ // ------------------------------------------------------------------------------------------------- -void Dqn_TicketMutexBegin(Dqn_TicketMutex *mutex) +void Dqn_TicketMutex_Begin(Dqn_TicketMutex *mutex) { - unsigned int ticket = Dqn_AtomicAddU32(&mutex->ticket, 1); - Dqn_TicketMutexBeginTicket(mutex, ticket); + unsigned int ticket = Dqn_Atomic_AddU32(&mutex->ticket, 1); + Dqn_TicketMutex_BeginTicket(mutex, ticket); } -void Dqn_TicketMutexEnd(Dqn_TicketMutex *mutex) +void Dqn_TicketMutex_End(Dqn_TicketMutex *mutex) { - Dqn_AtomicAddU32(&mutex->serving, 1); + Dqn_Atomic_AddU32(&mutex->serving, 1); } -unsigned int Dqn_TicketMutexMakeTicket(Dqn_TicketMutex *mutex) +Dqn_uint Dqn_TicketMutex_MakeTicket(Dqn_TicketMutex *mutex) { - unsigned int result = Dqn_AtomicAddU32(&mutex->ticket, 1); + Dqn_uint result = Dqn_Atomic_AddU32(&mutex->ticket, 1); return result; } -void Dqn_TicketMutexBeginTicket(Dqn_TicketMutex const *mutex, unsigned int ticket) +void Dqn_TicketMutex_BeginTicket(Dqn_TicketMutex const *mutex, Dqn_uint ticket) { DQN_ASSERT_MSG(mutex->serving <= ticket, "Mutex skipped ticket? Was ticket generated by the correct mutex via MakeTicket? ticket = %u, " @@ -3582,7 +3577,7 @@ void Dqn_TicketMutexBeginTicket(Dqn_TicketMutex const *mutex, unsigned int ticke } } -bool Dqn_TicketMutexCanLock(Dqn_TicketMutex const *mutex, unsigned int ticket) +bool Dqn_TicketMutex_CanLock(Dqn_TicketMutex const *mutex, Dqn_uint ticket) { bool result = (ticket == mutex->serving); return result; @@ -3590,7 +3585,7 @@ bool Dqn_TicketMutexCanLock(Dqn_TicketMutex const *mutex, unsigned int ticket) // NOTE: Dqn_Allocator // ------------------------------------------------------------------------------------------------- -void *Dqn_AllocatorAlloc(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, size_t size, uint8_t align, Dqn_ZeroMem zero_mem) +void *Dqn_Allocator_Alloc(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, size_t size, uint8_t align, Dqn_ZeroMem zero_mem) { void *result = NULL; if (allocator.alloc) { @@ -3606,7 +3601,7 @@ void *Dqn_AllocatorAlloc(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, size_t size return result; } -void Dqn_AllocatorDealloc(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, void *ptr, size_t size) +void Dqn_Allocator_Dealloc(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, void *ptr, size_t size) { if (allocator.dealloc) { allocator.dealloc(DQN_CALL_SITE_ARGS_INPUT ptr, size, allocator.user_context); @@ -3617,45 +3612,6 @@ void Dqn_AllocatorDealloc(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, void *ptr, } } - -// NOTE: Dqn_Fmt Implementation -// ------------------------------------------------------------------------------------------------- -DQN_API Dqn_isize Dqn_FmtVLenNoNullTerminator(char const *fmt, va_list args) -{ - va_list args_copy; - va_copy(args_copy, args); - Dqn_isize result = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, args_copy); - va_end(args_copy); - return result; -} - -DQN_API Dqn_isize Dqn_FmtLenNoNullTerminator(char const *fmt, ...) -{ - va_list args; - va_start(args, fmt); - Dqn_isize result = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, args); - va_end(args); - return result; -} - -DQN_API Dqn_isize Dqn_FmtVLen(char const *fmt, va_list args) -{ - va_list args_copy; - va_copy(args_copy, args); - Dqn_isize result = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, args_copy) + 1; - va_end(args_copy); - return result; -} - -DQN_API Dqn_isize Dqn_FmtLen(char const *fmt, ...) -{ - va_list args; - va_start(args, fmt); - Dqn_isize result = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, args) + 1; - va_end(args); - return result; -} - // NOTE: Dqn_Log // ------------------------------------------------------------------------------------------------- DQN_API void Dqn_LogVDefault(Dqn_LogType type, @@ -3669,33 +3625,33 @@ DQN_API void Dqn_LogVDefault(Dqn_LogType type, (void)user_data; // NOTE: Ensure log-file is opened for appending, ultra-lightweight spinlock mutex - Dqn_TicketMutexBegin(&dqn_lib_.log_file_mutex); + Dqn_TicketMutex_Begin(&dqn_lib_.log_file_mutex); if (!dqn_lib_.log_no_output_file) { if (!dqn_lib_.log_file) { - Dqn_ThreadScratch scratch = Dqn_ThreadGetScratch(); - Dqn_String8 exe_dir = Dqn_OSEXEDir(Dqn_ArenaAllocator(scratch.arena)); - Dqn_String8 log_file = Dqn_String8Fmt(Dqn_ArenaAllocator(scratch.arena), "%.*s/dqn.log", DQN_STRING_FMT(exe_dir)); + Dqn_ThreadTempArena scratch = Dqn_Thread_TempArena(); + Dqn_String8 exe_dir = Dqn_OS_EXEDir(Dqn_Arena_Allocator(scratch.arena)); + Dqn_String8 log_file = Dqn_String8_Fmt(Dqn_Arena_Allocator(scratch.arena), "%.*s/dqn.log", DQN_STRING_FMT(exe_dir)); fopen_s(DQN_CAST(FILE **)&dqn_lib_.log_file, log_file.data, "a"); } } - Dqn_TicketMutexEnd(&dqn_lib_.log_file_mutex); + Dqn_TicketMutex_End(&dqn_lib_.log_file_mutex); // NOTE: Construct log - Dqn_ThreadScratch scratch = Dqn_ThreadGetScratch(); + Dqn_ThreadTempArena scratch = Dqn_Thread_TempArena(); Dqn_String8Builder string_list = {}; - string_list.allocator = Dqn_ArenaAllocator(scratch.arena); + string_list.allocator = Dqn_Arena_Allocator(scratch.arena); { // NOTE: Generate the log header - Dqn_String8 file_name = Dqn_String8FileNameFromPath(file); - Dqn_DateHMSTimeString const time = Dqn_DateHMSLocalTimeStringNow(); + Dqn_String8 file_name = Dqn_String8_FileNameFromPath(file); + Dqn_DateHMSTimeString const time = Dqn_Date_HMSLocalTimeStringNow(); - Dqn_String8BuilderAppendFmtArgs(&string_list, + Dqn_String8Builder_AppendFmtArgs(&string_list, "[%.*s|%.*s|%.*s|%.*s|%05u|%.*s", time.date_size - 2, time.date + 2, time.hms_size, time.hms, - DQN_STRING_FMT(Dqn_LogTypeString8(type)), + DQN_STRING_FMT(Dqn_Log_TypeString8(type)), DQN_STRING_FMT(file_name), line, DQN_STRING_FMT(func)); @@ -3706,18 +3662,18 @@ DQN_API void Dqn_LogVDefault(Dqn_LogType type, if (string_list.string_size < max_log_header_length) { int pad_size = DQN_CAST(int)(max_log_header_length - string_list.string_size); - Dqn_String8 padding = Dqn_String8Allocate(Dqn_ArenaAllocator(scratch.arena), pad_size, Dqn_ZeroMem_No); + Dqn_String8 padding = Dqn_String8_Allocate(Dqn_Arena_Allocator(scratch.arena), pad_size, Dqn_ZeroMem_No); DQN_MEMSET(padding.data, ' ', padding.size); - Dqn_String8BuilderAppendString8Ref(&string_list, padding); + Dqn_String8Builder_AppendString8Ref(&string_list, padding); } // NOTE: Add the user message to the log line - Dqn_String8BuilderAppendString8Ref(&string_list, DQN_STRING8("] ")); - Dqn_String8BuilderAppendFmtVArgs(&string_list, fmt, va); + Dqn_String8Builder_AppendString8Ref(&string_list, DQN_STRING8("] ")); + Dqn_String8Builder_AppendFmtVArgs(&string_list, fmt, va); } // NOTE: Build the log line - Dqn_String8 log_line = Dqn_String8BuilderBuild(&string_list, Dqn_ArenaAllocator(scratch.arena)); + Dqn_String8 log_line = Dqn_String8Builder_Build(&string_list, Dqn_Arena_Allocator(scratch.arena)); // NOTE: Print log to destinations FILE *handles[] = { @@ -3757,9 +3713,9 @@ DQN_API void Dqn_Log(Dqn_LogType type, va_end(va); } -// NOTE: Dqn_Virtual +// NOTE: Dqn_VirtualMem_ // ------------------------------------------------------------------------------------------------- -DQN_API void *Dqn_VirtualReserve(Dqn_usize size, bool commit) +DQN_API void *Dqn_VirtualMem_Reserve(Dqn_usize size, bool commit) { #if defined(DQN_OS_WIN32) unsigned long flags = MEM_RESERVE | (commit ? (MEM_COMMIT | MEM_RESERVE) : 0); @@ -3773,24 +3729,24 @@ DQN_API void *Dqn_VirtualReserve(Dqn_usize size, bool commit) result = nullptr; #else - #error "Missing implementation for Dqn_VirtualReserve" + #error "Missing implementation for Dqn_VirtualMem_Reserve" #endif return result; } -DQN_API bool Dqn_VirtualCommit(void *ptr, Dqn_usize size) +DQN_API bool Dqn_VirtualMem_Commit(void *ptr, Dqn_usize size) { #if defined(DQN_OS_WIN32) bool result = VirtualAlloc(ptr, size, MEM_COMMIT, PAGE_READWRITE) != nullptr; #elif defined(DQN_OS_UNIX) bool result = mprotect(ptr, size, PROT_READ|PROT_WRITE) == 0; #else - #error "Missing implementation for Dqn_VirtualCommit" + #error "Missing implementation for Dqn_VirtualMem_Commit" #endif return result; } -DQN_API void Dqn_VirtualDecommit(void *ptr, Dqn_usize size) +DQN_API void Dqn_VirtualMem_Decommit(void *ptr, Dqn_usize size) { #if defined(DQN_OS_WIN32) VirtualFree(ptr, size, MEM_DECOMMIT); @@ -3798,11 +3754,11 @@ DQN_API void Dqn_VirtualDecommit(void *ptr, Dqn_usize size) mprotect(ptr, size, PROT_NONE) madvise(ptr, size, MADV_FREE) #else - #error "Missing implementation for Dqn_VirtualDecommit" + #error "Missing implementation for Dqn_VirtualMem_Decommit" #endif } -DQN_API void Dqn_VirtualRelease(void *ptr, Dqn_usize size) +DQN_API void Dqn_VirtualMem_Release(void *ptr, Dqn_usize size) { #if defined(DQN_OS_WIN32) (void)size; @@ -3810,13 +3766,13 @@ DQN_API void Dqn_VirtualRelease(void *ptr, Dqn_usize size) #elif defined(DQN_OS_UNIX) munmap(ptr, size); #else - #error "Missing implementation for Dqn_VirtualRelease" + #error "Missing implementation for Dqn_VirtualMem_Release" #endif } -// NOTE: Dqn_AllocationTracer +// NOTE: Dqn_AllocationTracer_ // ------------------------------------------------------------------------------------------------- -void Dqn_AllocationTracerAdd(Dqn_AllocationTracer *tracer, void *ptr, Dqn_usize size DQN_CALL_SITE_ARGS) +void Dqn_AllocationTracer_Add(Dqn_AllocationTracer *tracer, void *ptr, Dqn_usize size DQN_CALL_SITE_ARGS) { #if DQN_ALLOCATION_TRACING if (!tracer) return; @@ -3828,37 +3784,37 @@ void Dqn_AllocationTracerAdd(Dqn_AllocationTracer *tracer, void *ptr, Dqn_usize trace.line = line_; trace.msg = msg_; - Dqn_TicketMutexBegin(&tracer->mutex); + Dqn_TicketMutex_Begin(&tracer->mutex); #if 0 // TODO(dqn): We need to revisit this if (!trace->map.values) { trace->arena = Dqn_ArenaInitWithCRT(); - trace->map = Dqn_MapInitWithArena(&trace->arena, 16192); + trace->map = Dqn_Map_InitWithArena(&trace->arena, 16192); } #endif - bool added = Dqn_MapAdd(&tracer->map, DQN_CAST(Dqn_u64) ptr, trace, Dqn_MapCollideRule::Chain); + bool added = Dqn_Map_Add(&tracer->map, DQN_CAST(uint64_t) ptr, trace, Dqn_MapCollideRule::Chain); if (!added) { - // Dqn_AllocationTrace *other = Dqn_MapGet(&tracer->table, DQN_CAST(Dqn_u64) ptr); + // Dqn_AllocationTrace *other = Dqn_Map_Get(&tracer->table, DQN_CAST(uint64_t) ptr); DQN_ASSERT_MSG(added, "Hash table collision on %Ix", ptr); } - Dqn_TicketMutexEnd(&tracer->mutex); + Dqn_TicketMutex_End(&tracer->mutex); #else (void)tracer; (void)ptr; (void)size; #endif } -void Dqn_AllocationTracerRemove(Dqn_AllocationTracer *tracer, void *ptr) +void Dqn_AllocationTracer_Remove(Dqn_AllocationTracer *tracer, void *ptr) { #if DQN_ALLOCATION_TRACING if (!tracer) return; - Dqn_TicketMutexBegin(&tracer->mutex); - Dqn_AllocationTrace *trace = Dqn_MapGet(&tracer->map, DQN_CAST(Dqn_u64) ptr); + Dqn_TicketMutex_Begin(&tracer->mutex); + Dqn_AllocationTrace *trace = Dqn_Map_Get(&tracer->map, DQN_CAST(uint64_t) ptr); DQN_ASSERT_MSG(trace->ptr == ptr, "(trace->ptr = %Ix, raw_ptr = %Ix", trace->ptr, ptr); - Dqn_MapErase(&tracer->map, DQN_CAST(Dqn_u64) ptr); - Dqn_TicketMutexEnd(&tracer->mutex); + Dqn_Map_Erase(&tracer->map, DQN_CAST(uint64_t) ptr); + Dqn_TicketMutex_End(&tracer->mutex); #else (void)tracer; (void)ptr; #endif @@ -3866,7 +3822,7 @@ void Dqn_AllocationTracerRemove(Dqn_AllocationTracer *tracer, void *ptr) // NOTE: Dqn_String8 // ------------------------------------------------------------------------------------------------- -DQN_API Dqn_String8 Dqn_String8Init(char const *string, Dqn_isize size) +DQN_API Dqn_String8 Dqn_String8_Init(char const *string, Dqn_isize size) { Dqn_String8 result = {}; result.data = DQN_CAST(char *)string; @@ -3874,42 +3830,42 @@ DQN_API Dqn_String8 Dqn_String8Init(char const *string, Dqn_isize size) return result; } -DQN_API Dqn_String8 Dqn_String8InitCString(char const *string) +DQN_API Dqn_String8 Dqn_String8_InitCString(char const *string) { - Dqn_isize size = Dqn_CStringSize(string); - Dqn_String8 result = Dqn_String8Init(string, size); + Dqn_isize size = Dqn_CString8_Size(string); + Dqn_String8 result = Dqn_String8_Init(string, size); return result; } -DQN_API bool Dqn_String8IsValid(Dqn_String8 string) +DQN_API bool Dqn_String8_IsValid(Dqn_String8 string) { bool result = string.size >= 0 && string.data; return result; } -DQN_API Dqn_String8 Dqn_String8Slice(Dqn_String8 string, Dqn_isize offset, Dqn_isize size) +DQN_API Dqn_String8 Dqn_String8_Slice(Dqn_String8 string, Dqn_isize offset, Dqn_isize size) { - Dqn_String8 result = Dqn_String8Init(string.data, 0); - if (!Dqn_String8IsValid(string) || offset < 0 || size < 0) + Dqn_String8 result = Dqn_String8_Init(string.data, 0); + if (!Dqn_String8_IsValid(string) || offset < 0 || size < 0) return result; Dqn_isize capped_offset = DQN_MIN(offset, string.size); Dqn_isize max_size = string.size - capped_offset; Dqn_isize capped_size = DQN_MIN(size, max_size); - result = Dqn_String8Init(string.data + capped_offset, capped_size); + result = Dqn_String8_Init(string.data + capped_offset, capped_size); return result; } -DQN_API Dqn_String8 Dqn_String8Fmt_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, ...) +DQN_API Dqn_String8 Dqn_String8_Fmt_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, ...) { va_list va; va_start(va, fmt); - Dqn_String8 result = Dqn_String8FmtV_(DQN_CALL_SITE_ARGS_INPUT allocator, fmt, va); + Dqn_String8 result = Dqn_String8_FmtV_(DQN_CALL_SITE_ARGS_INPUT allocator, fmt, va); va_end(va); return result; } -DQN_API Dqn_String8 Dqn_String8FmtV_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, va_list va) +DQN_API Dqn_String8 Dqn_String8_FmtV_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *fmt, va_list va) { Dqn_String8 result = {}; if (!fmt) @@ -3920,99 +3876,117 @@ DQN_API Dqn_String8 Dqn_String8FmtV_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, int size = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, va2); va_end(va2); - result = Dqn_String8Allocate_(DQN_CALL_SITE_ARGS_INPUT allocator, size, Dqn_ZeroMem_No); - if (Dqn_String8IsValid(result)) { + result = Dqn_String8_Allocate_(DQN_CALL_SITE_ARGS_INPUT allocator, size, Dqn_ZeroMem_No); + if (Dqn_String8_IsValid(result)) { STB_SPRINTF_DECORATE(vsnprintf)(result.data, size + 1 /*null-terminator*/, fmt, va); result.data[result.size] = 0; } return result; } -DQN_API Dqn_String8 Dqn_String8Allocate_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, Dqn_isize size, Dqn_ZeroMem zero_mem) +DQN_API Dqn_isize Dqn_String8_FmtSize(char const *fmt, ...) +{ + va_list args; + va_start(args, fmt); + Dqn_isize result = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, args); + va_end(args); + return result; +} + +DQN_API Dqn_isize Dqn_String8_FmtSizeV(char const *fmt, va_list args) +{ + va_list args_copy; + va_copy(args_copy, args); + Dqn_isize result = STB_SPRINTF_DECORATE(vsnprintf)(nullptr, 0, fmt, args_copy); + va_end(args_copy); + return result; +} + +DQN_API Dqn_String8 Dqn_String8_Allocate_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, Dqn_isize size, Dqn_ZeroMem zero_mem) { Dqn_String8 result = {}; - result.data = (char *)Dqn_AllocatorAlloc(DQN_CALL_SITE_ARGS_INPUT allocator, size + 1, alignof(char), zero_mem); + result.data = (char *)Dqn_Allocator_Alloc(DQN_CALL_SITE_ARGS_INPUT allocator, size + 1, alignof(char), zero_mem); if (result.data) { result.size = size; } return result; } -DQN_API Dqn_String8 Dqn_String8CopyCString_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *string, Dqn_isize size) +DQN_API Dqn_String8 Dqn_String8_CopyCString_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, char const *string, Dqn_isize size) { Dqn_String8 result = {}; if (!string || size <= 0) return result; - result = Dqn_String8Allocate_(DQN_CALL_SITE_ARGS_INPUT allocator, size, Dqn_ZeroMem_No); - if (Dqn_String8IsValid(result)) { + result = Dqn_String8_Allocate_(DQN_CALL_SITE_ARGS_INPUT allocator, size, Dqn_ZeroMem_No); + if (Dqn_String8_IsValid(result)) { DQN_MEMCOPY(result.data, string, DQN_CAST(size_t)size); result.data[size] = 0; } return result; } -DQN_API Dqn_String8 Dqn_String8Copy_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, Dqn_String8 string) +DQN_API Dqn_String8 Dqn_String8_Copy_(DQN_CALL_SITE_ARGS Dqn_Allocator allocator, Dqn_String8 string) { - Dqn_String8 result = Dqn_String8CopyCString_(DQN_CALL_SITE_ARGS_INPUT allocator, string.data, string.size); + Dqn_String8 result = Dqn_String8_CopyCString_(DQN_CALL_SITE_ARGS_INPUT allocator, string.data, string.size); return result; } -DQN_API bool Dqn_String8Eq(Dqn_String8 lhs, Dqn_String8 rhs, Dqn_String8EqCase eq_case) +DQN_API bool Dqn_String8_Eq(Dqn_String8 lhs, Dqn_String8 rhs, Dqn_String8_EqCase eq_case) { - if (!Dqn_String8IsValid(lhs) || !Dqn_String8IsValid(rhs)) + if (!Dqn_String8_IsValid(lhs) || !Dqn_String8_IsValid(rhs)) return false; bool result = lhs.size == rhs.size; if (result) { - if (eq_case == Dqn_String8EqCase::Sensitive) { + if (eq_case == Dqn_String8_EqCase::Sensitive) { result = (DQN_MEMCMP(lhs.data, rhs.data, DQN_CAST(size_t)lhs.size) == 0); } else { for (Dqn_isize index = 0; index < lhs.size && result; index++) - result = (Dqn_CharToLower(lhs.data[index]) == Dqn_CharToLower(rhs.data[index])); + result = (Dqn_Char_ToLower(lhs.data[index]) == Dqn_Char_ToLower(rhs.data[index])); } } return result; } -DQN_API bool Dqn_String8EqInsensitive(Dqn_String8 lhs, Dqn_String8 rhs) +DQN_API bool Dqn_String8_EqInsensitive(Dqn_String8 lhs, Dqn_String8 rhs) { - bool result = Dqn_String8Eq(lhs, rhs, Dqn_String8EqCase::Insensitive); + bool result = Dqn_String8_Eq(lhs, rhs, Dqn_String8_EqCase::Insensitive); return result; } -DQN_API bool Dqn_String8StartsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8EqCase eq_case) +DQN_API bool Dqn_String8_StartsWith(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8_EqCase eq_case) { - Dqn_String8 substring = Dqn_String8Slice(string, 0, prefix.size); - bool result = Dqn_String8Eq(substring, prefix, eq_case); + Dqn_String8 substring = Dqn_String8_Slice(string, 0, prefix.size); + bool result = Dqn_String8_Eq(substring, prefix, eq_case); return result; } -DQN_API bool Dqn_String8StartsWithInsensitive(Dqn_String8 string, Dqn_String8 prefix) +DQN_API bool Dqn_String8_StartsWithInsensitive(Dqn_String8 string, Dqn_String8 prefix) { - bool result = Dqn_String8StartsWith(string, prefix, Dqn_String8EqCase::Insensitive); + bool result = Dqn_String8_StartsWith(string, prefix, Dqn_String8_EqCase::Insensitive); return result; } -DQN_API bool Dqn_String8EndsWith(Dqn_String8 string, +DQN_API bool Dqn_String8_EndsWith(Dqn_String8 string, Dqn_String8 suffix, - Dqn_String8EqCase eq_case) + Dqn_String8_EqCase eq_case) { - Dqn_String8 substring = Dqn_String8Slice(string, string.size - suffix.size, suffix.size); - bool result = Dqn_String8Eq(substring, suffix, eq_case); + Dqn_String8 substring = Dqn_String8_Slice(string, string.size - suffix.size, suffix.size); + bool result = Dqn_String8_Eq(substring, suffix, eq_case); return result; } -DQN_API bool Dqn_String8EndsWithInsensitive(Dqn_String8 string, Dqn_String8 suffix) +DQN_API bool Dqn_String8_EndsWithInsensitive(Dqn_String8 string, Dqn_String8 suffix) { - bool result = Dqn_String8EndsWith(string, suffix, Dqn_String8EqCase::Insensitive); + bool result = Dqn_String8_EndsWith(string, suffix, Dqn_String8_EqCase::Insensitive); return result; } -DQN_API Dqn_isize Dqn_String8Split(Dqn_String8 string, char delimiter, Dqn_String8 *splits, Dqn_isize splits_count) +DQN_API Dqn_isize Dqn_String8_Split(Dqn_String8 string, char delimiter, Dqn_String8 *splits, Dqn_isize splits_count) { Dqn_isize result = 0; // The number of splits in the actual string. - if (!Dqn_String8IsValid(string)) + if (!Dqn_String8_IsValid(string)) return result; Dqn_isize splits_index = 0; // The number of splits written. @@ -4024,7 +3998,7 @@ DQN_API Dqn_isize Dqn_String8Split(Dqn_String8 string, char delimiter, Dqn_Strin } if (splits && splits_index < splits_count) { - auto split = Dqn_String8Init(string.data + begin, index - begin); + auto split = Dqn_String8_Init(string.data + begin, index - begin); splits[splits_index++] = split; } @@ -4035,34 +4009,34 @@ DQN_API Dqn_isize Dqn_String8Split(Dqn_String8 string, char delimiter, Dqn_Strin return result; } -DQN_API Dqn_String8 Dqn_String8TrimPrefix(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8EqCase eq_case) +DQN_API Dqn_String8 Dqn_String8_TrimPrefix(Dqn_String8 string, Dqn_String8 prefix, Dqn_String8_EqCase eq_case) { Dqn_String8 result = string; - if (Dqn_String8StartsWith(result, prefix, eq_case)) { - result = Dqn_String8Slice(result, prefix.size, result.size - prefix.size); + if (Dqn_String8_StartsWith(result, prefix, eq_case)) { + result = Dqn_String8_Slice(result, prefix.size, result.size - prefix.size); } return result; } -DQN_API Dqn_String8 Dqn_String8TrimSuffix(Dqn_String8 string, Dqn_String8 suffix, Dqn_String8EqCase eq_case) +DQN_API Dqn_String8 Dqn_String8_TrimSuffix(Dqn_String8 string, Dqn_String8 suffix, Dqn_String8_EqCase eq_case) { Dqn_String8 result = string; - if (Dqn_String8EndsWith(string, suffix, eq_case)) { - result = Dqn_String8Slice(result, 0, result.size - suffix.size); + if (Dqn_String8_EndsWith(string, suffix, eq_case)) { + result = Dqn_String8_Slice(result, 0, result.size - suffix.size); } return result; } -DQN_API Dqn_String8 Dqn_String8TrimWhitespaceAround(Dqn_String8 string) +DQN_API Dqn_String8 Dqn_String8_TrimWhitespaceAround(Dqn_String8 string) { Dqn_String8 result = {}; - if (Dqn_String8IsValid(string)) { - result.data = DQN_CAST(char *)Dqn_CStringTrimWhitespaceAround(string.data, string.size, &result.size); + if (Dqn_String8_IsValid(string)) { + result.data = DQN_CAST(char *)Dqn_CString8_TrimWhitespaceAround(string.data, string.size, &result.size); } return result; } -DQN_API Dqn_String8 Dqn_String8TrimByteOrderMark(Dqn_String8 string) +DQN_API Dqn_String8 Dqn_String8_TrimByteOrderMark(Dqn_String8 string) { // TODO(dqn): This is little endian auto const UTF8_BOM = DQN_STRING8("\xEF\xBB\xBF"); @@ -4071,26 +4045,26 @@ DQN_API Dqn_String8 Dqn_String8TrimByteOrderMark(Dqn_String8 string) auto const UTF32_BOM_BE = DQN_STRING8("\x00\x00\xFE\xFF"); auto const UTF32_BOM_LE = DQN_STRING8("\xFF\xFE\x00\x00"); Dqn_String8 result = string; - result = Dqn_String8TrimPrefix(result, UTF8_BOM); - result = Dqn_String8TrimPrefix(result, UTF16_BOM_BE); - result = Dqn_String8TrimPrefix(result, UTF16_BOM_LE); - result = Dqn_String8TrimPrefix(result, UTF32_BOM_BE); - result = Dqn_String8TrimPrefix(result, UTF32_BOM_LE); + result = Dqn_String8_TrimPrefix(result, UTF8_BOM); + result = Dqn_String8_TrimPrefix(result, UTF16_BOM_BE); + result = Dqn_String8_TrimPrefix(result, UTF16_BOM_LE); + result = Dqn_String8_TrimPrefix(result, UTF32_BOM_BE); + result = Dqn_String8_TrimPrefix(result, UTF32_BOM_LE); return result; } -DQN_API bool Dqn_String8IsAllDigits(Dqn_String8 string) +DQN_API bool Dqn_String8_IsAllDigits(Dqn_String8 string) { - bool result = Dqn_String8IsValid(string) && string.size > 0; + bool result = Dqn_String8_IsValid(string) && string.size > 0; for (Dqn_isize index = 0; result && index < string.size; index++) result = string.data[index] >= '0' && string.data[index] <= '9'; return result; } -DQN_API bool Dqn_String8IsAllHex(Dqn_String8 string) +DQN_API bool Dqn_String8_IsAllHex(Dqn_String8 string) { - Dqn_String8 trimmed = Dqn_String8TrimPrefix(string, DQN_STRING8("0x"), Dqn_String8EqCase::Insensitive); - bool result = Dqn_String8IsValid(trimmed) && trimmed.size > 0; + Dqn_String8 trimmed = Dqn_String8_TrimPrefix(string, DQN_STRING8("0x"), Dqn_String8_EqCase::Insensitive); + bool result = Dqn_String8_IsValid(trimmed) && trimmed.size > 0; for (Dqn_isize index = 0; result && index < trimmed.size; index++) { char ch = trimmed.data[index]; result = (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'); @@ -4098,7 +4072,7 @@ DQN_API bool Dqn_String8IsAllHex(Dqn_String8 string) return result; } -DQN_API bool Dqn_String8HasChar(Dqn_String8 string, char ch) +DQN_API bool Dqn_String8_HasChar(Dqn_String8 string, char ch) { bool result = false; for (Dqn_isize index = 0; !result && index < string.size; index++) { @@ -4107,10 +4081,10 @@ DQN_API bool Dqn_String8HasChar(Dqn_String8 string, char ch) return result; } -DQN_API void Dqn_String8Remove(Dqn_String8 *string, Dqn_isize begin, Dqn_isize size) +DQN_API void Dqn_String8_Remove(Dqn_String8 *string, Dqn_isize begin, Dqn_isize size) { if (!string || - !Dqn_String8IsValid(*string) || + !Dqn_String8_IsValid(*string) || (begin < 0 || begin >= string->size) || (size <= 0 || size >= string->size)) { @@ -4124,46 +4098,46 @@ DQN_API void Dqn_String8Remove(Dqn_String8 *string, Dqn_isize begin, Dqn_isize s string->size -= size; } -DQN_API Dqn_isize Dqn_String8FindOffset(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8EqCase eq_case) +DQN_API Dqn_isize Dqn_String8_FindOffset(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8_EqCase eq_case) { Dqn_isize result = -1; - if (!Dqn_String8IsValid(string) || !Dqn_String8IsValid(find) || start_index < 0) + if (!Dqn_String8_IsValid(string) || !Dqn_String8_IsValid(find) || start_index < 0) return -1; Dqn_isize max = string.size - find.size; for (Dqn_isize index = start_index; result == -1 && index <= max; index++) { - Dqn_String8 check = Dqn_String8Slice(string, index, find.size); - if (Dqn_String8Eq(check, find, eq_case)) + Dqn_String8 check = Dqn_String8_Slice(string, index, find.size); + if (Dqn_String8_Eq(check, find, eq_case)) result = index; } return result; } -DQN_API Dqn_String8 Dqn_String8Find(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8EqCase eq_case) +DQN_API Dqn_String8 Dqn_String8_Find(Dqn_String8 string, Dqn_String8 find, Dqn_isize start_index, Dqn_String8_EqCase eq_case) { - Dqn_isize offset = Dqn_String8FindOffset(string, find, start_index, eq_case); - Dqn_String8 result = Dqn_String8Slice(string, offset == -1 ? 0 : offset, offset == -1 ? 0 : find.size); + Dqn_isize offset = Dqn_String8_FindOffset(string, find, start_index, eq_case); + Dqn_String8 result = Dqn_String8_Slice(string, offset == -1 ? 0 : offset, offset == -1 ? 0 : find.size); return result; } -DQN_API Dqn_String8 Dqn_String8Replace(Dqn_String8 string, +DQN_API Dqn_String8 Dqn_String8_Replace(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Arena *arena, Dqn_Arena *temp_arena, - Dqn_String8EqCase eq_case) + Dqn_String8_EqCase eq_case) { auto temp_arena_scope = Dqn_ArenaTempMemoryScope(temp_arena); Dqn_String8Builder string_builder = {}; - string_builder.allocator = Dqn_ArenaAllocator(temp_arena); + string_builder.allocator = Dqn_Arena_Allocator(temp_arena); Dqn_isize max = string.size - find.size; Dqn_isize head = start_index; for (Dqn_isize tail = head; tail <= max; tail++) { - Dqn_String8 check = Dqn_String8Slice(string, tail, find.size); - if (!Dqn_String8Eq(check, find, eq_case)) + Dqn_String8 check = Dqn_String8_Slice(string, tail, find.size); + if (!Dqn_String8_Eq(check, find, eq_case)) continue; if (start_index > 0 && string_builder.string_size == 0) { @@ -4171,13 +4145,13 @@ DQN_API Dqn_String8 Dqn_String8Replace(Dqn_String8 string, // need to add the string up to the hint. We only do this if there's // a replacement action, otherwise we have a special case for no // replacements, where the entire string gets copied. - Dqn_String8 slice = Dqn_String8Init(string.data, head); - Dqn_String8BuilderAppendString8Ref(&string_builder, slice); + Dqn_String8 slice = Dqn_String8_Init(string.data, head); + Dqn_String8Builder_AppendString8Ref(&string_builder, slice); } - Dqn_String8 range = Dqn_String8Slice(string, head, (tail - head)); - Dqn_String8BuilderAppendString8Ref(&string_builder, range); - Dqn_String8BuilderAppendString8Ref(&string_builder, replace); + Dqn_String8 range = Dqn_String8_Slice(string, head, (tail - head)); + Dqn_String8Builder_AppendString8Ref(&string_builder, range); + Dqn_String8Builder_AppendString8Ref(&string_builder, replace); head = tail + find.size; tail += find.size - 1; // NOTE: -1 since the for loop will post increment us past the end of the find string } @@ -4185,59 +4159,59 @@ DQN_API Dqn_String8 Dqn_String8Replace(Dqn_String8 string, Dqn_String8 result = {}; if (string_builder.string_size == 0) { // NOTE: No replacement possible, so we just do a full-copy - result = Dqn_String8Copy(Dqn_ArenaAllocator(arena), string); + result = Dqn_String8_Copy(Dqn_Arena_Allocator(arena), string); } else { - Dqn_String8 remainder = Dqn_String8Init(string.data + head, string.size - head); - Dqn_String8BuilderAppendString8Ref(&string_builder, remainder); - result = Dqn_String8BuilderBuild(&string_builder, Dqn_ArenaAllocator(arena)); + Dqn_String8 remainder = Dqn_String8_Init(string.data + head, string.size - head); + Dqn_String8Builder_AppendString8Ref(&string_builder, remainder); + result = Dqn_String8Builder_Build(&string_builder, Dqn_Arena_Allocator(arena)); } return result; } -DQN_API Dqn_String8 Dqn_String8ReplaceInsensitive(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Arena *arena, Dqn_Arena *temp_arena) +DQN_API Dqn_String8 Dqn_String8_ReplaceInsensitive(Dqn_String8 string, Dqn_String8 find, Dqn_String8 replace, Dqn_isize start_index, Dqn_Arena *arena, Dqn_Arena *temp_arena) { - Dqn_String8 result = Dqn_String8Replace(string, find, replace, start_index, arena, temp_arena, Dqn_String8EqCase::Insensitive); + Dqn_String8 result = Dqn_String8_Replace(string, find, replace, start_index, arena, temp_arena, Dqn_String8_EqCase::Insensitive); return result; } -DQN_API Dqn_String8 Dqn_String8FileNameFromPath(Dqn_String8 path) +DQN_API Dqn_String8 Dqn_String8_FileNameFromPath(Dqn_String8 path) { Dqn_String8 result = path; - if (!Dqn_String8IsValid(path)) { + if (!Dqn_String8_IsValid(path)) { return result; } for (Dqn_isize index = (result.size - 1); index >= 0; --index) { if (result.data[index] == '\\' || result.data[index] == '/') { char const *end = result.data + result.size; - result = Dqn_String8Slice(path, index + 1, end - result.data); + result = Dqn_String8_Slice(path, index + 1, end - result.data); break; } } return result; } -DQN_API Dqn_u64 Dqn_String8ToU64(Dqn_String8 string) +DQN_API uint64_t Dqn_String8_ToU64(Dqn_String8 string) { - Dqn_u64 result = Dqn_CStringToU64(string.data, DQN_CAST(int)string.size); + uint64_t result = Dqn_CString8_ToU64(string.data, DQN_CAST(int)string.size); return result; } -DQN_API Dqn_i64 Dqn_String8ToI64(Dqn_String8 string) +DQN_API uint64_t Dqn_String8_ToI64(Dqn_String8 string) { - Dqn_i64 result = Dqn_CStringToI64(string.data, DQN_CAST(int)string.size); + uint64_t result = Dqn_CString8_ToI64(string.data, DQN_CAST(int)string.size); return result; } // NOTE: Dqn_String8Builder Implementation // ----------------------------------------------------------------------------- -bool Dqn_String8BuilderAppendString8Ref(Dqn_String8Builder *builder, Dqn_String8 string) +bool Dqn_String8Builder_AppendString8Ref(Dqn_String8Builder *builder, Dqn_String8 string) { if (!builder || !string.data || string.size <= 0) return false; - Dqn_String8Link *link = Dqn_AllocatorNew(builder->allocator, Dqn_String8Link, Dqn_ZeroMem_No); + Dqn_String8_Link *link = Dqn_Allocator_New(builder->allocator, Dqn_String8_Link, Dqn_ZeroMem_No); if (!link) return false; link->string = string; @@ -4255,14 +4229,14 @@ bool Dqn_String8BuilderAppendString8Ref(Dqn_String8Builder *builder, Dqn_String8 return true; } -bool Dqn_String8BuilderAppendString8Copy(Dqn_String8Builder *builder, Dqn_String8 string) +bool Dqn_String8Builder_AppendString8Copy(Dqn_String8Builder *builder, Dqn_String8 string) { - Dqn_String8 copy = Dqn_String8Copy(builder->allocator, string); - bool result = Dqn_String8BuilderAppendString8Ref(builder, string); + Dqn_String8 copy = Dqn_String8_Copy(builder->allocator, string); + bool result = Dqn_String8Builder_AppendString8Ref(builder, string); return result; } -bool Dqn_String8BuilderAppendFmtVArgs(Dqn_String8Builder *builder, char const *fmt, va_list args) +bool Dqn_String8Builder_AppendFmtVArgs(Dqn_String8Builder *builder, char const *fmt, va_list args) { va_list args_copy; va_copy(args_copy, args); @@ -4278,40 +4252,40 @@ bool Dqn_String8BuilderAppendFmtVArgs(Dqn_String8Builder *builder, char const *f bool result = false; int alloc_size = size_no_zero_terminate + 1; Dqn_String8 string = DQN_ZERO_INIT; - string.data = Dqn_AllocatorNewArray(builder->allocator, char, alloc_size, Dqn_ZeroMem_No); + string.data = Dqn_Allocator_NewArray(builder->allocator, char, alloc_size, Dqn_ZeroMem_No); if (string.data) { vsnprintf(string.data, alloc_size, fmt, args); string.size = size_no_zero_terminate; - result = Dqn_String8BuilderAppendString8Ref(builder, string); + result = Dqn_String8Builder_AppendString8Ref(builder, string); } if (!result) { - Dqn_AllocatorDealloc(builder->allocator, string.data, size_no_zero_terminate); + Dqn_Allocator_Dealloc(builder->allocator, string.data, size_no_zero_terminate); } return result; } -bool Dqn_String8BuilderAppendFmtArgs(Dqn_String8Builder *builder, char const *fmt, ...) +bool Dqn_String8Builder_AppendFmtArgs(Dqn_String8Builder *builder, char const *fmt, ...) { va_list args; va_start(args, fmt); - bool result = Dqn_String8BuilderAppendFmtVArgs(builder, fmt, args); + bool result = Dqn_String8Builder_AppendFmtVArgs(builder, fmt, args); va_end(args); return result; } -Dqn_String8 Dqn_String8BuilderBuild(Dqn_String8Builder const *builder, Dqn_Allocator allocator) +Dqn_String8 Dqn_String8Builder_Build(Dqn_String8Builder const *builder, Dqn_Allocator allocator) { Dqn_String8 result = DQN_ZERO_INIT; if (!builder || builder->string_size <= 0 || builder->count <= 0) return result; - result.data = Dqn_AllocatorNewArray(allocator, char, builder->string_size + 1, Dqn_ZeroMem_No); + result.data = Dqn_Allocator_NewArray(allocator, char, builder->string_size + 1, Dqn_ZeroMem_No); if (!result.data) return result; - for (Dqn_String8Link *link = builder->head; link; link = link->next) { + for (Dqn_String8_Link *link = builder->head; link; link = link->next) { DQN_MEMCOPY(result.data + result.size, link->string.data, link->string.size); result.size += link->string.size; } @@ -4323,7 +4297,7 @@ Dqn_String8 Dqn_String8BuilderBuild(Dqn_String8Builder const *builder, Dqn_Alloc // NOTE: Dqn_Arena // ------------------------------------------------------------------------------------------------- -DQN_API bool Dqn_ArenaGrow_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize size, Dqn_isize commit) +DQN_API bool Dqn_Arena_Grow_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize size, Dqn_isize commit) { // TODO: Use the call site arguments if (!arena || size <= 0) { @@ -4340,7 +4314,7 @@ DQN_API bool Dqn_ArenaGrow_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize size, // the OS to reserve+commit in one call. bool commit_on_reserve = size == commit; auto const allocation_size = DQN_CAST(Dqn_isize)(sizeof(*arena->curr) + size); - auto *result = DQN_CAST(Dqn_ArenaBlock *)Dqn_VirtualReserve(allocation_size, commit_on_reserve); + auto *result = DQN_CAST(Dqn_Arena_Block *)Dqn_VirtualMem_Reserve(allocation_size, commit_on_reserve); if (result) { // NOTE: Sanity check memory is zero-ed out DQN_ASSERT(result->used == 0); @@ -4350,13 +4324,13 @@ DQN_API bool Dqn_ArenaGrow_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize size, // NOTE: If we didn't commit on reserve, commit the amount requested by // the user. if (!commit_on_reserve) { - Dqn_VirtualCommit(result, sizeof(*result) + commit); + Dqn_VirtualMem_Commit(result, sizeof(*result) + commit); } // NOTE: Setup the block result->size = size; result->committed = commit; - result->memory = DQN_CAST(Dqn_u8 *)result + sizeof(*result); + result->memory = DQN_CAST(uint8_t *)result + sizeof(*result); // NOTE: Attach the block to the arena if (arena->tail) { @@ -4380,7 +4354,7 @@ DQN_API bool Dqn_ArenaGrow_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize size, return result; } -DQN_API void *Dqn_ArenaAllocate_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize size, Dqn_u8 align, Dqn_ZeroMem zero_mem) +DQN_API void *Dqn_Arena_Allocate_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize size, uint8_t align, Dqn_ZeroMem zero_mem) { DQN_ASSERT_MSG((align & (align - 1)) == 0, "Power of two alignment required"); Dqn_isize allocation_size = size + (align - 1); @@ -4389,15 +4363,15 @@ DQN_API void *Dqn_ArenaAllocate_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize arena->curr = arena->curr->next; } else { Dqn_isize grow_size = DQN_MAX(DQN_MAX(allocation_size, arena->min_block_size), DQN_ARENA_MIN_BLOCK_SIZE); - if (!Dqn_ArenaGrow_(DQN_CALL_SITE_ARGS_INPUT arena, grow_size /*size*/, grow_size /*commit*/)) { + if (!Dqn_Arena_Grow_(DQN_CALL_SITE_ARGS_INPUT arena, grow_size /*size*/, grow_size /*commit*/)) { return nullptr; } } } // NOTE: Calculate an aligned allocation pointer - Dqn_ArenaBlock *block = arena->curr; - Dqn_uintptr const address = DQN_CAST(Dqn_uintptr)block->memory + block->used; + Dqn_Arena_Block *block = arena->curr; + uintptr_t const address = DQN_CAST(uintptr_t)block->memory + block->used; Dqn_isize const align_offset = (align - (address & (align - 1))) & (align - 1); void *result = DQN_CAST(char *)(address + align_offset); @@ -4409,7 +4383,7 @@ DQN_API void *Dqn_ArenaAllocate_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize Dqn_isize const commit_space = block->committed - block->used; if (commit_space < allocation_size) { Dqn_isize commit_size = allocation_size - commit_space; - Dqn_VirtualCommit(DQN_CAST(char *)result + commit_space, commit_size); + Dqn_VirtualMem_Commit(DQN_CAST(char *)result + commit_space, commit_size); block->committed += commit_size; } @@ -4429,37 +4403,37 @@ DQN_API void *Dqn_ArenaAllocate_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, Dqn_isize DQN_ASSERT_MSG(size + align_offset <= allocation_size, "Internal error: Alignment size calculation error [size=%_$$zd, offset=%zd, allocation_size=%_$$zd]", size, align_offset, allocation_size); DQN_ASSERT_MSG(block->used <= block->committed, "Internal error: Committed size must be greater than used size [used=%_$$zd, committed=%_$$zd]", block->used, block->committed); DQN_ASSERT_MSG(block->committed <= block->size, "Internal error: Allocation exceeded block capacity [committed=%_$$zd, size=%_$$zd]", block->committed, block->size); - DQN_ASSERT_MSG(((DQN_CAST(Dqn_uintptr)result) & (align - 1)) == 0, "Internal error: Pointer alignment failed [address=%p, align=%x]", result, align); + DQN_ASSERT_MSG(((DQN_CAST(uintptr_t)result) & (align - 1)) == 0, "Internal error: Pointer alignment failed [address=%p, align=%x]", result, align); return result; } -DQN_API void *Dqn_ArenaCopy_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, void *src, Dqn_isize size, Dqn_u8 alignment) +DQN_API void *Dqn_Arena_Copy_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, void *src, Dqn_isize size, uint8_t alignment) { - void *result = Dqn_ArenaAllocate_(DQN_CALL_SITE_ARGS_INPUT arena, size, alignment, Dqn_ZeroMem_No); + void *result = Dqn_Arena_Allocate_(DQN_CALL_SITE_ARGS_INPUT arena, size, alignment, Dqn_ZeroMem_No); DQN_MEMCOPY(result, src, size); return result; } -DQN_API void *Dqn_ArenaCopyZ_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, void *src, Dqn_isize size, Dqn_u8 alignment) +DQN_API void *Dqn_Arena_CopyZ_(DQN_CALL_SITE_ARGS Dqn_Arena *arena, void *src, Dqn_isize size, uint8_t alignment) { - void *result = Dqn_ArenaAllocate_(DQN_CALL_SITE_ARGS_INPUT arena, size + 1, alignment, Dqn_ZeroMem_No); + void *result = Dqn_Arena_Allocate_(DQN_CALL_SITE_ARGS_INPUT arena, size + 1, alignment, Dqn_ZeroMem_No); DQN_MEMCOPY(result, src, size); (DQN_CAST(char *)result)[size] = 0; return result; } -DQN_API void Dqn_ArenaFree(Dqn_Arena *arena, bool zero_mem) +DQN_API void Dqn_Arena_Free(Dqn_Arena *arena, bool zero_mem) { if (!arena) return; while (arena->tail) { - Dqn_ArenaBlock *tail = arena->tail; + Dqn_Arena_Block *tail = arena->tail; arena->tail = tail->prev; if (zero_mem) DQN_MEMSET(tail->memory, DQN_MEMSET_BYTE, tail->committed); - Dqn_VirtualRelease(tail, sizeof(*tail) + tail->size); + Dqn_VirtualMem_Release(tail, sizeof(*tail) + tail->size); } arena->curr = arena->tail = nullptr; @@ -4469,13 +4443,13 @@ DQN_API void Dqn_ArenaFree(Dqn_Arena *arena, bool zero_mem) arena->stats.blocks = 0; } -DQN_API void Dqn_ArenaReset(Dqn_Arena *arena, Dqn_ZeroMem zero_mem) +DQN_API void Dqn_Arena_Reset(Dqn_Arena *arena, Dqn_ZeroMem zero_mem) { if (!arena) return; // NOTE: Zero all the blocks until we reach the first block in the list - for (Dqn_ArenaBlock *block = arena->tail; block; block = block->prev) { + for (Dqn_Arena_Block *block = arena->tail; block; block = block->prev) { if (!block->prev) arena->curr = block; if (zero_mem == Dqn_ZeroMem_Yes) @@ -4487,35 +4461,35 @@ DQN_API void Dqn_ArenaReset(Dqn_Arena *arena, Dqn_ZeroMem zero_mem) arena->stats.wasted = 0; } -static void *Dqn_ArenaAllocatorAlloc(DQN_CALL_SITE_ARGS size_t size, uint8_t align, Dqn_ZeroMem zero_mem, void *user_context) +static void *Dqn_Arena_AllocatorAlloc(DQN_CALL_SITE_ARGS size_t size, uint8_t align, Dqn_ZeroMem zero_mem, void *user_context) { void *result = NULL; if (!user_context) return result; Dqn_Arena *arena = DQN_CAST(Dqn_Arena *)user_context; - result = Dqn_ArenaAllocate_(DQN_CALL_SITE_ARGS_INPUT arena, size, align, zero_mem); + result = Dqn_Arena_Allocate_(DQN_CALL_SITE_ARGS_INPUT arena, size, align, zero_mem); return result; } -static void Dqn_ArenaAllocatorDealloc(DQN_CALL_SITE_ARGS void *ptr, size_t size, void *user_context) +static void Dqn_Arena_AllocatorDealloc(DQN_CALL_SITE_ARGS void *ptr, size_t size, void *user_context) { // NOTE: No-op, arenas batch allocate and batch deallocate. Call free on the // underlying arena, since we can't free individual pointers. } -DQN_API Dqn_Allocator Dqn_ArenaAllocator(Dqn_Arena *arena) +DQN_API Dqn_Allocator Dqn_Arena_Allocator(Dqn_Arena *arena) { Dqn_Allocator result = {}; if (arena) { result.user_context = arena; - result.alloc = Dqn_ArenaAllocatorAlloc; - result.dealloc = Dqn_ArenaAllocatorDealloc; + result.alloc = Dqn_Arena_AllocatorAlloc; + result.dealloc = Dqn_Arena_AllocatorDealloc; } return result; } -DQN_API Dqn_ArenaTempMemory Dqn_ArenaBeginTempMemory(Dqn_Arena *arena) +DQN_API Dqn_ArenaTempMemory Dqn_Arena_BeginTempMemory(Dqn_Arena *arena) { Dqn_ArenaTempMemory result = {}; result.arena = arena; @@ -4526,7 +4500,7 @@ DQN_API Dqn_ArenaTempMemory Dqn_ArenaBeginTempMemory(Dqn_Arena *arena) return result; } -DQN_API void Dqn_ArenaEndTempMemory(Dqn_ArenaTempMemory scope) +DQN_API void Dqn_Arena_EndTempMemory(Dqn_ArenaTempMemory scope) { if (!scope.arena) { return; @@ -4545,7 +4519,7 @@ DQN_API void Dqn_ArenaEndTempMemory(Dqn_ArenaTempMemory scope) // NOTE: Free the tail blocks until we reach the scope's tail block while (arena->tail != scope.tail) { - Dqn_ArenaBlock *tail = arena->tail; + Dqn_Arena_Block *tail = arena->tail; arena->tail = tail->prev; DQN_FREE(tail); } @@ -4554,7 +4528,7 @@ DQN_API void Dqn_ArenaEndTempMemory(Dqn_ArenaTempMemory scope) if (arena->tail) { arena->tail->next = nullptr; - for (Dqn_ArenaBlock *block = arena->tail; block && block != arena->curr; block = block->prev) + for (Dqn_Arena_Block *block = arena->tail; block && block != arena->curr; block = block->prev) block->used = 0; } @@ -4562,15 +4536,15 @@ DQN_API void Dqn_ArenaEndTempMemory(Dqn_ArenaTempMemory scope) Dqn_ArenaTempMemoryScope::Dqn_ArenaTempMemoryScope(Dqn_Arena *arena) { - temp_memory = Dqn_ArenaBeginTempMemory(arena); + temp_memory = Dqn_Arena_BeginTempMemory(arena); } Dqn_ArenaTempMemoryScope::~Dqn_ArenaTempMemoryScope() { - Dqn_ArenaEndTempMemory(temp_memory); + Dqn_Arena_EndTempMemory(temp_memory); } -DQN_API Dqn_ArenaStatString Dqn_ArenaStatToString(Dqn_ArenaStat const *stat) +DQN_API Dqn_ArenaStatString Dqn_Arena_StatString(Dqn_ArenaStat const *stat) { // NOTE: We use a non-standard format string that is only usable via // stb sprintf that GCC warns about as an error. This pragma mutes that. @@ -4610,9 +4584,9 @@ DQN_API Dqn_ArenaStatString Dqn_ArenaStatToString(Dqn_ArenaStat const *stat) return result; } -DQN_API void Dqn_ArenaLogStats(Dqn_Arena const *arena) +DQN_API void Dqn_Arena_LogStats(Dqn_Arena const *arena) { - Dqn_ArenaStatString string = Dqn_ArenaStatToString(&arena->stats); + Dqn_ArenaStatString string = Dqn_Arena_StatString(&arena->stats); DQN_LOG_M("%.*s\n", DQN_STRING_FMT(string)); } @@ -4621,7 +4595,7 @@ DQN_API void Dqn_ArenaLogStats(Dqn_Arena const *arena) // ------------------------------------------------------------------------------------------------- DQN_API Dqn_V2I Dqn_V2ToV2I(Dqn_V2 a) { - Dqn_V2I result = Dqn_V2I(DQN_CAST(Dqn_i32)a.x, DQN_CAST(Dqn_i32)a.y); + Dqn_V2I result = Dqn_V2I(DQN_CAST(int32_t)a.x, DQN_CAST(int32_t)a.y); return result; } @@ -4703,7 +4677,7 @@ DQN_API Dqn_f32 Dqn_V4Dot(Dqn_V4 a, Dqn_V4 b) // NOTE: Dqn_M4 Implementation // ------------------------------------------------------------------------------------------------- -DQN_API Dqn_M4 Dqn_M4Identity() +DQN_API Dqn_M4 Dqn_M4_Identity() { Dqn_M4 result = {{ @@ -4716,7 +4690,7 @@ DQN_API Dqn_M4 Dqn_M4Identity() return result; } -DQN_API Dqn_M4 Dqn_M4ScaleF(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z) +DQN_API Dqn_M4 Dqn_M4_ScaleF(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z) { Dqn_M4 result = {{ @@ -4729,7 +4703,7 @@ DQN_API Dqn_M4 Dqn_M4ScaleF(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z) return result; } -DQN_API Dqn_M4 Dqn_M4Scale(Dqn_V3 xyz) +DQN_API Dqn_M4 Dqn_M4_Scale(Dqn_V3 xyz) { Dqn_M4 result = {{ @@ -4742,7 +4716,7 @@ DQN_API Dqn_M4 Dqn_M4Scale(Dqn_V3 xyz) return result; } -DQN_API Dqn_M4 Dqn_M4TranslateF(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z) +DQN_API Dqn_M4 Dqn_M4_TranslateF(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z) { Dqn_M4 result = {{ @@ -4755,7 +4729,7 @@ DQN_API Dqn_M4 Dqn_M4TranslateF(Dqn_f32 x, Dqn_f32 y, Dqn_f32 z) return result; } -DQN_API Dqn_M4 Dqn_M4Translate(Dqn_V3 xyz) +DQN_API Dqn_M4 Dqn_M4_Translate(Dqn_V3 xyz) { Dqn_M4 result = {{ @@ -4768,7 +4742,7 @@ DQN_API Dqn_M4 Dqn_M4Translate(Dqn_V3 xyz) return result; } -DQN_API Dqn_M4 Dqn_M4Transpose(Dqn_M4 mat) +DQN_API Dqn_M4 Dqn_M4_Transpose(Dqn_M4 mat) { Dqn_M4 result; for (int col = 0; col < 4; col++) @@ -4777,7 +4751,7 @@ DQN_API Dqn_M4 Dqn_M4Transpose(Dqn_M4 mat) return result; } -DQN_API Dqn_M4 Dqn_M4Rotate(Dqn_V3 axis01, Dqn_f32 radians) +DQN_API Dqn_M4 Dqn_M4_Rotate(Dqn_V3 axis01, Dqn_f32 radians) { DQN_ASSERT_MSG(DQN_ABS(Dqn_V3Length(axis01) - 1.f) <= 0.01f, "Rotation axis must be normalised, length = %f", @@ -4805,7 +4779,7 @@ DQN_API Dqn_M4 Dqn_M4Rotate(Dqn_V3 axis01, Dqn_f32 radians) return result; } -DQN_API Dqn_M4 Dqn_M4Orthographic(Dqn_f32 left, Dqn_f32 right, Dqn_f32 bottom, Dqn_f32 top, Dqn_f32 z_near, Dqn_f32 z_far) +DQN_API Dqn_M4 Dqn_M4_Orthographic(Dqn_f32 left, Dqn_f32 right, Dqn_f32 bottom, Dqn_f32 top, Dqn_f32 z_near, Dqn_f32 z_far) { Dqn_M4 result = {{ @@ -4818,7 +4792,7 @@ DQN_API Dqn_M4 Dqn_M4Orthographic(Dqn_f32 left, Dqn_f32 right, Dqn_f32 bottom, D return result; } -DQN_API Dqn_M4 Dqn_M4Perspective(Dqn_f32 fov /*radians*/, Dqn_f32 aspect, Dqn_f32 z_near, Dqn_f32 z_far) +DQN_API Dqn_M4 Dqn_M4_Perspective(Dqn_f32 fov /*radians*/, Dqn_f32 aspect, Dqn_f32 z_near, Dqn_f32 z_far) { Dqn_f32 tan_fov = DQN_TANF(fov / 2.f); Dqn_M4 result = @@ -4832,7 +4806,7 @@ DQN_API Dqn_M4 Dqn_M4Perspective(Dqn_f32 fov /*radians*/, Dqn_f32 aspect, Dqn_f3 return result; } -DQN_API Dqn_M4 Dqn_M4Add(Dqn_M4 lhs, Dqn_M4 rhs) +DQN_API Dqn_M4 Dqn_M4_Add(Dqn_M4 lhs, Dqn_M4 rhs) { Dqn_M4 result; for (int col = 0; col < 4; col++) @@ -4843,7 +4817,7 @@ DQN_API Dqn_M4 Dqn_M4Add(Dqn_M4 lhs, Dqn_M4 rhs) return result; } -DQN_API Dqn_M4 Dqn_M4Sub(Dqn_M4 lhs, Dqn_M4 rhs) +DQN_API Dqn_M4 Dqn_M4_Sub(Dqn_M4 lhs, Dqn_M4 rhs) { Dqn_M4 result; for (int col = 0; col < 4; col++) @@ -4854,7 +4828,7 @@ DQN_API Dqn_M4 Dqn_M4Sub(Dqn_M4 lhs, Dqn_M4 rhs) return result; } -DQN_API Dqn_M4 Dqn_M4Mul(Dqn_M4 lhs, Dqn_M4 rhs) +DQN_API Dqn_M4 Dqn_M4_Mul(Dqn_M4 lhs, Dqn_M4 rhs) { Dqn_M4 result; for (int col = 0; col < 4; col++) @@ -4871,7 +4845,7 @@ DQN_API Dqn_M4 Dqn_M4Mul(Dqn_M4 lhs, Dqn_M4 rhs) return result; } -DQN_API Dqn_M4 Dqn_M4Div(Dqn_M4 lhs, Dqn_M4 rhs) +DQN_API Dqn_M4 Dqn_M4_Div(Dqn_M4 lhs, Dqn_M4 rhs) { Dqn_M4 result; for (int col = 0; col < 4; col++) @@ -4882,7 +4856,7 @@ DQN_API Dqn_M4 Dqn_M4Div(Dqn_M4 lhs, Dqn_M4 rhs) return result; } -DQN_API Dqn_M4 Dqn_M4AddF(Dqn_M4 lhs, Dqn_f32 rhs) +DQN_API Dqn_M4 Dqn_M4_AddF(Dqn_M4 lhs, Dqn_f32 rhs) { Dqn_M4 result; for (int col = 0; col < 4; col++) @@ -4893,7 +4867,7 @@ DQN_API Dqn_M4 Dqn_M4AddF(Dqn_M4 lhs, Dqn_f32 rhs) return result; } -DQN_API Dqn_M4 Dqn_M4SubF(Dqn_M4 lhs, Dqn_f32 rhs) +DQN_API Dqn_M4 Dqn_M4_SubF(Dqn_M4 lhs, Dqn_f32 rhs) { Dqn_M4 result; for (int col = 0; col < 4; col++) @@ -4904,7 +4878,7 @@ DQN_API Dqn_M4 Dqn_M4SubF(Dqn_M4 lhs, Dqn_f32 rhs) return result; } -DQN_API Dqn_M4 Dqn_M4MulF(Dqn_M4 lhs, Dqn_f32 rhs) +DQN_API Dqn_M4 Dqn_M4_MulF(Dqn_M4 lhs, Dqn_f32 rhs) { Dqn_M4 result; for (int col = 0; col < 4; col++) @@ -4915,7 +4889,7 @@ DQN_API Dqn_M4 Dqn_M4MulF(Dqn_M4 lhs, Dqn_f32 rhs) return result; } -DQN_API Dqn_M4 Dqn_M4DivF(Dqn_M4 lhs, Dqn_f32 rhs) +DQN_API Dqn_M4 Dqn_M4_DivF(Dqn_M4 lhs, Dqn_f32 rhs) { Dqn_M4 result; for (int col = 0; col < 4; col++) @@ -4927,17 +4901,17 @@ DQN_API Dqn_M4 Dqn_M4DivF(Dqn_M4 lhs, Dqn_f32 rhs) } #if defined(DQN_WITH_FIXED_STRING) -DQN_API Dqn_FixedString<256> Dqn_M4ColumnMajorString(Dqn_M4 mat) +DQN_API Dqn_FixedString<256> Dqn_M4_ColumnMajorString(Dqn_M4 mat) { Dqn_FixedString<256> result = {}; for (int row = 0; row < 4; row++) { for (int it = 0; it < 4; it++) { - if (it == 0) Dqn_FixedStringAppend(&result, "|"); - Dqn_FixedStringAppendFmt(&result, "%.5f", mat.columns[it][row]); - if (it != 3) Dqn_FixedStringAppend(&result, ", "); - else Dqn_FixedStringAppend(&result, "|\n"); + if (it == 0) Dqn_FixedString_Append(&result, "|"); + Dqn_FixedString_AppendFmt(&result, "%.5f", mat.columns[it][row]); + if (it != 3) Dqn_FixedString_Append(&result, ", "); + else Dqn_FixedString_Append(&result, "|\n"); } } @@ -4947,7 +4921,7 @@ DQN_API Dqn_FixedString<256> Dqn_M4ColumnMajorString(Dqn_M4 mat) // NOTE: Dqn_Rect // ------------------------------------------------------------------------------------------------- -DQN_API Dqn_Rect Dqn_RectInitFromPosAndSize(Dqn_V2 pos, Dqn_V2 size) +DQN_API Dqn_Rect Dqn_Rect_InitFromPosAndSize(Dqn_V2 pos, Dqn_V2 size) { Dqn_Rect result = {}; result.min = pos; @@ -4957,32 +4931,32 @@ DQN_API Dqn_Rect Dqn_RectInitFromPosAndSize(Dqn_V2 pos, Dqn_V2 size) return result; } -DQN_API Dqn_V2 Dqn_RectCenter(Dqn_Rect rect) +DQN_API Dqn_V2 Dqn_Rect_Center(Dqn_Rect rect) { Dqn_V2 size = rect.max - rect.min; Dqn_V2 result = rect.min + (size * 0.5f); return result; } -DQN_API bool Dqn_RectContainsPoint(Dqn_Rect rect, Dqn_V2 p) +DQN_API bool Dqn_Rect_ContainsPoint(Dqn_Rect rect, Dqn_V2 p) { bool result = (p.x >= rect.min.x && p.x <= rect.max.x && p.y >= rect.min.y && p.y <= rect.max.y); return result; } -DQN_API bool Dqn_RectContainsRect(Dqn_Rect a, Dqn_Rect b) +DQN_API bool Dqn_Rect_ContainsRect(Dqn_Rect a, Dqn_Rect b) { bool result = (b.min >= a.min && b.max <= a.max); return result; } -DQN_API Dqn_V2 Dqn_RectSize(Dqn_Rect rect) +DQN_API Dqn_V2 Dqn_Rect_Size(Dqn_Rect rect) { Dqn_V2 result = rect.max - rect.min; return result; } -DQN_API Dqn_Rect Dqn_RectMove(Dqn_Rect src, Dqn_V2 move_amount) +DQN_API Dqn_Rect Dqn_Rect_Move(Dqn_Rect src, Dqn_V2 move_amount) { Dqn_Rect result = src; result.min += move_amount; @@ -4990,7 +4964,7 @@ DQN_API Dqn_Rect Dqn_RectMove(Dqn_Rect src, Dqn_V2 move_amount) return result; } -DQN_API Dqn_Rect Dqn_RectMoveTo(Dqn_Rect src, Dqn_V2 dest) +DQN_API Dqn_Rect Dqn_Rect_MoveTo(Dqn_Rect src, Dqn_V2 dest) { Dqn_V2 move_amount = dest - src.min; Dqn_Rect result = src; @@ -4999,17 +4973,17 @@ DQN_API Dqn_Rect Dqn_RectMoveTo(Dqn_Rect src, Dqn_V2 dest) return result; } -DQN_API bool Dqn_RectIntersects(Dqn_Rect a, Dqn_Rect b) +DQN_API bool Dqn_Rect_Intersects(Dqn_Rect a, Dqn_Rect b) { bool result = (a.min.x <= b.max.x && a.max.x >= b.min.x) && (a.min.y <= b.max.y && a.max.y >= b.min.y); return result; } -DQN_API Dqn_Rect Dqn_RectIntersection(Dqn_Rect a, Dqn_Rect b) +DQN_API Dqn_Rect Dqn_Rect_Intersection(Dqn_Rect a, Dqn_Rect b) { Dqn_Rect result = {}; - if (Dqn_RectIntersects(a, b)) + if (Dqn_Rect_Intersects(a, b)) { result.min.x = DQN_MAX(a.min.x, b.min.x); result.min.y = DQN_MAX(a.min.y, b.min.y); @@ -5020,7 +4994,7 @@ DQN_API Dqn_Rect Dqn_RectIntersection(Dqn_Rect a, Dqn_Rect b) return result; } -DQN_API Dqn_Rect Dqn_RectUnion(Dqn_Rect a, Dqn_Rect b) +DQN_API Dqn_Rect Dqn_Rect_Union(Dqn_Rect a, Dqn_Rect b) { Dqn_Rect result = {}; result.min.x = DQN_MIN(a.min.x, b.min.x); @@ -5030,7 +5004,7 @@ DQN_API Dqn_Rect Dqn_RectUnion(Dqn_Rect a, Dqn_Rect b) return result; } -DQN_API Dqn_Rect Dqn_RectFromRectI32(Dqn_RectI32 a) +DQN_API Dqn_Rect Dqn_Rect_FromRectI32(Dqn_RectI32 a) { Dqn_Rect result = Dqn_Rect(a.min, a.max); return result; @@ -5044,7 +5018,7 @@ DQN_API Dqn_V2I Dqn_RectI32_Size(Dqn_RectI32 rect) // NOTE: Math Utils // ------------------------------------------------------------------------------------------------- -DQN_API Dqn_V2 Dqn_LerpV2(Dqn_V2 a, Dqn_f32 t, Dqn_V2 b) +DQN_API Dqn_V2 Dqn_Lerp_V2(Dqn_V2 a, Dqn_f32 t, Dqn_V2 b) { Dqn_V2 result = {}; result.x = a.x + ((b.x - a.x) * t); @@ -5052,224 +5026,224 @@ DQN_API Dqn_V2 Dqn_LerpV2(Dqn_V2 a, Dqn_f32 t, Dqn_V2 b) return result; } -DQN_API Dqn_f32 Dqn_LerpF32(Dqn_f32 a, Dqn_f32 t, Dqn_f32 b) +DQN_API Dqn_f32 Dqn_Lerp_F32(Dqn_f32 a, Dqn_f32 t, Dqn_f32 b) { Dqn_f32 result = a + ((b - a) * t); return result; } #endif // DQN_WITH_MATH -// NOTE: Dqn_Bit +// NOTE: Dqn_Bit_ // ------------------------------------------------------------------------------------------------- -DQN_API void Dqn_BitUnsetInplace(Dqn_u64 *flags, Dqn_u64 bitfield) +DQN_API void Dqn_Bit_UnsetInplace(uint64_t *flags, uint64_t bitfield) { *flags = (*flags & ~bitfield); } -DQN_API void Dqn_BitSetInplace(Dqn_u64 *flags, Dqn_u64 bitfield) +DQN_API void Dqn_Bit_SetInplace(uint64_t *flags, uint64_t bitfield) { *flags = (*flags | bitfield); } -DQN_API bool Dqn_BitIsSet(Dqn_u64 bits, Dqn_u64 bits_to_set) +DQN_API bool Dqn_Bit_IsSet(uint64_t bits, uint64_t bits_to_set) { auto result = DQN_CAST(bool)((bits & bits_to_set) == bits_to_set); return result; } -DQN_API bool Dqn_BitIsNotSet(Dqn_u64 bits, Dqn_u64 bits_to_check) +DQN_API bool Dqn_Bit_IsNotSet(uint64_t bits, uint64_t bits_to_check) { - auto result = !Dqn_BitIsSet(bits, bits_to_check); + auto result = !Dqn_Bit_IsSet(bits, bits_to_check); return result; } // NOTE: Safe Arithmetic // ------------------------------------------------------------------------------------------------- -DQN_API Dqn_i64 Dqn_SafeAddI64(Dqn_i64 a, Dqn_i64 b) +DQN_API int64_t Dqn_Safe_AddI64(int64_t a, int64_t b) { - DQN_ASSERT_MSG(a <= DQN_I64_MAX - b, "%I64d <= %I64d", a, DQN_I64_MAX - b); - Dqn_i64 result = (a <= DQN_I64_MAX - b) ? (a + b) : DQN_I64_MAX; + DQN_ASSERT_MSG(a <= INT64_MAX - b, "%I64d <= %I64d", a, INT64_MAX - b); + int64_t result = (a <= INT64_MAX - b) ? (a + b) : INT64_MAX; return result; } -DQN_API Dqn_i64 Dqn_SafeMulI64(Dqn_i64 a, Dqn_i64 b) +DQN_API int64_t Dqn_Safe_MulI64(int64_t a, int64_t b) { - DQN_ASSERT_MSG(a <= DQN_I64_MAX / b , "%I64d <= %I64d", a, DQN_I64_MAX / b); - Dqn_i64 result = (a <= DQN_I64_MAX / b) ? (a * b) : DQN_I64_MAX; + DQN_ASSERT_MSG(a <= INT64_MAX / b , "%I64d <= %I64d", a, INT64_MAX / b); + int64_t result = (a <= INT64_MAX / b) ? (a * b) : INT64_MAX; return result; } -DQN_API Dqn_u64 Dqn_SafeAddU64(Dqn_u64 a, Dqn_u64 b) +DQN_API uint64_t Dqn_Safe_AddU64(uint64_t a, uint64_t b) { - DQN_ASSERT_MSG(a <= DQN_U64_MAX - b, "%I64u <= %I64u", a, DQN_U64_MAX - b); - Dqn_u64 result = (a <= DQN_U64_MAX - b) ? (a + b) : DQN_U64_MAX; + DQN_ASSERT_MSG(a <= UINT64_MAX - b, "%I64u <= %I64u", a, UINT64_MAX - b); + uint64_t result = (a <= UINT64_MAX - b) ? (a + b) : UINT64_MAX; return result; } -DQN_API Dqn_u64 Dqn_SafeSubU64(Dqn_u64 a, Dqn_u64 b) +DQN_API uint64_t Dqn_Safe_SubU64(uint64_t a, uint64_t b) { DQN_ASSERT_MSG(a >= b, "%I64u >= %I64u", a, b); - Dqn_u64 result = (a >= b) ? (a - b) : 0; + uint64_t result = (a >= b) ? (a - b) : 0; return result; } -DQN_API Dqn_u32 Dqn_SafeSubU32(Dqn_u32 a, Dqn_u32 b) +DQN_API uint32_t Dqn_Safe_SubU32(uint32_t a, uint32_t b) { DQN_ASSERT_MSG(a >= b, "%I32u >= %I32u", a, b); - Dqn_u32 result = (a >= b) ? (a - b) : 0; + uint32_t result = (a >= b) ? (a - b) : 0; return result; } -DQN_API Dqn_u64 Dqn_SafeMulU64(Dqn_u64 a, Dqn_u64 b) +DQN_API uint64_t Dqn_Safe_MulU64(uint64_t a, uint64_t b) { - DQN_ASSERT_MSG(a <= DQN_U64_MAX / b , "%I64u <= %I64u", a, DQN_U64_MAX / b); - Dqn_u64 result = (a <= DQN_U64_MAX / b) ? (a * b) : DQN_U64_MAX; + DQN_ASSERT_MSG(a <= UINT64_MAX / b , "%I64u <= %I64u", a, UINT64_MAX / b); + uint64_t result = (a <= UINT64_MAX / b) ? (a * b) : UINT64_MAX; return result; } -DQN_API int Dqn_SafeTruncateISizeToInt(Dqn_isize val) +DQN_API int Dqn_Safe_TruncateISizeToInt(Dqn_isize val) { - DQN_ASSERT_MSG(val >= DQN_I32_MIN && val <= DQN_I32_MAX, "%zd >= %zd && %zd <= %zd", val, DQN_I32_MAX, val, DQN_I32_MAX); - auto result = (val >= DQN_I32_MIN && val <= DQN_I32_MAX) ? DQN_CAST(int)val : 0; + DQN_ASSERT_MSG(val >= INT32_MIN && val <= INT32_MAX, "%zd >= %zd && %zd <= %zd", val, INT32_MAX, val, INT32_MAX); + auto result = (val >= INT32_MIN && val <= INT32_MAX) ? DQN_CAST(int)val : 0; return result; } -DQN_API Dqn_i32 Dqn_SafeTruncateISizeToI32(Dqn_isize val) +DQN_API int32_t Dqn_Safe_TruncateISizeToI32(Dqn_isize val) { - DQN_ASSERT_MSG(val >= DQN_I32_MIN && val <= DQN_I32_MAX, "%zd >= %zd && %zd <= %zd", val, DQN_I32_MIN, val, DQN_I32_MAX); - auto result = (val >= DQN_I32_MIN && val <= DQN_I32_MAX) ? DQN_CAST(Dqn_i32)val : 0; + DQN_ASSERT_MSG(val >= INT32_MIN && val <= INT32_MAX, "%zd >= %zd && %zd <= %zd", val, INT32_MIN, val, INT32_MAX); + auto result = (val >= INT32_MIN && val <= INT32_MAX) ? DQN_CAST(int32_t)val : 0; return result; } -DQN_API Dqn_u32 Dqn_SafeTruncateUSizeToU32(Dqn_usize val) +DQN_API uint32_t Dqn_Safe_TruncateUSizeToU32(Dqn_usize val) { - DQN_ASSERT_MSG(val <= DQN_U32_MAX, "%zu <= %zu", val, DQN_U32_MAX); - auto result = (val <= DQN_U32_MAX) ? DQN_CAST(Dqn_u32)val : DQN_U32_MAX; + DQN_ASSERT_MSG(val <= UINT32_MAX, "%zu <= %zu", val, UINT32_MAX); + auto result = (val <= UINT32_MAX) ? DQN_CAST(uint32_t)val : UINT32_MAX; return result; } -DQN_API Dqn_i32 Dqn_SafeTruncateUSizeToI32(Dqn_usize val) +DQN_API int32_t Dqn_Safe_TruncateUSizeToI32(Dqn_usize val) { - DQN_ASSERT_MSG(val <= DQN_I32_MAX, "%zu <= %zu", val, DQN_I32_MAX); - auto result = (val <= DQN_I32_MAX) ? DQN_CAST(int)val : DQN_I32_MAX; + DQN_ASSERT_MSG(val <= INT32_MAX, "%zu <= %zu", val, INT32_MAX); + auto result = (val <= INT32_MAX) ? DQN_CAST(int)val : INT32_MAX; return result; } -DQN_API int Dqn_SafeTruncateUSizeToInt(Dqn_usize val) +DQN_API int Dqn_Safe_TruncateUSizeToInt(Dqn_usize val) { - DQN_ASSERT_MSG(val <= DQN_I32_MAX, "%zu <= %zu", val, DQN_I32_MAX); - auto result = (val <= DQN_I32_MAX) ? DQN_CAST(int)val : DQN_I32_MAX; + DQN_ASSERT_MSG(val <= INT32_MAX, "%zu <= %zu", val, INT32_MAX); + auto result = (val <= INT32_MAX) ? DQN_CAST(int)val : INT32_MAX; return result; } -DQN_API Dqn_isize Dqn_SafeTruncateUSizeToISize(Dqn_usize val) +DQN_API Dqn_isize Dqn_Safe_TruncateUSizeToISize(Dqn_usize val) { DQN_ASSERT_MSG(val <= DQN_ISIZE_MAX, "%zu <= %zu", val, DQN_CAST(Dqn_usize)DQN_ISIZE_MAX); auto result = (val <= DQN_ISIZE_MAX) ? DQN_CAST(Dqn_isize)val : DQN_ISIZE_MAX; return result; } -DQN_API Dqn_isize Dqn_SafeTruncateI64ToISize(Dqn_i64 val) +DQN_API Dqn_isize Dqn_Safe_TruncateI64ToISize(uint64_t val) { DQN_ASSERT_MSG(val <= DQN_ISIZE_MAX, "[val=%zu, max=%zu]", val, DQN_ISIZE_MAX); auto result = (val <= DQN_ISIZE_MAX) ? DQN_CAST(Dqn_isize)val : DQN_ISIZE_MAX; return result; } -DQN_API Dqn_u32 Dqn_SafeTruncateU64ToU32(Dqn_u64 val) +DQN_API uint32_t Dqn_Safe_TruncateU64ToU32(uint64_t val) { - DQN_ASSERT_MSG(val <= DQN_U32_MAX, "%I64u <= %I64u", val, DQN_U32_MAX); - auto result = (val <= DQN_U32_MAX) ? DQN_CAST(Dqn_u32)val : DQN_U32_MAX; + DQN_ASSERT_MSG(val <= UINT32_MAX, "%I64u <= %I64u", val, UINT32_MAX); + auto result = (val <= UINT32_MAX) ? DQN_CAST(uint32_t)val : UINT32_MAX; return result; } -DQN_API Dqn_u16 Dqn_SafeTruncateU64ToU16(Dqn_u64 val) +DQN_API uint16_t Dqn_Safe_TruncateU64ToU16(uint64_t val) { - DQN_ASSERT_MSG(val <= DQN_U16_MAX, "%I64u <= %I64u", val, DQN_U16_MAX); - auto result = (val <= DQN_U16_MAX) ? DQN_CAST(Dqn_u16)val : DQN_U16_MAX; + DQN_ASSERT_MSG(val <= UINT16_MAX, "%I64u <= %I64u", val, UINT16_MAX); + auto result = (val <= UINT16_MAX) ? DQN_CAST(uint16_t)val : UINT16_MAX; return result; } -DQN_API Dqn_u8 Dqn_SafeTruncateU64ToU8(Dqn_u64 val) +DQN_API uint8_t Dqn_Safe_TruncateU64ToU8(uint64_t val) { - DQN_ASSERT_MSG(val <= DQN_U8_MAX, "%I64u <= %I64u", val, DQN_U8_MAX); - auto result = (val <= DQN_U8_MAX) ? DQN_CAST(Dqn_u8)val : DQN_U8_MAX; + DQN_ASSERT_MSG(val <= UINT8_MAX, "%I64u <= %I64u", val, UINT8_MAX); + auto result = (val <= UINT8_MAX) ? DQN_CAST(uint8_t)val : UINT8_MAX; return result; } -DQN_API Dqn_i64 Dqn_SafeTruncateU64ToI64(Dqn_u64 val) +DQN_API uint64_t Dqn_Safe_TruncateU64ToI64(uint64_t val) { - DQN_ASSERT_MSG(val <= DQN_I64_MAX, "%I64u <= %I64d", val, DQN_I64_MAX); - auto result = (val <= DQN_I64_MAX) ? DQN_CAST(Dqn_i64)val : DQN_I64_MAX; + DQN_ASSERT_MSG(val <= INT64_MAX, "%I64u <= %I64d", val, INT64_MAX); + auto result = (val <= INT64_MAX) ? DQN_CAST(uint64_t)val : INT64_MAX; return result; } -DQN_API Dqn_i32 Dqn_SafeTruncateU64ToI32(Dqn_u64 val) +DQN_API int32_t Dqn_Safe_TruncateU64ToI32(uint64_t val) { - DQN_ASSERT_MSG(val <= DQN_I32_MAX, "%I64u <= %I64d", val, DQN_I32_MAX); - auto result = (val <= DQN_I32_MAX) ? DQN_CAST(Dqn_i32)val : DQN_I32_MAX; + DQN_ASSERT_MSG(val <= INT32_MAX, "%I64u <= %I64d", val, INT32_MAX); + auto result = (val <= INT32_MAX) ? DQN_CAST(int32_t)val : INT32_MAX; return result; } -DQN_API Dqn_i16 Dqn_SafeTruncateU64ToI16(Dqn_u64 val) +DQN_API int16_t Dqn_Safe_TruncateU64ToI16(uint64_t val) { - DQN_ASSERT_MSG(val <= DQN_I16_MAX, "%I64u <= %I64d", val, DQN_I16_MAX); - auto result = (val <= DQN_I16_MAX) ? DQN_CAST(Dqn_i16)val : DQN_I16_MAX; + DQN_ASSERT_MSG(val <= UINT16_MAX, "%I64u <= %I64d", val, UINT16_MAX); + auto result = (val <= UINT16_MAX) ? DQN_CAST(int16_t)val : UINT16_MAX; return result; } -DQN_API Dqn_i8 Dqn_SafeTruncateU64ToI8(Dqn_u64 val) +DQN_API uint8_t Dqn_Safe_TruncateU64ToI8(uint64_t val) { - DQN_ASSERT_MSG(val <= DQN_I8_MAX, "%I64u <= %I64d", val, DQN_I8_MAX); - auto result = (val <= DQN_I8_MAX) ? DQN_CAST(Dqn_i8)val : DQN_I8_MAX; + DQN_ASSERT_MSG(val <= UINT8_MAX, "%I64u <= %I64d", val, UINT8_MAX); + auto result = (val <= UINT8_MAX) ? DQN_CAST(uint8_t)val : UINT8_MAX; return result; } -DQN_API int Dqn_SafeTruncateU64ToInt(Dqn_u64 val) +DQN_API int Dqn_Safe_TruncateU64ToInt(uint64_t val) { - DQN_ASSERT_MSG(val <= DQN_I32_MAX, "%I64u <= %I64d", val, DQN_I32_MAX); - auto result = (val <= DQN_I32_MAX) ? DQN_CAST(int)val : DQN_I32_MAX; + DQN_ASSERT_MSG(val <= INT32_MAX, "%I64u <= %I64d", val, INT32_MAX); + auto result = (val <= INT32_MAX) ? DQN_CAST(int)val : INT32_MAX; return result; } -// NOTE: Dqn_Char +// NOTE: Dqn_Char_ // ------------------------------------------------------------------------------------------------- -DQN_API bool Dqn_CharIsAlpha(char ch) +DQN_API bool Dqn_Char_IsAlpha(char ch) { bool result = (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); return result; } -DQN_API bool Dqn_CharIsDigit(char ch) +DQN_API bool Dqn_Char_IsDigit(char ch) { bool result = (ch >= '0' && ch <= '9'); return result; } -DQN_API bool Dqn_CharIsAlphaNum(char ch) +DQN_API bool Dqn_Char_IsAlphaNum(char ch) { - bool result = Dqn_CharIsAlpha(ch) || Dqn_CharIsDigit(ch); + bool result = Dqn_Char_IsAlpha(ch) || Dqn_Char_IsDigit(ch); return result; } -DQN_API bool Dqn_CharIsWhitespace(char ch) +DQN_API bool Dqn_Char_IsWhitespace(char ch) { bool result = (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); return result; } -DQN_API bool Dqn_CharIsHex(char ch) +DQN_API bool Dqn_Char_IsHex(char ch) { bool result = ((ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') || (ch >= '0' && ch <= '9')); return result; } -DQN_API Dqn_u8 Dqn_CharHexToU8(char ch) +DQN_API uint8_t Dqn_Char_HexToU8(char ch) { - DQN_ASSERT_MSG(Dqn_CharIsHex(ch), "Hex character not valid '%c'", ch); + DQN_ASSERT_MSG(Dqn_Char_IsHex(ch), "Hex character not valid '%c'", ch); - Dqn_u8 result = 0; + uint8_t result = 0; if (ch >= 'a' && ch <= 'f') result = ch - 'a' + 10; else if (ch >= 'A' && ch <= 'F') @@ -5280,20 +5254,20 @@ DQN_API Dqn_u8 Dqn_CharHexToU8(char ch) } char constexpr DQN_HEX_LUT[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; -DQN_API char Dqn_CharToHex(char ch) +DQN_API char Dqn_Char_ToHex(char ch) { char result = DQN_CAST(char)-1; if (ch <= 16) result = DQN_HEX_LUT[DQN_CAST(unsigned)ch]; return result; } -DQN_API char Dqn_CharToHexUnchecked(char ch) +DQN_API char Dqn_Char_ToHexUnchecked(char ch) { char result = DQN_HEX_LUT[DQN_CAST(unsigned)ch]; return result; } -DQN_API char Dqn_CharToLower(char ch) +DQN_API char Dqn_Char_ToLower(char ch) { char result = ch; if (result >= 'A' && result <= 'Z') @@ -5303,7 +5277,7 @@ DQN_API char Dqn_CharToLower(char ch) // NOTE: Dqn_UTF // ------------------------------------------------------------------------------------------------- -DQN_API int Dqn_UTF8EncodeCodepoint(Dqn_u8 utf8[4], Dqn_u32 codepoint) +DQN_API int Dqn_UTF8_EncodeCodepoint(uint8_t utf8[4], uint32_t codepoint) { // NOTE: Table from https://www.reedbeta.com/blog/programmers-intro-to-unicode/ // ----------------------------------------+----------------------------+--------------------+ @@ -5317,7 +5291,7 @@ DQN_API int Dqn_UTF8EncodeCodepoint(Dqn_u8 utf8[4], Dqn_u32 codepoint) if (codepoint <= 0b0111'1111) { - utf8[0] = DQN_CAST(Dqn_u8)codepoint; + utf8[0] = DQN_CAST(uint8_t)codepoint; return 1; } @@ -5348,7 +5322,7 @@ DQN_API int Dqn_UTF8EncodeCodepoint(Dqn_u8 utf8[4], Dqn_u32 codepoint) return 0; } -DQN_API int Dqn_UTF16EncodeCodepoint(Dqn_u16 utf16[2], Dqn_u32 codepoint) +DQN_API int Dqn_UTF16_EncodeCodepoint(uint16_t utf16[2], uint32_t codepoint) { // NOTE: Table from https://www.reedbeta.com/blog/programmers-intro-to-unicode/ // ----------------------------------------+------------------------------------+------------------+ @@ -5360,13 +5334,13 @@ DQN_API int Dqn_UTF16EncodeCodepoint(Dqn_u16 utf16[2], Dqn_u32 codepoint) if (codepoint <= 0b1111'1111'1111'1111) { - utf16[0] = DQN_CAST(Dqn_u16)codepoint; + utf16[0] = DQN_CAST(uint16_t)codepoint; return 1; } if (codepoint <= 0b1111'1111'1111'1111'1111) { - Dqn_u32 surrogate_codepoint = codepoint + 0x10000; + uint32_t surrogate_codepoint = codepoint + 0x10000; utf16[0] = 0b1101'1000'0000'0000 | ((surrogate_codepoint >> 10) & 0b11'1111'1111); // x utf16[1] = 0b1101'1100'0000'0000 | ((surrogate_codepoint >> 0) & 0b11'1111'1111); // y return 2; @@ -5376,13 +5350,13 @@ DQN_API int Dqn_UTF16EncodeCodepoint(Dqn_u16 utf16[2], Dqn_u32 codepoint) } #if defined(DQN_WITH_HEX) -// NOTE: Dqn_Hex +// NOTE: Dqn_Hex_ // ------------------------------------------------------------------------------------------------- -DQN_API char const *Dqn_HexCStringTrimSpaceAnd0xPrefix(char const *hex, Dqn_isize size, Dqn_isize *real_size) +DQN_API char const *Dqn_Hex_CStringTrimSpaceAnd0xPrefix(char const *hex, Dqn_isize size, Dqn_isize *real_size) { Dqn_isize trimmed_size = 0; - char const *trimmed_hex = Dqn_CStringTrimWhitespaceAround(hex, size, &trimmed_size); - char const *result = Dqn_CStringTrimPrefix(trimmed_hex, + char const *trimmed_hex = Dqn_CString8_TrimWhitespaceAround(hex, size, &trimmed_size); + char const *result = Dqn_CString8_TrimPrefix(trimmed_hex, trimmed_size, "0x", 2 /*prefix_size*/, @@ -5391,15 +5365,15 @@ DQN_API char const *Dqn_HexCStringTrimSpaceAnd0xPrefix(char const *hex, Dqn_isiz return result; } -DQN_API Dqn_String8 Dqn_HexStringTrimSpaceAnd0xPrefix(Dqn_String8 const string) +DQN_API Dqn_String8 Dqn_Hex_StringTrimSpaceAnd0xPrefix(Dqn_String8 const string) { Dqn_isize trimmed_size = 0; - char const *trimmed = Dqn_HexCStringTrimSpaceAnd0xPrefix(string.data, string.size, &trimmed_size); - Dqn_String8 result = Dqn_String8Init(trimmed, trimmed_size); + char const *trimmed = Dqn_Hex_CStringTrimSpaceAnd0xPrefix(string.data, string.size, &trimmed_size); + Dqn_String8 result = Dqn_String8_Init(trimmed, trimmed_size); return result; } -DQN_API Dqn_u64 Dqn_HexCStringToU64(char const *hex, Dqn_isize size) +DQN_API uint64_t Dqn_Hex_CStringToU64(char const *hex, Dqn_isize size) { Dqn_isize trim_size = size; char const *trim_hex = hex; @@ -5412,30 +5386,30 @@ DQN_API Dqn_u64 Dqn_HexCStringToU64(char const *hex, Dqn_isize size) } } - DQN_ASSERT(DQN_CAST(Dqn_usize)(trim_size * 4 / 8) /*maximum amount of bytes represented in the hex string*/ <= sizeof(Dqn_u64)); + DQN_ASSERT(DQN_CAST(Dqn_usize)(trim_size * 4 / 8) /*maximum amount of bytes represented in the hex string*/ <= sizeof(uint64_t)); - Dqn_u64 result = 0; + uint64_t result = 0; Dqn_usize bits_written = 0; for (Dqn_isize hex_index = 0; hex_index < size; hex_index++, bits_written += 4) { char ch = trim_hex[hex_index]; - if (!Dqn_CharIsHex(ch)) break; - Dqn_u8 val = Dqn_CharHexToU8(ch); + if (!Dqn_Char_IsHex(ch)) break; + uint8_t val = Dqn_Char_HexToU8(ch); Dqn_usize bit_shift = 60 - bits_written; - result |= (DQN_CAST(Dqn_u64)val << bit_shift); + result |= (DQN_CAST(uint64_t)val << bit_shift); } result >>= (64 - bits_written); // Shift the remainder digits to the end. return result; } -DQN_API Dqn_u64 Dqn_HexStringToU64(Dqn_String8 hex) +DQN_API uint64_t Dqn_Hex_StringToU64(Dqn_String8 hex) { - Dqn_u64 result = Dqn_HexCStringToU64(hex.data, hex.size); + uint64_t result = Dqn_Hex_CStringToU64(hex.data, hex.size); return result; } -DQN_API void Dqn_HexBytesToHex(void const *src, int src_size, char *dest, int dest_size) +DQN_API void Dqn_Hex_BytesToHex(void const *src, int src_size, char *dest, int dest_size) { (void)src_size; (void)dest_size; DQN_ASSERT(dest_size >= src_size * 2); @@ -5453,7 +5427,7 @@ DQN_API void Dqn_HexBytesToHex(void const *src, int src_size, char *dest, int de } } -DQN_API void Dqn_HexToBytes(char const *hex, int hex_size, void *dest, int dest_size) +DQN_API void Dqn_Hex_ToBytes(char const *hex, int hex_size, void *dest, int dest_size) { (void)hex_size; (void)dest_size; DQN_ASSERT(dest_size >= DQN_CAST(int)((hex_size / 2.f) + .5f)); @@ -5481,64 +5455,64 @@ DQN_API void Dqn_HexToBytes(char const *hex, int hex_size, void *dest, int dest_ } } -DQN_API char *Dqn_HexBytesToHexCStringArena(void const *bytes, Dqn_isize size, Dqn_Arena *arena) +DQN_API char *Dqn_Hex_BytesToHexCStringArena(void const *bytes, Dqn_isize size, Dqn_Arena *arena) { - char *result = size > 0 ? Dqn_ArenaNewArray(arena, char, (size * 2) + 1 /*null terminate*/, Dqn_ZeroMem_No) : nullptr; + char *result = size > 0 ? Dqn_Arena_NewArray(arena, char, (size * 2) + 1 /*null terminate*/, Dqn_ZeroMem_No) : nullptr; if (result) { - Dqn_HexBytesToHex(bytes, size, result, size * 2); + Dqn_Hex_BytesToHex(bytes, size, result, size * 2); result[size * 2] = 0; } return result; } -DQN_API Dqn_String8 Dqn_HexBytesToHexStringArena(void const *bytes, Dqn_isize size, Dqn_Arena *arena) +DQN_API Dqn_String8 Dqn_Hex_BytesToHexStringArena(void const *bytes, Dqn_isize size, Dqn_Arena *arena) { - char *c_string = Dqn_HexBytesToHexCStringArena(bytes, size, arena); + char *c_string = Dqn_Hex_BytesToHexCStringArena(bytes, size, arena); Dqn_String8 result = {}; if (c_string) - result = Dqn_String8Init(c_string, size * 2); + result = Dqn_String8_Init(c_string, size * 2); return result; } -DQN_API char *Dqn_HexU8ArrayToHexCStringArena(Dqn_Array const bytes, Dqn_Arena *arena) +DQN_API char *Dqn_Hex_U8ArrayToHexCStringArena(Dqn_Array const bytes, Dqn_Arena *arena) { - char *result = Dqn_HexBytesToHexCStringArena(bytes.data, bytes.size, arena); + char *result = Dqn_Hex_BytesToHexCStringArena(bytes.data, bytes.size, arena); return result; } -DQN_API Dqn_String8 Dqn_HexU8ArrayToHexStringArena(Dqn_Array const bytes, Dqn_Arena *arena) +DQN_API Dqn_String8 Dqn_Hex_U8ArrayToHexStringArena(Dqn_Array const bytes, Dqn_Arena *arena) { - Dqn_String8 result = Dqn_HexBytesToHexStringArena(bytes.data, bytes.size, arena); + Dqn_String8 result = Dqn_Hex_BytesToHexStringArena(bytes.data, bytes.size, arena); return result; } -DQN_API Dqn_u8 *Dqn_HexCStringToU8Bytes(char const *hex, Dqn_isize size, Dqn_isize *real_size, Dqn_Arena *arena) +DQN_API uint8_t *Dqn_Hex_CStringToU8Bytes(char const *hex, Dqn_isize size, Dqn_isize *real_size, Dqn_Arena *arena) { - hex = Dqn_HexCStringTrimSpaceAnd0xPrefix(hex, size, &size); + hex = Dqn_Hex_CStringTrimSpaceAnd0xPrefix(hex, size, &size); Dqn_isize binary_size = DQN_CAST(Dqn_isize)(size / 2.f + .5f); - Dqn_u8 *result = Dqn_ArenaNewArray(arena, Dqn_u8, binary_size, Dqn_ZeroMem_No); + uint8_t *result = Dqn_Arena_NewArray(arena, uint8_t, binary_size, Dqn_ZeroMem_No); if (result) - Dqn_HexToBytes(hex, size, result, binary_size); + Dqn_Hex_ToBytes(hex, size, result, binary_size); if (real_size) *real_size = binary_size; return result; } -DQN_API Dqn_Array Dqn_HexCStringToU8Array(char const *hex, Dqn_isize size, Dqn_Arena *arena) +DQN_API Dqn_Array Dqn_Hex_CStringToU8Array(char const *hex, Dqn_isize size, Dqn_Arena *arena) { Dqn_isize data_size = 0; - auto *data = DQN_CAST(Dqn_u8 *)Dqn_HexCStringToU8Bytes(hex, size, &data_size, arena); - Dqn_Array result = Dqn_ArrayInitWithMemory(data, data_size, data_size); + auto *data = DQN_CAST(uint8_t *)Dqn_Hex_CStringToU8Bytes(hex, size, &data_size, arena); + Dqn_Array result = Dqn_Array_InitWithMemory(data, data_size, data_size); return result; } -DQN_API Dqn_Array Dqn_HexStringToU8Array(Dqn_String8 const hex, Dqn_Arena *arena) +DQN_API Dqn_Array Dqn_Hex_StringToU8Array(Dqn_String8 const hex, Dqn_Arena *arena) { Dqn_isize data_size = 0; - auto *data = DQN_CAST(Dqn_u8 *) Dqn_HexCStringToU8Bytes(hex.data, hex.size, &data_size, arena); - Dqn_Array result = Dqn_ArrayInitWithMemory(data, data_size, data_size); + auto *data = DQN_CAST(uint8_t *) Dqn_Hex_CStringToU8Bytes(hex.data, hex.size, &data_size, arena); + Dqn_Array result = Dqn_Array_InitWithMemory(data, data_size, data_size); return result; } @@ -5547,19 +5521,19 @@ DQN_API Dqn_Array Dqn_HexStringToU8Array(Dqn_String8 const hex, Dqn_Aren // NOTE: Dqn_Str // ------------------------------------------------------------------------------------------------- -DQN_API bool Dqn_CStringEquals(char const *a, char const *b, Dqn_isize a_size, Dqn_isize b_size) +DQN_API bool Dqn_CString8_Equals(char const *a, char const *b, Dqn_isize a_size, Dqn_isize b_size) { - if (a_size == -1) a_size = DQN_CAST(Dqn_isize)Dqn_CStringSize(a); - if (b_size == -1) b_size = DQN_CAST(Dqn_isize)Dqn_CStringSize(b); + if (a_size == -1) a_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(a); + if (b_size == -1) b_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(b); if (a_size != b_size) return false; return (DQN_MEMCMP(a, b, DQN_CAST(size_t)a_size) == 0); } -DQN_API char const *Dqn_CStringFindMulti(char const *buf, char const *find_list[], Dqn_isize const *find_string_sizes, Dqn_isize find_size, Dqn_isize *match_index, Dqn_isize buf_size) +DQN_API char const *Dqn_CString8_FindMulti(char const *buf, char const *find_list[], Dqn_isize const *find_string_sizes, Dqn_isize find_size, Dqn_isize *match_index, Dqn_isize buf_size) { char const *result = nullptr; if (find_size == 0) return result; - if (buf_size < 0) buf_size = DQN_CAST(Dqn_isize)Dqn_CStringSize(buf); + if (buf_size < 0) buf_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(buf); char const *buf_end = buf + buf_size; for (; buf != buf_end; ++buf) { @@ -5580,11 +5554,11 @@ DQN_API char const *Dqn_CStringFindMulti(char const *buf, char const *find_list[ return result; } -DQN_API char const *Dqn_CStringFind(char const *buf, char const *find, Dqn_isize buf_size, Dqn_isize find_size, bool case_insensitive) +DQN_API char const *Dqn_CString8_Find(char const *buf, char const *find, Dqn_isize buf_size, Dqn_isize find_size, bool case_insensitive) { if (find_size == 0) return nullptr; - if (buf_size < 0) buf_size = DQN_CAST(Dqn_isize)Dqn_CStringSize(buf); - if (find_size < 0) find_size = DQN_CAST(Dqn_isize)Dqn_CStringSize(find); + if (buf_size < 0) buf_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(buf); + if (find_size < 0) find_size = DQN_CAST(Dqn_isize)Dqn_CString8_Size(find); char const *buf_end = buf + buf_size; char const *result = nullptr; @@ -5601,8 +5575,8 @@ DQN_API char const *Dqn_CStringFind(char const *buf, char const *find, Dqn_isize if (case_insensitive) { - lhs = Dqn_CharToLower(lhs); - rhs = Dqn_CharToLower(rhs); + lhs = Dqn_Char_ToLower(lhs); + rhs = Dqn_Char_ToLower(rhs); } if (lhs != rhs) @@ -5621,10 +5595,10 @@ DQN_API char const *Dqn_CStringFind(char const *buf, char const *find, Dqn_isize return result; } -DQN_API char const *Dqn_CStringFileNameFromPath(char const *path, Dqn_isize size, Dqn_isize *file_name_size) +DQN_API char const *Dqn_CString8_FileNameFromPath(char const *path, Dqn_isize size, Dqn_isize *file_name_size) { char const *result = path; - Dqn_isize result_size = size <= -1 ? Dqn_CStringSize(path) : size; + Dqn_isize result_size = size <= -1 ? Dqn_CString8_Size(path) : size; for (Dqn_isize i = (result_size - 1); i >= 0; --i) { if (result[i] == '\\' || result[i] == '/') @@ -5640,7 +5614,7 @@ DQN_API char const *Dqn_CStringFileNameFromPath(char const *path, Dqn_isize size return result; } -DQN_API Dqn_isize Dqn_CStringSize(char const *src) +DQN_API Dqn_isize Dqn_CString8_Size(char const *src) { Dqn_isize result = 0; while (src && src[0] != 0) @@ -5652,100 +5626,100 @@ DQN_API Dqn_isize Dqn_CStringSize(char const *src) return result; } -DQN_API bool Dqn_CStringMatch(char const *src, char const *find, int find_size) +DQN_API bool Dqn_CString8_Match(char const *src, char const *find, int find_size) { - if (find_size == -1) find_size = Dqn_SafeTruncateUSizeToInt(Dqn_CStringSize(find)); + if (find_size == -1) find_size = Dqn_Safe_TruncateUSizeToInt(Dqn_CString8_Size(find)); bool result = (DQN_MEMCMP(src, find, DQN_CAST(size_t)find_size) == 0); return result; } -DQN_API char const *Dqn_CStringSkipToChar(char const *src, char ch) +DQN_API char const *Dqn_CString8_SkipToChar(char const *src, char ch) { char const *result = src; while (result && result[0] && result[0] != ch) ++result; return result; } -DQN_API char const *Dqn_CStringSkipToNextAlphaNum(char const *src) +DQN_API char const *Dqn_CString8_SkipToNextAlphaNum(char const *src) { char const *result = src; - while (result && result[0] && !Dqn_CharIsAlphaNum(result[0])) ++result; + while (result && result[0] && !Dqn_Char_IsAlphaNum(result[0])) ++result; return result; } -DQN_API char const *Dqn_CStringSkipToNextDigit(char const *src) +DQN_API char const *Dqn_CString8_SkipToNextDigit(char const *src) { char const *result = src; - while (result && result[0] && !Dqn_CharIsDigit(result[0])) ++result; + while (result && result[0] && !Dqn_Char_IsDigit(result[0])) ++result; return result; } -DQN_API char const *Dqn_CStringSkipToNextChar(char const *src) +DQN_API char const *Dqn_CString8_SkipToNextChar(char const *src) { char const *result = src; - while (result && result[0] && !Dqn_CharIsAlpha(result[0])) ++result; + while (result && result[0] && !Dqn_Char_IsAlpha(result[0])) ++result; return result; } -DQN_API char const *Dqn_CStringSkipToNextWord(char const *src) +DQN_API char const *Dqn_CString8_SkipToNextWord(char const *src) { char const *result = src; - while (result && result[0] && !Dqn_CharIsWhitespace(result[0])) ++result; - while (result && result[0] && Dqn_CharIsWhitespace(result[0])) ++result; + while (result && result[0] && !Dqn_Char_IsWhitespace(result[0])) ++result; + while (result && result[0] && Dqn_Char_IsWhitespace(result[0])) ++result; return result; } -DQN_API char const *Dqn_CStringSkipToNextWhitespace(char const *src) +DQN_API char const *Dqn_CString8_SkipToNextWhitespace(char const *src) { char const *result = src; - while (result && result[0] && !Dqn_CharIsWhitespace(result[0])) ++result; + while (result && result[0] && !Dqn_Char_IsWhitespace(result[0])) ++result; return result; } -DQN_API char const *Dqn_CStringSkipWhitespace(char const *src) +DQN_API char const *Dqn_CString8_SkipWhitespace(char const *src) { char const *result = src; - while (result && result[0] && Dqn_CharIsWhitespace(result[0])) ++result; + while (result && result[0] && Dqn_Char_IsWhitespace(result[0])) ++result; return result; } -DQN_API char const *Dqn_CStringSkipToCharInPlace(char const **src, char ch) +DQN_API char const *Dqn_CString8_SkipToCharInPlace(char const **src, char ch) { - *src = Dqn_CStringSkipToChar(*src, ch); + *src = Dqn_CString8_SkipToChar(*src, ch); return *src; } -DQN_API char const *Dqn_CStringSkipToNextAlphaNumInPlace(char const **src) +DQN_API char const *Dqn_CString8_SkipToNextAlphaNumInPlace(char const **src) { - *src = Dqn_CStringSkipToNextAlphaNum(*src); + *src = Dqn_CString8_SkipToNextAlphaNum(*src); return *src; } -DQN_API char const *Dqn_CStringSkipToNextCharInPlace(char const **src) +DQN_API char const *Dqn_CString8_SkipToNextCharInPlace(char const **src) { - *src = Dqn_CStringSkipToNextChar(*src); + *src = Dqn_CString8_SkipToNextChar(*src); return *src; } -DQN_API char const *Dqn_CStringSkipToNextWhitespaceInPlace(char const **src) +DQN_API char const *Dqn_CString8_SkipToNextWhitespaceInPlace(char const **src) { - *src = Dqn_CStringSkipToNextWhitespace(*src); + *src = Dqn_CString8_SkipToNextWhitespace(*src); return *src; } -DQN_API char const *Dqn_CStringSkipToNextWordInPlace(char const **src) +DQN_API char const *Dqn_CString8_SkipToNextWordInPlace(char const **src) { - *src = Dqn_CStringSkipToNextWord(*src); + *src = Dqn_CString8_SkipToNextWord(*src); return *src; } -DQN_API char const *Dqn_CStringSkipWhitespaceInPlace(char const **src) +DQN_API char const *Dqn_CString8_SkipWhitespaceInPlace(char const **src) { - *src = Dqn_CStringSkipWhitespace(*src); + *src = Dqn_CString8_SkipWhitespace(*src); return *src; } -DQN_API char const *Dqn_CStringTrimWhitespaceAround(char const *src, Dqn_isize size, Dqn_isize *new_size) +DQN_API char const *Dqn_CString8_TrimWhitespaceAround(char const *src, Dqn_isize size, Dqn_isize *new_size) { char const *result = src; if (new_size) *new_size = 0; @@ -5753,18 +5727,18 @@ DQN_API char const *Dqn_CStringTrimWhitespaceAround(char const *src, Dqn_isize s char const *start = result; char const *end = start + (size - 1); - while (start <= end && Dqn_CharIsWhitespace(start[0])) start++; - while (end > start && Dqn_CharIsWhitespace(end[0])) end--; + while (start <= end && Dqn_Char_IsWhitespace(start[0])) start++; + while (end > start && Dqn_Char_IsWhitespace(end[0])) end--; result = start; if (new_size) *new_size = ((end - start) + 1); return result; } -DQN_API char const *Dqn_CStringTrimPrefix(char const *src, Dqn_isize size, char const *prefix, Dqn_isize prefix_size, Dqn_isize *trimmed_size) +DQN_API char const *Dqn_CString8_TrimPrefix(char const *src, Dqn_isize size, char const *prefix, Dqn_isize prefix_size, Dqn_isize *trimmed_size) { - if (size <= -1) size = Dqn_CStringSize(src); - if (prefix_size <= -1) prefix_size = Dqn_CStringSize(prefix); + if (size <= -1) size = Dqn_CString8_Size(src); + if (prefix_size <= -1) prefix_size = Dqn_CString8_Size(prefix); char const *result = src; if (prefix_size > size) return result; @@ -5777,10 +5751,10 @@ DQN_API char const *Dqn_CStringTrimPrefix(char const *src, Dqn_isize size, char return result; } -DQN_API bool Dqn_CStringIsAllDigits(char const *src, Dqn_isize size) +DQN_API bool Dqn_CString8_IsAllDigits(char const *src, Dqn_isize size) { if (!src) return false; - if (size <= -1) size = Dqn_CStringSize(src); + if (size <= -1) size = Dqn_CString8_Size(src); for (Dqn_isize ch_index = 0; ch_index < size; ch_index++) { if (!(src[ch_index] >= '0' && src[ch_index] <= '9')) return false; @@ -5789,14 +5763,14 @@ DQN_API bool Dqn_CStringIsAllDigits(char const *src, Dqn_isize size) return result; } -DQN_API Dqn_u64 Dqn_CStringToU64(char const *buf, Dqn_isize size, char separator) +DQN_API uint64_t Dqn_CString8_ToU64(char const *buf, Dqn_isize size, char separator) { - Dqn_u64 result = 0; + uint64_t result = 0; if (!buf) return result; if (size <= -1) - size = Dqn_CStringSize(buf); + size = Dqn_CString8_Size(buf); for (Dqn_isize index = 0; index < size; ++index) { @@ -5807,22 +5781,22 @@ DQN_API Dqn_u64 Dqn_CStringToU64(char const *buf, Dqn_isize size, char separator if (ch < '0' || ch > '9') break; - result = Dqn_SafeMulU64(result, 10); + result = Dqn_Safe_MulU64(result, 10); int digit = ch - '0'; - result = Dqn_SafeAddU64(result, digit); + result = Dqn_Safe_AddU64(result, digit); } return result; } -DQN_API Dqn_i64 Dqn_CStringToI64(char const *buf, Dqn_isize size, char separator) +DQN_API uint64_t Dqn_CString8_ToI64(char const *buf, Dqn_isize size, char separator) { - Dqn_i64 result = 0; + uint64_t result = 0; if (!buf) return result; if (size <= -1) - size = Dqn_CStringSize(buf); + size = Dqn_CString8_Size(buf); char const *buf_ptr = buf; bool negative = (buf[0] == '-'); @@ -5839,9 +5813,9 @@ DQN_API Dqn_i64 Dqn_CStringToI64(char const *buf, Dqn_isize size, char separator if (ch < '0' || ch > '9') break; - result = Dqn_SafeMulU64(result, 10); - Dqn_i64 val = ch - '0'; - result = Dqn_SafeAddI64(result, val); + result = Dqn_Safe_MulU64(result, 10); + uint64_t val = ch - '0'; + result = Dqn_Safe_AddI64(result, val); } if (negative) @@ -5849,11 +5823,10 @@ DQN_API Dqn_i64 Dqn_CStringToI64(char const *buf, Dqn_isize size, char separator return result; } -DQN_API Dqn_isize Dqn_LStringSize(wchar_t const *src) +DQN_API Dqn_isize Dqn_CString16_Size(wchar_t const *src) { Dqn_isize result = 0; - while (src && src[0] != 0) - { + while (src && src[0] != 0) { src++; result++; } @@ -5861,29 +5834,29 @@ DQN_API Dqn_isize Dqn_LStringSize(wchar_t const *src) return result; } -// NOTE: Dqn_Fs +// NOTE: Dqn_Fs_ // ------------------------------------------------------------------------------------------------- -DQN_API char *Dqn_FsReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS char const *path, Dqn_isize path_size, Dqn_isize *file_size, Dqn_Arena *arena) +DQN_API char *Dqn_Fs_ReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS char const *file_path, Dqn_isize file_path_size, Dqn_isize *file_size, Dqn_Arena *arena) { - if (!path || !arena) { + if (!file_path || !arena) { return nullptr; } #if defined(DQN_OS_WIN32) - if (path_size <= 0) - path_size = Dqn_CStringSize(path); + if (file_path_size <= 0) + file_path_size = Dqn_CString8_Size(file_path); - Dqn_ThreadScratch scratch = Dqn_ThreadGetScratch(arena); - Dqn_String8 path_string = Dqn_String8Init(path, path_size); - Dqn_String16 path_string_w = Dqn_WinString8ToString16Allocator(path_string, Dqn_ArenaAllocator(scratch.arena)); + Dqn_ThreadTempArena scratch = Dqn_Thread_TempArena(arena); + Dqn_String8 file_path_string = Dqn_String8_Init(file_path, file_path_size); + Dqn_String16 file_path_string_w = Dqn_Win_String8ToString16Allocator(file_path_string, Dqn_Arena_Allocator(scratch.arena)); void *file_handle = - CreateFileW(path_string_w.data, GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, nullptr); + CreateFileW(file_path_string_w.data, GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, nullptr); if (file_handle == INVALID_HANDLE_VALUE) { DQN_LOG_E("Failed to open file for reading [file=%.*s, reason=%.*s]", - DQN_STRING_FMT(path_string), - DQN_STRING_FMT(Dqn_WinLastError())); + DQN_STRING_FMT(file_path_string), + DQN_STRING_FMT(Dqn_Win_LastError())); return nullptr; } @@ -5893,8 +5866,8 @@ DQN_API char *Dqn_FsReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS char con if (!get_file_size_result || win_file_size.QuadPart > (unsigned long)-1) { if (!get_file_size_result) { DQN_LOG_E("Failed to query file size [file=%.*s, reason=%.*s]", - DQN_STRING_FMT(path_string), - DQN_STRING_FMT(Dqn_WinLastError())); + DQN_STRING_FMT(file_path_string), + DQN_STRING_FMT(Dqn_Win_LastError())); } else { DQN_LOG_E( "We don't support files larger than %$.2d yet, Win32 layer needs to use overlapped IO to chunk reading in " @@ -5903,22 +5876,22 @@ DQN_API char *Dqn_FsReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS char con return nullptr; } - Dqn_isize allocate_size = Dqn_SafeTruncateI64ToISize(win_file_size.QuadPart + 1); - auto arena_undo = Dqn_ArenaBeginTempMemory(arena); - auto *result = DQN_CAST(char *) Dqn_ArenaAllocate_(arena, allocate_size, alignof(char), Dqn_ZeroMem_No DQN_CALL_SITE_ARGS_INPUT); + Dqn_isize allocate_size = Dqn_Safe_TruncateI64ToISize(win_file_size.QuadPart + 1); + auto arena_undo = Dqn_Arena_BeginTempMemory(arena); + auto *result = DQN_CAST(char *) Dqn_Arena_Allocate_(arena, allocate_size, alignof(char), Dqn_ZeroMem_No DQN_CALL_SITE_ARGS_INPUT); // TODO(dqn): We need to chunk this and ensure that readfile read the bytes we wanted. unsigned long bytes_read = 0; if (ReadFile(file_handle, result, DQN_CAST(unsigned long)win_file_size.QuadPart, &bytes_read, nullptr /*overlapped*/) == 0) { - Dqn_ArenaEndTempMemory(arena_undo); + Dqn_Arena_EndTempMemory(arena_undo); DQN_LOG_E("Failed to read file to buffer [file=%.*s, reason=%.*s]", - DQN_STRING_FMT(path_string), - DQN_STRING_FMT(Dqn_WinLastError())); + DQN_STRING_FMT(file_path_string), + DQN_STRING_FMT(Dqn_Win_LastError())); return nullptr; } if (file_size) { - *file_size = Dqn_SafeTruncateI64ToISize(win_file_size.QuadPart); + *file_size = Dqn_Safe_TruncateI64ToISize(win_file_size.QuadPart); } // TODO: Zero terminate doesn't look necessary, ever? @@ -5929,9 +5902,9 @@ DQN_API char *Dqn_FsReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS char con if (!file_size) file_size = &file_size_; - FILE *file_handle = fopen(path, "rb"); + FILE *file_handle = fopen(file_path, "rb"); if (!file_handle) { - DQN_LOG_E("Failed to open file '%s' using fopen\n", path); + DQN_LOG_E("Failed to open file '%s' using fopen\n", file_path); return nullptr; } @@ -5945,8 +5918,8 @@ DQN_API char *Dqn_FsReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS char con } rewind(file_handle); - auto arena_undo = Dqn_ArenaBeginTempMemory(arena); - auto *result = DQN_CAST(char *) Dqn_ArenaAllocate_(arena, *file_size + 1, alignof(char), Dqn_ZeroMem_No DQN_CALL_SITE_ARGS_INPUT); + auto arena_undo = Dqn_Arena_BeginTempMemory(arena); + auto *result = DQN_CAST(char *) Dqn_Arena_Allocate_(arena, *file_size + 1, alignof(char), Dqn_ZeroMem_No DQN_CALL_SITE_ARGS_INPUT); if (!result) { DQN_LOG_M("Failed to allocate %td bytes to read file '%s'\n", *file_size + 1, file); return nullptr; @@ -5954,7 +5927,7 @@ DQN_API char *Dqn_FsReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS char con result[*file_size] = 0; if (fread(result, DQN_CAST(size_t)(*file_size), 1, file_handle) != 1) { - Dqn_ArenaEndTempMemory(arena_undo); + Dqn_Arena_EndTempMemory(arena_undo); DQN_LOG_E("Failed to read %td bytes into buffer from '%s'\n", *file_size, file); return nullptr; } @@ -5963,43 +5936,43 @@ DQN_API char *Dqn_FsReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS char con #endif } -DQN_API Dqn_String8 Dqn_FsReadFileCString8ToString8Arena_(DQN_CALL_SITE_ARGS - char const *path, - Dqn_isize path_size, +DQN_API Dqn_String8 Dqn_Fs_ReadFileCString8ToString8Arena_(DQN_CALL_SITE_ARGS + char const *file_path, + Dqn_isize file_path_size, Dqn_Arena *arena) { Dqn_isize file_size = 0; - char * string = Dqn_FsReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS_INPUT path, path_size, &file_size, arena); - Dqn_String8 result = Dqn_String8Init(string, file_size); + char * string = Dqn_Fs_ReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS_INPUT file_path, file_path_size, &file_size, arena); + Dqn_String8 result = Dqn_String8_Init(string, file_size); return result; } -DQN_API Dqn_String8 Dqn_FsReadFileString8ToString8Arena_(DQN_CALL_SITE_ARGS - Dqn_String8 path, +DQN_API Dqn_String8 Dqn_Fs_ReadFileString8ToString8Arena_(DQN_CALL_SITE_ARGS + Dqn_String8 file_path, Dqn_Arena *arena) { Dqn_isize file_size = 0; - char * string = Dqn_FsReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS_INPUT path.data, path.size, &file_size, arena); - Dqn_String8 result = Dqn_String8Init(string, file_size); + char * string = Dqn_Fs_ReadFileCString8ToCString8Arena_(DQN_CALL_SITE_ARGS_INPUT file_path.data, file_path.size, &file_size, arena); + Dqn_String8 result = Dqn_String8_Init(string, file_size); return result; } -DQN_API bool Dqn_FsWriteFileCString8(char const *path, Dqn_isize path_size, char const *buffer, Dqn_isize buffer_size) +DQN_API bool Dqn_Fs_WriteCString8ToFileCString8(char const *file_path, Dqn_isize file_path_size, char const *buffer, Dqn_isize buffer_size) { #if defined(DQN_OS_WIN32) - if (!path || path_size <= 0 || !buffer || buffer_size <= 0) + if (!file_path || file_path_size <= 0 || !buffer || buffer_size <= 0) return false; - if (path_size == 0) - path_size = Dqn_CStringSize(path); + if (file_path_size == 0) + file_path_size = Dqn_CString8_Size(file_path); - Dqn_ThreadScratch scratch = Dqn_ThreadGetScratch(); - Dqn_String8 path_str = Dqn_String8Init(path, path_size); - Dqn_String16 path16 = Dqn_WinString8ToString16Allocator(path_str, Dqn_ArenaAllocator(scratch.arena)); + Dqn_ThreadTempArena scratch = Dqn_Thread_TempArena(); + Dqn_String8 file_path_str = Dqn_String8_Init(file_path, file_path_size); + Dqn_String16 file_path16 = Dqn_Win_String8ToString16Allocator(file_path_str, Dqn_Arena_Allocator(scratch.arena)); bool result = false; if (buffer_size > 0) { - void *file_handle = CreateFileW(path16.data, // LPCWSTR lpFileName, + void *file_handle = CreateFileW(file_path16.data, // LPCWSTR lpFileName, GENERIC_WRITE, // DWORD dwDesiredAccess, 0, // DWORD dwShareMode, nullptr, // LPSECURITY_ATTRIBUTES lpSecurityAttributes, @@ -6020,12 +5993,12 @@ DQN_API bool Dqn_FsWriteFileCString8(char const *path, Dqn_isize path_size, char return result; #else // TODO(dqn): Use OS apis - (void)path_size; + (void)file_path_size; FILE *file_handle = nullptr; - fopen_s(&file_handle, path, "w+b"); + fopen_s(&file_handle, file_path, "w+b"); if (!file_handle) { - DQN_LOG_E("Failed to open file '%s' using fopen\n", path); + DQN_LOG_E("Failed to open file '%s' using fopen\n", file_path); return false; } @@ -6033,7 +6006,7 @@ DQN_API bool Dqn_FsWriteFileCString8(char const *path, Dqn_isize path_size, char Dqn_usize write_count = fwrite(buffer, buffer_size, 1 /*count*/, file_handle); if (write_count != 1) { - DQN_LOG_E("Failed to write to file '%s' using fwrite\n", path); + DQN_LOG_E("Failed to write to file '%s' using fwrite\n", file_path); return false; } @@ -6041,21 +6014,21 @@ DQN_API bool Dqn_FsWriteFileCString8(char const *path, Dqn_isize path_size, char #endif } -DQN_API bool Dqn_FsWriteFileString8(Dqn_String8 path, Dqn_String8 buffer) +DQN_API bool Dqn_Fs_WriteString8ToFileString8(Dqn_String8 file_path, Dqn_String8 buffer) { - bool result = Dqn_FsWriteFileCString8(path.data, path.size, buffer.data, buffer.size); + bool result = Dqn_Fs_WriteCString8ToFileCString8(file_path.data, file_path.size, buffer.data, buffer.size); return result; } -// NOTE: Dqn_Fs Implementation +// NOTE: Dqn_Fs_ Implementation // ------------------------------------------------------------------------------------------------- #if defined(DQN_OS_WIN32) -DQN_API Dqn_u64 Dqn__WinFileTimeToSeconds(FILETIME const *time) +DQN_API uint64_t Dqn__WinFileTimeToSeconds(FILETIME const *time) { ULARGE_INTEGER time_large_int = {}; time_large_int.u.LowPart = time->dwLowDateTime; time_large_int.u.HighPart = time->dwHighDateTime; - Dqn_u64 result = (time_large_int.QuadPart / 10000000ULL) - 11644473600ULL; + uint64_t result = (time_large_int.QuadPart / 10000000ULL) - 11644473600ULL; return result; } #endif @@ -6066,12 +6039,12 @@ DQN_API Dqn_u64 Dqn__WinFileTimeToSeconds(FILETIME const *time) #define DQN_OS_WIN32_MAX_PATH 32767 + 128 /*fudge*/ #endif -DQN_API bool Dqn_FsExists(Dqn_String8 path) +DQN_API bool Dqn_Fs_Exists(Dqn_String8 path) { bool result = false; #if defined(DQN_OS_WIN32) wchar_t path16[DQN_OS_WIN32_MAX_PATH]; - int path16_size = Dqn_WinString8ToCString16(path, path16, DQN_ARRAY_ICOUNT(path16)); + int path16_size = Dqn_Win_String8ToCString16(path, path16, DQN_ARRAY_ICOUNT(path16)); if (path16_size) { WIN32_FILE_ATTRIBUTE_DATA attrib_data = {}; if (GetFileAttributesExW(path16, GetFileExInfoStandard, &attrib_data)) { @@ -6093,12 +6066,12 @@ DQN_API bool Dqn_FsExists(Dqn_String8 path) return result; } -DQN_API bool Dqn_FsDirExists(Dqn_String8 path) +DQN_API bool Dqn_Fs_DirExists(Dqn_String8 path) { bool result = false; #if defined(DQN_OS_WIN32) wchar_t path16[DQN_OS_WIN32_MAX_PATH]; - int path16_size = Dqn_WinString8ToCString16(path, path16, DQN_ARRAY_ICOUNT(path16)); + int path16_size = Dqn_Win_String8ToCString16(path, path16, DQN_ARRAY_ICOUNT(path16)); if (path16_size) { WIN32_FILE_ATTRIBUTE_DATA attrib_data = {}; if (GetFileAttributesExW(path16, GetFileExInfoStandard, &attrib_data)) { @@ -6118,13 +6091,13 @@ DQN_API bool Dqn_FsDirExists(Dqn_String8 path) return result; } -DQN_API Dqn_FsInfo Dqn_FsGetInfo(Dqn_String8 path) +DQN_API Dqn_Fs_Info Dqn_Fs_GetInfo(Dqn_String8 path) { - Dqn_FsInfo result = {}; + Dqn_Fs_Info result = {}; #if defined(DQN_OS_WIN32) WIN32_FILE_ATTRIBUTE_DATA attrib_data = {}; wchar_t path16[DQN_OS_WIN32_MAX_PATH]; - Dqn_WinString8ToCString16(path, path16, DQN_ARRAY_ICOUNT(path16)); + Dqn_Win_String8ToCString16(path, path16, DQN_ARRAY_ICOUNT(path16)); if (!GetFileAttributesExW(path16, GetFileExInfoStandard, &attrib_data)) return result; @@ -6134,9 +6107,9 @@ DQN_API Dqn_FsInfo Dqn_FsGetInfo(Dqn_String8 path) result.last_write_time_in_s = Dqn__WinFileTimeToSeconds(&attrib_data.ftLastWriteTime); LARGE_INTEGER large_int = {}; - large_int.u.HighPart = DQN_CAST(Dqn_i32)attrib_data.nFileSizeHigh; + large_int.u.HighPart = DQN_CAST(int32_t)attrib_data.nFileSizeHigh; large_int.u.LowPart = attrib_data.nFileSizeLow; - result.size = (Dqn_u64)large_int.QuadPart; + result.size = (uint64_t)large_int.QuadPart; } #elif defined(DQN_OS_UNIX) struct stat file_stat; @@ -6159,13 +6132,13 @@ DQN_API Dqn_FsInfo Dqn_FsGetInfo(Dqn_String8 path) return result; } -DQN_API bool Dqn_FsCopy(Dqn_String8 src, Dqn_String8 dest, bool overwrite) +DQN_API bool Dqn_Fs_Copy(Dqn_String8 src, Dqn_String8 dest, bool overwrite) { bool result = false; #if defined(DQN_OS_WIN32) - Dqn_ThreadScratch scratch = Dqn_ThreadGetScratch(); - Dqn_String16 src16 = Dqn_WinString8ToString16Allocator(src, Dqn_ArenaAllocator(scratch.arena)); - Dqn_String16 dest16 = Dqn_WinString8ToString16Allocator(dest, Dqn_ArenaAllocator(scratch.arena)); + Dqn_ThreadTempArena scratch = Dqn_Thread_TempArena(); + Dqn_String16 src16 = Dqn_Win_String8ToString16Allocator(src, Dqn_Arena_Allocator(scratch.arena)); + Dqn_String16 dest16 = Dqn_Win_String8ToString16Allocator(dest, Dqn_Arena_Allocator(scratch.arena)); int fail_if_exists = overwrite == false; result = CopyFileW(src16.data, dest16.data, fail_if_exists) != 0; @@ -6174,7 +6147,7 @@ DQN_API bool Dqn_FsCopy(Dqn_String8 src, Dqn_String8 dest, bool overwrite) DQN_LOG_E("Failed to copy file [from=%.*s, to=%.*s, reason=%.*s]", DQN_STRING_FMT(src16), DQN_STRING_FMT(dest16), - DQN_STRING_FMT(Dqn_WinLastError())); + DQN_STRING_FMT(Dqn_Win_LastError())); } #elif defined(DQN_OS_UNIX) @@ -6200,15 +6173,15 @@ DQN_API bool Dqn_FsCopy(Dqn_String8 src, Dqn_String8 dest, bool overwrite) return result; } -DQN_API bool Dqn_FsMakeDir(Dqn_String8 path) +DQN_API bool Dqn_Fs_MakeDir(Dqn_String8 path) { - Dqn_ThreadScratch scratch = Dqn_ThreadGetScratch(); - bool result = true; - int path_indexes_size = 0; - Dqn_u16 path_indexes[64] = {}; + Dqn_ThreadTempArena scratch = Dqn_Thread_TempArena(); + bool result = true; + int path_indexes_size = 0; + uint16_t path_indexes[64] = {}; #if defined(DQN_OS_WIN32) - Dqn_String16 path16 = Dqn_WinString8ToString16Allocator(path, Dqn_ArenaAllocator(scratch.arena)); + Dqn_String16 path16 = Dqn_Win_String8ToString16Allocator(path, Dqn_Arena_Allocator(scratch.arena)); // NOTE: Go back from the end of the string to all the directories in the // string, and try to create them. Since Win32 API cannot create @@ -6248,13 +6221,13 @@ DQN_API bool Dqn_FsMakeDir(Dqn_String8 path) } else { // NOTE: There's nothing that exists at this path, we can create // a directory here - path_indexes[path_indexes_size++] = DQN_CAST(Dqn_u16)index; + path_indexes[path_indexes_size++] = DQN_CAST(uint16_t)index; } } } for (Dqn_isize index = path_indexes_size - 1; index >= 0 && result; index--) { - Dqn_u16 path_index = path_indexes[index]; + uint16_t path_index = path_indexes[index]; wchar_t temp = path16.data[path_index]; if (index != 0) path16.data[path_index] = 0; @@ -6263,14 +6236,14 @@ DQN_API bool Dqn_FsMakeDir(Dqn_String8 path) } #elif defined(DQN_OS_UNIX) - Dqn_String8 copy = Dqn_String8Copy(scratch.arena, path); - for (Dqn_i32 index = copy.size - 1; index >= 0; index--) { + Dqn_String8 copy = Dqn_String8_Copy(scratch.arena, path); + for (int32_t index = copy.size - 1; index >= 0; index--) { bool first_char = index == (copy.size - 1); wchar_t ch = copy.data[index]; if (ch == '/' || first_char) { char temp = copy.data[index]; if (!first_char) copy.data[index] = 0; // Temporarily null terminate it - bool is_file = Dqn_FsExists(copy); + bool is_file = Dqn_Fs_Exists(copy); if (!first_char) copy.data[index] = temp; // Undo null termination if (is_file) { @@ -6279,7 +6252,7 @@ DQN_API bool Dqn_FsMakeDir(Dqn_String8 path) // invalid. return false; } else { - if (Dqn_FsDirExists(copy)) { + if (Dqn_Fs_DirExists(copy)) { // NOTE: We found a directory, we can stop here and start // building up all the directories that didn't exist up to // this point. @@ -6287,14 +6260,14 @@ DQN_API bool Dqn_FsMakeDir(Dqn_String8 path) } else { // NOTE: There's nothing that exists at this path, we can // create a directory here - path_indexes[path_indexes_size++] = DQN_CAST(Dqn_u16)index; + path_indexes[path_indexes_size++] = DQN_CAST(uint16_t)index; } } } } for (Dqn_isize index = path_indexes_size - 1; index >= 0 && result; index--) { - Dqn_u16 path_index = path_indexes[index]; + uint16_t path_index = path_indexes[index]; char temp = copy.data[path_index]; if (index != 0) copy.data[path_index] = 0; @@ -6309,14 +6282,14 @@ DQN_API bool Dqn_FsMakeDir(Dqn_String8 path) return result; } -DQN_API bool Dqn_FsMove(Dqn_String8 src, Dqn_String8 dest, bool overwrite) +DQN_API bool Dqn_Fs_Move(Dqn_String8 src, Dqn_String8 dest, bool overwrite) { bool result = false; #if defined(DQN_OS_WIN32) - Dqn_ThreadScratch scratch = Dqn_ThreadGetScratch(); - Dqn_String16 src16 = Dqn_WinString8ToString16Allocator(src, Dqn_ArenaAllocator(scratch.arena)); - Dqn_String16 dest16 = Dqn_WinString8ToString16Allocator(dest, Dqn_ArenaAllocator(scratch.arena)); + Dqn_ThreadTempArena scratch = Dqn_Thread_TempArena(); + Dqn_String16 src16 = Dqn_Win_String8ToString16Allocator(src, Dqn_Arena_Allocator(scratch.arena)); + Dqn_String16 dest16 = Dqn_Win_String8ToString16Allocator(dest, Dqn_Arena_Allocator(scratch.arena)); unsigned long flags = MOVEFILE_COPY_ALLOWED; if (overwrite) { @@ -6328,7 +6301,7 @@ DQN_API bool Dqn_FsMove(Dqn_String8 src, Dqn_String8 dest, bool overwrite) DQN_LOG_E("Failed to move file [from=%.*s, to=%.*s, reason=%.*s]", DQN_STRING_FMT(src), DQN_STRING_FMT(dest), - DQN_STRING_FMT(Dqn_WinLastError())); + DQN_STRING_FMT(Dqn_Win_LastError())); } #elif defined(DQN_OS_UNIX) @@ -6338,7 +6311,7 @@ DQN_API bool Dqn_FsMove(Dqn_String8 src, Dqn_String8 dest, bool overwrite) { // NOTE: Link can fail if we're trying to link across different volumes // so we fall back to a binary directory. - file_moved |= Dqn_FsCopy(src, dest, overwrite); + file_moved |= Dqn_Fs_Copy(src, dest, overwrite); } if (file_moved) @@ -6352,12 +6325,12 @@ DQN_API bool Dqn_FsMove(Dqn_String8 src, Dqn_String8 dest, bool overwrite) return result; } -DQN_API bool Dqn_FsDelete(Dqn_String8 path) +DQN_API bool Dqn_Fs_Delete(Dqn_String8 path) { bool result = false; #if defined(DQN_OS_WIN32) wchar_t path16[DQN_OS_WIN32_MAX_PATH]; - int path16_size = Dqn_WinString8ToCString16(path, path16, DQN_ARRAY_ICOUNT(path16)); + int path16_size = Dqn_Win_String8ToCString16(path, path16, DQN_ARRAY_ICOUNT(path16)); if (path16_size) { result = DeleteFileW(path16); if (!result) @@ -6374,19 +6347,19 @@ DQN_API bool Dqn_FsDelete(Dqn_String8 path) // NOTE: Dqn_Date // ------------------------------------------------------------------------------------------------- -DQN_API Dqn_DateHMSTime Dqn_DateHMSLocalTimeNow() +DQN_API Dqn_DateHMSTime Dqn_Date_HMSLocalTimeNow() { Dqn_DateHMSTime result = {}; #if defined(DQN_OS_WIN32) SYSTEMTIME sys_time; GetLocalTime(&sys_time); - result.hour = DQN_CAST(Dqn_i8)sys_time.wHour; - result.minutes = DQN_CAST(Dqn_i8)sys_time.wMinute; - result.seconds = DQN_CAST(Dqn_i8)sys_time.wSecond; + result.hour = DQN_CAST(uint8_t)sys_time.wHour; + result.minutes = DQN_CAST(uint8_t)sys_time.wMinute; + result.seconds = DQN_CAST(uint8_t)sys_time.wSecond; - result.day = DQN_CAST(Dqn_i8)sys_time.wDay; - result.month = DQN_CAST(Dqn_i8)sys_time.wMonth; - result.year = DQN_CAST(Dqn_i16)sys_time.wYear; + result.day = DQN_CAST(uint8_t)sys_time.wDay; + result.month = DQN_CAST(uint8_t)sys_time.wMonth; + result.year = DQN_CAST(int16_t)sys_time.wYear; #else struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); @@ -6406,19 +6379,19 @@ DQN_API Dqn_DateHMSTime Dqn_DateHMSLocalTimeNow() result.minutes = time.tm_min; result.seconds = time.tm_sec; - result.day = DQN_CAST(Dqn_i8)time.tm_mday; - result.month = DQN_CAST(Dqn_i8)time.tm_mon + 1; - result.year = 1900 + DQN_CAST(Dqn_i16)time.tm_year; + result.day = DQN_CAST(uint8_t)time.tm_mday; + result.month = DQN_CAST(uint8_t)time.tm_mon + 1; + result.year = 1900 + DQN_CAST(int16_t)time.tm_year; #endif return result; } -DQN_API Dqn_DateHMSTimeString Dqn_DateHMSLocalTimeString(Dqn_DateHMSTime time, char date_separator, char hms_separator) +DQN_API Dqn_DateHMSTimeString Dqn_Date_HMSLocalTimeString(Dqn_DateHMSTime time, char date_separator, char hms_separator) { Dqn_DateHMSTimeString result = {}; - result.hms_size = DQN_CAST(Dqn_i8) STB_SPRINTF_DECORATE(snprintf)(result.hms, - DQN_CAST(int) Dqn_ArrayCountI(result.hms), + result.hms_size = DQN_CAST(uint8_t) STB_SPRINTF_DECORATE(snprintf)(result.hms, + DQN_CAST(int) Dqn_CArray_CountI(result.hms), "%02d%c%02d%c%02d", time.hour, hms_separator, @@ -6426,8 +6399,8 @@ DQN_API Dqn_DateHMSTimeString Dqn_DateHMSLocalTimeString(Dqn_DateHMSTime time, c hms_separator, time.seconds); - result.date_size = DQN_CAST(Dqn_i8) STB_SPRINTF_DECORATE(snprintf)(result.date, - DQN_CAST(int) Dqn_ArrayCountI(result.date), + result.date_size = DQN_CAST(uint8_t) STB_SPRINTF_DECORATE(snprintf)(result.date, + DQN_CAST(int) Dqn_CArray_CountI(result.date), "%d%c%02d%c%02d", time.year, date_separator, @@ -6438,18 +6411,18 @@ DQN_API Dqn_DateHMSTimeString Dqn_DateHMSLocalTimeString(Dqn_DateHMSTime time, c return result; } -DQN_API Dqn_DateHMSTimeString Dqn_DateHMSLocalTimeStringNow(char date_separator, char hms_separator) +DQN_API Dqn_DateHMSTimeString Dqn_Date_HMSLocalTimeStringNow(char date_separator, char hms_separator) { - Dqn_DateHMSTime time = Dqn_DateHMSLocalTimeNow(); - Dqn_DateHMSTimeString result = Dqn_DateHMSLocalTimeString(time, date_separator, hms_separator); + Dqn_DateHMSTime time = Dqn_Date_HMSLocalTimeNow(); + Dqn_DateHMSTimeString result = Dqn_Date_HMSLocalTimeString(time, date_separator, hms_separator); return result; } -DQN_API Dqn_u64 Dqn_DateEpochTime() +DQN_API uint64_t Dqn_Date_EpochTime() { #if defined(DQN_OS_WIN32) - const Dqn_i64 UNIX_TIME_START = 0x019DB1DED53E8000; //January 1, 1970 (start of Unix epoch) in "ticks" - const Dqn_i64 TICKS_PER_SECOND = 10'000'000; // Filetime returned is in intervals of 100 nanoseconds + const uint64_t UNIX_TIME_START = 0x019DB1DED53E8000; //January 1, 1970 (start of Unix epoch) in "ticks" + const uint64_t TICKS_PER_SECOND = 10'000'000; // Filetime returned is in intervals of 100 nanoseconds FILETIME file_time; GetSystemTimeAsFileTime(&file_time); @@ -6457,10 +6430,10 @@ DQN_API Dqn_u64 Dqn_DateEpochTime() LARGE_INTEGER date_time; date_time.LowPart = file_time.dwLowDateTime; date_time.HighPart = file_time.dwHighDateTime; - Dqn_u64 result = (date_time.QuadPart - UNIX_TIME_START) / TICKS_PER_SECOND; + uint64_t result = (date_time.QuadPart - UNIX_TIME_START) / TICKS_PER_SECOND; #elif defined(DQN_OS_UNIX) - Dqn_u64 result = time(nullptr); + uint64_t result = time(nullptr); #else #error Unimplemented #endif @@ -6470,7 +6443,7 @@ DQN_API Dqn_u64 Dqn_DateEpochTime() // NOTE: OS // ------------------------------------------------------------------------------------------------- -DQN_API bool Dqn_OSSecureRNGBytes(void *buffer, Dqn_u32 size) +DQN_API bool Dqn_OS_SecureRNGBytes(void *buffer, uint32_t size) { if (!buffer || size < 0) return false; @@ -6480,7 +6453,7 @@ DQN_API bool Dqn_OSSecureRNGBytes(void *buffer, Dqn_u32 size) #if defined(DQN_OS_WIN32) bool init = true; - Dqn_TicketMutexBegin(&dqn_lib_.win32_bcrypt_rng_mutex); + Dqn_TicketMutex_Begin(&dqn_lib_.win32_bcrypt_rng_mutex); if (!dqn_lib_.win32_bcrypt_rng_handle) { wchar_t const BCRYPT_ALGORITHM[] = L"RNG"; @@ -6491,7 +6464,7 @@ DQN_API bool Dqn_OSSecureRNGBytes(void *buffer, Dqn_u32 size) init = false; } } - Dqn_TicketMutexEnd(&dqn_lib_.win32_bcrypt_rng_mutex); + Dqn_TicketMutex_End(&dqn_lib_.win32_bcrypt_rng_mutex); if (!init) return false; @@ -6521,14 +6494,14 @@ DQN_API bool Dqn_OSSecureRNGBytes(void *buffer, Dqn_u32 size) return true; } -DQN_API Dqn_String8 Dqn_OSEXEDir(Dqn_Allocator allocator) +DQN_API Dqn_String8 Dqn_OS_EXEDir(Dqn_Allocator allocator) { Dqn_String8 result = {}; #if defined(DQN_OS_WIN32) wchar_t exe_dir[DQN_OS_WIN32_MAX_PATH]; - Dqn_isize exe_dir_size = Dqn_WinEXEDirW(exe_dir, DQN_ARRAY_ICOUNT(exe_dir)); - result = Dqn_WinCString16ToString8Allocator(exe_dir, DQN_CAST(int)exe_dir_size, allocator); + Dqn_isize exe_dir_size = Dqn_Win_EXEDirW(exe_dir, DQN_ARRAY_ICOUNT(exe_dir)); + result = Dqn_Win_CString16ToString8Allocator(exe_dir, DQN_CAST(int)exe_dir_size, allocator); #elif defined(DQN_OS_UNIX) @@ -6538,7 +6511,7 @@ DQN_API Dqn_String8 Dqn_OSEXEDir(Dqn_Allocator allocator) try_size *= 2) { auto scoped_arena = Dqn_ArenaTempMemoryScope(arena); - char *try_buf = Dqn_ArenaNewArray(arena, char, try_size, Dqn_ZeroMem_No); + char *try_buf = Dqn_Arena_NewArray(arena, char, try_size, Dqn_ZeroMem_No); int bytes_written = readlink("/proc/self/exe", try_buf, try_size); if (bytes_written == -1) { @@ -6585,8 +6558,8 @@ DQN_API Dqn_String8 Dqn_OSEXEDir(Dqn_Allocator allocator) if (required_size_wo_null_terminator) { - Dqn_ArenaTempMemory scope = Dqn_ArenaBeginTempMemory(arena); - char *exe_path = Dqn_ArenaNewArray(arena, char, required_size_wo_null_terminator + 1, Dqn_ZeroMem_No); + Dqn_ArenaTempMemory scope = Dqn_Arena_BeginTempMemory(arena); + char *exe_path = Dqn_Arena_NewArray(arena, char, required_size_wo_null_terminator + 1, Dqn_ZeroMem_No); exe_path[required_size_wo_null_terminator] = 0; int bytes_written = readlink("/proc/self/exe", exe_path, required_size_wo_null_terminator); @@ -6595,11 +6568,11 @@ DQN_API Dqn_String8 Dqn_OSEXEDir(Dqn_Allocator allocator) // Note that if read-link fails again can be because there's // a potential race condition here, our exe or directory could have // been deleted since the last call, so we need to be careful. - Dqn_ArenaEndTempMemory(scope); + Dqn_Arena_EndTempMemory(scope); } else { - result = Dqn_String8Init(exe_path, required_size_wo_null_terminator); + result = Dqn_String8_Init(exe_path, required_size_wo_null_terminator); } } @@ -6624,7 +6597,7 @@ DQN_API void Dqn_SleepMs(Dqn_uint milliseconds) #endif } -DQN_FILE_SCOPE void Dqn_PerfCounter_Init() +DQN_FILE_SCOPE void Dqn_Perf_Counter_Init() { #if defined(DQN_OS_WIN32) if (dqn_lib_.win32_qpc_frequency.QuadPart == 0) @@ -6632,10 +6605,10 @@ DQN_FILE_SCOPE void Dqn_PerfCounter_Init() #endif } -DQN_API Dqn_f64 Dqn_PerfCounterS(Dqn_u64 begin, Dqn_u64 end) +DQN_API Dqn_f64 Dqn_Perf_CounterS(uint64_t begin, uint64_t end) { - Dqn_PerfCounter_Init(); - Dqn_u64 ticks = end - begin; + Dqn_Perf_Counter_Init(); + uint64_t ticks = end - begin; #if defined(DQN_OS_WIN32) Dqn_f64 result = ticks / DQN_CAST(Dqn_f64)dqn_lib_.win32_qpc_frequency.QuadPart; #else @@ -6644,10 +6617,10 @@ DQN_API Dqn_f64 Dqn_PerfCounterS(Dqn_u64 begin, Dqn_u64 end) return result; } -DQN_API Dqn_f64 Dqn_PerfCounterMs(Dqn_u64 begin, Dqn_u64 end) +DQN_API Dqn_f64 Dqn_Perf_CounterMs(uint64_t begin, uint64_t end) { - Dqn_PerfCounter_Init(); - Dqn_u64 ticks = end - begin; + Dqn_Perf_Counter_Init(); + uint64_t ticks = end - begin; #if defined(DQN_OS_WIN32) Dqn_f64 result = (ticks * 1'000) / DQN_CAST(Dqn_f64)dqn_lib_.win32_qpc_frequency.QuadPart; #else @@ -6656,10 +6629,10 @@ DQN_API Dqn_f64 Dqn_PerfCounterMs(Dqn_u64 begin, Dqn_u64 end) return result; } -DQN_API Dqn_f64 Dqn_PerfCounterMicroS(Dqn_u64 begin, Dqn_u64 end) +DQN_API Dqn_f64 Dqn_Perf_CounterMicroS(uint64_t begin, uint64_t end) { - Dqn_PerfCounter_Init(); - Dqn_u64 ticks = end - begin; + Dqn_Perf_Counter_Init(); + uint64_t ticks = end - begin; #if defined(DQN_OS_WIN32) Dqn_f64 result = (ticks * 1'000'000) / DQN_CAST(Dqn_f64)dqn_lib_.win32_qpc_frequency.QuadPart; #else @@ -6668,10 +6641,10 @@ DQN_API Dqn_f64 Dqn_PerfCounterMicroS(Dqn_u64 begin, Dqn_u64 end) return result; } -DQN_API Dqn_f64 Dqn_PerfCounterNs(Dqn_u64 begin, Dqn_u64 end) +DQN_API Dqn_f64 Dqn_Perf_CounterNs(uint64_t begin, uint64_t end) { - Dqn_PerfCounter_Init(); - Dqn_u64 ticks = end - begin; + Dqn_Perf_Counter_Init(); + uint64_t ticks = end - begin; #if defined(DQN_OS_WIN32) Dqn_f64 result = (ticks * 1'000'000'000) / DQN_CAST(Dqn_f64)dqn_lib_.win32_qpc_frequency.QuadPart; #else @@ -6680,9 +6653,9 @@ DQN_API Dqn_f64 Dqn_PerfCounterNs(Dqn_u64 begin, Dqn_u64 end) return result; } -DQN_API Dqn_u64 Dqn_PerfCounterNow() +DQN_API uint64_t Dqn_Perf_CounterNow() { - Dqn_u64 result = 0; + uint64_t result = 0; #if defined(DQN_OS_WIN32) LARGE_INTEGER integer = {}; int qpc_result = QueryPerformanceCounter(&integer); @@ -6692,51 +6665,51 @@ DQN_API Dqn_u64 Dqn_PerfCounterNow() #else struct timespec ts; clock_gettime(CLOCK_MONOTONIC_RAW, &ts); - result = DQN_CAST(Dqn_u64)ts.tv_sec * 1'000'000'000 + DQN_CAST(Dqn_u64)ts.tv_nsec; + result = DQN_CAST(uint64_t)ts.tv_sec * 1'000'000'000 + DQN_CAST(uint64_t)ts.tv_nsec; #endif return result; } -DQN_API Dqn_Timer Dqn_TimerBegin() +DQN_API Dqn_Timer Dqn_Timer_Begin() { Dqn_Timer result = {}; - result.start = Dqn_PerfCounterNow(); + result.start = Dqn_Perf_CounterNow(); return result; } -DQN_API void Dqn_TimerEnd(Dqn_Timer *timer) +DQN_API void Dqn_Timer_End(Dqn_Timer *timer) { - timer->end = Dqn_PerfCounterNow(); + timer->end = Dqn_Perf_CounterNow(); } -DQN_API Dqn_f64 Dqn_TimerS(Dqn_Timer timer) +DQN_API Dqn_f64 Dqn_Timer_S(Dqn_Timer timer) { - Dqn_f64 result = Dqn_PerfCounterS(timer.start, timer.end); + Dqn_f64 result = Dqn_Perf_CounterS(timer.start, timer.end); return result; } -DQN_API Dqn_f64 Dqn_TimerMs(Dqn_Timer timer) +DQN_API Dqn_f64 Dqn_Timer_Ms(Dqn_Timer timer) { - Dqn_f64 result = Dqn_PerfCounterMs(timer.start, timer.end); + Dqn_f64 result = Dqn_Perf_CounterMs(timer.start, timer.end); return result; } -DQN_API Dqn_f64 Dqn_TimerMicroS(Dqn_Timer timer) +DQN_API Dqn_f64 Dqn_Timer_MicroS(Dqn_Timer timer) { - Dqn_f64 result = Dqn_PerfCounterMicroS(timer.start, timer.end); + Dqn_f64 result = Dqn_Perf_CounterMicroS(timer.start, timer.end); return result; } -DQN_API Dqn_f64 Dqn_TimerNs(Dqn_Timer timer) +DQN_API Dqn_f64 Dqn_Timer_Ns(Dqn_Timer timer) { - Dqn_f64 result = Dqn_PerfCounterNs(timer.start, timer.end); + Dqn_f64 result = Dqn_Perf_CounterNs(timer.start, timer.end); return result; } -DQN_API char *Dqn_U64ToStr(Dqn_u64 val, Dqn_U64Str *result, bool comma_sep) +DQN_API char *Dqn_U64ToStr(uint64_t val, Dqn_U64Str *result, bool comma_sep) { - int buf_index = (int)(Dqn_ArrayCount(result->buf) - 1); + int buf_index = (int)(Dqn_CArray_Count(result->buf) - 1); result->buf[buf_index--] = 0; if (val == 0) @@ -6764,7 +6737,7 @@ DQN_API char *Dqn_U64ToStr(Dqn_u64 val, Dqn_U64Str *result, bool comma_sep) return result->str; } -DQN_API char *Dqn_U64ToTempStr(Dqn_u64 val, bool comma_sep) +DQN_API char *Dqn_U64ToTempStr(uint64_t val, bool comma_sep) { DQN_LOCAL_PERSIST Dqn_U64Str string; string = {}; @@ -6772,9 +6745,9 @@ DQN_API char *Dqn_U64ToTempStr(Dqn_u64 val, bool comma_sep) return result; } -// NOTE: Dqn_Lib +// NOTE: Dqn_Lib_ // ------------------------------------------------------------------------------------------------- -DQN_API void Dqn_LibDumpThreadContextArenaStat(Dqn_String8 file_path) +DQN_API void Dqn_Lib_DumpThreadContextArenaStat(Dqn_String8 file_path) { (void)file_path; #if defined(DQN_DEBUG_THREAD_CONTEXT) @@ -6785,16 +6758,16 @@ DQN_API void Dqn_LibDumpThreadContextArenaStat(Dqn_String8 file_path) // NOTE: Copy the stats from library book-keeping // NOTE: Extremely short critical section, copy the stats then do our // work on it. - Dqn_ArenaStat stats[Dqn_ArrayCountI(dqn_lib_.thread_context_arena_stats)]; + Dqn_ArenaStat stats[Dqn_CArray_CountI(dqn_lib_.thread_context_arena_stats)]; int stats_size = 0; - Dqn_TicketMutexBegin(&dqn_lib_.thread_context_mutex); + Dqn_TicketMutex_Begin(&dqn_lib_.thread_context_mutex); stats_size = dqn_lib_.thread_context_arena_stats_count; DQN_MEMCOPY(stats, dqn_lib_.thread_context_arena_stats, sizeof(stats[0]) * stats_size); - Dqn_TicketMutexEnd(&dqn_lib_.thread_context_mutex); + Dqn_TicketMutex_End(&dqn_lib_.thread_context_mutex); // NOTE: Print the cumulative stat - Dqn_DateHMSTimeString now = Dqn_DateHMSLocalTimeStringNow(); + Dqn_DateHMSTimeString now = Dqn_Date_HMSLocalTimeStringNow(); fprintf(file, "Time=%.*s %.*s | Thread Context Arenas | Count=%d\n", now.date_size, now.date, @@ -6817,14 +6790,14 @@ DQN_API void Dqn_LibDumpThreadContextArenaStat(Dqn_String8 file_path) stat.blocks_hwm = DQN_MAX(stat.blocks_hwm, current->blocks_hwm); } - Dqn_ArenaStatString stats_string = Dqn_ArenaStatToString(&stat); + Dqn_ArenaStatString stats_string = Dqn_Arena_StatString(&stat); fprintf(file, " [ALL] CURR %.*s\n", stats_string.size, stats_string.data); } // NOTE: Print individual thread arena data for (Dqn_isize index = 0; index < stats_size; index++) { Dqn_ArenaStat const *current = stats + index; - Dqn_ArenaStatString current_string = Dqn_ArenaStatToString(current); + Dqn_ArenaStatString current_string = Dqn_Arena_StatString(current); fprintf(file, " [%03d] CURR %.*s\n", DQN_CAST(int)index, current_string.size, current_string.data); } @@ -6838,23 +6811,23 @@ DQN_API void Dqn_LibDumpThreadContextArenaStat(Dqn_String8 file_path) #endif // #if defined(DQN_DEBUG_THREAD_CONTEXT) } -DQN_API void Dqn_LibSetLogCallback(Dqn_LogProc *proc, void *user_data) +DQN_API void Dqn_Lib_SetLogCallback(Dqn_LogProc *proc, void *user_data) { dqn_lib_.LogCallback = proc; dqn_lib_.log_user_data = user_data; } -DQN_API void Dqn_LibSetLogFile(FILE *file) +DQN_API void Dqn_Lib_SetLogFile(FILE *file) { - Dqn_TicketMutexBegin(&dqn_lib_.log_file_mutex); + Dqn_TicketMutex_Begin(&dqn_lib_.log_file_mutex); dqn_lib_.log_file = file; dqn_lib_.log_no_output_file = file ? false : true; - Dqn_TicketMutexEnd(&dqn_lib_.log_file_mutex); + Dqn_TicketMutex_End(&dqn_lib_.log_file_mutex); } // NOTE: Dqn_ThreadContext // ------------------------------------------------------------------------------------------------- -DQN_API Dqn_ThreadContext *Dqn_ThreadGetContext() +DQN_API Dqn_ThreadContext *Dqn_Thread_Context() { thread_local Dqn_ThreadContext result = {}; if (result.init) { @@ -6862,16 +6835,16 @@ DQN_API Dqn_ThreadContext *Dqn_ThreadGetContext() } result.init = true; - for (Dqn_ThreadScratchData &scratch_data : result.scratch_data) { - Dqn_ArenaGrow(&scratch_data.arena, DQN_MEGABYTES(4), DQN_MEGABYTES(4)); + for (Dqn_ThreadArena &temp_arena : result.temp_arenas) { + Dqn_Arena_Grow(&temp_arena.arena, DQN_MEGABYTES(4), DQN_MEGABYTES(4)); #if defined(DQN_DEBUG_THREAD_CONTEXT) // NOTE: Assign this arena a slot in the global library's context // to allow recording of statistics of this thread's arena. - Dqn_TicketMutexBegin(&dqn_lib_.thread_context_mutex); - scratch_data.arena_stats_index = dqn_lib_.thread_context_arena_stats_count++; + Dqn_TicketMutex_Begin(&dqn_lib_.thread_context_mutex); + temp_arena.arena_stats_index = dqn_lib_.thread_context_arena_stats_count++; DQN_HARD_ASSERT(dqn_lib_.thread_context_arena_stats_count < - Dqn_ArrayCountI(dqn_lib_.thread_context_arena_stats)); - Dqn_TicketMutexEnd(&dqn_lib_.thread_context_mutex); + Dqn_CArray_CountI(dqn_lib_.thread_context_arena_stats)); + Dqn_TicketMutex_End(&dqn_lib_.thread_context_mutex); #endif } return &result; @@ -6879,102 +6852,102 @@ DQN_API Dqn_ThreadContext *Dqn_ThreadGetContext() // TODO: Is there a way to handle conflict arenas without the user needing to // manually pass it in? -DQN_API Dqn_ThreadScratch Dqn_ThreadGetScratch(const void *conflict_arena) +DQN_API Dqn_ThreadTempArena Dqn_Thread_TempArena(const void *conflict_arena) { - Dqn_ThreadContext *thread = Dqn_ThreadGetContext(); - Dqn_ThreadScratchData *result = nullptr; - for (Dqn_ThreadScratchData &scratch_data : thread->scratch_data) { - if (!conflict_arena || (&scratch_data.arena != conflict_arena)) { - result = &scratch_data; + Dqn_ThreadContext *thread = Dqn_Thread_Context(); + Dqn_ThreadArena *result = nullptr; + for (Dqn_ThreadArena &temp_arena : thread->temp_arenas) { + if (!conflict_arena || (&temp_arena.arena != conflict_arena)) { + result = &temp_arena; break; } } DQN_HARD_ASSERT(result); - return Dqn_ThreadScratch(result); + return Dqn_ThreadTempArena(result); } #if defined(DQN_WITH_JSON_WRITER) -// NOTE: Dqn_JSONWriter +// NOTE: Dqn_JSONWriter_ // ------------------------------------------------------------------------------------------------- -DQN_API Dqn_JSONWriter Dqn_JSONWriterInit(Dqn_Arena *arena, int spaces_per_indent) +DQN_API Dqn_JSONWriter_ Dqn_JSONWriter_Init(Dqn_Arena *arena, int spaces_per_indent) { - Dqn_JSONWriter result = {}; + Dqn_JSONWriter_ result = {}; result.spaces_per_indent = spaces_per_indent; - result.builder.allocator = Dqn_ArenaAllocator(arena); + result.builder.allocator = Dqn_Arena_Allocator(arena); return result; } -DQN_API Dqn_String8 Dqn_JSONWriterBuild(Dqn_JSONWriter *writer, Dqn_Allocator allocator) +DQN_API Dqn_String8 Dqn_JSONWriter_Build(Dqn_JSONWriter_ *writer, Dqn_Allocator allocator) { - Dqn_String8 result = Dqn_String8BuilderBuild(&writer->builder, allocator); + Dqn_String8 result = Dqn_String8Builder_Build(&writer->builder, allocator); return result; } -DQN_API void Dqn_JSONWriterDoIndent_(Dqn_JSONWriter *writer) +DQN_API void Dqn_JSONWriter_DoIndent_(Dqn_JSONWriter_ *writer) { int spaces_per_indent = writer->spaces_per_indent ? writer->spaces_per_indent : 2; int spaces = writer->indent_level * spaces_per_indent; if (spaces) { - Dqn_String8 padding = Dqn_String8Allocate(writer->builder.allocator, spaces, Dqn_ZeroMem_No); + Dqn_String8 padding = Dqn_String8_Allocate(writer->builder.allocator, spaces, Dqn_ZeroMem_No); DQN_MEMSET(padding.data, ' ', padding.size); - Dqn_String8BuilderAppendString8Ref(&writer->builder, padding); + Dqn_String8Builder_AppendString8Ref(&writer->builder, padding); } } -DQN_API void Dqn_JSONWriterPreAddItem_(Dqn_JSONWriter *writer) +DQN_API void Dqn_JSONWriter_PreAddItem_(Dqn_JSONWriter_ *writer) { if (writer->parent_field_count_stack_size <= 0) return; - Dqn_u16 *parent_field_count = &writer->parent_field_count_stack[writer->parent_field_count_stack_size - 1]; + uint16_t *parent_field_count = &writer->parent_field_count_stack[writer->parent_field_count_stack_size - 1]; if (*parent_field_count == 0) { // NOTE: First time we're adding an item to an object, we need to write // on a new line for nice formatting. - Dqn_String8BuilderAppendString8Ref(&writer->builder, DQN_STRING8("\n")); + Dqn_String8Builder_AppendString8Ref(&writer->builder, DQN_STRING8("\n")); } else if (*parent_field_count > 0) { // NOTE: We have items in the object already and we're adding another // item so we need to add a comma on the previous item. - Dqn_String8BuilderAppendString8Ref(&writer->builder, DQN_STRING8(",\n")); + Dqn_String8Builder_AppendString8Ref(&writer->builder, DQN_STRING8(",\n")); } - Dqn_JSONWriterDoIndent_(writer); + Dqn_JSONWriter_DoIndent_(writer); } -DQN_API void Dqn_JSONWriterPostAddItem_(Dqn_JSONWriter *writer) +DQN_API void Dqn_JSONWriter_PostAddItem_(Dqn_JSONWriter_ *writer) { if (writer->parent_field_count_stack_size <= 0) return; - Dqn_u16 *parent_field_count = &writer->parent_field_count_stack[writer->parent_field_count_stack_size - 1]; + uint16_t *parent_field_count = &writer->parent_field_count_stack[writer->parent_field_count_stack_size - 1]; (*parent_field_count)++; } -DQN_API void Dqn_JSONWriterBeginContainer_(Dqn_JSONWriter *writer, Dqn_String8 name, bool array) +DQN_API void Dqn_JSONWriter_BeginContainer_(Dqn_JSONWriter_ *writer, Dqn_String8 name, bool array) { Dqn_String8 container_ch = array ? DQN_STRING8("[") : DQN_STRING8("{"); - Dqn_JSONWriterPreAddItem_(writer); + Dqn_JSONWriter_PreAddItem_(writer); if (name.size) - Dqn_String8BuilderAppendFmtArgs(&writer->builder, "\"%.*s\": %.*s", DQN_STRING_FMT(name), DQN_STRING_FMT(container_ch)); + Dqn_String8Builder_AppendFmtArgs(&writer->builder, "\"%.*s\": %.*s", DQN_STRING_FMT(name), DQN_STRING_FMT(container_ch)); else - Dqn_String8BuilderAppendString8Ref(&writer->builder, container_ch); - Dqn_JSONWriterPostAddItem_(writer); + Dqn_String8Builder_AppendString8Ref(&writer->builder, container_ch); + Dqn_JSONWriter_PostAddItem_(writer); writer->indent_level++; DQN_ASSERT(writer->parent_field_count_stack_size < DQN_ARRAY_UCOUNT(writer->parent_field_count_stack)); - Dqn_u16 *parent_field_count = &writer->parent_field_count_stack[writer->parent_field_count_stack_size++]; + uint16_t *parent_field_count = &writer->parent_field_count_stack[writer->parent_field_count_stack_size++]; *parent_field_count = 0; } -DQN_API void Dqn_JSONWriterEndContainer_(Dqn_JSONWriter *writer, bool array) +DQN_API void Dqn_JSONWriter_EndContainer_(Dqn_JSONWriter_ *writer, bool array) { - Dqn_u16 *parent_field_count = &writer->parent_field_count_stack[writer->parent_field_count_stack_size - 1]; + uint16_t *parent_field_count = &writer->parent_field_count_stack[writer->parent_field_count_stack_size - 1]; if (*parent_field_count > 0) { // NOTE: End of object/array should start on a new line if the // array/object has atleast one field in it. - Dqn_String8BuilderAppendFmtArgs(&writer->builder, "\n"); + Dqn_String8Builder_AppendFmtArgs(&writer->builder, "\n"); } writer->parent_field_count_stack_size--; @@ -6983,86 +6956,86 @@ DQN_API void Dqn_JSONWriterEndContainer_(Dqn_JSONWriter *writer, bool array) writer->indent_level--; DQN_ASSERT(writer->indent_level >= 0); - Dqn_JSONWriterDoIndent_(writer); - Dqn_String8BuilderAppendString8Ref(&writer->builder, array ? DQN_STRING8("]") : DQN_STRING8("}")); + Dqn_JSONWriter_DoIndent_(writer); + Dqn_String8Builder_AppendString8Ref(&writer->builder, array ? DQN_STRING8("]") : DQN_STRING8("}")); } -DQN_API void Dqn_JSONWriterObjectBeginNamed(Dqn_JSONWriter *writer, Dqn_String8 name) +DQN_API void Dqn_JSONWriter_ObjectBeginNamed(Dqn_JSONWriter_ *writer, Dqn_String8 name) { - Dqn_JSONWriterBeginContainer_(writer, name, false /*array*/); + Dqn_JSONWriter_BeginContainer_(writer, name, false /*array*/); } -DQN_API void Dqn_JSONWriterObjectBegin(Dqn_JSONWriter *writer) +DQN_API void Dqn_JSONWriter_ObjectBegin(Dqn_JSONWriter_ *writer) { - Dqn_JSONWriterBeginContainer_(writer, DQN_STRING8(""), false /*array*/); + Dqn_JSONWriter_BeginContainer_(writer, DQN_STRING8(""), false /*array*/); } -DQN_API void Dqn_JSONWriterObjectEnd(Dqn_JSONWriter *writer) +DQN_API void Dqn_JSONWriter_ObjectEnd(Dqn_JSONWriter_ *writer) { - Dqn_JSONWriterEndContainer_(writer, false /*array*/); + Dqn_JSONWriter_EndContainer_(writer, false /*array*/); } -DQN_API void Dqn_JSONWriterArrayBeginNamed(Dqn_JSONWriter *writer, Dqn_String8 name) +DQN_API void Dqn_JSONWriter_ArrayBeginNamed(Dqn_JSONWriter_ *writer, Dqn_String8 name) { - Dqn_JSONWriterBeginContainer_(writer, name, true /*array*/); + Dqn_JSONWriter_BeginContainer_(writer, name, true /*array*/); } -DQN_API void Dqn_JSONWriterArrayBegin(Dqn_JSONWriter *writer) +DQN_API void Dqn_JSONWriter_ArrayBegin(Dqn_JSONWriter_ *writer) { - Dqn_JSONWriterBeginContainer_(writer, DQN_STRING8(""), false /*array*/); + Dqn_JSONWriter_BeginContainer_(writer, DQN_STRING8(""), false /*array*/); } -DQN_API void Dqn_JSONWriterArrayEnd(Dqn_JSONWriter *writer) +DQN_API void Dqn_JSONWriter_ArrayEnd(Dqn_JSONWriter_ *writer) { - Dqn_JSONWriterEndContainer_(writer, true /*array*/); + Dqn_JSONWriter_EndContainer_(writer, true /*array*/); } -DQN_API void Dqn_JSONWriterStringNamed(Dqn_JSONWriter *writer, Dqn_String8 key, Dqn_String8 value) +DQN_API void Dqn_JSONWriter_StringNamed(Dqn_JSONWriter_ *writer, Dqn_String8 key, Dqn_String8 value) { - Dqn_JSONWriterPreAddItem_(writer); + Dqn_JSONWriter_PreAddItem_(writer); if (key.size) - Dqn_String8BuilderAppendFmtArgs(&writer->builder, "\"%.*s\": \"%.*s\"", DQN_STRING_FMT(key), DQN_STRING_FMT(value)); + Dqn_String8Builder_AppendFmtArgs(&writer->builder, "\"%.*s\": \"%.*s\"", DQN_STRING_FMT(key), DQN_STRING_FMT(value)); else - Dqn_String8BuilderAppendFmtArgs(&writer->builder, "\"%.*s\"", DQN_STRING_FMT(value)); - Dqn_JSONWriterPostAddItem_(writer); + Dqn_String8Builder_AppendFmtArgs(&writer->builder, "\"%.*s\"", DQN_STRING_FMT(value)); + Dqn_JSONWriter_PostAddItem_(writer); } -DQN_API void Dqn_JSONWriterString(Dqn_JSONWriter *writer, Dqn_String8 value) +DQN_API void Dqn_JSONWriter_String(Dqn_JSONWriter_ *writer, Dqn_String8 value) { - Dqn_JSONWriterStringNamed(writer, DQN_STRING8("") /*key*/, value); + Dqn_JSONWriter_StringNamed(writer, DQN_STRING8("") /*key*/, value); } -DQN_API void Dqn_JSONWriterU64Named(Dqn_JSONWriter *writer, Dqn_String8 key, Dqn_u64 value) +DQN_API void Dqn_JSONWriter_U64Named(Dqn_JSONWriter_ *writer, Dqn_String8 key, uint64_t value) { - Dqn_JSONWriterPreAddItem_(writer); + Dqn_JSONWriter_PreAddItem_(writer); if (key.size) - Dqn_String8BuilderAppendFmtArgs(&writer->builder, "\"%.*s\": %I64u", DQN_STRING_FMT(key), value); + Dqn_String8Builder_AppendFmtArgs(&writer->builder, "\"%.*s\": %I64u", DQN_STRING_FMT(key), value); else - Dqn_String8BuilderAppendFmtArgs(&writer->builder, "%I64u", value); - Dqn_JSONWriterPostAddItem_(writer); + Dqn_String8Builder_AppendFmtArgs(&writer->builder, "%I64u", value); + Dqn_JSONWriter_PostAddItem_(writer); } -DQN_API void Dqn_JSONWriterU64(Dqn_JSONWriter *writer, Dqn_u64 value) +DQN_API void Dqn_JSONWriter_U64(Dqn_JSONWriter_ *writer, uint64_t value) { - Dqn_JSONWriterU64Named(writer, DQN_STRING8("") /*key*/, value); + Dqn_JSONWriter_U64Named(writer, DQN_STRING8("") /*key*/, value); } -DQN_API void Dqn_JSONWriterI64Named(Dqn_JSONWriter *writer, Dqn_String8 key, Dqn_i64 value) +DQN_API void Dqn_JSONWriter_I64Named(Dqn_JSONWriter_ *writer, Dqn_String8 key, uint64_t value) { - Dqn_JSONWriterPreAddItem_(writer); + Dqn_JSONWriter_PreAddItem_(writer); if (key.size) - Dqn_String8BuilderAppendFmtArgs(&writer->builder, "\"%.*s\": %I64d", DQN_STRING_FMT(key), value); + Dqn_String8Builder_AppendFmtArgs(&writer->builder, "\"%.*s\": %I64d", DQN_STRING_FMT(key), value); else - Dqn_String8BuilderAppendFmtArgs(&writer->builder, "%I64d", value); - Dqn_JSONWriterPostAddItem_(writer); + Dqn_String8Builder_AppendFmtArgs(&writer->builder, "%I64d", value); + Dqn_JSONWriter_PostAddItem_(writer); } -DQN_API void Dqn_JSONWriterI64(Dqn_JSONWriter *writer, Dqn_i64 value) +DQN_API void Dqn_JSONWriter_I64(Dqn_JSONWriter_ *writer, uint64_t value) { - Dqn_JSONWriterI64Named(writer, DQN_STRING8("") /*key*/, value); + Dqn_JSONWriter_I64Named(writer, DQN_STRING8("") /*key*/, value); } -DQN_API void Dqn_JSONWriterF64Named(Dqn_JSONWriter *writer, Dqn_String8 key, Dqn_f64 value, int decimal_places) +DQN_API void Dqn_JSONWriter_F64Named(Dqn_JSONWriter_ *writer, Dqn_String8 key, Dqn_f64 value, int decimal_places) { if (!writer) return; @@ -7083,33 +7056,33 @@ DQN_API void Dqn_JSONWriterF64Named(Dqn_JSONWriter *writer, Dqn_String8 key, Dqn } char fmt[32]; - if (Dqn_String8IsValid(key)) { + if (Dqn_String8_IsValid(key)) { STB_SPRINTF_DECORATE(snprintf)(fmt, sizeof(fmt), "\"%%.*s\": %s", float_fmt); } else { STB_SPRINTF_DECORATE(snprintf)(fmt, sizeof(fmt), "%s", float_fmt); } - Dqn_JSONWriterPreAddItem_(writer); - if (Dqn_String8IsValid(key)) - Dqn_String8BuilderAppendFmtArgs(&writer->builder, fmt, DQN_STRING_FMT(key), value); + Dqn_JSONWriter_PreAddItem_(writer); + if (Dqn_String8_IsValid(key)) + Dqn_String8Builder_AppendFmtArgs(&writer->builder, fmt, DQN_STRING_FMT(key), value); else - Dqn_String8BuilderAppendFmtArgs(&writer->builder, fmt, value); - Dqn_JSONWriterPostAddItem_(writer); + Dqn_String8Builder_AppendFmtArgs(&writer->builder, fmt, value); + Dqn_JSONWriter_PostAddItem_(writer); } -DQN_API void Dqn_JSONWriterF64(Dqn_JSONWriter *writer, Dqn_f64 value, int decimal_places) +DQN_API void Dqn_JSONWriter_F64(Dqn_JSONWriter_ *writer, Dqn_f64 value, int decimal_places) { - Dqn_JSONWriterF64Named(writer, DQN_STRING8("") /*key*/, value, decimal_places); + Dqn_JSONWriter_F64Named(writer, DQN_STRING8("") /*key*/, value, decimal_places); } #endif // DQN_WITH_JSON_WRITER #if defined(DQN_OS_WIN32) -// NOTE: Dqn_Win Implementation +// NOTE: Dqn_Win_ Implementation // ------------------------------------------------------------------------------------------------- -DQN_API Dqn_WinErrorMsg Dqn_WinLastError() +DQN_API Dqn_Win_ErrorMsg Dqn_Win_LastError() { - Dqn_WinErrorMsg result; + Dqn_Win_ErrorMsg result; result.code = GetLastError(); result.data[0] = 0; @@ -7133,7 +7106,7 @@ DQN_API Dqn_WinErrorMsg Dqn_WinLastError() return result; } -DQN_API void Dqn_WinMakeProcessDPIAware() +DQN_API void Dqn_Win_MakeProcessDPIAware() { typedef bool SetProcessDpiAwareProc(void); typedef bool SetProcessDpiAwarenessProc(PROCESS_DPI_AWARENESS); @@ -7153,10 +7126,10 @@ DQN_API void Dqn_WinMakeProcessDPIAware() } } -DQN_API void Dqn_WinDumpLastError_(Dqn_String8 file, Dqn_String8 func, Dqn_uint line, char const *fmt, ...) +DQN_API void Dqn_Win_DumpLastError_(Dqn_String8 file, Dqn_String8 func, Dqn_uint line, char const *fmt, ...) { - Dqn_WinErrorMsg msg = Dqn_WinLastError(); - Dqn_String8 file_name = Dqn_String8FileNameFromPath(file); + Dqn_Win_ErrorMsg msg = Dqn_Win_LastError(); + Dqn_String8 file_name = Dqn_String8_FileNameFromPath(file); // TODO(dqn): Hmmm .. should this be a separate log or part of the above // macro. If so we need to make the logging macros more flexible. @@ -7175,7 +7148,7 @@ DQN_API void Dqn_WinDumpLastError_(Dqn_String8 file, Dqn_String8 func, Dqn_uint // NOTE: Windows UTF8 to String16 // ----------------------------------------------------------------------------- -DQN_API int Dqn_WinCString8ToCString16(const char *src, int src_size, wchar_t *dest, int dest_size) +DQN_API int Dqn_Win_CString8ToCString16(const char *src, int src_size, wchar_t *dest, int dest_size) { int result = MultiByteToWideChar(CP_UTF8, 0 /*dwFlags*/, src, src_size, dest, dest_size); if (result) { @@ -7189,23 +7162,23 @@ DQN_API int Dqn_WinCString8ToCString16(const char *src, int src_size, wchar_t *d return result; } -DQN_API int Dqn_WinString8ToCString16(Dqn_String8 src, wchar_t *dest, int dest_size) +DQN_API int Dqn_Win_String8ToCString16(Dqn_String8 src, wchar_t *dest, int dest_size) { int result = 0; - int src_size = Dqn_SafeTruncateISizeToInt(src.size); + int src_size = Dqn_Safe_TruncateISizeToInt(src.size); if (src_size) - result = Dqn_WinCString8ToCString16(src.data, src_size, dest, dest_size); + result = Dqn_Win_CString8ToCString16(src.data, src_size, dest, dest_size); return result; } -DQN_API Dqn_String16 Dqn_WinString8ToString16Allocator(Dqn_String8 src, Dqn_Allocator allocator) +DQN_API Dqn_String16 Dqn_Win_String8ToString16Allocator(Dqn_String8 src, Dqn_Allocator allocator) { Dqn_String16 result = {}; - int required = Dqn_WinString8ToCString16(src, nullptr, 0); + int required = Dqn_Win_String8ToCString16(src, nullptr, 0); if (required != 0) { - result.data = Dqn_AllocatorNewArray(allocator, wchar_t, required, Dqn_ZeroMem_No); + result.data = Dqn_Allocator_NewArray(allocator, wchar_t, required, Dqn_ZeroMem_No); if (result.data) { - result.size = Dqn_WinString8ToCString16(src, result.data, required) - 1; + result.size = Dqn_Win_String8ToCString16(src, result.data, required) - 1; DQN_ASSERT(result.size == required - 1); } } @@ -7214,7 +7187,7 @@ DQN_API Dqn_String16 Dqn_WinString8ToString16Allocator(Dqn_String8 src, Dqn_Allo // NOTE: Windows String16 To UTF8 // ----------------------------------------------------------------------------- -DQN_API int Dqn_WinCString16ToCString8(const wchar_t* src, int src_size, char *dest, int dest_size) +DQN_API int Dqn_Win_CString16ToCString8(const wchar_t* src, int src_size, char *dest, int dest_size) { int result = WideCharToMultiByte(CP_UTF8, 0 /*dwFlags*/, src, src_size, dest, dest_size, nullptr, nullptr); if (result) { @@ -7228,46 +7201,46 @@ DQN_API int Dqn_WinCString16ToCString8(const wchar_t* src, int src_size, char *d return result; } -DQN_API Dqn_String8 Dqn_WinCString16ToString8Allocator(const wchar_t* src, int src_size, Dqn_Allocator allocator) +DQN_API Dqn_String8 Dqn_Win_CString16ToString8Allocator(const wchar_t* src, int src_size, Dqn_Allocator allocator) { Dqn_String8 result = {}; - int required = Dqn_WinCString16ToCString8(src, src_size, nullptr, 0); + int required = Dqn_Win_CString16ToCString8(src, src_size, nullptr, 0); if (required != 0) { // NOTE: String allocate ensures there's one extra byte for // null-termination already so we need to undo the +1 from our // functions. - result = Dqn_String8Allocate(allocator, required - 1, Dqn_ZeroMem_No); - if (Dqn_String8IsValid(result)) { - int next_required = Dqn_WinCString16ToCString8(src, src_size, result.data, required); + result = Dqn_String8_Allocate(allocator, required - 1, Dqn_ZeroMem_No); + if (Dqn_String8_IsValid(result)) { + int next_required = Dqn_Win_CString16ToCString8(src, src_size, result.data, required); DQN_ASSERT(required == next_required); } } return result; } -DQN_API int Dqn_WinString16ToCString8(Dqn_String16 src, char *dest, int dest_size) +DQN_API int Dqn_Win_String16ToCString8(Dqn_String16 src, char *dest, int dest_size) { int result = 0; - int src_size = Dqn_SafeTruncateISizeToInt(src.size); + int src_size = Dqn_Safe_TruncateISizeToInt(src.size); if (src_size) { - result = Dqn_WinCString16ToCString8(src.data, src_size, dest, dest_size); + result = Dqn_Win_CString16ToCString8(src.data, src_size, dest, dest_size); } return result; } -DQN_API Dqn_String8 Dqn_WinString16ToString8Allocator(Dqn_String16 src, Dqn_Allocator allocator) +DQN_API Dqn_String8 Dqn_Win_String16ToString8Allocator(Dqn_String16 src, Dqn_Allocator allocator) { Dqn_String8 result = {}; - int src_size = Dqn_SafeTruncateISizeToInt(src.size); + int src_size = Dqn_Safe_TruncateISizeToInt(src.size); if (src_size) { - result = Dqn_WinCString16ToString8Allocator(src.data, src_size, allocator); + result = Dqn_Win_CString16ToString8Allocator(src.data, src_size, allocator); } return result; } // NOTE: Windows Executable Directory // ----------------------------------------------------------------------------- -DQN_API Dqn_isize Dqn_WinEXEDirW(wchar_t *buffer, Dqn_isize size) +DQN_API Dqn_isize Dqn_Win_EXEDirW(wchar_t *buffer, Dqn_isize size) { wchar_t module_path[DQN_OS_WIN32_MAX_PATH]; int module_size = GetModuleFileNameW(nullptr /*module*/, module_path, DQN_ARRAY_UCOUNT(module_path)); @@ -7285,15 +7258,15 @@ DQN_API Dqn_isize Dqn_WinEXEDirW(wchar_t *buffer, Dqn_isize size) return result; } -DQN_API Dqn_String16 Dqn_WinEXEDirWArena(Dqn_Arena *arena) +DQN_API Dqn_String16 Dqn_Win_EXEDirWArena(Dqn_Arena *arena) { wchar_t dir[DQN_OS_WIN32_MAX_PATH]; - Dqn_isize dir_size = Dqn_WinEXEDirW(dir, DQN_ARRAY_ICOUNT(dir)); + Dqn_isize dir_size = Dqn_Win_EXEDirW(dir, DQN_ARRAY_ICOUNT(dir)); DQN_HARD_ASSERT_MSG(dir_size <= DQN_ARRAY_ICOUNT(dir), "How the hell?"); Dqn_String16 result = {}; if (dir_size > 0) { - result.data = Dqn_ArenaCopyZ(arena, wchar_t, dir, dir_size); + result.data = Dqn_Arena_CopyZ(arena, wchar_t, dir, dir_size); if (result.data) { result.size = dir_size; } @@ -7301,27 +7274,27 @@ DQN_API Dqn_String16 Dqn_WinEXEDirWArena(Dqn_Arena *arena) return result; } -DQN_API Dqn_String8 Dqn_WinWorkingDir(Dqn_Allocator allocator, Dqn_String8 suffix) +DQN_API Dqn_String8 Dqn_Win_WorkingDir(Dqn_Allocator allocator, Dqn_String8 suffix) { - Dqn_ThreadScratch scratch = Dqn_ThreadGetScratch(allocator.user_context); - Dqn_String16 suffix16 = Dqn_WinString8ToString16Allocator(suffix, Dqn_ArenaAllocator(scratch.arena)); - Dqn_String16 dir16 = Dqn_WinWorkingDirW(Dqn_ArenaAllocator(scratch.arena), suffix16); - Dqn_String8 result = Dqn_WinString16ToString8Allocator(dir16, allocator); + Dqn_ThreadTempArena scratch = Dqn_Thread_TempArena(allocator.user_context); + Dqn_String16 suffix16 = Dqn_Win_String8ToString16Allocator(suffix, Dqn_Arena_Allocator(scratch.arena)); + Dqn_String16 dir16 = Dqn_Win_WorkingDirW(Dqn_Arena_Allocator(scratch.arena), suffix16); + Dqn_String8 result = Dqn_Win_String16ToString8Allocator(dir16, allocator); return result; } -DQN_API Dqn_String16 Dqn_WinWorkingDirW(Dqn_Allocator allocator, Dqn_String16 suffix) +DQN_API Dqn_String16 Dqn_Win_WorkingDirW(Dqn_Allocator allocator, Dqn_String16 suffix) { DQN_ASSERT(suffix.size >= 0); Dqn_String16 result = {}; - Dqn_ThreadScratch scratch = Dqn_ThreadGetScratch(allocator.user_context); + Dqn_ThreadTempArena scratch = Dqn_Thread_TempArena(allocator.user_context); // NOTE: required_size is the size required *including* the null-terminator unsigned long required_size = GetCurrentDirectoryW(0, nullptr); unsigned long desired_size = required_size + DQN_CAST(unsigned long) suffix.size; - wchar_t *scratch_w_path = Dqn_ArenaNewArray(scratch.arena, wchar_t, desired_size, Dqn_ZeroMem_No); + wchar_t *scratch_w_path = Dqn_Arena_NewArray(scratch.arena, wchar_t, desired_size, Dqn_ZeroMem_No); if (!scratch_w_path) return result; @@ -7331,7 +7304,7 @@ DQN_API Dqn_String16 Dqn_WinWorkingDirW(Dqn_Allocator allocator, Dqn_String16 su return result; } - wchar_t *w_path = Dqn_AllocatorNewArray(allocator, wchar_t, desired_size, Dqn_ZeroMem_No); + wchar_t *w_path = Dqn_Allocator_NewArray(allocator, wchar_t, desired_size, Dqn_ZeroMem_No); if (!w_path) return result; @@ -7345,7 +7318,7 @@ DQN_API Dqn_String16 Dqn_WinWorkingDirW(Dqn_Allocator allocator, Dqn_String16 su return result; } -DQN_API bool Dqn_WinFolderWIterate(Dqn_String16 path, Dqn_WinFolderIteratorW *it) +DQN_API bool Dqn_Win_FolderWIterate(Dqn_String16 path, Dqn_Win_FolderIteratorW *it) { WIN32_FIND_DATAW find_data = {}; if (it->handle) @@ -7376,8 +7349,8 @@ DQN_API bool Dqn_WinFolderWIterate(Dqn_String16 path, Dqn_WinFolderIteratorW *it if (find_data.dwFileAttributes & ~FILE_ATTRIBUTE_DIRECTORY) { - it->file_name.size = Dqn_LStringSize(find_data.cFileName); - DQN_ASSERT(it->file_name.size < (Dqn_ArrayCountI(it->file_name_buf) - 1)); + it->file_name.size = Dqn_CString16_Size(find_data.cFileName); + DQN_ASSERT(it->file_name.size < (Dqn_CArray_CountI(it->file_name_buf) - 1)); DQN_MEMCOPY(it->file_name.data, find_data.cFileName, it->file_name.size * sizeof(wchar_t)); it->file_name_buf[it->file_name.size] = 0; @@ -7389,17 +7362,17 @@ DQN_API bool Dqn_WinFolderWIterate(Dqn_String16 path, Dqn_WinFolderIteratorW *it return true; } -DQN_API bool Dqn_WinFolderIterate(Dqn_String8 path, Dqn_WinFolderIterator *it) +DQN_API bool Dqn_Win_FolderIterate(Dqn_String8 path, Dqn_Win_FolderIterator *it) { wchar_t path16[DQN_OS_WIN32_MAX_PATH]; path16[0] = 0; int path16_size = 0; - Dqn_WinFolderIteratorW wide_it = {}; + Dqn_Win_FolderIteratorW wide_it = {}; if (it->handle) wide_it.handle = it->handle; else { - path16_size = Dqn_WinString8ToCString16(path, path16, DQN_OS_WIN32_MAX_PATH); + path16_size = Dqn_Win_String8ToCString16(path, path16, DQN_OS_WIN32_MAX_PATH); if (path16[path16_size - 2] != L'\\' && path16[path16_size - 1] != L'*') { @@ -7417,18 +7390,18 @@ DQN_API bool Dqn_WinFolderIterate(Dqn_String8 path, Dqn_WinFolderIterator *it) DQN_ASSERT(path16_size <= DQN_OS_WIN32_MAX_PATH); } - bool result = Dqn_WinFolderWIterate(Dqn_String16{path16, path16_size}, &wide_it); + bool result = Dqn_Win_FolderWIterate(Dqn_String16{path16, path16_size}, &wide_it); it->handle = wide_it.handle; if (result) { - int size = Dqn_WinString16ToCString8(wide_it.file_name, it->file_name_buf, DQN_ARRAY_ICOUNT(it->file_name_buf)); - it->file_name = Dqn_String8Init(it->file_name_buf, size); + int size = Dqn_Win_String16ToCString8(wide_it.file_name, it->file_name_buf, DQN_ARRAY_ICOUNT(it->file_name_buf)); + it->file_name = Dqn_String8_Init(it->file_name_buf, size); } return result; } #if defined(DQN_WITH_WIN_NET) -DQN_API Dqn_WinNetHandle Dqn_WinNetHandleInitCString(char const *url, int url_size) +DQN_API Dqn_Win_NetHandle Dqn_Win_NetHandleInitCString(char const *url, int url_size) { URL_COMPONENTSA components = {}; components.dwStructSize = sizeof(components); @@ -7436,10 +7409,10 @@ DQN_API Dqn_WinNetHandle Dqn_WinNetHandleInitCString(char const *url, int url_si components.dwUrlPathLength = url_size; // Seperate the URL into bits and bobs - Dqn_WinNetHandle result = {}; + Dqn_Win_NetHandle result = {}; if (!InternetCrackUrlA(url, url_size, 0 /*flags*/, &components)) { - Dqn_WinDumpLastError("InternetCrackUrlA"); + Dqn_Win_DumpLastError("InternetCrackUrlA"); return result; } @@ -7478,19 +7451,19 @@ DQN_API Dqn_WinNetHandle Dqn_WinNetHandleInitCString(char const *url, int url_si 0 /*flags*/, 0 /*context*/); - result.state = Dqn_WinNetHandleState::Initialised; + result.state = Dqn_Win_NetHandleState::Initialised; return result; } -DQN_API Dqn_WinNetHandle Dqn_WinNetHandleInitString(Dqn_String8 url) +DQN_API Dqn_Win_NetHandle Dqn_Win_NetHandleInitString(Dqn_String8 url) { - Dqn_WinNetHandle result = Dqn_WinNetHandleInitCString(url.data, DQN_CAST(int)url.size); + Dqn_Win_NetHandle result = Dqn_Win_NetHandleInitCString(url.data, DQN_CAST(int)url.size); return result; } -DQN_API void Dqn_WinNetHandleFinish(Dqn_WinNetHandle *handle) +DQN_API void Dqn_Win_NetHandleFinish(Dqn_Win_NetHandle *handle) { - if (!Dqn_WinNetHandleIsValid(handle)) + if (!Dqn_Win_NetHandleIsValid(handle)) return; InternetCloseHandle(handle->internet_open_handle); @@ -7501,26 +7474,26 @@ DQN_API void Dqn_WinNetHandleFinish(Dqn_WinNetHandle *handle) handle->http_handle = nullptr; } -DQN_API bool Dqn_WinNetHandleIsValid(Dqn_WinNetHandle const *handle) +DQN_API bool Dqn_Win_NetHandleIsValid(Dqn_Win_NetHandle const *handle) { - bool result = handle->state >= Dqn_WinNetHandleState::Initialised; + bool result = handle->state >= Dqn_Win_NetHandleState::Initialised; return result; } -DQN_API void Dqn_WinNetHandleSetUserAgentCString(Dqn_WinNetHandle *handle, char const *user_agent, int user_agent_size) +DQN_API void Dqn_Win_NetHandleSetUserAgentCString(Dqn_Win_NetHandle *handle, char const *user_agent, int user_agent_size) { - if (!Dqn_WinNetHandleIsValid(handle)) + if (!Dqn_Win_NetHandleIsValid(handle)) return; InternetSetOptionA(handle->internet_open_handle, INTERNET_OPTION_USER_AGENT, (void *)user_agent, user_agent_size); } -DQN_API bool Dqn_WinNetHandlePump(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size, char *dest, int dest_size, size_t *download_size) +DQN_API bool Dqn_Win_NetHandlePump(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size, char *dest, int dest_size, size_t *download_size) { - if (!Dqn_WinNetHandleIsValid(handle)) + if (!Dqn_Win_NetHandleIsValid(handle)) return false; - if (handle->state == Dqn_WinNetHandleState::Initialised) + if (handle->state == Dqn_Win_NetHandleState::Initialised) { DQN_ASSERT(handle->http_handle == nullptr); handle->http_handle = HttpOpenRequestA(handle->internet_connect_handle, @@ -7538,17 +7511,17 @@ DQN_API bool Dqn_WinNetHandlePump(Dqn_WinNetHandle *handle, char const *http_ver post_data, post_data_size)) { - handle->state = Dqn_WinNetHandleState::RequestGood; + handle->state = Dqn_Win_NetHandleState::RequestGood; return true; } else { - handle->state = Dqn_WinNetHandleState::RequestFailed; - Dqn_WinDumpLastError("Failed to send request for: %.*s", handle->host_name_size, handle->host_name); + handle->state = Dqn_Win_NetHandleState::RequestFailed; + Dqn_Win_DumpLastError("Failed to send request for: %.*s", handle->host_name_size, handle->host_name); } } - if (handle->state == Dqn_WinNetHandleState::RequestFailed) + if (handle->state == Dqn_Win_NetHandleState::RequestFailed) return false; bool result = true; @@ -7573,7 +7546,7 @@ DQN_API bool Dqn_WinNetHandlePump(Dqn_WinNetHandle *handle, char const *http_ver // IF they need to set a new URL/resource location then they need to // make a new handle for that otherwise they can re-use this handle to // hit that same end point. - handle->state = Dqn_WinNetHandleState::Initialised; + handle->state = Dqn_Win_NetHandleState::Initialised; InternetCloseHandle(handle->http_handle); handle->http_handle = nullptr; } @@ -7581,22 +7554,22 @@ DQN_API bool Dqn_WinNetHandlePump(Dqn_WinNetHandle *handle, char const *http_ver return result; } -struct Dqn_WinNetChunk +struct Dqn_Win_NetChunk { char data[DQN_WIN_NET_HANDLE_DOWNLOAD_SIZE]; size_t size; - Dqn_WinNetChunk *next; + Dqn_Win_NetChunk *next; }; -DQN_API char *Dqn_WinNetHandlePumpToCString(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size, Dqn_Arena *arena, size_t *download_size) +DQN_API char *Dqn_Win_NetHandlePumpToCString(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size, Dqn_Arena *arena, size_t *download_size) { - Dqn_ThreadScratch scratch = Dqn_ThreadGetScratch(arena); - size_t total_size = 0; - Dqn_WinNetChunk * first_chunk = nullptr; - for (Dqn_WinNetChunk *last_chunk = nullptr;;) + Dqn_ThreadTempArena scratch = Dqn_Thread_TempArena(arena); + size_t total_size = 0; + Dqn_Win_NetChunk *first_chunk = nullptr; + for (Dqn_Win_NetChunk *last_chunk = nullptr;;) { - Dqn_WinNetChunk *chunk = Dqn_ArenaNew(scratch.arena, Dqn_WinNetChunk, Dqn_ZeroMem_Yes); - bool pump_result = Dqn_WinNetHandlePump(handle, http_verb, post_data, post_data_size, chunk->data, DQN_WIN_NET_HANDLE_DOWNLOAD_SIZE, &chunk->size); + Dqn_Win_NetChunk *chunk = Dqn_Arena_New(scratch.arena, Dqn_Win_NetChunk, Dqn_ZeroMem_Yes); + bool pump_result = Dqn_Win_NetHandlePump(handle, http_verb, post_data, post_data_size, chunk->data, DQN_WIN_NET_HANDLE_DOWNLOAD_SIZE, &chunk->size); if (chunk->size) { total_size += chunk->size; @@ -7616,9 +7589,9 @@ DQN_API char *Dqn_WinNetHandlePumpToCString(Dqn_WinNetHandle *handle, char const break; } - char *result = Dqn_ArenaNewArray(arena, char, total_size + 1 /*null-terminator*/, Dqn_ZeroMem_No); + char *result = Dqn_Arena_NewArray(arena, char, total_size + 1 /*null-terminator*/, Dqn_ZeroMem_No); char *result_ptr = result; - for (Dqn_WinNetChunk *chunk = first_chunk; chunk; chunk = chunk->next) + for (Dqn_Win_NetChunk *chunk = first_chunk; chunk; chunk = chunk->next) { DQN_MEMCOPY(result_ptr, chunk->data, chunk->size); result_ptr += chunk->size; @@ -7629,33 +7602,33 @@ DQN_API char *Dqn_WinNetHandlePumpToCString(Dqn_WinNetHandle *handle, char const return result; } -DQN_API Dqn_String8 Dqn_WinNetHandlePumpToString(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size, Dqn_Arena *arena) +DQN_API Dqn_String8 Dqn_Win_NetHandlePumpToString(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size, Dqn_Arena *arena) { size_t size = 0; - char * download = Dqn_WinNetHandlePumpToCString(handle, http_verb, post_data, post_data_size, arena, &size); - Dqn_String8 result = Dqn_String8Init(download, size); + char * download = Dqn_Win_NetHandlePumpToCString(handle, http_verb, post_data, post_data_size, arena, &size); + Dqn_String8 result = Dqn_String8_Init(download, size); return result; } -DQN_API void Dqn_WinNetHandlePumpToCRTFile(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size, FILE *file) +DQN_API void Dqn_Win_NetHandlePumpToCRTFile(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size, FILE *file) { for (bool keep_pumping = true; keep_pumping;) { char buffer[DQN_WIN_NET_HANDLE_DOWNLOAD_SIZE]; size_t buffer_size = 0; - keep_pumping = Dqn_WinNetHandlePump(handle, http_verb, post_data, post_data_size, buffer, sizeof(buffer), &buffer_size); + keep_pumping = Dqn_Win_NetHandlePump(handle, http_verb, post_data, post_data_size, buffer, sizeof(buffer), &buffer_size); fprintf(file, "%.*s", (int)buffer_size, buffer); } } -DQN_API char *Dqn_WinNetHandlePumpToMallocCString(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size, size_t *download_size) +DQN_API char *Dqn_Win_NetHandlePumpToMallocCString(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size, size_t *download_size) { size_t total_size = 0; - Dqn_WinNetChunk * first_chunk = nullptr; - for (Dqn_WinNetChunk *last_chunk = nullptr;;) + Dqn_Win_NetChunk * first_chunk = nullptr; + for (Dqn_Win_NetChunk *last_chunk = nullptr;;) { - Dqn_WinNetChunk *chunk = (Dqn_WinNetChunk *)calloc(1, sizeof(Dqn_WinNetChunk)); - bool pump_result = Dqn_WinNetHandlePump(handle, http_verb, post_data, post_data_size, chunk->data, DQN_WIN_NET_HANDLE_DOWNLOAD_SIZE, &chunk->size); + Dqn_Win_NetChunk *chunk = (Dqn_Win_NetChunk *)calloc(1, sizeof(Dqn_Win_NetChunk)); + bool pump_result = Dqn_Win_NetHandlePump(handle, http_verb, post_data, post_data_size, chunk->data, DQN_WIN_NET_HANDLE_DOWNLOAD_SIZE, &chunk->size); if (chunk->size) { total_size += chunk->size; @@ -7677,12 +7650,12 @@ DQN_API char *Dqn_WinNetHandlePumpToMallocCString(Dqn_WinNetHandle *handle, char char *result = (char *)malloc((total_size + 1) * sizeof(char)); char *result_ptr = result; - for (Dqn_WinNetChunk *chunk = first_chunk; chunk;) + for (Dqn_Win_NetChunk *chunk = first_chunk; chunk;) { DQN_MEMCOPY(result_ptr, chunk->data, chunk->size); result_ptr += chunk->size; - Dqn_WinNetChunk *prev_chunk = chunk; + Dqn_Win_NetChunk *prev_chunk = chunk; chunk = chunk->next; free(prev_chunk); } @@ -7692,11 +7665,11 @@ DQN_API char *Dqn_WinNetHandlePumpToMallocCString(Dqn_WinNetHandle *handle, char return result; } -DQN_API Dqn_String8 Dqn_WinNetHandlePumpToMallocString(Dqn_WinNetHandle *handle, char const *http_verb, char *post_data, int post_data_size) +DQN_API Dqn_String8 Dqn_Win_NetHandlePumpToMallocString(Dqn_Win_NetHandle *handle, char const *http_verb, char *post_data, int post_data_size) { size_t download_size = 0; - char * download = Dqn_WinNetHandlePumpToMallocCString(handle, http_verb, post_data, post_data_size, &download_size); - Dqn_String8 result = Dqn_String8Init(download, download_size); + char * download = Dqn_Win_NetHandlePumpToMallocCString(handle, http_verb, post_data, post_data_size, &download_size); + Dqn_String8 result = Dqn_String8_Init(download, download_size); return result; } #endif // DQN_WITH_WIN_NET @@ -7707,31 +7680,31 @@ DQN_API Dqn_String8 Dqn_WinNetHandlePumpToMallocString(Dqn_WinNetHandle *handle, // // Default values recommended by: http://isthe.com/chongo/tech/comp/fnv/ // -DQN_API Dqn_u32 Dqn_FNV1A32Iterate(void const *bytes, Dqn_isize size, Dqn_u32 hash) +DQN_API uint32_t Dqn_FNV1A32_Iterate(void const *bytes, Dqn_isize size, uint32_t hash) { - auto buffer = DQN_CAST(Dqn_u8 const *)bytes; + auto buffer = DQN_CAST(uint8_t const *)bytes; for (Dqn_isize i = 0; i < size; i++) hash = (buffer[i] ^ hash) * 16777619 /*FNV Prime*/; return hash; } -DQN_API Dqn_u32 Dqn_FNV1A32Hash(void const *bytes, Dqn_isize size) +DQN_API uint32_t Dqn_FNV1A32_Hash(void const *bytes, Dqn_isize size) { - Dqn_u32 result = Dqn_FNV1A32Iterate(bytes, size, DQN_FNV1A32_SEED); + uint32_t result = Dqn_FNV1A32_Iterate(bytes, size, DQN_FNV1A32_SEED); return result; } -DQN_API Dqn_u64 Dqn_FNV1A64Iterate(void const *bytes, Dqn_isize size, Dqn_u64 hash) +DQN_API uint64_t Dqn_FNV1A64_Iterate(void const *bytes, Dqn_isize size, uint64_t hash) { - auto buffer = DQN_CAST(Dqn_u8 const *)bytes; + auto buffer = DQN_CAST(uint8_t const *)bytes; for (Dqn_isize i = 0; i < size; i++) hash = (buffer[i] ^ hash) * 1099511628211 /*FNV Prime*/; return hash; } -DQN_API Dqn_u64 Dqn_FNV1A64Hash(void const *bytes, Dqn_isize size) +DQN_API uint64_t Dqn_FNV1A64_Hash(void const *bytes, Dqn_isize size) { - Dqn_u64 result = Dqn_FNV1A64Iterate(bytes, size, DQN_FNV1A64_SEED); + uint64_t result = Dqn_FNV1A64_Iterate(bytes, size, DQN_FNV1A64_SEED); return result; } @@ -7752,12 +7725,12 @@ DQN_API Dqn_u64 Dqn_FNV1A64Hash(void const *bytes, Dqn_isize size) // Block read - if your platform needs to do endian-swapping or can only // handle aligned reads, do the conversion here -DQN_MMH3_FORCE_INLINE Dqn_u32 Dqn_MurmurHash3_GetBlock32(Dqn_u32 const *p, int i) +DQN_MMH3_FORCE_INLINE uint32_t Dqn_MurmurHash3_GetBlock32(uint32_t const *p, int i) { return p[i]; } -DQN_MMH3_FORCE_INLINE Dqn_u64 Dqn_MurmurHash3_GetBlock64(Dqn_u64 const *p, int i) +DQN_MMH3_FORCE_INLINE uint64_t Dqn_MurmurHash3_GetBlock64(uint64_t const *p, int i) { return p[i]; } @@ -7765,7 +7738,7 @@ DQN_MMH3_FORCE_INLINE Dqn_u64 Dqn_MurmurHash3_GetBlock64(Dqn_u64 const *p, int i //----------------------------------------------------------------------------- // Finalization mix - force all bits of a hash block to avalanche -DQN_MMH3_FORCE_INLINE Dqn_u32 Dqn_MurmurHash3_FMix32(Dqn_u32 h) +DQN_MMH3_FORCE_INLINE uint32_t Dqn_MurmurHash3_FMix32(uint32_t h) { h ^= h >> 16; h *= 0x85ebca6b; @@ -7775,7 +7748,7 @@ DQN_MMH3_FORCE_INLINE Dqn_u32 Dqn_MurmurHash3_FMix32(Dqn_u32 h) return h; } -DQN_MMH3_FORCE_INLINE Dqn_u64 Dqn_MurmurHash3_FMix64(Dqn_u64 k) +DQN_MMH3_FORCE_INLINE uint64_t Dqn_MurmurHash3_FMix64(uint64_t k) { k ^= k >> 33; k *= 0xff51afd7ed558ccd; @@ -7785,24 +7758,24 @@ DQN_MMH3_FORCE_INLINE Dqn_u64 Dqn_MurmurHash3_FMix64(Dqn_u64 k) return k; } -DQN_API Dqn_u32 Dqn_MurmurHash3x86_32(void const *key, int len, Dqn_u32 seed) +DQN_API uint32_t Dqn_MurmurHash3x86_32(void const *key, int len, uint32_t seed) { - const Dqn_u8 *data = (const Dqn_u8 *)key; + const uint8_t *data = (const uint8_t *)key; const int nblocks = len / 4; - Dqn_u32 h1 = seed; + uint32_t h1 = seed; - const Dqn_u32 c1 = 0xcc9e2d51; - const Dqn_u32 c2 = 0x1b873593; + const uint32_t c1 = 0xcc9e2d51; + const uint32_t c2 = 0x1b873593; //---------- // body - const Dqn_u32 *blocks = (const Dqn_u32 *)(data + nblocks * 4); + const uint32_t *blocks = (const uint32_t *)(data + nblocks * 4); for (int i = -nblocks; i; i++) { - Dqn_u32 k1 = Dqn_MurmurHash3_GetBlock32(blocks, i); + uint32_t k1 = Dqn_MurmurHash3_GetBlock32(blocks, i); k1 *= c1; k1 = DQN_MMH3_ROTL32(k1, 15); @@ -7816,9 +7789,9 @@ DQN_API Dqn_u32 Dqn_MurmurHash3x86_32(void const *key, int len, Dqn_u32 seed) //---------- // tail - const Dqn_u8 *tail = (const Dqn_u8 *)(data + nblocks * 4); + const uint8_t *tail = (const uint8_t *)(data + nblocks * 4); - Dqn_u32 k1 = 0; + uint32_t k1 = 0; switch (len & 3) { @@ -7844,26 +7817,26 @@ DQN_API Dqn_u32 Dqn_MurmurHash3x86_32(void const *key, int len, Dqn_u32 seed) return h1; } -DQN_API Dqn_MurmurHash3128 Dqn_MurmurHash3x64_128(void const *key, int len, Dqn_u32 seed) +DQN_API Dqn_MurmurHash3128 Dqn_MurmurHash3x64_128(void const *key, int len, uint32_t seed) { - const Dqn_u8 *data = (const Dqn_u8 *)key; + const uint8_t *data = (const uint8_t *)key; const int nblocks = len / 16; - Dqn_u64 h1 = seed; - Dqn_u64 h2 = seed; + uint64_t h1 = seed; + uint64_t h2 = seed; - const Dqn_u64 c1 = 0x87c37b91114253d5; - const Dqn_u64 c2 = 0x4cf5ad432745937f; + const uint64_t c1 = 0x87c37b91114253d5; + const uint64_t c2 = 0x4cf5ad432745937f; //---------- // body - const Dqn_u64 *blocks = (const Dqn_u64 *)(data); + const uint64_t *blocks = (const uint64_t *)(data); for (int i = 0; i < nblocks; i++) { - Dqn_u64 k1 = Dqn_MurmurHash3_GetBlock64(blocks, i * 2 + 0); - Dqn_u64 k2 = Dqn_MurmurHash3_GetBlock64(blocks, i * 2 + 1); + uint64_t k1 = Dqn_MurmurHash3_GetBlock64(blocks, i * 2 + 0); + uint64_t k2 = Dqn_MurmurHash3_GetBlock64(blocks, i * 2 + 1); k1 *= c1; k1 = DQN_MMH3_ROTL64(k1, 31); @@ -7887,48 +7860,48 @@ DQN_API Dqn_MurmurHash3128 Dqn_MurmurHash3x64_128(void const *key, int len, Dqn_ //---------- // tail - const Dqn_u8 *tail = (const Dqn_u8 *)(data + nblocks * 16); + const uint8_t *tail = (const uint8_t *)(data + nblocks * 16); - Dqn_u64 k1 = 0; - Dqn_u64 k2 = 0; + uint64_t k1 = 0; + uint64_t k2 = 0; switch (len & 15) { case 15: - k2 ^= ((Dqn_u64)tail[14]) << 48; + k2 ^= ((uint64_t)tail[14]) << 48; case 14: - k2 ^= ((Dqn_u64)tail[13]) << 40; + k2 ^= ((uint64_t)tail[13]) << 40; case 13: - k2 ^= ((Dqn_u64)tail[12]) << 32; + k2 ^= ((uint64_t)tail[12]) << 32; case 12: - k2 ^= ((Dqn_u64)tail[11]) << 24; + k2 ^= ((uint64_t)tail[11]) << 24; case 11: - k2 ^= ((Dqn_u64)tail[10]) << 16; + k2 ^= ((uint64_t)tail[10]) << 16; case 10: - k2 ^= ((Dqn_u64)tail[9]) << 8; + k2 ^= ((uint64_t)tail[9]) << 8; case 9: - k2 ^= ((Dqn_u64)tail[8]) << 0; + k2 ^= ((uint64_t)tail[8]) << 0; k2 *= c2; k2 = DQN_MMH3_ROTL64(k2, 33); k2 *= c1; h2 ^= k2; case 8: - k1 ^= ((Dqn_u64)tail[7]) << 56; + k1 ^= ((uint64_t)tail[7]) << 56; case 7: - k1 ^= ((Dqn_u64)tail[6]) << 48; + k1 ^= ((uint64_t)tail[6]) << 48; case 6: - k1 ^= ((Dqn_u64)tail[5]) << 40; + k1 ^= ((uint64_t)tail[5]) << 40; case 5: - k1 ^= ((Dqn_u64)tail[4]) << 32; + k1 ^= ((uint64_t)tail[4]) << 32; case 4: - k1 ^= ((Dqn_u64)tail[3]) << 24; + k1 ^= ((uint64_t)tail[3]) << 24; case 3: - k1 ^= ((Dqn_u64)tail[2]) << 16; + k1 ^= ((uint64_t)tail[2]) << 16; case 2: - k1 ^= ((Dqn_u64)tail[1]) << 8; + k1 ^= ((uint64_t)tail[1]) << 8; case 1: - k1 ^= ((Dqn_u64)tail[0]) << 0; + k1 ^= ((uint64_t)tail[0]) << 0; k1 *= c1; k1 = DQN_MMH3_ROTL64(k1, 31); k1 *= c2; diff --git a/dqn_keccak.h b/dqn_keccak.h index 36ea261..181921e 100644 --- a/dqn_keccak.h +++ b/dqn_keccak.h @@ -716,7 +716,7 @@ Dqn_KeccakBytes32 Dqn_KeccakHex64StringToBytes(Dqn_String8 hex) { DQN_KECCAK_ASSERT(hex.size == 64); Dqn_KeccakBytes32 result; - Dqn_HexToBytes(hex.data, hex.size, result.data, sizeof(result)); + Dqn_Hex_ToBytes(hex.data, hex.size, result.data, sizeof(result)); return result; } #endif // DQN_H && DQN_WITH_HEX diff --git a/dqn_tests.cpp b/dqn_tests.cpp index 33694bf..72cdb29 100644 --- a/dqn_tests.cpp +++ b/dqn_tests.cpp @@ -32,23 +32,23 @@ Dqn_Tester Dqn_Test_Array() { Dqn_Tester test = {}; DQN_TESTER_BEGIN_GROUP("Dqn_Array"); - // NOTE: Dqn_ArrayInitWithMemory + // NOTE: Dqn_Array_InitWithMemory { { Dqn_TesterBegin(&test, "Fixed Memory: Test add single item and can't allocate more"); int memory[4] = {}; - Dqn_Array array = Dqn_ArrayInitWithMemory(memory, Dqn_ArrayCount(memory), 0 /*size*/); - Dqn_ArrayAdd(&array, 1); - Dqn_ArrayAdd(&array, 2); - Dqn_ArrayAdd(&array, 3); - Dqn_ArrayAdd(&array, 4); + Dqn_Array array = Dqn_Array_InitWithMemory(memory, Dqn_CArray_Count(memory), 0 /*size*/); + Dqn_Array_Add(&array, 1); + Dqn_Array_Add(&array, 2); + Dqn_Array_Add(&array, 3); + Dqn_Array_Add(&array, 4); DQN_TESTER_ASSERTF(&test, array.data[0] == 1, "array.data %d", array.data[0]); DQN_TESTER_ASSERTF(&test, array.data[1] == 2, "array.data %d", array.data[1]); DQN_TESTER_ASSERTF(&test, array.data[2] == 3, "array.data %d", array.data[2]); DQN_TESTER_ASSERTF(&test, array.data[3] == 4, "array.data %d", array.data[3]); DQN_TESTER_ASSERTF(&test, array.size == 4, "array.size: %zu", array.size); - int *added_item = Dqn_ArrayAdd(&array, 5); + int *added_item = Dqn_Array_Add(&array, 5); DQN_TESTER_ASSERTF(&test, added_item == nullptr, "Failed to add item to array"); DQN_TESTER_ASSERTF(&test, array.size == 4, "array.size: %zu", array.size); DQN_TESTER_ASSERTF(&test, array.max == 4, "array.max: %zu", array.max); @@ -59,8 +59,8 @@ Dqn_Tester Dqn_Test_Array() Dqn_TesterBegin(&test, "Fixed Memory: Test add array of items"); int memory[4] = {}; int DATA[] = {1, 2, 3}; - Dqn_Array array = Dqn_ArrayInitWithMemory(memory, Dqn_ArrayCount(memory), 0 /*size*/); - Dqn_ArrayAddArray(&array, DATA, Dqn_ArrayCount(DATA)); + Dqn_Array array = Dqn_Array_InitWithMemory(memory, Dqn_CArray_Count(memory), 0 /*size*/); + Dqn_Array_AddArray(&array, DATA, Dqn_CArray_Count(DATA)); DQN_TESTER_ASSERTF(&test, array.data[0] == 1, "array.data %d", array.data[0]); DQN_TESTER_ASSERTF(&test, array.data[1] == 2, "array.data %d", array.data[1]); DQN_TESTER_ASSERTF(&test, array.data[2] == 3, "array.data %d", array.data[2]); @@ -73,14 +73,14 @@ Dqn_Tester Dqn_Test_Array() Dqn_TesterBegin(&test, "Fixed Memory: Test clear and clear with memory zeroed"); int memory[4] = {}; int DATA[] = {1, 2, 3}; - Dqn_Array array = Dqn_ArrayInitWithMemory(memory, Dqn_ArrayCount(memory), 0 /*size*/); - Dqn_ArrayAddArray(&array, DATA, Dqn_ArrayCount(DATA)); - Dqn_ArrayClear(&array, Dqn_ZeroMem_No); + Dqn_Array array = Dqn_Array_InitWithMemory(memory, Dqn_CArray_Count(memory), 0 /*size*/); + Dqn_Array_AddArray(&array, DATA, Dqn_CArray_Count(DATA)); + Dqn_Array_Clear(&array, Dqn_ZeroMem_No); DQN_TESTER_ASSERTF(&test, array.size == 0, "array.size: %zu", array.size); DQN_TESTER_ASSERTF(&test, array.max == 4, "array.max: %zu", array.max); DQN_TESTER_ASSERTF(&test, array.data[0] == 1, "array.data %d. Clear but don't zero memory so old values should still remain", array.data[0]); - Dqn_ArrayClear(&array, Dqn_ZeroMem_Yes); + Dqn_Array_Clear(&array, Dqn_ZeroMem_Yes); DQN_TESTER_ASSERTF(&test, array.data[0] == 0, "array.data %d. Clear but zero memory old values should not remain", array.data[0]); Dqn_TesterEnd(&test); } @@ -89,15 +89,15 @@ Dqn_Tester Dqn_Test_Array() Dqn_TesterBegin(&test, "Fixed Memory: Test erase stable and erase unstable"); int memory[4] = {}; int DATA[] = {1, 2, 3, 4}; - Dqn_Array array = Dqn_ArrayInitWithMemory(memory, Dqn_ArrayCount(memory), 0 /*size*/); - Dqn_ArrayAddArray(&array, DATA, Dqn_ArrayCount(DATA)); - Dqn_ArrayEraseUnstable(&array, 1); + Dqn_Array array = Dqn_Array_InitWithMemory(memory, Dqn_CArray_Count(memory), 0 /*size*/); + Dqn_Array_AddArray(&array, DATA, Dqn_CArray_Count(DATA)); + Dqn_Array_EraseUnstable(&array, 1); DQN_TESTER_ASSERTF(&test, array.data[0] == 1, "array.data %d", array.data[0]); DQN_TESTER_ASSERTF(&test, array.data[1] == 4, "array.data %d", array.data[1]); DQN_TESTER_ASSERTF(&test, array.data[2] == 3, "array.data %d", array.data[2]); DQN_TESTER_ASSERTF(&test, array.size == 3, "array.size: %zu", array.size); - Dqn_ArrayEraseStable(&array, 0); + Dqn_Array_EraseStable(&array, 0); DQN_TESTER_ASSERTF(&test, array.data[0] == 4, "array.data: %d", array.data[0]); DQN_TESTER_ASSERTF(&test, array.data[1] == 3, "array.data: %d", array.data[1]); DQN_TESTER_ASSERTF(&test, array.size == 2, "array.size: %zu", array.size); @@ -108,14 +108,14 @@ Dqn_Tester Dqn_Test_Array() Dqn_TesterBegin(&test, "Fixed Memory: Test array pop and peek"); int memory[4] = {}; int DATA[] = {1, 2, 3}; - Dqn_Array array = Dqn_ArrayInitWithMemory(memory, Dqn_ArrayCount(memory), 0 /*size*/); - Dqn_ArrayAddArray(&array, DATA, Dqn_ArrayCount(DATA)); - Dqn_ArrayPop(&array, 2); + Dqn_Array array = Dqn_Array_InitWithMemory(memory, Dqn_CArray_Count(memory), 0 /*size*/); + Dqn_Array_AddArray(&array, DATA, Dqn_CArray_Count(DATA)); + Dqn_Array_Pop(&array, 2); DQN_TESTER_ASSERTF(&test, array.data[0] == 1, "array.data: %d", array.data[0]); DQN_TESTER_ASSERTF(&test, array.size == 1, "array.size: %zu", array.size); DQN_TESTER_ASSERTF(&test, array.max == 4, "array.max: %zu", array.max); - int *peek_item = Dqn_ArrayPeek(&array); + int *peek_item = Dqn_Array_Peek(&array); DQN_TESTER_ASSERTF(&test, *peek_item == 1, "peek: %d", *peek_item); DQN_TESTER_ASSERTF(&test, array.size == 1, "array.size: %zu", array.size); DQN_TESTER_ASSERTF(&test, array.max == 4, "array.max: %zu", array.max); @@ -130,25 +130,25 @@ Dqn_Tester Dqn_Test_Array() Dqn_Array array = {}; array.arena = &arena; - Dqn_ArrayReserve(&array, 4); + Dqn_Array_Reserve(&array, 4); DQN_TESTER_ASSERTF(&test, array.size == 0, "array.size: %zu", array.size); DQN_TESTER_ASSERTF(&test, array.max == 4, "array.max: %zu", array.max); int DATA[] = {1, 2, 3, 4}; - Dqn_ArrayAddArray(&array, DATA, Dqn_ArrayCount(DATA)); + Dqn_Array_AddArray(&array, DATA, Dqn_CArray_Count(DATA)); DQN_TESTER_ASSERTF(&test, array.data[0] == 1, "array.data: %d", array.data[0]); DQN_TESTER_ASSERTF(&test, array.data[1] == 2, "array.data: %d", array.data[1]); DQN_TESTER_ASSERTF(&test, array.data[2] == 3, "array.data: %d", array.data[2]); DQN_TESTER_ASSERTF(&test, array.data[3] == 4, "array.data: %d", array.data[3]); DQN_TESTER_ASSERTF(&test, array.size == 4, "array.size: %zu", array.size); - int *added_item = Dqn_ArrayAdd(&array, 5); + int *added_item = Dqn_Array_Add(&array, 5); DQN_TESTER_ASSERTF(&test, *added_item == 5, "added_item: %d", *added_item); DQN_TESTER_ASSERTF(&test, array.data[4] == 5, "array.data: %d", array.data[4]); DQN_TESTER_ASSERTF(&test, array.size == 5, "array.size: %zu", array.size); DQN_TESTER_ASSERTF(&test, array.max >= 5, "array.max: %zu", array.max); - Dqn_ArenaFree(&arena, false /*clear_mem*/); + Dqn_Arena_Free(&arena, false /*clear_mem*/); Dqn_TesterEnd(&test); } @@ -162,16 +162,16 @@ Dqn_Tester Dqn_Test_File() DQN_TESTER_BEGIN_GROUP("Dqn_Fs"); { Dqn_Arena arena = {}; - Dqn_Allocator allocator = Dqn_ArenaAllocator(&arena); + Dqn_Allocator allocator = Dqn_Arena_Allocator(&arena); Dqn_TesterBegin(&test, "Make directory recursive \"abcd/efgh\""); - DQN_TESTER_ASSERTF(&test, Dqn_FsMakeDir(DQN_STRING8("abcd/efgh")), "Failed to make directory"); - DQN_TESTER_ASSERTF(&test, Dqn_FsDirExists(DQN_STRING8("abcd")), "Directory was not made"); - DQN_TESTER_ASSERTF(&test, Dqn_FsDirExists(DQN_STRING8("abcd/efgh")), "Subdirectory was not made"); - DQN_TESTER_ASSERTF(&test, Dqn_FsExists(DQN_STRING8("abcd")) == false, "This function should only return true for files"); - DQN_TESTER_ASSERTF(&test, Dqn_FsExists(DQN_STRING8("abcd/efgh")) == false, "This function should only return true for files"); - DQN_TESTER_ASSERTF(&test, Dqn_FsDelete(DQN_STRING8("abcd/efgh")), "Failed to delete directory"); - DQN_TESTER_ASSERTF(&test, Dqn_FsDelete(DQN_STRING8("abcd")), "Failed to cleanup directory"); - Dqn_ArenaFree(&arena, false /*clear_mem*/); + DQN_TESTER_ASSERTF(&test, Dqn_Fs_MakeDir(DQN_STRING8("abcd/efgh")), "Failed to make directory"); + DQN_TESTER_ASSERTF(&test, Dqn_Fs_DirExists(DQN_STRING8("abcd")), "Directory was not made"); + DQN_TESTER_ASSERTF(&test, Dqn_Fs_DirExists(DQN_STRING8("abcd/efgh")), "Subdirectory was not made"); + DQN_TESTER_ASSERTF(&test, Dqn_Fs_Exists(DQN_STRING8("abcd")) == false, "This function should only return true for files"); + DQN_TESTER_ASSERTF(&test, Dqn_Fs_Exists(DQN_STRING8("abcd/efgh")) == false, "This function should only return true for files"); + DQN_TESTER_ASSERTF(&test, Dqn_Fs_Delete(DQN_STRING8("abcd/efgh")), "Failed to delete directory"); + DQN_TESTER_ASSERTF(&test, Dqn_Fs_Delete(DQN_STRING8("abcd")), "Failed to cleanup directory"); + Dqn_Arena_Free(&arena, false /*clear_mem*/); Dqn_TesterEnd(&test); } @@ -179,43 +179,43 @@ Dqn_Tester Dqn_Test_File() // NOTE: Write step Dqn_String8 const SRC_FILE = DQN_STRING8("dqn_test_file"); Dqn_TesterBegin(&test, "Write file, read it, copy it, move it and delete it"); - Dqn_b32 write_result = Dqn_FsWriteFileCString8(SRC_FILE.data, SRC_FILE.size, "test", 4); + Dqn_b32 write_result = Dqn_Fs_WriteCString8ToFileCString8(SRC_FILE.data, SRC_FILE.size, "test", 4); DQN_TESTER_ASSERT(&test, write_result); - DQN_TESTER_ASSERT(&test, Dqn_FsExists(SRC_FILE)); + DQN_TESTER_ASSERT(&test, Dqn_Fs_Exists(SRC_FILE)); // NOTE: Read step Dqn_Arena arena = {}; - Dqn_String8 read_file = Dqn_FsReadFileCString8ToString8Arena(SRC_FILE.data, SRC_FILE.size, &arena); - DQN_TESTER_ASSERTF(&test, Dqn_String8IsValid(read_file), "Failed to load file"); + Dqn_String8 read_file = Dqn_Fs_ReadFileCString8ToString8Arena(SRC_FILE.data, SRC_FILE.size, &arena); + DQN_TESTER_ASSERTF(&test, Dqn_String8_IsValid(read_file), "Failed to load file"); DQN_TESTER_ASSERTF(&test, read_file.size == 4, "File read wrong amount of bytes"); - DQN_TESTER_ASSERTF(&test, Dqn_String8Eq(read_file, DQN_STRING8("test")), "read(%zu): %.*s", read_file.size, DQN_STRING_FMT(read_file)); + DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(read_file, DQN_STRING8("test")), "read(%zu): %.*s", read_file.size, DQN_STRING_FMT(read_file)); // NOTE: Copy step Dqn_String8 const COPY_FILE = DQN_STRING8("dqn_test_file_copy"); - Dqn_b32 copy_result = Dqn_FsCopy(SRC_FILE, COPY_FILE, true /*overwrite*/); + Dqn_b32 copy_result = Dqn_Fs_Copy(SRC_FILE, COPY_FILE, true /*overwrite*/); DQN_TESTER_ASSERT(&test, copy_result); - DQN_TESTER_ASSERT(&test, Dqn_FsExists(COPY_FILE)); + DQN_TESTER_ASSERT(&test, Dqn_Fs_Exists(COPY_FILE)); // NOTE: Move step Dqn_String8 const MOVE_FILE = DQN_STRING8("dqn_test_file_move"); - Dqn_b32 move_result = Dqn_FsMove(COPY_FILE, MOVE_FILE, true /*overwrite*/); + Dqn_b32 move_result = Dqn_Fs_Move(COPY_FILE, MOVE_FILE, true /*overwrite*/); DQN_TESTER_ASSERT(&test, move_result); - DQN_TESTER_ASSERT(&test, Dqn_FsExists(MOVE_FILE)); - DQN_TESTER_ASSERTF(&test, Dqn_FsExists(COPY_FILE) == false, "Moving a file should remove the original"); + DQN_TESTER_ASSERT(&test, Dqn_Fs_Exists(MOVE_FILE)); + DQN_TESTER_ASSERTF(&test, Dqn_Fs_Exists(COPY_FILE) == false, "Moving a file should remove the original"); // NOTE: Delete step - Dqn_b32 delete_src_file = Dqn_FsDelete(SRC_FILE); - Dqn_b32 delete_moved_file = Dqn_FsDelete(MOVE_FILE); + Dqn_b32 delete_src_file = Dqn_Fs_Delete(SRC_FILE); + Dqn_b32 delete_moved_file = Dqn_Fs_Delete(MOVE_FILE); DQN_TESTER_ASSERT(&test, delete_src_file); DQN_TESTER_ASSERT(&test, delete_moved_file); // NOTE: Deleting non-existent file fails - Dqn_b32 delete_non_existent_src_file = Dqn_FsDelete(SRC_FILE); - Dqn_b32 delete_non_existent_moved_file = Dqn_FsDelete(MOVE_FILE); + Dqn_b32 delete_non_existent_src_file = Dqn_Fs_Delete(SRC_FILE); + Dqn_b32 delete_non_existent_moved_file = Dqn_Fs_Delete(MOVE_FILE); DQN_TESTER_ASSERT(&test, delete_non_existent_moved_file == false); DQN_TESTER_ASSERT(&test, delete_non_existent_src_file == false); - Dqn_ArenaFree(&arena, false /*clear_mem*/); + Dqn_Arena_Free(&arena, false /*clear_mem*/); Dqn_TesterEnd(&test); } DQN_TESTER_END_GROUP(&test); @@ -227,60 +227,60 @@ Dqn_Tester Dqn_Test_FixedArray() Dqn_Tester test = {}; #if defined(DQN_WITH_FIXED_ARRAY) DQN_TESTER_BEGIN_GROUP("Dqn_FixedArray"); - // NOTE: Dqn_FixedArrayInit + // NOTE: Dqn_FixedArray_Init { Dqn_TesterBegin(&test, "Initialise from raw array"); int raw_array[] = {1, 2}; - auto array = Dqn_FixedArrayInit(raw_array, (int)Dqn_ArrayCount(raw_array)); + auto array = Dqn_FixedArray_Init(raw_array, (int)Dqn_CArray_Count(raw_array)); DQN_TESTER_ASSERT(&test, array.size == 2); DQN_TESTER_ASSERT(&test, array[0] == 1); DQN_TESTER_ASSERT(&test, array[1] == 2); Dqn_TesterEnd(&test); } - // NOTE: Dqn_FixedArrayEraseStable + // NOTE: Dqn_FixedArray_EraseStable { Dqn_TesterBegin(&test, "Erase stable 1 element from array"); int raw_array[] = {1, 2, 3}; - auto array = Dqn_FixedArrayInit(raw_array, (int)Dqn_ArrayCount(raw_array)); - Dqn_FixedArrayEraseStable(&array, 1); + auto array = Dqn_FixedArray_Init(raw_array, (int)Dqn_CArray_Count(raw_array)); + Dqn_FixedArray_EraseStable(&array, 1); DQN_TESTER_ASSERT(&test, array.size == 2); DQN_TESTER_ASSERT(&test, array[0] == 1); DQN_TESTER_ASSERT(&test, array[1] == 3); Dqn_TesterEnd(&test); } - // NOTE: Dqn_FixedArrayEraseUnstable + // NOTE: Dqn_FixedArray_EraseUnstable { Dqn_TesterBegin(&test, "Erase unstable 1 element from array"); int raw_array[] = {1, 2, 3}; - auto array = Dqn_FixedArrayInit(raw_array, (int)Dqn_ArrayCount(raw_array)); - Dqn_FixedArrayEraseUnstable(&array, 0); + auto array = Dqn_FixedArray_Init(raw_array, (int)Dqn_CArray_Count(raw_array)); + Dqn_FixedArray_EraseUnstable(&array, 0); DQN_TESTER_ASSERT(&test, array.size == 2); DQN_TESTER_ASSERT(&test, array[0] == 3); DQN_TESTER_ASSERT(&test, array[1] == 2); Dqn_TesterEnd(&test); } - // NOTE: Dqn_FixedArrayAdd + // NOTE: Dqn_FixedArray_Add { Dqn_TesterBegin(&test, "Add 1 element to array"); int const ITEM = 2; int raw_array[] = {1}; - auto array = Dqn_FixedArrayInit(raw_array, (int)Dqn_ArrayCount(raw_array)); - Dqn_FixedArrayAdd(&array, ITEM); + auto array = Dqn_FixedArray_Init(raw_array, (int)Dqn_CArray_Count(raw_array)); + Dqn_FixedArray_Add(&array, ITEM); DQN_TESTER_ASSERT(&test, array.size == 2); DQN_TESTER_ASSERT(&test, array[0] == 1); DQN_TESTER_ASSERT(&test, array[1] == ITEM); Dqn_TesterEnd(&test); } - // NOTE: Dqn_FixedArrayClear + // NOTE: Dqn_FixedArray_Clear { Dqn_TesterBegin(&test, "Clear array"); int raw_array[] = {1}; - auto array = Dqn_FixedArrayInit(raw_array, (int)Dqn_ArrayCount(raw_array)); - Dqn_FixedArrayClear(&array); + auto array = Dqn_FixedArray_Init(raw_array, (int)Dqn_CArray_Count(raw_array)); + Dqn_FixedArray_Clear(&array); DQN_TESTER_ASSERT(&test, array.size == 0); Dqn_TesterEnd(&test); } @@ -295,19 +295,19 @@ Dqn_Tester Dqn_Test_FixedString() #if defined(DQN_WITH_FIXED_STRING) DQN_TESTER_BEGIN_GROUP("Dqn_FixedString"); - // NOTE: Dqn_FixedStringAppend + // NOTE: Dqn_FixedString_Append { Dqn_TesterBegin(&test, "Append too much fails"); Dqn_FixedString<4> str = {}; - DQN_TESTER_ASSERTF(&test, Dqn_FixedStringAppend(&str, "abcd") == false, "We need space for the null-terminator"); + DQN_TESTER_ASSERTF(&test, Dqn_FixedString_Append(&str, "abcd") == false, "We need space for the null-terminator"); Dqn_TesterEnd(&test); } - // NOTE: Dqn_FixedStringAppendFmt + // NOTE: Dqn_FixedString_AppendFmt { Dqn_TesterBegin(&test, "Append format string too much fails"); Dqn_FixedString<4> str = {}; - DQN_TESTER_ASSERTF(&test, Dqn_FixedStringAppendFmt(&str, "abcd") == false, "We need space for the null-terminator"); + DQN_TESTER_ASSERTF(&test, Dqn_FixedString_AppendFmt(&str, "abcd") == false, "We need space for the null-terminator"); Dqn_TesterEnd(&test); } DQN_TESTER_END_GROUP(&test); @@ -322,77 +322,77 @@ Dqn_Tester Dqn_Test_Hex() DQN_TESTER_BEGIN_GROUP("Dqn_Hex"); { Dqn_TesterBegin(&test, "Convert 0x123"); - Dqn_u64 result = Dqn_HexStringToU64(DQN_STRING8("0x123")); + uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("0x123")); DQN_TESTER_ASSERTF(&test, result == 0x123, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Convert 0xFFFF"); - Dqn_u64 result = Dqn_HexStringToU64(DQN_STRING8("0xFFFF")); + uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("0xFFFF")); DQN_TESTER_ASSERTF(&test, result == 0xFFFF, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Convert FFFF"); - Dqn_u64 result = Dqn_HexStringToU64(DQN_STRING8("FFFF")); + uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("FFFF")); DQN_TESTER_ASSERTF(&test, result == 0xFFFF, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Convert abCD"); - Dqn_u64 result = Dqn_HexStringToU64(DQN_STRING8("abCD")); + uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("abCD")); DQN_TESTER_ASSERTF(&test, result == 0xabCD, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Convert 0xabCD"); - Dqn_u64 result = Dqn_HexStringToU64(DQN_STRING8("0xabCD")); + uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("0xabCD")); DQN_TESTER_ASSERTF(&test, result == 0xabCD, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Convert 0x"); - Dqn_u64 result = Dqn_HexStringToU64(DQN_STRING8("0x")); + uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("0x")); DQN_TESTER_ASSERTF(&test, result == 0x0, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Convert 0X"); - Dqn_u64 result = Dqn_HexStringToU64(DQN_STRING8("0X")); + uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("0X")); DQN_TESTER_ASSERTF(&test, result == 0x0, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Convert 3"); - Dqn_u64 result = Dqn_HexStringToU64(DQN_STRING8("3")); + uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("3")); DQN_TESTER_ASSERTF(&test, result == 3, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Convert f"); - Dqn_u64 result = Dqn_HexStringToU64(DQN_STRING8("f")); + uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("f")); DQN_TESTER_ASSERTF(&test, result == 0xf, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Convert g"); - Dqn_u64 result = Dqn_HexStringToU64(DQN_STRING8("g")); + uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("g")); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Convert -0x3"); - Dqn_u64 result = Dqn_HexStringToU64(DQN_STRING8("-0x3")); + uint64_t result = Dqn_Hex_StringToU64(DQN_STRING8("-0x3")); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); Dqn_TesterEnd(&test); } @@ -408,9 +408,9 @@ Dqn_Tester Dqn_Test_M4() DQN_TESTER_BEGIN_GROUP("Dqn_M4"); { Dqn_TesterBegin(&test, "Simple translate and scale matrix"); - Dqn_M4 translate = Dqn_M4TranslateF(1, 2, 3); - Dqn_M4 scale = Dqn_M4ScaleF(2, 2, 2); - Dqn_M4 result = Dqn_M4Mul(translate, scale); + Dqn_M4 translate = Dqn_M4_TranslateF(1, 2, 3); + Dqn_M4 scale = Dqn_M4_ScaleF(2, 2, 2); + Dqn_M4 result = Dqn_M4_Mul(translate, scale); const Dqn_M4 EXPECT = {{ {2, 0, 0, 0}, @@ -420,10 +420,10 @@ Dqn_Tester Dqn_Test_M4() }}; DQN_TESTER_ASSERTF(&test, - memcmp(result.columns, EXPECT.columns, sizeof(EXPECT)) == 0, - "\nresult =\n%s\nexpected =\n%s", - Dqn_M4ColumnMajorString(result).data, - Dqn_M4ColumnMajorString(EXPECT).data); + memcmp(result.columns, EXPECT.columns, sizeof(EXPECT)) == 0, + "\nresult =\n%s\nexpected =\n%s", + Dqn_M4_ColumnMajorString(result).data, + Dqn_M4_ColumnMajorString(EXPECT).data); Dqn_TesterEnd(&test); } DQN_TESTER_END_GROUP(&test); @@ -438,96 +438,96 @@ Dqn_Tester Dqn_Test_DSMap() DQN_TESTER_BEGIN_GROUP("Dqn_DSMap"); { Dqn_TesterBegin(&test, "Add r-value item to map"); - Dqn_DSMap map = Dqn_DSMapInit(128); - Dqn_DSMapEntry *entry = Dqn_DSMapAddCopy(&map, 3 /*hash*/, 5 /*value*/); + Dqn_DSMap map = Dqn_DSMap_Init(128); + Dqn_DSMapEntry *entry = Dqn_DSMap_AddCopy(&map, 3 /*hash*/, 5 /*value*/); DQN_TESTER_ASSERTF(&test, map.size == 128, "size: %I64d", map.size); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %zu", map.count); DQN_TESTER_ASSERTF(&test, entry->hash == 3, "hash: %zu", entry->hash); DQN_TESTER_ASSERTF(&test, entry->value == 5, "value: %d", entry->value); - Dqn_DSMapFree(&map, Dqn_ZeroMem_No); + Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Add l-value item to map"); - Dqn_DSMap map = Dqn_DSMapInit(128); + Dqn_DSMap map = Dqn_DSMap_Init(128); int value = 5; - Dqn_DSMapEntry *entry = Dqn_DSMapAdd(&map, 3 /*hash*/, value); + Dqn_DSMapEntry *entry = Dqn_DSMap_Add(&map, 3 /*hash*/, value); DQN_TESTER_ASSERTF(&test, map.size == 128, "size: %I64d", map.size); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %zu", map.count); DQN_TESTER_ASSERTF(&test, entry->hash == 3, "hash: %zu", entry->hash); DQN_TESTER_ASSERTF(&test, entry->value == 5, "value: %d", entry->value); - Dqn_DSMapFree(&map, Dqn_ZeroMem_No); + Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Get item from map"); - Dqn_DSMap map = Dqn_DSMapInit(128); - Dqn_DSMapEntry *entry = Dqn_DSMapAddCopy(&map, 3 /*hash*/, 5 /*value*/); - Dqn_DSMapEntry *get_entry = Dqn_DSMapGet(&map, 3 /*hash*/); + Dqn_DSMap map = Dqn_DSMap_Init(128); + Dqn_DSMapEntry *entry = Dqn_DSMap_AddCopy(&map, 3 /*hash*/, 5 /*value*/); + Dqn_DSMapEntry *get_entry = Dqn_DSMap_Get(&map, 3 /*hash*/); DQN_TESTER_ASSERTF(&test, get_entry == entry, "get_entry: %p, entry: %p", get_entry, entry); - Dqn_DSMapFree(&map, Dqn_ZeroMem_No); + Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Get non-existent item from map"); - Dqn_DSMap map = Dqn_DSMapInit(128); - Dqn_DSMapEntry *entry = Dqn_DSMapGet(&map, 3 /*hash*/); + Dqn_DSMap map = Dqn_DSMap_Init(128); + Dqn_DSMapEntry *entry = Dqn_DSMap_Get(&map, 3 /*hash*/); DQN_TESTER_ASSERT(&test, entry == nullptr); - Dqn_DSMapFree(&map, Dqn_ZeroMem_No); + Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Erase item from map"); - Dqn_DSMap map = Dqn_DSMapInit(128); - Dqn_DSMapAddCopy(&map, 3 /*hash*/, 5 /*value*/); + Dqn_DSMap map = Dqn_DSMap_Init(128); + Dqn_DSMap_AddCopy(&map, 3 /*hash*/, 5 /*value*/); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %I64d", map.count); - Dqn_DSMapErase(&map, 3 /*hash*/, Dqn_ZeroMem_No); + Dqn_DSMap_Erase(&map, 3 /*hash*/, Dqn_ZeroMem_No); DQN_TESTER_ASSERTF(&test, map.count == 0, "count: %I64d", map.count); - Dqn_DSMapFree(&map, Dqn_ZeroMem_No); + Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Erase non-existent item from map"); - Dqn_DSMap map = Dqn_DSMapInit(128); - Dqn_DSMapErase(&map, 3 /*hash*/, Dqn_ZeroMem_No); + Dqn_DSMap map = Dqn_DSMap_Init(128); + Dqn_DSMap_Erase(&map, 3 /*hash*/, Dqn_ZeroMem_No); DQN_TESTER_ASSERTF(&test, map.count == 0, "count: %I64d", map.count); - Dqn_DSMapFree(&map, Dqn_ZeroMem_No); + Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Test resize on maximum load"); const Dqn_isize INIT_SIZE = 4; - Dqn_DSMap map = Dqn_DSMapInit(INIT_SIZE); - Dqn_DSMapAddCopy(&map, 0 /*hash*/, 5 /*value*/); - Dqn_DSMapAddCopy(&map, 1 /*hash*/, 5 /*value*/); + Dqn_DSMap map = Dqn_DSMap_Init(INIT_SIZE); + Dqn_DSMap_AddCopy(&map, 0 /*hash*/, 5 /*value*/); + Dqn_DSMap_AddCopy(&map, 1 /*hash*/, 5 /*value*/); DQN_TESTER_ASSERTF(&test, map.count == 2, "count: %I64d", map.count); // This *should* cause a resize because 3/4 slots filled is 75% load - Dqn_DSMapAddCopy(&map, 6 /*hash*/, 5 /*value*/); + Dqn_DSMap_AddCopy(&map, 6 /*hash*/, 5 /*value*/); DQN_TESTER_ASSERTF(&test, map.count == 3, "count: %I64d", map.count); DQN_TESTER_ASSERTF(&test, map.size == INIT_SIZE * 2, "size: %I64d", map.size); // Check that the elements are rehashed where we expected them to be - DQN_TESTER_ASSERT(&test, map.slots[0].occupied == DQN_CAST(Dqn_u8)true); - DQN_TESTER_ASSERT(&test, map.slots[1].occupied == DQN_CAST(Dqn_u8)true); - DQN_TESTER_ASSERT(&test, map.slots[2].occupied == DQN_CAST(Dqn_u8)false); - DQN_TESTER_ASSERT(&test, map.slots[3].occupied == DQN_CAST(Dqn_u8)false); - DQN_TESTER_ASSERT(&test, map.slots[4].occupied == DQN_CAST(Dqn_u8)false); - DQN_TESTER_ASSERT(&test, map.slots[5].occupied == DQN_CAST(Dqn_u8)false); - DQN_TESTER_ASSERT(&test, map.slots[6].occupied == DQN_CAST(Dqn_u8)true); - DQN_TESTER_ASSERT(&test, map.slots[7].occupied == DQN_CAST(Dqn_u8)false); + DQN_TESTER_ASSERT(&test, map.slots[0].occupied == DQN_CAST(uint8_t)true); + DQN_TESTER_ASSERT(&test, map.slots[1].occupied == DQN_CAST(uint8_t)true); + DQN_TESTER_ASSERT(&test, map.slots[2].occupied == DQN_CAST(uint8_t)false); + DQN_TESTER_ASSERT(&test, map.slots[3].occupied == DQN_CAST(uint8_t)false); + DQN_TESTER_ASSERT(&test, map.slots[4].occupied == DQN_CAST(uint8_t)false); + DQN_TESTER_ASSERT(&test, map.slots[5].occupied == DQN_CAST(uint8_t)false); + DQN_TESTER_ASSERT(&test, map.slots[6].occupied == DQN_CAST(uint8_t)true); + DQN_TESTER_ASSERT(&test, map.slots[7].occupied == DQN_CAST(uint8_t)false); DQN_TESTER_ASSERTF(&test, map.slots[0].value == 5, "value: %d", map.slots[0].value); DQN_TESTER_ASSERTF(&test, map.slots[1].value == 5, "value: %d", map.slots[1].value); DQN_TESTER_ASSERTF(&test, map.slots[6].value == 5, "value: %d", map.slots[6].value); - Dqn_DSMapFree(&map, Dqn_ZeroMem_No); + Dqn_DSMap_Free(&map, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } DQN_TESTER_END_GROUP(&test); @@ -543,8 +543,8 @@ Dqn_Tester Dqn_Test_Map() Dqn_Arena arena = {}; { Dqn_TesterBegin(&test, "Add r-value item to map"); - Dqn_Map map = Dqn_MapInitWithArena(&arena, 1); - Dqn_MapEntry *entry = Dqn_MapAddCopy(&map, 3 /*hash*/, 5 /*value*/, Dqn_MapCollideRule::Overwrite); + Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); + Dqn_MapEntry *entry = Dqn_Map_AddCopy(&map, 3 /*hash*/, 5 /*value*/, Dqn_MapCollideRule::Overwrite); DQN_TESTER_ASSERTF(&test, map.size == 1, "size: %I64d", map.size); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %zu", map.count); DQN_TESTER_ASSERTF(&test, map.chain_count == 0, "chain_count: %zu", map.chain_count); @@ -552,15 +552,15 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, entry->hash == 3, "hash: %zu", entry->hash); DQN_TESTER_ASSERTF(&test, entry->value == 5, "value: %d", entry->value); DQN_TESTER_ASSERTF(&test, entry->next == nullptr, "next: %p", entry->next); - Dqn_ArenaFree(&arena, Dqn_ZeroMem_No); + Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Add l-value item to map"); - Dqn_Map map = Dqn_MapInitWithArena(&arena, 1); + Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); int value = 5; - Dqn_MapEntry *entry = Dqn_MapAdd(&map, 3 /*hash*/, value, Dqn_MapCollideRule::Overwrite); + Dqn_MapEntry *entry = Dqn_Map_Add(&map, 3 /*hash*/, value, Dqn_MapCollideRule::Overwrite); DQN_TESTER_ASSERTF(&test, map.size == 1, "size: %I64d", map.size); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %zu", map.count); DQN_TESTER_ASSERTF(&test, map.chain_count == 0, "chain_count: %zu", map.chain_count); @@ -568,15 +568,15 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, entry->hash == 3, "hash: %zu", entry->hash); DQN_TESTER_ASSERTF(&test, entry->value == 5, "value: %d", entry->value); DQN_TESTER_ASSERTF(&test, entry->next == nullptr, "next: %p", entry->next); - Dqn_ArenaFree(&arena, Dqn_ZeroMem_No); + Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Add r-value item and overwrite on collision"); - Dqn_Map map = Dqn_MapInitWithArena(&arena, 1); - Dqn_MapEntry *entry_a = Dqn_MapAddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); - Dqn_MapEntry *entry_b = Dqn_MapAddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Overwrite); + Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); + Dqn_MapEntry *entry_a = Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); + Dqn_MapEntry *entry_b = Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Overwrite); DQN_TESTER_ASSERTF(&test, map.size == 1, "size: %zu", map.size); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %zu", map.count); DQN_TESTER_ASSERTF(&test, map.chain_count == 0, "chain_count: %zu", map.chain_count); @@ -585,29 +585,29 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, entry_b->hash == 4, "hash: %zu", entry_b->hash); DQN_TESTER_ASSERTF(&test, entry_b->value == 6, "value: %d", entry_b->value); DQN_TESTER_ASSERTF(&test, entry_b->next == nullptr, "next: %p", entry_b->next); - Dqn_ArenaFree(&arena, Dqn_ZeroMem_No); + Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Add r-value item and fail on collision"); - Dqn_Map map = Dqn_MapInitWithArena(&arena, 1); - Dqn_MapAddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); - Dqn_MapEntry *entry_b = Dqn_MapAddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Fail); + Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); + Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); + Dqn_MapEntry *entry_b = Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Fail); DQN_TESTER_ASSERTF(&test, entry_b == nullptr, "Expected entry to be overwritten"); DQN_TESTER_ASSERTF(&test, map.size == 1, "size: %zu", map.size); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %zu", map.count); DQN_TESTER_ASSERTF(&test, map.chain_count == 0, "chain_count: %zu", map.chain_count); DQN_TESTER_ASSERTF(&test, map.free_list == nullptr, "free_list: %p", map.free_list); - Dqn_ArenaFree(&arena, Dqn_ZeroMem_No); + Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Add r-value item and chain on collision"); - Dqn_Map map = Dqn_MapInitWithArena(&arena, 1); - Dqn_MapEntry *entry_a = Dqn_MapAddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); - Dqn_MapEntry *entry_b = Dqn_MapAddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); + Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); + Dqn_MapEntry *entry_a = Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); + Dqn_MapEntry *entry_b = Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); DQN_TESTER_ASSERTF(&test, map.size == 1, "size: %zu", map.size); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %zu", map.count); DQN_TESTER_ASSERTF(&test, map.chain_count == 1, "chain_count: %zu", map.chain_count); @@ -617,36 +617,36 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, entry_b->hash == 4, "hash: %zu", entry_b->hash); DQN_TESTER_ASSERTF(&test, entry_b->value == 6, "value: %d", entry_b->value); DQN_TESTER_ASSERTF(&test, entry_b->next == nullptr, "next: %p", entry_b->next); - Dqn_ArenaFree(&arena, Dqn_ZeroMem_No); + Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Add r-value item and get them back out again"); - Dqn_Map map = Dqn_MapInitWithArena(&arena, 1); - Dqn_MapEntry *entry_a = Dqn_MapAddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); - Dqn_MapEntry *entry_b = Dqn_MapAddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); + Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); + Dqn_MapEntry *entry_a = Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); + Dqn_MapEntry *entry_b = Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); - Dqn_MapEntry *entry_a_copy = Dqn_MapGet(&map, 3 /*hash*/); - Dqn_MapEntry *entry_b_copy = Dqn_MapGet(&map, 4 /*hash*/); + Dqn_MapEntry *entry_a_copy = Dqn_Map_Get(&map, 3 /*hash*/); + Dqn_MapEntry *entry_b_copy = Dqn_Map_Get(&map, 4 /*hash*/); DQN_TESTER_ASSERTF(&test, map.size == 1, "size: %zu", map.size); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %zu", map.count); DQN_TESTER_ASSERTF(&test, map.chain_count == 1, "chain_count: %zu", map.chain_count); DQN_TESTER_ASSERTF(&test, map.free_list == nullptr, "free_list: %p", map.free_list); DQN_TESTER_ASSERT(&test, entry_a_copy == entry_a); DQN_TESTER_ASSERT(&test, entry_b_copy == entry_b); - Dqn_ArenaFree(&arena, Dqn_ZeroMem_No); + Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Add r-value item and erase it"); - Dqn_Map map = Dqn_MapInitWithArena(&arena, 1); - Dqn_MapAddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); - Dqn_MapAddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); - Dqn_MapGet(&map, 3 /*hash*/); + Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); + Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); + Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); + Dqn_Map_Get(&map, 3 /*hash*/); - Dqn_MapErase(&map, 3 /*hash*/, Dqn_ZeroMem_No); + Dqn_Map_Erase(&map, 3 /*hash*/, Dqn_ZeroMem_No); DQN_TESTER_ASSERTF(&test, map.size == 1, "size: %zu", map.size); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %zu", map.count); DQN_TESTER_ASSERTF(&test, map.chain_count == 0, "chain_count: %zu", map.chain_count); @@ -656,23 +656,23 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, map.free_list->value == 5, "Entry should not be zeroed out on erase"); DQN_TESTER_ASSERTF(&test, map.free_list->next == nullptr, "This should be the first and only entry in the free list"); - Dqn_MapEntry *entry = Dqn_MapGet(&map, 4 /*hash*/); + Dqn_MapEntry *entry = Dqn_Map_Get(&map, 4 /*hash*/); DQN_TESTER_ASSERTF(&test, entry->hash == 4, "hash: %zu", entry->hash); DQN_TESTER_ASSERTF(&test, entry->value == 6, "value: %d", entry->value); DQN_TESTER_ASSERTF(&test, entry->next == nullptr, "next: %p", entry->next); - Dqn_ArenaFree(&arena, Dqn_ZeroMem_No); + Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Add r-value item and erase it, zeroing the memory out"); - Dqn_Map map = Dqn_MapInitWithArena(&arena, 1); - Dqn_MapAddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); - Dqn_MapAddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); - Dqn_MapGet(&map, 3 /*hash*/); + Dqn_Map map = Dqn_Map_InitWithArena(&arena, 1); + Dqn_Map_AddCopy(&map, 3 /*hash*/, 5, Dqn_MapCollideRule::Overwrite); + Dqn_Map_AddCopy(&map, 4 /*hash*/, 6, Dqn_MapCollideRule::Chain); + Dqn_Map_Get(&map, 3 /*hash*/); - Dqn_MapErase(&map, 3 /*hash*/, Dqn_ZeroMem_Yes); + Dqn_Map_Erase(&map, 3 /*hash*/, Dqn_ZeroMem_Yes); DQN_TESTER_ASSERTF(&test, map.size == 1, "size: %zu", map.size); DQN_TESTER_ASSERTF(&test, map.count == 1, "count: %zu", map.count); DQN_TESTER_ASSERTF(&test, map.chain_count == 0, "chain_count: %zu", map.chain_count); @@ -682,12 +682,12 @@ Dqn_Tester Dqn_Test_Map() DQN_TESTER_ASSERTF(&test, map.free_list->value == 0, "Entry should be zeroed out on erase"); DQN_TESTER_ASSERTF(&test, map.free_list->next == nullptr, "This should be the first and only entry in the free list"); - Dqn_MapEntry *entry = Dqn_MapGet(&map, 4 /*hash*/); + Dqn_MapEntry *entry = Dqn_Map_Get(&map, 4 /*hash*/); DQN_TESTER_ASSERTF(&test, entry->hash == 4, "hash: %zu", entry->hash); DQN_TESTER_ASSERTF(&test, entry->value == 6, "value: %d", entry->value); DQN_TESTER_ASSERTF(&test, entry->next == nullptr, "next: %p", entry->next); - Dqn_ArenaFree(&arena, Dqn_ZeroMem_No); + Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } @@ -705,53 +705,53 @@ Dqn_Tester Dqn_Test_Intrinsics() // atomics/intrinsics are implemented using macros we ensure the macro was // written properly with these tests. - DQN_TESTER_BEGIN_GROUP("Dqn_Atomic"); + DQN_TESTER_BEGIN_GROUP("Dqn_Atomic_"); { - Dqn_TesterBegin(&test, "Dqn_AtomicAddU32"); - Dqn_u32 val = 0; - Dqn_AtomicAddU32(&val, 1); + Dqn_TesterBegin(&test, "Dqn_Atomic_AddU32"); + uint32_t val = 0; + Dqn_Atomic_AddU32(&val, 1); DQN_TESTER_ASSERTF(&test, val == 1, "val: %u", val); Dqn_TesterEnd(&test); } { - Dqn_TesterBegin(&test, "Dqn_AtomicAddU64"); - Dqn_u64 val = 0; - Dqn_AtomicAddU64(&val, 1); + Dqn_TesterBegin(&test, "Dqn_Atomic_AddU64"); + uint64_t val = 0; + Dqn_Atomic_AddU64(&val, 1); DQN_TESTER_ASSERTF(&test, val == 1, "val: %zu", val); Dqn_TesterEnd(&test); } { - Dqn_TesterBegin(&test, "Dqn_AtomicSubU32"); - Dqn_u32 val = 1; - Dqn_AtomicSubU32(&val, 1); + Dqn_TesterBegin(&test, "Dqn_Atomic_SubU32"); + uint32_t val = 1; + Dqn_Atomic_SubU32(&val, 1); DQN_TESTER_ASSERTF(&test, val == 0, "val: %u", val); Dqn_TesterEnd(&test); } { - Dqn_TesterBegin(&test, "Dqn_AtomicSubU64"); - Dqn_u64 val = 1; - Dqn_AtomicSubU64(&val, 1); + Dqn_TesterBegin(&test, "Dqn_Atomic_SubU64"); + uint64_t val = 1; + Dqn_Atomic_SubU64(&val, 1); DQN_TESTER_ASSERTF(&test, val == 0, "val: %zu", val); Dqn_TesterEnd(&test); } { - Dqn_TesterBegin(&test, "Dqn_AtomicSetValue32"); + Dqn_TesterBegin(&test, "Dqn_Atomic_SetValue32"); long a = 0; long b = 111; - Dqn_AtomicSetValue32(&a, b); + Dqn_Atomic_SetValue32(&a, b); DQN_TESTER_ASSERTF(&test, a == b, "a: %lu, b: %lu", a, b); Dqn_TesterEnd(&test); } { - Dqn_TesterBegin(&test, "Dqn_AtomicSetValue64"); - Dqn_i64 a = 0; - Dqn_i64 b = 111; - Dqn_AtomicSetValue64(&a, b); + Dqn_TesterBegin(&test, "Dqn_Atomic_SetValue64"); + int64_t a = 0; + int64_t b = 111; + Dqn_Atomic_SetValue64(DQN_CAST(uint64_t *)&a, b); DQN_TESTER_ASSERTF(&test, a == b, "a: %I64i, b: %I64i", a, b); Dqn_TesterEnd(&test); } @@ -782,13 +782,13 @@ Dqn_Tester Dqn_Test_Rect() Dqn_Tester test = {}; #if defined(DQN_WITH_MATH) DQN_TESTER_BEGIN_GROUP("Dqn_Rect"); - // NOTE: Dqn_RectIntersection + // NOTE: Dqn_Rect_Intersection { { Dqn_TesterBegin(&test, "No intersection"); - Dqn_Rect a = Dqn_RectInitFromPosAndSize(Dqn_V2(0, 0), Dqn_V2(100, 100)); - Dqn_Rect b = Dqn_RectInitFromPosAndSize(Dqn_V2(200, 0), Dqn_V2(200, 200)); - Dqn_Rect ab = Dqn_RectIntersection(a, b); + Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2(0, 0), Dqn_V2(100, 100)); + Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2(200, 0), Dqn_V2(200, 200)); + Dqn_Rect ab = Dqn_Rect_Intersection(a, b); DQN_TESTER_ASSERTF(&test, ab.min.x == 0 && ab.min.y == 0 && ab.max.x == 0 && ab.max.y == 0, @@ -802,9 +802,9 @@ Dqn_Tester Dqn_Test_Rect() { Dqn_TesterBegin(&test, "A's min intersects B"); - Dqn_Rect a = Dqn_RectInitFromPosAndSize(Dqn_V2(50, 50), Dqn_V2(100, 100)); - Dqn_Rect b = Dqn_RectInitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); - Dqn_Rect ab = Dqn_RectIntersection(a, b); + Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2(50, 50), Dqn_V2(100, 100)); + Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); + Dqn_Rect ab = Dqn_Rect_Intersection(a, b); DQN_TESTER_ASSERTF(&test, ab.min.x == 50 && ab.min.y == 50 && ab.max.x == 100 && ab.max.y == 100, @@ -818,9 +818,9 @@ Dqn_Tester Dqn_Test_Rect() { Dqn_TesterBegin(&test, "B's min intersects A"); - Dqn_Rect a = Dqn_RectInitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); - Dqn_Rect b = Dqn_RectInitFromPosAndSize(Dqn_V2(50, 50), Dqn_V2(100, 100)); - Dqn_Rect ab = Dqn_RectIntersection(a, b); + Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); + Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2(50, 50), Dqn_V2(100, 100)); + Dqn_Rect ab = Dqn_Rect_Intersection(a, b); DQN_TESTER_ASSERTF(&test, ab.min.x == 50 && ab.min.y == 50 && ab.max.x == 100 && ab.max.y == 100, @@ -834,9 +834,9 @@ Dqn_Tester Dqn_Test_Rect() { Dqn_TesterBegin(&test, "A's max intersects B"); - Dqn_Rect a = Dqn_RectInitFromPosAndSize(Dqn_V2(-50, -50), Dqn_V2(100, 100)); - Dqn_Rect b = Dqn_RectInitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); - Dqn_Rect ab = Dqn_RectIntersection(a, b); + Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2(-50, -50), Dqn_V2(100, 100)); + Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); + Dqn_Rect ab = Dqn_Rect_Intersection(a, b); DQN_TESTER_ASSERTF(&test, ab.min.x == 0 && ab.min.y == 0 && ab.max.x == 50 && ab.max.y == 50, @@ -850,9 +850,9 @@ Dqn_Tester Dqn_Test_Rect() { Dqn_TesterBegin(&test, "B's max intersects A"); - Dqn_Rect a = Dqn_RectInitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); - Dqn_Rect b = Dqn_RectInitFromPosAndSize(Dqn_V2(-50, -50), Dqn_V2(100, 100)); - Dqn_Rect ab = Dqn_RectIntersection(a, b); + Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); + Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2(-50, -50), Dqn_V2(100, 100)); + Dqn_Rect ab = Dqn_Rect_Intersection(a, b); DQN_TESTER_ASSERTF(&test, ab.min.x == 0 && ab.min.y == 0 && ab.max.x == 50 && ab.max.y == 50, @@ -867,9 +867,9 @@ Dqn_Tester Dqn_Test_Rect() { Dqn_TesterBegin(&test, "B contains A"); - Dqn_Rect a = Dqn_RectInitFromPosAndSize(Dqn_V2(25, 25), Dqn_V2( 25, 25)); - Dqn_Rect b = Dqn_RectInitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); - Dqn_Rect ab = Dqn_RectIntersection(a, b); + Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2(25, 25), Dqn_V2( 25, 25)); + Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); + Dqn_Rect ab = Dqn_Rect_Intersection(a, b); DQN_TESTER_ASSERTF(&test, ab.min.x == 25 && ab.min.y == 25 && ab.max.x == 50 && ab.max.y == 50, @@ -883,9 +883,9 @@ Dqn_Tester Dqn_Test_Rect() { Dqn_TesterBegin(&test, "A contains B"); - Dqn_Rect a = Dqn_RectInitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); - Dqn_Rect b = Dqn_RectInitFromPosAndSize(Dqn_V2(25, 25), Dqn_V2( 25, 25)); - Dqn_Rect ab = Dqn_RectIntersection(a, b); + Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2( 0, 0), Dqn_V2(100, 100)); + Dqn_Rect b = Dqn_Rect_InitFromPosAndSize(Dqn_V2(25, 25), Dqn_V2( 25, 25)); + Dqn_Rect ab = Dqn_Rect_Intersection(a, b); DQN_TESTER_ASSERTF(&test, ab.min.x == 25 && ab.min.y == 25 && ab.max.x == 50 && ab.max.y == 50, @@ -899,9 +899,9 @@ Dqn_Tester Dqn_Test_Rect() { Dqn_TesterBegin(&test, "A equals B"); - Dqn_Rect a = Dqn_RectInitFromPosAndSize(Dqn_V2(0, 0), Dqn_V2(100, 100)); + Dqn_Rect a = Dqn_Rect_InitFromPosAndSize(Dqn_V2(0, 0), Dqn_V2(100, 100)); Dqn_Rect b = a; - Dqn_Rect ab = Dqn_RectIntersection(a, b); + Dqn_Rect ab = Dqn_Rect_Intersection(a, b); DQN_TESTER_ASSERTF(&test, ab.min.x == 0 && ab.min.y == 0 && ab.max.x == 100 && ab.max.y == 100, @@ -921,31 +921,31 @@ Dqn_Tester Dqn_Test_Rect() Dqn_Tester Dqn_Test_PerfCounter() { Dqn_Tester test = {}; - DQN_TESTER_BEGIN_GROUP("Dqn_PerfCounter"); + DQN_TESTER_BEGIN_GROUP("Dqn_Perf_Counter"); { - Dqn_TesterBegin(&test, "Dqn_PerfCounterNow"); - Dqn_u64 result = Dqn_PerfCounterNow(); + Dqn_TesterBegin(&test, "Dqn_Perf_CounterNow"); + uint64_t result = Dqn_Perf_CounterNow(); DQN_TESTER_ASSERT(&test, result != 0); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Consecutive ticks are ordered"); - Dqn_u64 a = Dqn_PerfCounterNow(); - Dqn_u64 b = Dqn_PerfCounterNow(); + uint64_t a = Dqn_Perf_CounterNow(); + uint64_t b = Dqn_Perf_CounterNow(); DQN_TESTER_ASSERTF(&test, b >= a, "a: %zu, b: %zu", a, b); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Ticks to time are a correct order of magnitude"); - Dqn_u64 a = Dqn_PerfCounterNow(); - Dqn_u64 b = Dqn_PerfCounterNow(); + uint64_t a = Dqn_Perf_CounterNow(); + uint64_t b = Dqn_Perf_CounterNow(); - Dqn_f64 s = Dqn_PerfCounterS(a, b); - Dqn_f64 ms = Dqn_PerfCounterMs(a, b); - Dqn_f64 micro_s = Dqn_PerfCounterMicroS(a, b); - Dqn_f64 ns = Dqn_PerfCounterNs(a, b); + Dqn_f64 s = Dqn_Perf_CounterS(a, b); + Dqn_f64 ms = Dqn_Perf_CounterMs(a, b); + Dqn_f64 micro_s = Dqn_Perf_CounterMicroS(a, b); + Dqn_f64 ns = Dqn_Perf_CounterNs(a, b); DQN_TESTER_ASSERTF(&test, s <= ms, "s: %f, ms: %f", s, ms); DQN_TESTER_ASSERTF(&test, ms <= micro_s, "ms: %f, micro_s: %f", ms, micro_s); DQN_TESTER_ASSERTF(&test, micro_s <= ns, "micro_s: %f, ns: %f", micro_s, ns); @@ -958,10 +958,10 @@ Dqn_Tester Dqn_Test_PerfCounter() Dqn_Tester Dqn_Test_OS() { Dqn_Tester test = {}; - DQN_TESTER_BEGIN_GROUP("Dqn_OS"); + DQN_TESTER_BEGIN_GROUP("Dqn_OS_"); { Dqn_TesterBegin(&test, "Generate secure RNG bytes with nullptr"); - Dqn_b32 result = Dqn_OSSecureRNGBytes(nullptr, 1); + Dqn_b32 result = Dqn_OS_SecureRNGBytes(nullptr, 1); DQN_TESTER_ASSERT(&test, result == false); Dqn_TesterEnd(&test); } @@ -970,9 +970,9 @@ Dqn_Tester Dqn_Test_OS() Dqn_TesterBegin(&test, "Generate secure RNG 32 bytes"); char const ZERO[32] = {}; char buf[32] = {}; - Dqn_b32 result = Dqn_OSSecureRNGBytes(buf, Dqn_ArrayCountI(buf)); + Dqn_b32 result = Dqn_OS_SecureRNGBytes(buf, Dqn_CArray_CountI(buf)); DQN_TESTER_ASSERT(&test, result); - DQN_TESTER_ASSERT(&test, DQN_MEMCMP(buf, ZERO, Dqn_ArrayCount(buf)) != 0); + DQN_TESTER_ASSERT(&test, DQN_MEMCMP(buf, ZERO, Dqn_CArray_Count(buf)) != 0); Dqn_TesterEnd(&test); } @@ -980,7 +980,7 @@ Dqn_Tester Dqn_Test_OS() Dqn_TesterBegin(&test, "Generate secure RNG 0 bytes"); char buf[32] = {}; buf[0] = 'Z'; - Dqn_b32 result = Dqn_OSSecureRNGBytes(buf, 0); + Dqn_b32 result = Dqn_OS_SecureRNGBytes(buf, 0); DQN_TESTER_ASSERT(&test, result); DQN_TESTER_ASSERT(&test, buf[0] == 'Z'); Dqn_TesterEnd(&test); @@ -989,10 +989,10 @@ Dqn_Tester Dqn_Test_OS() { Dqn_TesterBegin(&test, "Query executable directory"); Dqn_Arena arena = {}; - Dqn_String8 result = Dqn_OSEXEDir(Dqn_ArenaAllocator(&arena)); - DQN_TESTER_ASSERT(&test, Dqn_String8IsValid(result)); - DQN_TESTER_ASSERTF(&test, Dqn_FsDirExists(result), "result(%zu): %.*s", result.size, DQN_STRING_FMT(result)); - Dqn_ArenaFree(&arena, Dqn_ZeroMem_No); + Dqn_String8 result = Dqn_OS_EXEDir(Dqn_Arena_Allocator(&arena)); + DQN_TESTER_ASSERT(&test, Dqn_String8_IsValid(result)); + DQN_TESTER_ASSERTF(&test, Dqn_Fs_DirExists(result), "result(%zu): %.*s", result.size, DQN_STRING_FMT(result)); + Dqn_Arena_Free(&arena, Dqn_ZeroMem_No); Dqn_TesterEnd(&test); } DQN_TESTER_END_GROUP(&test); @@ -1004,145 +1004,145 @@ Dqn_Tester Dqn_Test_Str() Dqn_Tester test = {}; DQN_TESTER_BEGIN_GROUP("Dqn_Str"); // --------------------------------------------------------------------------------------------- - // NOTE: Dqn_CStringToI64 + // NOTE: Dqn_CString8_ToI64 // --------------------------------------------------------------------------------------------- { Dqn_TesterBegin(&test, "To I64: Convert nullptr"); - Dqn_i64 result = Dqn_CStringToI64(nullptr); + int64_t result = Dqn_CString8_ToI64(nullptr); DQN_TESTER_ASSERT(&test, result == 0); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To I64: Convert empty string"); - Dqn_i64 result = Dqn_CStringToI64(""); + int64_t result = Dqn_CString8_ToI64(""); DQN_TESTER_ASSERT(&test, result == 0); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To I64: Convert \"1\""); - Dqn_i64 result = Dqn_CStringToI64("1"); + int64_t result = Dqn_CString8_ToI64("1"); DQN_TESTER_ASSERT(&test, result == 1); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To I64: Convert \"-0\""); - Dqn_i64 result = Dqn_CStringToI64("-0"); + int64_t result = Dqn_CString8_ToI64("-0"); DQN_TESTER_ASSERT(&test, result == 0); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To I64: Convert \"-1\""); - Dqn_i64 result = Dqn_CStringToI64("-1"); + int64_t result = Dqn_CString8_ToI64("-1"); DQN_TESTER_ASSERT(&test, result == -1); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To I64: Convert \"1.2\""); - Dqn_i64 result = Dqn_CStringToI64("1.2"); + int64_t result = Dqn_CString8_ToI64("1.2"); DQN_TESTER_ASSERT(&test, result == 1); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To I64: Convert \"1,234\""); - Dqn_i64 result = Dqn_CStringToI64("1,234"); + int64_t result = Dqn_CString8_ToI64("1,234"); DQN_TESTER_ASSERT(&test, result == 1234); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To I64: Convert \"1,2\""); - Dqn_i64 result = Dqn_CStringToI64("1,2"); + int64_t result = Dqn_CString8_ToI64("1,2"); DQN_TESTER_ASSERT(&test, result == 12); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To I64: Convert \"12a3\""); - Dqn_i64 result = Dqn_CStringToI64("12a3"); + int64_t result = Dqn_CString8_ToI64("12a3"); DQN_TESTER_ASSERT(&test, result == 12); Dqn_TesterEnd(&test); } // --------------------------------------------------------------------------------------------- - // NOTE: Dqn_CStringToU64 + // NOTE: Dqn_CString8_ToU64 // --------------------------------------------------------------------------------------------- { Dqn_TesterBegin(&test, "To U64: Convert nullptr"); - Dqn_u64 result = Dqn_CStringToU64(nullptr); + uint64_t result = Dqn_CString8_ToU64(nullptr); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To U64: Convert empty string"); - Dqn_u64 result = Dqn_CStringToU64(""); + uint64_t result = Dqn_CString8_ToU64(""); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To U64: Convert \"1\""); - Dqn_u64 result = Dqn_CStringToU64("1"); + uint64_t result = Dqn_CString8_ToU64("1"); DQN_TESTER_ASSERTF(&test, result == 1, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To U64: Convert \"-0\""); - Dqn_u64 result = Dqn_CStringToU64("-0"); + uint64_t result = Dqn_CString8_ToU64("-0"); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To U64: Convert \"-1\""); - Dqn_u64 result = Dqn_CStringToU64("-1"); + uint64_t result = Dqn_CString8_ToU64("-1"); DQN_TESTER_ASSERTF(&test, result == 0, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To U64: Convert \"1.2\""); - Dqn_u64 result = Dqn_CStringToU64("1.2"); + uint64_t result = Dqn_CString8_ToU64("1.2"); DQN_TESTER_ASSERTF(&test, result == 1, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To U64: Convert \"1,234\""); - Dqn_u64 result = Dqn_CStringToU64("1,234"); + uint64_t result = Dqn_CString8_ToU64("1,234"); DQN_TESTER_ASSERTF(&test, result == 1234, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To U64: Convert \"1,2\""); - Dqn_u64 result = Dqn_CStringToU64("1,2"); + uint64_t result = Dqn_CString8_ToU64("1,2"); DQN_TESTER_ASSERTF(&test, result == 12, "result: %zu", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "To U64: Convert \"12a3\""); - Dqn_u64 result = Dqn_CStringToU64("12a3"); + uint64_t result = Dqn_CString8_ToU64("12a3"); DQN_TESTER_ASSERTF(&test, result == 12, "result: %zu", result); Dqn_TesterEnd(&test); } // --------------------------------------------------------------------------------------------- - // NOTE: Dqn_CStringFind + // NOTE: Dqn_CString8_Find // --------------------------------------------------------------------------------------------- { Dqn_TesterBegin(&test, "Find: String (char) is not in buffer"); char const buf[] = "836a35becd4e74b66a0d6844d51f1a63018c7ebc44cf7e109e8e4bba57eefb55"; char const find[] = "2"; - char const *result = Dqn_CStringFind(buf, find, Dqn_CharCountI(buf), Dqn_CharCountI(find)); + char const *result = Dqn_CString8_Find(buf, find, Dqn_CString8_ArrayCountI(buf), Dqn_CString8_ArrayCountI(find)); DQN_TESTER_ASSERT(&test, result == nullptr); Dqn_TesterEnd(&test); } @@ -1151,21 +1151,21 @@ Dqn_Tester Dqn_Test_Str() Dqn_TesterBegin(&test, "Find: String (char) is in buffer"); char const buf[] = "836a35becd4e74b66a0d6844d51f1a63018c7ebc44cf7e109e8e4bba57eefb55"; char const find[] = "6"; - char const *result = Dqn_CStringFind(buf, find, Dqn_CharCountI(buf), Dqn_CharCountI(find)); + char const *result = Dqn_CString8_Find(buf, find, Dqn_CString8_ArrayCountI(buf), Dqn_CString8_ArrayCountI(find)); DQN_TESTER_ASSERT(&test, result != nullptr); DQN_TESTER_ASSERT(&test, result[0] == '6' && result[1] == 'a'); Dqn_TesterEnd(&test); } - // NOTE: Dqn_CStringFileNameFromPath + // NOTE: Dqn_CString8_FileNameFromPath // --------------------------------------------------------------------------------------------- { Dqn_TesterBegin(&test, "File name from Windows path"); Dqn_isize file_name_size = 0; char const buf[] = "C:\\ABC\\test.exe"; - char const *result = Dqn_CStringFileNameFromPath(buf, Dqn_CharCountI(buf), &file_name_size); + char const *result = Dqn_CString8_FileNameFromPath(buf, Dqn_CString8_ArrayCountI(buf), &file_name_size); DQN_TESTER_ASSERTF(&test, file_name_size == 8, "size: %I64d", file_name_size); - DQN_TESTER_ASSERTF(&test, Dqn_String8Eq(Dqn_String8Init(result, file_name_size), DQN_STRING8("test.exe")), "%.*s", DQN_CAST(int)file_name_size, result); + DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(Dqn_String8_Init(result, file_name_size), DQN_STRING8("test.exe")), "%.*s", DQN_CAST(int)file_name_size, result); Dqn_TesterEnd(&test); } @@ -1173,22 +1173,22 @@ Dqn_Tester Dqn_Test_Str() Dqn_TesterBegin(&test, "File name from Linux path"); Dqn_isize file_name_size = 0; char const buf[] = "/ABC/test.exe"; - char const *result = Dqn_CStringFileNameFromPath(buf, Dqn_CharCountI(buf), &file_name_size); + char const *result = Dqn_CString8_FileNameFromPath(buf, Dqn_CString8_ArrayCountI(buf), &file_name_size); DQN_TESTER_ASSERTF(&test, file_name_size == 8, "size: %I64d", file_name_size); - DQN_TESTER_ASSERTF(&test, Dqn_String8Eq(Dqn_String8Init(result, file_name_size), DQN_STRING8("test.exe")), "%.*s", (int)file_name_size, result); + DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(Dqn_String8_Init(result, file_name_size), DQN_STRING8("test.exe")), "%.*s", (int)file_name_size, result); Dqn_TesterEnd(&test); } - // NOTE: Dqn_CStringTrimPrefix + // NOTE: Dqn_CString8_TrimPrefix // --------------------------------------------------------------------------------------------- { Dqn_TesterBegin(&test, "Trim prefix"); char const prefix[] = "@123"; char const buf[] = "@123string"; Dqn_isize trimmed_size = 0; - char const *result = Dqn_CStringTrimPrefix(buf, Dqn_CharCountI(buf), prefix, Dqn_CharCountI(prefix), &trimmed_size); + char const *result = Dqn_CString8_TrimPrefix(buf, Dqn_CString8_ArrayCountI(buf), prefix, Dqn_CString8_ArrayCountI(prefix), &trimmed_size); DQN_TESTER_ASSERTF(&test, trimmed_size == 6, "size: %I64d", trimmed_size); - DQN_TESTER_ASSERTF(&test, Dqn_String8Eq(Dqn_String8Init(result, trimmed_size), DQN_STRING8("string")), "%.*s", (int)trimmed_size, result); + DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(Dqn_String8_Init(result, trimmed_size), DQN_STRING8("string")), "%.*s", (int)trimmed_size, result); Dqn_TesterEnd(&test); } @@ -1196,31 +1196,31 @@ Dqn_Tester Dqn_Test_Str() Dqn_TesterBegin(&test, "Trim prefix, nullptr trimmed size"); char const prefix[] = "@123"; char const buf[] = "@123string"; - char const *result = Dqn_CStringTrimPrefix(buf, Dqn_CharCountI(buf), prefix, Dqn_CharCountI(prefix), nullptr); + char const *result = Dqn_CString8_TrimPrefix(buf, Dqn_CString8_ArrayCountI(buf), prefix, Dqn_CString8_ArrayCountI(prefix), nullptr); DQN_TESTER_ASSERT(&test, result); Dqn_TesterEnd(&test); } - // NOTE: Dqn_CStringIsAllDigits + // NOTE: Dqn_CString8_IsAllDigits // --------------------------------------------------------------------------------------------- { Dqn_TesterBegin(&test, "Is all digits fails on non-digit string"); char const buf[] = "@123string"; - Dqn_b32 result = Dqn_CStringIsAllDigits(buf, Dqn_CharCountI(buf)); + Dqn_b32 result = Dqn_CString8_IsAllDigits(buf, Dqn_CString8_ArrayCountI(buf)); DQN_TESTER_ASSERT(&test, result == false); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Is all digits fails on nullptr"); - Dqn_b32 result = Dqn_CStringIsAllDigits(nullptr, 0); + Dqn_b32 result = Dqn_CString8_IsAllDigits(nullptr, 0); DQN_TESTER_ASSERT(&test, result == false); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Is all digits fails on nullptr w/ size"); - Dqn_b32 result = Dqn_CStringIsAllDigits(nullptr, 1); + Dqn_b32 result = Dqn_CString8_IsAllDigits(nullptr, 1); DQN_TESTER_ASSERT(&test, result == false); Dqn_TesterEnd(&test); } @@ -1228,7 +1228,7 @@ Dqn_Tester Dqn_Test_Str() { Dqn_TesterBegin(&test, "Is all digits fails on 0 size w/ string"); char const buf[] = "@123string"; - Dqn_b32 result = Dqn_CStringIsAllDigits(buf, 0); + Dqn_b32 result = Dqn_CString8_IsAllDigits(buf, 0); DQN_TESTER_ASSERT(&test, result == false); Dqn_TesterEnd(&test); } @@ -1236,7 +1236,7 @@ Dqn_Tester Dqn_Test_Str() { Dqn_TesterBegin(&test, "Is all digits success"); char const buf[] = "23"; - Dqn_b32 result = Dqn_CStringIsAllDigits(buf, Dqn_CharCountI(buf)); + Dqn_b32 result = Dqn_CString8_IsAllDigits(buf, Dqn_CString8_ArrayCountI(buf)); DQN_TESTER_ASSERT(&test, DQN_CAST(bool)result == true); Dqn_TesterEnd(&test); } @@ -1244,7 +1244,7 @@ Dqn_Tester Dqn_Test_Str() { Dqn_TesterBegin(&test, "Is all digits fails on whitespace"); char const buf[] = "23 "; - Dqn_b32 result = Dqn_CStringIsAllDigits(buf, Dqn_CharCountI(buf)); + Dqn_b32 result = Dqn_CString8_IsAllDigits(buf, Dqn_CString8_ArrayCountI(buf)); DQN_TESTER_ASSERT(&test, DQN_CAST(bool)result == false); Dqn_TesterEnd(&test); } @@ -1268,12 +1268,12 @@ Dqn_Tester Dqn_Test_String() { Dqn_TesterBegin(&test, "Initialise with format string"); Dqn_Arena arena = {}; - Dqn_String8 string = Dqn_String8Fmt(Dqn_ArenaAllocator(&arena), "%s", "AB"); + Dqn_String8 string = Dqn_String8_Fmt(Dqn_Arena_Allocator(&arena), "%s", "AB"); DQN_TESTER_ASSERTF(&test, string.size == 2, "size: %I64d", string.size); DQN_TESTER_ASSERTF(&test, string.data[0] == 'A', "string[0]: %c", string.data[0]); DQN_TESTER_ASSERTF(&test, string.data[1] == 'B', "string[1]: %c", string.data[1]); DQN_TESTER_ASSERTF(&test, string.data[2] == 0, "string[2]: %c", string.data[2]); - Dqn_ArenaFree(&arena, false /*clear_mem*/); + Dqn_Arena_Free(&arena, false /*clear_mem*/); Dqn_TesterEnd(&test); } @@ -1281,18 +1281,18 @@ Dqn_Tester Dqn_Test_String() Dqn_TesterBegin(&test, "Copy string"); Dqn_Arena arena = {}; Dqn_String8 string = DQN_STRING8("AB"); - Dqn_String8 copy = Dqn_String8Copy(Dqn_ArenaAllocator(&arena), string); + Dqn_String8 copy = Dqn_String8_Copy(Dqn_Arena_Allocator(&arena), string); DQN_TESTER_ASSERTF(&test, copy.size == 2, "size: %I64d", copy.size); DQN_TESTER_ASSERTF(&test, copy.data[0] == 'A', "copy[0]: %c", copy.data[0]); DQN_TESTER_ASSERTF(&test, copy.data[1] == 'B', "copy[1]: %c", copy.data[1]); DQN_TESTER_ASSERTF(&test, copy.data[2] == 0, "copy[2]: %c", copy.data[2]); - Dqn_ArenaFree(&arena, false /*clear_mem*/); + Dqn_Arena_Free(&arena, false /*clear_mem*/); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Trim whitespace around string"); - Dqn_String8 string = Dqn_String8TrimWhitespaceAround(DQN_STRING8(" AB ")); + Dqn_String8 string = Dqn_String8_TrimWhitespaceAround(DQN_STRING8(" AB ")); DQN_TESTER_ASSERTF(&test, string.size == 2, "size: %I64d", string.size); DQN_TESTER_ASSERTF(&test, string.data[0] == 'A', "string[0]: %c", string.data[0]); DQN_TESTER_ASSERTF(&test, string.data[1] == 'B', "string[1]: %c", string.data[1]); @@ -1303,67 +1303,67 @@ Dqn_Tester Dqn_Test_String() { Dqn_TesterBegin(&test, "Allocate string from arena"); Dqn_Arena arena = {}; - Dqn_String8 string = Dqn_String8Allocate(Dqn_ArenaAllocator(&arena), 2, Dqn_ZeroMem_No); + Dqn_String8 string = Dqn_String8_Allocate(Dqn_Arena_Allocator(&arena), 2, Dqn_ZeroMem_No); DQN_TESTER_ASSERTF(&test, string.size == 2, "size: %I64d", string.size); - Dqn_ArenaFree(&arena, false /*clear_mem*/); + Dqn_Arena_Free(&arena, false /*clear_mem*/); Dqn_TesterEnd(&test); } - // NOTE: Dqn_CStringTrim[Prefix/Suffix] + // NOTE: Dqn_CString8_Trim[Prefix/Suffix] // --------------------------------------------------------------------------------------------- { Dqn_TesterBegin(&test, "Trim prefix with matching prefix"); Dqn_String8 input = DQN_STRING8("nft/abc"); - Dqn_String8 result = Dqn_String8TrimPrefix(input, DQN_STRING8("nft/")); - DQN_TESTER_ASSERTF(&test, Dqn_String8Eq(result, DQN_STRING8("abc")), "%.*s", DQN_STRING_FMT(result)); + Dqn_String8 result = Dqn_String8_TrimPrefix(input, DQN_STRING8("nft/")); + DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(result, DQN_STRING8("abc")), "%.*s", DQN_STRING_FMT(result)); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Trim prefix with non matching prefix"); Dqn_String8 input = DQN_STRING8("nft/abc"); - Dqn_String8 result = Dqn_String8TrimPrefix(input, DQN_STRING8(" ft/")); - DQN_TESTER_ASSERTF(&test, Dqn_String8Eq(result, input), "%.*s", DQN_STRING_FMT(result)); + Dqn_String8 result = Dqn_String8_TrimPrefix(input, DQN_STRING8(" ft/")); + DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(result, input), "%.*s", DQN_STRING_FMT(result)); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Trim suffix with matching suffix"); Dqn_String8 input = DQN_STRING8("nft/abc"); - Dqn_String8 result = Dqn_String8TrimSuffix(input, DQN_STRING8("abc")); - DQN_TESTER_ASSERTF(&test, Dqn_String8Eq(result, DQN_STRING8("nft/")), "%.*s", DQN_STRING_FMT(result)); + Dqn_String8 result = Dqn_String8_TrimSuffix(input, DQN_STRING8("abc")); + DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(result, DQN_STRING8("nft/")), "%.*s", DQN_STRING_FMT(result)); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Trim suffix with non matching suffix"); Dqn_String8 input = DQN_STRING8("nft/abc"); - Dqn_String8 result = Dqn_String8TrimSuffix(input, DQN_STRING8("ab")); - DQN_TESTER_ASSERTF(&test, Dqn_String8Eq(result, input), "%.*s", DQN_STRING_FMT(result)); + Dqn_String8 result = Dqn_String8_TrimSuffix(input, DQN_STRING8("ab")); + DQN_TESTER_ASSERTF(&test, Dqn_String8_Eq(result, input), "%.*s", DQN_STRING_FMT(result)); Dqn_TesterEnd(&test); } // --------------------------------------------------------------------------------------------- - // NOTE: Dqn_String8IsAllDigits + // NOTE: Dqn_String8_IsAllDigits // --------------------------------------------------------------------------------------------- { Dqn_TesterBegin(&test, "Is all digits fails on non-digit string"); - Dqn_b32 result = Dqn_String8IsAllDigits(DQN_STRING8("@123string")); + Dqn_b32 result = Dqn_String8_IsAllDigits(DQN_STRING8("@123string")); DQN_TESTER_ASSERT(&test, result == false); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Is all digits fails on nullptr"); - Dqn_b32 result = Dqn_String8IsAllDigits(Dqn_String8Init(nullptr, 0)); + Dqn_b32 result = Dqn_String8_IsAllDigits(Dqn_String8_Init(nullptr, 0)); DQN_TESTER_ASSERT(&test, result == false); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Is all digits fails on nullptr w/ size"); - Dqn_b32 result = Dqn_String8IsAllDigits(Dqn_String8Init(nullptr, 1)); + Dqn_b32 result = Dqn_String8_IsAllDigits(Dqn_String8_Init(nullptr, 1)); DQN_TESTER_ASSERT(&test, result == false); Dqn_TesterEnd(&test); } @@ -1371,21 +1371,21 @@ Dqn_Tester Dqn_Test_String() { Dqn_TesterBegin(&test, "Is all digits fails on string w/ 0 size"); char const buf[] = "@123string"; - Dqn_b32 result = Dqn_String8IsAllDigits(Dqn_String8Init(buf, 0)); + Dqn_b32 result = Dqn_String8_IsAllDigits(Dqn_String8_Init(buf, 0)); DQN_TESTER_ASSERT(&test, result == false); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Is all digits success"); - Dqn_b32 result = Dqn_String8IsAllDigits(DQN_STRING8("23")); + Dqn_b32 result = Dqn_String8_IsAllDigits(DQN_STRING8("23")); DQN_TESTER_ASSERT(&test, DQN_CAST(bool)result == true); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "Is all digits fails on whitespace"); - Dqn_b32 result = Dqn_String8IsAllDigits(DQN_STRING8("23 ")); + Dqn_b32 result = Dqn_String8_IsAllDigits(DQN_STRING8("23 ")); DQN_TESTER_ASSERT(&test, DQN_CAST(bool)result == false); Dqn_TesterEnd(&test); } @@ -1403,8 +1403,8 @@ Dqn_Tester Dqn_Test_TicketMutex() // written correctly. Dqn_TesterBegin(&test, "Ticket mutex start and stop"); Dqn_TicketMutex mutex = {}; - Dqn_TicketMutexBegin(&mutex); - Dqn_TicketMutexEnd(&mutex); + Dqn_TicketMutex_Begin(&mutex); + Dqn_TicketMutex_End(&mutex); DQN_TESTER_ASSERT(&test, mutex.ticket == mutex.serving); Dqn_TesterEnd(&test); } @@ -1412,15 +1412,15 @@ Dqn_Tester Dqn_Test_TicketMutex() { Dqn_TesterBegin(&test, "Ticket mutex start and stop w/ advanced API"); Dqn_TicketMutex mutex = {}; - unsigned int ticket_a = Dqn_TicketMutexMakeTicket(&mutex); - unsigned int ticket_b = Dqn_TicketMutexMakeTicket(&mutex); - DQN_TESTER_ASSERT(&test, DQN_CAST(bool)Dqn_TicketMutexCanLock(&mutex, ticket_b) == false); - DQN_TESTER_ASSERT(&test, DQN_CAST(bool)Dqn_TicketMutexCanLock(&mutex, ticket_a) == true); + unsigned int ticket_a = Dqn_TicketMutex_MakeTicket(&mutex); + unsigned int ticket_b = Dqn_TicketMutex_MakeTicket(&mutex); + DQN_TESTER_ASSERT(&test, DQN_CAST(bool)Dqn_TicketMutex_CanLock(&mutex, ticket_b) == false); + DQN_TESTER_ASSERT(&test, DQN_CAST(bool)Dqn_TicketMutex_CanLock(&mutex, ticket_a) == true); - Dqn_TicketMutexBeginTicket(&mutex, ticket_a); - Dqn_TicketMutexEnd(&mutex); - Dqn_TicketMutexBeginTicket(&mutex, ticket_b); - Dqn_TicketMutexEnd(&mutex); + Dqn_TicketMutex_BeginTicket(&mutex, ticket_a); + Dqn_TicketMutex_End(&mutex); + Dqn_TicketMutex_BeginTicket(&mutex, ticket_b); + Dqn_TicketMutex_End(&mutex); DQN_TESTER_ASSERT(&test, mutex.ticket == mutex.serving); DQN_TESTER_ASSERT(&test, mutex.ticket == ticket_b + 1); @@ -1437,28 +1437,28 @@ Dqn_Tester Dqn_Test_Win() DQN_TESTER_BEGIN_GROUP("Dqn_Win"); { Dqn_TesterBegin(&test, "String8 to String16 size required"); - int result = Dqn_WinString8ToCString16(DQN_STRING8("a"), nullptr, 0); + int result = Dqn_Win_String8ToCString16(DQN_STRING8("a"), nullptr, 0); DQN_TESTER_ASSERTF(&test, result == 2, "Size returned: %d. This size should include the null-terminator", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "String16 to String8 size required"); - int result = Dqn_WinString16ToCString8(DQN_STRING16(L"a"), nullptr, 0); + int result = Dqn_Win_String16ToCString8(DQN_STRING16(L"a"), nullptr, 0); DQN_TESTER_ASSERTF(&test, result == 2, "Size returned: %d. This size should include the null-terminator", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "String8 to String16 size required"); - int result = Dqn_WinString8ToCString16(DQN_STRING8("String"), nullptr, 0); + int result = Dqn_Win_String8ToCString16(DQN_STRING8("String"), nullptr, 0); DQN_TESTER_ASSERTF(&test, result == 7, "Size returned: %d. This size should include the null-terminator", result); Dqn_TesterEnd(&test); } { Dqn_TesterBegin(&test, "String16 to String8 size required"); - int result = Dqn_WinString16ToCString8(DQN_STRING16(L"String"), nullptr, 0); + int result = Dqn_Win_String16ToCString8(DQN_STRING16(L"String"), nullptr, 0); DQN_TESTER_ASSERTF(&test, result == 7, "Size returned: %d. This size should include the null-terminator", result); Dqn_TesterEnd(&test); } @@ -1467,19 +1467,19 @@ Dqn_Tester Dqn_Test_Win() Dqn_TesterBegin(&test, "String8 to String16"); Dqn_Arena arena = {}; Dqn_String8 const INPUT = DQN_STRING8("String"); - int size_required = Dqn_WinString8ToCString16(INPUT, nullptr, 0); - wchar_t *string = Dqn_ArenaNewArray(&arena, wchar_t, size_required, Dqn_ZeroMem_No); + int size_required = Dqn_Win_String8ToCString16(INPUT, nullptr, 0); + wchar_t *string = Dqn_Arena_NewArray(&arena, wchar_t, size_required, Dqn_ZeroMem_No); // Fill the string with error sentinels, which ensures the string is zero terminated DQN_MEMSET(string, 'Z', size_required); - int size_returned = Dqn_WinString8ToCString16(INPUT, string, size_required); + int size_returned = Dqn_Win_String8ToCString16(INPUT, string, size_required); wchar_t const EXPECTED[] = {L'S', L't', L'r', L'i', L'n', L'g', 0}; DQN_TESTER_ASSERTF(&test, size_required == size_returned, "string_size: %d, result: %d", size_required, size_returned); - DQN_TESTER_ASSERTF(&test, size_returned == Dqn_ArrayCount(EXPECTED), "string_size: %d, expected: %zu", size_returned, Dqn_ArrayCount(EXPECTED)); + DQN_TESTER_ASSERTF(&test, size_returned == Dqn_CArray_Count(EXPECTED), "string_size: %d, expected: %zu", size_returned, Dqn_CArray_Count(EXPECTED)); DQN_TESTER_ASSERT(&test, DQN_MEMCMP(EXPECTED, string, sizeof(EXPECTED)) == 0); - Dqn_ArenaFree(&arena, false /*clear_mem*/); + Dqn_Arena_Free(&arena, false /*clear_mem*/); Dqn_TesterEnd(&test); } @@ -1487,19 +1487,19 @@ Dqn_Tester Dqn_Test_Win() Dqn_TesterBegin(&test, "String16 to String8: No null-terminate"); Dqn_Arena arena = {}; Dqn_String16 INPUT = DQN_STRING16(L"String"); - int size_required = Dqn_WinString16ToCString8(INPUT, nullptr, 0); - char *string = Dqn_ArenaNewArray(&arena, char, size_required, Dqn_ZeroMem_No); + int size_required = Dqn_Win_String16ToCString8(INPUT, nullptr, 0); + char *string = Dqn_Arena_NewArray(&arena, char, size_required, Dqn_ZeroMem_No); // Fill the string with error sentinels, which ensures the string is zero terminated DQN_MEMSET(string, 'Z', size_required); - int size_returned = Dqn_WinString16ToCString8(INPUT, string, size_required); + int size_returned = Dqn_Win_String16ToCString8(INPUT, string, size_required); char const EXPECTED[] = {'S', 't', 'r', 'i', 'n', 'g', 0}; DQN_TESTER_ASSERTF(&test, size_required == size_returned, "string_size: %d, result: %d", size_required, size_returned); - DQN_TESTER_ASSERTF(&test, size_returned == Dqn_ArrayCount(EXPECTED), "string_size: %d, expected: %zu", size_returned, Dqn_ArrayCount(EXPECTED)); + DQN_TESTER_ASSERTF(&test, size_returned == Dqn_CArray_Count(EXPECTED), "string_size: %d, expected: %zu", size_returned, Dqn_CArray_Count(EXPECTED)); DQN_TESTER_ASSERT(&test, DQN_MEMCMP(EXPECTED, string, sizeof(EXPECTED)) == 0); - Dqn_ArenaFree(&arena, false /*clear_mem*/); + Dqn_Arena_Free(&arena, false /*clear_mem*/); Dqn_TesterEnd(&test); } DQN_TESTER_END_GROUP(&test); @@ -1536,8 +1536,8 @@ Dqn_String8 const DQN_TESTS__HASH_STRING[] = void Dqn_Test__KeccakDispatch(Dqn_Tester *test, int hash_type, Dqn_String8 input) { #if defined(DQN_KECCAK_H) - Dqn_ThreadScratch scratch = Dqn_ThreadGetScratch(); - Dqn_String8 input_hex = Dqn_HexBytesToHexStringArena(input.data, input.size, scratch.arena); + Dqn_ThreadTempArena scratch = Dqn_Thread_TempArena(); + Dqn_String8 input_hex = Dqn_Hex_BytesToHexStringArena(input.data, input.size, scratch.arena); switch(hash_type) { @@ -1710,12 +1710,12 @@ Dqn_Tester Dqn_Test_Keccak() for (int index = 0; index < 128; index++) { char src[4096] = {}; - Dqn_u32 src_size = pcg32_boundedrand_r(&rng, sizeof(src)); + uint32_t src_size = pcg32_boundedrand_r(&rng, sizeof(src)); for (int src_index = 0; src_index < src_size; src_index++) src[src_index] = pcg32_boundedrand_r(&rng, 255); - Dqn_String8 input = Dqn_String8Init(src, src_size); + Dqn_String8 input = Dqn_String8_Init(src, src_size); Dqn_Test__KeccakDispatch(&test, hash_type, input); } Dqn_TesterEnd(&test); diff --git a/dqn_tests_helpers.cpp b/dqn_tests_helpers.cpp index fa806ef..93f94f9 100644 --- a/dqn_tests_helpers.cpp +++ b/dqn_tests_helpers.cpp @@ -48,15 +48,14 @@ void Keccak(ui r, ui c, const u8 *in, u64 inLen, u8 sfx, u8 *out, u64 outLen) } -// ----------------------------------------------------------------------------- // PCG32 Random Number Generator // ----------------------------------------------------------------------------- // NOTE: https://github.com/imneme/pcg-c-basic struct pcg_state_setseq_64 { // Internals are *Private*. - Dqn_u64 state; // RNG state. All values are possible. - Dqn_u64 inc; // Controls which RNG sequence (stream) is + uint64_t state; // RNG state. All values are possible. + uint64_t inc; // Controls which RNG sequence (stream) is // selected. Must *always* be odd. }; typedef struct pcg_state_setseq_64 pcg32_random_t; @@ -64,12 +63,12 @@ typedef struct pcg_state_setseq_64 pcg32_random_t; // pcg32_random_r(rng) // Generate a uniformly distributed 32-bit random number -Dqn_u32 pcg32_random_r(pcg32_random_t* rng) +uint32_t pcg32_random_r(pcg32_random_t* rng) { - Dqn_u64 oldstate = rng->state; + uint64_t oldstate = rng->state; rng->state = oldstate * 6364136223846793005ULL + rng->inc; - Dqn_u32 xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u; - Dqn_u32 rot = oldstate >> 59u; + uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u; + uint32_t rot = oldstate >> 59u; return (xorshifted >> rot) | (xorshifted << ((-rot) & 31)); } @@ -77,7 +76,7 @@ Dqn_u32 pcg32_random_r(pcg32_random_t* rng) // Seed the rng. Specified in two parts, state initializer and a // sequence selection constant (a.k.a. stream id) -void pcg32_srandom_r(pcg32_random_t* rng, Dqn_u64 initstate, Dqn_u64 initseq) +void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initstate, uint64_t initseq) { rng->state = 0U; rng->inc = (initseq << 1u) | 1u; @@ -89,11 +88,11 @@ void pcg32_srandom_r(pcg32_random_t* rng, Dqn_u64 initstate, Dqn_u64 initseq) // pcg32_boundedrand_r(rng, bound): // Generate a uniformly distributed number, r, where 0 <= r < bound -Dqn_u32 pcg32_boundedrand_r(pcg32_random_t* rng, Dqn_u32 bound) +uint32_t pcg32_boundedrand_r(pcg32_random_t* rng, uint32_t bound) { - Dqn_u32 threshold = -bound % bound; + uint32_t threshold = -bound % bound; for (;;) { - Dqn_u32 r = pcg32_random_r(rng); + uint32_t r = pcg32_random_r(rng); if (r >= threshold) return r % bound; }