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  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup DNA
22  * \brief blenloader genfile private function prototypes
23  */
24 
25 #pragma once
26 
27 #include "intern/dna_utils.h"
28 
29 struct SDNA;
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /**
36  * DNAstr contains the prebuilt SDNA structure defining the layouts of the types
37  * used by this version of Blender. It is defined in a file dna.c, which is
38  * generated by the makesdna program during the build process (see makesdna.c).
39  */
40 extern const unsigned char DNAstr[];
41 /** Length of DNAstr. */
42 extern const int DNAlen;
43 
44 /**
45  * Primitive (non-struct, non-pointer/function/array) types,
46  * \warning Don't change these values!
47  * Currently changes here here will work on native endianness,
48  * however #DNA_struct_switch_endian currently checks these
49  * hard-coded values against those from old files.
50  */
51 typedef enum eSDNA_Type {
52   SDNA_TYPE_CHAR = 0,
53   SDNA_TYPE_UCHAR = 1,
54   SDNA_TYPE_SHORT = 2,
55   SDNA_TYPE_USHORT = 3,
56   SDNA_TYPE_INT = 4,
57   /* SDNA_TYPE_LONG     = 5, */ /* deprecated (use as int) */
58   /* SDNA_TYPE_ULONG    = 6, */ /* deprecated (use as int) */
59   SDNA_TYPE_FLOAT = 7,
60   SDNA_TYPE_DOUBLE = 8,
61 /* ,SDNA_TYPE_VOID = 9 */
62 /* define so switch statements don't complain */
63 #define SDNA_TYPE_VOID 9
64   SDNA_TYPE_INT64 = 10,
65   SDNA_TYPE_UINT64 = 11,
66 } eSDNA_Type;
67 
68 /**
69  * For use with #DNA_struct_reconstruct & #DNA_struct_get_compareflags
70  */
71 enum eSDNA_StructCompare {
72   /* Struct has disappeared
73    * (values of this struct type will not be loaded by the current Blender) */
74   SDNA_CMP_REMOVED = 0,
75   /* Struct is the same
76    * (can be loaded with straight memory copy after any necessary endian conversion) */
77   SDNA_CMP_EQUAL = 1,
78   /* Struct is different in some way
79    * (needs to be copied/converted field by field) */
80   SDNA_CMP_NOT_EQUAL = 2,
81   /* This is only used temporarily by #DNA_struct_get_compareflags. */
82   SDNA_CMP_UNKNOWN = 3,
83 };
84 
85 struct SDNA *DNA_sdna_from_data(const void *data,
86                                 const int data_len,
87                                 bool do_endian_swap,
88                                 bool data_alloc,
89                                 const char **r_error_message);
90 void DNA_sdna_free(struct SDNA *sdna);
91 
92 /* Access for current Blender versions SDNA*/
93 void DNA_sdna_current_init(void);
94 /* borrowed reference */
95 const struct SDNA *DNA_sdna_current_get(void);
96 void DNA_sdna_current_free(void);
97 
98 struct DNA_ReconstructInfo;
99 struct DNA_ReconstructInfo *DNA_reconstruct_info_create(const struct SDNA *oldsdna,
100                                                         const struct SDNA *newsdna,
101                                                         const char *compare_flags);
102 void DNA_reconstruct_info_free(struct DNA_ReconstructInfo *reconstruct_info);
103 
104 int DNA_struct_find_nr_ex(const struct SDNA *sdna, const char *str, unsigned int *index_last);
105 int DNA_struct_find_nr(const struct SDNA *sdna, const char *str);
106 void DNA_struct_switch_endian(const struct SDNA *sdna, int struct_nr, char *data);
107 const char *DNA_struct_get_compareflags(const struct SDNA *sdna, const struct SDNA *newsdna);
108 void *DNA_struct_reconstruct(const struct DNA_ReconstructInfo *reconstruct_info,
109                              int old_struct_nr,
110                              int blocks,
111                              const void *old_blocks);
112 
113 int DNA_elem_offset(struct SDNA *sdna, const char *stype, const char *vartype, const char *name);
114 
115 int DNA_elem_size_nr(const struct SDNA *sdna, short type, short name);
116 
117 bool DNA_struct_find(const struct SDNA *sdna, const char *stype);
118 bool DNA_struct_elem_find(const struct SDNA *sdna,
119                           const char *stype,
120                           const char *vartype,
121                           const char *name);
122 
123 int DNA_elem_type_size(const eSDNA_Type elem_nr);
124 
125 bool DNA_sdna_patch_struct(struct SDNA *sdna,
126                            const char *struct_name_old,
127                            const char *struct_name_new);
128 bool DNA_sdna_patch_struct_member(struct SDNA *sdna,
129                                   const char *struct_name,
130                                   const char *elem_old,
131                                   const char *elem_new);
132 
133 void DNA_sdna_alias_data_ensure(struct SDNA *sdna);
134 
135 /* Alias lookups (using runtime struct member names). */
136 int DNA_struct_alias_find_nr_ex(const struct SDNA *sdna,
137                                 const char *str,
138                                 unsigned int *index_last);
139 int DNA_struct_alias_find_nr(const struct SDNA *sdna, const char *str);
140 bool DNA_struct_alias_elem_find(const struct SDNA *sdna,
141                                 const char *stype,
142                                 const char *vartype,
143                                 const char *name);
144 void DNA_sdna_alias_data_ensure_structs_map(struct SDNA *sdna);
145 
146 #ifdef __cplusplus
147 }
148 #endif
149