dqn: Add table of contents to each file

This commit is contained in:
doyle 2023-07-05 22:39:43 +10:00
parent 8ae369db0d
commit 580b8a6882
18 changed files with 165 additions and 243 deletions

View File

@ -1,7 +1,5 @@
#if !defined(DQN_NO_DSMAP) #if !defined(DQN_NO_DSMAP)
// ================================================================================================= // NOTE: [$DMAP] Dqn_DSMap =========================================================================
// [$DMAP] Dqn_DSMap | DQN_NO_DSMAP | Hashtable, 70% max load, PoT size, linear probe, chain repair
// =================================================================================================
DQN_API Dqn_DSMapKey Dqn_DSMap_KeyU64NoHash(uint64_t u64) DQN_API Dqn_DSMapKey Dqn_DSMap_KeyU64NoHash(uint64_t u64)
{ {
Dqn_DSMapKey result = {}; Dqn_DSMapKey result = {};
@ -31,6 +29,4 @@ DQN_API bool operator==(Dqn_DSMapKey lhs, Dqn_DSMapKey rhs)
bool result = Dqn_DSMap_KeyEquals(lhs, rhs); bool result = Dqn_DSMap_KeyEquals(lhs, rhs);
return result; return result;
} }
#endif // !defined(DQN_NO_DSMAP) #endif // !defined(DQN_NO_DSMAP)

View File

