Blender V5.0
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
30
31#pragma once
32
33#include "DNA_sdna_type_ids.hh"
34
35#include "BLI_function_ref.hh"
37#include "BLI_memory_utils.hh"
38
39namespace blender {
41}
42struct BlendDataReader;
44struct BlendLibReader;
45struct BlendWriter;
46struct ID;
47struct ListBase;
48struct Main;
50
51/* -------------------------------------------------------------------- */
85
89int BLO_get_struct_id_by_name(const BlendWriter *writer, const char *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, blender::dna::sdna_struct_id_get<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, blender::dna::sdna_struct_id_get<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, blender::dna::sdna_struct_id_get<struct_name>(), address, data_ptr)
119
124 const char *struct_name,
125 int64_t array_size,
126 const void *data_ptr);
128 int struct_id,
129 int64_t 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, blender::dna::sdna_struct_id_get<struct_name>(), array_size, data_ptr)
134
139 int struct_id,
140 int64_t array_size,
141 const void *address,
142 const void *data_ptr);
143#define BLO_write_struct_array_at_address(writer, struct_name, array_size, address, data_ptr) \
144 BLO_write_struct_array_at_address_by_id( \
145 writer, blender::dna::sdna_struct_id_get<struct_name>(), array_size, address, data_ptr)
146
150void BLO_write_struct_list_by_name(BlendWriter *writer, const char *struct_name, ListBase *list);
151void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, const ListBase *list);
152#define BLO_write_struct_list(writer, struct_name, list_ptr) \
153 BLO_write_struct_list_by_id(writer, blender::dna::sdna_struct_id_get<struct_name>(), list_ptr)
154
158void blo_write_id_struct(BlendWriter *writer, int struct_id, const void *id_address, const ID *id);
159#define BLO_write_id_struct(writer, struct_name, id_address, id) \
160 blo_write_id_struct(writer, blender::dna::sdna_struct_id_get<struct_name>(), id_address, id)
161
171 private:
172 static constexpr int static_size = 8192;
174
175 public:
176 BLO_Write_IDBuffer(ID &id, bool is_undo, bool is_placeholder);
177 BLO_Write_IDBuffer(ID &id, BlendWriter *writer);
178
180 {
181 return static_cast<ID *>(buffer_.buffer());
182 };
183};
184
199void BLO_write_raw(BlendWriter *writer, size_t size_in_bytes, const void *data_ptr);
203void BLO_write_char_array(BlendWriter *writer, int64_t num, const char *data_ptr);
204void BLO_write_int8_array(BlendWriter *writer, int64_t num, const int8_t *data_ptr);
205void BLO_write_int16_array(BlendWriter *writer, int64_t num, const int16_t *data_ptr);
206void BLO_write_uint8_array(BlendWriter *writer, int64_t num, const uint8_t *data_ptr);
207void BLO_write_int32_array(BlendWriter *writer, int64_t num, const int32_t *data_ptr);
208void BLO_write_uint32_array(BlendWriter *writer, int64_t num, const uint32_t *data_ptr);
209void BLO_write_float_array(BlendWriter *writer, int64_t num, const float *data_ptr);
210void BLO_write_double_array(BlendWriter *writer, int64_t num, const double *data_ptr);
211void BLO_write_float3_array(BlendWriter *writer, int64_t num, const float *data_ptr);
212void BLO_write_pointer_array(BlendWriter *writer, int64_t num, const void *data_ptr);
216void BLO_write_string(BlendWriter *writer, const char *data_ptr);
217
218/* Misc. */
219
233void BLO_write_shared(BlendWriter *writer,
234 const void *data,
235 size_t approximate_size_in_bytes,
236 const blender::ImplicitSharingInfo *sharing_info,
237 blender::FunctionRef<void()> write_fn);
238
242void BLO_write_shared_tag(BlendWriter *writer, const void *data);
243
248bool BLO_write_is_undo(BlendWriter *writer);
249
251
252/* -------------------------------------------------------------------- */
281
282void *BLO_read_get_new_data_address(BlendDataReader *reader, const void *old_address);
283#define BLO_read_data_address(reader, ptr_p) \
284 *((void **)ptr_p) = BLO_read_get_new_data_address((reader), *(ptr_p))
285
296 const void *old_address,
297 size_t expected_size);
298
306 const void *old_address,
307 size_t expected_size);
308#define BLO_read_struct(reader, struct_name, ptr_p) \
309 *((void **)ptr_p) = BLO_read_struct_array_with_size( \
310 reader, *((void **)ptr_p), sizeof(struct_name))
311#define BLO_read_struct_array(reader, struct_name, array_size, ptr_p) \
312 *((void **)ptr_p) = BLO_read_struct_array_with_size( \
313 reader, *((void **)ptr_p), sizeof(struct_name) * (array_size))
314
322 const char *struct_name,
323 int64_t items_num,
324 const void *old_address);
325
326/* Read all elements in list
327 *
328 * Updates all `->prev` and `->next` pointers of the list elements.
329 * Updates the `list->first` and `list->last` pointers.
330 */
332 size_t expected_elem_size,
333 ListBase *list);
334
335#define BLO_read_struct_list(reader, struct_name, list) \
336 BLO_read_struct_list_with_size(reader, sizeof(struct_name), list)
337
338/* Update data pointers and correct byte-order if necessary. */
339
340void BLO_read_char_array(BlendDataReader *reader, int64_t array_size, char **ptr_p);
341void BLO_read_int8_array(BlendDataReader *reader, int64_t array_size, int8_t **ptr_p);
342void BLO_read_uint8_array(BlendDataReader *reader, int64_t array_size, uint8_t **ptr_p);
343void BLO_read_int16_array(BlendDataReader *reader, const int64_t array_size, int16_t **ptr_p);
344void BLO_read_int32_array(BlendDataReader *reader, int64_t array_size, int32_t **ptr_p);
345void BLO_read_uint32_array(BlendDataReader *reader, int64_t array_size, uint32_t **ptr_p);
346void BLO_read_float_array(BlendDataReader *reader, int64_t array_size, float **ptr_p);
347void BLO_read_float3_array(BlendDataReader *reader, int64_t array_size, float **ptr_p);
348void BLO_read_double_array(BlendDataReader *reader, int64_t array_size, double **ptr_p);
349void BLO_read_pointer_array(BlendDataReader *reader, int64_t array_size, void **ptr_p);
350
351/* Read null terminated string. */
352
353void BLO_read_string(BlendDataReader *reader, char **ptr_p);
354void BLO_read_string(BlendDataReader *reader, char *const *ptr_p);
355void BLO_read_string(BlendDataReader *reader, const char **ptr_p);
356
357/* Misc. */
358
360 BlendDataReader *reader,
361 const void **ptr_p,
363
368template<typename T>
370 BlendDataReader *reader,
371 T **data_ptr,
373{
375 reader, (const void **)data_ptr, read_fn);
376 /* Need const-cast here, because not all DNA members that reference potentially shared data are
377 * const yet. */
378 *data_ptr = const_cast<T *>(static_cast<const T *>(shared_data.data));
379 return shared_data.sharing_info;
380}
381
384void BLO_read_data_globmap_add(BlendDataReader *reader, void *oldaddr, void *newaddr);
385void BLO_read_glob_list(BlendDataReader *reader, ListBase *list);
388
390
391/* -------------------------------------------------------------------- */
397
408 ID *self_id,
409 const bool is_linked_only,
410 ID *id) ATTR_NONNULL(2);
411
424 ATTR_NONNULL(1);
425
426/* Misc. */
427
431
433
434/* -------------------------------------------------------------------- */
437
445void BLO_reportf_wrap(BlendFileReadReport *reports, eReportType type, const char *format, ...)
446 ATTR_PRINTF_FORMAT(3, 4);
447
eReportType
Definition BKE_report.hh:33
#define ATTR_PRINTF_FORMAT(format_param, dots_param)
#define ATTR_NONNULL(...)
ATTR_WARN_UNUSED_RESULT const size_t num
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:5731
void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, const ListBase *list)
int BLO_get_struct_id_by_name(const BlendWriter *writer, const char *struct_name)
void BLO_write_float_array(BlendWriter *writer, int64_t num, const float *data_ptr)
void BLO_read_uint8_array(BlendDataReader *reader, int64_t array_size, uint8_t **ptr_p)
Definition readfile.cc:5776
void BLO_write_struct_at_address_by_id_with_filecode(BlendWriter *writer, int filecode, int struct_id, const void *address, const void *data_ptr)
void BLO_read_float3_array(BlendDataReader *reader, int64_t array_size, float **ptr_p)
Definition readfile.cc:5816
ID * BLO_read_get_new_id_address_from_session_uid(BlendLibReader *reader, uint session_uid) ATTR_NONNULL(1)
Definition readfile.cc:5739
void BLO_write_int32_array(BlendWriter *writer, int64_t num, const int32_t *data_ptr)
int BLO_read_fileversion_get(BlendDataReader *reader)
Definition readfile.cc:5744
void * BLO_read_get_new_data_address_no_us(BlendDataReader *reader, const void *old_address, size_t expected_size)
Definition readfile.cc:5703
BlendFileReadReport * BLO_read_data_reports(BlendDataReader *reader)
Definition readfile.cc:5978
void BLO_read_uint32_array(BlendDataReader *reader, int64_t array_size, uint32_t **ptr_p)
Definition readfile.cc:5802
Main * BLO_read_lib_get_main(BlendLibReader *reader)
Definition readfile.cc:5988
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:5711
void BLO_write_struct_by_name(BlendWriter *writer, const char *struct_name, const void *data_ptr)
void BLO_read_glob_list(BlendDataReader *reader, ListBase *list)
Definition readfile.cc:5973
void BLO_write_struct_array_by_name(BlendWriter *writer, const char *struct_name, int64_t array_size, const void *data_ptr)
void BLO_read_float_array(BlendDataReader *reader, int64_t array_size, float **ptr_p)
Definition readfile.cc:5809
void BLO_write_struct_array_by_id(BlendWriter *writer, int struct_id, int64_t array_size, const void *data_ptr)
bool BLO_read_data_is_undo(BlendDataReader *reader)
Definition readfile.cc:5963
void blo_write_id_struct(BlendWriter *writer, int struct_id, const void *id_address, const ID *id)
void BLO_read_int32_array(BlendDataReader *reader, int64_t array_size, int32_t **ptr_p)
Definition readfile.cc:5795
void BLO_write_uint8_array(BlendWriter *writer, int64_t num, const uint8_t *data_ptr)
void * BLO_read_struct_by_name_array(BlendDataReader *reader, const char *struct_name, int64_t items_num, const void *old_address)
Definition readfile.cc:5719
BlendFileReadReport * BLO_read_lib_reports(BlendLibReader *reader)
Definition readfile.cc:5993
void BLO_write_float3_array(BlendWriter *writer, int64_t num, const float *data_ptr)
void BLO_read_int16_array(BlendDataReader *reader, const int64_t array_size, int16_t **ptr_p)
Definition readfile.cc:5788
void BLO_read_struct_list_with_size(BlendDataReader *reader, size_t expected_elem_size, ListBase *list)
Definition readfile.cc:5749
void BLO_write_int8_array(BlendWriter *writer, int64_t num, const int8_t *data_ptr)
bool BLO_read_lib_is_undo(BlendLibReader *reader)
Definition readfile.cc:5983
void BLO_read_double_array(BlendDataReader *reader, int64_t array_size, double **ptr_p)
Definition readfile.cc:5821
blender::ImplicitSharingInfoAndData blo_read_shared_impl(BlendDataReader *reader, const void **ptr_p, blender::FunctionRef< const blender::ImplicitSharingInfo *()> read_fn)
void BLO_write_double_array(BlendWriter *writer, int64_t num, const double *data_ptr)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:5828
void BLO_read_data_globmap_add(BlendDataReader *reader, void *oldaddr, void *newaddr)
Definition readfile.cc:5968
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
void BLO_read_int8_array(BlendDataReader *reader, int64_t array_size, int8_t **ptr_p)
Definition readfile.cc:5782
void BLO_write_shared_tag(BlendWriter *writer, const void *data)
void BLO_write_uint32_array(BlendWriter *writer, int64_t num, const uint32_t *data_ptr)
void BLO_read_char_array(BlendDataReader *reader, int64_t array_size, char **ptr_p)
Definition readfile.cc:5770
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:5698
void BLO_write_pointer_array(BlendWriter *writer, int64_t num, const void *data_ptr)
void BLO_read_pointer_array(BlendDataReader *reader, int64_t array_size, void **ptr_p)
Definition readfile.cc:5880
bool BLO_write_is_undo(BlendWriter *writer)
void BLO_write_int16_array(BlendWriter *writer, int64_t num, const int16_t *data_ptr)
void BLO_write_char_array(BlendWriter *writer, int64_t num, const char *data_ptr)
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_write_struct_array_at_address_by_id(BlendWriter *writer, int struct_id, int64_t array_size, const void *address, const void *data_ptr)
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)
BMesh const char void * data
long long int int64_t
format
#define T
BLO_Write_IDBuffer(ID &id, bool is_undo, bool is_placeholder)
Definition DNA_ID.h:414
const ImplicitSharingInfo * sharing_info