Refactor: DNA: Add util to access size of a truct.

Avoids reafile code having to access 'internals' specifics of DNA data.
This commit is contained in:
Bastien Montagne
2024-07-29 17:23:42 +02:00
parent bae9a93d62
commit 97982360de
4 changed files with 15 additions and 4 deletions

View File

@@ -1697,7 +1697,8 @@ static void switch_endian_structs(const SDNA *filesdna, BHead *bhead)
char *data;
data = (char *)(bhead + 1);
blocksize = filesdna->types_size[filesdna->structs[bhead->SDNAnr]->type];
blocksize = DNA_struct_size(filesdna, bhead->SDNAnr);
nblocks = bhead->nr;
while (nblocks--) {

View File

@@ -738,9 +738,7 @@ static void writestruct_at_address_nr(
bh.nr = nr;
bh.SDNAnr = struct_nr;
const SDNA_Struct *struct_info = wd->sdna->structs[bh.SDNAnr];
bh.len = nr * wd->sdna->types_size[struct_info->type];
bh.len = nr * DNA_struct_size(wd->sdna, bh.SDNAnr);
if (bh.len == 0) {
return;

View File

@@ -192,6 +192,13 @@ int DNA_struct_member_size(const struct SDNA *sdna, short type, short name);
*/
int DNA_elem_type_size(eSDNA_Type elem_nr);
/**
* Returns the size of a struct.
*
* \param struct_index: Index into the #sdna.structs array (aka #BHead.SDNAnr).
*/
int DNA_struct_size(const struct SDNA *sdna, int struct_index);
/**
* Get the alignment that should be used when allocating memory for this type.
*/

View File

@@ -156,6 +156,11 @@ void DNA_sdna_free(SDNA *sdna)
MEM_freeN(sdna);
}
int DNA_struct_size(const SDNA *sdna, int struct_index)
{
return sdna->types_size[sdna->structs[struct_index]->type];
}
/**
* Return true if the name indicates a pointer of some kind.
*/