mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-30 19:01:02 -07:00
WIP: Broken af
This commit is contained in:
@ -66,27 +66,27 @@ struct Array
|
||||
Type* Data;
|
||||
|
||||
#pragma region Member Mapping
|
||||
forceinline static Array init(AllocatorInfo allocator) { return GEN_NS array_init<Type>(allocator); }
|
||||
forceinline static Array init_reserve(AllocatorInfo allocator, ssize capacity) { return GEN_NS array_init_reserve<Type>(allocator, capacity); }
|
||||
forceinline static usize grow_formula(ssize value) { return GEN_NS array_grow_formula<Type>(value); }
|
||||
forceinline static Array init(AllocatorInfo allocator) { return array_init<Type>(allocator); }
|
||||
forceinline static Array init_reserve(AllocatorInfo allocator, ssize capacity) { return array_init_reserve<Type>(allocator, capacity); }
|
||||
forceinline static usize grow_formula(ssize value) { return array_grow_formula<Type>(value); }
|
||||
|
||||
forceinline bool append(Array other) { return GEN_NS array_append_array<Type>(this, other); }
|
||||
forceinline bool append(Type value) { return GEN_NS array_append<Type>(this, value); }
|
||||
forceinline bool append(Type* items, usize item_num) { return GEN_NS array_append_items<Type>(this, items, item_num); }
|
||||
forceinline bool append_at(Type item, usize idx) { return GEN_NS array_append_at<Type>(this, item, idx); }
|
||||
forceinline bool append_at(Type* items, usize item_num, usize idx) { return GEN_NS array_append_items_at<Type>(this, items, item_num, idx); }
|
||||
forceinline Type* back() { return GEN_NS array_back<Type>(* this); }
|
||||
forceinline void clear() { GEN_NS array_clear<Type>(* this); }
|
||||
forceinline bool fill(usize begin, usize end, Type value) { return GEN_NS array_fill<Type>(* this, begin, end, value); }
|
||||
forceinline void free() { GEN_NS array_free<Type>(this); }
|
||||
forceinline ArrayHeader* get_header() { return GEN_NS array_get_header<Type>(* this); }
|
||||
forceinline bool grow(usize min_capacity) { return GEN_NS array_grow<Type>(this, min_capacity); }
|
||||
forceinline usize num() { return GEN_NS array_num<Type>(*this); }
|
||||
forceinline void pop() { GEN_NS array_pop<Type>(* this); }
|
||||
forceinline void remove_at(usize idx) { GEN_NS array_remove_at<Type>(* this, idx); }
|
||||
forceinline bool reserve(usize new_capacity) { return GEN_NS array_reserve<Type>(this, new_capacity); }
|
||||
forceinline bool resize(usize num) { return GEN_NS array_resize<Type>(this, num); }
|
||||
forceinline bool set_capacity(usize new_capacity) { return GEN_NS array_set_capacity<Type>(this, new_capacity); }
|
||||
forceinline bool append(Array other) { return array_append_array<Type>(this, other); }
|
||||
forceinline bool append(Type value) { return array_append<Type>(this, value); }
|
||||
forceinline bool append(Type* items, usize item_num) { return array_append_items<Type>(this, items, item_num); }
|
||||
forceinline bool append_at(Type item, usize idx) { return array_append_at<Type>(this, item, idx); }
|
||||
forceinline bool append_at(Type* items, usize item_num, usize idx) { return array_append_items_at<Type>(this, items, item_num, idx); }
|
||||
forceinline Type* back() { return array_back<Type>(* this); }
|
||||
forceinline void clear() { array_clear<Type>(* this); }
|
||||
forceinline bool fill(usize begin, usize end, Type value) { return array_fill<Type>(* this, begin, end, value); }
|
||||
forceinline void free() { array_free<Type>(this); }
|
||||
forceinline ArrayHeader* get_header() { return array_get_header<Type>(* this); }
|
||||
forceinline bool grow(usize min_capacity) { return array_grow<Type>(this, min_capacity); }
|
||||
forceinline usize num() { return array_num<Type>(*this); }
|
||||
forceinline void pop() { array_pop<Type>(* this); }
|
||||
forceinline void remove_at(usize idx) { array_remove_at<Type>(* this, idx); }
|
||||
forceinline bool reserve(usize new_capacity) { return array_reserve<Type>(this, new_capacity); }
|
||||
forceinline bool resize(usize num) { return array_resize<Type>(this, num); }
|
||||
forceinline bool set_capacity(usize new_capacity) { return array_set_capacity<Type>(this, new_capacity); }
|
||||
#pragma endregion Member Mapping
|
||||
|
||||
forceinline operator Type*() { return Data; }
|
||||
@ -102,16 +102,16 @@ struct Array
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP && 0
|
||||
template<class Type> bool append(Array<Type>& array, Array<Type> other) { return GEN_NS append( & array, other ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type value) { return GEN_NS append( & array, value ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type* items, usize item_num) { return GEN_NS append( & array, items, item_num ); }
|
||||
template<class Type> bool append_at(Array<Type>& array, Type item, usize idx) { return GEN_NS append_at( & array, item, idx ); }
|
||||
template<class Type> bool append_at(Array<Type>& array, Type* items, usize item_num, usize idx) { return GEN_NS append_at( & array, items, item_num, idx ); }
|
||||
template<class Type> void free(Array<Type>& array) { return GEN_NS free( & array ); }
|
||||
template<class Type> bool grow(Array<Type>& array, usize min_capacity) { return GEN_NS grow( & array, min_capacity); }
|
||||
template<class Type> bool reserve(Array<Type>& array, usize new_capacity) { return GEN_NS reserve( & array, new_capacity); }
|
||||
template<class Type> bool resize(Array<Type>& array, usize num) { return GEN_NS resize( & array, num); }
|
||||
template<class Type> bool set_capacity(Array<Type>& array, usize new_capacity) { return GEN_NS set_capacity( & array, new_capacity); }
|
||||
template<class Type> bool append(Array<Type>& array, Array<Type> other) { return append( & array, other ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type value) { return append( & array, value ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type* items, usize item_num) { return append( & array, items, item_num ); }
|
||||
template<class Type> bool append_at(Array<Type>& array, Type item, usize idx) { return append_at( & array, item, idx ); }
|
||||
template<class Type> bool append_at(Array<Type>& array, Type* items, usize item_num, usize idx) { return append_at( & array, items, item_num, idx ); }
|
||||
template<class Type> void free(Array<Type>& array) { return free( & array ); }
|
||||
template<class Type> bool grow(Array<Type>& array, usize min_capacity) { return grow( & array, min_capacity); }
|
||||
template<class Type> bool reserve(Array<Type>& array, usize new_capacity) { return reserve( & array, new_capacity); }
|
||||
template<class Type> bool resize(Array<Type>& array, usize num) { return resize( & array, num); }
|
||||
template<class Type> bool set_capacity(Array<Type>& array, usize new_capacity) { return set_capacity( & array, new_capacity); }
|
||||
|
||||
template<class Type> forceinline Type* begin(Array<Type>& array) { return array; }
|
||||
template<class Type> forceinline Type* end(Array<Type>& array) { return array + array_get_header(array)->Num; }
|
||||
@ -134,7 +134,7 @@ Array<Type> array_init_reserve(AllocatorInfo allocator, ssize capacity)
|
||||
ArrayHeader* header = rcast(ArrayHeader*, alloc(allocator, sizeof(ArrayHeader) + sizeof(Type) * capacity));
|
||||
|
||||
if (header == nullptr)
|
||||
return {nullptr};
|
||||
return {nullptr};
|
||||
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = capacity;
|
||||
@ -203,10 +203,10 @@ bool array_append_at(Array<Type>* array, Type item, usize idx)
|
||||
|
||||
ssize slot = idx;
|
||||
if (slot >= header->Num)
|
||||
slot = header->Num - 1;
|
||||
slot = header->Num - 1;
|
||||
|
||||
if (slot < 0)
|
||||
slot = 0;
|
||||
slot = 0;
|
||||
|
||||
if (header->Capacity < header->Num + 1)
|
||||
{
|
||||
@ -234,7 +234,7 @@ bool array_append_items_at(Array<Type>* array, Type* items, usize item_num, usiz
|
||||
if (idx >= header->Num)
|
||||
{
|
||||
return array_append_items(array, items, item_num);
|
||||
}
|
||||
}
|
||||
|
||||
if (item_num > header->Capacity)
|
||||
{
|
||||
@ -358,7 +358,7 @@ bool array_reserve(Array<Type>* array, usize new_capacity)
|
||||
ArrayHeader* header = array_get_header(array);
|
||||
|
||||
if (header->Capacity < new_capacity)
|
||||
return set_capacity(array, new_capacity);
|
||||
return set_capacity(array, new_capacity);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -377,7 +377,7 @@ bool array_resize(Array<Type>* array, usize num)
|
||||
}
|
||||
|
||||
header->Num = num;
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class Type> inline
|
||||
@ -493,23 +493,23 @@ struct HashTable
|
||||
Array<ssize> Hashes;
|
||||
Array<HashTableEntry<Type>> Entries;
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
#pragma region Member Mapping
|
||||
forceinline static HashTable init(AllocatorInfo allocator) { return GEN_NS hashtable_init<Type>(allocator); }
|
||||
forceinline static HashTable init_reserve(AllocatorInfo allocator, usize num) { return GEN_NS hashtable_init_reserve<Type>(allocator, num); }
|
||||
forceinline static HashTable init(AllocatorInfo allocator) { return hashtable_init<Type>(allocator); }
|
||||
forceinline static HashTable init_reserve(AllocatorInfo allocator, usize num) { return hashtable_init_reserve<Type>(allocator, num); }
|
||||
|
||||
forceinline void clear() { GEN_NS clear<Type>(*this); }
|
||||
forceinline void destroy() { GEN_NS destroy<Type>(*this); }
|
||||
forceinline Type* get(u64 key) { return GEN_NS get<Type>(*this, key); }
|
||||
forceinline void grow() { GEN_NS grow<Type>(*this); }
|
||||
forceinline void rehash(ssize new_num) { GEN_NS rehash<Type>(*this, new_num); }
|
||||
forceinline void rehash_fast() { GEN_NS rehash_fast<Type>(*this); }
|
||||
forceinline void remove(u64 key) { GEN_NS remove<Type>(*this, key); }
|
||||
forceinline void remove_entry(ssize idx) { GEN_NS remove_entry<Type>(*this, idx); }
|
||||
forceinline void set(u64 key, Type value) { GEN_NS set<Type>(*this, key, value); }
|
||||
forceinline ssize slot(u64 key) { return GEN_NS slot<Type>(*this, key); }
|
||||
forceinline void map(void (*proc)(u64, Type)) { GEN_NS map<Type>(*this, proc); }
|
||||
forceinline void map_mut(void (*proc)(u64, Type*)) { GEN_NS map_mut<Type>(*this, proc); }
|
||||
forceinline void clear() { clear<Type>(*this); }
|
||||
forceinline void destroy() { destroy<Type>(*this); }
|
||||
forceinline Type* get(u64 key) { return get<Type>(*this, key); }
|
||||
forceinline void grow() { grow<Type>(*this); }
|
||||
forceinline void rehash(ssize new_num) { rehash<Type>(*this, new_num); }
|
||||
forceinline void rehash_fast() { rehash_fast<Type>(*this); }
|
||||
forceinline void remove(u64 key) { remove<Type>(*this, key); }
|
||||
forceinline void remove_entry(ssize idx) { remove_entry<Type>(*this, idx); }
|
||||
forceinline void set(u64 key, Type value) { set<Type>(*this, key, value); }
|
||||
forceinline ssize slot(u64 key) { return slot<Type>(*this, key); }
|
||||
forceinline void map(void (*proc)(u64, Type)) { map<Type>(*this, proc); }
|
||||
forceinline void map_mut(void (*proc)(u64, Type*)) { map_mut<Type>(*this, proc); }
|
||||
#pragma endregion Member Mapping
|
||||
#endif
|
||||
|
||||
|
@ -7,9 +7,9 @@
|
||||
|
||||
#pragma region Debug
|
||||
|
||||
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... )
|
||||
void assert_handler( char const* condition, char const* file, char const* function, s32 line, char const* msg, ... )
|
||||
{
|
||||
_printf_err( "%s:(%d): Assert Failure: ", file, line );
|
||||
_printf_err( "%s - %s:(%d): Assert Failure: ", file, function, line );
|
||||
|
||||
if ( condition )
|
||||
_printf_err( "`%s` \n", condition );
|
||||
|
@ -19,14 +19,14 @@
|
||||
|
||||
#define GEN_ASSERT( cond ) GEN_ASSERT_MSG( cond, NULL )
|
||||
|
||||
#define GEN_ASSERT_MSG( cond, msg, ... ) \
|
||||
do \
|
||||
{ \
|
||||
if ( ! ( cond ) ) \
|
||||
{ \
|
||||
assert_handler( #cond, __FILE__, scast( s64, __LINE__ ), msg, ##__VA_ARGS__ ); \
|
||||
GEN_DEBUG_TRAP(); \
|
||||
} \
|
||||
#define GEN_ASSERT_MSG( cond, msg, ... ) \
|
||||
do \
|
||||
{ \
|
||||
if ( ! ( cond ) ) \
|
||||
{ \
|
||||
assert_handler( #cond, __FILE__, __func__, scast( s64, __LINE__ ), msg, ##__VA_ARGS__ ); \
|
||||
GEN_DEBUG_TRAP(); \
|
||||
} \
|
||||
} while ( 0 )
|
||||
|
||||
#define GEN_ASSERT_NOT_NULL( ptr ) GEN_ASSERT_MSG( ( ptr ) != NULL, #ptr " must not be NULL" )
|
||||
@ -56,7 +56,7 @@
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... );
|
||||
void assert_handler( char const* condition, char const* file, char const* function, s32 line, char const* msg, ... );
|
||||
s32 assert_crash( char const* condition );
|
||||
void process_exit( u32 code );
|
||||
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
#pragma region File Handling
|
||||
|
||||
typedef u32 FileMode;
|
||||
|
||||
enum FileModeFlag
|
||||
{
|
||||
EFileMode_READ = bit( 0 ),
|
||||
@ -45,6 +43,7 @@ union FileDescriptor
|
||||
uptr u;
|
||||
};
|
||||
|
||||
typedef u32 FileMode;
|
||||
typedef struct FileOperations FileOperations;
|
||||
|
||||
#define GEN_FILE_OPEN_PROC( name ) FileError name( FileDescriptor* fd, FileOperations* ops, FileMode mode, char const* filename )
|
||||
@ -107,7 +106,6 @@ struct FileInfo
|
||||
FileTime last_write_time;
|
||||
DirEntry* dir;
|
||||
};
|
||||
typedef struct FileInfo FileInfo;
|
||||
|
||||
enum FileStandardType
|
||||
{
|
||||
@ -117,7 +115,6 @@ enum FileStandardType
|
||||
|
||||
EFileStandard_COUNT,
|
||||
};
|
||||
typedef enum FileStandardType FileStandardType;
|
||||
|
||||
/**
|
||||
* Get standard file I/O.
|
||||
|
@ -322,17 +322,17 @@
|
||||
|
||||
// Below are generated on demand for an overlaod depdendent on a type:
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
#define GEN_FUNCTION_GENERIC_EXAMPLE( selector_arg ) _Generic( \
|
||||
(selector_arg), /* Select Via Expression*/ \
|
||||
/* Extendibility slots: */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST(FunctionID__ARGS_SIG_1 ) \
|
||||
#define GEN_FUNCTION_GENERIC_EXAMPLE( selector_arg ) _Generic( \
|
||||
(selector_arg), /* Select Via Expression*/ \
|
||||
/* Extendibility slots: */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST(FunctionID__ARGS_SIG_1 ) \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( selector_arg )
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -355,17 +355,17 @@ size_t gen_example_hash__P_long_long( long long val ) { return val * 2654435761u
|
||||
|
||||
// If using an Editor with support for syntax hightlighting macros: HASH__ARGS_SIG_1 and HASH_ARGS_SIG_2 should show color highlighting indicating the slot is enabled,
|
||||
// or, "defined" for usage during the compilation pass that handles the _Generic instrinsic.
|
||||
#define hash( function_arguments ) _Generic( \
|
||||
(function_arguments), /* Select Via Expression*/ \
|
||||
/* Extendibility slots: */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_2 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_3 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_4 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_5 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_6 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_7 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST( HASH__ARGS_SIG_8 ) \
|
||||
#define hash( function_arguments ) _Generic( \
|
||||
(function_arguments), /* Select Via Expression*/ \
|
||||
/* Extendibility slots: */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_2 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_3 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_4 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_5 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_6 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_7 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST( HASH__ARGS_SIG_8 ) \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( function_arguments )
|
||||
|
||||
// Additional Variations:
|
||||
|
@ -193,17 +193,17 @@ struct Arena
|
||||
ssize TotalUsed;
|
||||
ssize TempCount;
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
#pragma region Member Mapping
|
||||
forceinline operator AllocatorInfo() { return GEN_NS arena_allocator_info(this); }
|
||||
forceinline operator AllocatorInfo() { return arena_allocator_info(this); }
|
||||
|
||||
forceinline static void* allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags ) { return GEN_NS arena_allocator_proc( allocator_data, type, size, alignment, old_memory, old_size, flags ); }
|
||||
forceinline static Arena init_from_memory( void* start, ssize size ) { return GEN_NS arena_init_from_memory( start, size ); }
|
||||
forceinline static Arena init_from_allocator( AllocatorInfo backing, ssize size ) { return GEN_NS arena_init_from_allocator( backing, size ); }
|
||||
forceinline static Arena init_sub( Arena& parent, ssize size ) { return GEN_NS arena_init_from_allocator( parent.Backing, size ); }
|
||||
forceinline ssize alignment_of( ssize alignment ) { return GEN_NS arena_alignment_of(this, alignment); }
|
||||
forceinline void free() { return GEN_NS arena_free(this); }
|
||||
forceinline ssize size_remaining( ssize alignment ) { return GEN_NS arena_size_remaining(this, alignment); }
|
||||
forceinline static void* allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags ) { return arena_allocator_proc( allocator_data, type, size, alignment, old_memory, old_size, flags ); }
|
||||
forceinline static Arena init_from_memory( void* start, ssize size ) { return arena_init_from_memory( start, size ); }
|
||||
forceinline static Arena init_from_allocator( AllocatorInfo backing, ssize size ) { return arena_init_from_allocator( backing, size ); }
|
||||
forceinline static Arena init_sub( Arena& parent, ssize size ) { return arena_init_from_allocator( parent.Backing, size ); }
|
||||
forceinline ssize alignment_of( ssize alignment ) { return arena_alignment_of(this, alignment); }
|
||||
forceinline void free() { return arena_free(this); }
|
||||
forceinline ssize size_remaining( ssize alignment ) { return arena_size_remaining(this, alignment); }
|
||||
|
||||
// This id is defined by Unreal for asserts
|
||||
#pragma push_macro("check")
|
||||
@ -320,7 +320,7 @@ template<s32 Size> FixedArena<Size> fixed_arena_init();
|
||||
template<s32 Size> AllocatorInfo fixed_arena_allocator_info(FixedArena<Size>* fixed_arena );
|
||||
template<s32 Size> ssize fixed_arena_size_remaining(FixedArena<Size>* fixed_arena, ssize alignment);
|
||||
|
||||
#if 0
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
template<s32 Size> AllocatorInfo allocator_info( FixedArena<Size>& fixed_arena ) { return allocator_info(& fixed_arena); }
|
||||
template<s32 Size> ssize size_remaining(FixedArena<Size>& fixed_arena, ssize alignment) { return size_remaining( & fixed_arena, alignment); }
|
||||
#endif
|
||||
@ -333,12 +333,12 @@ struct FixedArena
|
||||
char memory[Size];
|
||||
Arena arena;
|
||||
|
||||
#if 0
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
#pragma region Member Mapping
|
||||
forceinline operator AllocatorInfo() { return GEN_NS allocator_info(this); }
|
||||
|
||||
forceinline static FixedArena init() { FixedArena result; GEN_NS fixed_arena_init<Size>(result); return result; }
|
||||
forceinline ssize size_remaining(ssize alignment) { GEN_NS size_remaining(this, alignment); }
|
||||
forceinline static FixedArena init() { FixedArena result; fixed_arena_init<Size>(result); return result; }
|
||||
forceinline ssize size_remaining(ssize alignment) { fixed_arena_size_remaining(this, alignment); }
|
||||
#pragma endregion Member Mapping
|
||||
#endif
|
||||
};
|
||||
@ -390,7 +390,7 @@ AllocatorInfo pool_allocator_info(Pool* pool);
|
||||
void pool_clear(Pool* pool);
|
||||
void pool_free(Pool* pool);
|
||||
|
||||
#if 0
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
AllocatorInfo allocator_info(Pool& pool) { return pool_allocator_info(& pool); }
|
||||
void clear(Pool& pool) { return pool_clear(& pool); }
|
||||
void free(Pool& pool) { return pool_free(& pool); }
|
||||
@ -406,15 +406,15 @@ struct Pool
|
||||
ssize TotalSize;
|
||||
ssize NumBlocks;
|
||||
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
#pragma region Member Mapping
|
||||
forceinline operator AllocatorInfo() { return GEN_NS pool_allocator_info(this); }
|
||||
forceinline operator AllocatorInfo() { return pool_allocator_info(this); }
|
||||
|
||||
forceinline static void* allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags) { return GEN_NS pool_allocator_proc(allocator_data, type, size, alignment, old_memory, old_size, flags); }
|
||||
forceinline static Pool init(AllocatorInfo backing, ssize num_blocks, ssize block_size) { return GEN_NS pool_init(backing, num_blocks, block_size); }
|
||||
forceinline static Pool init_align(AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align) { return GEN_NS pool_init_align(backing, num_blocks, block_size, block_align); }
|
||||
forceinline void clear() { GEN_NS pool_clear( this); }
|
||||
forceinline void free() { GEN_NS pool_free( this); }
|
||||
forceinline static void* allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags) { return pool_allocator_proc(allocator_data, type, size, alignment, old_memory, old_size, flags); }
|
||||
forceinline static Pool init(AllocatorInfo backing, ssize num_blocks, ssize block_size) { return pool_init(backing, num_blocks, block_size); }
|
||||
forceinline static Pool init_align(AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align) { return pool_init_align(backing, num_blocks, block_size, block_align); }
|
||||
forceinline void clear() { pool_clear( this); }
|
||||
forceinline void free() { pool_free( this); }
|
||||
#pragma endregion
|
||||
#endif
|
||||
};
|
||||
@ -427,14 +427,14 @@ AllocatorInfo pool_allocator_info(Pool* pool) {
|
||||
|
||||
inline
|
||||
Pool pool_init(AllocatorInfo backing, ssize num_blocks, ssize block_size) {
|
||||
return pool_init_align(backing, num_blocks, block_size, GEN_DEFAULT_MEMORY_ALIGNMENT);
|
||||
return pool_init_align(backing, num_blocks, block_size, GEN_DEFAULT_MEMORY_ALIGNMENT);
|
||||
}
|
||||
|
||||
inline
|
||||
void pool_free(Pool* pool) {
|
||||
if(pool->Backing.Proc) {
|
||||
allocator_free(pool->Backing, pool->PhysicalStart);
|
||||
}
|
||||
if(pool->Backing.Proc) {
|
||||
allocator_free(pool->Backing, pool->PhysicalStart);
|
||||
}
|
||||
}
|
||||
#pragma endregion Pool
|
||||
|
||||
|
@ -5,8 +5,7 @@
|
||||
|
||||
#pragma region Strings
|
||||
|
||||
struct StrC_Def;
|
||||
typedef struct StrC_Def StrC;
|
||||
struct StrC;
|
||||
|
||||
bool strc_are_equal (StrC lhs, StrC rhs);
|
||||
char const* strc_back (StrC str);
|
||||
@ -17,7 +16,7 @@ StrC strc_to_str (char const* bad_string);
|
||||
StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator);
|
||||
|
||||
// Constant string with length.
|
||||
struct StrC_Def
|
||||
struct StrC
|
||||
{
|
||||
ssize Len;
|
||||
char const* Ptr;
|
||||
@ -27,12 +26,12 @@ struct StrC_Def
|
||||
forceinline char const& operator[]( ssize index ) const { return Ptr[index]; }
|
||||
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
forceinline bool is_equal (StrC rhs) const { return GEN_NS strc_are_equal(* this, rhs); }
|
||||
forceinline char const* back () const { return GEN_NS strc_back(* this); }
|
||||
forceinline bool contains (StrC substring) const { return GEN_NS strc_contains(* this, substring); }
|
||||
forceinline StrC duplicate (AllocatorInfo allocator) const { return GEN_NS strc_duplicate(* this, allocator); }
|
||||
forceinline b32 starts_with (StrC substring) const { return GEN_NS strc_starts_with(* this, substring); }
|
||||
forceinline StrC visualize_whitespace(AllocatorInfo allocator) const { return GEN_NS strc_visualize_whitespace(* this, allocator); }
|
||||
forceinline bool is_equal (StrC rhs) const { return strc_are_equal(* this, rhs); }
|
||||
forceinline char const* back () const { return strc_back(* this); }
|
||||
forceinline bool contains (StrC substring) const { return strc_contains(* this, substring); }
|
||||
forceinline StrC duplicate (AllocatorInfo allocator) const { return strc_duplicate(* this, allocator); }
|
||||
forceinline b32 starts_with (StrC substring) const { return strc_starts_with(* this, substring); }
|
||||
forceinline StrC visualize_whitespace(AllocatorInfo allocator) const { return strc_visualize_whitespace(* this, allocator); }
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
@ -113,8 +112,7 @@ StrC to_strc_from_c_str( char const* bad_str ) {
|
||||
// They used a header pattern
|
||||
// I kept it for simplicty of porting but its not necessary to keep it that way.
|
||||
#pragma region String
|
||||
struct StringHeader;
|
||||
typedef struct StringHeader StringHeader;
|
||||
struct StringHeader;
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
typedef char* String;
|
||||
@ -267,11 +265,9 @@ struct String
|
||||
};
|
||||
#endif
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
forceinline char* string_begin(String str) { return ((char*) str); }
|
||||
forceinline char* string_end (String str) { return ((char*) str + string_length(str)); }
|
||||
forceinline char* string_next (String str, char const* iter) { return ((char*) iter + 1); }
|
||||
GEN_API_C_END
|
||||
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
forceinline char* begin(String str) { return ((char*) str); }
|
||||
@ -488,18 +484,18 @@ bool string_contains_string(String const str, String const substring)
|
||||
|
||||
forceinline
|
||||
ssize string_capacity(String const str) {
|
||||
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
|
||||
return header->Capacity;
|
||||
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
|
||||
return header->Capacity;
|
||||
}
|
||||
|
||||
forceinline
|
||||
void string_clear(String str) {
|
||||
string_get_header(str)->Length = 0;
|
||||
string_get_header(str)->Length = 0;
|
||||
}
|
||||
|
||||
forceinline
|
||||
String string_duplicate(String const str, AllocatorInfo allocator) {
|
||||
return string_make_length(allocator, str, string_length(str));
|
||||
return string_make_length(allocator, str, string_length(str));
|
||||
}
|
||||
|
||||
forceinline
|
||||
@ -514,14 +510,14 @@ void string_free(String* str) {
|
||||
|
||||
forceinline
|
||||
StringHeader* string_get_header(String str) {
|
||||
return (StringHeader*)(scast(char*, str) - sizeof(StringHeader));
|
||||
return (StringHeader*)(scast(char*, str) - sizeof(StringHeader));
|
||||
}
|
||||
|
||||
forceinline
|
||||
ssize string_length(String const str)
|
||||
{
|
||||
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
|
||||
return header->Length;
|
||||
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
|
||||
return header->Length;
|
||||
}
|
||||
|
||||
inline
|
||||
@ -586,7 +582,7 @@ void string_skip_line(String str)
|
||||
#define current (*scanner)
|
||||
char* scanner = str;
|
||||
while (current != '\r' && current != '\n') {
|
||||
++scanner;
|
||||
++scanner;
|
||||
}
|
||||
|
||||
s32 new_length = scanner - str;
|
||||
@ -605,23 +601,22 @@ void string_skip_line(String str)
|
||||
inline
|
||||
void strip_space(String str)
|
||||
{
|
||||
char* write_pos = str;
|
||||
char* read_pos = str;
|
||||
|
||||
while (* read_pos)
|
||||
{
|
||||
if (! char_is_space(* read_pos))
|
||||
{
|
||||
* write_pos = * read_pos;
|
||||
write_pos++;
|
||||
}
|
||||
read_pos++;
|
||||
}
|
||||
char* write_pos = str;
|
||||
char* read_pos = str;
|
||||
|
||||
while (* read_pos)
|
||||
{
|
||||
if (! char_is_space(* read_pos))
|
||||
{
|
||||
* write_pos = * read_pos;
|
||||
write_pos++;
|
||||
}
|
||||
read_pos++;
|
||||
}
|
||||
write_pos[0] = '\0'; // Null-terminate the modified string
|
||||
|
||||
// Update the length if needed
|
||||
string_get_header(str)->Length = write_pos - str;
|
||||
// Update the length if needed
|
||||
string_get_header(str)->Length = write_pos - str;
|
||||
}
|
||||
|
||||
forceinline
|
||||
@ -651,12 +646,12 @@ void trim(String str, char const* cut_set)
|
||||
|
||||
str[len] = '\0';
|
||||
|
||||
string_get_header(str)->Length = len;
|
||||
string_get_header(str)->Length = len;
|
||||
}
|
||||
|
||||
forceinline
|
||||
void trim_space(String str) {
|
||||
trim(str, " \t\r\n\v\f");
|
||||
trim(str, " \t\r\n\v\f");
|
||||
}
|
||||
|
||||
inline
|
||||
@ -712,7 +707,7 @@ inline
|
||||
StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator)
|
||||
{
|
||||
String result = string_make_reserve(allocator, str.Len * 2); // Assume worst case for space requirements.
|
||||
for (char const* c = strc_begin(str); c != strc_end(str); c = strc_next(str, c))
|
||||
for (char const* c = strc_begin(str); c != strc_end(str); c = strc_next(str, c))
|
||||
switch ( * c )
|
||||
{
|
||||
case ' ':
|
||||
|
Reference in New Issue
Block a user