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:
@@ -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--) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user