BLO: Read API: Add a new function taking a DNA type name as 'type' parameter.

Somewhat mirrors similar API in the write code, allows to do properly
typed-read calls on some 'generic' types like constraints, customdata,
etc., which have a 'TypeInfo' system storing their DNA struct names.
This commit is contained in:
Bastien Montagne
2024-07-31 19:19:54 +02:00
parent b5b13fec4c
commit 7a897bfdb9
2 changed files with 23 additions and 0 deletions

View File

@@ -291,6 +291,17 @@ void *BLO_read_struct_array_with_size(BlendDataReader *reader,
*((void **)ptr_p) = BLO_read_struct_array_with_size( \
reader, *((void **)ptr_p), sizeof(struct_name) * (array_size))
/**
* Similar to #BLO_read_struct_array_with_size, but can use a (DNA) type name instead of the type
* itself to find the expected data size.
*
* Somewhat mirrors #BLO_write_struct_array_by_name.
*/
void *BLO_read_struct_by_name_array(BlendDataReader *reader,
const char *struct_name,
uint32_t items_num,
const void *old_address);
/* Read all elements in list
*
* Updates all `->prev` and `->next` pointers of the list elements.

View File

@@ -4823,6 +4823,18 @@ void *BLO_read_struct_array_with_size(BlendDataReader *reader,
return blo_verify_data_address(new_address, old_address, expected_size);
}
void *BLO_read_struct_by_name_array(BlendDataReader *reader,
const char *struct_name,
const uint32_t items_num,
const void *old_address)
{
const int struct_index = DNA_struct_find_with_alias(reader->fd->memsdna, struct_name);
BLI_assert(STREQ(DNA_struct_identifier(const_cast<SDNA *>(reader->fd->memsdna), struct_index),
struct_name));
const size_t struct_size = size_t(DNA_struct_size(reader->fd->memsdna, struct_index));
return BLO_read_struct_array_with_size(reader, old_address, struct_size * items_num);
}
ID *BLO_read_get_new_id_address(BlendLibReader *reader,
ID *self_id,
const bool is_linked_only,