2024-11-30 22:40:14 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../project/gen.hpp"
|
|
|
|
|
|
|
|
using namespace gen;
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
// Used to know what slot the array will be for generic selection
|
2024-12-05 20:02:26 -08:00
|
|
|
global s32 Array_DefinitionCounter = 0;
|
2024-12-05 14:04:17 -08:00
|
|
|
|
2024-11-30 22:40:14 -08:00
|
|
|
CodeBody gen_array_base()
|
|
|
|
{
|
|
|
|
CodeTypedef td_header = parse_typedef( code( typedef struct ArrayHeader ArrayHeader; ));
|
|
|
|
CodeStruct header = parse_struct( code(
|
|
|
|
struct ArrayHeader
|
|
|
|
{
|
|
|
|
AllocatorInfo Allocator;
|
|
|
|
usize Capacity;
|
|
|
|
usize Num;
|
|
|
|
};
|
|
|
|
));
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
Code grow_formula = untyped_str( txt( "#define array_grow_formula( value ) ( 2 * value + 8 )\n" ));
|
|
|
|
Code get_header = untyped_str( txt( "#define array_get_header( self ) ( (ArrayHeader*)( self ) - 1)\n" ));
|
2024-12-08 13:37:04 -08:00
|
|
|
Code type_define = untyped_str( txt( "#define Array(Type) Array_##Type\n"));
|
2024-11-30 22:40:14 -08:00
|
|
|
|
2024-12-08 13:37:04 -08:00
|
|
|
return def_global_body( args( fmt_newline, td_header, header, type_define, grow_formula, get_header, fmt_newline ) );
|
2024-11-30 22:40:14 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
CodeBody gen_array( StrC type, StrC array_name )
|
|
|
|
{
|
|
|
|
String array_type = String::fmt_buf( GlobalAllocator, "%.*s", array_name.Len, array_name.Ptr );
|
|
|
|
String fn = String::fmt_buf( GlobalAllocator, "%.*s", array_name.Len, array_name.Ptr );
|
2024-12-05 14:04:17 -08:00
|
|
|
// str_to_lower(fn.Data);
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
#pragma push_macro( "GEN_ASSERT" )
|
2024-12-05 14:04:17 -08:00
|
|
|
#pragma push_macro( "rcast" )
|
|
|
|
#pragma push_macro( "cast" )
|
2024-12-05 18:01:04 -08:00
|
|
|
#pragma push_macro( "typeof" )
|
|
|
|
#pragma push_macro( "forceinline" )
|
2024-11-30 22:40:14 -08:00
|
|
|
#undef GEN_ASSERT
|
2024-12-05 14:04:17 -08:00
|
|
|
#undef rcast
|
|
|
|
#undef cast
|
2024-12-05 18:01:04 -08:00
|
|
|
#undef typeof
|
|
|
|
#undef forceinline
|
2024-11-30 22:40:14 -08:00
|
|
|
CodeBody result = parse_global_body( token_fmt( "array_type", (StrC)array_type, "fn", (StrC)fn, "type", (StrC)type
|
|
|
|
, stringize(
|
|
|
|
typedef <type>* <array_type>;
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
<array_type> <fn>_init ( AllocatorInfo allocator );
|
|
|
|
<array_type> <fn>_init_reserve ( AllocatorInfo allocator, usize capacity );
|
2024-12-05 14:48:24 -08:00
|
|
|
bool <fn>_append_array ( <array_type>* self, <array_type> other );
|
|
|
|
bool <fn>_append ( <array_type>* self, <type> value );
|
|
|
|
bool <fn>_append_items ( <array_type>* self, <type>* items, usize item_num );
|
|
|
|
bool <fn>_append_at ( <array_type>* self, <type> item, usize idx );
|
|
|
|
bool <fn>_append_items_at( <array_type>* self, <type>* items, usize item_num, usize idx );
|
|
|
|
<type>* <fn>_back ( <array_type> self );
|
|
|
|
void <fn>_clear ( <array_type> self );
|
|
|
|
bool <fn>_fill ( <array_type> self, usize begin, usize end, <type> value );
|
|
|
|
void <fn>_free ( <array_type>* self );
|
|
|
|
bool <fn>_grow ( <array_type>* self, usize min_capacity );
|
|
|
|
usize <fn>_num ( <array_type> self );
|
|
|
|
<type> <fn>_pop ( <array_type> self );
|
|
|
|
void <fn>_remove_at ( <array_type> self, usize idx );
|
|
|
|
bool <fn>_reserve ( <array_type>* self, usize new_capacity );
|
|
|
|
bool <fn>_resize ( <array_type>* self, usize num );
|
|
|
|
bool <fn>_set_capacity ( <array_type>* self, usize new_capacity );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
forceinline
|
|
|
|
<array_type> <fn>_init( AllocatorInfo allocator )
|
2024-11-30 22:40:14 -08:00
|
|
|
{
|
2024-12-05 14:04:17 -08:00
|
|
|
size_t initial_size = array_grow_formula(0);
|
2024-12-08 13:37:04 -08:00
|
|
|
return array_init_reserve( <type>, allocator, initial_size );
|
2024-11-30 22:40:14 -08:00
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
|
|
|
<array_type> <fn>_init_reserve( AllocatorInfo allocator, usize capacity )
|
2024-11-30 22:40:14 -08:00
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT(capacity > 0);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = rcast(ArrayHeader*, alloc(allocator, sizeof(ArrayHeader) + sizeof(<type>) * capacity));
|
2024-11-30 22:40:14 -08:00
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
if (header == nullptr)
|
2024-12-05 18:01:04 -08:00
|
|
|
return nullptr;
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
header->Allocator = allocator;
|
|
|
|
header->Capacity = capacity;
|
|
|
|
header->Num = 0;
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
return rcast(<type>*, header + 1);
|
2024-12-05 14:04:17 -08:00
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
forceinline
|
2024-12-05 14:04:17 -08:00
|
|
|
bool <fn>_append_array( <array_type>* self, <array_type> other )
|
|
|
|
{
|
|
|
|
return array_append_items( * self, (<array_type>)other, <fn>_num(other));
|
2024-11-30 22:40:14 -08:00
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
bool <fn>_append( <array_type>* self, <type> value )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
|
|
|
GEN_ASSERT(* self != nullptr);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
if ( header->Num == header->Capacity )
|
|
|
|
{
|
2024-12-05 14:04:17 -08:00
|
|
|
if ( ! array_grow( self, header->Capacity))
|
2024-11-30 22:40:14 -08:00
|
|
|
return false;
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
(* self)[ header->Num ] = value;
|
|
|
|
header->Num++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
bool <fn>_append_items( <array_type>* self, <type>* items, usize item_num )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
|
|
|
GEN_ASSERT(* self != nullptr);
|
|
|
|
GEN_ASSERT(items != nullptr);
|
|
|
|
GEN_ASSERT(item_num > 0);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
if ( header->Num + item_num > header->Capacity )
|
|
|
|
{
|
2024-12-05 14:04:17 -08:00
|
|
|
if ( ! array_grow( self, header->Capacity + item_num ))
|
2024-11-30 22:40:14 -08:00
|
|
|
return false;
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
mem_copy( (* self) + header->Num, items, sizeof(<type>) * item_num );
|
|
|
|
header->Num += item_num;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
bool <fn>_append_at( <array_type>* self, <type> item, usize idx )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
|
|
|
GEN_ASSERT(* self != nullptr);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
if ( idx >= header->Num )
|
|
|
|
idx = header->Num - 1;
|
|
|
|
|
|
|
|
if ( idx < 0 )
|
|
|
|
idx = 0;
|
|
|
|
|
|
|
|
if ( header->Capacity < header->Num + 1 )
|
|
|
|
{
|
2024-12-05 14:04:17 -08:00
|
|
|
if ( ! array_grow( self, header->Capacity + 1 ) )
|
2024-11-30 22:40:14 -08:00
|
|
|
return false;
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
<array_type> target = (* self) + idx;
|
|
|
|
|
|
|
|
mem_move( target + 1, target, (header->Num - idx) * sizeof(<type>) );
|
|
|
|
header->Num++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
bool <fn>_append_items_at( <array_type>* self, <type>* items, usize item_num, usize idx )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
|
|
|
GEN_ASSERT(* self != nullptr);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
if ( idx >= header->Num )
|
|
|
|
{
|
2024-12-05 14:04:17 -08:00
|
|
|
return array_append_items( * self, items, item_num );
|
2024-11-30 22:40:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( item_num > header->Capacity )
|
|
|
|
{
|
2024-12-05 14:04:17 -08:00
|
|
|
if ( ! array_grow( self, item_num + header->Capacity ) )
|
2024-11-30 22:40:14 -08:00
|
|
|
return false;
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
<type>* target = (* self) + idx + item_num;
|
|
|
|
<type>* src = (* self) + idx;
|
|
|
|
|
|
|
|
mem_move( target, src, (header->Num - idx) * sizeof(<type>) );
|
|
|
|
mem_copy( src, items, item_num * sizeof(<type>) );
|
|
|
|
header->Num += item_num;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
<type>* <fn>_back( <array_type> self )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT(self != nullptr);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( self );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
if ( header->Num == 0 )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return self + header->Num - 1;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
void <fn>_clear( <array_type> self )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT(self != nullptr);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( self );
|
2024-11-30 22:40:14 -08:00
|
|
|
header->Num = 0;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
bool <fn>_fill( <array_type> self, usize begin, usize end, <type> value )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT(self != nullptr);
|
|
|
|
GEN_ASSERT(begin <= end);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( self );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
if ( begin < 0 || end >= header->Num )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for ( ssize idx = begin; idx < end; idx ++ )
|
|
|
|
self[ idx ] = value;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-12-05 14:48:24 -08:00
|
|
|
void <fn>_free( <array_type>* self )
|
2024-11-30 22:40:14 -08:00
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
|
|
|
GEN_ASSERT(* self != nullptr);
|
2024-12-05 14:48:24 -08:00
|
|
|
ArrayHeader* header = array_get_header( * self );
|
2024-12-05 14:04:17 -08:00
|
|
|
allocator_free( header->Allocator, header );
|
2024-11-30 22:40:14 -08:00
|
|
|
self = NULL;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
bool <fn>_grow( <array_type>* self, usize min_capacity )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
|
|
|
GEN_ASSERT(* self != nullptr);
|
|
|
|
GEN_ASSERT( min_capacity > 0 );
|
|
|
|
ArrayHeader* header = array_get_header( *self );
|
|
|
|
usize new_capacity = array_grow_formula( header->Capacity );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
if ( new_capacity < min_capacity )
|
|
|
|
new_capacity = min_capacity;
|
|
|
|
|
2024-12-05 14:48:24 -08:00
|
|
|
return array_set_capacity( self, new_capacity );
|
2024-11-30 22:40:14 -08:00
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
forceinline
|
2024-11-30 22:40:14 -08:00
|
|
|
usize <fn>_num( <array_type> self )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
2024-12-05 14:04:17 -08:00
|
|
|
return array_get_header(self)->Num;
|
2024-11-30 22:40:14 -08:00
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
<type> <fn>_pop( <array_type> self )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( self );
|
2024-11-30 22:40:14 -08:00
|
|
|
GEN_ASSERT( header->Num > 0 );
|
|
|
|
|
|
|
|
<type> result = self[ header->Num - 1 ];
|
|
|
|
header->Num--;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
forceinline
|
2024-11-30 22:40:14 -08:00
|
|
|
void <fn>_remove_at( <array_type> self, usize idx )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( self );
|
2024-11-30 22:40:14 -08:00
|
|
|
GEN_ASSERT( idx < header->Num );
|
|
|
|
|
|
|
|
mem_move( self + idx, self + idx + 1, sizeof( <type> ) * ( header->Num - idx - 1 ) );
|
|
|
|
header->Num--;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
bool <fn>_reserve( <array_type>* self, usize new_capacity )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
|
|
|
GEN_ASSERT(* self != nullptr);
|
|
|
|
GEN_ASSERT(new_capacity > 0);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
if ( header->Capacity < new_capacity )
|
2024-12-05 14:48:24 -08:00
|
|
|
return array_set_capacity( self, new_capacity );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
bool <fn>_resize( <array_type>* self, usize num )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
|
|
|
GEN_ASSERT(* self != nullptr);
|
|
|
|
GEN_ASSERT(num > 0);
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
if ( header->Capacity < num )
|
|
|
|
{
|
2024-12-05 14:04:17 -08:00
|
|
|
if ( ! array_grow( self, num ) )
|
2024-11-30 22:40:14 -08:00
|
|
|
return false;
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
header->Num = num;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
inline
|
2024-11-30 22:40:14 -08:00
|
|
|
bool <fn>_set_capacity( <array_type>* self, usize new_capacity )
|
|
|
|
{
|
2024-12-05 18:01:04 -08:00
|
|
|
GEN_ASSERT( self != nullptr);
|
|
|
|
GEN_ASSERT(* self != nullptr);
|
|
|
|
GEN_ASSERT( new_capacity > 0 );
|
2024-12-05 14:04:17 -08:00
|
|
|
ArrayHeader* header = array_get_header( * self );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
if ( new_capacity == header->Capacity )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ( new_capacity < header->Num )
|
2024-12-05 18:01:04 -08:00
|
|
|
{
|
2024-11-30 22:40:14 -08:00
|
|
|
header->Num = new_capacity;
|
2024-12-05 18:01:04 -08:00
|
|
|
return true;
|
|
|
|
}
|
2024-11-30 22:40:14 -08:00
|
|
|
|
2024-12-05 18:01:04 -08:00
|
|
|
usize size = sizeof( ArrayHeader ) + sizeof( <type> ) * new_capacity;
|
2024-11-30 22:40:14 -08:00
|
|
|
ArrayHeader* new_header = cast( ArrayHeader*, alloc( header->Allocator, size ));
|
|
|
|
|
|
|
|
if ( new_header == NULL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
mem_move( new_header, header, sizeof( ArrayHeader ) + sizeof( <type> ) * header->Num );
|
2024-12-05 18:01:04 -08:00
|
|
|
new_header->Capacity = new_capacity;
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
allocator_free( header->Allocator, & header );
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
* self = cast( <type>*, new_header + 1 );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)));
|
|
|
|
#pragma pop_macro( "GEN_ASSERT" )
|
2024-12-05 14:04:17 -08:00
|
|
|
#pragma pop_macro( "rcast" )
|
|
|
|
#pragma pop_macro( "cast" )
|
2024-12-05 18:01:04 -08:00
|
|
|
#pragma pop_macro( "typeof" )
|
|
|
|
#pragma pop_macro( "forceinline" )
|
2024-12-05 14:04:17 -08:00
|
|
|
|
2024-12-05 20:02:26 -08:00
|
|
|
++ Array_DefinitionCounter;
|
|
|
|
StrC slot_str = String::fmt_buf(GlobalAllocator, "%d", Array_DefinitionCounter).to_strc();
|
2024-12-05 14:04:17 -08:00
|
|
|
|
2024-12-08 13:37:04 -08:00
|
|
|
Code generic_interface_slot = untyped_str(token_fmt( "type", type, "array_type", (StrC)array_type, "slot", (StrC)slot_str,
|
|
|
|
R"(#define GENERIC_SLOT_<slot>__array_init <type>, <array_type>_init
|
|
|
|
#define GENERIC_SLOT_<slot>__array_init_reserve <type>, <array_type>_init_reserve
|
|
|
|
#define GENERIC_SLOT_<slot>__array_append <array_type>, <array_type>_append
|
|
|
|
#define GENERIC_SLOT_<slot>__array_append_items <array_type>, <array_type>_append_items
|
|
|
|
#define GENERIC_SLOT_<slot>__array_append_at <array_type>, <array_type>_append_at
|
|
|
|
#define GENERIC_SLOT_<slot>__array_append_items_at <array_type>, <array_type>_append_items_at
|
|
|
|
#define GENERIC_SLOT_<slot>__array_back <array_type>, <array_type>_back
|
|
|
|
#define GENERIC_SLOT_<slot>__array_clear <array_type>, <array_type>_clear
|
|
|
|
#define GENERIC_SLOT_<slot>__array_fill <array_type>, <array_type>_fill
|
|
|
|
#define GENERIC_SLOT_<slot>__array_free <array_type>, <array_type>_free
|
|
|
|
#define GENERIC_SLOT_<slot>__array_grow <array_type>*, <array_type>_grow
|
|
|
|
#define GENERIC_SLOT_<slot>__array_num <array_type>, <array_type>_num
|
|
|
|
#define GENERIC_SLOT_<slot>__array_pop <array_type>, <array_type>_pop
|
|
|
|
#define GENERIC_SLOT_<slot>__array_remove_at <array_type>, <array_type>_remove_at
|
|
|
|
#define GENERIC_SLOT_<slot>__array_reserve <array_type>, <array_type>_reserve
|
|
|
|
#define GENERIC_SLOT_<slot>__array_resize <array_type>, <array_type>_resize
|
|
|
|
#define GENERIC_SLOT_<slot>__array_set_capacity <array_type>*, <array_type>_set_capacity
|
2024-12-05 14:04:17 -08:00
|
|
|
)"
|
|
|
|
));
|
2024-11-30 22:40:14 -08:00
|
|
|
|
|
|
|
return def_global_body( args(
|
2024-12-04 08:30:54 -08:00
|
|
|
def_pragma( string_to_strc( string_fmt_buf( GlobalAllocator, "region %S", array_type ))),
|
2024-11-30 22:40:14 -08:00
|
|
|
fmt_newline,
|
2024-12-05 14:04:17 -08:00
|
|
|
generic_interface_slot,
|
|
|
|
fmt_newline,
|
2024-11-30 22:40:14 -08:00
|
|
|
result,
|
|
|
|
fmt_newline,
|
2024-12-04 08:30:54 -08:00
|
|
|
def_pragma( string_to_strc(string_fmt_buf( GlobalAllocator, "endregion %S", array_type ))),
|
2024-11-30 22:40:14 -08:00
|
|
|
fmt_newline
|
|
|
|
));
|
|
|
|
};
|
|
|
|
|
2024-12-05 14:04:17 -08:00
|
|
|
CodeBody gen_array_generic_selection_interface()
|
|
|
|
{
|
|
|
|
CodeBody interface_defines = def_body(CT_Global_Body);
|
2024-12-05 20:02:26 -08:00
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_init"), GenericSel_Direct_Type ));
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_init_reserve"), GenericSel_Direct_Type ));
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_append"), GenericSel_By_Ref ));
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_append_items"), GenericSel_By_Ref ));
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_back"), GenericSel_Default, GenericSel_One_Arg ));
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_clear"), GenericSel_Default, GenericSel_One_Arg ));
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_fill")) );
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_free"), GenericSel_By_Ref, GenericSel_One_Arg ) );
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_grow")) );
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_num"), GenericSel_Default, GenericSel_One_Arg ));
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_pop"), GenericSel_Default, GenericSel_One_Arg ));
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_remove_at")) );
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_reserve"), GenericSel_By_Ref) );
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_resize"), GenericSel_By_Ref) );
|
|
|
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_set_capacity")) );
|
2024-12-05 14:04:17 -08:00
|
|
|
return interface_defines;
|
|
|
|
}
|