@ -1,8 +1,14 @@
// NOTE: Table Of Contents =========================================================================
// Index | Disable #define | Description
// =================================================================================================
// [$VARR] Dqn_VArray | DQN_NO_VARRAY | Array backed by virtual memory arena
// [$FARR] Dqn_FArray | DQN_NO_FARRAY | Fixed-size arrays
// [$DMAP] Dqn_DSMap | DQN_NO_DSMAP | Hashtable, 70% max load, PoT size, linear probe, chain repair
// [$LIST] Dqn_List | DQN_NO_LIST | Chunked linked lists, append only
// =================================================================================================
#if !defined(DQN_NO_VARRAY) #if !defined(DQN_NO_VARRAY)
// ================================================================================================= // NOTE: [$VARR] Dqn_VArray ========================================================================
// [$VARR] Dqn_VArray | DQN_NO_VARRAY | Array backed by virtual memory arena
// =================================================================================================
//
// An array that is backed by virtual memory by reserving addressing space and // An array that is backed by virtual memory by reserving addressing space and
// comitting pages as items are allocated in the array. This array never // comitting pages as items are allocated in the array. This array never
// reallocs, instead you should reserve the upper bound of the memory you will // reallocs, instead you should reserve the upper bound of the memory you will
@ -96,10 +102,7 @@ DQN_API template <typename T> void Dqn_VArray_Reserve (Dqn_VArray<
#endif // !defined(DQN_NO_VARRAY) #endif // !defined(DQN_NO_VARRAY)
#if !defined(DQN_NO_DSMAP) #if !defined(DQN_NO_DSMAP)
// ================================================================================================= // NOTE: [$DMAP] Dqn_DSMap =========================================================================
// [$DMAP] Dqn_DSMap | DQN_NO_DSMAP | Hashtable, 70% max load, PoT size, linear probe, chain repair
// =================================================================================================
//
// A hash table configured using the presets recommended by Demitri Spanos // A hash table configured using the presets recommended by Demitri Spanos
// from the Handmade Network (HMN), // from the Handmade Network (HMN),
// //
@ -298,10 +301,8 @@ DQN_API bool Dqn_DSMap_KeyEquals (Dqn_DS
DQN_API bool operator== (Dqn_DSMapKey lhs, Dqn_DSMapKey rhs); DQN_API bool operator== (Dqn_DSMapKey lhs, Dqn_DSMapKey rhs);
#endif // !defined(DQN_NO_DSMAP) #endif // !defined(DQN_NO_DSMAP)
// =================================================================================================
// [$FARR] Dqn_FArray | DQN_NO_FARRAY | Fixed-size arrays
// =================================================================================================
#if !defined(DQN_NO_FARRAY) #if !defined(DQN_NO_FARRAY)
// NOTE: [$FARR] Dqn_FArray ========================================================================
template <typename T, Dqn_usize N> struct Dqn_FArray template <typename T, Dqn_usize N> struct Dqn_FArray
{ {
T data[N]; ///< Pointer to the start of the array items in the block of memory T data[N]; ///< Pointer to the start of the array items in the block of memory
@ -327,10 +328,8 @@ DQN_API template <typename T, Dqn_usize N> void Dqn_FArray_EraseRang
DQN_API template <typename T, Dqn_usize N> void Dqn_FArray_Clear (Dqn_FArray<T, N> *array); DQN_API template <typename T, Dqn_usize N> void Dqn_FArray_Clear (Dqn_FArray<T, N> *array);
#endif // !defined(DQN_NO_FARRAY) #endif // !defined(DQN_NO_FARRAY)
// ================================================================================================= #if !defined(DQN_NO_LIST)
// [$LIST] Dqn_List | | Chunked linked lists, append only // NOTE: [$LIST] Dqn_List ==========================================================================
// =================================================================================================
//
// NOTE: API // NOTE: API
// //
// @proc Dqn_List_At // @proc Dqn_List_At
@ -389,11 +388,10 @@ DQN_API template <typename T> bool Dqn_List_Iterate (Dqn_List<T> *li
// NOTE: Internal ================================================================================== // NOTE: Internal ==================================================================================
DQN_API template <typename T> T * Dqn_List_Make_ (DQN_LEAK_TRACE_FUNCTION Dqn_List<T> *list, Dqn_usize count); DQN_API template <typename T> T * Dqn_List_Make_ (DQN_LEAK_TRACE_FUNCTION Dqn_List<T> *list, Dqn_usize count);
DQN_API template <typename T> T * Dqn_List_Add_ (DQN_LEAK_TRACE_FUNCTION Dqn_List<T> *list, Dqn_usize count); DQN_API template <typename T> T * Dqn_List_Add_ (DQN_LEAK_TRACE_FUNCTION Dqn_List<T> *list, Dqn_usize count);
#endif // !defined(DQN_NO_LIST)
#if !defined(DQN_NO_VARRAY) #if !defined(DQN_NO_VARRAY)
// ================================================================================================= // NOTE: [$VARR] Dqn_VArray ========================================================================
// [$VARR] Dqn_VArray | | Array backed by virtual memory arena
// =================================================================================================
DQN_API template <typename T> Dqn_VArray<T> Dqn_VArray_InitByteSize(Dqn_Arena *arena, Dqn_usize byte_size) DQN_API template <typename T> Dqn_VArray<T> Dqn_VArray_InitByteSize(Dqn_Arena *arena, Dqn_usize byte_size)
{ {
Dqn_usize byte_size_64k_aligned = Dqn_PowerOfTwoAlign(byte_size, DQN_VMEM_RESERVE_GRANULARITY); Dqn_usize byte_size_64k_aligned = Dqn_PowerOfTwoAlign(byte_size, DQN_VMEM_RESERVE_GRANULARITY);
@ -501,9 +499,7 @@ DQN_API template <typename T> void Dqn_VArray_Reserve(Dqn_VArray<T> *array, Dqn_
#endif // !defined(DQN_NO_VARRAY) #endif // !defined(DQN_NO_VARRAY)
#if !defined(DQN_NO_DSMAP) #if !defined(DQN_NO_DSMAP)
// ================================================================================================= // NOTE: [$DMAP] Dqn_DSMap =========================================================================
// [$DMAP] Dqn_DSMap | DQN_NO_DSMAP | Hashtable, 70% max load, PoT size, linear probe, chain repair
// =================================================================================================
uint32_t const DQN_DS_MAP_DEFAULT_HASH_SEED = 0x8a1ced49; uint32_t const DQN_DS_MAP_DEFAULT_HASH_SEED = 0x8a1ced49;
uint32_t const DQN_DS_MAP_SENTINEL_SLOT = 0; uint32_t const DQN_DS_MAP_SENTINEL_SLOT = 0;
@ -855,9 +851,7 @@ DQN_API Dqn_DSMapKey Dqn_DSMap_KeyString8Copy(Dqn_DSMap<T> const *map, Dqn_Alloc
#endif // !defined(DQN_NO_DSMAP) #endif // !defined(DQN_NO_DSMAP)
#if !defined(DQN_NO_FARRAY) #if !defined(DQN_NO_FARRAY)
// ================================================================================================= // NOTE: [$FARR] Dqn_FArray ========================================================================
// [$FARR] Dqn_FArray | DQN_NO_FARRAY | Fixed-size arrays
// =================================================================================================
DQN_API template <typename T, Dqn_usize N> Dqn_FArray<T, N> Dqn_FArray_Init(T const *array, Dqn_usize count) DQN_API template <typename T, Dqn_usize N> Dqn_FArray<T, N> Dqn_FArray_Init(T const *array, Dqn_usize count)
{ {
Dqn_FArray<T, N> result = {}; Dqn_FArray<T, N> result = {};
@ -948,9 +942,8 @@ DQN_API template <typename T, Dqn_usize N> void Dqn_FArray_Clear(Dqn_FArray<T, N
} }
#endif // !defined(DQN_NO_FARRAY) #endif // !defined(DQN_NO_FARRAY)
// ================================================================================================= #if !defined(DQN_NO_LIST)
// [$LIST] Dqn_List | | Chunked linked lists, append only // NOTE: [$LIST] Dqn_List ==========================================================================
// =================================================================================================
template <typename T> DQN_API Dqn_List<T> Dqn_List_InitWithArena(Dqn_Arena *arena, Dqn_usize chunk_size) template <typename T> DQN_API Dqn_List<T> Dqn_List_InitWithArena(Dqn_Arena *arena, Dqn_usize chunk_size)
{ {
Dqn_List<T> result = {}; Dqn_List<T> result = {};
@ -1070,4 +1063,5 @@ template <typename T> DQN_API T *Dqn_List_At(Dqn_List<T> *list, Dqn_usize index,
return result; return result;
} }
#endif // !defined(DQN_NO_LIST)

View File

@ -1,6 +1,4 @@
// ================================================================================================= // NOTE: [$INTR] Intrinsics ========================================================================
// [$INTR] Intrinsics | | Atomics, cpuid, ticket mutex
// =================================================================================================
#if !defined(DQN_OS_ARM64) #if !defined(DQN_OS_ARM64)
#if defined(DQN_COMPILER_GCC) || defined(DQN_COMPILER_CLANG) #if defined(DQN_COMPILER_GCC) || defined(DQN_COMPILER_CLANG)
#include <cpuid.h> #include <cpuid.h>
@ -20,9 +18,7 @@ Dqn_CPUIDRegisters Dqn_CPUID(int function_id)
} }
#endif // !defined(DQN_OS_ARM64) #endif // !defined(DQN_OS_ARM64)
// ================================================================================================= // NOTE: [$TMUT] Dqn_TicketMutex ===================================================================
// [$TMUT] Dqn_TicketMutex | | Userland mutex via spinlocking atomics
// =================================================================================================
DQN_API void Dqn_TicketMutex_Begin(Dqn_TicketMutex *mutex) DQN_API void Dqn_TicketMutex_Begin(Dqn_TicketMutex *mutex)
{ {
unsigned int ticket = Dqn_Atomic_AddU32(&mutex->ticket, 1); unsigned int ticket = Dqn_Atomic_AddU32(&mutex->ticket, 1);

View File

@ -1,6 +1,17 @@
// NOTE: Table Of Contents =========================================================================
// Index | Disable #define | Description
// ================================================================================================= // =================================================================================================
// [$CFGM] Config macros | | Compile time customisation of library // [$CFGM] Config macros | | Compile time customisation of library
// ================================================================================================= // [$CMAC] Compiler macros | | Macros for the compiler
// [$MACR] Macros | | Define macros used in the library
// [$TYPE] Typedefs | | Typedefs used in the library
// [$GSTR] Global Structs | | Forward declare useful structs
// [$INTR] Intrinsics | | Atomics, cpuid, ticket mutex
// [$TMUT] Dqn_TicketMutex | | Userland mutex via spinlocking atomics
// [$CALL] Dqn_CallSite | | Source code location/tracing
// ===================+=================+===========================================================
// NOTE: [$CFGM] Config macros =====================================================================
// #define DQN_IMPLEMENTATION // #define DQN_IMPLEMENTATION
// Define this in one and only one C++ file to enable the implementation // Define this in one and only one C++ file to enable the implementation
// code of the header file // code of the header file
@ -46,9 +57,7 @@
// thread context. The thread context arena stats can be printed by using // thread context. The thread context arena stats can be printed by using
// Dqn_Library_DumpThreadContextArenaStat. // Dqn_Library_DumpThreadContextArenaStat.
// //
// ================================================================================================= // NOTE: [$CMAC] Compiler macros ===================================================================
// [$CMAC] Compiler macros | | Macros for the compiler
// =================================================================================================
// NOTE: Warning! Order is important here, clang-cl on Windows defines _MSC_VER // NOTE: Warning! Order is important here, clang-cl on Windows defines _MSC_VER
#if defined(_MSC_VER) #if defined(_MSC_VER)
#if defined(__clang__) #if defined(__clang__)
@ -78,9 +87,7 @@
#endif #endif
#endif #endif
// ================================================================================================= // NOTE: [$MACR] Macros ============================================================================
// [$MACR] Macros | | Define macros used in the library
// =================================================================================================
#define DQN_FOR_UINDEX(index, size) for (Dqn_usize index = 0; index < size; index++) #define DQN_FOR_UINDEX(index, size) for (Dqn_usize index = 0; index < size; index++)
#define DQN_FOR_IINDEX(index, size) for (Dqn_isize index = 0; index < size; index++) #define DQN_FOR_IINDEX(index, size) for (Dqn_isize index = 0; index < size; index++)
@ -301,9 +308,7 @@ struct Dqn_DeferHelper
DQN_UNIQUE_NAME(once); \ DQN_UNIQUE_NAME(once); \
end, DQN_UNIQUE_NAME(once) = false) end, DQN_UNIQUE_NAME(once) = false)
// ================================================================================================= // NOTE: [$TYPE] Typedefs ==========================================================================
// [$TYPE] Typedefs | | Typedefs used in the library
// =================================================================================================
typedef intptr_t Dqn_isize; typedef intptr_t Dqn_isize;
typedef uintptr_t Dqn_usize; typedef uintptr_t Dqn_usize;
typedef intptr_t Dqn_isize; typedef intptr_t Dqn_isize;
@ -316,9 +321,7 @@ typedef int32_t Dqn_b32;
#define DQN_ISIZE_MAX INTPTR_MAX #define DQN_ISIZE_MAX INTPTR_MAX
#define DQN_ISIZE_MIN INTPTR_MIN #define DQN_ISIZE_MIN INTPTR_MIN
// ================================================================================================= // NOTE [$GSTR] Global Structs =====================================================================
// [$GSTR] Global Structs | | Forward declare useful structs
// =================================================================================================
struct Dqn_String8 ///< Pointer and length style UTF8 strings struct Dqn_String8 ///< Pointer and length style UTF8 strings
{ {
char *data; ///< The UTF8 bytes of the string char *data; ///< The UTF8 bytes of the string
@ -332,9 +335,7 @@ struct Dqn_String8 ///< Pointer and length style UTF8 strings
#endif #endif
}; };
// ================================================================================================= // NOTE: [$INTR] Intrinsics ========================================================================
// [$INTR] Intrinsics | | Atomics, cpuid, ticket mutex
// =================================================================================================
typedef enum Dqn_ZeroMem { typedef enum Dqn_ZeroMem {
Dqn_ZeroMem_No, ///< Memory can be handed out without zero-ing it out Dqn_ZeroMem_No, ///< Memory can be handed out without zero-ing it out
Dqn_ZeroMem_Yes, ///< Memory should be zero-ed out before giving to the callee Dqn_ZeroMem_Yes, ///< Memory should be zero-ed out before giving to the callee
@ -424,9 +425,8 @@ struct Dqn_CPUIDRegisters
Dqn_CPUIDRegisters Dqn_CPUID(int function_id); Dqn_CPUIDRegisters Dqn_CPUID(int function_id);
#endif // DQN_OS_ARM64 #endif // DQN_OS_ARM64
// ================================================================================================= // NOTE: [$TMUT] Dqn_TicketMutex ===================================================================
// [$TMUT] Dqn_TicketMutex | | Userland mutex via spinlocking atomics //
// =================================================================================================
// A mutex implemented using an atomic compare and swap on tickets handed out // A mutex implemented using an atomic compare and swap on tickets handed out
// for each critical section. // for each critical section.
// //
@ -476,9 +476,7 @@ Dqn_uint Dqn_TicketMutex_MakeTicket (Dqn_TicketMutex *mutex);
void Dqn_TicketMutex_BeginTicket(Dqn_TicketMutex const *mutex, Dqn_uint ticket); void Dqn_TicketMutex_BeginTicket(Dqn_TicketMutex const *mutex, Dqn_uint ticket);
bool Dqn_TicketMutex_CanLock (Dqn_TicketMutex const *mutex, Dqn_uint ticket); bool Dqn_TicketMutex_CanLock (Dqn_TicketMutex const *mutex, Dqn_uint ticket);
// ================================================================================================= // NOTE: [$CALL] Dqn_CallSite ======================================================================
// [$CALL] Dqn_CallSite | | Source code location/tracing
// =================================================================================================
typedef struct Dqn_CallSite { typedef struct Dqn_CallSite {
Dqn_String8 file; Dqn_String8 file;
Dqn_String8 function; Dqn_String8 function;

View File

@ -1,6 +1,4 @@
// ================================================================================================= // NOTE: [$FNV1] Dqn_FNV1A =========================================================================
// [$FNV1] Dqn_FNV1A | | Hash(x) -> 32/64bit via FNV1a
// =================================================================================================
// Default values recommended by: http://isthe.com/chongo/tech/comp/fnv/ // Default values recommended by: http://isthe.com/chongo/tech/comp/fnv/
DQN_API uint32_t Dqn_FNV1A32_Iterate(void const *bytes, Dqn_usize size, uint32_t hash) DQN_API uint32_t Dqn_FNV1A32_Iterate(void const *bytes, Dqn_usize size, uint32_t hash)
{ {
@ -30,9 +28,7 @@ DQN_API uint64_t Dqn_FNV1A64_Hash(void const *bytes, Dqn_usize size)
return result; return result;
} }
// ================================================================================================= // NOTE: [$MMUR] Dqn_MurmurHash3 ===================================================================
// [$MMUR] Dqn_MurmurHash3 | | Hash(x) -> 32/128bit via MurmurHash3
// =================================================================================================
#if defined(DQN_COMPILER_W32_MSVC) || defined(DQN_COMPILER_W32_CLANG) #if defined(DQN_COMPILER_W32_MSVC) || defined(DQN_COMPILER_W32_CLANG)
#define DQN_MMH3_ROTL32(x, y) _rotl(x, y) #define DQN_MMH3_ROTL32(x, y) _rotl(x, y)
#define DQN_MMH3_ROTL64(x, y) _rotl64(x, y) #define DQN_MMH3_ROTL64(x, y) _rotl64(x, y)

View File

@ -1,6 +1,11 @@
// NOTE: Table Of Contents =========================================================================
// Index | Disable #define | Description
// ================================================================================================= // =================================================================================================
// [$FNV1] Dqn_FNV1A | | Hash(x) -> 32/64bit via FNV1a // [$FNV1] Dqn_FNV1A | | Hash(x) -> 32/64bit via FNV1a
// [$MMUR] Dqn_MurmurHash3 | | Hash(x) -> 32/128bit via MurmurHash3
// ================================================================================================= // =================================================================================================
// NOTE: [$FNV1] Dqn_FNV1A =========================================================================
#ifndef DQN_FNV1A32_SEED #ifndef DQN_FNV1A32_SEED
#define DQN_FNV1A32_SEED 2166136261U #define DQN_FNV1A32_SEED 2166136261U
#endif #endif
@ -20,9 +25,7 @@ DQN_API uint64_t Dqn_FNV1A64_Hash (void const *bytes, Dqn_usize size);
DQN_API uint32_t Dqn_FNV1A32_Iterate(void const *bytes, Dqn_usize size, uint32_t hash); DQN_API uint32_t Dqn_FNV1A32_Iterate(void const *bytes, Dqn_usize size, uint32_t hash);
DQN_API uint64_t Dqn_FNV1A64_Iterate(void const *bytes, Dqn_usize size, uint64_t hash); DQN_API uint64_t Dqn_FNV1A64_Iterate(void const *bytes, Dqn_usize size, uint64_t hash);
// ================================================================================================= // NOTE: [$MMUR] Dqn_MurmurHash3 ===================================================================
// [$MMUR] Dqn_MurmurHash3 | | Hash(x) -> 32/128bit via MurmurHash3
// =================================================================================================
// MurmurHash3 was written by Austin Appleby, and is placed in the public // MurmurHash3 was written by Austin Appleby, and is placed in the public
// domain. The author (Austin Appleby) hereby disclaims copyright to this source // domain. The author (Austin Appleby) hereby disclaims copyright to this source
// code. // code.

View File

@ -1,7 +1,5 @@
#if !defined(DQN_NO_MATH) #if !defined(DQN_NO_MATH)
// ================================================================================================= // NOTE: [$MATH] Math ==============================================================================
// [$MATH] Math | DQN_NO_MATH | v2i, V2, V3, V4, Mat4, Rect, RectI32, Lerp
// =================================================================================================
DQN_API Dqn_V2I Dqn_V2ToV2I(Dqn_V2 a) DQN_API Dqn_V2I Dqn_V2ToV2I(Dqn_V2 a)
{ {
Dqn_V2I result = Dqn_V2I(DQN_CAST(int32_t)a.x, DQN_CAST(int32_t)a.y); Dqn_V2I result = Dqn_V2I(DQN_CAST(int32_t)a.x, DQN_CAST(int32_t)a.y);

View File

@ -1,7 +1,11 @@
// NOTE: Table Of Contents =========================================================================
// Index | Disable #define | Description
// ================================================================================================= // =================================================================================================
// [$MATH] Math | DQN_NO_MATH | v2i, V2, V3, V4, Mat4, Rect, RectI32, Lerp // [$MATH] Math | DQN_NO_MATH | v2i, V2, V3, V4, Mat4, Rect, RectI32, Lerp
// ================================================================================================= // =================================================================================================
#if !defined(DQN_NO_MATH) #if !defined(DQN_NO_MATH)
// NOTE: [$MATH] Math ==============================================================================
struct Dqn_V2I struct Dqn_V2I
{ {
int32_t x, y; int32_t x, y;

View File

@ -1,6 +1,4 @@
// ================================================================================================= // NOTE: [$ALLO] Dqn_Allocator =====================================================================
// [$ALLO] Dqn_Allocator | | Generic allocator interface
// =================================================================================================
DQN_API void *Dqn_Allocator_Alloc_(DQN_LEAK_TRACE_FUNCTION Dqn_Allocator allocator, size_t size, uint8_t align, Dqn_ZeroMem zero_mem) DQN_API void *Dqn_Allocator_Alloc_(DQN_LEAK_TRACE_FUNCTION Dqn_Allocator allocator, size_t size, uint8_t align, Dqn_ZeroMem zero_mem)
{ {
void *result = NULL; void *result = NULL;
@ -23,9 +21,7 @@ DQN_API void Dqn_Allocator_Dealloc_(DQN_LEAK_TRACE_FUNCTION Dqn_Allocator alloca
} }
} }
// ================================================================================================= // NOTE: [$VMEM] Dqn_VMem ==========================================================================
// [$VMEM] Dqn_VMem | | Virtual memory allocation
// =================================================================================================
DQN_FILE_SCOPE uint32_t Dqn_VMem_ConvertPageToOSFlags_(uint32_t protect) DQN_FILE_SCOPE uint32_t Dqn_VMem_ConvertPageToOSFlags_(uint32_t protect)
{ {
DQN_ASSERT((protect & ~(Dqn_VMemPage_ReadWrite | Dqn_VMemPage_Guard)) == 0); DQN_ASSERT((protect & ~(Dqn_VMemPage_ReadWrite | Dqn_VMemPage_Guard)) == 0);
@ -151,9 +147,7 @@ DQN_API int Dqn_VMem_Protect(void *ptr, Dqn_usize size, uint32_t page_flags)
return result; return result;
} }
// ================================================================================================= // NOTE: [$AREN] Dqn_Arena =========================================================================
// [$AREN] Dqn_Arena | | Growing bump allocator
// =================================================================================================
DQN_API void Dqn_Arena_CommitFromBlock(Dqn_ArenaBlock *block, Dqn_usize size, Dqn_ArenaCommit commit) DQN_API void Dqn_Arena_CommitFromBlock(Dqn_ArenaBlock *block, Dqn_usize size, Dqn_ArenaCommit commit)
{ {
Dqn_usize commit_size = 0; Dqn_usize commit_size = 0;
@ -581,9 +575,7 @@ DQN_API void Dqn_Arena_Free_(DQN_LEAK_TRACE_FUNCTION Dqn_Arena *arena, Dqn_ZeroM
arena->stats.blocks = 0; arena->stats.blocks = 0;
} }
// ================================================================================================= // NOTE: [$ACAT] Dqn_ArenaCatalog ==================================================================
// [$ACAT] Dqn_ArenaCatalog | | Collate, create & manage arenas in a catalog
// =================================================================================================
DQN_API void Dqn_ArenaCatalog_Init(Dqn_ArenaCatalog *catalog, Dqn_Arena *arena) DQN_API void Dqn_ArenaCatalog_Init(Dqn_ArenaCatalog *catalog, Dqn_Arena *arena)
{ {
catalog->arena = arena; catalog->arena = arena;

View File

@ -1,6 +1,13 @@
// NOTE: Table Of Contents =========================================================================
// Index | Disable #define | Description
// ================================================================================================= // =================================================================================================
// [$ALLO] Dqn_Allocator | | Generic allocator interface // [$ALLO] Dqn_Allocator | | Generic allocator interface
// [$VMEM] Dqn_VMem | | Virtual memory allocation
// [$AREN] Dqn_Arena | | Growing bump allocator
// [$ACAT] Dqn_ArenaCatalog | | Collate, create & manage arenas in a catalog
// ================================================================================================= // =================================================================================================
// NOTE: [$ALLO] Dqn_Allocator =====================================================================
#if defined(DQN_LEAK_TRACING) #if defined(DQN_LEAK_TRACING)
#if defined(DQN_NO_DSMAP) #if defined(DQN_NO_DSMAP)
#error "DSMap is required for allocation tracing" #error "DSMap is required for allocation tracing"
@ -70,9 +77,7 @@ void Dqn_Allocator_Dealloc_(DQN_LEAK_TRACE_FUNCTION Dqn_Allocator allocator, voi
#define Dqn_Allocator_NewArray(allocator, Type, count, zero_mem) (Type *)Dqn_Allocator_Alloc_(DQN_LEAK_TRACE allocator, sizeof(Type) * count, alignof(Type), zero_mem) #define Dqn_Allocator_NewArray(allocator, Type, count, zero_mem) (Type *)Dqn_Allocator_Alloc_(DQN_LEAK_TRACE allocator, sizeof(Type) * count, alignof(Type), zero_mem)
#define Dqn_Allocator_New(allocator, Type, zero_mem) (Type *)Dqn_Allocator_Alloc_(DQN_LEAK_TRACE allocator, sizeof(Type), alignof(Type), zero_mem) #define Dqn_Allocator_New(allocator, Type, zero_mem) (Type *)Dqn_Allocator_Alloc_(DQN_LEAK_TRACE allocator, sizeof(Type), alignof(Type), zero_mem)
// ================================================================================================= // NOTE: [$VMEM] Dqn_VMem ==========================================================================
// [$VMEM] Dqn_VMem | | Virtual memory allocation
// =================================================================================================
enum Dqn_VMemCommit enum Dqn_VMemCommit
{ {
Dqn_VMemCommit_No, Dqn_VMemCommit_No,
@ -124,10 +129,7 @@ DQN_API void Dqn_VMem_Decommit(void *ptr, Dqn_usize size);
DQN_API void Dqn_VMem_Release (void *ptr, Dqn_usize size); DQN_API void Dqn_VMem_Release (void *ptr, Dqn_usize size);
DQN_API int Dqn_VMem_Protect (void *ptr, Dqn_usize size, uint32_t page_flags); DQN_API int Dqn_VMem_Protect (void *ptr, Dqn_usize size, uint32_t page_flags);
// ================================================================================================= // NOTE: [$AREN] Dqn_Arena =========================================================================
// [$AREN] Dqn_Arena | | Growing bump allocator
// =================================================================================================
//
// A bump-allocator that can grow dynamically by chaining blocks of memory // A bump-allocator that can grow dynamically by chaining blocks of memory
// together. The arena's memory is backed by virtual memory allowing the // together. The arena's memory is backed by virtual memory allowing the
// allocator to reserve and commit physical pages as memory is given from // allocator to reserve and commit physical pages as memory is given from
@ -314,9 +316,7 @@ DQN_API void Dqn_Arena_Free_ (DQN_LEAK_TRACE_FUNCTION
DQN_API void * Dqn_Arena_CopyZ_ (DQN_LEAK_TRACE_FUNCTION Dqn_Arena *arena, void *src, Dqn_usize size, uint8_t alignment); DQN_API void * Dqn_Arena_CopyZ_ (DQN_LEAK_TRACE_FUNCTION Dqn_Arena *arena, void *src, Dqn_usize size, uint8_t alignment);
DQN_API void Dqn_Arena_EndTempMemory_ (DQN_LEAK_TRACE_FUNCTION Dqn_ArenaTempMemory arena_temp_memory); DQN_API void Dqn_Arena_EndTempMemory_ (DQN_LEAK_TRACE_FUNCTION Dqn_ArenaTempMemory arena_temp_memory);
// ================================================================================================= // NOTE: [$ACAT] Dqn_ArenaCatalog ==================================================================
// [$ACAT] Dqn_ArenaCatalog | | Collate, create & manage arenas in a catalog
// =================================================================================================
struct Dqn_ArenaCatalogItem struct Dqn_ArenaCatalogItem
{ {
Dqn_Arena *arena; Dqn_Arena *arena;

View File

@ -1,8 +1,5 @@
// NOTE: [$DLIB] Dqn_Library =======================================================================
Dqn_Library dqn_library; Dqn_Library dqn_library;
// =================================================================================================
// [$DLIB] Dqn_Library | | Library run-time behaviour configuration
// =================================================================================================
DQN_API Dqn_Library *Dqn_Library_Init(Dqn_Arena *arena) DQN_API Dqn_Library *Dqn_Library_Init(Dqn_Arena *arena)
{ {
Dqn_Library *result = &dqn_library; Dqn_Library *result = &dqn_library;
@ -156,9 +153,7 @@ DQN_API void Dqn_Library_LeakTraceMarkFree(Dqn_CallSite call_site, void *ptr)
} }
#endif /// defined(DQN_LEAK_TRACING) #endif /// defined(DQN_LEAK_TRACING)
// ================================================================================================= // NOTE: [$BITS] Dqn_Bit ===========================================================================
// [$BITS] Dqn_Bit | | Bitset manipulation
// =================================================================================================
DQN_API void Dqn_Bit_UnsetInplace(uint64_t *flags, uint64_t bitfield) DQN_API void Dqn_Bit_UnsetInplace(uint64_t *flags, uint64_t bitfield)
{ {
*flags = (*flags & ~bitfield); *flags = (*flags & ~bitfield);
@ -181,9 +176,7 @@ DQN_API bool Dqn_Bit_IsNotSet(uint64_t bits, uint64_t bits_to_check)
return result; return result;
} }
// ================================================================================================= // NOTE: [$SAFE] Dqn_Safe ==========================================================================
// [$SAFE] Dqn_Safe | | Safe arithmetic, casts, asserts
// =================================================================================================
DQN_API int64_t Dqn_Safe_AddI64(int64_t a, int64_t b) DQN_API int64_t Dqn_Safe_AddI64(int64_t a, int64_t b)
{ {
int64_t result = DQN_CHECKF(a <= INT64_MAX - b, "a=%zd, b=%zd", a, b) ? (a + b) : INT64_MAX; int64_t result = DQN_CHECKF(a <= INT64_MAX - b, "a=%zd, b=%zd", a, b) ? (a + b) : INT64_MAX;
@ -505,9 +498,7 @@ DQN_API uint64_t Dqn_Safe_SaturateCastIntToU64(int val)
return result; return result;
} }
// ================================================================================================= // NOTE: [$TCTX] Dqn_ThreadContext =================================================================
// [$TCTX] Dqn_ThreadContext | | Per-thread data structure e.g. temp arenas
// =================================================================================================
Dqn_ThreadScratch::Dqn_ThreadScratch(DQN_LEAK_TRACE_FUNCTION Dqn_ThreadContext *context, uint8_t context_index) Dqn_ThreadScratch::Dqn_ThreadScratch(DQN_LEAK_TRACE_FUNCTION Dqn_ThreadContext *context, uint8_t context_index)
{ {
index = context_index; index = context_index;

View File

@ -1,12 +1,18 @@
// NOTE: Table Of Contents =========================================================================
// Index | Disable #define | Description
// ================================================================================================= // =================================================================================================
// [$DLIB] Dqn_Library | | Library run-time behaviour configuration // [$DLIB] Dqn_Library | | Library run-time behaviour configuration
// [$BITS] Dqn_Bit | | Bitset manipulation
// [$SAFE] Dqn_Safe | | Safe arithmetic, casts, asserts
// [$TCTX] Dqn_ThreadContext | | Per-thread data structure e.g. temp arenas
// [$BSEA] Dqn_BinarySearch | | Binary search
// ================================================================================================= // =================================================================================================
//
// NOTE: [$DLIB] Dqn_Library =======================================================================
// Book-keeping data for the library and allow customisation of certain features // Book-keeping data for the library and allow customisation of certain features
// provided. // provided.
// //
// NOTE: API // NOTE: API =======================================================================================
//
// @proc Dqn_Library_SetLogCallback // @proc Dqn_Library_SetLogCallback
// @desc Update the default logging function, all logging functions will run through // @desc Update the default logging function, all logging functions will run through
// this callback // this callback
@ -70,27 +76,23 @@ DQN_API void Dqn_Library_LeakTraceMarkFree (Dqn_CallSite call_site, void
#define Dqn_Library_LeakTraceMarkFree(...) #define Dqn_Library_LeakTraceMarkFree(...)
#endif #endif
// ================================================================================================= // NOTE: [$BITS] Dqn_Bit ===========================================================================
// [$BITS] Dqn_Bit | | Bitset manipulation
// =================================================================================================
DQN_API void Dqn_Bit_UnsetInplace(uint32_t *flags, uint32_t bitfield); 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 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_IsSet(uint32_t bits, uint32_t bits_to_set);
DQN_API bool Dqn_Bit_IsNotSet(uint32_t bits, uint32_t bits_to_check); DQN_API bool Dqn_Bit_IsNotSet(uint32_t bits, uint32_t bits_to_check);
// ================================================================================================= // NOTE: [$SAFE] Dqn_Safe ==========================================================================
// [$SAFE] Dqn_Safe | | Safe arithmetic, casts, asserts // Assert the expression given in debug, whilst in release- assertion is
// ================================================================================================= // removed and the expression is evaluated and returned.
/// Assert the expression given in debug, whilst in release- assertion is //
/// removed and the expression is evaluated and returned. // This function provides dual logic which allows handling of the condition
/// // gracefully in release mode, but asserting in debug mode. This is an internal
/// This function provides dual logic which allows handling of the condition // function, prefer the @see DQN_CHECK macros.
/// gracefully in release mode, but asserting in debug mode. This is an internal //
/// function, prefer the @see DQN_CHECK macros. // @param assertion_expr[in] Expressin to assert on
/// // @param fmt[in] Format string for providing a message on assertion
/// @param assertion_expr[in] Expressin to assert on // @return True if the expression evaluated to true, false otherwise.
/// @param fmt[in] Format string for providing a message on assertion
/// @return True if the expression evaluated to true, false otherwise.
DQN_API bool DQN_CHECKF_(bool assertion_expr, Dqn_CallSite call_site, char const *fmt, ...); DQN_API bool DQN_CHECKF_(bool assertion_expr, Dqn_CallSite call_site, char const *fmt, ...);
// NOTE: Dqn_Safe Arithmetic // NOTE: Dqn_Safe Arithmetic
@ -335,10 +337,7 @@ DQN_API uint32_t Dqn_Safe_SaturateCastIntToU32(int val);
/// out of the valid range when casted. /// out of the valid range when casted.
DQN_API uint64_t Dqn_Safe_SaturateCastIntToU64(int val); DQN_API uint64_t Dqn_Safe_SaturateCastIntToU64(int val);
// ================================================================================================= // NOTE: [$TCTX] Dqn_ThreadContext =================================================================
// [$TCTX] Dqn_ThreadContext | | Per-thread data structure e.g. temp arenas
// =================================================================================================
//
// Each thread is assigned in their thread-local storage (TLS) scratch and // Each thread is assigned in their thread-local storage (TLS) scratch and
// permanent arena allocators. These can be used for allocations with a lifetime // permanent arena allocators. These can be used for allocations with a lifetime
// scoped to the lexical scope or for storing data permanently using the arena // scoped to the lexical scope or for storing data permanently using the arena
@ -417,9 +416,7 @@ DQN_API uint32_t Dqn_Thread_GetID();
DQN_API Dqn_ThreadContext *Dqn_Thread_GetContext_(DQN_LEAK_TRACE_FUNCTION_NO_COMMA); DQN_API Dqn_ThreadContext *Dqn_Thread_GetContext_(DQN_LEAK_TRACE_FUNCTION_NO_COMMA);
DQN_API Dqn_ThreadScratch Dqn_Thread_GetScratch_(DQN_LEAK_TRACE_FUNCTION void const *conflict_arena); DQN_API Dqn_ThreadScratch Dqn_Thread_GetScratch_(DQN_LEAK_TRACE_FUNCTION void const *conflict_arena);
// ================================================================================================= // NOTE: [$BSEA] Dqn_BinarySearch ==================================================================
// [$BSEA] Binary Search | |
// =================================================================================================
template <typename T> template <typename T>
using Dqn_BinarySearchLessThanProc = bool(T const &lhs, T const &rhs); using Dqn_BinarySearchLessThanProc = bool(T const &lhs, T const &rhs);

View File

@ -1,7 +1,5 @@
#if defined(DQN_OS_WIN32) #if defined(DQN_OS_WIN32)
// ================================================================================================= // NOTE: [$W32H] Win32 Min Header ==================================================================
// [$W32H] Win32 minimal header | DQN_NO_WIN32_MINIMAL_HEADER | Minimal windows.h subset
// =================================================================================================
#pragma comment(lib, "bcrypt") #pragma comment(lib, "bcrypt")
#pragma comment(lib, "wininet") #pragma comment(lib, "wininet")
@ -353,9 +351,7 @@
#include <unistd.h> // access, gettid #include <unistd.h> // access, gettid
#endif #endif
// ================================================================================================= // NOTE: [$FSYS] Dqn_Fs ============================================================================
// [$FSYS] Dqn_Fs | | Filesystem helpers
// =================================================================================================
#if defined(DQN_OS_WIN32) #if defined(DQN_OS_WIN32)
DQN_API uint64_t Dqn__WinFileTimeToSeconds(FILETIME const *time) DQN_API uint64_t Dqn__WinFileTimeToSeconds(FILETIME const *time)
{ {
@ -1141,9 +1137,7 @@ DQN_API Dqn_String8 Dqn_FsPath_BuildWithSeparator(Dqn_Arena *arena, Dqn_FsPath c
return result; return result;
} }
// ================================================================================================= // NOTE: [$DATE] Dqn_Date ==========================================================================
// [$DATE] Dqn_Date | | Date-time helpers
// =================================================================================================
DQN_API Dqn_DateHMSTime Dqn_Date_HMSLocalTimeNow() DQN_API Dqn_DateHMSTime Dqn_Date_HMSLocalTimeNow()
{ {
Dqn_DateHMSTime result = {}; Dqn_DateHMSTime result = {};
@ -1241,9 +1235,7 @@ DQN_API uint64_t Dqn_Date_EpochTime()
} }
#if defined(DQN_OS_WIN32) #if defined(DQN_OS_WIN32)
// ================================================================================================= // NOTE: [$WIND] Dqn_Win ===========================================================================
// [$WIND] Dqn_Win | | Windows OS helpers
// =================================================================================================
DQN_API void Dqn_Win_LastErrorToBuffer(Dqn_WinErrorMsg *msg) DQN_API void Dqn_Win_LastErrorToBuffer(Dqn_WinErrorMsg *msg)
{ {
msg->code = GetLastError(); msg->code = GetLastError();
@ -1564,9 +1556,7 @@ DQN_API bool Dqn_Win_FolderIterate(Dqn_String8 path, Dqn_Win_FolderIterator *it)
} }
#if !defined(DQN_NO_WIN_NET) #if !defined(DQN_NO_WIN_NET)
// ================================================================================================= // NOTE: [$WINN] Dqn_WinNet ========================================================================
// [$WINN] Dqn_WinNet | DQN_NO_WINNET | Windows internet download/query helpers
// =================================================================================================
DQN_API Dqn_WinNetHandle Dqn_Win_NetHandleInitCString(char const *url, int url_size) DQN_API Dqn_WinNetHandle Dqn_Win_NetHandleInitCString(char const *url, int url_size)
{ {
URL_COMPONENTSA components = {}; URL_COMPONENTSA components = {};
@ -1961,9 +1951,7 @@ DQN_API Dqn_String8 Dqn_Win_NetHandlePumpToAllocString(Dqn_WinNetHandle *handle)
#endif // !defined(DQN_NO_WINNET) #endif // !defined(DQN_NO_WINNET)
#endif // defined(DQN_OS_WIN32) #endif // defined(DQN_OS_WIN32)
// ================================================================================================= // NOTE: [$OSYS] Dqn_OS ============================================================================
// [$OSYS] Dqn_OS | DQN_NO_WIN | Operating-system APIs
// =================================================================================================
DQN_API bool Dqn_OS_SecureRNGBytes(void *buffer, uint32_t size) DQN_API bool Dqn_OS_SecureRNGBytes(void *buffer, uint32_t size)
{ {
if (!buffer || size < 0) if (!buffer || size < 0)

View File

@ -1,6 +1,15 @@
// NOTE: Table Of Contents =========================================================================
// Index | Disable #define | Description
// ================================================================================================= // =================================================================================================
// [$FSYS] Dqn_Fs | | Filesystem helpers // [$FSYS] Dqn_Fs | | Filesystem helpers
// [$DATE] Dqn_Date | | Date-time helpers
// [$W32H] Win32 Min Header | DQN_NO_WIN32_MIN_HEADER | Minimal windows.h subset
// [$WIND] Dqn_Win | | Windows OS helpers
// [$WINN] Dqn_WinNet | DQN_NO_WINNET | Windows internet download/query helpers
// [$OSYS] Dqn_OS | DQN_NO_WIN | Operating-system APIs
// ================================================================================================= // =================================================================================================
// NOTE: [$FSYS] Dqn_Fs ============================================================================
enum Dqn_FsInfoType enum Dqn_FsInfoType
{ {
Dqn_FsInfoType_Unknown, Dqn_FsInfoType_Unknown,
@ -128,10 +137,7 @@ DQN_API Dqn_String8 Dqn_FsPath_ConvertString8 (Dqn_Arena *arena, Dqn_String8
#endif #endif
#endif #endif
// NOTE: [$DATE] Dqn_Date ==========================================================================
// =================================================================================================
// [$DATE] Dqn_Date | | Date-time helpers
// =================================================================================================
struct Dqn_DateHMSTimeString struct Dqn_DateHMSTimeString
{ {
char date[DQN_ARRAY_UCOUNT("YYYY-MM-SS")]; char date[DQN_ARRAY_UCOUNT("YYYY-MM-SS")];
@ -160,11 +166,9 @@ DQN_API Dqn_DateHMSTimeString Dqn_Date_HMSLocalTimeString(Dqn_DateHMSTime time,
// return: The time elapsed since Unix epoch (1970-01-01T00:00:00Z) in seconds // return: The time elapsed since Unix epoch (1970-01-01T00:00:00Z) in seconds
DQN_API uint64_t Dqn_Date_EpochTime(); DQN_API uint64_t Dqn_Date_EpochTime();
// ================================================================================================= // NOTE: [$W32H] Win32 Min Header ==================================================================
// [$W32H] Win32 minimal header | DQN_NO_WIN32_MINIMAL_HEADER | Minimal windows.h subset
// =================================================================================================
#if defined(DQN_OS_WIN32) #if defined(DQN_OS_WIN32)
#if !defined(DQN_NO_WIN32_MINIMAL_HEADER) && !defined(_INC_WINDOWS) #if !defined(DQN_NO_WIN32_MIN_HEADER) && !defined(_INC_WINDOWS)
// Taken from Windows.h // Taken from Windows.h
// typedef unsigned long DWORD; // typedef unsigned long DWORD;
// typedef unsigned short WORD; // typedef unsigned short WORD;
@ -185,11 +189,9 @@ DQN_API uint64_t Dqn_Date_EpochTime();
} u; } u;
uint64_t QuadPart; uint64_t QuadPart;
} LARGE_INTEGER; } LARGE_INTEGER;
#endif // !defined(DQN_NO_WIN32_MINIMAL_HEADER) && !defined(_INC_WINDOWS) #endif // !defined(DQN_NO_WIN32_MIN_HEADER) && !defined(_INC_WINDOWS)
// ================================================================================================= // NOTE: [$WIND] Dqn_Win ===========================================================================
// [$WIND] Dqn_Win | | Windows OS helpers
// =================================================================================================
struct Dqn_WinErrorMsg struct Dqn_WinErrorMsg
{ {
unsigned long code; unsigned long code;
@ -274,9 +276,7 @@ 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); DQN_API bool Dqn_Win_FolderWIterate(Dqn_String16 path, Dqn_Win_FolderIteratorW *it);
#if !defined(DQN_NO_WINNET) #if !defined(DQN_NO_WINNET)
// ================================================================================================= // NOTE: [$WINN] Dqn_WinNet ========================================================================
// [$WINN] Dqn_WinNet | DQN_NO_WINNET | Windows internet download/query helpers
// =================================================================================================
enum Dqn_WinNetHandleState enum Dqn_WinNetHandleState
{ {
Dqn_WinNetHandleState_Invalid, Dqn_WinNetHandleState_Invalid,
@ -385,9 +385,7 @@ DQN_API Dqn_String8 Dqn_Win_NetHandlePumpToAllocString(Dqn_WinNetHandle *ha
#endif // !defined(DQN_NO_WINNET) #endif // !defined(DQN_NO_WINNET)
#endif // defined(DQN_OS_WIN32) #endif // defined(DQN_OS_WIN32)
// ================================================================================================= // NOTE: [$OSYS] Dqn_OS ============================================================================
// [$OSYS] Dqn_OS | DQN_NO_WIN | Operating-system APIs
// =================================================================================================
/// Generate cryptographically secure bytes /// Generate cryptographically secure bytes
DQN_API bool Dqn_OS_SecureRNGBytes(void *buffer, uint32_t size); DQN_API bool Dqn_OS_SecureRNGBytes(void *buffer, uint32_t size);

View File

@ -1,6 +1,4 @@
// ================================================================================================= // NOTE: [$PRIN] Dqn_Print =========================================================================
// [$PRIN] Dqn_Print | | Printing
// =================================================================================================
DQN_API Dqn_PrintStyle Dqn_Print_StyleColour(uint8_t r, uint8_t g, uint8_t b, Dqn_PrintBold bold) DQN_API Dqn_PrintStyle Dqn_Print_StyleColour(uint8_t r, uint8_t g, uint8_t b, Dqn_PrintBold bold)
{ {
Dqn_PrintStyle result = {}; Dqn_PrintStyle result = {};
@ -194,9 +192,7 @@ DQN_API Dqn_String8 Dqn_Print_ESCColourU32String(Dqn_PrintESCColour colour, uint
return result; return result;
} }
// ================================================================================================= // NOTE: [$LLOG] Dqn_Log ==========================================================================
// [$LLOG] Dqn_Log | | Library logging
// =================================================================================================
DQN_API Dqn_String8 Dqn_Log_MakeString(Dqn_Allocator allocator, DQN_API Dqn_String8 Dqn_Log_MakeString(Dqn_Allocator allocator,
bool colour, bool colour,
Dqn_String8 type, Dqn_String8 type,

View File

@ -1,6 +1,11 @@
// NOTE: Table Of Contents =========================================================================
// Index | Disable #define | Description
// ================================================================================================= // =================================================================================================
// [$PRIN] Dqn_Print | | Console printing // [$PRIN] Dqn_Print | | Console printing
// [$LLOG] Dqn_Log | | Library logging
// ================================================================================================= // =================================================================================================
// NOTE: [$PRIN] Dqn_Print =========================================================================
enum Dqn_PrintStd enum Dqn_PrintStd
{ {
Dqn_PrintStd_Out, Dqn_PrintStd_Out,
@ -84,9 +89,7 @@ Dqn_String8 Dqn_Print_ESCColourU32String(Dqn_PrintESCColour colour, u
#define Dqn_Print_ESCResetString DQN_STRING8(Dqn_Print_ESCReset) #define Dqn_Print_ESCResetString DQN_STRING8(Dqn_Print_ESCReset)
#define Dqn_Print_ESCBoldString DQN_STRING8(Dqn_Print_ESCBold) #define Dqn_Print_ESCBoldString DQN_STRING8(Dqn_Print_ESCBold)
// ================================================================================================= // NOTE: [$LLOG] Dqn_Log ==========================================================================
// [$LLOG] Dqn_Log | | Library logging
// =================================================================================================
enum Dqn_LogType enum Dqn_LogType
{ {
Dqn_LogType_Debug, Dqn_LogType_Debug,

View File

@ -1,6 +1,4 @@
// ================================================================================================= // NOTE: [$CSTR] Dqn_CString8 ======================================================================
// [$CSTR] Dqn_CString8 | | C-string helpers
// =================================================================================================
DQN_API Dqn_usize Dqn_CString8_FSize(char const *fmt, ...) DQN_API Dqn_usize Dqn_CString8_FSize(char const *fmt, ...)
{ {
va_list args; va_list args;
@ -41,9 +39,7 @@ DQN_API Dqn_usize Dqn_CString16_Size(wchar_t const *src)
return result; return result;
} }
// ================================================================================================= // NOTE: [$STR8] Dqn_String8 =======================================================================
// [$STR8] Dqn_String8 | | Pointer and length strings
// =================================================================================================
DQN_API Dqn_String8 Dqn_String8_InitCString8(char const *src) DQN_API Dqn_String8 Dqn_String8_InitCString8(char const *src)
{ {
Dqn_usize size = Dqn_CString8_Size(src); Dqn_usize size = Dqn_CString8_Size(src);
@ -592,9 +588,7 @@ DQN_API Dqn_String8 Dqn_String8_Copy_(DQN_LEAK_TRACE_FUNCTION Dqn_Allocator allo
return result; return result;
} }
// ================================================================================================= // NOTE: [$STRB] Dqn_String8Builder ================================================================
// [$STRB] Dqn_String8Builder | |
// =================================================================================================
bool Dqn_String8Builder_AppendRef(Dqn_String8Builder *builder, Dqn_String8 string) bool Dqn_String8Builder_AppendRef(Dqn_String8Builder *builder, Dqn_String8 string)
{ {
if (!builder || !string.data || string.size <= 0) if (!builder || !string.data || string.size <= 0)
@ -667,9 +661,7 @@ Dqn_String8 Dqn_String8Builder_Build(Dqn_String8Builder const *builder, Dqn_Allo
} }
#if !defined(DQN_NO_JSON_BUILDER) #if !defined(DQN_NO_JSON_BUILDER)
// ================================================================================================= // NOTE: [$JSON] Dqn_JSONBuilder ===================================================================
// [$JSON] Dqn_JSONBuilder | DQN_NO_JSON_BUILDER | Construct json output
// =================================================================================================
Dqn_JSONBuilder Dqn_JSONBuilder_Init(Dqn_Allocator allocator, int spaces_per_indent) Dqn_JSONBuilder Dqn_JSONBuilder_Init(Dqn_Allocator allocator, int spaces_per_indent)
{ {
Dqn_JSONBuilder result = {}; Dqn_JSONBuilder result = {};
@ -827,9 +819,7 @@ void Dqn_JSONBuilder_BoolNamed(Dqn_JSONBuilder *builder, Dqn_String8 key, bool v
} }
#endif // !defined(DQN_NO_JSON_BUILDER) #endif // !defined(DQN_NO_JSON_BUILDER)
// ================================================================================================= // NOTE: [$CHAR] Dqn_Char ==========================================================================
// [$CHAR] Dqn_Char | | Character ascii/digit.. helpers
// =================================================================================================
DQN_API bool Dqn_Char_IsAlphabet(char ch) DQN_API bool Dqn_Char_IsAlphabet(char ch)
{ {
bool result = (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); bool result = (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
@ -896,9 +886,7 @@ DQN_API char Dqn_Char_ToLower(char ch)
return result; return result;
} }
// ================================================================================================= // NOTE: [$UTFX] Dqn_UTF ===========================================================================
// [$UTFX] Dqn_UTF | | Unicode helpers
// =================================================================================================
DQN_API int Dqn_UTF8_EncodeCodepoint(uint8_t utf8[4], uint32_t 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/ // NOTE: Table from https://www.reedbeta.com/blog/programmers-intro-to-unicode/
@ -972,9 +960,7 @@ DQN_API int Dqn_UTF16_EncodeCodepoint(uint16_t utf16[2], uint32_t codepoint)
} }
#if !defined(DQN_NO_HEX) #if !defined(DQN_NO_HEX)
// ================================================================================================= // NOTE: [$BHEX] Dqn_Bin ===========================================================================
// [$BHEX] Dqn_Bin | DQN_NO_HEX | Binary <-> hex helpers
// =================================================================================================
DQN_API char const *Dqn_Bin_HexBufferTrim0x(char const *hex, Dqn_usize size, Dqn_usize *real_size) DQN_API char const *Dqn_Bin_HexBufferTrim0x(char const *hex, Dqn_usize size, Dqn_usize *real_size)
{ {
Dqn_String8 result = Dqn_String8_TrimWhitespaceAround(Dqn_String8_Init(hex, size)); Dqn_String8 result = Dqn_String8_TrimWhitespaceAround(Dqn_String8_Init(hex, size));
@ -1251,9 +1237,7 @@ DQN_API Dqn_U64String Dqn_U64ToString(uint64_t val, char separator)
return result; return result;
} }
// ================================================================================================= // NOTE: [$STBS] stb_sprintf =======================================================================
// [$STBS] stb_sprintf | | Portable sprintf
// =================================================================================================
#if !defined(DQN_STB_SPRINTF_HEADER_ONLY) #if !defined(DQN_STB_SPRINTF_HEADER_ONLY)
#define STB_SPRINTF_IMPLEMENTATION #define STB_SPRINTF_IMPLEMENTATION
#ifdef STB_SPRINTF_IMPLEMENTATION #ifdef STB_SPRINTF_IMPLEMENTATION

View File

@ -1,6 +1,18 @@
// NOTE: Table Of Contents =========================================================================
// Index | Disable #define | Description
// ================================================================================================= // =================================================================================================
// [$CSTR] Dqn_CString8 | | C-string helpers // [$CSTR] Dqn_CString8 | | C-string helpers
// [$STR8] Dqn_String8 | | Pointer and length strings
// [$FSTR] Dqn_FString8 | DQN_NO_FSTRING8 | Fixed-size strings
// [$STRB] Dqn_String8Builder | |
// [$JSON] Dqn_JSONBuilder | DQN_NO_JSON_BUILDER | Construct json output
// [$CHAR] Dqn_Char | | Character ascii/digit.. helpers
// [$UTFX] Dqn_UTF | | Unicode helpers
// [$BHEX] Dqn_Bin | DQN_NO_HEX | Binary <-> hex helpers
// [$STBS] stb_sprintf | DQN_STB_SPRINTF_HEADER_ONLY | Portable sprintf
// ================================================================================================= // =================================================================================================
// NOTE: [$CSTR] Dqn_CString8 ======================================================================
// @proc Dqn_CString8_ArrayCount // @proc Dqn_CString8_ArrayCount
// @desc Calculate the size of a cstring literal/array at compile time // @desc Calculate the size of a cstring literal/array at compile time
// @param literal The cstring literal/array to calculate the size for // @param literal The cstring literal/array to calculate the size for
@ -24,12 +36,8 @@ DQN_API Dqn_usize Dqn_CString8_FVSize (char
DQN_API Dqn_usize Dqn_CString8_Size (char const *a); DQN_API Dqn_usize Dqn_CString8_Size (char const *a);
DQN_API Dqn_usize Dqn_CString16_Size (wchar_t const *a); DQN_API Dqn_usize Dqn_CString16_Size (wchar_t const *a);
// ================================================================================================= // NOTE: [$STR8] Dqn_String8 =======================================================================
// [$STR8] Dqn_String8 | | Pointer and length strings
// =================================================================================================
//
// NOTE: API // NOTE: API
// @proc Dqn_String8_Init // @proc Dqn_String8_Init
// @desc Initialise a string from a pointer and length // @desc Initialise a string from a pointer and length
// The string is invalid (i.e. Dqn_String8_IsValid() returns false) if size is // The string is invalid (i.e. Dqn_String8_IsValid() returns false) if size is
@ -360,10 +368,7 @@ DQN_API Dqn_String8 Dqn_String8_CopyCString_ (DQN_LEAK_TRACE_FUNCTION Dq
DQN_API Dqn_String8 Dqn_String8_Copy_ (DQN_LEAK_TRACE_FUNCTION Dqn_Allocator allocator, Dqn_String8 string); DQN_API Dqn_String8 Dqn_String8_Copy_ (DQN_LEAK_TRACE_FUNCTION Dqn_Allocator allocator, Dqn_String8 string);
#if !defined(DQN_NO_FSTRING8) #if !defined(DQN_NO_FSTRING8)
// ================================================================================================= // NOTE: [$FSTR] Dqn_FString8 ======================================================================
// [$FSTR] Dqn_FString8 | DQN_NO_FSTRING8 | Fixed-size strings
// =================================================================================================
//
// NOTE: API // NOTE: API
// //
// @proc Dqn_FString8_InitF // @proc Dqn_FString8_InitF
@ -461,9 +466,7 @@ template <Dqn_usize A, Dqn_usize B> bool Dqn_FString8_EqFString8
template <Dqn_usize A, Dqn_usize B> bool Dqn_FString8_EqFString8Insensitive(Dqn_FString8<A> const *lhs, Dqn_FString8<B> const *rhs); template <Dqn_usize A, Dqn_usize B> bool Dqn_FString8_EqFString8Insensitive(Dqn_FString8<A> const *lhs, Dqn_FString8<B> const *rhs);
#endif // !defined(DQN_NO_FSTRING8) #endif // !defined(DQN_NO_FSTRING8)
// ================================================================================================= // NOTE: [$STRB] Dqn_String8Builder ================================================================
// [$STRB] Dqn_String8Builder | |
// =================================================================================================
struct Dqn_String8Builder struct Dqn_String8Builder
{ {
Dqn_Allocator allocator; ///< Allocator to use to back the string list Dqn_Allocator allocator; ///< Allocator to use to back the string list
@ -509,10 +512,8 @@ bool Dqn_String8Builder_AppendF(Dqn_String8Builder *builder, char const *fmt, ..
/// invalid or memory allocation failure. /// invalid or memory allocation failure.
Dqn_String8 Dqn_String8Builder_Build(Dqn_String8Builder const *builder, Dqn_Allocator allocator); Dqn_String8 Dqn_String8Builder_Build(Dqn_String8Builder const *builder, Dqn_Allocator allocator);
// =================================================================================================
// [$JSON] Dqn_JSONBuilder | DQN_NO_JSON_BUILDER | Construct json output
// =================================================================================================
#if !defined(DQN_NO_JSON_BUILDER) #if !defined(DQN_NO_JSON_BUILDER)
// NOTE: [$JSON] Dqn_JSONBuilder ===================================================================
// TODO(dqn): We need to write tests for this // TODO(dqn): We need to write tests for this
enum Dqn_JSONBuilderItem { enum Dqn_JSONBuilderItem {
Dqn_JSONBuilderItem_Empty, Dqn_JSONBuilderItem_Empty,
@ -625,10 +626,7 @@ void Dqn_JSONBuilder_BoolNamed(Dqn_JSONBuilder *builder, Dqn_String8 key, boo
#define Dqn_JSONBuilder_Bool(builder, value) Dqn_JSONBuilder_BoolNamed(builder, DQN_STRING8(""), value) #define Dqn_JSONBuilder_Bool(builder, value) Dqn_JSONBuilder_BoolNamed(builder, DQN_STRING8(""), value)
#endif // !defined(DQN_NO_JSON_BUIDLER) #endif // !defined(DQN_NO_JSON_BUIDLER)
// NOTE: [$CHAR] Dqn_Char ==========================================================================
// =================================================================================================
// [$CHAR] Dqn_Char | | Character ascii/digit.. helpers
// =================================================================================================
DQN_API bool Dqn_Char_IsAlphabet (char ch); DQN_API bool Dqn_Char_IsAlphabet (char ch);
DQN_API bool Dqn_Char_IsDigit (char ch); DQN_API bool Dqn_Char_IsDigit (char ch);
DQN_API bool Dqn_Char_IsAlphaNum (char ch); DQN_API bool Dqn_Char_IsAlphaNum (char ch);
@ -639,16 +637,12 @@ DQN_API char Dqn_Char_ToHex (char ch);
DQN_API char Dqn_Char_ToHexUnchecked(char ch); DQN_API char Dqn_Char_ToHexUnchecked(char ch);
DQN_API char Dqn_Char_ToLower (char ch); DQN_API char Dqn_Char_ToLower (char ch);
// ================================================================================================= // NOTE: [$UTFX] Dqn_UTF ===========================================================================
// [$UTFX] Dqn_UTF | | Unicode helpers
// =================================================================================================
DQN_API int Dqn_UTF8_EncodeCodepoint(uint8_t utf8[4], uint32_t 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); DQN_API int Dqn_UTF16_EncodeCodepoint(uint16_t utf16[2], uint32_t codepoint);
#if !defined(DQN_NO_HEX) #if !defined(DQN_NO_HEX)
// ================================================================================================= // NOTE: [$BHEX] Dqn_Bin ===========================================================================
// [$BHEX] Dqn_Bin | DQN_NO_HEX | Binary <-> hex helpers
// =================================================================================================
// //
// NOTE: API // NOTE: API
// //
@ -790,10 +784,7 @@ struct Dqn_U64String
/// 0 if no separator is desired. /// 0 if no separator is desired.
DQN_API Dqn_U64String Dqn_U64ToString(uint64_t val, char separator); DQN_API Dqn_U64String Dqn_U64ToString(uint64_t val, char separator);
// ================================================================================================= // NOTE: [$STBS] stb_sprintf =======================================================================
// [$STBS] stb_sprintf | | Portable sprintf
// =================================================================================================
/// @cond NO_DOXYYGEN
// stb_sprintf - v1.10 - public domain snprintf() implementation // stb_sprintf - v1.10 - public domain snprintf() implementation
// originally by Jeff Roberts / RAD Game Tools, 2015/10/20 // originally by Jeff Roberts / RAD Game Tools, 2015/10/20
// http://github.com/nothings/stb // http://github.com/nothings/stb
@ -1009,12 +1000,9 @@ STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(snprintf)(char *buf, int count, char c
STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, void *user, char *buf, char const *fmt, va_list va); STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, void *user, char *buf, char const *fmt, va_list va);
STBSP__PUBLICDEC void STB_SPRINTF_DECORATE(set_separators)(char comma, char period); STBSP__PUBLICDEC void STB_SPRINTF_DECORATE(set_separators)(char comma, char period);
#endif // STB_SPRINTF_H_INCLUDE #endif // STB_SPRINTF_H_INCLUDE
/// @endcond
#if !defined(DQN_NO_FSTRING8) #if !defined(DQN_NO_FSTRING8)
// ================================================================================================= // NOTE: [$FSTR] Dqn_FString8 ======================================================================
// [$FSTR] Dqn_FString8 | DQN_NO_FSTRING8 | Fixed-size strings
// =================================================================================================
template <Dqn_usize N> Dqn_FString8<N> Dqn_FString8_InitF(char const *fmt, ...) template <Dqn_usize N> Dqn_FString8<N> Dqn_FString8_InitF(char const *fmt, ...)
{ {
Dqn_FString8<N> result = {}; Dqn_FString8<N> result = {};