Blender  V3.3
rna_test.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 /* Defines a structure with properties used for array manipulation tests in BPY. */
8 
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include "RNA_define.h"
13 
14 #include "rna_internal.h"
15 
16 #ifdef RNA_RUNTIME
17 
18 # ifdef ARRAY_SIZE
19 # undef ARRAY_SIZE
20 # endif
21 
22 # define ARRAY_SIZE 3
23 # define DYNAMIC_ARRAY_SIZE 64
24 # define MARRAY_DIM [3][4][5]
25 # define MARRAY_TOTDIM 3
26 # define MARRAY_DIMSIZE 4, 5
27 # define MARRAY_SIZE(type) (sizeof(type MARRAY_DIM) / sizeof(type))
28 # define DYNAMIC_MARRAY_DIM [3][4][5]
29 # define DYNAMIC_MARRAY_SIZE(type) (sizeof(type DYNAMIC_MARRAY_DIM) / sizeof(type))
30 
31 # ifdef UNIT_TEST
32 
33 # define DEF_VARS(type, prefix) \
34  static type prefix##arr[ARRAY_SIZE]; \
35  static type prefix##darr[DYNAMIC_ARRAY_SIZE]; \
36  static int prefix##darr_len = ARRAY_SIZE; \
37  static type prefix##marr MARRAY_DIM; \
38  static type prefix##dmarr DYNAMIC_MARRAY_DIM; \
39  static int prefix##dmarr_len = sizeof(prefix##dmarr); \
40  (void)0
41 
42 # define DEF_GET_SET(type, arr) \
43  void rna_Test_##arr##_get(PointerRNA *ptr, type *values) \
44  { \
45  memcpy(values, arr, sizeof(arr)); \
46  } \
47 \
48  void rna_Test_##arr##_set(PointerRNA *ptr, const type *values) \
49  { \
50  memcpy(arr, values, sizeof(arr)); \
51  } \
52  ((void)0)
53 
54 # define DEF_GET_SET_LEN(arr, max) \
55  static int rna_Test_##arr##_get_length(PointerRNA *ptr) \
56  { \
57  return arr##_len; \
58  } \
59 \
60  static int rna_Test_##arr##_set_length(PointerRNA *ptr, int length) \
61  { \
62  if (length > max) { \
63  return 0; \
64  } \
65  arr##_len = length; \
66 \
67  return 1; \
68  } \
69  ((void)0)
70 
71 DEF_VARS(float, f);
72 DEF_VARS(int, i);
73 DEF_VARS(int, b);
74 
75 DEF_GET_SET(float, farr);
76 DEF_GET_SET(int, iarr);
77 DEF_GET_SET(int, barr);
78 
79 DEF_GET_SET(float, fmarr);
80 DEF_GET_SET(int, imarr);
81 DEF_GET_SET(int, bmarr);
82 
83 DEF_GET_SET(float, fdarr);
84 DEF_GET_SET_LEN(fdarr, DYNAMIC_ARRAY_SIZE);
85 DEF_GET_SET(int, idarr);
86 DEF_GET_SET_LEN(idarr, DYNAMIC_ARRAY_SIZE);
87 DEF_GET_SET(int, bdarr);
88 DEF_GET_SET_LEN(bdarr, DYNAMIC_ARRAY_SIZE);
89 
90 DEF_GET_SET(float, fdmarr);
91 DEF_GET_SET_LEN(fdmarr, DYNAMIC_MARRAY_SIZE(float));
92 DEF_GET_SET(int, idmarr);
93 DEF_GET_SET_LEN(idmarr, DYNAMIC_MARRAY_SIZE(int));
94 DEF_GET_SET(int, bdmarr);
95 DEF_GET_SET_LEN(bdmarr, DYNAMIC_MARRAY_SIZE(int));
96 
97 # endif
98 
99 #else
100 
102 {
103 # ifdef UNIT_TEST
104  StructRNA *srna;
105  PropertyRNA *prop;
106  unsigned short dimsize[] = {MARRAY_DIMSIZE};
107 
108  srna = RNA_def_struct(brna, "Test", NULL);
109  RNA_def_struct_sdna(srna, "Test");
110 
111  prop = RNA_def_float_array(
112  srna, "farr", ARRAY_SIZE, NULL, 0.0f, 0.0f, "farr", "float array", 0.0f, 0.0f);
113  RNA_def_property_float_funcs(prop, "rna_Test_farr_get", "rna_Test_farr_set", NULL);
114 
115  prop = RNA_def_int_array(srna, "iarr", ARRAY_SIZE, NULL, 0, 0, "iarr", "int array", 0, 0);
116  RNA_def_property_int_funcs(prop, "rna_Test_iarr_get", "rna_Test_iarr_set", NULL);
117 
118  prop = RNA_def_boolean_array(srna, "barr", ARRAY_SIZE, NULL, "barr", "boolean array");
119  RNA_def_property_boolean_funcs(prop, "rna_Test_barr_get", "rna_Test_barr_set");
120 
121  /* dynamic arrays */
122 
123  prop = RNA_def_float_array(srna,
124  "fdarr",
125  DYNAMIC_ARRAY_SIZE,
126  NULL,
127  0.0f,
128  0.0f,
129  "fdarr",
130  "dynamic float array",
131  0.0f,
132  0.0f);
135  prop, "rna_Test_fdarr_get_length", "rna_Test_fdarr_set_length");
136  RNA_def_property_float_funcs(prop, "rna_Test_fdarr_get", "rna_Test_fdarr_set", NULL);
137 
138  prop = RNA_def_int_array(
139  srna, "idarr", DYNAMIC_ARRAY_SIZE, NULL, 0, 0, "idarr", "int array", 0, 0);
142  prop, "rna_Test_idarr_get_length", "rna_Test_idarr_set_length");
143  RNA_def_property_int_funcs(prop, "rna_Test_idarr_get", "rna_Test_idarr_set", NULL);
144 
145  prop = RNA_def_boolean_array(srna, "bdarr", DYNAMIC_ARRAY_SIZE, NULL, "bdarr", "boolean array");
148  prop, "rna_Test_bdarr_get_length", "rna_Test_bdarr_set_length");
149  RNA_def_property_boolean_funcs(prop, "rna_Test_bdarr_get", "rna_Test_bdarr_set");
150 
151  /* multidimensional arrays */
152 
153  prop = RNA_def_property(srna, "fmarr", PROP_FLOAT, PROP_NONE);
154  RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(float), MARRAY_TOTDIM, dimsize);
155  RNA_def_property_float_funcs(prop, "rna_Test_fmarr_get", "rna_Test_fmarr_set", NULL);
156 
157  prop = RNA_def_property(srna, "imarr", PROP_INT, PROP_NONE);
158  RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize);
159  RNA_def_property_int_funcs(prop, "rna_Test_imarr_get", "rna_Test_imarr_set", NULL);
160 
161  prop = RNA_def_property(srna, "bmarr", PROP_BOOLEAN, PROP_NONE);
162  RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize);
163  RNA_def_property_boolean_funcs(prop, "rna_Test_bmarr_get", "rna_Test_bmarr_set");
164 
165  /* dynamic multidimensional arrays */
166 
167  prop = RNA_def_property(srna, "fdmarr", PROP_FLOAT, PROP_NONE);
168  RNA_def_property_multidimensional_array(
169  prop, DYNAMIC_MARRAY_SIZE(float), MARRAY_TOTDIM, dimsize);
172  prop, "rna_Test_fdmarr_get_length", "rna_Test_fdmarr_set_length");
173  RNA_def_property_float_funcs(prop, "rna_Test_fdmarr_get", "rna_Test_fdmarr_set", NULL);
174 
175  prop = RNA_def_property(srna, "idmarr", PROP_INT, PROP_NONE);
176  RNA_def_property_multidimensional_array(prop, DYNAMIC_MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize);
179  prop, "rna_Test_idmarr_get_length", "rna_Test_idmarr_set_length");
180  RNA_def_property_int_funcs(prop, "rna_Test_idmarr_get", "rna_Test_idmarr_set", NULL);
181 
182  prop = RNA_def_property(srna, "bdmarr", PROP_BOOLEAN, PROP_NONE);
183  RNA_def_property_multidimensional_array(prop, DYNAMIC_MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize);
186  prop, "rna_Test_bdmarr_get_length", "rna_Test_bdmarr_set_length");
187  RNA_def_property_boolean_funcs(prop, "rna_Test_bdmarr_get", "rna_Test_bdmarr_set");
188 # else
189  (void)brna;
190 # endif
191 }
192 
193 #endif /* RNA_RUNTIME */
#define ARRAY_SIZE(arr)
@ PROP_FLOAT
Definition: RNA_types.h:61
@ PROP_BOOLEAN
Definition: RNA_types.h:59
@ PROP_INT
Definition: RNA_types.h:60
@ PROP_DYNAMIC
Definition: RNA_types.h:290
@ PROP_NONE
Definition: RNA_types.h:126
SyclQueue void void size_t num_bytes void
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3655
PropertyRNA * RNA_def_float_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:4076
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3126
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
Definition: rna_define.c:2944
void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength)
Definition: rna_define.c:2926
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1048
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1257
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1028
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3028
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
PropertyRNA * RNA_def_boolean_array(StructOrFunctionRNA *cont_, const char *identifier, int len, bool *default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3509
void RNA_def_test(BlenderRNA *brna)
Definition: rna_test.c:101