Blender V4.5
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#include "DNA_windowmanager_types.h" /* for eReportType */
35
36#include "BLI_function_ref.hh"
38#include "BLI_memory_utils.hh"
39
40namespace blender {
42}
43struct BlendDataReader;
45struct BlendLibReader;
46struct BlendWriter;
47struct Main;
48
49/* -------------------------------------------------------------------- */
83
87int BLO_get_struct_id_by_name(const BlendWriter *writer, const char *struct_name);
88
92void BLO_write_struct_by_name(BlendWriter *writer, const char *struct_name, const void *data_ptr);
93void BLO_write_struct_by_id(BlendWriter *writer, int struct_id, const void *data_ptr);
94#define BLO_write_struct(writer, struct_name, data_ptr) \
95 BLO_write_struct_by_id(writer, blender::dna::sdna_struct_id_get<struct_name>(), data_ptr)
96
101 int struct_id,
102 const void *address,
103 const void *data_ptr);
104#define BLO_write_struct_at_address(writer, struct_name, address, data_ptr) \
105 BLO_write_struct_at_address_by_id( \
106 writer, blender::dna::sdna_struct_id_get<struct_name>(), address, data_ptr)
107
112 BlendWriter *writer, int filecode, int struct_id, const void *address, const void *data_ptr);
113#define BLO_write_struct_at_address_with_filecode( \
114 writer, filecode, struct_name, address, data_ptr) \
115 BLO_write_struct_at_address_by_id_with_filecode( \
116 writer, filecode, blender::dna::sdna_struct_id_get<struct_name>(), address, data_ptr)
117
122 const char *struct_name,
123 int64_t array_size,
124 const void *data_ptr);
126 int struct_id,
127 int64_t array_size,
128 const void *data_ptr);
129#define BLO_write_struct_array(writer, struct_name, array_size, data_ptr) \
130 BLO_write_struct_array_by_id( \
131 writer, blender::dna::sdna_struct_id_get<struct_name>(), array_size, data_ptr)
132
137 int struct_id,
138 int64_t array_size,
139 const void *address,
140 const void *data_ptr);
141#define BLO_write_struct_array_at_address(writer, struct_name, array_size, address, data_ptr) \
142 BLO_write_struct_array_at_address_by_id( \
143 writer, blender::dna::sdna_struct_id_get<struct_name>(), array_size, address, data_ptr)
144
148void BLO_write_struct_list_by_name(BlendWriter *writer, const char *struct_name, ListBase *list);
149void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, const ListBase *list);
150#define BLO_write_struct_list(writer, struct_name, list_ptr) \
151 BLO_write_struct_list_by_id(writer, blender::dna::sdna_struct_id_get<struct_name>(), list_ptr)
152
156void blo_write_id_struct(BlendWriter *writer, int struct_id, const void *id_address, const ID *id);
157#define BLO_write_id_struct(writer, struct_name, id_address, id) \
158 blo_write_id_struct(writer, blender::dna::sdna_struct_id_get<struct_name>(), id_address, id)
159
169 private:
170 static constexpr int static_size = 8192;
172
173 public:
174 BLO_Write_IDBuffer(ID &id, bool is_undo, bool is_placeholder);
175 BLO_Write_IDBuffer(ID &id, BlendWriter *writer);
176
178 {
179 return static_cast<ID *>(buffer_.buffer());
180 };
181};
182
197void BLO_write_raw(BlendWriter *writer, size_t size_in_bytes, const void *data_ptr);
201void BLO_write_char_array(BlendWriter *writer, int64_t num, const char *data_ptr);
202void BLO_write_int8_array(BlendWriter *writer, int64_t num, const int8_t *data_ptr);
203void BLO_write_int16_array(BlendWriter *writer, int64_t num, const int16_t *data_ptr);
204void BLO_write_uint8_array(BlendWriter *writer, int64_t num, const uint8_t *data_ptr);
205void BLO_write_int32_array(BlendWriter *writer, int64_t num, const int32_t *data_ptr);
206void BLO_write_uint32_array(BlendWriter *writer, int64_t num, const uint32_t *data_ptr);
207void BLO_write_float_array(BlendWriter *writer, int64_t num, const float *data_ptr);
208void BLO_write_double_array(BlendWriter *writer, int64_t num, const double *data_ptr);
209void BLO_write_float3_array(BlendWriter *writer, int64_t num, const float *data_ptr);
210void BLO_write_pointer_array(BlendWriter *writer, int64_t num, const void *data_ptr);
214void BLO_write_string(BlendWriter *writer, const char *data_ptr);
215
216/* Misc. */
217
227void BLO_write_shared(BlendWriter *writer,
228 const void *data,
229 size_t approximate_size_in_bytes,
230 const blender::ImplicitSharingInfo *sharing_info,
231 blender::FunctionRef<void()> write_fn);
232
237bool BLO_write_is_undo(BlendWriter *writer);
238
240
241/* -------------------------------------------------------------------- */
270
271void *BLO_read_get_new_data_address(BlendDataReader *reader, const void *old_address);
272#define BLO_read_data_address(reader, ptr_p) \
273 *((void **)ptr_p) = BLO_read_get_new_data_address((reader), *(ptr_p))
274
285 const void *old_address,
286 size_t expected_size);
287
295 const void *old_address,
296 size_t expected_size);
297#define BLO_read_struct(reader, struct_name, ptr_p) \
298 *((void **)ptr_p) = BLO_read_struct_array_with_size( \
299 reader, *((void **)ptr_p), sizeof(struct_name))
300#define BLO_read_struct_array(reader, struct_name, array_size, ptr_p) \
301 *((void **)ptr_p) = BLO_read_struct_array_with_size( \
302 reader, *((void **)ptr_p), sizeof(struct_name) * (array_size))
303
311 const char *struct_name,
312 int64_t items_num,
313 const void *old_address);
314
315/* Read all elements in list
316 *
317 * Updates all `->prev` and `->next` pointers of the list elements.
318 * Updates the `list->first` and `list->last` pointers.
319 */
321 size_t expected_elem_size,
322 ListBase *list);
323
324#define BLO_read_struct_list(reader, struct_name, list) \
325 BLO_read_struct_list_with_size(reader, sizeof(struct_name), list)
326
327/* Update data pointers and correct byte-order if necessary. */
328
329void BLO_read_char_array(BlendDataReader *reader, int64_t array_size, char **ptr_p);
330void BLO_read_int8_array(BlendDataReader *reader, int64_t array_size, int8_t **ptr_p);
331void BLO_read_uint8_array(BlendDataReader *reader, int64_t array_size, uint8_t **ptr_p);
332void BLO_read_int16_array(BlendDataReader *reader, const int64_t array_size, int16_t **ptr_p);
333void BLO_read_int32_array(BlendDataReader *reader, int64_t array_size, int32_t **ptr_p);
334void BLO_read_uint32_array(BlendDataReader *reader, int64_t array_size, uint32_t **ptr_p);
335void BLO_read_float_array(BlendDataReader *reader, int64_t array_size, float **ptr_p);
336void BLO_read_float3_array(BlendDataReader *reader, int64_t array_size, float **ptr_p);
337void BLO_read_double_array(BlendDataReader *reader, int64_t array_size, double **ptr_p);
338void BLO_read_pointer_array(BlendDataReader *reader, int64_t array_size, void **ptr_p);
339
340/* Read null terminated string. */
341
342void BLO_read_string(BlendDataReader *reader, char **ptr_p);
343void BLO_read_string(BlendDataReader *reader, char *const *ptr_p);
344void BLO_read_string(BlendDataReader *reader, const char **ptr_p);
345
346/* Misc. */
347
349 BlendDataReader *reader,
350 const void **ptr_p,
352
357template<typename T>
359 BlendDataReader *reader,
360 T **data_ptr,
362{
364 reader, (const void **)data_ptr, read_fn);
365 /* Need const-cast here, because not all DNA members that reference potentially shared data are
366 * const yet. */
367 *data_ptr = const_cast<T *>(static_cast<const T *>(shared_data.data));
368 return shared_data.sharing_info;
369}
370
374void BLO_read_data_globmap_add(BlendDataReader *reader, void *oldaddr, void *newaddr);
375void BLO_read_glob_list(BlendDataReader *reader, ListBase *list);
378
380 const char *stype,
381 const char *vartype,
382 const char *name);
383
385
386/* -------------------------------------------------------------------- */
392
403 ID *self_id,
404 const bool is_linked_only,
405 ID *id) ATTR_NONNULL(2);
406
419 ATTR_NONNULL(1);
420
421/* Misc. */
422
426
428
429/* -------------------------------------------------------------------- */
432
441 ATTR_PRINTF_FORMAT(3, 4);
442
#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:5226
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:5284
int BLO_read_struct_member_offset(const BlendDataReader *reader, const char *stype, const char *vartype, const char *name)
Definition readfile.cc:5249
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:5336
ID * BLO_read_get_new_id_address_from_session_uid(BlendLibReader *reader, uint session_uid) ATTR_NONNULL(1)
Definition readfile.cc:5234
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:5239
void * BLO_read_get_new_data_address_no_us(BlendDataReader *reader, const void *old_address, size_t expected_size)
Definition readfile.cc:5198
BlendFileReadReport * BLO_read_data_reports(BlendDataReader *reader)
Definition readfile.cc:5500
void BLO_read_uint32_array(BlendDataReader *reader, int64_t array_size, uint32_t **ptr_p)
Definition readfile.cc:5316
Main * BLO_read_lib_get_main(BlendLibReader *reader)
Definition readfile.cc:5510
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:5206
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:5495
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:5326
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:5485
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:5306
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:5214
BlendFileReadReport * BLO_read_lib_reports(BlendLibReader *reader)
Definition readfile.cc:5515
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:5296
void BLO_read_struct_list_with_size(BlendDataReader *reader, size_t expected_elem_size, ListBase *list)
Definition readfile.cc:5257
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:5505
void BLO_read_double_array(BlendDataReader *reader, int64_t array_size, double **ptr_p)
Definition readfile.cc:5341
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:5351
void BLO_read_data_globmap_add(BlendDataReader *reader, void *oldaddr, void *newaddr)
Definition readfile.cc:5490
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
bool BLO_read_requires_endian_switch(BlendDataReader *reader)
Definition readfile.cc:5244
void BLO_read_int8_array(BlendDataReader *reader, int64_t array_size, int8_t **ptr_p)
Definition readfile.cc:5290
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:5278
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:5193
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:5402
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)
ReportList * reports
Definition WM_types.hh:1025
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:404
const ImplicitSharingInfo * sharing_info