|
Blender
V2.59
|
00001 /* 00002 * $Id: rna_test.c 35238 2011-02-27 20:20:01Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Contributor(s): Arystanbek Dyussenov 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00030 /* Defines a structure with properties used for array manipulation tests in BPY. */ 00031 00032 #include <stdlib.h> 00033 #include <string.h> 00034 00035 #include "RNA_define.h" 00036 00037 #include "rna_internal.h" 00038 00039 #define ARRAY_SIZE 3 00040 #define DYNAMIC_ARRAY_SIZE 64 00041 #define MARRAY_DIM [3][4][5] 00042 #define MARRAY_TOTDIM 3 00043 #define MARRAY_DIMSIZE 4, 5 00044 #define MARRAY_SIZE(type) (sizeof(type MARRAY_DIM) / sizeof(type)) 00045 #define DYNAMIC_MARRAY_DIM [3][4][5] 00046 #define DYNAMIC_MARRAY_SIZE(type) (sizeof(type DYNAMIC_MARRAY_DIM) / sizeof(type)) 00047 00048 #ifdef RNA_RUNTIME 00049 00050 #ifdef UNIT_TEST 00051 00052 #define DEF_VARS(type, prefix) \ 00053 static type prefix ## arr[ARRAY_SIZE]; \ 00054 static type prefix ## darr[DYNAMIC_ARRAY_SIZE]; \ 00055 static int prefix ## darr_len= ARRAY_SIZE; \ 00056 static type prefix ## marr MARRAY_DIM; \ 00057 static type prefix ## dmarr DYNAMIC_MARRAY_DIM; \ 00058 static int prefix ## dmarr_len= sizeof(prefix ## dmarr); 00059 00060 #define DEF_GET_SET(type, arr) \ 00061 void rna_Test_ ## arr ## _get(PointerRNA *ptr, type *values) \ 00062 { \ 00063 memcpy(values, arr, sizeof(arr)); \ 00064 } \ 00065 \ 00066 void rna_Test_ ## arr ## _set(PointerRNA *ptr, const type *values) \ 00067 { \ 00068 memcpy(arr, values, sizeof(arr)); \ 00069 } 00070 00071 #define DEF_GET_SET_LEN(arr, max) \ 00072 static int rna_Test_ ## arr ## _get_length(PointerRNA *ptr) \ 00073 { \ 00074 return arr ## _len; \ 00075 } \ 00076 \ 00077 static int rna_Test_ ## arr ## _set_length(PointerRNA *ptr, int length) \ 00078 { \ 00079 if (length > max) \ 00080 return 0; \ 00081 \ 00082 arr ## _len= length; \ 00083 \ 00084 return 1; \ 00085 } \ 00086 00087 DEF_VARS(float, f) 00088 DEF_VARS(int, i) 00089 DEF_VARS(int, b) 00090 00091 DEF_GET_SET(float, farr) 00092 DEF_GET_SET(int, iarr) 00093 DEF_GET_SET(int, barr) 00094 00095 DEF_GET_SET(float, fmarr) 00096 DEF_GET_SET(int, imarr) 00097 DEF_GET_SET(int, bmarr) 00098 00099 DEF_GET_SET(float, fdarr) 00100 DEF_GET_SET_LEN(fdarr, DYNAMIC_ARRAY_SIZE) 00101 DEF_GET_SET(int, idarr) 00102 DEF_GET_SET_LEN(idarr, DYNAMIC_ARRAY_SIZE) 00103 DEF_GET_SET(int, bdarr) 00104 DEF_GET_SET_LEN(bdarr, DYNAMIC_ARRAY_SIZE) 00105 00106 DEF_GET_SET(float, fdmarr) 00107 DEF_GET_SET_LEN(fdmarr, DYNAMIC_MARRAY_SIZE(float)) 00108 DEF_GET_SET(int, idmarr) 00109 DEF_GET_SET_LEN(idmarr, DYNAMIC_MARRAY_SIZE(int)) 00110 DEF_GET_SET(int, bdmarr) 00111 DEF_GET_SET_LEN(bdmarr, DYNAMIC_MARRAY_SIZE(int)) 00112 00113 #endif 00114 00115 #else 00116 00117 void RNA_def_test(BlenderRNA *brna) 00118 { 00119 #ifdef UNIT_TEST 00120 StructRNA *srna; 00121 PropertyRNA *prop; 00122 unsigned short dimsize[]= {MARRAY_DIMSIZE}; 00123 00124 srna= RNA_def_struct(brna, "Test", NULL); 00125 RNA_def_struct_sdna(srna, "Test"); 00126 00127 prop= RNA_def_float_array(srna, "farr", ARRAY_SIZE, NULL, 0.0f, 0.0f, "farr", "float array", 0.0f, 0.0f); 00128 RNA_def_property_float_funcs(prop, "rna_Test_farr_get", "rna_Test_farr_set", NULL); 00129 00130 prop= RNA_def_int_array(srna, "iarr", ARRAY_SIZE, NULL, 0, 0, "iarr", "int array", 0, 0); 00131 RNA_def_property_int_funcs(prop, "rna_Test_iarr_get", "rna_Test_iarr_set", NULL); 00132 00133 prop= RNA_def_boolean_array(srna, "barr", ARRAY_SIZE, NULL, "barr", "boolean array"); 00134 RNA_def_property_boolean_funcs(prop, "rna_Test_barr_get", "rna_Test_barr_set"); 00135 00136 /* dynamic arrays */ 00137 00138 prop= RNA_def_float_array(srna, "fdarr", DYNAMIC_ARRAY_SIZE, NULL, 0.0f, 0.0f, "fdarr", "dynamic float array", 0.0f, 0.0f); 00139 RNA_def_property_flag(prop, PROP_DYNAMIC); 00140 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_fdarr_get_length", "rna_Test_fdarr_set_length"); 00141 RNA_def_property_float_funcs(prop, "rna_Test_fdarr_get", "rna_Test_fdarr_set", NULL); 00142 00143 prop= RNA_def_int_array(srna, "idarr", DYNAMIC_ARRAY_SIZE, NULL, 0, 0, "idarr", "int array", 0, 0); 00144 RNA_def_property_flag(prop, PROP_DYNAMIC); 00145 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_idarr_get_length", "rna_Test_idarr_set_length"); 00146 RNA_def_property_int_funcs(prop, "rna_Test_idarr_get", "rna_Test_idarr_set", NULL); 00147 00148 prop= RNA_def_boolean_array(srna, "bdarr", DYNAMIC_ARRAY_SIZE, NULL, "bdarr", "boolean array"); 00149 RNA_def_property_flag(prop, PROP_DYNAMIC); 00150 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_bdarr_get_length", "rna_Test_bdarr_set_length"); 00151 RNA_def_property_boolean_funcs(prop, "rna_Test_bdarr_get", "rna_Test_bdarr_set"); 00152 00153 /* multidimensional arrays */ 00154 00155 prop= RNA_def_property(srna, "fmarr", PROP_FLOAT, PROP_NONE); 00156 RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(float), MARRAY_TOTDIM, dimsize); 00157 RNA_def_property_float_funcs(prop, "rna_Test_fmarr_get", "rna_Test_fmarr_set", NULL); 00158 00159 prop= RNA_def_property(srna, "imarr", PROP_INT, PROP_NONE); 00160 RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize); 00161 RNA_def_property_int_funcs(prop, "rna_Test_imarr_get", "rna_Test_imarr_set", NULL); 00162 00163 prop= RNA_def_property(srna, "bmarr", PROP_BOOLEAN, PROP_NONE); 00164 RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize); 00165 RNA_def_property_boolean_funcs(prop, "rna_Test_bmarr_get", "rna_Test_bmarr_set"); 00166 00167 /* dynamic multidimensional arrays */ 00168 00169 prop= RNA_def_property(srna, "fdmarr", PROP_FLOAT, PROP_NONE); 00170 RNA_def_property_multidimensional_array(prop, DYNAMIC_MARRAY_SIZE(float), MARRAY_TOTDIM, dimsize); 00171 RNA_def_property_flag(prop, PROP_DYNAMIC); 00172 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_fdmarr_get_length", "rna_Test_fdmarr_set_length"); 00173 RNA_def_property_float_funcs(prop, "rna_Test_fdmarr_get", "rna_Test_fdmarr_set", NULL); 00174 00175 prop= RNA_def_property(srna, "idmarr", PROP_INT, PROP_NONE); 00176 RNA_def_property_multidimensional_array(prop, DYNAMIC_MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize); 00177 RNA_def_property_flag(prop, PROP_DYNAMIC); 00178 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_idmarr_get_length", "rna_Test_idmarr_set_length"); 00179 RNA_def_property_int_funcs(prop, "rna_Test_idmarr_get", "rna_Test_idmarr_set", NULL); 00180 00181 prop= RNA_def_property(srna, "bdmarr", PROP_BOOLEAN, PROP_NONE); 00182 RNA_def_property_multidimensional_array(prop, DYNAMIC_MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize); 00183 RNA_def_property_flag(prop, PROP_DYNAMIC); 00184 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_bdmarr_get_length", "rna_Test_bdmarr_set_length"); 00185 RNA_def_property_boolean_funcs(prop, "rna_Test_bdmarr_get", "rna_Test_bdmarr_set"); 00186 00187 #endif 00188 } 00189 00190 #endif /* RNA_RUNTIME */ 00191 00192