Blender  V2.93
BLO_read_write.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
41 #pragma once
42 
43 /* for SDNA_TYPE_FROM_STRUCT() macro */
44 #include "dna_type_offsets.h"
45 
46 #include "DNA_windowmanager_types.h" /* for ReportType */
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 typedef struct BlendDataReader BlendDataReader;
53 typedef struct BlendExpander BlendExpander;
54 typedef struct BlendLibReader BlendLibReader;
55 typedef struct BlendWriter BlendWriter;
56 
57 struct Main;
58 struct ReportList;
59 
60 /* Blend Write API
61  * ===============
62  *
63  * Most functions fall into one of two categories. Either they write a DNA struct or a raw memory
64  * buffer to the .blend file.
65  *
66  * It is safe to pass NULL as data_ptr. In this case nothing will be stored.
67  *
68  * DNA Struct Writing
69  * ------------------
70  *
71  * Functions dealing with DNA structs begin with BLO_write_struct_*.
72  *
73  * DNA struct types can be identified in different ways:
74  * - Run-time Name: The name is provided as const char *.
75  * - Compile-time Name: The name is provided at compile time. This is more efficient.
76  * - Struct ID: Every DNA struct type has an integer ID that can be queried with
77  * BLO_get_struct_id_by_name. Providing this ID can be a useful optimization when many structs
78  * of the same type are stored AND if those structs are not in a continuous array.
79  *
80  * Often only a single instance of a struct is written at once. However, sometimes it is necessary
81  * to write arrays or linked lists. Separate functions for that are provided as well.
82  *
83  * There is a special macro for writing id structs: BLO_write_id_struct. Those are handled
84  * differently from other structs.
85  *
86  * Raw Data Writing
87  * ----------------
88  *
89  * At the core there is BLO_write_raw, which can write arbitrary memory buffers to the file. The
90  * code that reads this data might have to correct its byte-order. For the common cases there are
91  * convenience functions that write and read arrays of simple types such as int32. Those will
92  * correct endianness automatically.
93  */
94 
95 /* Mapping between names and ids. */
96 int BLO_get_struct_id_by_name(BlendWriter *writer, const char *struct_name);
97 #define BLO_get_struct_id(writer, struct_name) SDNA_TYPE_FROM_STRUCT(struct_name)
98 
99 /* Write single struct. */
100 void BLO_write_struct_by_name(BlendWriter *writer, const char *struct_name, const void *data_ptr);
101 void BLO_write_struct_by_id(BlendWriter *writer, int struct_id, const void *data_ptr);
102 #define BLO_write_struct(writer, struct_name, data_ptr) \
103  BLO_write_struct_by_id(writer, BLO_get_struct_id(writer, struct_name), data_ptr)
104 
105 /* Write single struct at address. */
107  int struct_id,
108  const void *address,
109  const void *data_ptr);
110 #define BLO_write_struct_at_address(writer, struct_name, address, data_ptr) \
111  BLO_write_struct_at_address_by_id( \
112  writer, BLO_get_struct_id(writer, struct_name), address, data_ptr)
113 
114 /* Write single struct at address and specify a filecode. */
116  BlendWriter *writer, int filecode, int struct_id, const void *address, const void *data_ptr);
117 #define BLO_write_struct_at_address_with_filecode( \
118  writer, filecode, struct_name, address, data_ptr) \
119  BLO_write_struct_at_address_by_id_with_filecode( \
120  writer, filecode, BLO_get_struct_id(writer, struct_name), address, data_ptr)
121 
122 /* Write struct array. */
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 
135 /* Write struct array at address. */
137  BlendWriter *writer, int struct_id, int array_size, const void *address, const void *data_ptr);
138 #define BLO_write_struct_array_at_address(writer, struct_name, array_size, address, data_ptr) \
139  BLO_write_struct_array_at_address_by_id( \
140  writer, BLO_get_struct_id(writer, struct_name), array_size, address, data_ptr)
141 
142 /* Write struct list. */
144  const char *struct_name,
145  struct ListBase *list);
146 void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, struct ListBase *list);
147 #define BLO_write_struct_list(writer, struct_name, list_ptr) \
148  BLO_write_struct_list_by_id(writer, BLO_get_struct_id(writer, struct_name), list_ptr)
149 
150 /* Write id struct. */
152  int struct_id,
153  const void *id_address,
154  const struct ID *id);
155 #define BLO_write_id_struct(writer, struct_name, id_address, id) \
156  blo_write_id_struct(writer, BLO_get_struct_id(writer, struct_name), id_address, id)
157 
158 /* Write raw data. */
159 void BLO_write_raw(BlendWriter *writer, size_t size_in_bytes, const void *data_ptr);
160 void BLO_write_int32_array(BlendWriter *writer, uint num, const int32_t *data_ptr);
161 void BLO_write_uint32_array(BlendWriter *writer, uint num, const uint32_t *data_ptr);
162 void BLO_write_float_array(BlendWriter *writer, uint num, const float *data_ptr);
163 void BLO_write_double_array(BlendWriter *writer, uint num, const double *data_ptr);
164 void BLO_write_float3_array(BlendWriter *writer, uint num, const float *data_ptr);
165 void BLO_write_pointer_array(BlendWriter *writer, uint num, const void *data_ptr);
166 void BLO_write_string(BlendWriter *writer, const char *data_ptr);
167 
168 /* Misc. */
169 bool BLO_write_is_undo(BlendWriter *writer);
170 
171 /* Blend Read Data API
172  * ===================
173  *
174  * Generally, for every BLO_write_* call there should be a corresponding BLO_read_* call.
175  *
176  * Most BLO_read_* functions get a pointer to a pointer as argument. That allows the function to
177  * update the pointer to its new value.
178  *
179  * When the given pointer points to a memory buffer that was not stored in the file, the pointer is
180  * updated to be NULL. When it was pointing to NULL before, it will stay that way.
181  *
182  * Examples of matching calls:
183  * BLO_write_struct(writer, ClothSimSettings, clmd->sim_parms);
184  * BLO_read_data_address(reader, &clmd->sim_parms);
185  *
186  * BLO_write_struct_list(writer, TimeMarker, &action->markers);
187  * BLO_read_list(reader, &action->markers);
188  *
189  * BLO_write_int32_array(writer, hmd->totindex, hmd->indexar);
190  * BLO_read_int32_array(reader, hmd->totindex, &hmd->indexar);
191  */
192 
193 void *BLO_read_get_new_data_address(BlendDataReader *reader, const void *old_address);
194 void *BLO_read_get_new_data_address_no_us(BlendDataReader *reader, const void *old_address);
195 void *BLO_read_get_new_packed_address(BlendDataReader *reader, const void *old_address);
196 
197 #define BLO_read_data_address(reader, ptr_p) \
198  *((void **)ptr_p) = BLO_read_get_new_data_address((reader), *(ptr_p))
199 #define BLO_read_packed_address(reader, ptr_p) \
200  *((void **)ptr_p) = BLO_read_get_new_packed_address((reader), *(ptr_p))
201 
202 typedef void (*BlendReadListFn)(BlendDataReader *reader, void *data);
204 void BLO_read_list(BlendDataReader *reader, struct ListBase *list);
205 
206 /* Update data pointers and correct byte-order if necessary. */
207 void BLO_read_int32_array(BlendDataReader *reader, int array_size, int32_t **ptr_p);
208 void BLO_read_uint32_array(BlendDataReader *reader, int array_size, uint32_t **ptr_p);
209 void BLO_read_float_array(BlendDataReader *reader, int array_size, float **ptr_p);
210 void BLO_read_float3_array(BlendDataReader *reader, int array_size, float **ptr_p);
211 void BLO_read_double_array(BlendDataReader *reader, int array_size, double **ptr_p);
212 void BLO_read_pointer_array(BlendDataReader *reader, void **ptr_p);
213 
214 /* Misc. */
217 void BLO_read_data_globmap_add(BlendDataReader *reader, void *oldaddr, void *newaddr);
218 void BLO_read_glob_list(BlendDataReader *reader, struct ListBase *list);
220 
221 /* Blend Read Lib API
222  * ===================
223  *
224  * This API does almost the same as the Blend Read Data API. However, now only pointers to ID data
225  * blocks are updated.
226  */
227 
228 ID *BLO_read_get_new_id_address(BlendLibReader *reader, struct Library *lib, struct ID *id);
229 
230 #define BLO_read_id_address(reader, lib, id_ptr_p) \
231  *((void **)id_ptr_p) = (void *)BLO_read_get_new_id_address((reader), (lib), (ID *)*(id_ptr_p))
232 
233 /* Misc. */
235 struct Main *BLO_read_lib_get_main(BlendLibReader *reader);
237 
238 /* Blend Expand API
239  * ===================
240  *
241  * BLO_expand has to be called for every data block that should be loaded. If the data block is in
242  * a separate .blend file, it will be pulled from there.
243  */
244 
245 void BLO_expand_id(BlendExpander *expander, struct ID *id);
246 
247 #define BLO_expand(expander, id) BLO_expand_id(expander, (struct ID *)id)
248 
249 /* Report API
250  * ===================
251  */
252 
253 void BLO_reportf_wrap(struct ReportList *reports, ReportType type, const char *format, ...)
254  ATTR_PRINTF_FORMAT(3, 4);
255 
256 #ifdef __cplusplus
257 }
258 #endif
size_t ATTR_PRINTF_FORMAT(3, 4)
unsigned int uint
Definition: BLI_sys_types.h:83
void BLO_write_double_array(BlendWriter *writer, uint num, const double *data_ptr)
Definition: writefile.c:1383
void BLO_read_float3_array(BlendDataReader *reader, int array_size, float **ptr_p)
Definition: readfile.c:5683
void BLO_write_uint32_array(BlendWriter *writer, uint num, const uint32_t *data_ptr)
Definition: writefile.c:1373
void BLO_write_float3_array(BlendWriter *writer, uint num, const float *data_ptr)
Definition: writefile.c:1393
void BLO_write_struct_list_by_id(BlendWriter *writer, int struct_id, struct ListBase *list)
Definition: writefile.c:1342
void BLO_write_struct_at_address_by_id_with_filecode(BlendWriter *writer, int filecode, int struct_id, const void *address, const void *data_ptr)
Definition: writefile.c:1322
void BLO_reportf_wrap(struct ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
struct Main * BLO_read_lib_get_main(BlendLibReader *reader)
Definition: readfile.c:5795
void * BLO_read_get_new_packed_address(BlendDataReader *reader, const void *old_address)
Definition: readfile.c:5610
void * BLO_read_get_new_data_address_no_us(BlendDataReader *reader, const void *old_address)
Definition: readfile.c:5605
ID * BLO_read_get_new_id_address(BlendLibReader *reader, struct Library *lib, struct ID *id)
Definition: readfile.c:5615
void BLO_write_struct_by_name(BlendWriter *writer, const char *struct_name, const void *data_ptr)
Definition: writefile.c:1291
void BLO_write_int32_array(BlendWriter *writer, uint num, const int32_t *data_ptr)
Definition: writefile.c:1368
struct ReportList * BLO_read_data_reports(BlendDataReader *reader)
Definition: readfile.c:5785
void BLO_read_double_array(BlendDataReader *reader, int array_size, double **ptr_p)
Definition: readfile.c:5688
bool BLO_read_data_is_undo(BlendDataReader *reader)
Definition: readfile.c:5770
void BLO_read_float_array(BlendDataReader *reader, int array_size, float **ptr_p)
Definition: readfile.c:5675
void BLO_read_int32_array(BlendDataReader *reader, int array_size, int32_t **ptr_p)
Definition: readfile.c:5659
void(* BlendReadListFn)(BlendDataReader *reader, void *data)
void BLO_write_struct_list_by_name(BlendWriter *writer, const char *struct_name, struct ListBase *list)
Definition: writefile.c:1347
void BLO_read_list(BlendDataReader *reader, struct ListBase *list)
Definition: readfile.c:5654
void BLO_write_struct_array_by_id(BlendWriter *writer, int struct_id, int array_size, const void *data_ptr)
Definition: writefile.c:1328
bool BLO_read_lib_is_undo(BlendLibReader *reader)
Definition: readfile.c:5790
void BLO_read_glob_list(BlendDataReader *reader, struct ListBase *list)
Definition: readfile.c:5780
void * BLO_read_get_new_data_address(BlendDataReader *reader, const void *old_address)
Definition: readfile.c:5600
void BLO_read_list_cb(BlendDataReader *reader, struct ListBase *list, BlendReadListFn callback)
Definition: readfile.c:5630
void BLO_read_uint32_array(BlendDataReader *reader, int array_size, uint32_t **ptr_p)
Definition: readfile.c:5667
void BLO_read_data_globmap_add(BlendDataReader *reader, void *oldaddr, void *newaddr)
Definition: readfile.c:5775
void BLO_write_float_array(BlendWriter *writer, uint num, const float *data_ptr)
Definition: writefile.c:1378
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
Definition: writefile.c:1401
int BLO_get_struct_id_by_name(BlendWriter *writer, const char *struct_name)
Definition: writefile.c:1362
void BLO_write_struct_array_by_name(BlendWriter *writer, const char *struct_name, int array_size, const void *data_ptr)
Definition: writefile.c:1296
bool BLO_read_requires_endian_switch(BlendDataReader *reader)
Definition: readfile.c:5620
void BLO_expand_id(BlendExpander *expander, struct ID *id)
Definition: readfile.c:5805
void BLO_write_raw(BlendWriter *writer, size_t size_in_bytes, const void *data_ptr)
Definition: writefile.c:1286
void BLO_write_struct_at_address_by_id(BlendWriter *writer, int struct_id, const void *address, const void *data_ptr)
Definition: writefile.c:1314
void BLO_read_pointer_array(BlendDataReader *reader, void **ptr_p)
Definition: readfile.c:5727
void BLO_write_struct_array_at_address_by_id(BlendWriter *writer, int struct_id, int array_size, const void *address, const void *data_ptr)
Definition: writefile.c:1336
bool BLO_write_is_undo(BlendWriter *writer)
Definition: writefile.c:1412
struct ReportList * BLO_read_lib_reports(BlendLibReader *reader)
Definition: readfile.c:5800
void BLO_write_struct_by_id(BlendWriter *writer, int struct_id, const void *data_ptr)
Definition: writefile.c:1309
void blo_write_id_struct(BlendWriter *writer, int struct_id, const void *id_address, const struct ID *id)
void BLO_write_pointer_array(BlendWriter *writer, uint num, const void *data_ptr)
Definition: writefile.c:1388
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
DEGForeachIDComponentCallback callback
DRWShaderLibrary * lib
format
Definition: logImageCore.h:47
unsigned int uint32_t
Definition: stdint.h:83
signed int int32_t
Definition: stdint.h:80
Definition: DNA_ID.h:273
Definition: BKE_main.h:116