Blender V4.3
BLO_read_write.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
31#pragma once
32
33/* for SDNA_TYPE_FROM_STRUCT() macro */
34#include "dna_type_offsets.h"
35
36#include "DNA_windowmanager_types.h" /* for eReportType */
37
38#include "BLI_function_ref.hh"
40
41namespace blender {
42class ImplicitSharingInfo;
43}
44struct BlendDataReader;
46struct BlendLibReader;
47struct BlendWriter;
48struct Main;
49
50/* -------------------------------------------------------------------- */
88int BLO_get_struct_id_by_name(const BlendWriter *writer, const char *struct_name);
89#define BLO_get_struct_id(writer, struct_name) SDNA_TYPE_FROM_STRUCT(struct_name)
90
94void BLO_write_struct_by_name(BlendWriter *writer, const char *struct_name, const void *data_ptr);
95void BLO_write_struct_by_id(BlendWriter *writer, int struct_id, const void *data_ptr);
96#define BLO_write_struct(writer, struct_name, data_ptr) \
97 BLO_write_struct_by_id(writer, BLO_get_struct_id(writer, struct_name), data_ptr)
98
103 int struct_id,
104 const void *address,
105 const void *data_ptr);
106#define BLO_write_struct_at_address(writer, struct_name, address, data_ptr) \
107 BLO_write_struct_at_address_by_id( \
108 writer, BLO_get_struct_id(writer, struct_name), address, data_ptr)
109
114 BlendWriter *writer, int filecode, int struct_id, const void *address, const void *data_ptr);
115#define BLO_write_struct_at_address_with_filecode( \
116 writer, filecode, struct_name, address, data_ptr) \
117 BLO_write_struct_at_address_by_id_with_filecode( \
118 writer, filecode, BLO_get_struct_id(writer, struct_name), address, data_ptr)
119
124 const char *struct_name,
125 int array_size,
126 const void *data_ptr);
128 int struct_id,
129 int array_size,
130 const void *data_ptr);
131#define BLO_write_struct_array(writer, struct_name, array_size, data_ptr) \
132 BLO_write_struct_array_by_id( \
133 writer, BLO_get_struct_id(writer, struct_name), array_size, data_ptr)
134
139 BlendWriter *writer, int struct_id, int array_size, const void *address, const void *data_ptr);
140#define BLO_write_struct_array_at_address(writer, struct_name, array_size, address, data_ptr) \
141 BLO_write_struct_array_at_address_by_id( \
142 writer, BLO_get_struct_id(writer, struct_name), array_size, address, data_ptr)
143
147void BLO_write_struct_list_by_name(BlendWriter *writer, const char *struct_name, ListBase *list);
148void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, const ListBase *list);
149#define BLO_write_struct_list(writer, struct_name, list_ptr) \
150 BLO_write_struct_list_by_id(writer, BLO_get_struct_id(writer, struct_name), list_ptr)
151
155void blo_write_id_struct(BlendWriter *writer, int struct_id, const void *id_address, const ID *id);
156#define BLO_write_id_struct(writer, struct_name, id_address, id) \
157 blo_write_id_struct(writer, BLO_get_struct_id(writer, struct_name), id_address, id)
158
167struct BLO_Write_IDBuffer;
168
170void BLO_write_init_id_buffer_from_id(BLO_Write_IDBuffer *id_buffer, ID *id, const bool is_undo);
173
188void BLO_write_raw(BlendWriter *writer, size_t size_in_bytes, const void *data_ptr);
192void BLO_write_char_array(BlendWriter *writer, uint num, const char *data_ptr);
193void BLO_write_int8_array(BlendWriter *writer, uint num, const int8_t *data_ptr);
194void BLO_write_uint8_array(BlendWriter *writer, uint num, const uint8_t *data_ptr);
195void BLO_write_int32_array(BlendWriter *writer, uint num, const int32_t *data_ptr);
196void BLO_write_uint32_array(BlendWriter *writer, uint num, const uint32_t *data_ptr);
197void BLO_write_float_array(BlendWriter *writer, uint num, const float *data_ptr);
198void BLO_write_double_array(BlendWriter *writer, uint num, const double *data_ptr);
199void BLO_write_float3_array(BlendWriter *writer, uint num, const float *data_ptr);
200void BLO_write_pointer_array(BlendWriter *writer, uint num, const void *data_ptr);
204void BLO_write_string(BlendWriter *writer, const char *data_ptr);
205
206/* Misc. */
207
217void BLO_write_shared(BlendWriter *writer,
218 const void *data,
219 size_t approximate_size_in_bytes,
220 const blender::ImplicitSharingInfo *sharing_info,
221 blender::FunctionRef<void()> write_fn);
222
227bool BLO_write_is_undo(BlendWriter *writer);
228
231/* -------------------------------------------------------------------- */
261void *BLO_read_get_new_data_address(BlendDataReader *reader, const void *old_address);
262#define BLO_read_data_address(reader, ptr_p) \
263 *((void **)ptr_p) = BLO_read_get_new_data_address((reader), *(ptr_p))
264
275 const void *old_address,
276 size_t expected_size);
277
285 const void *old_address,
286 size_t expected_size);
287#define BLO_read_struct(reader, struct_name, ptr_p) \
288 *((void **)ptr_p) = BLO_read_struct_array_with_size( \
289 reader, *((void **)ptr_p), sizeof(struct_name))
290#define BLO_read_struct_array(reader, struct_name, array_size, ptr_p) \
291 *((void **)ptr_p) = BLO_read_struct_array_with_size( \
292 reader, *((void **)ptr_p), sizeof(struct_name) * (array_size))
293
301 const char *struct_name,
302 uint32_t items_num,
303 const void *old_address);
304
305/* Read all elements in list
306 *
307 * Updates all `->prev` and `->next` pointers of the list elements.
308 * Updates the `list->first` and `list->last` pointers.
309 */
311 size_t expected_elem_size,
312 ListBase *list);
313
314#define BLO_read_struct_list(reader, struct_name, list) \
315 BLO_read_struct_list_with_size(reader, sizeof(struct_name), list)
316
317/* Update data pointers and correct byte-order if necessary. */
318
319void BLO_read_char_array(BlendDataReader *reader, int array_size, char **ptr_p);
320void BLO_read_int8_array(BlendDataReader *reader, int array_size, int8_t **ptr_p);
321void BLO_read_uint8_array(BlendDataReader *reader, int array_size, uint8_t **ptr_p);
322void BLO_read_int32_array(BlendDataReader *reader, int array_size, int32_t **ptr_p);
323void BLO_read_uint32_array(BlendDataReader *reader, int array_size, uint32_t **ptr_p);
324void BLO_read_float_array(BlendDataReader *reader, int array_size, float **ptr_p);
325void BLO_read_float3_array(BlendDataReader *reader, int array_size, float **ptr_p);
326void BLO_read_double_array(BlendDataReader *reader, int array_size, double **ptr_p);
327void BLO_read_pointer_array(BlendDataReader *reader, int array_size, void **ptr_p);
328
329/* Read null terminated string. */
330
331void BLO_read_string(BlendDataReader *reader, char **ptr_p);
332void BLO_read_string(BlendDataReader *reader, char *const *ptr_p);
333void BLO_read_string(BlendDataReader *reader, const char **ptr_p);
334
335/* Misc. */
336
338 BlendDataReader *reader,
339 const void **ptr_p,
341
346template<typename T>
348 BlendDataReader *reader,
349 T **data_ptr,
351{
353 reader, (const void **)data_ptr, read_fn);
354 /* Need const-cast here, because not all DNA members that reference potentially shared data are
355 * const yet. */
356 *data_ptr = const_cast<T *>(static_cast<const T *>(shared_data.data));
357 return shared_data.sharing_info;
358}
359
363void BLO_read_data_globmap_add(BlendDataReader *reader, void *oldaddr, void *newaddr);
364void BLO_read_glob_list(BlendDataReader *reader, ListBase *list);
367
370/* -------------------------------------------------------------------- */
387 ID *self_id,
388 const bool is_linked_only,
389 ID *id) ATTR_NONNULL(2);
390
403 ATTR_NONNULL(1);
404
405/* Misc. */
406
410
413/* -------------------------------------------------------------------- */
424void BLO_reportf_wrap(BlendFileReadReport *reports, eReportType type, const char *format, ...)
425 ATTR_PRINTF_FORMAT(3, 4);
426
#define ATTR_PRINTF_FORMAT(format_param, dots_param)
#define ATTR_NONNULL(...)
unsigned int uint
ID * BLO_read_get_new_id_address(BlendLibReader *reader, ID *self_id, const bool is_linked_only, ID *id) ATTR_NONNULL(2)
Definition readfile.cc:4885
void BLO_write_double_array(BlendWriter *writer, uint num, const double *data_ptr)
void BLO_read_float3_array(BlendDataReader *reader, int array_size, float **ptr_p)
Definition readfile.cc:4977
void BLO_write_uint32_array(BlendWriter *writer, uint num, const uint32_t *data_ptr)
void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, const ListBase *list)
void * BLO_read_struct_by_name_array(BlendDataReader *reader, const char *struct_name, uint32_t items_num, const void *old_address)
Definition readfile.cc:4873
int BLO_get_struct_id_by_name(const BlendWriter *writer, const char *struct_name)
void BLO_write_float3_array(BlendWriter *writer, uint num, const float *data_ptr)
void BLO_write_struct_at_address_by_id_with_filecode(BlendWriter *writer, int filecode, int struct_id, const void *address, const void *data_ptr)
ID * BLO_read_get_new_id_address_from_session_uid(BlendLibReader *reader, uint session_uid) ATTR_NONNULL(1)
Definition readfile.cc:4893
void BLO_read_uint8_array(BlendDataReader *reader, int array_size, uint8_t **ptr_p)
Definition readfile.cc:4935
int BLO_read_fileversion_get(BlendDataReader *reader)
Definition readfile.cc:4898
void * BLO_read_get_new_data_address_no_us(BlendDataReader *reader, const void *old_address, size_t expected_size)
Definition readfile.cc:4857
BlendFileReadReport * BLO_read_data_reports(BlendDataReader *reader)
Definition readfile.cc:5150
Main * BLO_read_lib_get_main(BlendLibReader *reader)
Definition readfile.cc:5160
struct Library * BLO_read_data_current_library(BlendDataReader *reader)
void * BLO_read_struct_array_with_size(BlendDataReader *reader, const void *old_address, size_t expected_size)
Definition readfile.cc:4865
void BLO_write_struct_by_name(BlendWriter *writer, const char *struct_name, const void *data_ptr)
BLO_Write_IDBuffer * BLO_write_allocate_id_buffer()
void BLO_read_glob_list(BlendDataReader *reader, ListBase *list)
Definition readfile.cc:5145
void BLO_write_int32_array(BlendWriter *writer, uint num, const int32_t *data_ptr)
void BLO_read_double_array(BlendDataReader *reader, int array_size, double **ptr_p)
Definition readfile.cc:4982
bool BLO_read_data_is_undo(BlendDataReader *reader)
Definition readfile.cc:5135
void blo_write_id_struct(BlendWriter *writer, int struct_id, const void *id_address, const ID *id)
void BLO_write_uint8_array(BlendWriter *writer, uint num, const uint8_t *data_ptr)
void BLO_read_float_array(BlendDataReader *reader, int array_size, float **ptr_p)
Definition readfile.cc:4967
void BLO_read_int32_array(BlendDataReader *reader, int array_size, int32_t **ptr_p)
Definition readfile.cc:4947
BlendFileReadReport * BLO_read_lib_reports(BlendLibReader *reader)
Definition readfile.cc:5165
void BLO_read_struct_list_with_size(BlendDataReader *reader, size_t expected_elem_size, ListBase *list)
Definition readfile.cc:4908
void BLO_write_init_id_buffer_from_id(BLO_Write_IDBuffer *id_buffer, ID *id, const bool is_undo)
void BLO_write_struct_array_by_id(BlendWriter *writer, int struct_id, int array_size, const void *data_ptr)
bool BLO_read_lib_is_undo(BlendLibReader *reader)
Definition readfile.cc:5155
blender::ImplicitSharingInfoAndData blo_read_shared_impl(BlendDataReader *reader, const void **ptr_p, blender::FunctionRef< const blender::ImplicitSharingInfo *()> read_fn)
void BLO_read_uint32_array(BlendDataReader *reader, int array_size, uint32_t **ptr_p)
Definition readfile.cc:4957
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:4992
void BLO_read_data_globmap_add(BlendDataReader *reader, void *oldaddr, void *newaddr)
Definition readfile.cc:5140
void BLO_write_float_array(BlendWriter *writer, uint num, const float *data_ptr)
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
void BLO_write_destroy_id_buffer(BLO_Write_IDBuffer **id_buffer)
ID * BLO_write_get_id_buffer_temp_id(BLO_Write_IDBuffer *id_buffer)
void BLO_write_int8_array(BlendWriter *writer, uint num, const int8_t *data_ptr)
void BLO_read_char_array(BlendDataReader *reader, int array_size, char **ptr_p)
Definition readfile.cc:4929
void BLO_write_struct_array_by_name(BlendWriter *writer, const char *struct_name, int array_size, const void *data_ptr)
bool BLO_read_requires_endian_switch(BlendDataReader *reader)
Definition readfile.cc:4903
void BLO_write_char_array(BlendWriter *writer, uint num, const char *data_ptr)
void BLO_write_raw(BlendWriter *writer, size_t size_in_bytes, const void *data_ptr)
void BLO_write_struct_at_address_by_id(BlendWriter *writer, int struct_id, const void *address, const void *data_ptr)
void * BLO_read_get_new_data_address(BlendDataReader *reader, const void *old_address)
Definition readfile.cc:4852
void BLO_read_pointer_array(BlendDataReader *reader, int array_size, void **ptr_p)
Definition readfile.cc:5052
void BLO_write_struct_array_at_address_by_id(BlendWriter *writer, int struct_id, int array_size, const void *address, const void *data_ptr)
bool BLO_write_is_undo(BlendWriter *writer)
void BLO_reportf_wrap(BlendFileReadReport *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BLO_write_shared(BlendWriter *writer, const void *data, size_t approximate_size_in_bytes, const blender::ImplicitSharingInfo *sharing_info, blender::FunctionRef< void()> write_fn)
void BLO_read_int8_array(BlendDataReader *reader, int array_size, int8_t **ptr_p)
Definition readfile.cc:4941
void BLO_write_struct_by_id(BlendWriter *writer, int struct_id, const void *data_ptr)
void BLO_write_struct_list_by_name(BlendWriter *writer, const char *struct_name, ListBase *list)
const blender::ImplicitSharingInfo * BLO_read_shared(BlendDataReader *reader, T **data_ptr, blender::FunctionRef< const blender::ImplicitSharingInfo *()> read_fn)
void BLO_write_pointer_array(BlendWriter *writer, uint num, const void *data_ptr)
format
unsigned int uint32_t
Definition stdint.h:80
signed int int32_t
Definition stdint.h:77
unsigned char uint8_t
Definition stdint.h:78
signed char int8_t
Definition stdint.h:75
Definition DNA_ID.h:413
const ImplicitSharingInfo * sharing_info